X-Git-Url: http://git.chise.org/gitweb/?p=chise%2Fxemacs-chise.git.1;a=blobdiff_plain;f=src%2Fglyphs-eimage.c;h=e3df95f92ffc2c863b7dce9d08fc7483ee62395a;hp=c2958343e470d3a87173d92d52d42529ba4e8b0b;hb=566b3d194e2d5c783808ac39437bd7e1a28b1c5c;hpb=d81014e89b5102527e5b50aac62edeed2955671d diff --git a/src/glyphs-eimage.c b/src/glyphs-eimage.c index c295834..e3df95f 100644 --- a/src/glyphs-eimage.c +++ b/src/glyphs-eimage.c @@ -2,7 +2,7 @@ Copyright (C) 1993, 1994, 1998 Free Software Foundation, Inc. Copyright (C) 1995 Board of Trustees, University of Illinois. Copyright (C) 1995 Tinker Systems - Copyright (C) 1995, 1996 Ben Wing + Copyright (C) 1995, 1996, 2005 Ben Wing Copyright (C) 1995 Sun Microsystems This file is part of XEmacs. @@ -105,6 +105,19 @@ Lisp_Object Qpng; #ifdef __cplusplus extern "C" { #endif + +#ifdef WIN32_NATIVE +/* #### Yuck! More horrifitude. tiffio.h, below, includes , + which defines INT32 and INT16, the former differently and incompatibly + from jmorecfg.h, included by jpeglib.h. We can disable the stuff in + jmorecfg.h by defining XMD_H (clever, huh?); then we define these + typedefs the way that wants them (which is more correct, + anyway; jmorecfg.h defines INT32 as `long'). */ +#define XMD_H +typedef signed int INT32; +typedef signed short INT16; +#endif + #include #include #ifdef __cplusplus @@ -834,7 +847,13 @@ png_instantiate_unwind (Lisp_Object unwind_obj) free_opaque_ptr (unwind_obj); if (data->png_ptr) - png_destroy_read_struct (&(data->png_ptr), &(data->info_ptr), (png_infopp)NULL); + { + /* ensure we can't get here again */ + png_structp tmp = data->png_ptr; + data->png_ptr = NULL; + png_destroy_read_struct (&tmp, &(data->info_ptr), (png_infopp)NULL); + } + if (data->instream) fclose (data->instream); @@ -858,24 +877,36 @@ png_instantiate (Lisp_Object image_instance, Lisp_Object instantiator, png_structp png_ptr; png_infop info_ptr; + xzero (unwind); + record_unwind_protect (png_instantiate_unwind, make_opaque_ptr (&unwind)); + + if (setjmp (png_err_stct.setjmp_buffer)) + { + /* Something blew up: + just display the error (cleanup happens in the unwind) */ + signal_image_error_2 ("Error decoding PNG", + build_string(png_err_stct.err_str), + instantiator); + } + /* Initialize all PNG structures */ - png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING, (void*)&png_err_stct, + png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING, + (void *) &png_err_stct, png_error_func, png_warning_func); if (!png_ptr) signal_image_error ("Error obtaining memory for png_read", instantiator); + unwind.png_ptr = png_ptr; + info_ptr = png_create_info_struct (png_ptr); if (!info_ptr) { + unwind.png_ptr = NULL; /* avoid re-calling png_destroy_read_struct + when unwinding */ png_destroy_read_struct (&png_ptr, (png_infopp)NULL, (png_infopp)NULL); signal_image_error ("Error obtaining memory for png_read", instantiator); } - - xzero (unwind); - unwind.png_ptr = png_ptr; unwind.info_ptr = info_ptr; - record_unwind_protect (png_instantiate_unwind, make_opaque_ptr (&unwind)); - /* This code is a mixture of stuff from Ben's GIF/JPEG stuff from this file, example.c from the libpng 0.81 distribution, and the pngtopnm sources. -WMP- @@ -884,16 +915,6 @@ png_instantiate (Lisp_Object image_instance, Lisp_Object instantiator, and is no longer usable for previous versions. jh */ - /* Set the jmp_buf return context for png_error ... if this returns !0, then - we ran into a problem somewhere, and need to clean up after ourselves. */ - if (setjmp (png_err_stct.setjmp_buffer)) - { - /* Something blew up: just display the error (cleanup happens in the unwind) */ - signal_image_error_2 ("Error decoding PNG", - build_string(png_err_stct.err_str), - instantiator); - } - /* Initialize the IO layer and read in header information */ { Lisp_Object data = find_keyword_in_vector (instantiator, Q_data); @@ -916,8 +937,8 @@ png_instantiate (Lisp_Object image_instance, Lisp_Object instantiator, { int y; unsigned char **row_pointers; - height = info_ptr->height; - width = info_ptr->width; + height = png_get_image_height (png_ptr, info_ptr) /* info_ptr->height */; + width = png_get_image_width (png_ptr, info_ptr) /* info_ptr->width */; /* Wow, allocate all the memory. Truly, exciting. */ unwind.eimage = xnew_array_and_zero (unsigned char, width * height * 3); @@ -969,22 +990,22 @@ png_instantiate (Lisp_Object image_instance, Lisp_Object instantiator, /* Now that we're using EImage, ask for 8bit RGB triples for any type of image*/ /* convert palette images to full RGB */ - if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + if (png_get_color_type(png_ptr, info_ptr) /* info_ptr->color_type */ == PNG_COLOR_TYPE_PALETTE) png_set_expand (png_ptr); /* send grayscale images to RGB too */ - if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY || - info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) + if (png_get_color_type(png_ptr, info_ptr) /* info_ptr->color_type */ == PNG_COLOR_TYPE_GRAY || + png_get_color_type(png_ptr, info_ptr) /* info_ptr->color_type */ == PNG_COLOR_TYPE_GRAY_ALPHA) png_set_gray_to_rgb (png_ptr); /* we can't handle alpha values */ - if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA) + if (png_get_color_type(png_ptr, info_ptr) /* info_ptr->color_type */ & PNG_COLOR_MASK_ALPHA) png_set_strip_alpha (png_ptr); /* tell libpng to strip 16 bit depth files down to 8 bits */ - if (info_ptr->bit_depth == 16) + if (png_get_bit_depth(png_ptr, info_ptr) /* info_ptr->bit_depth */ == 16) png_set_strip_16 (png_ptr); /* if the image is < 8 bits, pad it out */ - if (info_ptr->bit_depth < 8) + if (png_get_bit_depth(png_ptr, info_ptr) /* info_ptr->bit_depth */ < 8) { - if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY) + if (png_get_color_type(png_ptr, info_ptr) /* info_ptr->color_type */ == PNG_COLOR_TYPE_GRAY) png_set_expand (png_ptr); else png_set_packing (png_ptr); @@ -1103,7 +1124,7 @@ tiff_memory_read(thandle_t data, tdata_t buf, tsize_t size) static size_t tiff_memory_write(thandle_t data, tdata_t buf, tsize_t size) { - abort(); + ABORT(); return 0; /* Shut up warnings. */ }