From b2a77abd1953f0f69ac5606cdb93c5aa83867827 Mon Sep 17 00:00:00 2001 From: Laurent Monin Date: Thu, 30 Aug 2012 14:01:41 +0200 Subject: [PATCH] Fix up indentation and coding style. --- src/image_load_tiff.c | 212 +++++++++++++++++++++--------------------- 1 file changed, 107 insertions(+), 105 deletions(-) diff --git a/src/image_load_tiff.c b/src/image_load_tiff.c index 71a33b8f..1f894ac5 100644 --- a/src/image_load_tiff.c +++ b/src/image_load_tiff.c @@ -72,72 +72,73 @@ static void free_buffer (guchar *pixels, gpointer data) static tsize_t tiff_load_read (thandle_t handle, tdata_t buf, tsize_t size) { - ImageLoaderTiff *context = (ImageLoaderTiff *)handle; - - if (context->pos + size > context->used) - return 0; - - memcpy (buf, context->buffer + context->pos, size); - context->pos += size; - return size; + ImageLoaderTiff *context = (ImageLoaderTiff *)handle; + + if (context->pos + size > context->used) + return 0; + + memcpy (buf, context->buffer + context->pos, size); + context->pos += size; + return size; } static tsize_t tiff_load_write (thandle_t handle, tdata_t buf, tsize_t size) { - return -1; + return -1; } static toff_t tiff_load_seek (thandle_t handle, toff_t offset, int whence) { - ImageLoaderTiff *context = (ImageLoaderTiff *)handle; - - switch (whence) { - case SEEK_SET: - if (offset > context->used) - return -1; - context->pos = offset; - break; - case SEEK_CUR: - if (offset + context->pos >= context->used) - return -1; - context->pos += offset; - break; - case SEEK_END: - if (offset + context->used > context->used) - return -1; - context->pos = context->used + offset; - break; - default: - return -1; - } - return context->pos; + ImageLoaderTiff *context = (ImageLoaderTiff *)handle; + + switch (whence) + { + case SEEK_SET: + if (offset > context->used) + return -1; + context->pos = offset; + break; + case SEEK_CUR: + if (offset + context->pos >= context->used) + return -1; + context->pos += offset; + break; + case SEEK_END: + if (offset + context->used > context->used) + return -1; + context->pos = context->used + offset; + break; + default: + return -1; + } + + return context->pos; } static int tiff_load_close (thandle_t context) { - return 0; + return 0; } static toff_t tiff_load_size (thandle_t handle) { - ImageLoaderTiff *context = (ImageLoaderTiff *)handle; - - return context->used; + ImageLoaderTiff *context = (ImageLoaderTiff *)handle; + return context->used; } static int tiff_load_map_file (thandle_t handle, tdata_t *buf, toff_t *size) { - ImageLoaderTiff *context = (ImageLoaderTiff *)handle; - - *buf = (tdata_t *) context->buffer; - *size = context->used; - - return 0; + ImageLoaderTiff *context = (ImageLoaderTiff *)handle; + + *buf = (tdata_t *) context->buffer; + *size = context->used; + + return 0; } static void @@ -149,7 +150,7 @@ static gboolean image_loader_tiff_load (gpointer loader, const guchar *buf, gsiz { ImageLoaderTiff *lt = (ImageLoaderTiff *) loader; - TIFF *tiff; + TIFF *tiff; guchar *pixels = NULL; gint width, height, rowstride, bytes; uint16 orientation = 0; @@ -162,72 +163,78 @@ static gboolean image_loader_tiff_load (gpointer loader, const guchar *buf, gsiz TIFFSetWarningHandler(NULL); - tiff = TIFFClientOpen ("libtiff-geeqie", "r", lt, - tiff_load_read, tiff_load_write, - tiff_load_seek, tiff_load_close, - tiff_load_size, - tiff_load_map_file, tiff_load_unmap_file); - if (!tiff) - { - DEBUG_1("Failed to open TIFF image"); - return FALSE; - } - + tiff = TIFFClientOpen ( "libtiff-geeqie", "r", lt, + tiff_load_read, tiff_load_write, + tiff_load_seek, tiff_load_close, + tiff_load_size, + tiff_load_map_file, tiff_load_unmap_file); + if (!tiff) + { + DEBUG_1("Failed to open TIFF image"); + return FALSE; + } - if (!TIFFGetField (tiff, TIFFTAG_IMAGEWIDTH, &width)) { + if (!TIFFGetField (tiff, TIFFTAG_IMAGEWIDTH, &width)) + { DEBUG_1("Could not get image width (bad TIFF file)"); TIFFClose(tiff); - return FALSE; - } - - if (!TIFFGetField (tiff, TIFFTAG_IMAGELENGTH, &height)) { - DEBUG_1("Could not get image height (bad TIFF file)"); + return FALSE; + } + + if (!TIFFGetField (tiff, TIFFTAG_IMAGELENGTH, &height)) + { + DEBUG_1("Could not get image height (bad TIFF file)"); TIFFClose(tiff); - return FALSE; - } + return FALSE; + } - if (width <= 0 || height <= 0) { - DEBUG_1("Width or height of TIFF image is zero"); + if (width <= 0 || height <= 0) + { + DEBUG_1("Width or height of TIFF image is zero"); TIFFClose(tiff); - return FALSE; - } - - rowstride = width * 4; - if (rowstride / 4 != width) { /* overflow */ - DEBUG_1("Dimensions of TIFF image too large"); + return FALSE; + } + + rowstride = width * 4; + if (rowstride / 4 != width) + { /* overflow */ + DEBUG_1("Dimensions of TIFF image too large"); TIFFClose(tiff); - return FALSE; - } - - bytes = height * rowstride; - if (bytes / rowstride != height) { /* overflow */ - DEBUG_1("Dimensions of TIFF image too large"); + return FALSE; + } + + bytes = height * rowstride; + if (bytes / rowstride != height) + { /* overflow */ + DEBUG_1("Dimensions of TIFF image too large"); TIFFClose(tiff); - return FALSE; - } + return FALSE; + } lt->requested_width = width; lt->requested_height = height; lt->size_cb(loader, lt->requested_width, lt->requested_height, lt->data); - pixels = g_try_malloc (bytes); + pixels = g_try_malloc (bytes); - if (!pixels) { - DEBUG_1("Insufficient memory to open TIFF file"); + if (!pixels) + { + DEBUG_1("Insufficient memory to open TIFF file"); TIFFClose(tiff); - return FALSE; - } + return FALSE; + } lt->pixbuf = gdk_pixbuf_new_from_data (pixels, GDK_COLORSPACE_RGB, TRUE, 8, - width, height, rowstride, - free_buffer, NULL); - if (!lt->pixbuf) { - g_free (pixels); - DEBUG_1("Insufficient memory to open TIFF file"); + width, height, rowstride, + free_buffer, NULL); + if (!lt->pixbuf) + { + g_free (pixels); + DEBUG_1("Insufficient memory to open TIFF file"); TIFFClose(tiff); - return FALSE; - } + return FALSE; + } /* Set the "orientation" key associated with this image. libtiff orientation handling is odd, so further processing is required @@ -259,19 +266,15 @@ static gboolean image_loader_tiff_load (gpointer loader, const guchar *buf, gsiz break; } - lt->area_prepared_cb(loader, lt->data); - - - if( TIFFGetField(tiff, TIFFTAG_ROWSPERSTRIP, &rowsperstrip) ) + if (TIFFGetField(tiff, TIFFTAG_ROWSPERSTRIP, &rowsperstrip)) { /* read by strip */ int row; guchar *wrk_line = (guchar *)g_malloc(width * sizeof (uint32)); - - for( row = 0; row < height; row += rowsperstrip ) + for (row = 0; row < height; row += rowsperstrip) { int rows_to_write, i_row; @@ -287,18 +290,16 @@ static gboolean image_loader_tiff_load (gpointer loader, const guchar *buf, gsiz /* * Figure out the number of scanlines actually in this strip. */ - if( row + (int)rowsperstrip > height ) + if (row + (int)rowsperstrip > height) rows_to_write = height - row; else rows_to_write = rowsperstrip; - - /* * For some reason the TIFFReadRGBAStrip() function chooses the * lower left corner as the origin. Vertically mirror scanlines. */ - for( i_row = 0; i_row < rows_to_write / 2; i_row++ ) + for (i_row = 0; i_row < rows_to_write / 2; i_row++) { guchar *top_line, *bottom_line; @@ -308,7 +309,7 @@ static gboolean image_loader_tiff_load (gpointer loader, const guchar *buf, gsiz memcpy(wrk_line, top_line, 4*width); memcpy(top_line, bottom_line, 4*width); memcpy(bottom_line, wrk_line, 4*width); - } + } lt->area_updated_cb(loader, 0, row, width, rows_to_write, lt->data); } g_free(wrk_line); @@ -323,9 +324,9 @@ static gboolean image_loader_tiff_load (gpointer loader, const guchar *buf, gsiz } #if G_BYTE_ORDER == G_BIG_ENDIAN - /* Turns out that the packing used by TIFFRGBAImage depends on - * the host byte order... - */ + /* Turns out that the packing used by TIFFRGBAImage depends on + * the host byte order... + */ while (pixels < lt->pixbuf->pixels + bytes) { uint32 pixel = *(uint32 *)pixels; @@ -350,8 +351,8 @@ static gboolean image_loader_tiff_load (gpointer loader, const guchar *buf, gsiz static gpointer image_loader_tiff_new(ImageLoaderBackendCbAreaUpdated area_updated_cb, ImageLoaderBackendCbSize size_cb, ImageLoaderBackendCbAreaPrepared area_prepared_cb, gpointer data) { - ImageLoaderTiff *loader = g_new0(ImageLoaderTiff, 1); - + ImageLoaderTiff *loader = g_new0(ImageLoaderTiff, 1); + loader->area_updated_cb = area_updated_cb; loader->size_cb = size_cb; loader->area_prepared_cb = area_prepared_cb; @@ -420,3 +421,4 @@ void image_loader_backend_set_tiff(ImageLoaderBackend *funcs) #endif +/* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ -- 2.20.1