Author: spouliot
Date: 2007-01-12 11:12:31 -0500 (Fri, 12 Jan 2007)
New Revision: 70926

Modified:
   trunk/libgdiplus/src/ChangeLog
   trunk/libgdiplus/src/icocodec.c
Log:
2007-01-12  Sebastien Pouliot  <[EMAIL PROTECTED]> 
        * icocodec.c: Fix endianess when reading the ICONDIRENTRY.


Modified: trunk/libgdiplus/src/ChangeLog
===================================================================
--- trunk/libgdiplus/src/ChangeLog      2007-01-12 15:30:41 UTC (rev 70925)
+++ trunk/libgdiplus/src/ChangeLog      2007-01-12 16:12:31 UTC (rev 70926)
@@ -1,4 +1,4 @@
-2007-01-12  Sebastien Pouliot  <[EMAIL PROTECTED]>
+2007-01-12  Sebastien Pouliot  <[EMAIL PROTECTED]> 
 
        * bitmap.c: Fix HBITMAP support in GdipCreateBitmapFromHBITMAP and 
        GdipCreateHBITMAPFromBitmap functions so an HBITMAP can survive the
@@ -6,6 +6,7 @@
        and GdipCreateHICONFromBitmap functions. See comments about freeing
        the memory associated with HBITMAP and HICON.
        * gdip.h: Add new undocumented ImageFlag to match MS results.
+       * icocodec.c: Fix endianess when reading the ICONDIRENTRY.
 
 2007-01-11  Sebastien Pouliot  <[EMAIL PROTECTED]>
 

Modified: trunk/libgdiplus/src/icocodec.c
===================================================================
--- trunk/libgdiplus/src/icocodec.c     2007-01-12 15:30:41 UTC (rev 70925)
+++ trunk/libgdiplus/src/icocodec.c     2007-01-12 16:12:31 UTC (rev 70926)
@@ -75,6 +75,28 @@
        return result;
 }
 
+static BOOL
+read_ICONDIRENTRY (void *pointer, ICONDIRENTRY *entry, BOOL useFile, BOOL 
decode)
+{
+       if (gdip_read_ico_data (pointer, (void*)entry, sizeof (ICONDIRENTRY), 
useFile) != sizeof (ICONDIRENTRY))
+               return FALSE;
+#if WORDS_BIGENDIAN
+       if (decode) {
+               BYTE *b;
+               /* entry->bWidth, bHeight, bColorCount, bReserved are all BYTE, 
no change required */
+               b = (BYTE*)&entry->wPlanes;
+               entry->wPlanes = (b[1] << 8) | b[0]; 
+               b = (BYTE*)&entry->wBitCount;
+               entry->wBitCount = (b[1] << 8) | b[0];
+               b = (BYTE*)&entry->dwBytesInRes;
+               entry->dwBytesInRes = (b[3] << 24) | (b[2] << 16) | (b[1] << 8) 
| b[0];
+               b = (BYTE*)&entry->dwImageOffset;
+               entry->dwImageOffset = (b[3] << 24) | (b[2] << 16) | (b[1] << 
8) | b[0];
+       }
+#endif
+       return TRUE;
+}
+
 static GpStatus
 gdip_read_ico_image_from_file_stream (void *pointer, GpImage **image, bool 
useFile)
 {
@@ -120,11 +142,15 @@
         * NOTE: it looks like (from unit tests) that we get the last icon 
         * (e.g. it can return the 16 pixel version, instead of the 32 or 48 
pixels available in the same file)
         */ 
-       for (i = 0; i < count; i++) {
-               if (gdip_read_ico_data (pointer, (void*)&entry, sizeof 
(ICONDIRENTRY), useFile) != sizeof (ICONDIRENTRY))
+       for (i = 0; i < count - 1; i++) {
+               if (!read_ICONDIRENTRY (pointer, &entry, useFile, FALSE))
                        goto error;
                pos += sizeof (ICONDIRENTRY);
        }
+       /* last one is important, so we must decode (endianess) it's values */
+       if (!read_ICONDIRENTRY (pointer, &entry, useFile, TRUE))
+               goto error;
+       pos += sizeof (ICONDIRENTRY);
 
        while (pos < entry.dwImageOffset) {
                if (gdip_read_ico_data (pointer, p, sizeof (WORD), useFile) != 
sizeof (WORD))

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to