Added PALT viewing to iff2html

This commit is contained in:
Fatbag 2012-05-25 15:48:09 -05:00
parent 783227a630
commit 62ad3dfc4f
12 changed files with 116 additions and 21 deletions

View file

@ -7,6 +7,7 @@ set(IFF_SOURCES
bcon.c
fcns.c
glob.c
palt.c
rsmp.c
str.c
string.c

View file

@ -30,7 +30,7 @@ int iff_parse_bcon(IFFChunk * ChunkInfo, const uint8_t * Buffer){
if(ChunkInfo->FormattedData == NULL)
return 0;
BCONData = (IFF_BCON*) ChunkInfo->FormattedData;
BCONData = ChunkInfo->FormattedData;
BCONData->ConstantCount = read_uint8le(Buffer);
BCONData->Flags = read_uint8le(Buffer + 1);
if(BCONData->ConstantCount == 0)
@ -49,6 +49,6 @@ int iff_parse_bcon(IFFChunk * ChunkInfo, const uint8_t * Buffer){
}
void iff_free_bcon(void * FormattedData){
IFF_BCON *BCONData = (IFF_BCON*) FormattedData;
IFF_BCON *BCONData = FormattedData;
free(BCONData->Constants);
}

View file

@ -26,7 +26,7 @@ int iff_parse_cats(IFFChunk * ChunkInfo, const uint8_t * Buffer){
ChunkInfo->FormattedData = calloc(1, sizeof(IFFStringPair));
if(ChunkInfo->FormattedData == NULL)
return 0;
StringData = (IFFStringPair*) ChunkInfo->FormattedData;
StringData = ChunkInfo->FormattedData;
for(s=0; s<2; s++){
unsigned length;
@ -49,7 +49,7 @@ int iff_parse_cats(IFFChunk * ChunkInfo, const uint8_t * Buffer){
}
void iff_free_cats(void * FormattedData){
IFFStringPair * StringData = (IFFStringPair*) FormattedData;
IFFStringPair * StringData = FormattedData;
free(StringData->Key);
free(StringData->Value);
}

View file

@ -33,6 +33,7 @@ iff_register(cats);
iff_register(c_string);
iff_register(glob);
iff_register(fcns);
iff_register(palt);
iff_register(tmpl);
iff_register(trcn);
iff_register(rsmp);
@ -45,6 +46,7 @@ const char chunktypes[] =
"GLOB"
"BCON"
"FCNS"
"PALT"
"TMPL"
"TRCN"
"rsmp"
@ -56,6 +58,7 @@ int (* const iff_parse_function[])(IFFChunk*, const uint8_t*) = {
iff_parse_glob,
iff_parse_bcon,
iff_parse_fcns,
iff_parse_palt,
iff_parse_tmpl,
iff_parse_trcn,
iff_parse_rsmp
@ -67,6 +70,7 @@ void (* const iff_free_function[])(void*) = {
NULL,
iff_free_bcon,
iff_free_fcns,
NULL,
iff_free_tmpl,
iff_free_trcn,
iff_free_rsmp

View file

@ -98,6 +98,17 @@ typedef struct IFFConstantList_s
IFFConstant * Constants;
} IFFConstantList;
/* PALT chunk */
typedef struct IFFPalette_s
{
uint32_t Version;
uint32_t ColorCount;
uint32_t Reserved1;
uint32_t Reserved2;
uint8_t Data[256*3];
} IFFPalette;
/* STR# chunk */
enum IFFLanguage {
@ -161,7 +172,7 @@ typedef struct IFFTemplate_s
typedef struct IFFRangeEntry_s
{
uint32_t IsUnused;
uint32_t IsUsed;
uint32_t DefaultValue;
char * Name;
char * Comment;

View file

@ -0,0 +1,42 @@
/*
FileHandler - General-purpose file handling library for Niotso
palt.c - Copyright (c) 2012 Niotso Project <http://niotso.org/>
Author(s): Fatbag <X-Fi6@phppoll.org>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "iff.h"
int iff_parse_palt(IFFChunk * ChunkInfo, const uint8_t * Buffer){
IFFPalette *Palette;
unsigned Size = ChunkInfo->Size - 76;
if(Size < 16)
return 0;
ChunkInfo->FormattedData = malloc(sizeof(IFFPalette));
if(ChunkInfo->FormattedData == NULL)
return 0;
Palette = ChunkInfo->FormattedData;
Palette->Version = read_uint32le(Buffer);
Palette->ColorCount = read_uint32le(Buffer+4);
Palette->Reserved1 = read_uint32le(Buffer+8);
Palette->Reserved2 = read_uint32le(Buffer+12);
if(Palette->Version != 1 || Palette->ColorCount == 0 || Palette->ColorCount > 256 ||
Palette->Reserved1 != 0 || Palette->Reserved2 != 0 || Palette->ColorCount*3 > Size-16)
return 0;
memcpy(Palette->Data, Buffer+16, Palette->ColorCount*3);
return 1;
}

View file

@ -29,7 +29,7 @@ int iff_parse_str(IFFChunk * ChunkInfo, const uint8_t * Buffer){
if(ChunkInfo->FormattedData == NULL)
return 0;
StringData = (IFFString*) ChunkInfo->FormattedData;
StringData = ChunkInfo->FormattedData;
StringData->Format = read_int16le(Buffer);
if((Size-=2) < 2) /* TSO allows this; as seen in the animations chunk in personglobals.iff */
return 1;
@ -261,7 +261,7 @@ void iff_free_str(void * FormattedData){
** - If the Pairs pointer is nonzero, there must be PairCount initialized pairs in Pairs
*/
IFFString * StringData = (IFFString*) FormattedData;
IFFString * StringData = FormattedData;
unsigned ls;
for(ls=0; ls<20; ls++){

View file

@ -39,7 +39,7 @@ int iff_parse_tmpl(IFFChunk * ChunkInfo, const uint8_t * Buffer){
if(ChunkInfo->FormattedData == NULL)
return 0;
Template = (IFFTemplate*) ChunkInfo->FormattedData;
Template = ChunkInfo->FormattedData;
Template->FieldCount = FieldCount;
Template->Fields = calloc(FieldCount, sizeof(IFFTemplateField));
if(Template->Fields == NULL)

View file

@ -30,7 +30,7 @@ int iff_parse_trcn(IFFChunk * ChunkInfo, const uint8_t * Buffer){
if(ChunkInfo->FormattedData == NULL)
return 0;
RangeSet = (IFFRangeSet*) ChunkInfo->FormattedData;
RangeSet = ChunkInfo->FormattedData;
RangeSet->Ranges = NULL;
RangeSet->Reserved = read_uint32le(Buffer);
RangeSet->Version = read_uint32le(Buffer+4);
@ -53,7 +53,7 @@ int iff_parse_trcn(IFFChunk * ChunkInfo, const uint8_t * Buffer){
if(Size < 10)
return 0;
Range->IsUnused = read_uint32le(Buffer);
Range->IsUsed = read_uint32le(Buffer);
Range->DefaultValue = read_uint32le(Buffer+4);
Buffer += 8; Size -= 8;
@ -116,7 +116,7 @@ int iff_parse_trcn(IFFChunk * ChunkInfo, const uint8_t * Buffer){
}
void iff_free_trcn(void * FormattedData){
IFFRangeSet *RangeSet = (IFFRangeSet*) FormattedData;
IFFRangeSet *RangeSet = FormattedData;
if(RangeSet->Ranges){
unsigned i;
for(i=0; i<RangeSet->RangeCount; i++){