Applied a patch from Brion Vibber that fixes byte-swapping on big endian

2004-07-15  Philip Lafleur  <plafleur@cvs.gnome.org>

	* plug-ins/winicon/icoload.c:
	* plug-ins/winicon/icosave.c: Applied a patch from Brion Vibber
	that fixes byte-swapping on big endian hosts.	Fixes bug #147610.
This commit is contained in:
Philip Lafleur 2004-07-15 11:10:09 +00:00 committed by Philip Lafleur
parent 9098878252
commit de5aa52eb8
3 changed files with 60 additions and 40 deletions

View file

@ -1,3 +1,9 @@
2004-07-15 Philip Lafleur <plafleur@cvs.gnome.org>
* plug-ins/winicon/icoload.c:
* plug-ins/winicon/icosave.c: Applied a patch from Brion Vibber
that fixes byte-swapping on big endian hosts. Fixes bug #147610.
2004-07-15 Sven Neumann <sven@gimp.org>
* plug-ins/helpbrowser/dialog.c

View file

@ -36,21 +36,15 @@
#include "libgimp/stdplugins-intl.h"
#if (G_BYTE_ORDER == G_BIG_ENDIAN)
#define A_VAL(p) ((guchar *)(p))[0]
#define R_VAL(p) ((guchar *)(p))[1]
#define G_VAL(p) ((guchar *)(p))[2]
#define B_VAL(p) ((guchar *)(p))[3]
#elif (G_BYTE_ORDER == G_LITTLE_ENDIAN)
#define A_VAL(p) ((guchar *)(p))[3]
#define R_VAL(p) ((guchar *)(p))[2]
#define G_VAL(p) ((guchar *)(p))[1]
#define B_VAL(p) ((guchar *)(p))[0]
#endif
#define A_VAL_GIMP(p) ((guchar *)(p))[3]
#define R_VAL_GIMP(p) ((guchar *)(p))[0]
#define G_VAL_GIMP(p) ((guchar *)(p))[1]
#define B_VAL_GIMP(p) ((guchar *)(p))[2]
static gint ico_read_int8 (FILE *fp, guint8 *data, gint count);
@ -233,7 +227,7 @@ ico_read_data (MsIcon *ico,
data->used_clrs, data->bpp));
data->palette = g_new0 (guint32, data->used_clrs);
ico->cp += ico_read_int32 (ico->fp, data->palette, data->used_clrs);
ico->cp += ico_read_int8 (ico->fp, data->palette, data->used_clrs * 4);
}
data->xor_map = ico_alloc_map (entry->width, entry->height,
@ -407,14 +401,14 @@ ico_to_gimp (MsIcon *ico)
w, y * w + x)];
guint32 *dest = &(dest_vec[(h-1-y) * w + x]);
B_VAL (dest) = R_VAL (&color);
G_VAL (dest) = G_VAL (&color);
R_VAL (dest) = B_VAL (&color);
R_VAL_GIMP (dest) = R_VAL (&color);
G_VAL_GIMP (dest) = G_VAL (&color);
B_VAL_GIMP (dest) = B_VAL (&color);
if (ico_get_bit_from_data (and_map, w, y*w + x))
A_VAL (dest) = 0;
A_VAL_GIMP (dest) = 0;
else
A_VAL (dest) = 255;
A_VAL_GIMP (dest) = 255;
}
break;
@ -426,14 +420,14 @@ ico_to_gimp (MsIcon *ico)
w, y * w + x)];
guint32 *dest = &(dest_vec[(h-1-y) * w + x]);
B_VAL (dest) = R_VAL (&color);
G_VAL (dest) = G_VAL (&color);
R_VAL (dest) = B_VAL (&color);
R_VAL_GIMP (dest) = R_VAL (&color);
G_VAL_GIMP (dest) = G_VAL (&color);
B_VAL_GIMP (dest) = B_VAL (&color);
if (ico_get_bit_from_data (and_map, w, y*w + x))
A_VAL (dest) = 0;
A_VAL_GIMP (dest) = 0;
else
A_VAL (dest) = 255;
A_VAL_GIMP (dest) = 255;
}
break;
@ -445,14 +439,14 @@ ico_to_gimp (MsIcon *ico)
w, y * w + x)];
guint32 *dest = &(dest_vec[(h-1-y) * w + x]);
B_VAL (dest) = R_VAL (&color);
G_VAL (dest) = G_VAL (&color);
R_VAL (dest) = B_VAL (&color);
R_VAL_GIMP (dest) = R_VAL (&color);
G_VAL_GIMP (dest) = G_VAL (&color);
B_VAL_GIMP (dest) = B_VAL (&color);
if (ico_get_bit_from_data (and_map, w, y*w + x))
A_VAL (dest) = 0;
A_VAL_GIMP (dest) = 0;
else
A_VAL (dest) = 255;
A_VAL_GIMP (dest) = 255;
}
break;
@ -465,20 +459,20 @@ ico_to_gimp (MsIcon *ico)
{
guint32 *dest = &(dest_vec[(h-1-y) * w + x]);
R_VAL(dest) = xor_map[(y * w + x) * bytespp];
G_VAL(dest) = xor_map[(y * w + x) * bytespp + 1];
B_VAL(dest) = xor_map[(y * w + x) * bytespp + 2];
B_VAL_GIMP(dest) = xor_map[(y * w + x) * bytespp];
G_VAL_GIMP(dest) = xor_map[(y * w + x) * bytespp + 1];
R_VAL_GIMP(dest) = xor_map[(y * w + x) * bytespp + 2];
if (idata->bpp < 32)
{
if (ico_get_bit_from_data (and_map, w, y*w + x))
A_VAL (dest) = 0;
A_VAL_GIMP (dest) = 0;
else
A_VAL (dest) = 255;
A_VAL_GIMP (dest) = 255;
}
else
{
A_VAL (dest) = xor_map[(y * w + x) * bytespp + 3];
A_VAL_GIMP (dest) = xor_map[(y * w + x) * bytespp + 3];
}
}
}

View file

@ -60,15 +60,25 @@ ico_write_int32 (FILE *fp,
guint32 *data,
gint count)
{
gint i, total;
gint total;
total = count;
if (count > 0)
{
#if (G_BYTE_ORDER == G_BIG_ENDIAN)
gint i;
for (i = 0; i < count; i++)
data[i] = GUINT32_FROM_LE (data[i]);
data[i] = GUINT32_FROM_LE (data[i]);
#endif
ico_write_int8 (fp, (guint8*) data, count * 4);
#if (G_BYTE_ORDER == G_BIG_ENDIAN)
/* Put it back like we found it */
for (i = 0; i < count; i++)
data[i] = GUINT32_FROM_LE (data[i]);
#endif
}
return total * 4;
@ -80,15 +90,25 @@ ico_write_int16 (FILE *fp,
guint16 *data,
gint count)
{
gint i, total;
gint total;
total = count;
if (count > 0)
{
#if (G_BYTE_ORDER == G_BIG_ENDIAN)
gint i;
for (i = 0; i < count; i++)
data[i] = GUINT16_FROM_LE (data[i]);
data[i] = GUINT16_FROM_LE (data[i]);
#endif
ico_write_int8 (fp, (guint8*) data, count * 2);
#if (G_BYTE_ORDER == G_BIG_ENDIAN)
/* Put it back like we found it */
for (i = 0; i < count; i++)
data[i] = GUINT16_FROM_LE (data[i]);
#endif
}
return total * 2;
@ -222,7 +242,7 @@ ico_init (const gchar *filename,
ico->filename = filename;
ico->reserved = 0;
ico->resource_type = GUINT16_FROM_LE (1);
ico->resource_type = 1;
ico->icon_count = num_icons;
ico->icon_dir = g_new0 (MsIconEntry, num_icons);
ico->icon_data = g_new0 (MsIconData, num_icons);
@ -580,7 +600,7 @@ ico_init_data (MsIcon *ico,
pixel = (guint8*) &buffer32[y * entry->width + x];
((guint32*) data->xor_map)[(entry->height-y-1) * entry->width + x] =
((pixel[0] << 16) | (pixel[1] << 8) | pixel[2] | (pixel[3] << 24));
GUINT32_TO_LE((pixel[0] << 16) | (pixel[1] << 8) | pixel[2] | (pixel[3] << 24));
}
}
@ -679,8 +699,8 @@ ico_save (MsIcon *ico)
ico->cp += ico_write_int32 (ico->fp, &data->compression, 6);
if (data->palette)
ico->cp += ico_write_int32 (ico->fp,
data->palette, data->palette_len / 4);
ico->cp += ico_write_int8 (ico->fp,
data->palette, data->palette_len);
ico->cp += ico_write_int8 (ico->fp, data->xor_map, data->xor_len);
ico->cp += ico_write_int8 (ico->fp, data->and_map, data->and_len);