Author: gonzalo
Date: 2006-04-03 18:41:34 -0400 (Mon, 03 Apr 2006)
New Revision: 58983
Modified:
trunk/libgdiplus/src/ChangeLog
trunk/libgdiplus/src/bmpcodec.c
Log:
2006-04-03 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
* bmpcodec.c: fix offset when saving to a file and speed up writing
the palette (15% faster saving).
Modified: trunk/libgdiplus/src/ChangeLog
===================================================================
--- trunk/libgdiplus/src/ChangeLog 2006-04-03 22:27:06 UTC (rev 58982)
+++ trunk/libgdiplus/src/ChangeLog 2006-04-03 22:41:34 UTC (rev 58983)
@@ -1,3 +1,8 @@
+2006-04-03 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
+
+ * bmpcodec.c: fix offset when saving to a file and speed up writing
+ the palette (15% faster saving).
+
2006-03-31 Peter Dennis Bartok <[EMAIL PROTECTED]>
* graphics.c:
Modified: trunk/libgdiplus/src/bmpcodec.c
===================================================================
--- trunk/libgdiplus/src/bmpcodec.c 2006-04-03 22:27:06 UTC (rev 58982)
+++ trunk/libgdiplus/src/bmpcodec.c 2006-04-03 22:41:34 UTC (rev 58983)
@@ -155,10 +155,13 @@
BITMAPINFOHEADER bmi;
int bitmapLen = bitmap->data.Stride * bitmap->data.Height;
FILE *fp;
+ int ncolors = 0;
bmfh.bfReserved1 = bmfh.bfReserved2 = 0;
bmfh.bfType = BFT_BITMAP;
- bmfh.bfOffBits = (14 + 40 + 0 * 4);
+ if (bitmap->image.palette)
+ ncolors = bitmap->image.palette->Count;
+ bmfh.bfOffBits = (14 + 40 + ncolors * 4);
bmfh.bfSize = (bmfh.bfOffBits + bitmapLen);
fp = fopen (name, "w+b");
fwrite (&bmfh, sizeof (bmfh), 1, fp);
@@ -169,29 +172,30 @@
if (gdip_is_an_indexed_pixelformat (bitmap->data.PixelFormat)) {
int i;
+ char *entries;
int palette_entries = bitmap->image.palette->Count;
if (bitmap->data.PixelFormat == Format4bppIndexed)
palette_entries = 16;
- for (i=0; i < palette_entries; i++)
- {
- unsigned char entry[4];
-
+ entries = (char *) GdipAlloc (palette_entries * 4);
+ for (i = 0; i < palette_entries; i++) {
+ /* Pixel format: 0xAARRGGBB */
+ int idx;
unsigned int packed = bitmap->image.palette->Entries[i];
-
- /* Pixel format: 0xAARRGGBB
- * Therefore, it can be split numerically :-)
- * Output always expects little-endian pixels.
- */
-
- entry[0] = ( packed & 0xFF); /* B */
- entry[1] = ((packed >> 8) & 0xFF); /* G */
- entry[2] = ((packed >> 16) & 0xFF); /* R */
- entry[3] = ((packed >> 24) & 0xFF); /* Alpha */
-
- fwrite(entry, 4, 1, fp);
+ idx = i * 4;
+#ifdef WORDS_BIGENDIAN
+ entries [idx] = ( packed & 0xFF); /* B */
+ entries [idx + 1] = ((packed >> 8) & 0xFF); /* G */
+ entries [idx + 2] = ((packed >> 16) & 0xFF); /* R */
+ entries [idx + 3] = ((packed >> 24) & 0xFF); /* Alpha */
+#else
+ *((guint32 *) entries + idx) = packed;
+#endif
}
+ fwrite (entries, 4, palette_entries, fp);
+ GdipFree (entries);
+ entries = NULL;
}
fwrite (bitmap->data.Scan0, bitmapLen, 1, fp);
@@ -1130,7 +1134,6 @@
GpBitmap *bitmap = (GpBitmap *) image;
int bitmapLen = bitmap->data.Stride * bitmap->data.Height;
int i;
- byte b;
ARGB color;
int colours = 0;
@@ -1154,23 +1157,29 @@
gdip_write_bmp_data (pointer, (byte *)&bmi, sizeof (bmi), useFile);
if (colours) {
+ unsigned char *entries;
int palette_entries = bitmap->image.palette->Count;
if (bitmap->data.PixelFormat == Format4bppIndexed)
palette_entries = 16;
- /* Write palette on disk on BGRA*/
+ entries = (unsigned char *) GdipAlloc (palette_entries * 4);
for (i = 0; i < palette_entries; i++) {
+ int idx;
+
color = bitmap->image.palette->Entries[i];
-
- b = color & 0xff;
- gdip_write_bmp_data (pointer, &b, 1, useFile);
- b = (color >> 8) & 0xff;
- gdip_write_bmp_data (pointer, &b, 1, useFile);
- b = (color >> 16) & 0xff;
- gdip_write_bmp_data (pointer, &b, 1, useFile);
- b = color >> 24;
- gdip_write_bmp_data (pointer, &b, 1, useFile);
- }
+ idx = i * 4;
+#ifdef WORDS_BIGENDIAN
+ entries [idx] = color & 0xff;
+ entries [idx + 1] = (color >> 8) & 0xff;
+ entries [idx + 2] = (color >> 16) & 0xff;
+ entries [idx + 3] = color >> 24;
+#else
+ *((guint32 *) entries + idx) = color;
+#endif
+ }
+ gdip_write_bmp_data (pointer, entries, palette_entries * 4,
useFile);
+ GdipFree (entries);
+ entries = NULL;
}
/* Writes bitmap upside down. Many tools can only process bmp stored
this way*/
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches