From b43b708893a9cdd602e55c7f96a21ca16c05f3cd Mon Sep 17 00:00:00 2001 From: n-a-c-h <> Date: Thu, 6 May 2004 19:03:17 +0000 Subject: [PATCH] Fixed PNG width. --- zsnes/src/zip/zpng.c | 462 ++++++++++++++++++++++--------------------- 1 file changed, 232 insertions(+), 230 deletions(-) diff --git a/zsnes/src/zip/zpng.c b/zsnes/src/zip/zpng.c index 70a99cd6..4e9586cb 100644 --- a/zsnes/src/zip/zpng.c +++ b/zsnes/src/zip/zpng.c @@ -1,230 +1,232 @@ -#include "zpng.h" - - -#ifdef __WIN32__ - #include - #include - - #ifdef __WIN32DBG__ - #include - #endif -#endif - -#ifdef __MSDOS__ - #include - #include - #include - #include -#endif - -#ifdef __LINUX__ -#include "../gblhdr.h" -#endif - -extern unsigned int vidbuffer; - -#ifdef __PNG__ - -int Png_Dump(const char * filename, unsigned short width, unsigned short height, unsigned char * image_data, bool usebgr) -{ - png_structp png_ptr; - png_infop info_ptr; - png_bytep * row_pointers; - /*Set scanline width for 32-bit color data*/ - int scanline=width*4; - int i; /*counter.*/ - int png_transforms=0; - png_color fake_pal; - /*Try to open the file.*/ - FILE *fp = fopen(filename, "wb"); - if (!fp) - { - return (-1); - } - - fake_pal.red = 0; - fake_pal.green = 0; - fake_pal.blue = 0; - /*Try to create png write struct, fail if we cannot.*/ - png_ptr = png_create_write_struct - (PNG_LIBPNG_VER_STRING, NULL,/*(png_voidp)user_error_ptr, - user_error_fn*/NULL, NULL/*user_warning_fn*/); - if (!png_ptr) - return (-1); - - /*set png I/O source.*/ - png_init_io(png_ptr, fp); - - /* set the zlib compression level */ - png_set_compression_level(png_ptr, - Z_BEST_COMPRESSION); - - /* set other zlib parameters */ - png_set_compression_mem_level(png_ptr, 8); - png_set_compression_strategy(png_ptr, - Z_DEFAULT_STRATEGY); - png_set_compression_window_bits(png_ptr, 15); - png_set_compression_method(png_ptr, 8); - png_set_compression_buffer_size(png_ptr, 8192); - - /*try to create info struct. Fail and delete existing structs if info struct cannot be created.*/ - info_ptr = png_create_info_struct(png_ptr); - if (!info_ptr) - { - png_destroy_write_struct(&png_ptr, - (png_infopp)NULL); - return (-1); - } - - - /*set a lot of image info (code adapted from libpng documentation!)*/ - png_set_IHDR(png_ptr, info_ptr, width, height, - 8, PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE, - PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); - - info_ptr->color_type=PNG_COLOR_TYPE_RGB_ALPHA; - - /*Allocate an array of scanline pointers*/ - row_pointers=(png_bytep*)malloc(height*sizeof(png_bytep)); - for (i=0;i1000) - sprintf(filename, "Image%03d.png", i); - else sprintf(filename, "Imag%04d.png", i); - if(stat(filename, &buf)==-1) - break; - } - return filename; -#endif - - tmp++; // the first char is the string length - // removes the path if there is one - while (*tmp!=0) tmp++; - while ((*tmp!='/') && (tmp!=&fnames)) tmp--; - tmp++; - // allocates enough memory to store the filename - filename = (char *)malloc(strlen(tmp)+10); - strcpy(filename, tmp); - - tmp = filename+strlen(filename); - while (*tmp!='.') tmp--; - -#ifdef __LINUX__ - tmp2 = filename; - while (tmp2 + #include + + #ifdef __WIN32DBG__ + #include + #endif +#endif + +#ifdef __MSDOS__ + #include + #include + #include + #include +#endif + +#ifdef __LINUX__ +#include "../gblhdr.h" +#endif + +extern unsigned int vidbuffer; + +#ifdef __PNG__ + +int Png_Dump(const char * filename, unsigned short width, unsigned short height, unsigned char * image_data, bool usebgr) +{ + png_structp png_ptr; + png_infop info_ptr; + png_bytep * row_pointers; + /*Set scanline width for 32-bit color data*/ + int scanline=width*4; + int i; /*counter.*/ + int png_transforms=0; + png_color fake_pal; + /*Try to open the file.*/ + FILE *fp = fopen(filename, "wb"); + if (!fp) + { + return (-1); + } + + fake_pal.red = 0; + fake_pal.green = 0; + fake_pal.blue = 0; + /*Try to create png write struct, fail if we cannot.*/ + png_ptr = png_create_write_struct + (PNG_LIBPNG_VER_STRING, NULL,/*(png_voidp)user_error_ptr, + user_error_fn*/NULL, NULL/*user_warning_fn*/); + if (!png_ptr) + return (-1); + + /*set png I/O source.*/ + png_init_io(png_ptr, fp); + + /* set the zlib compression level */ + png_set_compression_level(png_ptr, + Z_BEST_COMPRESSION); + + /* set other zlib parameters */ + png_set_compression_mem_level(png_ptr, 8); + png_set_compression_strategy(png_ptr, + Z_DEFAULT_STRATEGY); + png_set_compression_window_bits(png_ptr, 15); + png_set_compression_method(png_ptr, 8); + png_set_compression_buffer_size(png_ptr, 8192); + + /*try to create info struct. Fail and delete existing structs if info struct cannot be created.*/ + info_ptr = png_create_info_struct(png_ptr); + if (!info_ptr) + { + png_destroy_write_struct(&png_ptr, + (png_infopp)NULL); + return (-1); + } + + + /*set a lot of image info (code adapted from libpng documentation!)*/ + png_set_IHDR(png_ptr, info_ptr, width, height, + 8, PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE, + PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); + + info_ptr->color_type=PNG_COLOR_TYPE_RGB_ALPHA; + + /*Allocate an array of scanline pointers*/ + row_pointers=(png_bytep*)malloc(height*sizeof(png_bytep)); + for (i=0;i1000) + sprintf(filename, "Image%03d.png", i); + else sprintf(filename, "Imag%04d.png", i); + if(stat(filename, &buf)==-1) + break; + } + return filename; +#endif + + tmp++; // the first char is the string length + // removes the path if there is one + while (*tmp!=0) tmp++; + while ((*tmp!='/') && (tmp!=&fnames)) tmp--; + tmp++; + // allocates enough memory to store the filename + filename = (char *)malloc(strlen(tmp)+10); + strcpy(filename, tmp); + + tmp = filename+strlen(filename); + while (*tmp!='.') tmp--; + +#ifdef __LINUX__ + tmp2 = filename; + while (tmp2