Usermode/libimage_sif - Added endian-flipping support
authorJohn Hodge <[email protected]>
Mon, 22 Jul 2013 12:30:23 +0000 (20:30 +0800)
committerJohn Hodge <[email protected]>
Mon, 22 Jul 2013 12:30:23 +0000 (20:30 +0800)
Usermode/Libraries/libimage_sif.so_src/main.c

index a515856..61136a1 100644 (file)
@@ -27,6 +27,29 @@ int SoMain(void)
        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)
@@ -94,14 +117,15 @@ 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)
@@ -138,6 +162,8 @@ tImage *Image_SIF_Parse(void *Buffer, size_t Size)
                                fileOfs += sampleSize;
                        }
                }
+               if(bRevOrder)
+                       flip_buffer_endian(ret->Data, sampleSize, w*h);
                _SysDebug("Image_SIF_Parse: Complete at %i bytes", fileOfs);
                return ret;
        

UCC git Repository :: git.ucc.asn.au