Author: spouliot
Date: 2007-04-04 14:54:47 -0400 (Wed, 04 Apr 2007)
New Revision: 75403

Modified:
   trunk/libgdiplus/src/ChangeLog
   trunk/libgdiplus/src/bmpcodec.c
   trunk/libgdiplus/src/bmpcodec.h
   trunk/libgdiplus/src/emfcodec.c
   trunk/libgdiplus/src/icocodec.c
   trunk/libgdiplus/src/metafile.c
   trunk/libgdiplus/src/metafile.h
   trunk/libgdiplus/src/wmfcodec.c
Log:
2007-04-04  Sebastien Pouliot  <[EMAIL PROTECTED]> 

        * bmpcodec.c|h: Refactor reading to use ImageSource so metafiles can
        reuse the codec to load bitmaps.
        * emfcodec.c: Update reading to ImageSource.
        * icocodec.c: Update reading to ImageSource.
        * metafile.c|h: Implement StretchDIBits for #81178. Update reading to 
        ImageSource.
        * wmfcodec.c: Update reading to ImageSource.



Modified: trunk/libgdiplus/src/ChangeLog
===================================================================
--- trunk/libgdiplus/src/ChangeLog      2007-04-04 18:30:07 UTC (rev 75402)
+++ trunk/libgdiplus/src/ChangeLog      2007-04-04 18:54:47 UTC (rev 75403)
@@ -1,3 +1,13 @@
+2007-04-04  Sebastien Pouliot  <[EMAIL PROTECTED]> 
+
+       * bmpcodec.c|h: Refactor reading to use ImageSource so metafiles can
+       reuse the codec to load bitmaps.
+       * emfcodec.c: Update reading to ImageSource.
+       * icocodec.c: Update reading to ImageSource.
+       * metafile.c|h: Implement StretchDIBits for #81178. Update reading to 
+       ImageSource.
+       * wmfcodec.c: Update reading to ImageSource.
+
 2007-04-04  Sebastien Pouliot  <[EMAIL PROTECTED]>
 
        * image.c: Hack around codec signature detection to add support for 

Modified: trunk/libgdiplus/src/bmpcodec.c
===================================================================
--- trunk/libgdiplus/src/bmpcodec.c     2007-04-04 18:30:07 UTC (rev 75402)
+++ trunk/libgdiplus/src/bmpcodec.c     2007-04-04 18:54:47 UTC (rev 75403)
@@ -24,6 +24,7 @@
  *      Sanjay Gupta ([EMAIL PROTECTED])
  *      Mark Steele ([EMAIL PROTECTED])
  *      Jonathan Gilbert ([EMAIL PROTECTED])
+ *     Sebastien Pouliot  <[EMAIL PROTECTED]>
  *
  * Useful documentation about bitmaps
  *
@@ -45,9 +46,6 @@
 #include "dstream.h"
 
 
-static GpStatus gdip_save_bmp_image_to_file_stream (void *pointer, GpImage 
*image, bool useFile);
-static GpStatus gdip_read_bmp_image_from_file_stream (void *pointer, GpImage 
**image, bool useFile);
-
 /* Codecinfo related data*/
 static ImageCodecInfo bmp_codec;
 static const WCHAR bmp_codecname[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' 
', 'B', 'M', 'P', 0}; /* Built-in BMP */
@@ -167,20 +165,8 @@
 #endif
 }                                                           
 
-GpStatus 
-gdip_load_bmp_image_from_file (FILE *fp, GpImage **image)
-{
-        return gdip_read_bmp_image_from_file_stream ( (void*)fp, image, TRUE);
-}
-
-GpStatus 
-gdip_load_bmp_image_from_stream_delegate (dstream_t *loader, GpImage **image)
-{
-       return gdip_read_bmp_image_from_file_stream ((void *)loader, image, 
FALSE);
-}
-
 static GpStatus
-gdip_read_bmp_rle_8bit (void *pointer, byte *scan0, bool upsidedown, int 
stride, int scanWidth, int scanCount, bool useFile)
+gdip_read_bmp_rle_8bit (void *pointer, byte *scan0, bool upsidedown, int 
stride, int scanWidth, int scanCount, ImageSource source)
 {
        byte code;
        int bytes_read;
@@ -196,13 +182,13 @@
 
        while ((rows_remaining > 0)
            || ((row_offset == 0) && (col_offset < scanWidth))) {
-               bytes_read = gdip_read_bmp_data (pointer, &code, 1, useFile);
+               bytes_read = gdip_read_bmp_data (pointer, &code, 1, source);
 
                if (bytes_read < 1)
                        return GenericError; /* TODO?: Add an "unexpected end 
of file" error code */
 
                if (code == 0) { /* RLE escape code */
-                       bytes_read = gdip_read_bmp_data (pointer, &code, 1, 
useFile);
+                       bytes_read = gdip_read_bmp_data (pointer, &code, 1, 
source);
 
                        if (bytes_read < 1)
                                return GenericError; /* TODO?: Add an 
"unexpected end of file" error code */
@@ -228,8 +214,8 @@
                                {
                                        byte dx, dy;
 
-                                       bytes_read  = gdip_read_bmp_data 
(pointer, &dx, 1, useFile);
-                                       bytes_read += gdip_read_bmp_data 
(pointer, &dy, 1, useFile);
+                                       bytes_read  = gdip_read_bmp_data 
(pointer, &dx, 1, source);
+                                       bytes_read += gdip_read_bmp_data 
(pointer, &dy, 1, source);
 
                                        if (bytes_read < 2)
                                                return GenericError; /* TODO?: 
Add an "unexpected end of file" error code */
@@ -263,7 +249,7 @@
                                                        pointer,
                                                        &scan0[row_offset + 
col_offset],
                                                        bytes_to_read_this_scan,
-                                                       useFile);
+                                                       source);
 
                                                if (bytes_read < 
bytes_to_read_this_scan)
                                                        return GenericError; /* 
TODO?: Add an "unexpected end of file" error code */
@@ -287,7 +273,7 @@
                                        }
 
                                        if (pad_byte_present) {
-                                               bytes_read = 
gdip_read_bmp_data(pointer, &code, 1, useFile);
+                                               bytes_read = 
gdip_read_bmp_data(pointer, &code, 1, source);
 
                                                if (bytes_read < 1)
                                                        return GenericError; /* 
TODO?: Add an "unexpected end of file" error code */
@@ -302,7 +288,7 @@
                        int run_length = code;
                        byte pixel_value;
 
-                       bytes_read = gdip_read_bmp_data(pointer, &pixel_value, 
1, useFile);
+                       bytes_read = gdip_read_bmp_data(pointer, &pixel_value, 
1, source);
 
                        if (bytes_read < 1)
                                return GenericError; /* TODO?: Add an 
"unexpected end of file" error code */
@@ -339,7 +325,7 @@
 }
 
 static GpStatus
-gdip_read_bmp_rle_4bit (void *pointer, byte *scan0, bool upsidedown, int 
stride, int scanWidth, int scanCount, bool useFile)
+gdip_read_bmp_rle_4bit (void *pointer, byte *scan0, bool upsidedown, int 
stride, int scanWidth, int scanCount, ImageSource source)
 {
        byte code;
        int bytes_read;
@@ -357,13 +343,13 @@
                return InvalidParameter;
 
        while (rows_remaining > 0) {
-               bytes_read = gdip_read_bmp_data (pointer, &code, 1, useFile);
+               bytes_read = gdip_read_bmp_data (pointer, &code, 1, source);
 
                if (bytes_read < 1)
                        return GenericError; /* TODO?: Add an "unexpected end 
of file" error code */
 
                if (code == 0) { /* RLE escape code */
-                       bytes_read = gdip_read_bmp_data (pointer, &code, 1, 
useFile);
+                       bytes_read = gdip_read_bmp_data (pointer, &code, 1, 
source);
 
                        if (bytes_read < 1)
                                return GenericError; /* TODO?: Add an 
"unexpected end of file" error code */
@@ -389,8 +375,8 @@
                                {
                                        byte dx, dy;
 
-                                       bytes_read  = gdip_read_bmp_data 
(pointer, &dx, 1, useFile);
-                                       bytes_read += gdip_read_bmp_data 
(pointer, &dy, 1, useFile);
+                                       bytes_read  = gdip_read_bmp_data 
(pointer, &dx, 1, source);
+                                       bytes_read += gdip_read_bmp_data 
(pointer, &dy, 1, source);
 
                                        if (bytes_read < 2)
                                                return GenericError; /* TODO?: 
Add an "unexpected end of file" error code */
@@ -424,7 +410,7 @@
                                                        /* special case: a pair 
of pixels is split across two rows. */
                                                        byte pixels, 
same_row_pixel, next_row_pixel;
 
-                                                       bytes_read = 
gdip_read_bmp_data (pointer, &pixels, 1, useFile);
+                                                       bytes_read = 
gdip_read_bmp_data (pointer, &pixels, 1, source);
 
                                                        if (bytes_read < 1)
                                                                return 
GenericError; /* TODO?: Add an "unexpected end of file" error code */
@@ -467,7 +453,7 @@
                                                                pointer,
                                                                
&scan0[row_offset + col_offset / 2],
                                                                
bytes_to_read_this_scan,
-                                                               useFile);
+                                                               source);
 
                                                        if (bytes_read < 
bytes_to_read_this_scan)
                                                                return 
GenericError; /* TODO?: Add an "unexpected end of file" error code */
@@ -489,7 +475,7 @@
                                                        while 
(bytes_to_read_this_scan >= 0) {
                                                                byte pixels;
 
-                                                               bytes_read = 
gdip_read_bmp_data (pointer, &pixels, 1, useFile);
+                                                               bytes_read = 
gdip_read_bmp_data (pointer, &pixels, 1, source);
 
                                                                if (bytes_read 
< 1)
                                                                        return 
GenericError; /* TODO?: Add an "unexpected end of file" error code */
@@ -521,7 +507,7 @@
                                                /* half of a byte remains to be 
inserted into the correct nybble */
                                                byte pixel;
 
-                                               bytes_read = gdip_read_bmp_data 
(pointer, &pixel, 1, useFile);
+                                               bytes_read = gdip_read_bmp_data 
(pointer, &pixel, 1, source);
 
                                                if (bytes_read < 1)
                                                        return GenericError; /* 
TODO?: Add an "unexpected end of file" error code */
@@ -552,7 +538,7 @@
                                        }
 
                                        if (pad_byte_present) {
-                                               bytes_read = 
gdip_read_bmp_data(pointer, &code, 1, useFile);
+                                               bytes_read = 
gdip_read_bmp_data(pointer, &code, 1, source);
 
                                                if (bytes_read < 1)
                                                        return GenericError; /* 
TODO?: Add an "unexpected end of file" error code */
@@ -575,7 +561,7 @@
                        byte pixel_values;
                        byte inverted_pixel_values;
 
-                       bytes_read = gdip_read_bmp_data(pointer, &pixel_values, 
1, useFile);
+                       bytes_read = gdip_read_bmp_data(pointer, &pixel_values, 
1, source);
 
                        if (bytes_read < 1)
                                return GenericError; /* TODO?: Add an 
"unexpected end of file" error code */
@@ -699,32 +685,32 @@
 }
 
 GpStatus
-gdip_read_BITMAPINFOHEADER (void *pointer, BITMAPINFOHEADER *bmi, bool 
useFile, BOOL *os2format, BOOL *upsidedown)
+gdip_read_BITMAPINFOHEADER (void *pointer, BITMAPINFOHEADER *bmi, ImageSource 
source, BOOL *os2format, BOOL *upsidedown)
 {
        DWORD dw = 0;
        byte *data_read = (byte*)&dw;
        int size = sizeof (DWORD);
-       int size_read = gdip_read_bmp_data (pointer, data_read, size, useFile);
+       int size_read = gdip_read_bmp_data (pointer, data_read, size, source);
        if (size_read < size)
                return InvalidParameter;
 
        bmi->biSize = (data_read[3]<<24 | data_read[2]<<16 | data_read[1]<<8 | 
data_read[0]);
        if (bmi->biSize > BITMAPCOREHEADER_SIZE){   /* New Windows headers can 
be bigger */ 
                dw = 0;
-               size_read = gdip_read_bmp_data (pointer, data_read, size, 
useFile);
+               size_read = gdip_read_bmp_data (pointer, data_read, size, 
source);
                if (size_read < size)
                        return InvalidParameter;
                bmi->biWidth = (data_read[3]<<24 | data_read[2]<<16 | 
data_read[1]<<8 | data_read[0]);
 
                dw = 0;
-               size_read = gdip_read_bmp_data (pointer, data_read, size, 
useFile);
+               size_read = gdip_read_bmp_data (pointer, data_read, size, 
source);
                if (size_read < size)
                        return InvalidParameter;
                bmi->biHeight = (data_read[3]<<24 | data_read[2]<<16 | 
data_read[1]<<8 | data_read[0]);
        } else if (bmi->biSize == BITMAPCOREHEADER_SIZE) {
                /* Old OS/2 format. Width and Height fields are WORDs instead 
of DWORDS */
                dw = 0;
-               size_read = gdip_read_bmp_data (pointer, data_read, size, 
useFile);
+               size_read = gdip_read_bmp_data (pointer, data_read, size, 
source);
                if (size_read < size)
                        return InvalidParameter;
                bmi->biWidth = (data_read[1]<<8 | data_read[0]);
@@ -735,14 +721,14 @@
        }
 
        dw = 0;
-       size_read = gdip_read_bmp_data (pointer, data_read, size, useFile);
+       size_read = gdip_read_bmp_data (pointer, data_read, size, source);
        if (size_read < size)
                return InvalidParameter;
        bmi->biPlanes = (data_read[1]<<8 | data_read[0]); 
        bmi->biBitCount = (data_read[3]<<8 | data_read[2]); 
 
        dw = 0;
-       size_read = gdip_read_bmp_data (pointer, data_read, size, useFile);
+       size_read = gdip_read_bmp_data (pointer, data_read, size, source);
        if (size_read < size)
                return InvalidParameter;
        bmi->biCompression = (data_read[3]<<24 | data_read[2]<<16 | 
data_read[1]<<8 | data_read[0]);
@@ -753,31 +739,31 @@
        }
 
        dw = 0;
-       size_read = gdip_read_bmp_data (pointer, data_read, size, useFile);
+       size_read = gdip_read_bmp_data (pointer, data_read, size, source);
        if (size_read < size)
                return InvalidParameter;
        bmi->biSizeImage = (data_read[3]<<24 | data_read[2]<<16 | 
data_read[1]<<8 | data_read[0]);
                
        dw = 0;
-       size_read = gdip_read_bmp_data (pointer, data_read, size, useFile);
+       size_read = gdip_read_bmp_data (pointer, data_read, size, source);
        if (size_read < size)
                return InvalidParameter;
        bmi->biXPelsPerMeter = (data_read[3]<<24 | data_read[2]<<16 | 
data_read[1]<<8 | data_read[0]);
        
        dw = 0;
-       size_read = gdip_read_bmp_data (pointer, data_read, size, useFile);
+       size_read = gdip_read_bmp_data (pointer, data_read, size, source);
        if (size_read < size)
                return InvalidParameter;
        bmi->biYPelsPerMeter = (data_read[3]<<24 | data_read[2]<<16 | 
data_read[1]<<8 | data_read[0]);
                
        dw = 0;
-       size_read = gdip_read_bmp_data (pointer, data_read, size, useFile);
+       size_read = gdip_read_bmp_data (pointer, data_read, size, source);
        if (size_read < size)
                return InvalidParameter;
        bmi->biClrUsed = (data_read[3]<<24 | data_read[2]<<16 | data_read[1]<<8 
| data_read[0]);
                
        dw = 0;
-       size_read = gdip_read_bmp_data (pointer, data_read, size, useFile);
+       size_read = gdip_read_bmp_data (pointer, data_read, size, source);
        if (size_read < size)
                return InvalidParameter;
        bmi->biClrImportant = (data_read[3]<<24 | data_read[2]<<16 | 
data_read[1]<<8 | data_read[0]);
@@ -785,10 +771,10 @@
        return Ok;
 }
 
+/* For use with in-memory bitmaps, where the BITMAPFILEHEADER doesn't exists */
 GpStatus 
-gdip_read_bmp_image_from_file_stream (void *pointer, GpImage **image, bool 
useFile)
+gdip_read_bmp_image (void *pointer, GpImage **image, ImageSource source)
 {
-       BITMAPFILEHEADER bmfh;
        BITMAPINFOHEADER bmi;
        GpBitmap        *result = NULL;
        guchar          *pixels = NULL;
@@ -799,7 +785,7 @@
        BOOL            upsidedown = TRUE;
        int             size;
        int             size_read;
-       byte            *data_read;
+       byte            *data_read = NULL;
        int             line;
        int             loop;
        long            index;
@@ -809,34 +795,8 @@
        ARGB green_mask = 0;
        ARGB blue_mask = 0;
        int red_shift = 0;
-               
-       size = sizeof(bmfh);
-       data_read = (byte*) GdipAlloc(size);
-       if (data_read == NULL) {
-               status = OutOfMemory;
-               goto error;
-       }
-       memset (data_read, 0, size);
-       size_read = gdip_read_bmp_data (pointer, data_read, size, useFile);
-       if (size_read < size) {
-               status = InvalidParameter;
-               goto error;
-       }
-       
-       bmfh.bfType = ((data_read[1]<<8)|data_read[0]);
-       if (bmfh.bfType != BFT_BITMAP) {
-               status = UnknownImageFormat;
-               goto error;
-       }
 
-       bmfh.bfSize = (data_read[5]<<24 | data_read[4]<<16 | data_read[3]<<8 | 
data_read[2]);
-       bmfh.bfReserved1 = ((data_read[7]<<8)|data_read[6]);
-       bmfh.bfReserved1 = ((data_read[9]<<8)|data_read[8]);
-       bmfh.bfOffBits = (data_read[13]<<24 | data_read[12]<<16 | 
data_read[11]<<8 | data_read[10]);
-       GdipFree (data_read);
-       data_read = NULL;
-
-       status = gdip_read_BITMAPINFOHEADER (pointer, &bmi, useFile, 
&os2format, &upsidedown);
+       status = gdip_read_BITMAPINFOHEADER (pointer, &bmi, source, &os2format, 
&upsidedown);
        if (status != Ok)
                goto error;
 
@@ -863,13 +823,13 @@
                } else if (bmi.biSize == sizeof (BITMAPINFOHEADER)) {
                        // next three DWORD are the R,G,B masks, like bmiColors 
in BITMAPINFO
                        int size = sizeof (RGBQUAD);
-                       size_read = gdip_read_bmp_data (pointer, 
(void*)&red_mask, size, useFile);
+                       size_read = gdip_read_bmp_data (pointer, 
(void*)&red_mask, size, source);
                        if (size_read != size)
                                goto error;
-                       size_read = gdip_read_bmp_data (pointer, 
(void*)&green_mask, size, useFile);
+                       size_read = gdip_read_bmp_data (pointer, 
(void*)&green_mask, size, source);
                        if (size_read != size)
                                goto error;
-                       size_read = gdip_read_bmp_data (pointer, 
(void*)&blue_mask, size, useFile);
+                       size_read = gdip_read_bmp_data (pointer, 
(void*)&blue_mask, size, source);
                        if (size_read != size)
                                goto error;
                }
@@ -953,7 +913,7 @@
                        goto error;
                }
                for (i = 0; i < colours; i++) {
-                       size_read = gdip_read_bmp_data (pointer, data_read, 
size, useFile);
+                       size_read = gdip_read_bmp_data (pointer, data_read, 
size, source);
                        if (size_read < size) {
                                status = InvalidParameter;
                                goto error;
@@ -978,10 +938,10 @@
        if ((bmi.biCompression == BI_RLE4) || (bmi.biCompression == BI_RLE8)) {
                switch (bmi.biCompression) {
                        case BI_RLE4:
-                               gdip_read_bmp_rle_4bit (pointer, pixels, 
upsidedown, result->active_bitmap->stride, result->active_bitmap->width, 
result->active_bitmap->height, useFile);
+                               gdip_read_bmp_rle_4bit (pointer, pixels, 
upsidedown, result->active_bitmap->stride, result->active_bitmap->width, 
result->active_bitmap->height, source);
                                break;
                        case BI_RLE8:
-                               gdip_read_bmp_rle_8bit (pointer, pixels, 
upsidedown, result->active_bitmap->stride, result->active_bitmap->width, 
result->active_bitmap->height, useFile);
+                               gdip_read_bmp_rle_8bit (pointer, pixels, 
upsidedown, result->active_bitmap->stride, result->active_bitmap->width, 
result->active_bitmap->height, source);
                                break;
                }
        } else {
@@ -1027,7 +987,7 @@
                                line = i;
                        }
 
-                       size_read = gdip_read_bmp_data (pointer, data_read, 
size, useFile);
+                       size_read = gdip_read_bmp_data (pointer, data_read, 
size, source);
 
                        if (size_read < size) {
                                /* special case for missing data in the last 
line */
@@ -1125,15 +1085,68 @@
        }
 
        return InvalidParameter;
+}
 
+/* BMP read from files have a BITMAPFILEHEADER but this isn't the case for the 
GDI API
+ * (e.g. displaying a bitmap) */
+GpStatus 
+gdip_read_bmp_image_from_file_stream (void *pointer, GpImage **image, 
ImageSource source)
+{
+       GpStatus status;
+       BITMAPFILEHEADER bmfh;
+       int size_read;
+               
+       int size = sizeof (bmfh);
+       BYTE* data_read = (BYTE*) GdipAlloc (size);
+
+       if (!data_read)
+               return OutOfMemory;
+
+       memset (data_read, 0, size);
+       size_read = gdip_read_bmp_data (pointer, data_read, size, source);
+       if (size_read < size) {
+               status = InvalidParameter;
+               goto error;
+       }
+       
+       bmfh.bfType = ((data_read[1]<<8)|data_read[0]);
+       if (bmfh.bfType != BFT_BITMAP) {
+               status = UnknownImageFormat;
+               goto error;
+       }
+
+       bmfh.bfSize = (data_read[5]<<24 | data_read[4]<<16 | data_read[3]<<8 | 
data_read[2]);
+       bmfh.bfReserved1 = ((data_read[7]<<8)|data_read[6]);
+       bmfh.bfReserved1 = ((data_read[9]<<8)|data_read[8]);
+       bmfh.bfOffBits = (data_read[13]<<24 | data_read[12]<<16 | 
data_read[11]<<8 | data_read[10]);
+       GdipFree (data_read);
+
+       return gdip_read_bmp_image (pointer, image, source);
+error:
+       if (data_read != NULL)
+               GdipFree(data_read);
+       return status;
 }
 
+GpStatus 
+gdip_load_bmp_image_from_file (FILE *fp, GpImage **image)
+{
+        return gdip_read_bmp_image_from_file_stream ((void*)fp, image, File);
+}
+
+GpStatus 
+gdip_load_bmp_image_from_stream_delegate (dstream_t *loader, GpImage **image)
+{
+       return gdip_read_bmp_image_from_file_stream ((void*)loader, image, 
DStream);
+}
+
 int 
-gdip_read_bmp_data (void *pointer, byte *data, int size, bool useFile)
+gdip_read_bmp_data (void *pointer, byte *data, int size, ImageSource source)
 {
-       if (useFile) {
+       switch (source) {
+       case File:
                return fread (data, 1, size, (FILE*) pointer);
-       } else {
+       case DStream: {
                /* Streams are not required to return the number of bytes
                   requested, they could return less yet our code seems to 
assume
                   it will always get what it's asking for; lets loop until we
@@ -1155,6 +1168,18 @@
 
                return total;
        }
+       case Memory: {
+               MemorySource *ms = (MemorySource*)pointer;
+               int len = (ms->pos + size < ms->size) ? size : ms->size - 
ms->pos;
+               if (len > 0) {
+                       memcpy (data, ms->ptr + ms->pos, len);
+                       ms->pos += len;
+               }
+               return size;
+       }
+       default:
+               return -1;
+       }
 }
 
 static void 
@@ -1167,19 +1192,6 @@
 }
 
 GpStatus 
-gdip_save_bmp_image_to_file (FILE *fp, GpImage *image)
-{
-       return gdip_save_bmp_image_to_file_stream ( (void *)fp, image, TRUE);
-}
-
-GpStatus 
-gdip_save_bmp_image_to_stream_delegate (PutBytesDelegate putBytesFunc,
-                                        GpImage *image)
-{      
-        return gdip_save_bmp_image_to_file_stream ( (void *)putBytesFunc, 
image, FALSE);
-}
-
-GpStatus 
 gdip_save_bmp_image_to_file_stream (void *pointer, GpImage *image, bool 
useFile)
 {
        BITMAPFILEHEADER        bmfh;
@@ -1314,3 +1326,16 @@
 
        return Ok;
 }
+
+GpStatus 
+gdip_save_bmp_image_to_file (FILE *fp, GpImage *image)
+{
+       return gdip_save_bmp_image_to_file_stream ( (void *)fp, image, TRUE);
+}
+
+GpStatus 
+gdip_save_bmp_image_to_stream_delegate (PutBytesDelegate putBytesFunc,
+                                        GpImage *image)
+{      
+        return gdip_save_bmp_image_to_file_stream ( (void *)putBytesFunc, 
image, FALSE);
+}

Modified: trunk/libgdiplus/src/bmpcodec.h
===================================================================
--- trunk/libgdiplus/src/bmpcodec.h     2007-04-04 18:30:07 UTC (rev 75402)
+++ trunk/libgdiplus/src/bmpcodec.h     2007-04-04 18:54:47 UTC (rev 75403)
@@ -105,6 +105,19 @@
        RGBQUAD bmiColors[1];
 } BITMAPINFO, *PBITMAPINFO, *LPBITMAPINFO;
 
+typedef enum {
+       File,
+       DStream,
+       Memory
+} ImageSource;
+
+typedef struct {
+       BYTE* ptr;
+       int size;
+       int pos;
+} MemorySource;
+
+GpStatus gdip_read_bmp_image (void *pointer, GpImage **image, ImageSource 
source) GDIP_INTERNAL;
 GpStatus gdip_load_bmp_image_from_file (FILE *fp, GpImage **image) 
GDIP_INTERNAL;
 GpStatus gdip_load_bmp_image_from_stream_delegate (dstream_t *loader, GpImage 
**image) GDIP_INTERNAL;
 
@@ -114,7 +127,8 @@
 ImageCodecInfo *gdip_getcodecinfo_bmp () GDIP_INTERNAL;
 
 /* helper functions / shared with ICOn codec */
-GpStatus gdip_read_BITMAPINFOHEADER (void *pointer, BITMAPINFOHEADER *bmi, 
bool useFile, BOOL *os2format, BOOL *upsidedown) GDIP_INTERNAL;
-int gdip_read_bmp_data (void *pointer, byte *data, int size, bool useFile) 
GDIP_INTERNAL;
+GpStatus gdip_read_BITMAPINFOHEADER (void *pointer, BITMAPINFOHEADER *bmi, 
ImageSource source, BOOL *os2format, 
+       BOOL *upsidedown) GDIP_INTERNAL;
+int gdip_read_bmp_data (void *pointer, byte *data, int size, ImageSource 
source) GDIP_INTERNAL;
 
 #endif /* _BMPCODEC_H */

Modified: trunk/libgdiplus/src/emfcodec.c
===================================================================
--- trunk/libgdiplus/src/emfcodec.c     2007-04-04 18:30:07 UTC (rev 75402)
+++ trunk/libgdiplus/src/emfcodec.c     2007-04-04 18:54:47 UTC (rev 75403)
@@ -597,11 +597,11 @@
 GpStatus 
 gdip_load_emf_image_from_file (FILE *fp, GpImage **image)
 {
-       return gdip_get_metafile_from ((void*)fp, (GpMetafile**)image, TRUE);
+       return gdip_get_metafile_from ((void*)fp, (GpMetafile**)image, File);
 }
 
 GpStatus 
 gdip_load_emf_image_from_stream_delegate (dstream_t *loader, GpImage **image)
 {
-       return gdip_get_metafile_from ((void *)loader, (GpMetafile**)image, 
FALSE);
+       return gdip_get_metafile_from ((void *)loader, (GpMetafile**)image, 
DStream);
 }

Modified: trunk/libgdiplus/src/icocodec.c
===================================================================
--- trunk/libgdiplus/src/icocodec.c     2007-04-04 18:30:07 UTC (rev 75402)
+++ trunk/libgdiplus/src/icocodec.c     2007-04-04 18:54:47 UTC (rev 75403)
@@ -76,9 +76,9 @@
 }
 
 static BOOL
-read_ICONDIRENTRY (void *pointer, ICONDIRENTRY *entry, BOOL useFile, BOOL 
decode)
+read_ICONDIRENTRY (void *pointer, ICONDIRENTRY *entry, ImageSource source, 
BOOL decode)
 {
-       if (gdip_read_ico_data (pointer, (void*)entry, sizeof (ICONDIRENTRY), 
useFile) != sizeof (ICONDIRENTRY))
+       if (gdip_read_ico_data (pointer, (void*)entry, sizeof (ICONDIRENTRY), 
source) != sizeof (ICONDIRENTRY))
                return FALSE;
 #if WORDS_BIGENDIAN
        if (decode) {
@@ -98,7 +98,7 @@
 }
 
 static GpStatus
-gdip_read_ico_image_from_file_stream (void *pointer, GpImage **image, bool 
useFile)
+gdip_read_ico_image_from_file_stream (void *pointer, GpImage **image, 
ImageSource source)
 {
        GpStatus status = InvalidParameter;
        GpBitmap *result = NULL;
@@ -119,20 +119,20 @@
        BYTE *xor_data = NULL, *and_data = NULL;
 
        /* WORD ICONDIR.idReserved / reversed, MUST be 0 */
-       if (gdip_read_ico_data (pointer, p, sizeof (WORD), useFile) != sizeof 
(WORD))
+       if (gdip_read_ico_data (pointer, p, sizeof (WORD), source) != sizeof 
(WORD))
                goto error;
        if (w != 0)
                goto error;
 
        /* WORD ICONDIR.idType / resource type, MUST be 1 for icons */
-       if (gdip_read_ico_data (pointer, p, sizeof (WORD), useFile) != sizeof 
(WORD))
+       if (gdip_read_ico_data (pointer, p, sizeof (WORD), source) != sizeof 
(WORD))
                goto error;
        i = (b[1] << 8 | b[0]);
        if (i != 1)
                goto error;
 
        /* WORD ICONDIR.idCount / number of icons, must be greater than 0 */
-       if (gdip_read_ico_data (pointer, p, sizeof (WORD), useFile) != sizeof 
(WORD))
+       if (gdip_read_ico_data (pointer, p, sizeof (WORD), source) != sizeof 
(WORD))
                goto error;
        count = (b[1] << 8 | b[0]); 
        if (count < 1)
@@ -144,23 +144,23 @@
         * (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 - 1; i++) {
-               if (!read_ICONDIRENTRY (pointer, &entry, useFile, FALSE))
+               if (!read_ICONDIRENTRY (pointer, &entry, source, 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))
+       if (!read_ICONDIRENTRY (pointer, &entry, source, TRUE))
                goto error;
        pos += sizeof (ICONDIRENTRY);
 
        while (pos < entry.dwImageOffset) {
-               if (gdip_read_ico_data (pointer, p, sizeof (WORD), useFile) != 
sizeof (WORD))
+               if (gdip_read_ico_data (pointer, p, sizeof (WORD), source) != 
sizeof (WORD))
                        goto error;
                pos += sizeof (WORD);
        }
 
        /* BITMAPINFOHEADER */
-       status = gdip_read_BITMAPINFOHEADER (pointer, &bih, useFile, 
&os2format, &upsidedown);
+       status = gdip_read_BITMAPINFOHEADER (pointer, &bih, source, &os2format, 
&upsidedown);
        if (status != Ok)
                goto error;
        
@@ -217,7 +217,7 @@
                BYTE color[4]; 
                void *p = &color;
 
-               if (gdip_read_ico_data (pointer, p, 4, useFile) < 4) {
+               if (gdip_read_ico_data (pointer, p, 4, source) < 4) {
                        status = InvalidParameter;
                        goto error;
                }
@@ -253,7 +253,7 @@
                status = OutOfMemory;
                goto error;
        }
-       if (gdip_read_ico_data (pointer, xor_data, xor_size, useFile) < 
xor_size) {
+       if (gdip_read_ico_data (pointer, xor_data, xor_size, source) < 
xor_size) {
                status = InvalidParameter;
                goto error;
        }
@@ -265,7 +265,7 @@
                status = OutOfMemory;
                goto error;
        }
-       if (gdip_read_ico_data (pointer, and_data, and_size, useFile) < 
and_size) {
+       if (gdip_read_ico_data (pointer, and_data, and_size, source) < 
and_size) {
                status = InvalidParameter;
                goto error;
        }
@@ -315,11 +315,11 @@
 GpStatus 
 gdip_load_ico_image_from_file (FILE *fp, GpImage **image)
 {
-       return gdip_read_ico_image_from_file_stream ((void*)fp, image, TRUE);
+       return gdip_read_ico_image_from_file_stream ((void*)fp, image, File);
 }
 
 GpStatus 
 gdip_load_ico_image_from_stream_delegate (dstream_t *loader, GpImage **image)
 {
-       return gdip_read_ico_image_from_file_stream ((void *)loader, image, 
FALSE);
+       return gdip_read_ico_image_from_file_stream ((void *)loader, image, 
DStream);
 }

Modified: trunk/libgdiplus/src/metafile.c
===================================================================
--- trunk/libgdiplus/src/metafile.c     2007-04-04 18:30:07 UTC (rev 75402)
+++ trunk/libgdiplus/src/metafile.c     2007-04-04 18:54:47 UTC (rev 75403)
@@ -568,13 +568,16 @@
                (right - left), (bottom - top), atan2 (ystart, xstart), atan2 
(yend, xend));
 }
 
+
 /* http://wvware.sourceforge.net/caolan/ora-wmf.html */
 GpStatus
 gdip_metafile_StretchDIBits (MetafilePlayContext *context, int XDest, int 
YDest, int nDestWidth, int nDestHeight, 
        int XSrc, int YSrc, int nSrcWidth, int nSrcHeight, CONST void *lpBits, 
CONST BITMAPINFO *lpBitsInfo, 
        UINT iUsage, DWORD dwRop)
 {
-       GpStatus status;
+       GpStatus status = OutOfMemory;
+       GpImage *image = NULL;
+       MemorySource ms;
 #ifdef DEBUG_METAFILE
        printf ("StretchDIBits\n\t[XDest %d, YDest %d, nDestWidth %d, 
nDestHeight %d]", XDest, YDest, nDestWidth, nDestHeight);
        printf ("\n\t[XSrc %d, YSrc %d, nSrcWidth %d, nSrcHeight %d]", XSrc, 
YSrc, nSrcWidth, nSrcHeight);
@@ -591,14 +594,15 @@
        printf ("\n\t\tClrUsed: %d", lpBitsInfo->bmiHeader.biClrUsed);
        printf ("\n\t\tClrImportant: %d", lpBitsInfo->bmiHeader.biClrImportant);
 #endif
-       /* temporary hack to adjust size */
-       GpPen *pen = NULL;
-       status = GdipCreatePen1 (0xFF000000, 0, UnitPixel, &pen);
+       ms.ptr = (unsigned char*)lpBitsInfo;
+       ms.size = lpBitsInfo->bmiHeader.biSizeImage;
+       ms.pos = 0;
+       status = gdip_read_bmp_image (&ms, &image, Memory);
        if (status == Ok) {
-               status = GdipDrawRectangle (context->graphics, pen, XDest, 
YDest, nDestWidth, nDestHeight);
+               status = GdipDrawImageRect (context->graphics, image, 
context->x + XDest, context->y + YDest, nDestWidth, nDestHeight);
        }
-       if (pen)
-               GdipDeletePen (pen);
+       if (image)
+               GdipDisposeImage (image);
        return status;
 }
 
@@ -1180,7 +1184,7 @@
 }
 
 static GpStatus 
-gdip_get_metafileheader_from (void *pointer, MetafileHeader *header, BOOL 
useFile)
+gdip_get_metafileheader_from (void *pointer, MetafileHeader *header, 
ImageSource source)
 {
        int size;
        DWORD key;
@@ -1190,7 +1194,7 @@
 
        /* peek at first DWORD to select the right format */
        size = sizeof (DWORD);
-       if (gdip_read_wmf_data (pointer, (void*)&key, size, useFile) != size)
+       if (gdip_read_wmf_data (pointer, (void*)&key, size, source) != size)
                return GenericError;
 
 #if G_BYTE_ORDER != G_LITTLE_ENDIAN
@@ -1200,7 +1204,7 @@
        case ALDUS_PLACEABLE_METAFILE_KEY:
                aldus_header.Key = key;
                size = sizeof (WmfPlaceableFileHeader) - size;
-               if (gdip_read_wmf_data (pointer, (void*)(&aldus_header) + 
sizeof (DWORD), size, useFile) != size)
+               if (gdip_read_wmf_data (pointer, (void*)(&aldus_header) + 
sizeof (DWORD), size, source) != size)
                        return InvalidParameter;
 #if FALSE
 g_warning ("ALDUS_PLACEABLE_METAFILE key %d, hmf %d, L %d, T %d, R %d, B %d, 
inch %d, reserved %d, checksum %d", 
@@ -1209,7 +1213,7 @@
        aldus_header.Checksum);
 #endif
                size = sizeof (METAHEADER);
-               if (gdip_read_wmf_data (pointer, (void*)&header->WmfHeader, 
size, useFile) != size)
+               if (gdip_read_wmf_data (pointer, (void*)&header->WmfHeader, 
size, source) != size)
                        return InvalidParameter;
 
                WmfPlaceableFileHeaderLE (&aldus_header);
@@ -1220,7 +1224,7 @@
                memcpy (&header->WmfHeader, &key, size);
 
                size = sizeof (METAHEADER) - size;
-               if (gdip_read_wmf_data (pointer, (void*)(&header->WmfHeader) + 
sizeof (DWORD), size, useFile) != size)
+               if (gdip_read_wmf_data (pointer, (void*)(&header->WmfHeader) + 
sizeof (DWORD), size, source) != size)
                        return InvalidParameter;
 
                MetafileHeaderLE (header);
@@ -1230,7 +1234,7 @@
                emf = &(header->EmfHeader);
                emf->iType = key;
                size = sizeof (ENHMETAHEADER3) - size;
-               if (gdip_read_emf_data (pointer, (void*)(&header->EmfHeader) + 
sizeof (DWORD), size, useFile) != size)
+               if (gdip_read_emf_data (pointer, (void*)(&header->EmfHeader) + 
sizeof (DWORD), size, source) != size)
                        return InvalidParameter;
                EnhMetaHeaderLE (&header->EmfHeader);
 #if FALSE
@@ -1275,12 +1279,12 @@
                size = emf->nSize - sizeof (ENHMETAHEADER3);
                if (size > 0) {
                        while (size > sizeof (DWORD)) {
-                               if (gdip_read_emf_data (pointer, (void*)(&key), 
sizeof (DWORD), useFile) != sizeof (DWORD))
+                               if (gdip_read_emf_data (pointer, (void*)(&key), 
sizeof (DWORD), source) != sizeof (DWORD))
                                        return InvalidParameter;
                                size -= sizeof (DWORD);
                        }
                        if (size > 0) {
-                               if (gdip_read_emf_data (pointer, (void*)(&key), 
size, useFile) != size)
+                               if (gdip_read_emf_data (pointer, (void*)(&key), 
size, source) != size)
                                        return InvalidParameter;
                        }
                }
@@ -1301,7 +1305,7 @@
 }
 
 GpStatus 
-gdip_get_metafile_from (void *pointer, GpMetafile **metafile, BOOL useFile)
+gdip_get_metafile_from (void *pointer, GpMetafile **metafile, ImageSource 
source)
 {
        BOOL adjust_emf_headers = FALSE;
        GpStatus status = OutOfMemory;
@@ -1310,7 +1314,7 @@
                goto error;
 
        /* decode metafile header */
-       status = gdip_get_metafileheader_from (pointer, &mf->metafile_header, 
useFile);
+       status = gdip_get_metafileheader_from (pointer, &mf->metafile_header, 
source);
        if (status != Ok)
                goto error;
 
@@ -1334,7 +1338,7 @@
        if (!mf->data)
                goto error;
        /* copy data in memory (to play it later) */
-       if (gdip_read_wmf_data (pointer, (void*)mf->data, mf->length, useFile) 
!= mf->length) {
+       if (gdip_read_wmf_data (pointer, (void*)mf->data, mf->length, source) 
!= mf->length) {
                status = InvalidParameter;
                goto error;
        }
@@ -1371,7 +1375,7 @@
        
        fp = fopen (file_name, "rb");
        if (fp) {
-               status = gdip_get_metafile_from (fp, metafile, TRUE);
+               status = gdip_get_metafile_from (fp, metafile, File);
                fclose (fp);
        }
        GdipFree (file_name);
@@ -1401,7 +1405,7 @@
 
        loader = dstream_input_new (getBytesFunc, seekFunc);
        if (loader) {
-               status = gdip_get_metafile_from (loader, metafile, FALSE);
+               status = gdip_get_metafile_from (loader, metafile, DStream);
                dstream_free (loader);
        }
        return status;
@@ -1495,7 +1499,7 @@
        
        fp = fopen (file_name, "rb");
        if (fp) {
-               status = gdip_get_metafileheader_from (fp, header, TRUE);
+               status = gdip_get_metafileheader_from (fp, header, File);
                /* if EMF check for additional header record */
                if (header->Type == METAFILETYPE_EMF) {
                        /* look for more details, possibly upgrading the 
metafile to METAFILETYPE_EMFPLUSONLY or EMFPLUSDUAL */
@@ -1531,7 +1535,7 @@
 
        loader = dstream_input_new (getBytesFunc, seekFunc);
        if (loader) {
-               status = gdip_get_metafileheader_from (loader, header, FALSE);
+               status = gdip_get_metafileheader_from (loader, header, DStream);
                /* if EMF check for additional header record */
                if (header->Type == METAFILETYPE_EMF) {
                        /* look for more details, possibly upgrading the 
metafile to METAFILETYPE_EMFPLUSONLY or EMFPLUSDUAL */

Modified: trunk/libgdiplus/src/metafile.h
===================================================================
--- trunk/libgdiplus/src/metafile.h     2007-04-04 18:30:07 UTC (rev 75402)
+++ trunk/libgdiplus/src/metafile.h     2007-04-04 18:54:47 UTC (rev 75403)
@@ -334,7 +334,7 @@
 
 #define gdip_get_metaheader(image)     (&((GpMetafile*)image)->metafile_header)
 
-GpStatus gdip_get_metafile_from (void *pointer, GpMetafile **metafile, bool 
useFile) GDIP_INTERNAL;
+GpStatus gdip_get_metafile_from (void *pointer, GpMetafile **metafile, 
ImageSource source) GDIP_INTERNAL;
 GpStatus gdip_metafile_clone (GpMetafile *metafile, GpMetafile 
**clonedmetafile) GDIP_INTERNAL;
 GpStatus gdip_metafile_dispose (GpMetafile *metafile) GDIP_INTERNAL;
 

Modified: trunk/libgdiplus/src/wmfcodec.c
===================================================================
--- trunk/libgdiplus/src/wmfcodec.c     2007-04-04 18:30:07 UTC (rev 75402)
+++ trunk/libgdiplus/src/wmfcodec.c     2007-04-04 18:54:47 UTC (rev 75403)
@@ -367,11 +367,11 @@
 GpStatus 
 gdip_load_wmf_image_from_file (FILE *fp, GpImage **image)
 {
-       return gdip_get_metafile_from ((void*)fp, (GpMetafile**)image, TRUE);
+       return gdip_get_metafile_from ((void*)fp, (GpMetafile**)image, File);
 }
 
 GpStatus 
 gdip_load_wmf_image_from_stream_delegate (dstream_t *loader, GpImage **image)
 {
-       return gdip_get_metafile_from ((void *)loader, (GpMetafile**)image, 
FALSE);
+       return gdip_get_metafile_from ((void *)loader, (GpMetafile**)image, 
DStream);
 }

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

Reply via email to