Fix for #102562 + minor clean-up of bmp plug-in

This commit is contained in:
Maurits Rijk
2003-01-05 15:48:32 +00:00
parent 50c8c56fe0
commit 0eccb0fec1
9 changed files with 113 additions and 137 deletions

View File

@ -1,3 +1,9 @@
2003-01-05 Maurits Rijk <lpeek.mrijk@consunet.nl>
* libgimp/gimpmisc.c (gimp_pixel_fetcher_get_pixel2): x and y
coordinates have to be clamped on image width/height - 1. Fixes
#102562
2003-01-05 Sven Neumann <sven@gimp.org> 2003-01-05 Sven Neumann <sven@gimp.org>
* libgimpwidgets/gimpchainbutton.[ch] * libgimpwidgets/gimpchainbutton.[ch]
@ -63,6 +69,13 @@
return the offset. Finally allows to handle swap files larger than return the offset. Finally allows to handle swap files larger than
2 GB (fixes bug #74478). 2 GB (fixes bug #74478).
2003-01-03 Maurits Rijk <lpeek.mrijk@consunet.nl>
* plug-ins/bmp/bmpread.c
* plug-ins/bmp/bmpwrite.c
* plug-ins/bmp/bmp.[ch]: added mnemonics to save dialog. Minor code
clean-up.
2003-01-03 Sven Neumann <sven@gimp.org> 2003-01-03 Sven Neumann <sven@gimp.org>
* configure.in: bumped the version number to 1.3.12. * configure.in: bumped the version number to 1.3.12.

View File

@ -197,8 +197,8 @@ gimp_pixel_fetcher_get_pixel2 (GimpPixelFetcher *pf,
} }
break; break;
case PIXEL_SMEAR: case PIXEL_SMEAR:
x = CLAMP (x, 0, pf->img_width); x = CLAMP (x, 0, pf->img_width - 1);
y = CLAMP (y, 0, pf->img_height); y = CLAMP (y, 0, pf->img_height - 1);
break; break;
case PIXEL_BLACK: case PIXEL_BLACK:
if (x < 0 || x >= pf->img_width || if (x < 0 || x >= pf->img_width ||

View File

@ -197,8 +197,8 @@ gimp_pixel_fetcher_get_pixel2 (GimpPixelFetcher *pf,
} }
break; break;
case PIXEL_SMEAR: case PIXEL_SMEAR:
x = CLAMP (x, 0, pf->img_width); x = CLAMP (x, 0, pf->img_width - 1);
y = CLAMP (y, 0, pf->img_height); y = CLAMP (y, 0, pf->img_height - 1);
break; break;
case PIXEL_BLACK: case PIXEL_BLACK:
if (x < 0 || x >= pf->img_width || if (x < 0 || x >= pf->img_width ||

View File

@ -197,8 +197,8 @@ gimp_pixel_fetcher_get_pixel2 (GimpPixelFetcher *pf,
} }
break; break;
case PIXEL_SMEAR: case PIXEL_SMEAR:
x = CLAMP (x, 0, pf->img_width); x = CLAMP (x, 0, pf->img_width - 1);
y = CLAMP (y, 0, pf->img_height); y = CLAMP (y, 0, pf->img_height - 1);
break; break;
case PIXEL_BLACK: case PIXEL_BLACK:
if (x < 0 || x >= pf->img_width || if (x < 0 || x >= pf->img_width ||

View File

@ -63,10 +63,9 @@
#include "libgimp/stdplugins-intl.h" #include "libgimp/stdplugins-intl.h"
FILE *errorfile;
gchar *prog_name = "bmp"; gchar *prog_name = "bmp";
gchar *filename; gchar *filename;
gint interactive_bmp; gboolean interactive_bmp;
struct Bitmap_File_Head_Struct Bitmap_File_Head; struct Bitmap_File_Head_Struct Bitmap_File_Head;
struct Bitmap_Head_Struct Bitmap_Head; struct Bitmap_Head_Struct Bitmap_Head;
@ -271,32 +270,3 @@ run (gchar *name,
values[0].data.d_status = status; values[0].data.d_status = status;
} }
gint32
ToL (guchar *puffer)
{
return (puffer[0] | puffer[1]<<8 | puffer[2]<<16 | puffer[3]<<24);
}
gint16
ToS (guchar *puffer)
{
return (puffer[0] | puffer[1]<<8);
}
void
FromL (gint32 wert,
guchar *bopuffer)
{
bopuffer[0] = (wert & 0x000000ff)>>0x00;
bopuffer[1] = (wert & 0x0000ff00)>>0x08;
bopuffer[2] = (wert & 0x00ff0000)>>0x10;
bopuffer[3] = (wert & 0xff000000)>>0x18;
}
void
FromS (gint16 wert,
guchar *bopuffer)
{
bopuffer[0] = (wert & 0x00ff)>>0x00;
bopuffer[1] = (wert & 0xff00)>>0x08;
}

View File

@ -9,21 +9,10 @@
#define Write(file,buffer,len) fwrite(buffer, len, 1, file) #define Write(file,buffer,len) fwrite(buffer, len, 1, file)
#define WriteOK(file,buffer,len) (Write(buffer, len, file) != 0) #define WriteOK(file,buffer,len) (Write(buffer, len, file) != 0)
extern gint32 ToL (guchar *);
extern void FromL (gint32,
guchar *);
extern gint16 ToS (guchar *);
extern void FromS (gint16,
guchar *);
extern gint32 ReadBMP (gchar *); extern gint32 ReadBMP (gchar *);
extern GimpPDBStatusType WriteBMP (gchar *, extern GimpPDBStatusType WriteBMP (gchar *,
gint32, gint32,
gint32); gint32);
extern gint ReadColorMap (FILE *,
guchar[256][3],
gint,
gint,
gint *);
extern Image ReadImage (FILE *, extern Image ReadImage (FILE *,
gint, gint,
gint, gint,
@ -33,11 +22,6 @@ extern Image ReadImage (FILE *,
gint, gint,
gint, gint,
gint); gint);
extern void WriteColorMap (FILE *,
gint *,
gint *,
gint *,
gint);
extern void WriteImage (FILE *, extern void WriteImage (FILE *,
guchar *, guchar *,
gint, gint,
@ -48,10 +32,9 @@ extern void WriteImage (FILE *,
gint, gint,
gint); gint);
extern gint interactive_bmp; extern gboolean interactive_bmp;
extern gchar *prog_name; extern gchar *prog_name;
extern gchar *filename; extern gchar *filename;
extern FILE *errorfile;
extern struct Bitmap_File_Head_Struct extern struct Bitmap_File_Head_Struct
{ {

View File

@ -36,6 +36,47 @@
#include "libgimp/stdplugins-intl.h" #include "libgimp/stdplugins-intl.h"
static gint32
ToL (guchar *puffer)
{
return (puffer[0] | puffer[1]<<8 | puffer[2]<<16 | puffer[3]<<24);
}
static gint16
ToS (guchar *puffer)
{
return (puffer[0] | puffer[1]<<8);
}
static gboolean
ReadColorMap (FILE *fd,
guchar buffer[256][3],
gint number,
gint size,
gint *grey)
{
gint i;
guchar rgb[4];
*grey=(number>2);
for (i = 0; i < number ; i++)
{
if (!ReadOK (fd, rgb, size))
{
g_message (_("%s: bad colormap"), prog_name);
return FALSE;
}
/* Bitmap save the colors in another order! But change only once! */
buffer[i][0] = rgb[2];
buffer[i][1] = rgb[1];
buffer[i][2] = rgb[0];
*grey = ((*grey) && (rgb[0]==rgb[1]) && (rgb[1]==rgb[2]));
}
return TRUE;
}
gint32 gint32
ReadBMP (gchar *name) ReadBMP (gchar *name)
{ {
@ -219,7 +260,7 @@ ReadBMP (gchar *name)
/* Get the Colormap */ /* Get the Colormap */
if (ReadColorMap (fd, ColorMap, ColormapSize, Maps, &Grey) == -1) if (!ReadColorMap (fd, ColorMap, ColormapSize, Maps, &Grey))
return -1; return -1;
#ifdef DEBUG #ifdef DEBUG
@ -259,35 +300,6 @@ ReadBMP (gchar *name)
return (image_ID); return (image_ID);
} }
gint
ReadColorMap (FILE *fd,
guchar buffer[256][3],
gint number,
gint size,
gint *grey)
{
gint i;
guchar rgb[4];
*grey=(number>2);
for (i = 0; i < number ; i++)
{
if (!ReadOK (fd, rgb, size))
{
g_message (_("%s: bad colormap"), prog_name);
return -1;
}
/* Bitmap save the colors in another order! But change only once! */
buffer[i][0] = rgb[2];
buffer[i][1] = rgb[1];
buffer[i][2] = rgb[0];
*grey = ((*grey) && (rgb[0]==rgb[1]) && (rgb[1]==rgb[2]));
}
return 0;
}
Image Image
ReadImage (FILE *fd, ReadImage (FILE *fd,
gint width, gint width,

View File

@ -45,10 +45,8 @@
#include "libgimp/stdplugins-intl.h" #include "libgimp/stdplugins-intl.h"
guchar *pixels; static gint cur_progress;
gint cur_progress; static gint max_progress;
gint max_progress;
typedef struct typedef struct
{ {
@ -60,13 +58,52 @@ static BMPSaveInterface gsint =
FALSE /* run */ FALSE /* run */
}; };
gint encoded = 0; static gint encoded = 0;
static gint save_dialog (void); static gint save_dialog (void);
static void save_ok_callback (GtkWidget *widget, static void save_ok_callback (GtkWidget *widget,
gpointer data); gpointer data);
static void
FromL (gint32 wert,
guchar *bopuffer)
{
bopuffer[0] = (wert & 0x000000ff)>>0x00;
bopuffer[1] = (wert & 0x0000ff00)>>0x08;
bopuffer[2] = (wert & 0x00ff0000)>>0x10;
bopuffer[3] = (wert & 0xff000000)>>0x18;
}
static void
FromS (gint16 wert,
guchar *bopuffer)
{
bopuffer[0] = (wert & 0x00ff)>>0x00;
bopuffer[1] = (wert & 0xff00)>>0x08;
}
static void
WriteColorMap (FILE *f,
gint red[MAXCOLORS],
gint green[MAXCOLORS],
gint blue[MAXCOLORS],
gint size)
{
gchar trgb[4];
gint i;
size /= 4;
trgb[3] = 0;
for (i = 0; i < size; i++)
{
trgb[0] = (guchar) blue[i];
trgb[1] = (guchar) green[i];
trgb[2] = (guchar) red[i];
Write (f, trgb, 4);
}
}
GimpPDBStatusType GimpPDBStatusType
WriteBMP (gchar *filename, WriteBMP (gchar *filename,
gint32 image, gint32 image,
@ -94,16 +131,10 @@ WriteBMP (gchar *filename,
drawable_type = gimp_drawable_type(drawable_ID); drawable_type = gimp_drawable_type(drawable_ID);
gimp_pixel_rgn_init (&pixel_rgn, drawable, gimp_pixel_rgn_init (&pixel_rgn, drawable,
0, 0, drawable->width, drawable->height, FALSE, FALSE); 0, 0, drawable->width, drawable->height, FALSE, FALSE);
switch (drawable_type) if (gimp_drawable_has_alpha(drawable_ID))
{ {
case GIMP_RGB_IMAGE:
case GIMP_GRAY_IMAGE:
case GIMP_INDEXED_IMAGE:
break;
default:
g_message(_("BMP: cannot operate on unknown image types or alpha images")); g_message(_("BMP: cannot operate on unknown image types or alpha images"));
return GIMP_PDB_EXECUTION_ERROR; return GIMP_PDB_EXECUTION_ERROR;
break;
} }
/* We can save it. So what colors do we use? */ /* We can save it. So what colors do we use? */
@ -297,28 +328,7 @@ WriteBMP (gchar *filename,
return GIMP_PDB_SUCCESS; return GIMP_PDB_SUCCESS;
} }
void static void
WriteColorMap (FILE *f,
gint red[MAXCOLORS],
gint green[MAXCOLORS],
gint blue[MAXCOLORS],
gint size)
{
gchar trgb[4];
gint i;
size /= 4;
trgb[3] = 0;
for (i = 0; i < size; i++)
{
trgb[0] = (guchar) blue[i];
trgb[1] = (guchar) green[i];
trgb[2] = (guchar) red[i];
Write (f, trgb, 4);
}
}
void
WriteImage (FILE *f, WriteImage (FILE *f,
guchar *src, guchar *src,
gint width, gint width,
@ -413,7 +423,6 @@ WriteImage (FILE *f,
ketten = (guchar *) g_malloc (width / (8 / bpp) + 10); ketten = (guchar *) g_malloc (width / (8 / bpp) + 10);
for (ypos = height - 1; ypos >= 0; ypos--) for (ypos = height - 1; ypos >= 0; ypos--)
{ /* each row separately */ { /* each row separately */
/*printf("Line: %i\n",ypos); */
j = 0; j = 0;
/* first copy the pixels to a buffer, /* first copy the pixels to a buffer,
* making one byte from two 4bit pixels * making one byte from two 4bit pixels
@ -443,10 +452,8 @@ WriteImage (FILE *f,
j++; j++;
ketten[i] = j; ketten[i] = j;
/*printf("%i:",ketten[i]); */
i += j; i += j;
} }
/*printf("\n"); */
/* then write the strings and the other pixels to the file */ /* then write the strings and the other pixels to the file */
for (i = 0; i < breite;) for (i = 0; i < breite;)
@ -475,16 +482,12 @@ WriteImage (FILE *f,
Write (f, &n, 1); Write (f, &n, 1);
laenge += 2; laenge += 2;
Write (f, &Zeile[i], j); Write (f, &Zeile[i], j);
/*printf("0.%i.",n); */
/*for (k=j;k;k--) printf("#"); */
laenge += j; laenge += j;
if ((j) % 2) if ((j) % 2)
{ {
Write (f, &buf[12], 1); Write (f, &buf[12], 1);
laenge++; laenge++;
/*printf("0"); */
} }
/*printf("|"); */
} }
else else
{ {
@ -509,12 +512,10 @@ WriteImage (FILE *f,
n--; n--;
Write (f, &n, 1); Write (f, &n, 1);
Write (f, &Zeile[i], 1); Write (f, &Zeile[i], 1);
/*printf("%i.#|",n); */
i += ketten[i]; i += ketten[i];
laenge += 2; laenge += 2;
} }
} }
/*printf("\n"); */
Write (f, &buf[14], 2); /* End of row */ Write (f, &buf[14], 2); /* End of row */
laenge += 2; laenge += 2;
@ -578,7 +579,7 @@ save_dialog (void)
gtk_container_set_border_width (GTK_CONTAINER (vbox), 4); gtk_container_set_border_width (GTK_CONTAINER (vbox), 4);
gtk_container_add (GTK_CONTAINER (frame), vbox); gtk_container_add (GTK_CONTAINER (frame), vbox);
toggle = gtk_check_button_new_with_label (_("RLE encoded")); toggle = gtk_check_button_new_with_mnemonic (_("_RLE encoded"));
gtk_box_pack_start (GTK_BOX (vbox), toggle, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox), toggle, FALSE, FALSE, 0);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), encoded); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), encoded);
gtk_widget_show (toggle); gtk_widget_show (toggle);

View File

@ -27,7 +27,8 @@ VPATH = @srcdir@
prefix = @prefix@ prefix = @prefix@
exec_prefix = @exec_prefix@ exec_prefix = @exec_prefix@
datadir = @datadir@ datadir = @datadir@
localedir = $(datadir)/locale libdir = @libdir@
localedir = $(libdir)/locale
gnulocaledir = $(datadir)/locale gnulocaledir = $(datadir)/locale
gettextsrcdir = $(datadir)/glib-2.0/gettext/po gettextsrcdir = $(datadir)/glib-2.0/gettext/po
subdir = po subdir = po
@ -38,13 +39,10 @@ MKINSTALLDIRS = $(top_srcdir)/@MKINSTALLDIRS@
CC = @CC@ CC = @CC@
GENCAT = @GENCAT@ GENCAT = @GENCAT@
GMSGFMT = PATH=../src:$$PATH @GMSGFMT@ GMSGFMT = @GMSGFMT@
MSGFMT = @MSGFMT@ MSGFMT = @MSGFMT@
XGETTEXT = PATH=../src:$$PATH @XGETTEXT@ XGETTEXT = @XGETTEXT@
INTLTOOL_UPDATE = @INTLTOOL_UPDATE@ MSGMERGE = msgmerge
INTLTOOL_EXTRACT = @INTLTOOL_EXTRACT@
MSGMERGE = INTLTOOL_EXTRACT=$(INTLTOOL_EXTRACT) $(INTLTOOL_UPDATE) --gettext-package $(GETTEXT_PACKAGE) --dist
GENPOT = INTLTOOL_EXTRACT=$(INTLTOOL_EXTRACT) $(INTLTOOL_UPDATE) --gettext-package $(GETTEXT_PACKAGE) --pot
DEFS = @DEFS@ DEFS = @DEFS@
CFLAGS = @CFLAGS@ CFLAGS = @CFLAGS@
@ -197,7 +195,6 @@ dist distdir: update-po $(DISTFILES)
update-po: Makefile update-po: Makefile
$(MAKE) $(GETTEXT_PACKAGE).pot $(MAKE) $(GETTEXT_PACKAGE).pot
PATH=`pwd`/../src:$$PATH; \
cd $(srcdir); \ cd $(srcdir); \
catalogs='$(CATALOGS)'; \ catalogs='$(CATALOGS)'; \
for cat in $$catalogs; do \ for cat in $$catalogs; do \