return 0;
}
+static uint32_t flipendian32(uint32_t val)
+{
+ return ((val >> 24) & 0xFF) << 0
+ | ((val >> 16) & 0xFF) << 8
+ | ((val >> 8) & 0xFF) << 16
+ | ((val >> 0) & 0xFF) << 24;
+}
+
+static void flip_buffer_endian(void *Data, size_t SampleSize, size_t Pixels)
+{
+ if( SampleSize == 3 )
+ return ;
+
+ if( SampleSize == 4 )
+ {
+ uint32_t *data32 = Data;
+ while( Pixels -- ) {
+ *data32 = flipendian32(*data32);
+ data32 ++;
+ }
+ }
+}
+
/**
*/
tImage *Image_SIF_Parse(void *Buffer, size_t Size)
switch(comp)
{
// Uncompressed 32-bpp data
- case 0:
- if( fileOfs + w*h*sampleSize > Size ) {
- memcpy(ret->Data, Buffer+fileOfs, Size-fileOfs);
- }
- else {
- memcpy(ret->Data, Buffer+fileOfs, w*h*sampleSize);
- }
+ case 0: {
+ size_t idatsize = w*h*sampleSize;
+ if( idatsize > Size - fileOfs )
+ idatsize = Size - fileOfs;
+ memcpy(ret->Data, Buffer+fileOfs, idatsize);
+ if(bRevOrder)
+ flip_buffer_endian(ret->Data, sampleSize, w*h);
return ret;
+ }
// 1.7.n*8 RLE
// (1 Flag, 7-bit size, 32-bit value)
fileOfs += sampleSize;
}
}
+ if(bRevOrder)
+ flip_buffer_endian(ret->Data, sampleSize, w*h);
_SysDebug("Image_SIF_Parse: Complete at %i bytes", fileOfs);
return ret;