[gimp] Bug 707239 - Gimp destroys image file when exporting...
- From: Massimo Valentini <mvalentini src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] Bug 707239 - Gimp destroys image file when exporting...
- Date: Wed, 7 May 2014 16:43:11 +0000 (UTC)
commit 7e80e2e3bc77f17dac3fc0f712970a34215a6814
Author: Massimo Valentini <mvalentini src gnome org>
Date: Wed May 7 18:10:26 2014 +0200
Bug 707239 - Gimp destroys image file when exporting...
as .tif with jpeg compression
make unsensitive the JPEG radio button when the image
is indexed, similarly to Fax Group 3/4 compression
enabled only for monochrome images
move the file creation/truncation after checking for
invalid requests and return a GError in case of error
plug-ins/common/file-tiff-save.c | 59 +++++++++++++++++++++++++++-----------
1 files changed, 42 insertions(+), 17 deletions(-)
---
diff --git a/plug-ins/common/file-tiff-save.c b/plug-ins/common/file-tiff-save.c
index fab5120..a1c2c1b 100644
--- a/plug-ins/common/file-tiff-save.c
+++ b/plug-ins/common/file-tiff-save.c
@@ -118,7 +118,8 @@ static gboolean save_image (const gchar *filename,
GError **error);
static gboolean save_dialog (gboolean has_alpha,
- gboolean is_monochrome);
+ gboolean is_monochrome,
+ gboolean is_indexed);
static void comment_entry_callback (GtkWidget *widget,
gpointer data);
@@ -306,7 +307,8 @@ run (const gchar *name,
/* First acquire information with a dialog */
if (! save_dialog (gimp_drawable_has_alpha (drawable),
- image_is_monochrome (image)))
+ image_is_monochrome (image),
+ gimp_image_base_type (image) == GIMP_INDEXED))
status = GIMP_PDB_CANCEL;
break;
@@ -745,17 +747,6 @@ save_image (const gchar *filename,
tile_height = gimp_tile_height ();
rowsperstrip = tile_height;
- tif = tiff_open (filename, "w", error);
-
- if (! tif)
- {
- if (! error)
- g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
- _("Could not open '%s' for writing: %s"),
- gimp_filename_to_utf8 (filename), g_strerror (errno));
- goto out;
- }
-
TIFFSetWarningHandler (tiff_warning);
TIFFSetErrorHandler (tiff_error);
@@ -896,12 +887,37 @@ save_image (const gchar *filename,
{
if (bitspersample != 1 || samplesperpixel != 1)
{
- g_message (_("Only monochrome pictures can be compressed with "
- "\"CCITT Group 4\" or \"CCITT Group 3\"."));
+ const gchar *msg = _("Only monochrome pictures can be compressed "
+ "with \"CCITT Group 4\" or \"CCITT Group 3\".");
+
+ g_set_error_literal (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, msg);
+
goto out;
}
}
+ if (compression == COMPRESSION_JPEG)
+ {
+ if (gimp_image_base_type (image) == GIMP_INDEXED)
+ {
+ g_set_error_literal (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
+ _("Indexed pictures cannot be compressed "
+ "with \"JPEG\"."));
+ goto out;
+ }
+ }
+
+ tif = tiff_open (filename, "w", error);
+
+ if (! tif)
+ {
+ if (! error)
+ g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
+ _("Could not open '%s' for writing: %s"),
+ gimp_filename_to_utf8 (filename), g_strerror (errno));
+ goto out;
+ }
+
/* Set TIFF parameters. */
TIFFSetField (tif, TIFFTAG_SUBFILETYPE, 0);
TIFFSetField (tif, TIFFTAG_IMAGEWIDTH, cols);
@@ -1109,7 +1125,8 @@ save_image (const gchar *filename,
static gboolean
save_dialog (gboolean has_alpha,
- gboolean is_monochrome)
+ gboolean is_monochrome,
+ gboolean is_indexed)
{
GError *error = NULL;
GtkWidget *dialog;
@@ -1119,6 +1136,7 @@ save_dialog (gboolean has_alpha,
GtkWidget *toggle;
GtkWidget *cmp_g3;
GtkWidget *cmp_g4;
+ GtkWidget *cmp_jpeg;
GtkBuilder *builder;
gchar *ui_file;
gboolean run;
@@ -1157,7 +1175,7 @@ save_dialog (gboolean has_alpha,
_("_LZW"), COMPRESSION_LZW, NULL,
_("_Pack Bits"), COMPRESSION_PACKBITS, NULL,
_("_Deflate"), COMPRESSION_ADOBE_DEFLATE, NULL,
- _("_JPEG"), COMPRESSION_JPEG, NULL,
+ _("_JPEG"), COMPRESSION_JPEG, &cmp_jpeg,
_("CCITT Group _3 fax"), COMPRESSION_CCITTFAX3, &cmp_g3,
_("CCITT Group _4 fax"), COMPRESSION_CCITTFAX4, &cmp_g4,
@@ -1165,6 +1183,7 @@ save_dialog (gboolean has_alpha,
gtk_widget_set_sensitive (cmp_g3, is_monochrome);
gtk_widget_set_sensitive (cmp_g4, is_monochrome);
+ gtk_widget_set_sensitive (cmp_jpeg, ! is_indexed);
if (! is_monochrome)
{
@@ -1176,6 +1195,12 @@ save_dialog (gboolean has_alpha,
}
}
+ if (is_indexed && tsvals.compression == COMPRESSION_JPEG)
+ {
+ gimp_int_radio_group_set_active (GTK_RADIO_BUTTON (cmp_jpeg),
+ COMPRESSION_NONE);
+ }
+
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]