aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw27@cam.ac.uk>2009-03-17 17:34:56 +0000
committerThomas White <taw27@cam.ac.uk>2009-03-17 17:34:56 +0000
commit12a5c6a53397ecce8622105c6b2f272422285a7f (patch)
tree3041825ff399567e497ca4d6abbeb6b82baf8314
parent2c359093a6497614e1ba37f1d2a1d4ac59b224b9 (diff)
Linewrap in readpng.c
-rw-r--r--src/readpng.c49
1 files 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 <taw27@cam.ac.uk>
+ * (c) 2007-2009 Thomas White <taw27@cam.ac.uk>
*
* 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<height; y++ ) {
for ( x=0; x<width; x++ ) {
-
+
int val = 0;
if ( bit_depth == 16 ) {
@@ -120,8 +124,10 @@ int readpng_read(const char *filename, double tilt, ControlContext *ctx) {
val = 0;
for ( i=0; i<channels; i++ ) {
/* PNG files are big-endian... */
- val += row_pointers[y][(channels*x*2)+(2*i)] << 8;
- val += row_pointers[y][(channels*x*2)+(2*i)+1];
+ val += row_pointers[y][(channels*x*2)
+ +(2*i)] << 8;
+ val += row_pointers[y][(channels*x*2)
+ +(2*i)+1];
}
val /= channels;
if ( val > 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;
-
-}
+}