Fixed erroneously reported warning message when saving indexed layers with
2004-07-14 Philip Lafleur <plafleur@cvs.gnome.org> * plug-ins/common/png.c: * plug-ins/common/mng.c: Fixed erroneously reported warning message when saving indexed layers with an alpha channel but no transparent pixels.
This commit is contained in:

committed by
Philip Lafleur

parent
deb8f7bfc4
commit
6f6c71d01c
@ -1,3 +1,10 @@
|
|||||||
|
2004-07-14 Philip Lafleur <plafleur@cvs.gnome.org>
|
||||||
|
|
||||||
|
* plug-ins/common/png.c:
|
||||||
|
* plug-ins/common/mng.c: Fixed erroneously reported warning
|
||||||
|
message when saving indexed layers with an alpha channel but
|
||||||
|
no transparent pixels.
|
||||||
|
|
||||||
2004-07-14 Sven Neumann <sven@gimp.org>
|
2004-07-14 Sven Neumann <sven@gimp.org>
|
||||||
|
|
||||||
* app/app_procs.c (app_run): register a log handler for the
|
* app/app_procs.c (app_run): register a log handler for the
|
||||||
|
@ -347,6 +347,20 @@ find_unused_ia_colour (guchar *pixels,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
ia_has_transparent_pixels (guchar *pixels,
|
||||||
|
gint numpixels)
|
||||||
|
{
|
||||||
|
while (numpixels --)
|
||||||
|
{
|
||||||
|
if (pixels [1] <= 127)
|
||||||
|
return TRUE;
|
||||||
|
pixels += 2;
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Spins the color map (palette) putting the transparent color at
|
/* Spins the color map (palette) putting the transparent color at
|
||||||
* index 0 if there is space. If there isn't any space, warn the user
|
* index 0 if there is space. If there isn't any space, warn the user
|
||||||
* and forget about transparency. Returns TRUE if the colormap has
|
* and forget about transparency. Returns TRUE if the colormap has
|
||||||
@ -363,6 +377,7 @@ respin_cmap (png_structp png_ptr,
|
|||||||
static guchar trans[] = { 0 };
|
static guchar trans[] = { 0 };
|
||||||
guchar *before;
|
guchar *before;
|
||||||
guchar *pixels;
|
guchar *pixels;
|
||||||
|
gint numpixels;
|
||||||
gint colors;
|
gint colors;
|
||||||
gint transparent;
|
gint transparent;
|
||||||
gint cols, rows;
|
gint cols, rows;
|
||||||
@ -379,48 +394,58 @@ respin_cmap (png_structp png_ptr,
|
|||||||
colors = 1;
|
colors = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
cols = drawable->width;
|
cols = drawable->width;
|
||||||
rows = drawable->height;
|
rows = drawable->height;
|
||||||
|
numpixels = cols * rows;
|
||||||
|
|
||||||
gimp_pixel_rgn_init (&pixel_rgn, drawable, 0, 0,
|
gimp_pixel_rgn_init (&pixel_rgn, drawable, 0, 0,
|
||||||
drawable->width, drawable->height, FALSE, FALSE);
|
drawable->width, drawable->height, FALSE, FALSE);
|
||||||
|
|
||||||
pixels = (guchar *) g_malloc (drawable->width * drawable->height * 2);
|
pixels = (guchar *) g_malloc (numpixels * 2);
|
||||||
|
|
||||||
gimp_pixel_rgn_get_rect (&pixel_rgn, pixels, 0, 0,
|
gimp_pixel_rgn_get_rect (&pixel_rgn, pixels, 0, 0,
|
||||||
drawable->width, drawable->height);
|
drawable->width, drawable->height);
|
||||||
|
|
||||||
transparent = find_unused_ia_colour (pixels,
|
if (ia_has_transparent_pixels (pixels, numpixels))
|
||||||
drawable->width * drawable->height,
|
|
||||||
&colors);
|
|
||||||
|
|
||||||
if (transparent != -1)
|
|
||||||
{
|
{
|
||||||
png_color palette[256];
|
transparent = find_unused_ia_colour (pixels, numpixels, &colors);
|
||||||
gint i;
|
|
||||||
|
|
||||||
png_set_tRNS (png_ptr, png_info_ptr, (png_bytep) trans, 1, NULL);
|
if (transparent != -1)
|
||||||
|
|
||||||
remap[0] = transparent;
|
|
||||||
remap[transparent] = 0;
|
|
||||||
|
|
||||||
for (i = 0; i < colors; i++)
|
|
||||||
{
|
{
|
||||||
palette[i].red = before[3 * remap[i]];
|
png_color palette[256];
|
||||||
palette[i].green = before[3 * remap[i] + 1];
|
gint i;
|
||||||
palette[i].blue = before[3 * remap[i] + 2];
|
|
||||||
|
png_set_tRNS (png_ptr, png_info_ptr, (png_bytep) trans, 1, NULL);
|
||||||
|
|
||||||
|
/* Transform all pixels with a value = transparent to
|
||||||
|
* 0 and vice versa to compensate for re-ordering in palette
|
||||||
|
* due to png_set_tRNS() */
|
||||||
|
|
||||||
|
remap[0] = transparent;
|
||||||
|
remap[transparent] = 0;
|
||||||
|
|
||||||
|
/* Copy from index 0 to index transparent - 1 to index 1 to
|
||||||
|
* transparent of after, then from transparent+1 to colors-1
|
||||||
|
* unchanged, and finally from index transparent to index 0. */
|
||||||
|
|
||||||
|
for (i = 0; i < colors; i++)
|
||||||
|
{
|
||||||
|
palette[i].red = before[3 * remap[i]];
|
||||||
|
palette[i].green = before[3 * remap[i] + 1];
|
||||||
|
palette[i].blue = before[3 * remap[i] + 2];
|
||||||
|
}
|
||||||
|
|
||||||
|
png_set_PLTE (png_ptr, png_info_ptr, (png_colorp) palette, colors);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
png_set_PLTE (png_ptr, png_info_ptr, (png_colorp) palette, colors);
|
g_message (_("Couldn't losslessly save transparency, "
|
||||||
|
"saving opacity instead."));
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
g_message ("Couldn't losslessly save transparency, so saving opacity instead.");
|
|
||||||
png_set_PLTE (png_ptr, png_info_ptr, (png_colorp) before, colors);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
png_set_PLTE (png_ptr, png_info_ptr, (png_colorp) before, colors);
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,40 +109,43 @@ PngSaveGui;
|
|||||||
* Local functions...
|
* Local functions...
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void query (void);
|
static void query (void);
|
||||||
static void run (const gchar *name,
|
static void run (const gchar *name,
|
||||||
gint nparams,
|
gint nparams,
|
||||||
const GimpParam *param,
|
const GimpParam *param,
|
||||||
gint *nreturn_vals,
|
gint *nreturn_vals,
|
||||||
GimpParam **return_vals);
|
GimpParam **return_vals);
|
||||||
|
|
||||||
static gint32 load_image (const gchar *filename,
|
static gint32 load_image (const gchar *filename,
|
||||||
gboolean interactive);
|
gboolean interactive);
|
||||||
static gint save_image (const gchar *filename,
|
static gint save_image (const gchar *filename,
|
||||||
gint32 image_ID,
|
gint32 image_ID,
|
||||||
gint32 drawable_ID,
|
gint32 drawable_ID,
|
||||||
gint32 orig_image_ID);
|
gint32 orig_image_ID);
|
||||||
|
|
||||||
static void respin_cmap (png_structp pp,
|
static void respin_cmap (png_structp pp,
|
||||||
png_infop info,
|
png_infop info,
|
||||||
guchar *remap,
|
guchar *remap,
|
||||||
gint32 image_ID,
|
gint32 image_ID,
|
||||||
GimpDrawable *drawable);
|
GimpDrawable *drawable);
|
||||||
|
|
||||||
static gboolean save_dialog (gint32 image_ID,
|
static gboolean save_dialog (gint32 image_ID,
|
||||||
gboolean alpha);
|
gboolean alpha);
|
||||||
|
|
||||||
static void save_dialog_response (GtkWidget *widget,
|
static void save_dialog_response (GtkWidget *widget,
|
||||||
gint response_id,
|
gint response_id,
|
||||||
gpointer data);
|
gpointer data);
|
||||||
|
|
||||||
static int find_unused_ia_colour (guchar *pixels,
|
static gboolean ia_has_transparent_pixels (guchar *pixels,
|
||||||
gint numpixels,
|
gint numpixels);
|
||||||
gint *colors);
|
|
||||||
|
|
||||||
static gboolean load_defaults (void);
|
static int find_unused_ia_colour (guchar *pixels,
|
||||||
static void save_defaults (void);
|
gint numpixels,
|
||||||
static void load_gui_defaults (PngSaveGui *pg);
|
gint *colors);
|
||||||
|
|
||||||
|
static gboolean load_defaults (void);
|
||||||
|
static void save_defaults (void);
|
||||||
|
static void load_gui_defaults (PngSaveGui *pg);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Globals...
|
* Globals...
|
||||||
@ -1463,6 +1466,19 @@ save_image (const gchar *filename,
|
|||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
ia_has_transparent_pixels (guchar *pixels,
|
||||||
|
gint numpixels)
|
||||||
|
{
|
||||||
|
while (numpixels --)
|
||||||
|
{
|
||||||
|
if (pixels [1] <= 127)
|
||||||
|
return TRUE;
|
||||||
|
pixels += 2;
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
respin_cmap (png_structp pp,
|
respin_cmap (png_structp pp,
|
||||||
png_infop info,
|
png_infop info,
|
||||||
@ -1478,6 +1494,7 @@ respin_cmap (png_structp pp,
|
|||||||
gint cols, rows;
|
gint cols, rows;
|
||||||
GimpPixelRgn pixel_rgn;
|
GimpPixelRgn pixel_rgn;
|
||||||
guchar *pixels;
|
guchar *pixels;
|
||||||
|
gint numpixels;
|
||||||
|
|
||||||
before = gimp_image_get_cmap (image_ID, &colors);
|
before = gimp_image_get_cmap (image_ID, &colors);
|
||||||
|
|
||||||
@ -1490,13 +1507,14 @@ respin_cmap (png_structp pp,
|
|||||||
colors = 1;
|
colors = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
cols = drawable->width;
|
cols = drawable->width;
|
||||||
rows = drawable->height;
|
rows = drawable->height;
|
||||||
|
numpixels = cols * rows;
|
||||||
|
|
||||||
gimp_pixel_rgn_init (&pixel_rgn, drawable, 0, 0,
|
gimp_pixel_rgn_init (&pixel_rgn, drawable, 0, 0,
|
||||||
drawable->width, drawable->height, FALSE, FALSE);
|
drawable->width, drawable->height, FALSE, FALSE);
|
||||||
|
|
||||||
pixels = (guchar *) g_malloc (drawable->width * drawable->height * 2);
|
pixels = (guchar *) g_malloc (numpixels * 2);
|
||||||
|
|
||||||
gimp_pixel_rgn_get_rect (&pixel_rgn, pixels, 0, 0,
|
gimp_pixel_rgn_get_rect (&pixel_rgn, pixels, 0, 0,
|
||||||
drawable->width, drawable->height);
|
drawable->width, drawable->height);
|
||||||
@ -1505,48 +1523,52 @@ respin_cmap (png_structp pp,
|
|||||||
/* Try to find an entry which isn't actually used in the
|
/* Try to find an entry which isn't actually used in the
|
||||||
image, for a transparency index. */
|
image, for a transparency index. */
|
||||||
|
|
||||||
transparent = find_unused_ia_colour (pixels,
|
|
||||||
drawable->width * drawable->height,
|
|
||||||
&colors);
|
|
||||||
|
|
||||||
#if PNG_LIBPNG_VER > 99
|
#if PNG_LIBPNG_VER > 99
|
||||||
if (transparent != -1) /* we have a winner for a transparent
|
if (ia_has_transparent_pixels (pixels, numpixels))
|
||||||
* index - do like gif2png and swap
|
|
||||||
* index 0 and index transparent */
|
|
||||||
{
|
{
|
||||||
png_color palette[256];
|
transparent = find_unused_ia_colour (pixels, numpixels, &colors);
|
||||||
gint i;
|
|
||||||
|
|
||||||
png_set_tRNS (pp, info, (png_bytep) trans, 1, NULL);
|
if (transparent != -1) /* we have a winner for a transparent
|
||||||
|
* index - do like gif2png and swap
|
||||||
/* Transform all pixels with a value = transparent to
|
* index 0 and index transparent */
|
||||||
* 0 and vice versa to compensate for re-ordering in palette
|
|
||||||
* due to png_set_tRNS() */
|
|
||||||
|
|
||||||
remap[0] = transparent;
|
|
||||||
remap[transparent] = 0;
|
|
||||||
|
|
||||||
/* Copy from index 0 to index transparent - 1 to index 1 to
|
|
||||||
* transparent of after, then from transparent+1 to colors-1
|
|
||||||
* unchanged, and finally from index transparent to index 0. */
|
|
||||||
|
|
||||||
for (i = 0; i < colors; i++)
|
|
||||||
{
|
{
|
||||||
palette[i].red = before[3 * remap[i]];
|
png_color palette[256];
|
||||||
palette[i].green = before[3 * remap[i] + 1];
|
gint i;
|
||||||
palette[i].blue = before[3 * remap[i] + 2];
|
|
||||||
}
|
|
||||||
|
|
||||||
png_set_PLTE (pp, info, palette, colors);
|
png_set_tRNS (pp, info, (png_bytep) trans, 1, NULL);
|
||||||
|
|
||||||
|
/* Transform all pixels with a value = transparent to
|
||||||
|
* 0 and vice versa to compensate for re-ordering in palette
|
||||||
|
* due to png_set_tRNS() */
|
||||||
|
|
||||||
|
remap[0] = transparent;
|
||||||
|
remap[transparent] = 0;
|
||||||
|
|
||||||
|
/* Copy from index 0 to index transparent - 1 to index 1 to
|
||||||
|
* transparent of after, then from transparent+1 to colors-1
|
||||||
|
* unchanged, and finally from index transparent to index 0. */
|
||||||
|
|
||||||
|
for (i = 0; i < colors; i++)
|
||||||
|
{
|
||||||
|
palette[i].red = before[3 * remap[i]];
|
||||||
|
palette[i].green = before[3 * remap[i] + 1];
|
||||||
|
palette[i].blue = before[3 * remap[i] + 2];
|
||||||
|
}
|
||||||
|
|
||||||
|
png_set_PLTE (pp, info, palette, colors);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Inform the user that we couldn't losslessly save the
|
||||||
|
* transparency & just use the full palette */
|
||||||
|
g_message (_("Couldn't losslessly save transparency, "
|
||||||
|
"saving opacity instead."));
|
||||||
|
png_set_PLTE (pp, info, (png_colorp) before, colors);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
png_set_PLTE (pp, info, (png_colorp) before, colors);
|
||||||
/* Inform the user that we couldn't losslessly save the
|
|
||||||
* transparency & just use the full palette */
|
|
||||||
g_message (_("Couldn't losslessly save transparency, "
|
|
||||||
"saving opacity instead."));
|
|
||||||
png_set_PLTE (pp, info, (png_colorp) before, colors);
|
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
info->valid |= PNG_INFO_PLTE;
|
info->valid |= PNG_INFO_PLTE;
|
||||||
info->palette = (png_colorp) before;
|
info->palette = (png_colorp) before;
|
||||||
|
Reference in New Issue
Block a user