mirror of
https://github.com/simtactics/niotso.git
synced 2025-03-22 02:52:18 +00:00
The iff parsing code now accepts SPR# chunks with a "blank sprite", one that has zero dimensions.
This commit is contained in:
parent
31282d91f2
commit
ec45a6ce82
3 changed files with 16 additions and 9 deletions
|
@ -118,6 +118,8 @@ typedef struct IFFSprite_s
|
||||||
uint16_t Width;
|
uint16_t Width;
|
||||||
uint8_t * IndexData;
|
uint8_t * IndexData;
|
||||||
uint8_t * BGRA32Data;
|
uint8_t * BGRA32Data;
|
||||||
|
|
||||||
|
uint8_t InvalidDimensions;
|
||||||
} IFFSprite;
|
} IFFSprite;
|
||||||
|
|
||||||
typedef struct IFFSpriteList_s
|
typedef struct IFFSpriteList_s
|
||||||
|
|
|
@ -117,11 +117,15 @@ int iff_parse_spr(IFFChunk * ChunkInfo, const uint8_t * Buffer){
|
||||||
if(SpriteSize > b.Size || SpriteSize < 10)
|
if(SpriteSize > b.Size || SpriteSize < 10)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Sprite->Reserved = read_uint32xe(&b);
|
Sprite->Reserved = read_uint32xe(&b);
|
||||||
Sprite->Height = read_uint16xe(&b);
|
Sprite->Height = read_uint16xe(&b);
|
||||||
Sprite->Width = read_uint16xe(&b);
|
Sprite->Width = read_uint16xe(&b);
|
||||||
if(Sprite->Reserved != 0 || Sprite->Height == 0 || Sprite->Width == 0 || Sprite->Height > UINT_MAX/Sprite->Width/2)
|
if(Sprite->Reserved != 0 || Sprite->Height == 0 || Sprite->Width == 0 || Sprite->Height > UINT_MAX/Sprite->Width/2){
|
||||||
return 0;
|
/* This happens in the third sprite of every SPR# chunk in sprites.iff */
|
||||||
|
Sprite->InvalidDimensions = 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
Sprite->IndexData = calloc(Sprite->Height*Sprite->Width, 2);
|
Sprite->IndexData = calloc(Sprite->Height*Sprite->Width, 2);
|
||||||
if(Sprite->IndexData == NULL)
|
if(Sprite->IndexData == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -229,6 +233,7 @@ int iff_depalette(IFFSprite * Sprite, const IFFPalette * Palette){
|
||||||
uint8_t Index = Sprite->IndexData[2*i + 0];
|
uint8_t Index = Sprite->IndexData[2*i + 0];
|
||||||
if(Index >= Palette->ColorCount){
|
if(Index >= Palette->ColorCount){
|
||||||
free(Sprite->BGRA32Data);
|
free(Sprite->BGRA32Data);
|
||||||
|
Sprite->BGRA32Data = NULL;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Sprite->BGRA32Data[4*i + 0] = Palette->Data[3*Index + 2];
|
Sprite->BGRA32Data[4*i + 0] = Palette->Data[3*Index + 2];
|
||||||
|
|
|
@ -309,13 +309,13 @@ int main(int argc, char *argv[]){
|
||||||
if(!strcmp(ChunkData->Type, "BMP_") || !strcmp(ChunkData->Type, "FBMP")){
|
if(!strcmp(ChunkData->Type, "BMP_") || !strcmp(ChunkData->Type, "FBMP")){
|
||||||
size_t Width, Height;
|
size_t Width, Height;
|
||||||
char filename[32];
|
char filename[32];
|
||||||
sprintf(filename, "%simg_%u_%.4x.png", OutDir, c, ChunkData->ChunkID);
|
sprintf(filename, "%sbmp_%u_%.4x.png", OutDir, c+1, ChunkData->ChunkID);
|
||||||
|
|
||||||
if(WritePNG(filename, ChunkData, NULL, &Width, &Height)){
|
if(WritePNG(filename, ChunkData, NULL, &Width, &Height)){
|
||||||
fprintf(hFile, "<table class=\"center centerall\">\n");
|
fprintf(hFile, "<table class=\"center centerall\">\n");
|
||||||
fprintf(hFile, "<tr><th>Image</th></tr>\n");
|
fprintf(hFile, "<tr><th>Image</th></tr>\n");
|
||||||
fprintf(hFile, "<tr><td><img src=\"img_%u_%.4x.png\" width=\"%u\" height=\"%u\" alt=\"\" /></td></tr>\n",
|
fprintf(hFile, "<tr><td><img src=\"bmp_%u_%.4x.png\" width=\"%u\" height=\"%u\" alt=\"\" /></td></tr>\n",
|
||||||
c, ChunkData->ChunkID, Width, Height);
|
c+1, ChunkData->ChunkID, Width, Height);
|
||||||
fprintf(hFile, "</table>\n");
|
fprintf(hFile, "</table>\n");
|
||||||
success++;
|
success++;
|
||||||
}
|
}
|
||||||
|
@ -563,14 +563,14 @@ int main(int argc, char *argv[]){
|
||||||
for(i=0; i<SpriteList->SpriteCount; i++){
|
for(i=0; i<SpriteList->SpriteCount; i++){
|
||||||
IFFSprite * Sprite = &SpriteList->Sprites[i];
|
IFFSprite * Sprite = &SpriteList->Sprites[i];
|
||||||
char filename[32];
|
char filename[32];
|
||||||
sprintf(filename, "%sspr1_%u_%.4x_%u.png", OutDir, c, ChunkData->ChunkID, i+1);
|
sprintf(filename, "%sspr1_%u_%.4x_%u.png", OutDir, c+1, ChunkData->ChunkID, i+1);
|
||||||
|
|
||||||
fprintf(hFile, "<tr><td>%u</td><td>", i+1);
|
fprintf(hFile, "<tr><td>%u</td><td>", i+1);
|
||||||
if(iff_depalette(Sprite, PaletteData) && WritePNG(filename, NULL, Sprite, NULL, NULL))
|
if(Sprite->IndexData && iff_depalette(Sprite, PaletteData) && WritePNG(filename, NULL, Sprite, NULL, NULL))
|
||||||
fprintf(hFile, "<img src=\"spr1_%u_%.4x_%u.png\" width=\"%u\" height=\"%u\" alt=\"\" />",
|
fprintf(hFile, "<img src=\"spr1_%u_%.4x_%u.png\" width=\"%u\" height=\"%u\" alt=\"\" />",
|
||||||
c, ChunkData->ChunkID, i+1, Sprite->Width, Sprite->Height);
|
c+1, ChunkData->ChunkID, i+1, Sprite->Width, Sprite->Height);
|
||||||
else
|
else
|
||||||
fprintf(hFile, "This sprite cannot be displayed.");
|
fprintf(hFile, Sprite->InvalidDimensions ? "Blank sprite" : "This sprite cannot be displayed.");
|
||||||
fprintf(hFile, "</td></tr>\n");
|
fprintf(hFile, "</td></tr>\n");
|
||||||
}
|
}
|
||||||
fprintf(hFile, "</table>\n");
|
fprintf(hFile, "</table>\n");
|
||||||
|
|
Loading…
Add table
Reference in a new issue