8 //#include <image_sif.h>
9 #include <acess/sys.h> // _SysDebug
11 #define _SysDebug(...) do{}while(0)
32 tImage *Image_SIF_Parse(void *Buffer, size_t Size)
41 struct sHeader *hdr = Buffer;
43 _SysDebug("Image_SIF_Parse: (Buffer=%p, Size=0x%x)", Buffer, Size);
45 // Get magic word and determine byte ordering
46 if(hdr->Magic == 0x51F0) // Little Endian
48 else if(hdr->Magic == 0xF051) // Big Endian
51 _SysDebug(" Image_SIF_Parse: Magic invalid (0x%x)", hdr->Magic);
55 _SysDebug(" Image_SIF_Parse: bRevOrder = %i", bRevOrder);
58 comp = hdr->Flags & 7;
59 fmt = (hdr->Flags >> 3) & 7;
65 _SysDebug(" Image_SIF_Parse: Dimensions %ix%i", w, h);
70 case 0: // ARGB 32-bit Little Endian
74 case 1: // RGB 24-bit big endian
82 _SysDebug(" Image_SIF_Parse: sampleSize = %i, fmt = %i", sampleSize, fmt);
84 fileOfs = sizeof(struct sHeader);
87 ret = calloc(1, sizeof(tImage) + w * h * sampleSize);
91 for( ofs = 0; ofs < w*h*sampleSize; ofs ++ )
96 // Uncompressed 32-bpp data
98 if( fileOfs + w*h*sampleSize > Size ) {
99 memcpy(ret->Data, Buffer+fileOfs, Size-fileOfs);
102 memcpy(ret->Data, Buffer+fileOfs, w*h*sampleSize);
107 // (1 Flag, 7-bit size, 32-bit value)
110 while( ofs < w*h*sampleSize )
113 if( fileOfs + 1 > Size )
115 len = ((uint8_t*)Buffer)[fileOfs++];
121 if( fileOfs + sampleSize > Size )
123 memcpy(ret->Data+ofs, Buffer+fileOfs, sampleSize);
125 fileOfs += sampleSize;
130 if( fileOfs + sampleSize > Size )
135 memcpy(ret->Data+ofs, Buffer+fileOfs, sampleSize);
138 fileOfs += sampleSize;
141 _SysDebug("Image_SIF_Parse: Complete at %i bytes", fileOfs);
145 // - Each channel is separately 1.7 RLE compressed
147 // Alpha, Red, Green, Blue
148 for( i = 0; i < sampleSize; i++ )
151 while( ofs < w*h*sampleSize )
154 if( fileOfs + 1 > Size ) return ret;
155 len = ((uint8_t*)Buffer)[fileOfs++];
159 if( fileOfs + 1 > Size ) return ret;
160 val = ((uint8_t*)Buffer)[fileOfs++];
161 ret->Data[ofs] = val;
166 if( fileOfs + 1 > Size ) return ret;
167 val = ((uint8_t*)Buffer)[fileOfs++];
169 ret->Data[ofs] = val;
178 fprintf(stderr, "Warning: Unknown compression scheme %i for SIF\n", comp);