]> Pileus Git - ~andy/gtk/blobdiff - gdk-pixbuf/io-tiff.c
Updated Slovenian translation
[~andy/gtk] / gdk-pixbuf / io-tiff.c
index 64da064883bf560deb81a28748aadfb34b2bc5c3..7f8b79318e7dcad7c09c9b03ae17e709afce5948 100644 (file)
@@ -7,7 +7,7 @@
  * Authors: Mark Crichton <crichton@gimp.org>
  *          Federico Mena-Quintero <federico@gimp.org>
  *          Jonathan Blandford <jrb@redhat.com>
- *          Søren Sandmann <sandmann@daimi.au.dk>
+ *          Sren Sandmann <sandmann@daimi.au.dk>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -27,7 +27,7 @@
 
 /* Following code (almost) blatantly ripped from Imlib */
 
-#include <config.h>
+#include "config.h"
 #include <stdlib.h>
 #include <string.h>
 #ifdef HAVE_UNISTD_H
@@ -128,9 +128,9 @@ tiff_set_error (GError    **error,
                 global_error = NULL;
         }
         else {
-                g_set_error (error,
-                             GDK_PIXBUF_ERROR,
-                             error_code, msg);
+                g_set_error_literal (error,
+                                     GDK_PIXBUF_ERROR,
+                                     error_code, msg);
         }
 }
 
@@ -149,6 +149,7 @@ tiff_image_parse (TIFF *tiff, TiffContext *context, GError **error)
        GdkPixbuf *pixbuf;
        uint16 orientation = 0;
        uint16 transform = 0;
+        uint16 codec;
 
         /* We're called with the lock held. */
         
@@ -169,28 +170,28 @@ tiff_image_parse (TIFF *tiff, TiffContext *context, GError **error)
         }
 
         if (width <= 0 || height <= 0) {
-                g_set_error (error,
-                             GDK_PIXBUF_ERROR,
-                             GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
-                             _("Width or height of TIFF image is zero"));
+                g_set_error_literal (error,
+                                     GDK_PIXBUF_ERROR,
+                                     GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
+                                     _("Width or height of TIFF image is zero"));
                 return NULL;                
         }
         
         rowstride = width * 4;
         if (rowstride / 4 != width) { /* overflow */
-                g_set_error (error,
-                             GDK_PIXBUF_ERROR,
-                             GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
-                             _("Dimensions of TIFF image too large"));
+                g_set_error_literal (error,
+                                     GDK_PIXBUF_ERROR,
+                                     GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
+                                     _("Dimensions of TIFF image too large"));
                 return NULL;                
         }
         
         bytes = height * rowstride;
         if (bytes / rowstride != height) { /* overflow */
-                g_set_error (error,
-                             GDK_PIXBUF_ERROR,
-                             GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
-                             _("Dimensions of TIFF image too large"));
+                g_set_error_literal (error,
+                                     GDK_PIXBUF_ERROR,
+                                     GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
+                                     _("Dimensions of TIFF image too large"));
                 return NULL;                
         }
 
@@ -211,10 +212,10 @@ tiff_image_parse (TIFF *tiff, TiffContext *context, GError **error)
         pixels = g_try_malloc (bytes);
 
         if (!pixels) {
-                g_set_error (error,
-                             GDK_PIXBUF_ERROR,
-                             GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY,
-                             _("Insufficient memory to open TIFF file"));
+                g_set_error_literal (error,
+                                     GDK_PIXBUF_ERROR,
+                                     GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY,
+                                     _("Insufficient memory to open TIFF file"));
                 return NULL;
         }
 
@@ -223,10 +224,10 @@ tiff_image_parse (TIFF *tiff, TiffContext *context, GError **error)
                                            free_buffer, NULL);
         if (!pixbuf) {
                 g_free (pixels);
-                g_set_error (error,
-                             GDK_PIXBUF_ERROR,
-                             GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY,
-                             _("Insufficient memory to open TIFF file"));
+                g_set_error_literal (error,
+                                     GDK_PIXBUF_ERROR,
+                                     GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY,
+                                     _("Insufficient memory to open TIFF file"));
                 return NULL;
         }
 
@@ -262,10 +263,17 @@ tiff_image_parse (TIFF *tiff, TiffContext *context, GError **error)
 
        if (transform > 0 ) {
                gchar str[5];
-               snprintf (str, sizeof (str), "%d", transform);
+               g_snprintf (str, sizeof (str), "%d", transform);
                gdk_pixbuf_set_option (pixbuf, "orientation", str);
        }
 
+        TIFFGetField (tiff, TIFFTAG_COMPRESSION, &codec);
+        if (codec > 0) {
+          gchar str[5];
+          g_snprintf (str, sizeof (str), "%d", codec);
+          gdk_pixbuf_set_option (pixbuf, "compression", str);
+        }
+
        if (context && context->prepare_func)
                (* context->prepare_func) (pixbuf, NULL, context->user_data);
 
@@ -535,10 +543,10 @@ gdk_pixbuf__tiff_image_load_increment (gpointer data, const guchar *buf,
        g_return_val_if_fail (data != NULL, FALSE);
         
         if (!make_available_at_least (context, size)) {
-                g_set_error (error,
-                             GDK_PIXBUF_ERROR,
-                             GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY,
-                             _("Insufficient memory to open TIFF file"));
+                g_set_error_literal (error,
+                                     GDK_PIXBUF_ERROR,
+                                     GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY,
+                                     _("Insufficient memory to open TIFF file"));
                 return FALSE;
         }
         
@@ -689,6 +697,31 @@ gdk_pixbuf__tiff_image_save_to_callback (GdkPixbufSaveFunc   save_func,
         TIFFSetField (tiff, TIFFTAG_SAMPLESPERPIXEL, has_alpha ? 4 : 3);
         TIFFSetField (tiff, TIFFTAG_ROWSPERSTRIP, height);
 
+        /* libtiff supports a number of 'codecs' such as:
+           1 None, 2 Huffman, 5 LZW, 7 JPEG, 8 Deflate, see tiff.h */
+        if (keys && *keys && values && *values) {
+            guint i = 0;
+
+            while (keys[i]) {
+                if (g_str_equal (keys[i], "compression")) {
+                    guint16 codec = strtol (values[i], NULL, 0);
+                    if (TIFFIsCODECConfigured (codec))
+                        TIFFSetField (tiff, TIFFTAG_COMPRESSION, codec);
+                    else {
+                        tiff_set_error (error,
+                                        GDK_PIXBUF_ERROR_FAILED,
+                            _("TIFF compression doesn't refer to a valid codec."));
+
+                        tiff_pop_handlers ();
+
+                        free_save_context (context);
+                        return FALSE;
+                    }
+                }
+                i++;
+            }
+        }
+
         if (has_alpha)
                 TIFFSetField (tiff, TIFFTAG_EXTRASAMPLES, 1, alpha_samples);
 
@@ -754,10 +787,10 @@ save_to_file_cb (const gchar *buf,
        }
 
        if (count) {
-               g_set_error (error,
-                            GDK_PIXBUF_ERROR,
-                            GDK_PIXBUF_ERROR_FAILED,
-                            _("Couldn't write to TIFF file"));
+               g_set_error_literal (error,
+                                     GDK_PIXBUF_ERROR,
+                                     GDK_PIXBUF_ERROR_FAILED,
+                                     _("Couldn't write to TIFF file"));
                return FALSE;
        }
        
@@ -797,6 +830,7 @@ MODULE_ENTRY (fill_info) (GdkPixbufFormat *info)
         static GdkPixbufModulePattern signature[] = {
                 { "MM \x2a", "  z ", 100 },
                 { "II\x2a ", "   z", 100 },
+                { "II* \020   CR\002 ", "   z zzz   z", 0 },
                 { NULL, NULL, 0 }
         };
        static gchar * mime_types[] = {