[gimp] plug-ins: more code cleanup in file-bmp
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] plug-ins: more code cleanup in file-bmp
- Date: Fri, 22 Apr 2016 23:08:22 +0000 (UTC)
commit 785c104c69d09f24771a6893fee32a6076fb8ea1
Author: Michael Natterer <mitch gimp org>
Date: Sat Apr 23 01:07:20 2016 +0200
plug-ins: more code cleanup in file-bmp
Use GLib endian macros in bmp-save.c
plug-ins/file-bmp/bmp-load.c | 245 ++++++++++++++++++++++++------------------
plug-ins/file-bmp/bmp-save.c | 200 +++++++++++++++++-----------------
plug-ins/file-bmp/bmp.h | 42 ++++----
3 files changed, 260 insertions(+), 227 deletions(-)
---
diff --git a/plug-ins/file-bmp/bmp-load.c b/plug-ins/file-bmp/bmp-load.c
index 8950d1a..723bf86 100644
--- a/plug-ins/file-bmp/bmp-load.c
+++ b/plug-ins/file-bmp/bmp-load.c
@@ -44,72 +44,71 @@
#endif
-static gint32 ReadImage (FILE *fd,
- const gchar *filename,
- gint width,
- gint height,
- guchar cmap[256][3],
- gint ncols,
- gint bpp,
- gint compression,
- gint rowbytes,
- gboolean gray,
- const Bitmap_Channel *masks,
- GError **error);
-
-
-static Bitmap_File_Head bitmap_file_head;
-static Bitmap_Head bitmap_head;
+static gint32 ReadImage (FILE *fd,
+ const gchar *filename,
+ gint width,
+ gint height,
+ guchar cmap[256][3],
+ gint ncols,
+ gint bpp,
+ gint compression,
+ gint rowbytes,
+ gboolean gray,
+ const BitmapChannel *masks,
+ GError **error);
static void
-setMasksDefault (gushort biBitCnt,
- Bitmap_Channel *masks)
+setMasksDefault (gushort biBitCnt,
+ BitmapChannel *masks)
{
switch (biBitCnt)
{
case 32:
- masks[0].mask = 0x00ff0000;
- masks[0].shiftin = 16;
- masks[0].max_value= (gfloat)255.0;
- masks[1].mask = 0x0000ff00;
- masks[1].shiftin = 8;
- masks[1].max_value= (gfloat)255.0;
- masks[2].mask = 0x000000ff;
- masks[2].shiftin = 0;
- masks[2].max_value= (gfloat)255.0;
- masks[3].mask = 0x00000000;
- masks[3].shiftin = 0;
- masks[3].max_value= (gfloat)0.0;
+ masks[0].mask = 0x00ff0000;
+ masks[0].shiftin = 16;
+ masks[0].max_value = (gfloat)255.0;
+ masks[1].mask = 0x0000ff00;
+ masks[1].shiftin = 8;
+ masks[1].max_value = (gfloat)255.0;
+ masks[2].mask = 0x000000ff;
+ masks[2].shiftin = 0;
+ masks[2].max_value = (gfloat)255.0;
+ masks[3].mask = 0x00000000;
+ masks[3].shiftin = 0;
+ masks[3].max_value = (gfloat)0.0;
break;
+
case 24:
- masks[0].mask = 0xff0000;
- masks[0].shiftin = 16;
- masks[0].max_value= (gfloat)255.0;
- masks[1].mask = 0x00ff00;
- masks[1].shiftin = 8;
- masks[1].max_value= (gfloat)255.0;
- masks[2].mask = 0x0000ff;
- masks[2].shiftin = 0;
- masks[2].max_value= (gfloat)255.0;
- masks[3].mask = 0x0;
- masks[3].shiftin = 0;
- masks[3].max_value= (gfloat)0.0;
+ masks[0].mask = 0xff0000;
+ masks[0].shiftin = 16;
+ masks[0].max_value = (gfloat)255.0;
+ masks[1].mask = 0x00ff00;
+ masks[1].shiftin = 8;
+ masks[1].max_value = (gfloat)255.0;
+ masks[2].mask = 0x0000ff;
+ masks[2].shiftin = 0;
+ masks[2].max_value = (gfloat)255.0;
+ masks[3].mask = 0x0;
+ masks[3].shiftin = 0;
+ masks[3].max_value = (gfloat)0.0;
break;
+
case 16:
- masks[0].mask = 0x7c00;
- masks[0].shiftin = 10;
- masks[0].max_value= (gfloat)31.0;
- masks[1].mask = 0x03e0;
- masks[1].shiftin = 5;
- masks[1].max_value= (gfloat)31.0;
- masks[2].mask = 0x001f;
- masks[2].shiftin = 0;
- masks[2].max_value= (gfloat)31.0;
- masks[3].mask = 0x0;
- masks[3].shiftin = 0;
- masks[3].max_value= (gfloat)0.0;
+ masks[0].mask = 0x7c00;
+ masks[0].shiftin = 10;
+ masks[0].max_value = (gfloat)31.0;
+ masks[1].mask = 0x03e0;
+ masks[1].shiftin = 5;
+ masks[1].max_value = (gfloat)31.0;
+ masks[2].mask = 0x001f;
+ masks[2].shiftin = 0;
+ masks[2].max_value = (gfloat)31.0;
+ masks[3].mask = 0x0;
+ masks[3].shiftin = 0;
+ masks[3].max_value = (gfloat)0.0;
break;
+
default:
break;
}
@@ -134,13 +133,14 @@ ReadColorMap (FILE *fd,
gint size,
gboolean *gray)
{
- gint i;
- guchar rgb[4];
+ gint i;
*gray = (number > 2);
for (i = 0; i < number ; i++)
{
+ guchar rgb[4];
+
if (! ReadOK (fd, rgb, size))
{
g_message (_("Bad colormap"));
@@ -152,26 +152,30 @@ ReadColorMap (FILE *fd,
buffer[i][0] = rgb[2];
buffer[i][1] = rgb[1];
buffer[i][2] = rgb[0];
- *gray = ((*gray) && (rgb[0]==rgb[1]) && (rgb[1]==rgb[2]));
+
+ *gray = ((*gray) && (rgb[0] == rgb[1]) && (rgb[1] == rgb[2]));
}
return TRUE;
}
static gboolean
-ReadChannelMasks (guint32 *tmp,
- Bitmap_Channel *masks,
- guint channels)
+ReadChannelMasks (guint32 *tmp,
+ BitmapChannel *masks,
+ guint channels)
{
- guint32 mask;
- gint i, nbits, offset, bit;
+ gint i;
for (i = 0; i < channels; i++)
{
+ guint32 mask;
+ gint nbits, offset, bit;
+
mask = tmp[i];
masks[i].mask = mask;
nbits = 0;
offset = -1;
+
for (bit = 0; bit < 32; bit++)
{
if (mask & 1)
@@ -180,10 +184,12 @@ ReadChannelMasks (guint32 *tmp,
if (offset == -1)
offset = bit;
}
+
mask = mask >> 1;
}
- masks[i].shiftin = offset;
- masks[i].max_value = (gfloat)((1<<(nbits))-1);
+
+ masks[i].shiftin = offset;
+ masks[i].max_value = (gfloat) ((1 << nbits) - 1);
#ifdef DEBUG
g_print ("Channel %d mask %08x in %d max_val %d\n",
@@ -198,14 +204,16 @@ gint32
load_image (const gchar *filename,
GError **error)
{
- FILE *fd;
- guchar buffer[124];
- gint ColormapSize, rowbytes, Maps;
- gboolean gray = FALSE;
- guchar ColorMap[256][3];
- gint32 image_ID = -1;
- gchar magick[2];
- Bitmap_Channel masks[4];
+ FILE *fd;
+ BitmapFileHead bitmap_file_head;
+ BitmapHead bitmap_head;
+ guchar buffer[124];
+ gint ColormapSize, rowbytes, Maps;
+ gboolean gray = FALSE;
+ guchar ColorMap[256][3];
+ gint32 image_ID = -1;
+ gchar magick[2];
+ BitmapChannel masks[4];
gimp_progress_init_printf (_("Opening '%s'"),
gimp_filename_to_utf8 (filename));
@@ -351,9 +359,9 @@ load_image (const gchar *filename,
goto out;
}
- bitmap_head.masks[0] = ToL(&buffer[0x00]);
- bitmap_head.masks[1] = ToL(&buffer[0x04]);
- bitmap_head.masks[2] = ToL(&buffer[0x08]);
+ bitmap_head.masks[0] = ToL (&buffer[0x00]);
+ bitmap_head.masks[1] = ToL (&buffer[0x04]);
+ bitmap_head.masks[2] = ToL (&buffer[0x08]);
ReadChannelMasks (&bitmap_head.masks[0], masks, 3);
}
@@ -370,7 +378,7 @@ load_image (const gchar *filename,
{
/* BI_ALPHABITFIELDS, etc. */
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
- _("Unsupported compression (%lu) in BMP file from '%s'"),
+ _("Unsupported compression (%u) in BMP file from '%s'"),
bitmap_head.biCompr,
gimp_filename_to_utf8 (filename));
}
@@ -392,20 +400,20 @@ load_image (const gchar *filename,
goto out;
}
- bitmap_head.biWidth =ToL (&buffer[0x00]); /* 12 */
- bitmap_head.biHeight =ToL (&buffer[0x04]); /* 16 */
- bitmap_head.biPlanes =ToS (&buffer[0x08]); /* 1A */
- bitmap_head.biBitCnt =ToS (&buffer[0x0A]); /* 1C */
- bitmap_head.biCompr =ToL (&buffer[0x0C]); /* 1E */
- bitmap_head.biSizeIm =ToL (&buffer[0x10]); /* 22 */
- bitmap_head.biXPels =ToL (&buffer[0x14]); /* 26 */
- bitmap_head.biYPels =ToL (&buffer[0x18]); /* 2A */
- bitmap_head.biClrUsed =ToL (&buffer[0x1C]); /* 2E */
- bitmap_head.biClrImp =ToL (&buffer[0x20]); /* 32 */
- bitmap_head.masks[0] =ToL (&buffer[0x24]); /* 36 */
- bitmap_head.masks[1] =ToL (&buffer[0x28]); /* 3A */
- bitmap_head.masks[2] =ToL (&buffer[0x2C]); /* 3E */
- bitmap_head.masks[3] =ToL (&buffer[0x30]); /* 42 */
+ bitmap_head.biWidth = ToL (&buffer[0x00]); /* 12 */
+ bitmap_head.biHeight = ToL (&buffer[0x04]); /* 16 */
+ bitmap_head.biPlanes = ToS (&buffer[0x08]); /* 1A */
+ bitmap_head.biBitCnt = ToS (&buffer[0x0A]); /* 1C */
+ bitmap_head.biCompr = ToL (&buffer[0x0C]); /* 1E */
+ bitmap_head.biSizeIm = ToL (&buffer[0x10]); /* 22 */
+ bitmap_head.biXPels = ToL (&buffer[0x14]); /* 26 */
+ bitmap_head.biYPels = ToL (&buffer[0x18]); /* 2A */
+ bitmap_head.biClrUsed = ToL (&buffer[0x1C]); /* 2E */
+ bitmap_head.biClrImp = ToL (&buffer[0x20]); /* 32 */
+ bitmap_head.masks[0] = ToL (&buffer[0x24]); /* 36 */
+ bitmap_head.masks[1] = ToL (&buffer[0x28]); /* 3A */
+ bitmap_head.masks[2] = ToL (&buffer[0x2C]); /* 3E */
+ bitmap_head.masks[3] = ToL (&buffer[0x30]); /* 42 */
Maps = 4;
ReadChannelMasks (&bitmap_head.masks[0], masks, 4);
@@ -554,7 +562,7 @@ load_image (const gchar *filename,
* word length (32 bits == 4 bytes)
*/
- rowbytes= ((bitmap_head.biWidth * bitmap_head.biBitCnt - 1) / 32) * 4 + 4;
+ rowbytes = ((bitmap_head.biWidth * bitmap_head.biBitCnt - 1) / 32) * 4 + 4;
#ifdef DEBUG
printf ("\nSize: %lu, Colors: %lu, Bits: %hu, Width: %ld, Height: %ld, "
@@ -627,18 +635,18 @@ out:
}
static gint32
-ReadImage (FILE *fd,
- const gchar *filename,
- gint width,
- gint height,
- guchar cmap[256][3],
- gint ncols,
- gint bpp,
- gint compression,
- gint rowbytes,
- gboolean gray,
- const Bitmap_Channel *masks,
- GError **error)
+ReadImage (FILE *fd,
+ const gchar *filename,
+ gint width,
+ gint height,
+ guchar cmap[256][3],
+ gint ncols,
+ gint bpp,
+ gint compression,
+ gint rowbytes,
+ gboolean gray,
+ const BitmapChannel *masks,
+ GError **error)
{
guchar v, n;
gint xpos = 0;
@@ -749,6 +757,7 @@ ReadImage (FILE *fd,
while (ReadOK (fd, row_buf, rowbytes))
{
temp = dest + (ypos * rowstride);
+
for (xpos= 0; xpos < width; ++xpos)
{
px32 = ToL(&row_buf[xpos*4]);
@@ -758,9 +767,12 @@ ReadImage (FILE *fd,
if (channels > 3)
*(temp++) = ((px32 & masks[3].mask) >> masks[3].shiftin) * 255.0 / masks[3].max_value +
0.5;
}
+
if (ypos == 0)
break;
+
--ypos; /* next line */
+
cur_progress++;
if ((cur_progress % 5) == 0)
gimp_progress_update ((gdouble) cur_progress /
@@ -774,15 +786,19 @@ ReadImage (FILE *fd,
while (ReadOK (fd, row_buf, rowbytes))
{
temp = dest + (ypos * rowstride);
+
for (xpos= 0; xpos < width; ++xpos)
{
*(temp++) = row_buf[xpos * 3 + 2];
*(temp++) = row_buf[xpos * 3 + 1];
*(temp++) = row_buf[xpos * 3];
}
+
if (ypos == 0)
break;
+
--ypos; /* next line */
+
cur_progress++;
if ((cur_progress % 5) == 0)
gimp_progress_update ((gdouble) cur_progress /
@@ -796,6 +812,7 @@ ReadImage (FILE *fd,
while (ReadOK (fd, row_buf, rowbytes))
{
temp = dest + (ypos * rowstride);
+
for (xpos= 0; xpos < width; ++xpos)
{
rgb= ToS(&row_buf[xpos * 2]);
@@ -805,9 +822,12 @@ ReadImage (FILE *fd,
if (channels > 3)
*(temp++) = ((rgb & masks[3].mask) >> masks[3].shiftin) * 255.0 / masks[3].max_value + 0.5;
}
+
if (ypos == 0)
break;
+
--ypos; /* next line */
+
cur_progress++;
if ((cur_progress % 5) == 0)
gimp_progress_update ((gdouble) cur_progress /
@@ -832,11 +852,14 @@ ReadImage (FILE *fd,
if (gray)
*temp = cmap[*temp][0];
}
+
if (xpos == width)
{
fread (row_buf, rowbytes - 1 - (width * bpp - 1) / 8, 1, fd);
+
if (ypos == 0)
break;
+
ypos--;
xpos = 0;
@@ -845,6 +868,7 @@ ReadImage (FILE *fd,
gimp_progress_update ((gdouble) cur_progress /
(gdouble) max_progress);
}
+
if (ypos < 0)
break;
}
@@ -865,9 +889,9 @@ ReadImage (FILE *fd,
/* Count + Color - record */
{
/* encoded mode run -
- row_buf[0] == run_length
- row_buf[1] == pixel data
- */
+ * row_buf[0] == run_length
+ * row_buf[1] == pixel data
+ */
for (j = 0;
((guchar) j < row_buf[0]) && (xpos < width);)
{
@@ -888,11 +912,13 @@ ReadImage (FILE *fd,
}
}
}
+
if ((row_buf[0] == 0) && (row_buf[1] > 2))
/* uncompressed record */
{
n = row_buf[1];
total_bytes_read = 0;
+
for (j = 0; j < n; j += (8 / bpp))
{
/* read the next byte in the record */
@@ -901,6 +927,7 @@ ReadImage (FILE *fd,
g_message (_("The bitmap ends unexpectedly."));
break;
}
+
total_bytes_read++;
/* read all pixels from that byte */
@@ -925,8 +952,9 @@ ReadImage (FILE *fd,
/* absolute mode runs are padded to 16-bit alignment */
if (total_bytes_read % 2)
- fread(&v, 1, 1, fd);
+ fread (&v, 1, 1, fd);
}
+
if ((row_buf[0] == 0) && (row_buf[1] == 0))
/* Line end */
{
@@ -938,11 +966,13 @@ ReadImage (FILE *fd,
gimp_progress_update ((gdouble) cur_progress /
(gdouble) max_progress);
}
+
if ((row_buf[0] == 0) && (row_buf[1] == 1))
/* Bitmap end */
{
break;
}
+
if ((row_buf[0] == 0) && (row_buf[1] == 2))
/* Deltarecord */
{
@@ -951,6 +981,7 @@ ReadImage (FILE *fd,
g_message (_("The bitmap ends unexpectedly."));
break;
}
+
xpos += row_buf[0];
ypos -= row_buf[1];
}
diff --git a/plug-ins/file-bmp/bmp-save.c b/plug-ins/file-bmp/bmp-save.c
index 214e62a..83c661a 100644
--- a/plug-ins/file-bmp/bmp-save.c
+++ b/plug-ins/file-bmp/bmp-save.c
@@ -78,27 +78,6 @@ static struct
gint dont_write_color_space_data;
} BMPSaveData;
-static Bitmap_File_Head bitmap_file_head;
-static Bitmap_Head bitmap_head;
-
-
-static void
-FromL (gint32 wert,
- guchar *bopuffer)
-{
- bopuffer[0] = (wert) & 0xff;
- bopuffer[1] = (wert >> 0x08) & 0xff;
- bopuffer[2] = (wert >> 0x10) & 0xff;
- bopuffer[3] = (wert >> 0x18) & 0xff;
-}
-
-static void
-FromS (gint16 wert,
- guchar *bopuffer)
-{
- bopuffer[0] = (wert) & 0xff;
- bopuffer[1] = (wert >> 0x08) & 0xff;
-}
static void
write_color_map (FILE *f,
@@ -151,25 +130,26 @@ save_image (const gchar *filename,
GimpRunMode run_mode,
GError **error)
{
- FILE *outfile;
- gint Red[MAXCOLORS];
- gint Green[MAXCOLORS];
- gint Blue[MAXCOLORS];
- guchar *cmap;
- gint rows, cols, Spcols, channels, MapSize, SpZeile;
- glong BitsPerPixel;
- gint colors;
- guchar *pixels;
- GeglBuffer *buffer;
- const Babl *format;
- GimpImageType drawable_type;
- gint drawable_width;
- gint drawable_height;
- guchar puffer[128];
- gint i;
- gint mask_info_size;
- gint color_space_size;
- guint32 Mask[4];
+ FILE *outfile;
+ BitmapFileHead bitmap_file_head;
+ BitmapHead bitmap_head;
+ gint Red[MAXCOLORS];
+ gint Green[MAXCOLORS];
+ gint Blue[MAXCOLORS];
+ guchar *cmap;
+ gint rows, cols, Spcols, channels, MapSize, SpZeile;
+ glong BitsPerPixel;
+ gint colors;
+ guchar *pixels;
+ GeglBuffer *buffer;
+ const Babl *format;
+ GimpImageType drawable_type;
+ gint drawable_width;
+ gint drawable_height;
+ gint i;
+ gint mask_info_size;
+ gint color_space_size;
+ guint32 Mask[4];
buffer = gimp_drawable_get_buffer (drawable_ID);
@@ -284,7 +264,8 @@ save_image (const gchar *filename,
if (! save_dialog (1))
return GIMP_PDB_CANCEL;
}
- else if ((BitsPerPixel == 24 || BitsPerPixel == 32))
+ else if (BitsPerPixel == 24 ||
+ BitsPerPixel == 32)
{
if (run_mode == GIMP_RUN_INTERACTIVE)
{
@@ -299,23 +280,23 @@ save_image (const gchar *filename,
BitsPerPixel = 24;
break;
case RGBA_8888:
- BitsPerPixel = 32;
+ BitsPerPixel = 32;
mask_info_size = 16;
break;
case RGBX_8888:
- BitsPerPixel = 32;
+ BitsPerPixel = 32;
mask_info_size = 16;
break;
case RGB_565:
- BitsPerPixel = 16;
+ BitsPerPixel = 16;
mask_info_size = 16;
break;
case RGBA_5551:
- BitsPerPixel = 16;
+ BitsPerPixel = 16;
mask_info_size = 16;
break;
case RGB_555:
- BitsPerPixel = 16;
+ BitsPerPixel = 16;
mask_info_size = 16;
break;
default:
@@ -449,26 +430,26 @@ save_image (const gchar *filename,
Write (outfile, "BM", 2);
- FromL (bitmap_file_head.bfSize, &puffer[0x00]);
- FromS (bitmap_file_head.zzHotX, &puffer[0x04]);
- FromS (bitmap_file_head.zzHotY, &puffer[0x06]);
- FromL (bitmap_file_head.bfOffs, &puffer[0x08]);
- FromL (bitmap_file_head.biSize, &puffer[0x0C]);
+ bitmap_file_head.bfSize = GUINT32_TO_LE (bitmap_file_head.bfSize);
+ bitmap_file_head.zzHotX = GUINT16_TO_LE (bitmap_file_head.zzHotX);
+ bitmap_file_head.zzHotY = GUINT16_TO_LE (bitmap_file_head.zzHotY);
+ bitmap_file_head.bfOffs = GUINT32_TO_LE (bitmap_file_head.bfOffs);
+ bitmap_file_head.biSize = GUINT32_TO_LE (bitmap_file_head.biSize);
- Write (outfile, puffer, 16);
+ Write (outfile, &bitmap_file_head.bfSize, 16);
- FromL (bitmap_head.biWidth, &puffer[0x00]);
- FromL (bitmap_head.biHeight, &puffer[0x04]);
- FromS (bitmap_head.biPlanes, &puffer[0x08]);
- FromS (bitmap_head.biBitCnt, &puffer[0x0A]);
- FromL (bitmap_head.biCompr, &puffer[0x0C]);
- FromL (bitmap_head.biSizeIm, &puffer[0x10]);
- FromL (bitmap_head.biXPels, &puffer[0x14]);
- FromL (bitmap_head.biYPels, &puffer[0x18]);
- FromL (bitmap_head.biClrUsed, &puffer[0x1C]);
- FromL (bitmap_head.biClrImp, &puffer[0x20]);
+ bitmap_head.biWidth = GINT32_TO_LE (bitmap_head.biWidth);
+ bitmap_head.biHeight = GINT32_TO_LE (bitmap_head.biHeight);
+ bitmap_head.biPlanes = GUINT16_TO_LE (bitmap_head.biPlanes);
+ bitmap_head.biBitCnt = GUINT16_TO_LE (bitmap_head.biBitCnt);
+ bitmap_head.biCompr = GUINT32_TO_LE (bitmap_head.biCompr);
+ bitmap_head.biSizeIm = GUINT32_TO_LE (bitmap_head.biSizeIm);
+ bitmap_head.biXPels = GUINT32_TO_LE (bitmap_head.biXPels);
+ bitmap_head.biYPels = GUINT32_TO_LE (bitmap_head.biYPels);
+ bitmap_head.biClrUsed = GUINT32_TO_LE (bitmap_head.biClrUsed);
+ bitmap_head.biClrImp = GUINT32_TO_LE (bitmap_head.biClrImp);
- Write (outfile, puffer, 36);
+ Write (outfile, &bitmap_head, 36);
if (mask_info_size > 0)
{
@@ -512,46 +493,49 @@ save_image (const gchar *filename,
break;
}
- FromL (Mask[0], &puffer[0x00]);
- FromL (Mask[1], &puffer[0x04]);
- FromL (Mask[2], &puffer[0x08]);
- FromL (Mask[3], &puffer[0x0C]);
- Write (outfile, puffer, mask_info_size);
+ Mask[0] = GUINT32_TO_LE (Mask[0]);
+ Mask[1] = GUINT32_TO_LE (Mask[1]);
+ Mask[2] = GUINT32_TO_LE (Mask[2]);
+ Mask[3] = GUINT32_TO_LE (Mask[3]);
+
+ Write (outfile, &Mask, mask_info_size);
}
if (! BMPSaveData.dont_write_color_space_data)
{
+ guint32 buf[0x11];
+
/* Write V5 color space fields */
/* bV5CSType = LCS_sRGB */
- FromL (0x73524742, &puffer[0x00]);
+ buf[0x00] = GUINT32_TO_LE (0x73524742);
/* bV5Endpoints is set to 0 (ignored) */
- for (i = 0; i < 0x24; i++)
- puffer[0x04 + i] = 0x00;
+ for (i = 0; i < 0x09; i++)
+ buf[i + 1] = 0x00;
/* bV5GammaRed is set to 0 (ignored) */
- FromL (0x0, &puffer[0x28]);
+ buf[0x0a] = GUINT32_TO_LE (0x0);
/* bV5GammaGreen is set to 0 (ignored) */
- FromL (0x0, &puffer[0x2c]);
+ buf[0x0b] = GUINT32_TO_LE (0x0);
/* bV5GammaBlue is set to 0 (ignored) */
- FromL (0x0, &puffer[0x30]);
+ buf[0x0c] = GUINT32_TO_LE (0x0);
/* bV5Intent = LCS_GM_GRAPHICS */
- FromL (0x00000002, &puffer[0x34]);
+ buf[0x0d] = GUINT32_TO_LE (0x00000002);
/* bV5ProfileData is set to 0 (ignored) */
- FromL (0x0, &puffer[0x38]);
+ buf[0x0e] = GUINT32_TO_LE (0x0);
/* bV5ProfileSize is set to 0 (ignored) */
- FromL (0x0, &puffer[0x3c]);
+ buf[0x0f] = GUINT32_TO_LE (0x0);
/* bV5Reserved = 0 */
- FromL (0x0, &puffer[0x40]);
+ buf[0x10] = GUINT32_TO_LE (0x0);
- Write (outfile, puffer, color_space_size);
+ Write (outfile, buf, color_space_size);
}
write_color_map (outfile, Red, Green, Blue, MapSize);
@@ -573,25 +557,38 @@ save_image (const gchar *filename,
return GIMP_PDB_SUCCESS;
}
-static inline void Make565(guchar r, guchar g, guchar b, guchar *buf)
+static inline void
+Make565 (guchar r,
+ guchar g,
+ guchar b,
+ guchar *buf)
{
- gint p;
- p = (((gint)(r / 255.0 * 31.0 + 0.5))<<11) |
- (((gint)(g / 255.0 * 63.0 + 0.5))<<5) |
- ((gint)(b / 255.0 * 31.0 + 0.5));
- buf[0] = (guchar)(p & 0xff);
- buf[1] = (guchar)(p>>8);
+ gint p;
+
+ p = ((((gint) (r / 255.0 * 31.0 + 0.5)) << 11) |
+ (((gint) (g / 255.0 * 63.0 + 0.5)) << 5) |
+ (((gint) (b / 255.0 * 31.0 + 0.5))));
+
+ buf[0] = (guchar) (p & 0xff);
+ buf[1] = (guchar) (p >> 8);
}
-static inline void Make5551(guchar r, guchar g, guchar b, guchar a, guchar *buf)
+static inline void
+Make5551 (guchar r,
+ guchar g,
+ guchar b,
+ guchar a,
+ guchar *buf)
{
- gint p;
- p = (((gint)(r / 255.0 * 31.0 + 0.5))<<10) |
- (((gint)(g / 255.0 * 31.0 + 0.5))<<5) |
- ((gint)(b / 255.0 * 31.0 + 0.5)) |
- ((gint)(a / 255.0 + 0.5)<<15);
- buf[0] = (guchar)(p & 0xff);
- buf[1] = (guchar)(p>>8);
+ gint p;
+
+ p = ((((gint) (r / 255.0 * 31.0 + 0.5)) << 10) |
+ (((gint) (g / 255.0 * 31.0 + 0.5)) << 5) |
+ (((gint) (b / 255.0 * 31.0 + 0.5))) |
+ (((gint) (a / 255.0 + 0.5) << 15)));
+
+ buf[0] = (guchar) (p & 0xff);
+ buf[1] = (guchar) (p >> 8);
}
static void
@@ -609,7 +606,7 @@ write_image (FILE *f,
gint color_space_size)
{
guchar buf[16] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0 };
- guchar puffer[8];
+ guint32 uint32buf;
guchar *temp, v;
guchar *row, *ketten;
gint xpos, ypos, i, j, rowstride, length, thiswidth;
@@ -771,6 +768,7 @@ write_image (FILE *f,
breite = width / (8 / bpp);
if (width % (8 / bpp))
breite++;
+
/* then check for strings of equal bytes */
for (i = 0; i < breite; i += j)
{
@@ -844,6 +842,7 @@ write_image (FILE *f,
length += 2;
}
}
+
Write (f, &buf[14], 2); /* End of row */
length += 2;
@@ -852,16 +851,19 @@ write_image (FILE *f,
gimp_progress_update ((gdouble) cur_progress /
(gdouble) max_progress);
}
+
fseek (f, -2, SEEK_CUR); /* Overwrite last End of row ... */
Write (f, &buf[12], 2); /* ... with End of file */
fseek (f, 0x22, SEEK_SET); /* Write length of image */
- FromL (length, puffer);
- Write (f, puffer, 4);
+ uint32buf = GUINT32_TO_LE (length);
+ Write (f, &uint32buf, 4);
+
fseek (f, 0x02, SEEK_SET); /* Write length of file */
length += (0x36 + MapSize + mask_info_size + color_space_size);
- FromL (length, puffer);
- Write (f, puffer, 4);
+ uint32buf = GUINT32_TO_LE (length);
+ Write (f, &uint32buf, 4);
+
g_free (ketten);
g_free (row);
break;
diff --git a/plug-ins/file-bmp/bmp.h b/plug-ins/file-bmp/bmp.h
index 45bd3ae..bae296a 100644
--- a/plug-ins/file-bmp/bmp.h
+++ b/plug-ins/file-bmp/bmp.h
@@ -34,37 +34,37 @@
#define WriteOK(file,buffer,len) (Write(buffer, len, file) != 0)
-typedef struct _Bitmap_File_Head
+typedef struct
{
gchar zzMagic[2]; /* 00 "BM" */
- gulong bfSize; /* 02 */
- gushort zzHotX; /* 06 */
- gushort zzHotY; /* 08 */
- gulong bfOffs; /* 0A */
- gulong biSize; /* 0E */
-} Bitmap_File_Head;
+ guint32 bfSize; /* 02 */
+ guint16 zzHotX; /* 06 */
+ guint16 zzHotY; /* 08 */
+ guint32 bfOffs; /* 0A */
+ guint32 biSize; /* 0E */
+} BitmapFileHead;
-typedef struct _Bitmap_Head
+typedef struct
{
- glong biWidth; /* 12 */
- glong biHeight; /* 16 */
- gushort biPlanes; /* 1A */
- gushort biBitCnt; /* 1C */
- gulong biCompr; /* 1E */
- gulong biSizeIm; /* 22 */
- gulong biXPels; /* 26 */
- gulong biYPels; /* 2A */
- gulong biClrUsed; /* 2E */
- gulong biClrImp; /* 32 */
+ gint32 biWidth; /* 12 */
+ gint32 biHeight; /* 16 */
+ guint16 biPlanes; /* 1A */
+ guint16 biBitCnt; /* 1C */
+ guint32 biCompr; /* 1E */
+ guint32 biSizeIm; /* 22 */
+ guint32 biXPels; /* 26 */
+ guint32 biYPels; /* 2A */
+ guint32 biClrUsed; /* 2E */
+ guint32 biClrImp; /* 32 */
guint32 masks[4]; /* 36 */
-} Bitmap_Head;
+} BitmapHead;
-typedef struct _Bitmap_Channel
+typedef struct
{
guint32 mask;
guint32 shiftin;
gfloat max_value;
-} Bitmap_Channel;
+} BitmapChannel;
#endif /* __BMP_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]