diff options
Diffstat (limited to 'src/readpng.c')
-rw-r--r-- | src/readpng.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/readpng.c b/src/readpng.c index dc72e6e..0ea87fe 100644 --- a/src/readpng.c +++ b/src/readpng.c @@ -37,7 +37,7 @@ int readpng_read(const char *filename, double tilt, ControlContext *ctx) { png_bytep *row_pointers; unsigned int x; unsigned int y; - int16_t *image; + uint16_t *image; /* Open file */ fh = fopen(filename, "rb"); @@ -97,7 +97,7 @@ 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"); png_destroy_read_struct(&png_ptr, &info_ptr, &end_info); @@ -108,7 +108,7 @@ int readpng_read(const char *filename, double tilt, ControlContext *ctx) { /* Get image data */ row_pointers = png_get_rows(png_ptr, info_ptr); - image = malloc(height * width * sizeof(int16_t)); + image = malloc(height * width * sizeof(uint16_t)); ctx->fmode = FORMULATION_CLEN; for ( y=0; y<height; y++ ) { @@ -120,10 +120,12 @@ int readpng_read(const char *filename, double tilt, ControlContext *ctx) { int i; val = 0; for ( i=0; i<channels; i++ ) { - /* PNG files are big-endian: */ + /* 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 /= channels; + if ( val > 65535 ) printf("%i\n", val); } if ( bit_depth == 8 ) { int i; @@ -131,6 +133,7 @@ int readpng_read(const char *filename, double tilt, ControlContext *ctx) { for ( i=0; i<channels; i++ ) { val += row_pointers[y][(channels*x)+i]; } + val /= channels; } image[x + width*(height-1-y)] = val; @@ -141,7 +144,9 @@ int readpng_read(const char *filename, double tilt, ControlContext *ctx) { png_destroy_read_struct(&png_ptr, &info_ptr, &end_info); fclose(fh); - control_add_image(ctx, image, width, height, tilt); + if ( control_add_image(ctx, image, width, height, tilt) == 0 ) { + imagedisplay_open(image, width, height, "First image"); + } return 0; |