From: <pan...@li...> - 2011-03-05 22:23:42
|
branch: details: http://panotools.hg.sourceforge.net/hgweb/panotools/panotools/hgrepo/p/pa/panotools/libpano/rev/3209bc93c5ae changeset: 744:3209bc93c5ae user: Bruno Postle <br...@po...> date: diffstat: png.c | 40 ++++++++++++++++++---------------------- 1 files changed, 18 insertions(+), 22 deletions(-) diffs (94 lines): diff -r 2ed25471680c -r 3209bc93c5ae png.c --- a/png.c Fri Mar 04 01:09:26 2011 -0800 +++ b/png.c Sat Mar 05 22:34:04 2011 +0000 @@ -56,7 +56,7 @@ } /* set error handling */ - if (setjmp(png_ptr->jmpbuf)) + if (setjmp(png_jmpbuf(png_ptr))) { /* If we get here, we had a problem reading the file */ fclose(outfile); @@ -68,14 +68,15 @@ png_init_io(png_ptr, outfile); FourToThreeBPP( im ); - info_ptr->width = im->width; - info_ptr->height = im->height; - info_ptr->bit_depth = (im->bitsPerPixel > 32 ? 16 : 8); - info_ptr->color_type = PNG_COLOR_TYPE_RGB; + png_set_IHDR(png_ptr, info_ptr, im->width, im->height, + (im->bitsPerPixel > 32 ? 16 : 8), PNG_COLOR_TYPE_RGB, + 0, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); + +#if 0 info_ptr->channels = (png_byte)(im->bitsPerPixel / info_ptr->bit_depth); info_ptr->pixel_depth = (png_byte)(im->bitsPerPixel); info_ptr->rowbytes = im->bytesPerLine; - info_ptr->interlace_type= 0; +#endif png_write_info(png_ptr, info_ptr); @@ -120,6 +121,7 @@ png_bytep *row_pointers; int row; unsigned long dataSize; + int color_type; #ifdef __Mac__ unsigned char the_pcUnixFilePath[256];//added by Kekus Digital @@ -165,7 +167,7 @@ } /* set error handling if you are using the setjmp/longjmp method */ - if (setjmp(png_ptr->jmpbuf)) + if (setjmp(png_jmpbuf(png_ptr))) { /* Free all of the memory associated with the png_ptr and info_ptr */ png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL); @@ -182,9 +184,10 @@ /* read the file information */ png_read_info(png_ptr, info_ptr); - if( info_ptr->color_type != PNG_COLOR_TYPE_RGB && - info_ptr->color_type != PNG_COLOR_TYPE_PALETTE && - info_ptr->color_type != PNG_COLOR_TYPE_RGB_ALPHA) + color_type = png_get_color_type(png_ptr, info_ptr); + if( color_type != PNG_COLOR_TYPE_RGB && + color_type != PNG_COLOR_TYPE_PALETTE && + color_type != PNG_COLOR_TYPE_RGB_ALPHA) { PrintError(" Only rgb images supported"); png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL); @@ -194,24 +197,17 @@ /* expand paletted colors into true RGB triplets */ - if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + if (color_type == PNG_COLOR_TYPE_PALETTE) png_set_expand(png_ptr); SetImageDefaults( im ); - im->width = info_ptr->width; - im->height = info_ptr->height; - im->bytesPerLine = info_ptr->rowbytes; - im->bitsPerPixel = info_ptr->pixel_depth; + im->width = png_get_image_width(png_ptr, info_ptr); + im->height = png_get_image_height(png_ptr, info_ptr); + im->bytesPerLine = png_get_rowbytes(png_ptr, info_ptr); im->dataSize = im->height * im->bytesPerLine; - if( im->bitsPerPixel == 24 ) - dataSize = im->width * im->height * 4; - else if( im->bitsPerPixel == 48 ) - dataSize = im->width * im->height * 8; - else - dataSize = im->width * im->height * im->bitsPerPixel/8; - + im->bitsPerPixel = 8 * im->bytesPerLine / im->width; im->data = (unsigned char**)mymalloc( (dataSize > im->dataSize ? dataSize : im->dataSize) ); if( im->data == NULL ){ |