Commit ed153851 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

plug-ins/bmp/bmp.[ch] plug-ins/bmp/bmpread.c applied patch from Piotr

2006-08-15  Sven Neumann  <sven@gimp.org>

	* plug-ins/bmp/bmp.[ch]
	* plug-ins/bmp/bmpread.c
	* plug-ins/bmp/bmpwrite.c: applied patch from Piotr Filiciak that
	merges the save dialogs and completes the changes in bug #342355.
parent 33d41964
2006-08-15 Sven Neumann <sven@gimp.org>
* plug-ins/bmp/bmp.[ch]
* plug-ins/bmp/bmpread.c
* plug-ins/bmp/bmpwrite.c: applied patch from Piotr Filiciak that
merges the save dialogs and completes the changes in bug #342355.
2006-08-15 Bill Skaggs <weskaggs@primate.ucdavis.edu>
* app/paint/gimpbrushcore.c (gimp_brush_core_color_area_with_pixmap):
......
......@@ -65,12 +65,9 @@
#include "libgimp/stdplugins-intl.h"
#define LOAD_PROC "file-bmp-load"
#define SAVE_PROC "file-bmp-save"
const gchar *filename = NULL;
gboolean interactive = FALSE;
gboolean lastvals = FALSE;
struct Bitmap_File_Head_Struct Bitmap_File_Head;
struct Bitmap_Head_Struct Bitmap_Head;
......@@ -223,6 +220,7 @@ run (const gchar *name,
/* fallthrough */
case GIMP_RUN_WITH_LAST_VALS:
if (run_mode == GIMP_RUN_WITH_LAST_VALS) lastvals = TRUE;
gimp_ui_init ("bmp", FALSE);
export = gimp_export_image (&image_ID, &drawable_ID, "BMP",
(GIMP_EXPORT_CAN_HANDLE_RGB |
......
......@@ -17,6 +17,9 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#define LOAD_PROC "file-bmp-load"
#define SAVE_PROC "file-bmp-save"
#define MAXCOLORS 256
#define BitSet(byte, bit) (((byte) & (bit)) == (bit))
......@@ -31,6 +34,7 @@ GimpPDBStatusType WriteBMP (const gchar *filename,
gint32 drawable_ID);
extern gboolean interactive;
extern gboolean lastvals;
extern const gchar *filename;
extern struct Bitmap_File_Head_Struct
......
......@@ -655,7 +655,7 @@ ReadImage (FILE *fd,
}
if (xpos == width)
{
ReadOK (fd, buffer, rowbytes - 1 - (width * bpp - 1) / 8);
fread(buffer, rowbytes - 1 - (width * bpp - 1) / 8, 1, fd);
if (ypos == 0)
break;
ypos--;
......@@ -746,7 +746,7 @@ ReadImage (FILE *fd,
/* absolute mode runs are padded to 16-bit alignment */
if (total_bytes_read % 2)
ReadOK (fd, &v, 1);
fread(&v, 1, 1, fd);
}
if (((guchar) buffer[0] == 0) && ((guchar) buffer[1]==0))
/* Line end */
......
......@@ -51,10 +51,14 @@ typedef enum
RGBX_8888
} RGBMode;
static RGBMode rgb_format = RGB_888;
static struct
{
RGBMode rgb_format;
gint encoded;
} BMPSaveData;
static gint cur_progress = 0;
static gint max_progress = 0;
static gint encoded = 0;
static void write_image (FILE *f,
......@@ -67,8 +71,9 @@ static void write_image (FILE *f,
gint spzeile,
gint MapSize,
RGBMode rgb_format);
static gboolean save_dialog (void);
static gboolean save_dialog_rgb (gint channels);
static gboolean save_dialog (gint channels);
static void
FromL (gint32 wert,
......@@ -167,7 +172,7 @@ WriteBMP (const gchar *filename,
BitsPerPixel = 32;
MapSize = 0;
channels = 4;
rgb_format = RGBA_8888;
BMPSaveData.rgb_format = RGBA_8888;
break;
case GIMP_RGB_IMAGE:
......@@ -175,15 +180,17 @@ WriteBMP (const gchar *filename,
BitsPerPixel = 24;
MapSize = 0;
channels = 3;
rgb_format = RGB_888;
BMPSaveData.rgb_format = RGB_888;
break;
case GIMP_GRAYA_IMAGE:
if (!warning_dialog (_("Cannot save indexed image with transparency "
"in BMP file format."),
_("Alpha channel will be ignored.")));
if (interactive && !warning_dialog (_("Cannot save indexed image with "
"transparency in BMP file format."),
_("Alpha channel will be ignored.")))
return GIMP_PDB_CANCEL;
/* fallthrough */
case GIMP_GRAY_IMAGE:
colors = 256;
BitsPerPixel = 8;
......@@ -199,11 +206,13 @@ WriteBMP (const gchar *filename,
break;
case GIMP_INDEXEDA_IMAGE:
if (!warning_dialog (_("Cannot save indexed image with transparency "
"in BMP file format."),
_("Alpha channel will be ignored.")));
if (interactive && !warning_dialog (_("Cannot save indexed image with "
"transparency in BMP file format."),
_("Alpha channel will be ignored.")))
return GIMP_PDB_CANCEL;
/* fallthrough */
case GIMP_INDEXED_IMAGE:
cmap = gimp_image_get_colormap (image, &colors);
MapSize = 4 * colors;
......@@ -230,20 +239,25 @@ WriteBMP (const gchar *filename,
}
/* Perhaps someone wants RLE encoded Bitmaps */
encoded = 0;
BMPSaveData.encoded = 0;
mask_info_size = 0;
if (!interactive && lastvals)
{
gimp_get_data (SAVE_PROC, &BMPSaveData);
}
if ((BitsPerPixel == 8 || BitsPerPixel == 4) && interactive)
{
if (! save_dialog ())
if (! save_dialog (1))
return GIMP_PDB_CANCEL;
}
else if ((BitsPerPixel == 24 || BitsPerPixel == 32))
{
if (interactive && !save_dialog_rgb (channels))
if (interactive && !save_dialog (channels))
return GIMP_PDB_CANCEL;
switch (rgb_format)
switch (BMPSaveData.rgb_format)
{
case RGB_888:
BitsPerPixel = 24;
......@@ -271,6 +285,8 @@ WriteBMP (const gchar *filename,
}
}
gimp_set_data (SAVE_PROC, &BMPSaveData, sizeof (BMPSaveData));
/* Let's take some file */
outfile = g_fopen (filename, "wb");
if (!outfile)
......@@ -318,7 +334,7 @@ WriteBMP (const gchar *filename,
Bitmap_Head.biPlanes = 1;
Bitmap_Head.biBitCnt = BitsPerPixel;
if (encoded == 0)
if (BMPSaveData.encoded == 0)
{
if (!mask_info_size) Bitmap_Head.biCompr = 0;
else Bitmap_Head.biCompr = 3;
......@@ -397,7 +413,7 @@ WriteBMP (const gchar *filename,
if (mask_info_size)
{
switch (rgb_format)
switch (BMPSaveData.rgb_format)
{
default:
case RGB_888:
......@@ -407,24 +423,28 @@ WriteBMP (const gchar *filename,
Mask[2] = 0x0000ff00;
Mask[3] = 0x00000000;
break;
case RGBA_8888:
Mask[0] = 0xff000000;
Mask[1] = 0x00ff0000;
Mask[2] = 0x0000ff00;
Mask[3] = 0x000000ff;
break;
case RGB_565:
Mask[0] = 0xf800;
Mask[1] = 0x7e0;
Mask[2] = 0x1f;
Mask[3] = 0x0;
break;
case RGBA_5551:
Mask[0] = 0x7c00;
Mask[1] = 0x3e0;
Mask[2] = 0x1f;
Mask[3] = 0x8000;
break;
case RGB_555:
Mask[0] = 0x7c00;
Mask[1] = 0x3e0;
......@@ -432,6 +452,7 @@ WriteBMP (const gchar *filename,
Mask[3] = 0x0;
break;
}
FromL (Mask[0], &puffer[0x00]);
FromL (Mask[1], &puffer[0x04]);
FromL (Mask[2], &puffer[0x08]);
......@@ -443,7 +464,8 @@ WriteBMP (const gchar *filename,
write_image (outfile,
pixels, cols, rows,
encoded, channels, BitsPerPixel, SpZeile, MapSize, rgb_format);
BMPSaveData.encoded, channels, BitsPerPixel, SpZeile, MapSize,
BMPSaveData.rgb_format);
/* ... and exit normally */
......@@ -515,7 +537,7 @@ write_image (FILE *f,
buf[1] = *temp++;
buf[0] = *temp++;
xpos++;
if (channels > 3 && *temp == 0)
if (channels > 3 && (guchar) *temp == 0)
buf[0] = buf[1] = buf[2] = 0xff;
Write (f, buf, 3);
break;
......@@ -525,7 +547,7 @@ write_image (FILE *f,
buf[2] = *temp++;
buf[1] = *temp++;
xpos++;
if (channels > 3 && *temp == 0)
if (channels > 3 && (guchar) *temp == 0)
buf[0] = buf[1] = buf[2] = 0xff;
Write (f, buf, 4);
break;
......@@ -541,7 +563,7 @@ write_image (FILE *f,
r = *temp++;
g = *temp++;
b = *temp++;
if (channels > 3 && *temp == 0)
if (channels > 3 && (guchar) *temp == 0)
r = g = b = 0xff;
Make565 (r, g, b, buf);
xpos++;
......@@ -551,7 +573,7 @@ write_image (FILE *f,
r = *temp++;
g = *temp++;
b = *temp++;
if (channels > 3 && *temp == 0)
if (channels > 3 && (guchar) *temp == 0)
r = g = b = 0xff;
Make5551 (r, g, b, 0x0, buf);
xpos++;
......@@ -746,74 +768,29 @@ write_image (FILE *f,
gimp_progress_update (1);
}
static gboolean
save_dialog (void)
{
GtkWidget *dialog;
GtkWidget *toggle;
GtkWidget *vbox;
gboolean run;
dialog = gimp_dialog_new (_("Save as BMP"), "bmp",
NULL, 0,
gimp_standard_help_func, "file-bmp-save",
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_SAVE, GTK_RESPONSE_OK,
NULL);
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
GTK_RESPONSE_OK,
GTK_RESPONSE_CANCEL,
-1);
gimp_window_set_transient (GTK_WINDOW (dialog));
vbox = gtk_vbox_new (FALSE, 12);
gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), vbox);
gtk_widget_show (vbox);
toggle = gtk_check_button_new_with_mnemonic (_("_Run-Length Encoded"));
gtk_box_pack_start (GTK_BOX (vbox), toggle, FALSE, FALSE, 0);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), encoded);
gtk_widget_show (toggle);
g_signal_connect (toggle, "toggled",
G_CALLBACK (gimp_toggle_button_update),
&encoded);
gtk_widget_show (dialog);
run = (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_OK);
gtk_widget_destroy (dialog);
return run;
}
static void
format_callback (GtkWidget *widget,
gpointer *data)
{
rgb_format = GPOINTER_TO_INT (data);
BMPSaveData.rgb_format = GPOINTER_TO_INT (data);
}
static gboolean
save_dialog_rgb (gint channels)
save_dialog (gint channels)
{
GtkWidget *dialog;
GtkWidget *toggle;
GtkWidget *vbox_main;
GtkWidget *vbox;
GtkWidget *vbox2;
GtkWidget *expander;
GtkWidget *frame;
GSList *group;
gboolean run;
dialog = gimp_dialog_new (_("Save as BMP"), "bmp",
NULL, 0,
gimp_standard_help_func, "file-bmp-save",
gimp_standard_help_func, SAVE_PROC,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_SAVE, GTK_RESPONSE_OK,
......@@ -827,15 +804,42 @@ save_dialog_rgb (gint channels)
gimp_window_set_transient (GTK_WINDOW (dialog));
gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
vbox_main = gtk_vbox_new (FALSE, 12);
gtk_container_set_border_width (GTK_CONTAINER (vbox_main), 12);
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), vbox_main);
gtk_widget_show (vbox_main);
toggle = gtk_check_button_new_with_mnemonic (_("_Run-Length Encoded"));
gtk_box_pack_start (GTK_BOX (vbox_main), toggle, FALSE, FALSE, 0);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle),
BMPSaveData.encoded);
gtk_widget_show (toggle);
if (channels > 1)
gtk_widget_set_sensitive (toggle, FALSE);
g_signal_connect (toggle, "toggled",
G_CALLBACK (gimp_toggle_button_update),
&BMPSaveData.encoded);
expander = gtk_expander_new_with_mnemonic (_("_Advanced Options"));
gtk_box_pack_start (GTK_BOX (vbox_main), expander, TRUE, TRUE, 0);
gtk_widget_show (expander);
if (channels < 3)
gtk_widget_set_sensitive (expander, FALSE);
vbox2 = gtk_vbox_new (FALSE, 12);
gtk_container_set_border_width (GTK_CONTAINER (vbox2), 12);
gtk_container_add (GTK_CONTAINER (expander), vbox2);
gtk_widget_show (vbox2);
group = NULL;
frame = gimp_frame_new (_("16 bits"));
gtk_box_pack_start (GTK_BOX (vbox_main), frame, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (vbox2), frame, TRUE, TRUE, 0);
gtk_widget_show (frame);
vbox = gtk_vbox_new (FALSE, 6);
......@@ -853,8 +857,10 @@ save_dialog_rgb (gint channels)
toggle = gtk_radio_button_new_with_label (group, "A1 R5 G5 B5");
group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (toggle));
gtk_box_pack_start (GTK_BOX (vbox), toggle, FALSE, FALSE, 0);
if (channels < 4)
gtk_widget_set_sensitive (toggle, FALSE);
gtk_widget_show (toggle);
g_signal_connect (toggle, "pressed",
......@@ -869,7 +875,7 @@ save_dialog_rgb (gint channels)
GINT_TO_POINTER (RGB_555));
frame = gimp_frame_new (_("24 bits"));
gtk_box_pack_start (GTK_BOX (vbox_main), frame, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (vbox2), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
toggle = gtk_radio_button_new_with_label (group, "R8 G8 B8");
......@@ -879,10 +885,14 @@ save_dialog_rgb (gint channels)
g_signal_connect (toggle, "pressed",
G_CALLBACK (format_callback),
GINT_TO_POINTER (RGB_888));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), TRUE);
if (channels < 4)
{
BMPSaveData.rgb_format = RGB_888;
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), TRUE);
}
frame = gimp_frame_new (_("32 bits"));
gtk_box_pack_start (GTK_BOX (vbox_main), frame, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (vbox2), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
vbox = gtk_vbox_new (FALSE, 6);
......@@ -892,8 +902,17 @@ save_dialog_rgb (gint channels)
toggle = gtk_radio_button_new_with_label (group, "A8 R8 G8 B8");
group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (toggle));
gtk_container_add (GTK_CONTAINER (vbox), toggle);
if (channels < 4)
gtk_widget_set_sensitive (toggle, FALSE);
{
gtk_widget_set_sensitive (toggle, FALSE);
}
else
{
BMPSaveData.rgb_format = RGBA_8888;
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), TRUE);
}
gtk_widget_show (toggle);
g_signal_connect (toggle, "pressed",
G_CALLBACK (format_callback),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment