From 12a5c6a53397ecce8622105c6b2f272422285a7f Mon Sep 17 00:00:00 2001 From: Thomas White Date: Tue, 17 Mar 2009 17:34:56 +0000 Subject: Linewrap in readpng.c --- src/readpng.c | 49 +++++++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/src/readpng.c b/src/readpng.c index 8b70f8e..a0aaa75 100644 --- a/src/readpng.c +++ b/src/readpng.c @@ -3,7 +3,7 @@ * * Read PNG images * - * (c) 2007 Thomas White + * (c) 2007-2009 Thomas White * * dtr - Diffraction Tomography Reconstruction * @@ -23,8 +23,8 @@ #include "reflections.h" #include "itrans.h" -int readpng_read(const char *filename, double tilt, ControlContext *ctx) { - +int readpng_read(const char *filename, double tilt, ControlContext *ctx) +{ FILE *fh; png_bytep header; png_structp png_ptr; @@ -38,7 +38,7 @@ int readpng_read(const char *filename, double tilt, ControlContext *ctx) { unsigned int x; unsigned int y; uint16_t *image; - + /* Open file */ fh = fopen(filename, "rb"); if ( !fh ) { @@ -56,8 +56,9 @@ int readpng_read(const char *filename, double tilt, ControlContext *ctx) { return -1; } free(header); - - png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); + + png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, + NULL, NULL, NULL); if ( !png_ptr ) { printf("RI: Couldn't create PNG read structure.\n"); fclose(fh); @@ -66,7 +67,8 @@ int readpng_read(const char *filename, double tilt, ControlContext *ctx) { info_ptr = png_create_info_struct(png_ptr); if ( !info_ptr ) { - png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL); + png_destroy_read_struct(&png_ptr, (png_infopp)NULL, + (png_infopp)NULL); printf("RI: Couldn't create PNG info structure.\n"); fclose(fh); return -1; @@ -79,7 +81,7 @@ int readpng_read(const char *filename, double tilt, ControlContext *ctx) { fclose(fh); return -1; } - + if ( setjmp(png_jmpbuf(png_ptr)) ) { png_destroy_read_struct(&png_ptr, &info_ptr, &end_info); fclose(fh); @@ -89,7 +91,7 @@ int readpng_read(const char *filename, double tilt, ControlContext *ctx) { png_init_io(png_ptr, fh); png_set_sig_bytes(png_ptr, 8); - + /* Read! */ png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_STRIP_ALPHA, NULL); @@ -97,22 +99,24 @@ int readpng_read(const char *filename, double tilt, ControlContext *ctx) { height = png_get_image_height(png_ptr, info_ptr); bit_depth = png_get_bit_depth(png_ptr, info_ptr); channels = png_get_channels(png_ptr, info_ptr); - //printf("RI: width=%i, height=%i, depth=%i, channels=%i\n", width, height, bit_depth, channels); + //printf("RI: width=%i, height=%i, depth=%i, channels=%i\n", + // width, height, bit_depth, channels); if ( (bit_depth != 16) && (bit_depth != 8) ) { - printf("RI: Whoops! Can't handle images with other than 8 or 16 bpp yet...\n"); + printf("RI: Whoops! Can't handle images with other" + " than 8 or 16 bpp yet...\n"); png_destroy_read_struct(&png_ptr, &info_ptr, &end_info); fclose(fh); return -1; } - + /* Get image data */ row_pointers = png_get_rows(png_ptr, info_ptr); - + image = malloc(height * width * sizeof(uint16_t)); - + for ( y=0; y 65535 ) printf("%i\n", val); @@ -134,18 +140,17 @@ int readpng_read(const char *filename, double tilt, ControlContext *ctx) { } val /= channels; } - + image[x + width*(height-1-y)] = val; } } - + png_destroy_read_struct(&png_ptr, &info_ptr, &end_info); fclose(fh); image_add(ctx->images, image, width, height, tilt, ctx); - + return 0; - -} +} -- cgit v1.2.3