Fix for #126366 (bmp - wrong colors loaded)

This commit is contained in:
Maurits Rijk 2003-11-25 09:50:39 +00:00
parent c4032a9d19
commit d1b4eed971
2 changed files with 55 additions and 7 deletions

View File

@ -1,3 +1,7 @@
2003-11-25 Maurits Rijk <m.rijk@chello.nl>
* plug-ins/bmp/bmpread.c: fix for #126366 (bmp - wrong colors loaded)
2003-11-25 Raphaël Quinet <quinet@gamers.org> 2003-11-25 Raphaël Quinet <quinet@gamers.org>
* NEWS: Improved the spelling of my name (missing accents) and * NEWS: Improved the spelling of my name (missing accents) and

View File

@ -36,6 +36,14 @@
#include "libgimp/stdplugins-intl.h" #include "libgimp/stdplugins-intl.h"
#if !defined(WIN32) || defined(__MINGW32__)
#define BI_RGB 0
#define BI_RLE8 1
#define BI_RLE4 2
#define BI_BITFIELDS 3
#endif
static gboolean using565;
static gint32 static gint32
ToL (guchar *puffer) ToL (guchar *puffer)
@ -254,11 +262,38 @@ ReadBMP (const gchar *name)
Bitmap_File_Head.bfSize,Bitmap_Head.biClrUsed,Bitmap_Head.biBitCnt,Bitmap_Head.biWidth, Bitmap_File_Head.bfSize,Bitmap_Head.biClrUsed,Bitmap_Head.biBitCnt,Bitmap_Head.biWidth,
Bitmap_Head.biHeight, Bitmap_Head.biCompr, rowbytes); Bitmap_Head.biHeight, Bitmap_Head.biCompr, rowbytes);
#endif #endif
if (Bitmap_Head.biCompr == BI_BITFIELDS &&
(Bitmap_Head.biBitCnt == 16 || Bitmap_Head.biBitCnt == 16))
{
gint32 tmp[3];
gint32 green_mask;
gint i, green;
/* Get the Colormap */ if (!ReadOK(fd, tmp, 3 * sizeof(gint32)))
{
g_message (_("'%s' is not a valid BMP file"), filename);
return -1;
}
if (!ReadColorMap (fd, ColorMap, ColormapSize, Maps, &Grey)) green_mask = ToL ((guchar*) &tmp[1]);
return -1;
green = 0;
for (i = 0; i < 32; i++)
{
if (green_mask & 1)
green++;
green_mask = green_mask >> 1;
}
using565 = green == 6;
}
else
{
/* Get the Colormap */
if (!ReadColorMap (fd, ColorMap, ColormapSize, Maps, &Grey))
return -1;
}
#ifdef DEBUG #ifdef DEBUG
printf("Colormap read\n"); printf("Colormap read\n");
@ -294,7 +329,7 @@ ReadBMP (const gchar *name)
gimp_image_set_resolution (image_ID, xresolution, yresolution); gimp_image_set_resolution (image_ID, xresolution, yresolution);
} }
return (image_ID); return image_ID;
} }
Image Image
@ -410,9 +445,18 @@ ReadImage (FILE *fd,
for (xpos= 0; xpos < width; ++xpos) for (xpos= 0; xpos < width; ++xpos)
{ {
rgb= ToS(&buffer[xpos * 2]); rgb= ToS(&buffer[xpos * 2]);
*(temp++)= ((rgb >> 10) & 0x1f) * 8; if (using565) /* rgb 565 encoded */
*(temp++)= ((rgb >> 5) & 0x1f) * 8; {
*(temp++)= ((rgb) & 0x1f) * 8; *(temp++)= ((rgb >> 11) & 0x1f) * 8;
*(temp++)= ((rgb >> 5) & 0x3f) * 4;
*(temp++)= ((rgb) & 0x1f) * 8;
}
else /* rgb555 */
{
*(temp++)= ((rgb >> 10) & 0x1f) * 8;
*(temp++)= ((rgb >> 5) & 0x1f) * 8;
*(temp++)= ((rgb) & 0x1f) * 8;
}
} }
--ypos; /* next line */ --ypos; /* next line */
cur_progress++; cur_progress++;