better fix for big-endian architectures
[geeqie.git] / src / image_load_tiff.c
index 1f894ac..07e6786 100644 (file)
@@ -50,13 +50,13 @@ struct _ImageLoaderTiff {
        ImageLoaderBackendCbAreaUpdated area_updated_cb;
        ImageLoaderBackendCbSize size_cb;
        ImageLoaderBackendCbAreaPrepared area_prepared_cb;
-       
+
        gpointer data;
 
        GdkPixbuf *pixbuf;
        guint requested_width;
        guint requested_height;
-       
+
        gboolean abort;
 
        const guchar *buffer;
@@ -153,8 +153,6 @@ static gboolean image_loader_tiff_load (gpointer loader, const guchar *buf, gsiz
        TIFF *tiff;
        guchar *pixels = NULL;
        gint width, height, rowstride, bytes;
-       uint16 orientation = 0;
-       uint16 transform = 0;
        uint32 rowsperstrip;
 
        lt->buffer = buf;
@@ -225,7 +223,7 @@ static gboolean image_loader_tiff_load (gpointer loader, const guchar *buf, gsiz
                return FALSE;
                }
 
-       lt->pixbuf = gdk_pixbuf_new_from_data (pixels, GDK_COLORSPACE_RGB, TRUE, 8, 
+       lt->pixbuf = gdk_pixbuf_new_from_data (pixels, GDK_COLORSPACE_RGB, TRUE, 8,
                                                                                   width, height, rowstride,
                                                                                   free_buffer, NULL);
        if (!lt->pixbuf)
@@ -236,36 +234,6 @@ static gboolean image_loader_tiff_load (gpointer loader, const guchar *buf, gsiz
                return FALSE;
                }
 
-       /* Set the "orientation" key associated with this image. libtiff 
-          orientation handling is odd, so further processing is required
-          by higher-level functions based on this tag. If the embedded
-          orientation tag is 1-4, libtiff flips/mirrors the image as
-          required, and no client processing is required - so we report 
-          no orientation. Orientations 5-8 require rotations which would 
-          swap the width and height of the image. libtiff does not do this. 
-          Instead it interprets orientations 5-8 the same as 1-4. 
-          See http://bugzilla.remotesensing.org/show_bug.cgi?id=1548.
-          To correct for this, the client must apply the transform normally
-          used for orientation 5 to both orientations 5 and 7, and apply
-          the transform normally used for orientation 7 for both
-          orientations 6 and 8. Then everythings works out OK! */
-       
-       TIFFGetField (tiff, TIFFTAG_ORIENTATION, &orientation);
-
-       switch (orientation) {
-               case 5:
-               case 7:
-                       transform = 5;
-                       break;
-               case 6:
-               case 8:
-                       transform = 7;
-                       break;
-               default:
-                       transform = 0;
-                       break;
-       }
-
        lt->area_prepared_cb(loader, lt->data);
 
        if (TIFFGetField(tiff, TIFFTAG_ROWSPERSTRIP, &rowsperstrip))
@@ -277,7 +245,7 @@ static gboolean image_loader_tiff_load (gpointer loader, const guchar *buf, gsiz
                for (row = 0; row < height; row += rowsperstrip)
                        {
                        int rows_to_write, i_row;
-                       
+
                        if (lt->abort) {
                                break;
                        }
@@ -304,7 +272,7 @@ static gboolean image_loader_tiff_load (gpointer loader, const guchar *buf, gsiz
                                guchar *top_line, *bottom_line;
 
                                top_line = pixels + (row + i_row) * rowstride;
-                               bottom_line = pixels + (row + rows_to_write - i_row - 1) * rowstride; 
+                               bottom_line = pixels + (row + rows_to_write - i_row - 1) * rowstride;
 
                                memcpy(wrk_line, top_line, 4*width);
                                memcpy(top_line, bottom_line, 4*width);
@@ -317,7 +285,7 @@ static gboolean image_loader_tiff_load (gpointer loader, const guchar *buf, gsiz
        else
                {
                /* fallback, tiled tiff */
-               if (!TIFFReadRGBAImageOriented (tiff, width, height, (uint32 *)pixels, ORIENTATION_TOPLEFT, 1)) 
+               if (!TIFFReadRGBAImageOriented (tiff, width, height, (uint32 *)pixels, ORIENTATION_TOPLEFT, 1))
                        {
                        TIFFClose(tiff);
                        return FALSE;
@@ -327,18 +295,21 @@ static gboolean image_loader_tiff_load (gpointer loader, const guchar *buf, gsiz
                /* Turns out that the packing used by TIFFRGBAImage depends on
                 * the host byte order...
                 */
-               while (pixels < lt->pixbuf->pixels + bytes) 
+               {
+               guchar *ptr = pixels;
+               while (ptr < pixels + bytes)
                        {
-                       uint32 pixel = *(uint32 *)pixels;
+                       uint32 pixel = *(uint32 *)ptr;
                        int r = TIFFGetR(pixel);
                        int g = TIFFGetG(pixel);
                        int b = TIFFGetB(pixel);
                        int a = TIFFGetA(pixel);
-                       *pixels++ = r;
-                       *pixels++ = g;
-                       *pixels++ = b;
-                       *pixels++ = a;
+                       *ptr++ = r;
+                       *ptr++ = g;
+                       *ptr++ = b;
+                       *ptr++ = a;
                        }
+               }
 #endif
 
                lt->area_updated_cb(loader, 0, 0, width, height, lt->data);
@@ -413,7 +384,7 @@ void image_loader_backend_set_tiff(ImageLoaderBackend *funcs)
        funcs->close = image_loader_tiff_close;
        funcs->abort = image_loader_tiff_abort;
        funcs->free = image_loader_tiff_free;
-       
+
        funcs->get_format_name = image_loader_tiff_get_format_name;
        funcs->get_format_mime_types = image_loader_tiff_get_format_mime_types;
 }