plug-ins/bmp/bmp.c plug-ins/bmp/bmpread.c applied a (slightly modified)

2005-06-07  Sven Neumann  <sven@gimp.org>

	* plug-ins/bmp/bmp.c
	* plug-ins/bmp/bmpread.c
	* plug-ins/bmp/bmpwrite.c: applied a (slightly modified) patch
	contributed by Brandon that adds support for reading and writing
	RGBA BMP files (bug #306339).
This commit is contained in:
Sven Neumann 2005-06-07 16:55:21 +00:00 committed by Sven Neumann
parent 3e7aaa368c
commit df623bf246
4 changed files with 65 additions and 19 deletions

View File

@ -1,3 +1,11 @@
2005-06-07 Sven Neumann <sven@gimp.org>
* plug-ins/bmp/bmp.c
* plug-ins/bmp/bmpread.c
* plug-ins/bmp/bmpwrite.c: applied a (slightly modified) patch
contributed by Brandon that adds support for reading and writing
RGBA BMP files (bug #306339).
2005-06-07 Manish Singh <yosh@gimp.org>
* app/base/cpu-accel.[ch]: detect SSE3.

View File

@ -135,7 +135,7 @@ query (void)
"Alexander Schulz",
"1997",
N_("Windows BMP image"),
"INDEXED, GRAY, RGB",
"INDEXED, GRAY, RGB*",
GIMP_PLUGIN,
G_N_ELEMENTS (save_args), 0,
save_args, NULL);
@ -215,6 +215,7 @@ run (const gchar *name,
gimp_ui_init ("bmp", FALSE);
export = gimp_export_image (&image_ID, &drawable_ID, "BMP",
(GIMP_EXPORT_CAN_HANDLE_RGB |
GIMP_EXPORT_CAN_HANDLE_ALPHA |
GIMP_EXPORT_CAN_HANDLE_GRAY |
GIMP_EXPORT_CAN_HANDLE_INDEXED));
if (export == GIMP_EXPORT_CANCEL)

View File

@ -457,9 +457,9 @@ ReadImage (FILE *fd,
case 24:
case 16:
base_type = GIMP_RGB;
image_type = GIMP_RGB_IMAGE;
image_type = bpp == 32 ? GIMP_RGBA_IMAGE : GIMP_RGB_IMAGE;
channels = 3;
channels = bpp == 32 ? 4 : 3;
break;
case 8:
@ -516,7 +516,8 @@ ReadImage (FILE *fd,
{
*(temp++)= buffer[xpos * 4 + 2];
*(temp++)= buffer[xpos * 4 + 1];
*(temp++)= buffer[xpos * 4];
*(temp++)= buffer[xpos * 4 + 0];
*(temp++)= buffer[xpos * 4 + 3];
}
if (ypos == 0)
break;

View File

@ -119,30 +119,28 @@ WriteBMP (const gchar *filename,
guchar puffer[50];
gint i;
/* first: can we save this image? */
drawable = gimp_drawable_get (drawable_ID);
drawable_type = gimp_drawable_type (drawable_ID);
gimp_pixel_rgn_init (&pixel_rgn, drawable,
0, 0, drawable->width, drawable->height, FALSE, FALSE);
if (gimp_drawable_has_alpha (drawable_ID))
{
g_message (_("Cannot save images with alpha channel."));
return GIMP_PDB_EXECUTION_ERROR;
}
/* We can save it. So what colors do we use? */
switch (drawable_type)
{
case GIMP_RGBA_IMAGE:
colors = 0;
BitsPerPixel = 32;
MapSize = 0;
channels = 4;
break;
case GIMP_RGB_IMAGE:
colors = 0;
BitsPerPixel = 24;
MapSize = 0;
channels = 3;
break;
case GIMP_GRAY_IMAGE:
colors = 256;
BitsPerPixel = 8;
@ -155,6 +153,11 @@ WriteBMP (const gchar *filename,
Blue[i] = i;
}
break;
case GIMP_GRAYA_IMAGE:
g_message (_("Cannot operate on grayscale images with alpha channel."));
return GIMP_PDB_EXECUTION_ERROR;
case GIMP_INDEXED_IMAGE:
cmap = gimp_image_get_colormap (image, &colors);
MapSize = 4 * colors;
@ -174,9 +177,13 @@ WriteBMP (const gchar *filename,
Blue[i] = *cmap++;
}
break;
default:
g_message (_("Cannot operate on unknown image types."));
case GIMP_INDEXEDA_IMAGE:
g_message (_("Cannot operate on indexed images with alpha channel."));
return GIMP_PDB_EXECUTION_ERROR;
default:
g_assert_not_reached ();
}
/* Perhaps someone wants RLE encoded Bitmaps */
@ -215,7 +222,7 @@ WriteBMP (const gchar *filename,
rows = drawable->height;
/* ... that we write to our headers. */
if ((BitsPerPixel != 24) &&
if ((BitsPerPixel < 24) &&
(cols % (8/BitsPerPixel)))
Spcols = (((cols / (8 / BitsPerPixel)) + 1) * (8 / BitsPerPixel));
else
@ -346,9 +353,38 @@ WriteImage (FILE *f,
xpos = 0;
rowstride = width * channels;
/* We'll begin with the 24 bit Bitmaps, they are easy :-) */
/* We'll begin with the 32 and 24 bit Bitmaps, they are easy :-) */
if (bpp == 24)
if (bpp == 32)
{
for (ypos = height - 1; ypos >= 0; ypos--) /* for each row */
{
for (i = 0; i < width; i++) /* for each pixel */
{
temp = src + (ypos * rowstride) + (xpos * channels);
buf[2] = (guchar) *temp;
temp++;
buf[1] = (guchar) *temp;
temp++;
buf[0] = (guchar) *temp;
temp++;
buf[3] = (guchar) *temp;
xpos++;
Write (f, buf, 4);
}
Write (f, &buf[3], spzeile - (width * 4));
cur_progress++;
if ((cur_progress % 5) == 0)
gimp_progress_update ((gdouble) cur_progress /
(gdouble) max_progress);
xpos = 0;
}
}
else if (bpp == 24)
{
for (ypos = height - 1; ypos >= 0; ypos--) /* for each row */
{