Commit 65d4c193 authored by Adam D. Moss's avatar Adam D. Moss
Browse files

Attempt to use the palette colour closest to that of the GIMP's current


	* plug-ins/common/gif.c: Attempt to use the palette colour
	closest to that of the GIMP's current brush background colour
	for the GIF file's background index hint for non-transparency-aware
	image viewers.  NOTE that this is merely a hint and may be
	ignored by this plugin for various (rare) reasons that
	would usually entail writing a somewhat larger image file.
parent 98fc5e38
2003-06-16 Adam D. Moss <adam@gimp.org>
* plug-ins/common/gif.c: Attempt to use the palette colour
closest to that of the GIMP's current brush background colour
for the GIF file's background index hint for non-transparency-aware
image viewers. NOTE that this is merely a hint and may be
ignored by this plugin for various (rare) reasons that
would usually entail writing a somewhat larger image file.
2003-06-16 Sven Neumann <sven@gimp.org>
 
* libgimpcolor/gimpcolorspace.c: Applied a patch from S. Mukund
/* GIF saving file filter for The GIMP version 1.0/1.1
/* GIF saving file filter for The GIMP version 1.3/1.4
*
* Copyright
* - Adam D. Moss
* - Peter Mattis
* - Spencer Kimball
......@@ -7,7 +8,7 @@
* Based around original GIF code by David Koblas.
*
*
* Version 3.0.2 - 99/04/25
* Version 4.1.0 - 2003-06-16
* Adam D. Moss - <adam@gimp.org> <adam@foxbox.org>
*/
/*
......@@ -28,6 +29,15 @@
/*
* REVISION HISTORY
*
* 2003-06-16
* 4.01.00 - Attempt to use the palette colour closest to that of the
* GIMP's current brush background colour for the GIF file's
* background index hint for non-transparency-aware image
* viewers. NOTE that this is merely a hint and may be
* ignored by this plugin for various (rare) reasons that
* would usually entail writing a somewhat larger image file.
* + major version bump to indicate 1.3/1.4 branch.
*
* 99/04/25
* 3.00.02 - Save the comment back onto the image as a persistent
* parasite if the comment was edited.
......@@ -600,13 +610,11 @@ static int GIFNextPixel (ifunptr);
static void GIFEncodeHeader (FILE *, gboolean, int, int, int, int,
int *, int *, int *, ifunptr);
static void GIFEncodeGraphicControlExt (FILE *, int, int, int, int, int,
int, int, int, int *, int *, int *,
ifunptr);
static void GIFEncodeImageData (FILE *, int, int, int, int, int, int,
int *, int *, int *, ifunptr, gint, gint);
static void GIFEncodeClose (FILE *, int, int, int, int, int, int,
int *, int *, int *, ifunptr);
static void GIFEncodeGraphicControlExt (FILE *, int, int, int, int,
int, int, int, ifunptr);
static void GIFEncodeImageData (FILE *, int, int, int, int,
ifunptr, gint, gint);
static void GIFEncodeClose (FILE *);
static void GIFEncodeLoopExt (FILE *, guint);
static void GIFEncodeCommentExt (FILE *, char *);
......@@ -865,6 +873,8 @@ save_image (gchar *filename,
GimpRGB background;
guchar bgred, bggreen, bgblue;
guchar bgindex = 0;
guint best_error = 0xFFFFFFFF;
#ifdef FACEHUGGERS
......@@ -936,6 +946,21 @@ save_image (gchar *filename,
return FALSE;
break;
}
/* find earliest index in palette which is closest to the background
colour, and ATTEMPT to use that as the GIF's default background colour. */
for (i=255; i>=0; --i) {
unsigned int local_error = 0;
local_error += (Red[i] - bgred) * (Red[i] - bgred);
local_error += (Green[i] - bggreen) * (Green[i] - bggreen);
local_error += (Blue[i] - bgblue) * (Blue[i] - bgblue);
if (local_error <= best_error) {
bgindex = i;
best_error = local_error;
}
}
/* open the destination file for writing */
outfile = fopen (filename, "wb");
......@@ -977,7 +1002,7 @@ save_image (gchar *filename,
cols = gimp_image_width (image_ID);
rows = gimp_image_height (image_ID);
Interlace = gsvals.interlace;
GIFEncodeHeader (outfile, is_gif89, cols, rows, 0,
GIFEncodeHeader (outfile, is_gif89, cols, rows, bgindex,
BitsPerPixel, Red, Green, Blue, GetPixel);
......@@ -1051,12 +1076,21 @@ save_image (gchar *filename,
/* We were able to re-use an index within the existing bitspace,
whereas the estimate in the header was pessimistic but still
needs to be upheld... */
static gboolean onceonly = FALSE;
if (!onceonly)
{
#ifdef GIFDEBUG
g_warning("Promised %d bpp, pondered writing chunk with %d bpp!",
liberalBPP, BitsPerPixel);
g_warning("Promised %d bpp, pondered writing chunk with %d bpp!",
liberalBPP, BitsPerPixel);
#endif
g_warning ("Transparent colour *might* be incorrect "
"on viewers which don't support transparency.");
g_message ("GIF plugin: "
"Warning: "
"Transparent colour in written file *might* be "
"incorrect on viewers which don't support "
"transparency.");
onceonly = TRUE;
}
}
useBPP = (BitsPerPixel > liberalBPP) ? BitsPerPixel : liberalBPP;
......@@ -1090,7 +1124,7 @@ save_image (gchar *filename,
if (!onceonly)
{
g_warning("GIF plugin: Delay inserted to prevent evil "
g_message("GIF plugin: Delay inserted to prevent evil "
"CPU-sucking anim.\n");
onceonly = TRUE;
}
......@@ -1098,18 +1132,16 @@ save_image (gchar *filename,
}
GIFEncodeGraphicControlExt (outfile, Disposal, Delay89, nlayers,
cols, rows, 0,
cols, rows,
transparent,
useBPP,
Red, Green,
Blue, GetPixel);
GetPixel);
}
GIFEncodeImageData (outfile, cols, rows,
(rows>4) ? gsvals.interlace : 0,
0, transparent,
useBPP,
Red, Green, Blue, GetPixel,
GetPixel,
offset_x, offset_y);
......@@ -1123,8 +1155,7 @@ save_image (gchar *filename,
g_free(layers);
GIFEncodeClose (outfile, cols, rows, gsvals.interlace, 0, transparent,
useBPP, Red, Green, Blue, GetPixel);
GIFEncodeClose (outfile);
return TRUE;
}
......@@ -1670,12 +1701,8 @@ GIFEncodeGraphicControlExt (FILE *fp,
int NumFramesInImage,
int GWidth,
int GHeight,
int Background,
int Transparent,
int BitsPerPixel,
int Red[],
int Green[],
int Blue[],
ifunptr GetPixel)
{
int RWidth, RHeight;
......@@ -1753,12 +1780,7 @@ GIFEncodeImageData (FILE *fp,
int GWidth,
int GHeight,
int GInterlace,
int Background,
int Transparent,
int BitsPerPixel,
int Red[],
int Green[],
int Blue[],
ifunptr GetPixel,
gint offset_x,
gint offset_y)
......@@ -1910,17 +1932,7 @@ GIFEncodeImageData (FILE *fp,
static void
GIFEncodeClose (FILE *fp,
int GWidth,
int GHeight,
int GInterlace,
int Background,
int Transparent,
int BitsPerPixel,
int Red[],
int Green[],
int Blue[],
ifunptr GetPixel)
GIFEncodeClose (FILE *fp)
{
/*
* Write the GIF file terminator
......
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