[gimp/gimp-2-8] Bug 673729: tiff plug in not working 2.8.0-RC1 windows install
- From: Massimo Valentini <mvalentini src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/gimp-2-8] Bug 673729: tiff plug in not working 2.8.0-RC1 windows install
- Date: Sat, 9 Jun 2012 13:48:01 +0000 (UTC)
commit 0ba99a05ff162a6894686035398b0a82a348a5d7
Author: Massimo Valentini <mvalentini src gnome org>
Date: Sat Jun 9 15:36:35 2012 +0200
Bug 673729: tiff plug in not working 2.8.0-RC1 windows install
implement win32 filename Unicode management in the plug-ins
to work-around a problem in libtiff TIFFFdOpen.
Based on a patch from Hartmut Kuhse.
plug-ins/common/file-tiff-load.c | 46 ++++++++++++++++++++++---------------
plug-ins/common/file-tiff-save.c | 41 ++++++++++++++++++++++++++-------
2 files changed, 59 insertions(+), 28 deletions(-)
---
diff --git a/plug-ins/common/file-tiff-load.c b/plug-ins/common/file-tiff-load.c
index ea93fe2..ec651c1 100644
--- a/plug-ins/common/file-tiff-load.c
+++ b/plug-ins/common/file-tiff-load.c
@@ -192,6 +192,9 @@ static void tiff_warning (const gchar *module,
static void tiff_error (const gchar *module,
const gchar *fmt,
va_list ap);
+static TIFF *tiff_open (const gchar *filename,
+ const gchar *mode,
+ GError **error);
const GimpPlugInInfo PLUG_IN_INFO =
@@ -280,23 +283,7 @@ run (const gchar *name,
if (strcmp (name, LOAD_PROC) == 0)
{
const gchar *filename = param[1].data.d_string;
- TIFF *tif = NULL;
- gint fd;
-
- fd = g_open (filename, O_RDONLY | _O_BINARY, 0);
-
- if (fd == -1)
- {
- g_set_error (&error, G_FILE_ERROR, g_file_error_from_errno (errno),
- _("Could not open '%s' for reading: %s"),
- gimp_filename_to_utf8 (filename), g_strerror (errno));
-
- status = GIMP_PDB_EXECUTION_ERROR;
- }
- else
- {
- tif = TIFFFdOpen (fd, filename, "r");
- }
+ TIFF *tif = tiff_open (filename, "r", &error);
if (tif)
{
@@ -365,11 +352,9 @@ run (const gchar *name,
}
TIFFClose (tif);
- close (fd);
}
else
{
- close (fd);
status = GIMP_PDB_EXECUTION_ERROR;
}
}
@@ -447,6 +432,29 @@ tiff_error (const gchar *module,
g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, fmt, ap);
}
+static TIFF *
+tiff_open (const gchar *filename,
+ const gchar *mode,
+ GError **error)
+{
+#ifdef G_OS_WIN32
+ gunichar2 *utf16_filename = g_utf8_to_utf16 (filename, -1, NULL, NULL, error);
+
+ if (utf16_filename)
+ {
+ TIFF *tif = TIFFOpenW (utf16_filename, mode);
+
+ g_free (utf16_filename);
+
+ return tif;
+ }
+
+ return NULL;
+#else
+ return TIFFOpen (filename, mode);
+#endif
+}
+
/* returns a pointer into the TIFF */
static const gchar *
tiff_get_page_name (TIFF *tif)
diff --git a/plug-ins/common/file-tiff-save.c b/plug-ins/common/file-tiff-save.c
index c3af7de..15fdd9f 100644
--- a/plug-ins/common/file-tiff-save.c
+++ b/plug-ins/common/file-tiff-save.c
@@ -129,6 +129,9 @@ static void tiff_warning (const gchar *module,
static void tiff_error (const gchar *module,
const gchar *fmt,
va_list ap);
+static TIFF *tiff_open (const gchar *filename,
+ const gchar *mode,
+ GError **error);
const GimpPlugInInfo PLUG_IN_INFO =
{
@@ -413,6 +416,29 @@ tiff_error (const gchar *module,
g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, fmt, ap);
}
+static TIFF *
+tiff_open (const gchar *filename,
+ const gchar *mode,
+ GError **error)
+{
+#ifdef G_OS_WIN32
+ gunichar2 *utf16_filename = g_utf8_to_utf16 (filename, -1, NULL, NULL, error);
+
+ if (utf16_filename)
+ {
+ TIFF *tif = TIFFOpenW (utf16_filename, mode);
+
+ g_free (utf16_filename);
+
+ return tif;
+ }
+
+ return NULL;
+#else
+ return TIFFOpen (filename, mode);
+#endif
+}
+
static gboolean
image_is_monochrome (gint32 image)
{
@@ -657,7 +683,6 @@ save_image (const gchar *filename,
GimpPixelRgn pixel_rgn;
gint tile_height;
gint y, yend;
- gint fd;
gboolean is_bw = FALSE;
gboolean invert = TRUE;
const guchar bw_map[] = { 0, 0, 0, 255, 255, 255 };
@@ -676,18 +701,17 @@ save_image (const gchar *filename,
tile_height = gimp_tile_height ();
rowsperstrip = tile_height;
- fd = g_open (filename, O_CREAT | O_TRUNC | O_WRONLY | _O_BINARY, 0666);
+ tif = tiff_open (filename, "w", error);
- if (fd == -1)
+ if (! tif)
{
- 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));
+ 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));
return FALSE;
}
- tif = TIFFFdOpen (fd, filename, "w");
-
TIFFSetWarningHandler (tiff_warning);
TIFFSetErrorHandler (tiff_error);
@@ -1034,7 +1058,6 @@ save_image (const gchar *filename,
TIFFFlushData (tif);
TIFFClose (tif);
- close (fd);
gimp_progress_update (1.0);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]