Mercurial > hg > xemacs-beta
annotate src/glyphs-eimage.c @ 5278:d9e65b48e2bf
Correct the NEW_GC non-DEBUG_XEMACS version of PARSE_KEYWORDS().
2010-09-18 Aidan Kehoe <kehoea@parhasard.net>
* lisp.h (PARSE_KEYWORDS):
Correct the NEW_GC non-DEBUG_XEMACS version of this macro; under
such builds S##function is a pointer, not a Lisp_Subr structure.
| author | Aidan Kehoe <kehoea@parhasard.net> |
|---|---|
| date | Sat, 18 Sep 2010 16:46:56 +0100 |
| parents | db84c9d41437 |
| children | 6c3a695f54f5 308d34e9f07d |
| rev | line source |
|---|---|
| 428 | 1 /* EImage-specific Lisp objects. |
| 2 Copyright (C) 1993, 1994, 1998 Free Software Foundation, Inc. | |
| 3 Copyright (C) 1995 Board of Trustees, University of Illinois. | |
| 4 Copyright (C) 1995 Tinker Systems | |
|
5169
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5024
diff
changeset
|
5 Copyright (C) 1995, 1996, 2001, 2002, 2004, 2005, 2010 Ben Wing |
| 428 | 6 Copyright (C) 1995 Sun Microsystems |
| 7 | |
| 8 This file is part of XEmacs. | |
| 9 | |
| 10 XEmacs is free software; you can redistribute it and/or modify it | |
| 11 under the terms of the GNU General Public License as published by the | |
| 12 Free Software Foundation; either version 2, or (at your option) any | |
| 13 later version. | |
| 14 | |
| 15 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
| 16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 18 for more details. | |
| 19 | |
| 20 You should have received a copy of the GNU General Public License | |
| 21 along with XEmacs; see the file COPYING. If not, write to | |
| 22 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
| 23 Boston, MA 02111-1307, USA. */ | |
| 24 | |
| 25 /* Synched up with: Not in FSF. */ | |
| 26 | |
| 2959 | 27 /* Originally part of glyphs.c. |
| 28 | |
| 428 | 29 GIF/JPEG support added by Ben Wing for 19.14 |
| 30 PNG support added by Bill Perry for 19.14 | |
| 31 Improved GIF/JPEG support added by Bill Perry for 19.14 | |
| 32 Cleanup/simplification of error handling by Ben Wing for 19.14 | |
| 33 GIF support changed to external Gifreader lib by Jareth Hein for 21.0 | |
| 34 Many changes for color work and optimizations by Jareth Hein for 21.0 | |
| 35 Switch of GIF/JPEG/PNG to new EImage intermediate code by Jareth Hein for 21.0 | |
| 36 TIFF code by Jareth Hein for 21.0 | |
|
4708
1cecc3e9f0a0
Use giflib or libungif to provide GIF support, instead of using internal
Jerry James <james@xemacs.org>
parents:
4698
diff
changeset
|
37 GIF support changed to external giflib by Jerry James for 21.5 |
| 428 | 38 TODO: |
| 39 Convert images.el to C and stick it in here? | |
| 3094 | 40 This file is really repetitious; can we refactor? |
| 428 | 41 */ |
| 42 | |
| 43 #include <config.h> | |
| 44 #include "lisp.h" | |
| 45 #include "lstream.h" | |
| 46 #include "console.h" | |
| 872 | 47 #include "device-impl.h" |
| 428 | 48 #include "faces.h" |
| 49 #include "glyphs.h" | |
|
5176
8b2f75cecb89
rename objects* (.c, .h and .el files) to fontcolor*
Ben Wing <ben@xemacs.org>
parents:
5024
diff
changeset
|
50 #include "fontcolor-impl.h" |
| 428 | 51 |
| 52 #include "buffer.h" | |
| 53 #include "frame.h" | |
| 54 #include "opaque.h" | |
| 442 | 55 #include "window.h" |
| 428 | 56 |
| 57 #include "sysfile.h" | |
| 58 | |
| 59 #ifdef HAVE_PNG | |
| 1743 | 60 |
| 61 BEGIN_C_DECLS | |
| 62 | |
| 647 | 63 #define message message_ /* Yuck */ |
| 428 | 64 #include <png.h> |
| 647 | 65 #undef message |
| 1743 | 66 |
| 67 END_C_DECLS | |
| 68 | |
| 428 | 69 #else |
| 70 #include <setjmp.h> | |
| 71 #endif | |
| 72 #include "file-coding.h" | |
| 73 | |
| 74 #ifdef HAVE_TIFF | |
| 75 DEFINE_IMAGE_INSTANTIATOR_FORMAT (tiff); | |
| 76 Lisp_Object Qtiff; | |
| 77 #endif | |
| 78 | |
| 79 #ifdef HAVE_JPEG | |
| 80 DEFINE_IMAGE_INSTANTIATOR_FORMAT (jpeg); | |
| 81 Lisp_Object Qjpeg; | |
| 82 #endif | |
| 83 | |
| 84 #ifdef HAVE_GIF | |
| 85 DEFINE_IMAGE_INSTANTIATOR_FORMAT (gif); | |
| 86 Lisp_Object Qgif; | |
| 87 #endif | |
| 88 | |
| 89 #ifdef HAVE_PNG | |
| 90 DEFINE_IMAGE_INSTANTIATOR_FORMAT (png); | |
| 91 Lisp_Object Qpng; | |
| 92 #endif | |
| 93 | |
| 94 | |
| 95 #ifdef HAVE_JPEG | |
| 96 | |
| 97 /********************************************************************** | |
| 98 * JPEG * | |
| 99 **********************************************************************/ | |
| 100 | |
| 1743 | 101 BEGIN_C_DECLS |
| 102 | |
| 4854 | 103 #ifdef WIN32_ANY |
| 104 /* #### Yuck! More horrifitude. tiffio.h, below, and sysfile.h above, | |
| 105 include <windows.h>, which defines INT32 and INT16, the former | |
| 106 differently and incompatibly from jmorecfg.h, included by jpeglib.h. We | |
| 107 can disable the stuff in jmorecfg.h by defining XMD_H (clever, huh?); | |
| 108 then we define these typedefs the way that <windows.h> wants them (which | |
| 109 is more correct, anyway; jmorecfg.h defines INT32 as `long'). */ | |
| 2500 | 110 #define XMD_H |
| 111 typedef signed int INT32; | |
| 112 typedef signed short INT16; | |
|
4326
a5ff7e67ac1b
Don't let libtiff override the size of a boolean, Win32. From Ron Isaacson.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3839
diff
changeset
|
113 |
|
a5ff7e67ac1b
Don't let libtiff override the size of a boolean, Win32. From Ron Isaacson.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3839
diff
changeset
|
114 /* And another one... jmorecfg.h defines the 'boolean' type as int, |
|
a5ff7e67ac1b
Don't let libtiff override the size of a boolean, Win32. From Ron Isaacson.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3839
diff
changeset
|
115 which conflicts with the standard Windows 'boolean' definition as |
|
a5ff7e67ac1b
Don't let libtiff override the size of a boolean, Win32. From Ron Isaacson.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3839
diff
changeset
|
116 unsigned char. Ref: http://www.asmail.be/msg0054688232.html */ |
|
a5ff7e67ac1b
Don't let libtiff override the size of a boolean, Win32. From Ron Isaacson.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3839
diff
changeset
|
117 #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */ |
|
a5ff7e67ac1b
Don't let libtiff override the size of a boolean, Win32. From Ron Isaacson.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3839
diff
changeset
|
118 typedef unsigned char boolean; |
|
a5ff7e67ac1b
Don't let libtiff override the size of a boolean, Win32. From Ron Isaacson.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3839
diff
changeset
|
119 #endif |
|
a5ff7e67ac1b
Don't let libtiff override the size of a boolean, Win32. From Ron Isaacson.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3839
diff
changeset
|
120 #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */ |
| 2500 | 121 #endif |
| 122 | |
|
5009
2eec7322eb7f
Miscellaneous small fixes to Windows VS6 build
Vin Shelton <acs@xemacs.org>
parents:
4982
diff
changeset
|
123 /* Yet more breakage... jmorecfg.h unconditionally defines FAR either as |
|
2eec7322eb7f
Miscellaneous small fixes to Windows VS6 build
Vin Shelton <acs@xemacs.org>
parents:
4982
diff
changeset
|
124 "far" or as blank. Windef.h unconditionally defines FAR as "far". |
|
2eec7322eb7f
Miscellaneous small fixes to Windows VS6 build
Vin Shelton <acs@xemacs.org>
parents:
4982
diff
changeset
|
125 We'll avoid the compile warning by redefing FAR the way windows defines it, |
|
2eec7322eb7f
Miscellaneous small fixes to Windows VS6 build
Vin Shelton <acs@xemacs.org>
parents:
4982
diff
changeset
|
126 after loading the JPEG headers. */ |
|
2eec7322eb7f
Miscellaneous small fixes to Windows VS6 build
Vin Shelton <acs@xemacs.org>
parents:
4982
diff
changeset
|
127 #undef FAR |
| 428 | 128 #include <jpeglib.h> |
| 129 #include <jerror.h> | |
|
5009
2eec7322eb7f
Miscellaneous small fixes to Windows VS6 build
Vin Shelton <acs@xemacs.org>
parents:
4982
diff
changeset
|
130 #undef FAR |
|
2eec7322eb7f
Miscellaneous small fixes to Windows VS6 build
Vin Shelton <acs@xemacs.org>
parents:
4982
diff
changeset
|
131 #define FAR far |
| 1743 | 132 |
| 133 END_C_DECLS | |
| 428 | 134 |
| 135 /*#define USE_TEMP_FILES_FOR_JPEG_IMAGES 1*/ | |
| 136 static void | |
| 137 jpeg_validate (Lisp_Object instantiator) | |
| 138 { | |
| 139 file_or_data_must_be_present (instantiator); | |
| 140 } | |
| 141 | |
| 142 static Lisp_Object | |
| 442 | 143 jpeg_normalize (Lisp_Object inst, Lisp_Object console_type, |
| 2286 | 144 Lisp_Object UNUSED (dest_mask)) |
| 428 | 145 { |
| 146 return simple_image_type_normalize (inst, console_type, Qjpeg); | |
| 147 } | |
| 148 | |
| 149 static int | |
| 150 jpeg_possible_dest_types (void) | |
| 151 { | |
| 152 return IMAGE_COLOR_PIXMAP_MASK; | |
| 153 } | |
| 154 | |
| 155 /* To survive the otherwise baffling complexity of making sure | |
| 156 everything gets cleaned up in the presence of an error, we | |
| 157 use an unwind_protect(). */ | |
| 158 | |
| 159 struct jpeg_unwind_data | |
| 160 { | |
| 161 /* Stream that we need to close */ | |
| 162 FILE *instream; | |
| 163 /* Object that holds state info for JPEG decoding */ | |
| 164 struct jpeg_decompress_struct *cinfo_ptr; | |
| 165 /* EImage data */ | |
| 2367 | 166 Binbyte *eimage; |
| 428 | 167 }; |
| 168 | |
| 169 static Lisp_Object | |
| 170 jpeg_instantiate_unwind (Lisp_Object unwind_obj) | |
| 171 { | |
| 172 struct jpeg_unwind_data *data = | |
| 173 (struct jpeg_unwind_data *) get_opaque_ptr (unwind_obj); | |
| 174 | |
| 175 free_opaque_ptr (unwind_obj); | |
| 176 if (data->cinfo_ptr) | |
| 177 jpeg_destroy_decompress (data->cinfo_ptr); | |
| 178 | |
| 179 if (data->instream) | |
|
5169
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5024
diff
changeset
|
180 { |
|
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5024
diff
changeset
|
181 retry_fclose (data->instream); |
|
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5024
diff
changeset
|
182 data->instream = 0; |
|
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5024
diff
changeset
|
183 } |
| 428 | 184 |
| 1726 | 185 if (data->eimage) |
|
5169
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5024
diff
changeset
|
186 { |
|
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5024
diff
changeset
|
187 xfree (data->eimage); |
|
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5024
diff
changeset
|
188 data->eimage = 0; |
|
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5024
diff
changeset
|
189 } |
| 428 | 190 |
| 191 return Qnil; | |
| 192 } | |
| 193 | |
| 194 /* | |
| 195 * ERROR HANDLING: | |
| 196 * | |
| 197 * The JPEG library's standard error handler (jerror.c) is divided into | |
| 198 * several "methods" which you can override individually. This lets you | |
| 199 * adjust the behavior without duplicating a lot of code, which you might | |
| 200 * have to update with each future release. | |
| 201 * | |
| 202 * Our example here shows how to override the "error_exit" method so that | |
| 203 * control is returned to the library's caller when a fatal error occurs, | |
| 204 * rather than calling exit() as the standard error_exit method does. | |
| 205 * | |
| 206 * We use C's setjmp/longjmp facility to return control. This means that the | |
| 207 * routine which calls the JPEG library must first execute a setjmp() call to | |
| 208 * establish the return point. We want the replacement error_exit to do a | |
| 209 * longjmp(). But we need to make the setjmp buffer accessible to the | |
| 210 * error_exit routine. To do this, we make a private extension of the | |
| 211 * standard JPEG error handler object. (If we were using C++, we'd say we | |
| 212 * were making a subclass of the regular error handler.) | |
| 213 * | |
| 214 * Here's the extended error handler struct: | |
| 215 */ | |
| 216 | |
| 217 struct my_jpeg_error_mgr | |
| 218 { | |
| 219 struct jpeg_error_mgr pub; /* "public" fields */ | |
| 220 jmp_buf setjmp_buffer; /* for return to caller */ | |
| 221 }; | |
| 222 | |
| 223 #if defined(JPEG_LIB_VERSION) && (JPEG_LIB_VERSION >= 61) | |
| 224 METHODDEF(void) | |
| 225 #else | |
| 226 METHODDEF void | |
| 227 #endif | |
| 2286 | 228 our_init_source (j_decompress_ptr UNUSED (cinfo)) |
| 428 | 229 { |
| 230 } | |
| 231 | |
| 232 #if defined(JPEG_LIB_VERSION) && (JPEG_LIB_VERSION >= 61) | |
| 233 METHODDEF(boolean) | |
| 234 #else | |
| 235 METHODDEF boolean | |
| 236 #endif | |
| 237 our_fill_input_buffer (j_decompress_ptr cinfo) | |
| 238 { | |
| 239 /* Insert a fake EOI marker */ | |
| 240 struct jpeg_source_mgr *src = cinfo->src; | |
| 241 static JOCTET buffer[2]; | |
| 242 | |
| 243 buffer[0] = (JOCTET) 0xFF; | |
| 244 buffer[1] = (JOCTET) JPEG_EOI; | |
| 245 | |
| 246 src->next_input_byte = buffer; | |
| 247 src->bytes_in_buffer = 2; | |
| 248 return TRUE; | |
| 249 } | |
| 250 | |
| 251 #if defined(JPEG_LIB_VERSION) && (JPEG_LIB_VERSION >= 61) | |
| 252 METHODDEF(void) | |
| 253 #else | |
| 254 METHODDEF void | |
| 255 #endif | |
| 256 our_skip_input_data (j_decompress_ptr cinfo, long num_bytes) | |
| 257 { | |
| 258 struct jpeg_source_mgr *src = NULL; | |
| 259 | |
| 260 src = (struct jpeg_source_mgr *) cinfo->src; | |
| 261 | |
| 262 if (!src) | |
| 647 | 263 return; |
| 264 else if (num_bytes > (long) src->bytes_in_buffer) | |
| 428 | 265 { |
| 647 | 266 ERREXIT (cinfo, JERR_INPUT_EOF); |
| 267 /*NOTREACHED*/ | |
| 268 } | |
| 428 | 269 |
| 270 src->bytes_in_buffer -= num_bytes; | |
| 271 src->next_input_byte += num_bytes; | |
| 272 } | |
| 273 | |
| 274 #if defined(JPEG_LIB_VERSION) && (JPEG_LIB_VERSION >= 61) | |
| 275 METHODDEF(void) | |
| 276 #else | |
| 277 METHODDEF void | |
| 278 #endif | |
| 2286 | 279 our_term_source (j_decompress_ptr UNUSED (cinfo)) |
| 428 | 280 { |
| 281 } | |
| 282 | |
| 283 typedef struct | |
| 284 { | |
| 285 struct jpeg_source_mgr pub; | |
| 286 } our_jpeg_source_mgr; | |
| 287 | |
| 288 static void | |
| 665 | 289 jpeg_memory_src (j_decompress_ptr cinfo, JOCTET *data, Bytecount len) |
| 428 | 290 { |
| 291 struct jpeg_source_mgr *src; | |
| 292 | |
| 293 if (cinfo->src == NULL) | |
| 294 { /* first time for this JPEG object? */ | |
| 295 cinfo->src = (struct jpeg_source_mgr *) | |
| 296 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, | |
| 297 sizeof(our_jpeg_source_mgr)); | |
| 298 src = (struct jpeg_source_mgr *) cinfo->src; | |
| 299 src->next_input_byte = data; | |
| 300 } | |
| 301 src = (struct jpeg_source_mgr *) cinfo->src; | |
| 302 src->init_source = our_init_source; | |
| 303 src->fill_input_buffer = our_fill_input_buffer; | |
| 304 src->skip_input_data = our_skip_input_data; | |
| 305 src->resync_to_restart = jpeg_resync_to_restart; /* use default method */ | |
| 306 src->term_source = our_term_source; | |
| 307 src->bytes_in_buffer = len; | |
| 308 src->next_input_byte = data; | |
| 309 } | |
| 310 | |
| 311 #if defined(JPEG_LIB_VERSION) && (JPEG_LIB_VERSION >= 61) | |
| 312 METHODDEF(void) | |
| 313 #else | |
| 314 METHODDEF void | |
| 315 #endif | |
| 316 my_jpeg_error_exit (j_common_ptr cinfo) | |
| 317 { | |
| 318 /* cinfo->err really points to a my_error_mgr struct, so coerce pointer */ | |
| 319 struct my_jpeg_error_mgr *myerr = (struct my_jpeg_error_mgr *) cinfo->err; | |
| 320 | |
| 321 /* Return control to the setjmp point */ | |
| 322 longjmp (myerr->setjmp_buffer, 1); | |
| 323 } | |
| 324 | |
| 325 #if defined(JPEG_LIB_VERSION) && (JPEG_LIB_VERSION >= 61) | |
| 326 METHODDEF(void) | |
| 327 #else | |
| 328 METHODDEF void | |
| 329 #endif | |
| 330 my_jpeg_output_message (j_common_ptr cinfo) | |
| 331 { | |
| 771 | 332 Extbyte buffer[JMSG_LENGTH_MAX]; |
| 867 | 333 Ibyte *intbuf; |
| 428 | 334 |
| 335 /* Create the message */ | |
| 336 (*cinfo->err->format_message) (cinfo, buffer); | |
|
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4953
diff
changeset
|
337 intbuf = EXTERNAL_TO_ITEXT (buffer, Qjpeg_error_message_encoding); |
| 771 | 338 warn_when_safe (Qjpeg, Qinfo, "%s", intbuf); |
| 428 | 339 } |
| 340 | |
| 341 /* The code in this routine is based on example.c from the JPEG library | |
| 342 source code and from gif_instantiate() */ | |
| 343 static void | |
| 344 jpeg_instantiate (Lisp_Object image_instance, Lisp_Object instantiator, | |
| 2959 | 345 Lisp_Object pointer_fg, Lisp_Object pointer_bg, |
| 428 | 346 int dest_mask, Lisp_Object domain) |
| 347 { | |
| 440 | 348 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance); |
| 428 | 349 /* It is OK for the unwind data to be local to this function, |
| 350 because the unwind-protect is always executed when this | |
| 351 stack frame is still valid. */ | |
| 352 struct jpeg_unwind_data unwind; | |
| 353 int speccount = specpdl_depth (); | |
| 354 | |
| 355 /* This struct contains the JPEG decompression parameters and pointers to | |
| 356 * working space (which is allocated as needed by the JPEG library). | |
| 357 */ | |
| 358 struct jpeg_decompress_struct cinfo; | |
| 359 /* We use our private extension JPEG error handler. | |
| 360 * Note that this struct must live as long as the main JPEG parameter | |
| 361 * struct, to avoid dangling-pointer problems. | |
| 362 */ | |
| 363 struct my_jpeg_error_mgr jerr; | |
| 364 | |
| 365 /* Step -1: First record our unwind-protect, which will clean up after | |
| 366 any exit, normal or not */ | |
| 367 | |
| 368 xzero (unwind); | |
| 369 record_unwind_protect (jpeg_instantiate_unwind, make_opaque_ptr (&unwind)); | |
| 370 | |
| 371 /* Step 1: allocate and initialize JPEG decompression object */ | |
| 372 | |
| 373 /* We set up the normal JPEG error routines, then override error_exit. */ | |
| 374 cinfo.err = jpeg_std_error (&jerr.pub); | |
| 375 jerr.pub.error_exit = my_jpeg_error_exit; | |
| 376 jerr.pub.output_message = my_jpeg_output_message; | |
| 377 | |
| 378 /* Establish the setjmp return context for my_error_exit to use. */ | |
| 379 if (setjmp (jerr.setjmp_buffer)) | |
| 380 { | |
| 381 /* If we get here, the JPEG code has signaled an error. | |
| 382 * We need to clean up the JPEG object, close the input file, and return. | |
| 383 */ | |
| 384 | |
| 385 { | |
| 386 Lisp_Object errstring; | |
| 771 | 387 Extbyte buffer[JMSG_LENGTH_MAX]; |
| 428 | 388 |
| 389 /* Create the message */ | |
| 390 (*cinfo.err->format_message) ((j_common_ptr) &cinfo, buffer); | |
|
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
391 errstring = build_extstring (buffer, Qjpeg_error_message_encoding); |
| 428 | 392 |
| 393 signal_image_error_2 ("JPEG decoding error", | |
| 394 errstring, instantiator); | |
| 395 } | |
| 396 } | |
| 397 | |
| 398 /* Now we can initialize the JPEG decompression object. */ | |
| 399 jpeg_create_decompress (&cinfo); | |
| 400 unwind.cinfo_ptr = &cinfo; | |
| 401 | |
| 402 /* Step 2: specify data source (eg, a file) */ | |
| 403 | |
| 404 { | |
| 405 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data); | |
| 2367 | 406 const Binbyte *bytes; |
| 665 | 407 Bytecount len; |
| 428 | 408 |
| 409 /* #### This is a definite problem under Mule due to the amount of | |
| 410 stack data it might allocate. Need to be able to convert and | |
| 411 write out to a file. */ | |
|
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4953
diff
changeset
|
412 LISP_STRING_TO_SIZED_EXTERNAL (data, bytes, len, Qbinary); |
| 428 | 413 jpeg_memory_src (&cinfo, (JOCTET *) bytes, len); |
| 414 } | |
| 415 | |
| 416 /* Step 3: read file parameters with jpeg_read_header() */ | |
| 417 | |
| 418 jpeg_read_header (&cinfo, TRUE); | |
| 419 /* We can ignore the return value from jpeg_read_header since | |
| 420 * (a) suspension is not possible with the stdio data source, and | |
| 421 * (b) we passed TRUE to reject a tables-only JPEG file as an error. | |
| 422 * See libjpeg.doc for more info. | |
| 423 */ | |
| 424 | |
| 425 { | |
|
4646
6c6bfdb80a0c
Prevent integer overflow and subsequent crashes when attempting to load large
Jerry James <james@xemacs.org>
parents:
4326
diff
changeset
|
426 UINT_64_BIT pixels_sq; |
| 428 | 427 int jpeg_gray = 0; /* if we're dealing with a grayscale */ |
| 428 /* Step 4: set parameters for decompression. */ | |
| 429 | |
| 430 /* Now that we're using EImages, send all data as 24bit color. | |
| 431 The backend routine will take care of any necessary reductions. | |
| 432 We do have to handle the grayscale case ourselves, however. */ | |
| 433 if (cinfo.jpeg_color_space == JCS_GRAYSCALE) | |
| 434 { | |
| 435 cinfo.out_color_space = JCS_GRAYSCALE; | |
| 436 jpeg_gray = 1; | |
| 437 } | |
| 438 else | |
| 439 { | |
| 440 /* we're relying on the jpeg driver to do any other conversions, | |
| 441 or signal an error if the conversion isn't supported. */ | |
| 442 cinfo.out_color_space = JCS_RGB; | |
| 443 } | |
| 444 | |
| 445 /* Step 5: Start decompressor */ | |
| 446 jpeg_start_decompress (&cinfo); | |
| 447 | |
| 448 /* Step 6: Read in the data and put into EImage format (8bit RGB triples)*/ | |
|
4646
6c6bfdb80a0c
Prevent integer overflow and subsequent crashes when attempting to load large
Jerry James <james@xemacs.org>
parents:
4326
diff
changeset
|
449 pixels_sq = |
|
6c6bfdb80a0c
Prevent integer overflow and subsequent crashes when attempting to load large
Jerry James <james@xemacs.org>
parents:
4326
diff
changeset
|
450 (UINT_64_BIT) cinfo.output_width * (UINT_64_BIT) cinfo.output_height; |
|
6c6bfdb80a0c
Prevent integer overflow and subsequent crashes when attempting to load large
Jerry James <james@xemacs.org>
parents:
4326
diff
changeset
|
451 if (pixels_sq > ((size_t) -1) / 3) |
|
6c6bfdb80a0c
Prevent integer overflow and subsequent crashes when attempting to load large
Jerry James <james@xemacs.org>
parents:
4326
diff
changeset
|
452 signal_image_error ("JPEG image too large to instantiate", instantiator); |
| 2367 | 453 unwind.eimage = |
| 454 xnew_binbytes (cinfo.output_width * cinfo.output_height * 3); | |
| 428 | 455 if (!unwind.eimage) |
| 456 signal_image_error("Unable to allocate enough memory for image", instantiator); | |
| 457 | |
| 458 { | |
| 459 JSAMPARRAY row_buffer; /* Output row buffer */ | |
| 460 JSAMPLE *jp; | |
| 461 int row_stride; /* physical row width in output buffer */ | |
| 2367 | 462 Binbyte *op = unwind.eimage; |
| 428 | 463 |
| 464 /* We may need to do some setup of our own at this point before reading | |
| 465 * the data. After jpeg_start_decompress() we have the correct scaled | |
| 466 * output image dimensions available | |
| 467 * We need to make an output work buffer of the right size. | |
| 468 */ | |
| 469 /* JSAMPLEs per row in output buffer. */ | |
| 470 row_stride = cinfo.output_width * cinfo.output_components; | |
| 471 /* Make a one-row-high sample array that will go away when done | |
| 472 with image */ | |
| 473 row_buffer = ((*cinfo.mem->alloc_sarray) | |
| 474 ((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1)); | |
| 475 | |
| 476 /* Here we use the library's state variable cinfo.output_scanline as the | |
| 477 * loop counter, so that we don't have to keep track ourselves. | |
| 478 */ | |
| 479 while (cinfo.output_scanline < cinfo.output_height) | |
| 480 { | |
| 481 int i; | |
| 482 | |
| 483 /* jpeg_read_scanlines expects an array of pointers to scanlines. | |
| 484 * Here the array is only one element long, but you could ask for | |
| 485 * more than one scanline at a time if that's more convenient. | |
| 486 */ | |
| 487 (void) jpeg_read_scanlines (&cinfo, row_buffer, 1); | |
| 488 jp = row_buffer[0]; | |
| 647 | 489 for (i = 0; i < (int) cinfo.output_width; i++) |
| 428 | 490 { |
| 491 int clr; | |
| 492 if (jpeg_gray) | |
| 493 { | |
| 2367 | 494 Binbyte val; |
| 428 | 495 #if (BITS_IN_JSAMPLE == 8) |
| 2367 | 496 val = (Binbyte) *jp++; |
| 428 | 497 #else /* other option is 12 */ |
| 2367 | 498 val = (Binbyte) (*jp++ >> 4); |
| 428 | 499 #endif |
| 500 for (clr = 0; clr < 3; clr++) /* copy the same value into RGB */ | |
| 501 *op++ = val; | |
| 502 } | |
| 503 else | |
| 504 { | |
| 505 for (clr = 0; clr < 3; clr++) | |
| 506 #if (BITS_IN_JSAMPLE == 8) | |
| 2367 | 507 *op++ = (Binbyte)*jp++; |
| 428 | 508 #else /* other option is 12 */ |
| 2367 | 509 *op++ = (Binbyte)(*jp++ >> 4); |
| 428 | 510 #endif |
| 511 } | |
| 512 } | |
| 513 } | |
| 514 } | |
| 515 } | |
| 516 | |
| 517 /* Step 6.5: Create the pixmap and set up the image instance */ | |
| 518 /* now instantiate */ | |
| 442 | 519 MAYBE_DEVMETH (DOMAIN_XDEVICE (ii->domain), |
| 428 | 520 init_image_instance_from_eimage, |
| 521 (ii, cinfo.output_width, cinfo.output_height, 1, | |
| 522 unwind.eimage, dest_mask, | |
| 2959 | 523 instantiator, pointer_fg, pointer_bg, domain)); |
| 428 | 524 |
| 525 /* Step 7: Finish decompression */ | |
| 526 | |
| 527 jpeg_finish_decompress (&cinfo); | |
| 528 /* We can ignore the return value since suspension is not possible | |
| 529 * with the stdio data source. | |
| 530 */ | |
| 531 | |
| 532 /* And we're done! */ | |
| 533 /* This will clean up everything else. */ | |
| 771 | 534 unbind_to (speccount); |
| 428 | 535 } |
| 536 | |
| 537 #endif /* HAVE_JPEG */ | |
| 538 | |
| 539 #ifdef HAVE_GIF | |
| 540 /********************************************************************** | |
| 541 * GIF * | |
| 542 **********************************************************************/ | |
| 543 | |
|
4708
1cecc3e9f0a0
Use giflib or libungif to provide GIF support, instead of using internal
Jerry James <james@xemacs.org>
parents:
4698
diff
changeset
|
544 #include <gif_lib.h> |
| 428 | 545 |
| 546 static void | |
| 547 gif_validate (Lisp_Object instantiator) | |
| 548 { | |
| 549 file_or_data_must_be_present (instantiator); | |
| 550 } | |
| 551 | |
| 552 static Lisp_Object | |
| 442 | 553 gif_normalize (Lisp_Object inst, Lisp_Object console_type, |
| 2286 | 554 Lisp_Object UNUSED (dest_mask)) |
| 428 | 555 { |
| 556 return simple_image_type_normalize (inst, console_type, Qgif); | |
| 557 } | |
| 558 | |
| 559 static int | |
| 560 gif_possible_dest_types (void) | |
| 561 { | |
| 562 return IMAGE_COLOR_PIXMAP_MASK; | |
| 563 } | |
| 564 | |
| 565 /* To survive the otherwise baffling complexity of making sure | |
| 566 everything gets cleaned up in the presence of an error, we | |
| 567 use an unwind_protect(). */ | |
| 568 | |
| 569 struct gif_unwind_data | |
| 570 { | |
| 2367 | 571 Binbyte *eimage; |
| 428 | 572 /* Object that holds the decoded data from a GIF file */ |
| 573 GifFileType *giffile; | |
| 574 }; | |
| 575 | |
| 576 static Lisp_Object | |
| 577 gif_instantiate_unwind (Lisp_Object unwind_obj) | |
| 578 { | |
| 579 struct gif_unwind_data *data = | |
| 580 (struct gif_unwind_data *) get_opaque_ptr (unwind_obj); | |
| 581 | |
| 582 free_opaque_ptr (unwind_obj); | |
| 583 if (data->giffile) | |
| 584 { | |
| 585 DGifCloseFile (data->giffile); | |
|
5169
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5024
diff
changeset
|
586 FreeSavedImages (data->giffile); |
|
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5024
diff
changeset
|
587 data->giffile = 0; |
| 428 | 588 } |
| 647 | 589 if (data->eimage) |
|
5169
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5024
diff
changeset
|
590 { |
|
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5024
diff
changeset
|
591 xfree (data->eimage); |
|
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5024
diff
changeset
|
592 data->eimage = 0; |
|
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5024
diff
changeset
|
593 } |
| 428 | 594 |
| 595 return Qnil; | |
| 596 } | |
| 597 | |
| 598 typedef struct gif_memory_storage | |
| 599 { | |
| 2367 | 600 Binbyte *bytes; /* The data */ |
| 665 | 601 Bytecount len; /* How big is it? */ |
| 602 Bytecount index; /* Where are we? */ | |
| 428 | 603 } gif_memory_storage; |
| 604 | |
|
4708
1cecc3e9f0a0
Use giflib or libungif to provide GIF support, instead of using internal
Jerry James <james@xemacs.org>
parents:
4698
diff
changeset
|
605 static int |
|
1cecc3e9f0a0
Use giflib or libungif to provide GIF support, instead of using internal
Jerry James <james@xemacs.org>
parents:
4698
diff
changeset
|
606 gif_read_from_memory (GifFileType *gif, GifByteType *buf, int size) |
| 428 | 607 { |
|
4708
1cecc3e9f0a0
Use giflib or libungif to provide GIF support, instead of using internal
Jerry James <james@xemacs.org>
parents:
4698
diff
changeset
|
608 gif_memory_storage *mem = (gif_memory_storage *) gif->UserData; |
| 428 | 609 |
| 610 if (size > (mem->len - mem->index)) | |
| 647 | 611 return -1; |
| 612 memcpy (buf, mem->bytes + mem->index, size); | |
| 428 | 613 mem->index = mem->index + size; |
| 614 return size; | |
| 615 } | |
| 616 | |
|
4708
1cecc3e9f0a0
Use giflib or libungif to provide GIF support, instead of using internal
Jerry James <james@xemacs.org>
parents:
4698
diff
changeset
|
617 static const char * |
|
5016
2ade80e8c640
enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents:
4982
diff
changeset
|
618 gif_decode_error_string (void) |
| 428 | 619 { |
|
4708
1cecc3e9f0a0
Use giflib or libungif to provide GIF support, instead of using internal
Jerry James <james@xemacs.org>
parents:
4698
diff
changeset
|
620 switch (GifLastError ()) |
|
1cecc3e9f0a0
Use giflib or libungif to provide GIF support, instead of using internal
Jerry James <james@xemacs.org>
parents:
4698
diff
changeset
|
621 { |
|
1cecc3e9f0a0
Use giflib or libungif to provide GIF support, instead of using internal
Jerry James <james@xemacs.org>
parents:
4698
diff
changeset
|
622 case D_GIF_ERR_OPEN_FAILED: |
|
1cecc3e9f0a0
Use giflib or libungif to provide GIF support, instead of using internal
Jerry James <james@xemacs.org>
parents:
4698
diff
changeset
|
623 return "GIF error: unable to open"; |
|
1cecc3e9f0a0
Use giflib or libungif to provide GIF support, instead of using internal
Jerry James <james@xemacs.org>
parents:
4698
diff
changeset
|
624 case D_GIF_ERR_READ_FAILED: |
|
1cecc3e9f0a0
Use giflib or libungif to provide GIF support, instead of using internal
Jerry James <james@xemacs.org>
parents:
4698
diff
changeset
|
625 return "GIF error: read failed"; |
|
1cecc3e9f0a0
Use giflib or libungif to provide GIF support, instead of using internal
Jerry James <james@xemacs.org>
parents:
4698
diff
changeset
|
626 case D_GIF_ERR_NOT_GIF_FILE: |
|
1cecc3e9f0a0
Use giflib or libungif to provide GIF support, instead of using internal
Jerry James <james@xemacs.org>
parents:
4698
diff
changeset
|
627 return "GIF error: not a GIF file"; |
|
1cecc3e9f0a0
Use giflib or libungif to provide GIF support, instead of using internal
Jerry James <james@xemacs.org>
parents:
4698
diff
changeset
|
628 case D_GIF_ERR_NO_SCRN_DSCR: |
|
1cecc3e9f0a0
Use giflib or libungif to provide GIF support, instead of using internal
Jerry James <james@xemacs.org>
parents:
4698
diff
changeset
|
629 return "GIF error: no Screen Descriptor detected"; |
|
1cecc3e9f0a0
Use giflib or libungif to provide GIF support, instead of using internal
Jerry James <james@xemacs.org>
parents:
4698
diff
changeset
|
630 case D_GIF_ERR_NO_IMAG_DSCR: |
|
1cecc3e9f0a0
Use giflib or libungif to provide GIF support, instead of using internal
Jerry James <james@xemacs.org>
parents:
4698
diff
changeset
|
631 return "GIF error: no Image Descriptor detected"; |
|
1cecc3e9f0a0
Use giflib or libungif to provide GIF support, instead of using internal
Jerry James <james@xemacs.org>
parents:
4698
diff
changeset
|
632 case D_GIF_ERR_NO_COLOR_MAP: |
|
1cecc3e9f0a0
Use giflib or libungif to provide GIF support, instead of using internal
Jerry James <james@xemacs.org>
parents:
4698
diff
changeset
|
633 return "GIF error: no global or local color map"; |
|
1cecc3e9f0a0
Use giflib or libungif to provide GIF support, instead of using internal
Jerry James <james@xemacs.org>
parents:
4698
diff
changeset
|
634 case D_GIF_ERR_WRONG_RECORD: |
|
1cecc3e9f0a0
Use giflib or libungif to provide GIF support, instead of using internal
Jerry James <james@xemacs.org>
parents:
4698
diff
changeset
|
635 return "GIF error: wrong record type"; |
|
1cecc3e9f0a0
Use giflib or libungif to provide GIF support, instead of using internal
Jerry James <james@xemacs.org>
parents:
4698
diff
changeset
|
636 case D_GIF_ERR_DATA_TOO_BIG: |
|
1cecc3e9f0a0
Use giflib or libungif to provide GIF support, instead of using internal
Jerry James <james@xemacs.org>
parents:
4698
diff
changeset
|
637 return "GIF error: image is larger than indicated by header"; |
|
1cecc3e9f0a0
Use giflib or libungif to provide GIF support, instead of using internal
Jerry James <james@xemacs.org>
parents:
4698
diff
changeset
|
638 case D_GIF_ERR_NOT_ENOUGH_MEM: |
|
1cecc3e9f0a0
Use giflib or libungif to provide GIF support, instead of using internal
Jerry James <james@xemacs.org>
parents:
4698
diff
changeset
|
639 return "GIF error: out of memory"; |
|
1cecc3e9f0a0
Use giflib or libungif to provide GIF support, instead of using internal
Jerry James <james@xemacs.org>
parents:
4698
diff
changeset
|
640 case D_GIF_ERR_CLOSE_FAILED: |
|
1cecc3e9f0a0
Use giflib or libungif to provide GIF support, instead of using internal
Jerry James <james@xemacs.org>
parents:
4698
diff
changeset
|
641 return "GIF error: failed to close file"; |
|
1cecc3e9f0a0
Use giflib or libungif to provide GIF support, instead of using internal
Jerry James <james@xemacs.org>
parents:
4698
diff
changeset
|
642 case D_GIF_ERR_NOT_READABLE: |
|
1cecc3e9f0a0
Use giflib or libungif to provide GIF support, instead of using internal
Jerry James <james@xemacs.org>
parents:
4698
diff
changeset
|
643 return "GIF error: file is not readable"; |
|
1cecc3e9f0a0
Use giflib or libungif to provide GIF support, instead of using internal
Jerry James <james@xemacs.org>
parents:
4698
diff
changeset
|
644 case D_GIF_ERR_IMAGE_DEFECT: |
|
1cecc3e9f0a0
Use giflib or libungif to provide GIF support, instead of using internal
Jerry James <james@xemacs.org>
parents:
4698
diff
changeset
|
645 return "GIF error: image is defective"; |
|
1cecc3e9f0a0
Use giflib or libungif to provide GIF support, instead of using internal
Jerry James <james@xemacs.org>
parents:
4698
diff
changeset
|
646 case D_GIF_ERR_EOF_TOO_SOON: |
|
1cecc3e9f0a0
Use giflib or libungif to provide GIF support, instead of using internal
Jerry James <james@xemacs.org>
parents:
4698
diff
changeset
|
647 return "GIF error: image EOF detected before image complete"; |
|
1cecc3e9f0a0
Use giflib or libungif to provide GIF support, instead of using internal
Jerry James <james@xemacs.org>
parents:
4698
diff
changeset
|
648 default: |
|
1cecc3e9f0a0
Use giflib or libungif to provide GIF support, instead of using internal
Jerry James <james@xemacs.org>
parents:
4698
diff
changeset
|
649 return "GIF error: unknown error"; |
|
1cecc3e9f0a0
Use giflib or libungif to provide GIF support, instead of using internal
Jerry James <james@xemacs.org>
parents:
4698
diff
changeset
|
650 } |
| 428 | 651 } |
| 652 | |
| 653 static void | |
| 654 gif_instantiate (Lisp_Object image_instance, Lisp_Object instantiator, | |
| 2959 | 655 Lisp_Object pointer_fg, Lisp_Object pointer_bg, |
| 428 | 656 int dest_mask, Lisp_Object domain) |
| 657 { | |
| 440 | 658 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance); |
| 428 | 659 /* It is OK for the unwind data to be local to this function, |
| 660 because the unwind-protect is always executed when this | |
| 661 stack frame is still valid. */ | |
| 662 struct gif_unwind_data unwind; | |
| 663 int speccount = specpdl_depth (); | |
| 664 gif_memory_storage mem_struct; | |
| 2367 | 665 Binbyte *bytes; |
| 665 | 666 Bytecount len; |
| 428 | 667 int height = 0; |
| 668 int width = 0; | |
| 669 | |
| 670 xzero (unwind); | |
| 671 record_unwind_protect (gif_instantiate_unwind, make_opaque_ptr (&unwind)); | |
| 672 | |
| 673 /* 1. Now decode the data. */ | |
| 674 | |
| 675 { | |
| 676 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data); | |
| 677 | |
| 678 assert (!NILP (data)); | |
| 679 | |
|
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4953
diff
changeset
|
680 LISP_STRING_TO_SIZED_EXTERNAL (data, bytes, len, Qbinary); |
| 428 | 681 mem_struct.bytes = bytes; |
| 682 mem_struct.len = len; | |
| 683 mem_struct.index = 0; | |
|
4708
1cecc3e9f0a0
Use giflib or libungif to provide GIF support, instead of using internal
Jerry James <james@xemacs.org>
parents:
4698
diff
changeset
|
684 unwind.giffile = DGifOpen (&mem_struct, gif_read_from_memory); |
|
1cecc3e9f0a0
Use giflib or libungif to provide GIF support, instead of using internal
Jerry James <james@xemacs.org>
parents:
4698
diff
changeset
|
685 if (unwind.giffile == NULL) |
|
1cecc3e9f0a0
Use giflib or libungif to provide GIF support, instead of using internal
Jerry James <james@xemacs.org>
parents:
4698
diff
changeset
|
686 signal_image_error (gif_decode_error_string (), instantiator); |
| 428 | 687 |
| 688 /* Then slurp the image into memory, decoding along the way. | |
| 689 The result is the image in a simple one-byte-per-pixel | |
|
4708
1cecc3e9f0a0
Use giflib or libungif to provide GIF support, instead of using internal
Jerry James <james@xemacs.org>
parents:
4698
diff
changeset
|
690 format. */ |
|
1cecc3e9f0a0
Use giflib or libungif to provide GIF support, instead of using internal
Jerry James <james@xemacs.org>
parents:
4698
diff
changeset
|
691 if (DGifSlurp (unwind.giffile) == GIF_ERROR) |
|
1cecc3e9f0a0
Use giflib or libungif to provide GIF support, instead of using internal
Jerry James <james@xemacs.org>
parents:
4698
diff
changeset
|
692 signal_image_error (gif_decode_error_string (), instantiator); |
| 428 | 693 } |
| 694 | |
| 695 /* 3. Now create the EImage(s) */ | |
| 696 { | |
|
5250
db84c9d41437
Apply GIF colormap fix from Adam Sjogren for issues 150 and 713
Vin Shelton <acs@xemacs.org>
parents:
5178
diff
changeset
|
697 ColorMapObject *cmo = (unwind.giffile->Image.ColorMap ? unwind.giffile->Image.ColorMap : unwind.giffile->SColorMap); |
| 428 | 698 int i, j, row, pass, interlace, slice; |
|
4646
6c6bfdb80a0c
Prevent integer overflow and subsequent crashes when attempting to load large
Jerry James <james@xemacs.org>
parents:
4326
diff
changeset
|
699 UINT_64_BIT pixels_sq; |
| 2367 | 700 Binbyte *eip; |
| 428 | 701 /* interlaced gifs have rows in this order: |
| 702 0, 8, 16, ..., 4, 12, 20, ..., 2, 6, 10, ..., 1, 3, 5, ... */ | |
| 703 static int InterlacedOffset[] = { 0, 4, 2, 1 }; | |
| 704 static int InterlacedJumps[] = { 8, 8, 4, 2 }; | |
| 705 | |
|
5250
db84c9d41437
Apply GIF colormap fix from Adam Sjogren for issues 150 and 713
Vin Shelton <acs@xemacs.org>
parents:
5178
diff
changeset
|
706 if (cmo == NULL) |
|
db84c9d41437
Apply GIF colormap fix from Adam Sjogren for issues 150 and 713
Vin Shelton <acs@xemacs.org>
parents:
5178
diff
changeset
|
707 signal_image_error ("GIF image has no color map", instantiator); |
|
db84c9d41437
Apply GIF colormap fix from Adam Sjogren for issues 150 and 713
Vin Shelton <acs@xemacs.org>
parents:
5178
diff
changeset
|
708 |
| 428 | 709 height = unwind.giffile->SHeight; |
| 710 width = unwind.giffile->SWidth; | |
|
4646
6c6bfdb80a0c
Prevent integer overflow and subsequent crashes when attempting to load large
Jerry James <james@xemacs.org>
parents:
4326
diff
changeset
|
711 pixels_sq = (UINT_64_BIT) width * (UINT_64_BIT) height; |
|
6c6bfdb80a0c
Prevent integer overflow and subsequent crashes when attempting to load large
Jerry James <james@xemacs.org>
parents:
4326
diff
changeset
|
712 if (pixels_sq > ((size_t) -1) / (3 * unwind.giffile->ImageCount)) |
|
6c6bfdb80a0c
Prevent integer overflow and subsequent crashes when attempting to load large
Jerry James <james@xemacs.org>
parents:
4326
diff
changeset
|
713 signal_image_error ("GIF image too large to instantiate", instantiator); |
| 2367 | 714 unwind.eimage = |
| 715 xnew_binbytes (width * height * 3 * unwind.giffile->ImageCount); | |
| 428 | 716 if (!unwind.eimage) |
| 717 signal_image_error("Unable to allocate enough memory for image", instantiator); | |
| 718 | |
| 719 /* write the data in EImage format (8bit RGB triples) */ | |
| 720 | |
| 721 for (slice = 0; slice < unwind.giffile->ImageCount; slice++) | |
| 722 { | |
| 638 | 723 /* We check here that the current image covers the full "screen" size. */ |
| 428 | 724 if (unwind.giffile->SavedImages[slice].ImageDesc.Height != height |
| 725 || unwind.giffile->SavedImages[slice].ImageDesc.Width != width | |
| 726 || unwind.giffile->SavedImages[slice].ImageDesc.Left != 0 | |
| 727 || unwind.giffile->SavedImages[slice].ImageDesc.Top != 0) | |
| 728 signal_image_error ("Image in GIF file is not full size", | |
| 729 instantiator); | |
| 730 | |
| 731 interlace = unwind.giffile->SavedImages[slice].ImageDesc.Interlace; | |
| 732 pass = 0; | |
| 733 row = interlace ? InterlacedOffset[pass] : 0; | |
| 734 eip = unwind.eimage + (width * height * 3 * slice); | |
| 735 for (i = 0; i < height; i++) | |
| 736 { | |
| 737 if (interlace) | |
| 738 if (row >= height) { | |
| 739 row = InterlacedOffset[++pass]; | |
| 740 while (row >= height) | |
| 741 row = InterlacedOffset[++pass]; | |
| 742 } | |
| 743 eip = unwind.eimage + (width * height * 3 * slice) + (row * width * 3); | |
| 744 for (j = 0; j < width; j++) | |
| 745 { | |
| 2367 | 746 Binbyte pixel = |
| 428 | 747 unwind.giffile->SavedImages[slice].RasterBits[(i * width) + j]; |
| 748 *eip++ = cmo->Colors[pixel].Red; | |
| 749 *eip++ = cmo->Colors[pixel].Green; | |
| 750 *eip++ = cmo->Colors[pixel].Blue; | |
| 751 } | |
| 752 row += interlace ? InterlacedJumps[pass] : 1; | |
| 753 } | |
| 754 } | |
| 755 | |
| 756 /* now instantiate */ | |
| 442 | 757 MAYBE_DEVMETH (DOMAIN_XDEVICE (ii->domain), |
| 428 | 758 init_image_instance_from_eimage, |
| 2959 | 759 (ii, width, height, unwind.giffile->ImageCount, |
| 760 unwind.eimage, dest_mask, instantiator, pointer_fg, | |
| 761 pointer_bg, domain)); | |
| 428 | 762 } |
| 763 | |
| 764 /* We read the gif successfully. If we have more than one slice then | |
| 765 animate the gif. */ | |
| 766 if (unwind.giffile->ImageCount > 1) | |
| 767 { | |
| 768 /* See if there is a timeout value. In theory there could be one | |
|
4708
1cecc3e9f0a0
Use giflib or libungif to provide GIF support, instead of using internal
Jerry James <james@xemacs.org>
parents:
4698
diff
changeset
|
769 for every image - but that makes the implementation way too |
| 428 | 770 complicated for now so we just take the first. */ |
| 771 unsigned short timeout = 0; | |
| 772 Lisp_Object tid; | |
| 773 | |
| 774 if (unwind.giffile->SavedImages[0].Function == GRAPHICS_EXT_FUNC_CODE | |
| 775 && | |
| 776 unwind.giffile->SavedImages[0].ExtensionBlockCount) | |
| 777 { | |
| 778 timeout = (unsigned short) | |
| 438 | 779 ((unwind.giffile->SavedImages[0].ExtensionBlocks[0].Bytes[2] << 8) + |
| 428 | 780 unwind.giffile-> SavedImages[0].ExtensionBlocks[0].Bytes[1]) * 10; |
| 781 } | |
| 782 | |
| 783 /* Too short a timeout will crucify us performance-wise. */ | |
| 784 tid = add_glyph_animated_timeout (timeout > 10 ? timeout : 10, image_instance); | |
| 785 | |
| 786 if (!NILP (tid)) | |
| 787 IMAGE_INSTANCE_PIXMAP_TIMEOUT (ii) = XINT (tid); | |
| 788 } | |
| 438 | 789 |
| 771 | 790 unbind_to (speccount); |
| 428 | 791 } |
| 792 | |
| 793 #endif /* HAVE_GIF */ | |
| 794 | |
| 795 | |
| 796 #ifdef HAVE_PNG | |
| 797 | |
| 798 /********************************************************************** | |
| 799 * PNG * | |
| 800 **********************************************************************/ | |
| 801 static void | |
| 802 png_validate (Lisp_Object instantiator) | |
| 803 { | |
| 804 file_or_data_must_be_present (instantiator); | |
| 805 } | |
| 806 | |
| 807 static Lisp_Object | |
| 442 | 808 png_normalize (Lisp_Object inst, Lisp_Object console_type, |
| 2286 | 809 Lisp_Object UNUSED (dest_mask)) |
| 428 | 810 { |
| 811 return simple_image_type_normalize (inst, console_type, Qpng); | |
| 812 } | |
| 813 | |
| 814 static int | |
| 815 png_possible_dest_types (void) | |
| 816 { | |
| 817 return IMAGE_COLOR_PIXMAP_MASK; | |
| 818 } | |
| 819 | |
| 820 struct png_memory_storage | |
| 821 { | |
| 2367 | 822 const Binbyte *bytes; /* The data */ |
| 665 | 823 Bytecount len; /* How big is it? */ |
| 824 Bytecount index; /* Where are we? */ | |
| 428 | 825 }; |
| 826 | |
| 827 static void | |
| 647 | 828 png_read_from_memory (png_structp png_ptr, png_bytep data, |
| 829 png_size_t length) | |
| 428 | 830 { |
| 831 struct png_memory_storage *tbr = | |
| 832 (struct png_memory_storage *) png_get_io_ptr (png_ptr); | |
| 833 | |
| 665 | 834 if ((Bytecount) length > (tbr->len - tbr->index)) |
| 428 | 835 png_error (png_ptr, (png_const_charp) "Read Error"); |
| 647 | 836 memcpy (data, tbr->bytes + tbr->index,length); |
| 428 | 837 tbr->index = tbr->index + length; |
| 838 } | |
| 839 | |
| 840 struct png_error_struct | |
| 841 { | |
| 442 | 842 const char *err_str; |
| 428 | 843 jmp_buf setjmp_buffer; /* for return to caller */ |
| 844 }; | |
| 845 | |
| 846 /* jh 98/03/12 - #### AARRRGH! libpng includes jmp_buf inside its own | |
| 847 structure, and there are cases where the size can be different from | |
| 848 between inside the library, and inside the code! To do an end run | |
| 849 around this, use our own error functions, and don't rely on things | |
| 850 passed in the png_ptr to them. This is an ugly hack and must | |
| 851 go away when the lisp engine is threaded! */ | |
| 852 static struct png_error_struct png_err_stct; | |
| 853 | |
| 854 static void | |
| 2286 | 855 png_error_func (png_structp UNUSED (png_ptr), png_const_charp msg) |
| 428 | 856 { |
| 857 png_err_stct.err_str = msg; | |
| 858 longjmp (png_err_stct.setjmp_buffer, 1); | |
| 859 } | |
| 860 | |
| 861 static void | |
| 2286 | 862 png_warning_func (png_structp UNUSED (png_ptr), png_const_charp msg) |
| 428 | 863 { |
| 3734 | 864 DECLARE_EISTRING (eimsg); |
| 865 | |
| 866 eicpy_ext(eimsg, msg, Qbinary); | |
| 867 warn_when_safe (Qpng, Qinfo, "%s", eidata(eimsg)); | |
| 428 | 868 } |
| 869 | |
| 870 struct png_unwind_data | |
| 871 { | |
| 872 FILE *instream; | |
| 2367 | 873 Binbyte *eimage; |
| 428 | 874 png_structp png_ptr; |
| 875 png_infop info_ptr; | |
| 876 }; | |
| 877 | |
| 878 static Lisp_Object | |
| 879 png_instantiate_unwind (Lisp_Object unwind_obj) | |
| 880 { | |
| 881 struct png_unwind_data *data = | |
| 882 (struct png_unwind_data *) get_opaque_ptr (unwind_obj); | |
| 883 | |
| 884 free_opaque_ptr (unwind_obj); | |
| 885 if (data->png_ptr) | |
| 3839 | 886 { |
| 887 /* ensure we can't get here again */ | |
| 888 png_structp tmp = data->png_ptr; | |
| 889 data->png_ptr = NULL; | |
| 890 png_destroy_read_struct (&tmp, &(data->info_ptr), (png_infopp)NULL); | |
| 891 } | |
| 892 | |
| 428 | 893 if (data->instream) |
|
5169
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5024
diff
changeset
|
894 { |
|
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5024
diff
changeset
|
895 retry_fclose (data->instream); |
|
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5024
diff
changeset
|
896 data->instream = 0; |
|
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5024
diff
changeset
|
897 } |
| 428 | 898 |
| 1726 | 899 if (data->eimage) |
|
5169
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5024
diff
changeset
|
900 { |
|
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5024
diff
changeset
|
901 xfree (data->eimage); |
|
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5024
diff
changeset
|
902 data->eimage = 0; |
|
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5024
diff
changeset
|
903 } |
| 428 | 904 |
| 905 return Qnil; | |
| 906 } | |
| 907 | |
| 908 static void | |
| 909 png_instantiate (Lisp_Object image_instance, Lisp_Object instantiator, | |
| 2959 | 910 Lisp_Object pointer_fg, Lisp_Object pointer_bg, |
| 428 | 911 int dest_mask, Lisp_Object domain) |
| 912 { | |
| 440 | 913 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance); |
| 428 | 914 struct png_unwind_data unwind; |
| 915 int speccount = specpdl_depth (); | |
| 916 int height, width; | |
| 917 struct png_memory_storage tbr; /* Data to be read */ | |
| 918 | |
| 919 /* PNG variables */ | |
| 920 png_structp png_ptr; | |
| 921 png_infop info_ptr; | |
| 922 | |
| 3839 | 923 xzero (unwind); |
| 924 record_unwind_protect (png_instantiate_unwind, make_opaque_ptr (&unwind)); | |
| 925 | |
| 926 if (setjmp (png_err_stct.setjmp_buffer)) | |
| 927 { | |
| 928 /* Something blew up: | |
| 929 just display the error (cleanup happens in the unwind) */ | |
| 930 signal_image_error_2 ("Error decoding PNG", | |
|
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
931 build_extstring (png_err_stct.err_str, |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
932 Qerror_message_encoding), |
| 3839 | 933 instantiator); |
| 934 } | |
| 935 | |
| 428 | 936 /* Initialize all PNG structures */ |
| 3839 | 937 png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING, |
| 938 (void *) &png_err_stct, | |
| 428 | 939 png_error_func, png_warning_func); |
| 940 if (!png_ptr) | |
| 941 signal_image_error ("Error obtaining memory for png_read", instantiator); | |
| 3839 | 942 unwind.png_ptr = png_ptr; |
| 943 | |
| 428 | 944 info_ptr = png_create_info_struct (png_ptr); |
| 945 if (!info_ptr) | |
| 946 { | |
| 3839 | 947 unwind.png_ptr = NULL; /* avoid re-calling png_destroy_read_struct |
| 948 when unwinding */ | |
| 428 | 949 png_destroy_read_struct (&png_ptr, (png_infopp)NULL, (png_infopp)NULL); |
| 950 signal_image_error ("Error obtaining memory for png_read", instantiator); | |
| 951 } | |
| 952 unwind.info_ptr = info_ptr; | |
| 953 | |
| 954 /* This code is a mixture of stuff from Ben's GIF/JPEG stuff from | |
| 955 this file, example.c from the libpng 0.81 distribution, and the | |
| 956 pngtopnm sources. -WMP- | |
| 957 */ | |
| 958 /* It has been further modified to handle the API changes for 0.96, | |
| 959 and is no longer usable for previous versions. jh | |
| 960 */ | |
| 961 | |
| 962 /* Initialize the IO layer and read in header information */ | |
| 963 { | |
| 964 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data); | |
| 2367 | 965 const Binbyte *bytes; |
| 665 | 966 Bytecount len; |
| 428 | 967 |
| 968 assert (!NILP (data)); | |
| 969 | |
| 970 /* #### This is a definite problem under Mule due to the amount of | |
| 971 stack data it might allocate. Need to think about using Lstreams */ | |
|
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4953
diff
changeset
|
972 LISP_STRING_TO_SIZED_EXTERNAL (data, bytes, len, Qbinary); |
| 428 | 973 tbr.bytes = bytes; |
| 974 tbr.len = len; | |
| 975 tbr.index = 0; | |
| 976 png_set_read_fn (png_ptr,(void *) &tbr, png_read_from_memory); | |
| 977 } | |
| 978 | |
| 979 png_read_info (png_ptr, info_ptr); | |
| 980 | |
| 981 { | |
|
4698
a9493cab536f
Fix crash due to mishandling transparency.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4682
diff
changeset
|
982 int y, padding; |
| 2367 | 983 Binbyte **row_pointers; |
|
4646
6c6bfdb80a0c
Prevent integer overflow and subsequent crashes when attempting to load large
Jerry James <james@xemacs.org>
parents:
4326
diff
changeset
|
984 UINT_64_BIT pixels_sq; |
| 428 | 985 height = info_ptr->height; |
| 986 width = info_ptr->width; | |
|
4646
6c6bfdb80a0c
Prevent integer overflow and subsequent crashes when attempting to load large
Jerry James <james@xemacs.org>
parents:
4326
diff
changeset
|
987 pixels_sq = (UINT_64_BIT) width * (UINT_64_BIT) height; |
|
6c6bfdb80a0c
Prevent integer overflow and subsequent crashes when attempting to load large
Jerry James <james@xemacs.org>
parents:
4326
diff
changeset
|
988 if (pixels_sq > ((size_t) -1) / 3) |
|
6c6bfdb80a0c
Prevent integer overflow and subsequent crashes when attempting to load large
Jerry James <james@xemacs.org>
parents:
4326
diff
changeset
|
989 signal_image_error ("PNG image too large to instantiate", instantiator); |
| 428 | 990 |
|
4698
a9493cab536f
Fix crash due to mishandling transparency.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4682
diff
changeset
|
991 /* Wow, allocate all the memory. Truly, exciting. |
|
a9493cab536f
Fix crash due to mishandling transparency.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4682
diff
changeset
|
992 Well, yes, there's excitement to be had. It turns out that libpng |
|
a9493cab536f
Fix crash due to mishandling transparency.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4682
diff
changeset
|
993 strips in place, so the last row overruns the buffer if depth is 16 |
|
a9493cab536f
Fix crash due to mishandling transparency.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4682
diff
changeset
|
994 or there's an alpha channel. This is a crash on Linux. So we need |
|
a9493cab536f
Fix crash due to mishandling transparency.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4682
diff
changeset
|
995 to add padding. |
|
a9493cab536f
Fix crash due to mishandling transparency.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4682
diff
changeset
|
996 The worst case is reducing 8 bytes (16-bit RGBA) to 3 (8-bit RGB). */ |
|
a9493cab536f
Fix crash due to mishandling transparency.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4682
diff
changeset
|
997 |
|
a9493cab536f
Fix crash due to mishandling transparency.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4682
diff
changeset
|
998 padding = 5 * width; |
|
a9493cab536f
Fix crash due to mishandling transparency.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4682
diff
changeset
|
999 unwind.eimage = xnew_array_and_zero (Binbyte, |
|
a9493cab536f
Fix crash due to mishandling transparency.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4682
diff
changeset
|
1000 (size_t) (pixels_sq * 3 + padding)); |
|
a9493cab536f
Fix crash due to mishandling transparency.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4682
diff
changeset
|
1001 |
| 428 | 1002 /* libpng expects that the image buffer passed in contains a |
| 1003 picture to draw on top of if the png has any transparencies. | |
| 1004 This could be a good place to pass that in... */ | |
| 1005 | |
| 1006 row_pointers = xnew_array (png_byte *, height); | |
| 1007 for (y = 0; y < height; y++) | |
| 1008 row_pointers[y] = unwind.eimage + (width * 3 * y); | |
| 1009 | |
| 1010 { | |
| 1011 /* if the png specifies a background chunk, go ahead and | |
| 1012 use it, else use what we can get from the default face. */ | |
| 1013 png_color_16 my_background, *image_background; | |
| 1014 Lisp_Object bkgd = Qnil; | |
| 1015 | |
| 1016 my_background.red = 0x7fff; | |
| 1017 my_background.green = 0x7fff; | |
| 1018 my_background.blue = 0x7fff; | |
| 1019 bkgd = FACE_BACKGROUND (Vdefault_face, domain); | |
| 1020 if (!COLOR_INSTANCEP (bkgd)) | |
| 1021 { | |
| 1022 warn_when_safe (Qpng, Qinfo, "Couldn't get background color!"); | |
| 1023 } | |
| 1024 else | |
| 1025 { | |
|
4698
a9493cab536f
Fix crash due to mishandling transparency.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4682
diff
changeset
|
1026 Lisp_Color_Instance *c = XCOLOR_INSTANCE (bkgd); |
|
a9493cab536f
Fix crash due to mishandling transparency.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4682
diff
changeset
|
1027 Lisp_Object rgb = MAYBE_LISP_DEVMETH (XDEVICE (c->device), |
|
a9493cab536f
Fix crash due to mishandling transparency.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4682
diff
changeset
|
1028 color_instance_rgb_components, |
|
a9493cab536f
Fix crash due to mishandling transparency.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4682
diff
changeset
|
1029 (c)); |
|
a9493cab536f
Fix crash due to mishandling transparency.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4682
diff
changeset
|
1030 #define GETCOLOR(col) my_background.col = (unsigned short) XINT (XCAR (rgb)) |
|
a9493cab536f
Fix crash due to mishandling transparency.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4682
diff
changeset
|
1031 GETCOLOR(red); rgb = XCDR (rgb); |
|
a9493cab536f
Fix crash due to mishandling transparency.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4682
diff
changeset
|
1032 GETCOLOR(green); rgb = XCDR (rgb); |
|
a9493cab536f
Fix crash due to mishandling transparency.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4682
diff
changeset
|
1033 GETCOLOR(blue); |
|
a9493cab536f
Fix crash due to mishandling transparency.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4682
diff
changeset
|
1034 #undef GETCOLOR |
| 428 | 1035 } |
| 1036 | |
| 1037 if (png_get_bKGD (png_ptr, info_ptr, &image_background)) | |
| 1038 png_set_background (png_ptr, image_background, | |
| 1039 PNG_BACKGROUND_GAMMA_FILE, 1, 1.0); | |
| 1040 else | |
| 1041 png_set_background (png_ptr, &my_background, | |
| 1042 PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0); | |
| 1043 } | |
| 1044 | |
| 1045 /* Now that we're using EImage, ask for 8bit RGB triples for any type | |
| 1046 of image*/ | |
|
4698
a9493cab536f
Fix crash due to mishandling transparency.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4682
diff
changeset
|
1047 /* convert palette images to RGB */ |
| 428 | 1048 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) |
|
4698
a9493cab536f
Fix crash due to mishandling transparency.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4682
diff
changeset
|
1049 png_set_palette_to_rgb (png_ptr); |
|
a9493cab536f
Fix crash due to mishandling transparency.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4682
diff
changeset
|
1050 /* convert grayscale images to RGB */ |
|
a9493cab536f
Fix crash due to mishandling transparency.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4682
diff
changeset
|
1051 else if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY || |
| 428 | 1052 info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) |
| 1053 png_set_gray_to_rgb (png_ptr); | |
|
4698
a9493cab536f
Fix crash due to mishandling transparency.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4682
diff
changeset
|
1054 /* pad images with depth < 8 bits */ |
|
a9493cab536f
Fix crash due to mishandling transparency.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4682
diff
changeset
|
1055 else if (info_ptr->bit_depth < 8) |
| 428 | 1056 { |
| 1057 if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY) | |
| 1058 png_set_expand (png_ptr); | |
| 1059 else | |
| 1060 png_set_packing (png_ptr); | |
| 1061 } | |
|
4698
a9493cab536f
Fix crash due to mishandling transparency.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4682
diff
changeset
|
1062 /* strip 16-bit depth files down to 8 bits */ |
|
a9493cab536f
Fix crash due to mishandling transparency.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4682
diff
changeset
|
1063 if (info_ptr->bit_depth == 16) |
|
a9493cab536f
Fix crash due to mishandling transparency.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4682
diff
changeset
|
1064 png_set_strip_16 (png_ptr); |
|
a9493cab536f
Fix crash due to mishandling transparency.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4682
diff
changeset
|
1065 /* strip alpha channel |
|
a9493cab536f
Fix crash due to mishandling transparency.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4682
diff
changeset
|
1066 #### shouldn't we handle this? |
|
a9493cab536f
Fix crash due to mishandling transparency.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4682
diff
changeset
|
1067 first call png_read_update_info in case above transformations |
|
a9493cab536f
Fix crash due to mishandling transparency.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4682
diff
changeset
|
1068 have generated an alpha channel */ |
|
a9493cab536f
Fix crash due to mishandling transparency.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4682
diff
changeset
|
1069 png_read_update_info(png_ptr, info_ptr); |
|
a9493cab536f
Fix crash due to mishandling transparency.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4682
diff
changeset
|
1070 if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA) |
|
a9493cab536f
Fix crash due to mishandling transparency.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4682
diff
changeset
|
1071 png_set_strip_alpha (png_ptr); |
| 428 | 1072 |
| 1073 png_read_image (png_ptr, row_pointers); | |
| 1074 png_read_end (png_ptr, info_ptr); | |
| 1075 | |
|
4698
a9493cab536f
Fix crash due to mishandling transparency.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4682
diff
changeset
|
1076 /* #### There should be some way to pass this type of data down |
|
a9493cab536f
Fix crash due to mishandling transparency.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4682
diff
changeset
|
1077 * into the glyph code, where you can get to it from lisp |
|
a9493cab536f
Fix crash due to mishandling transparency.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4682
diff
changeset
|
1078 * anyway. - WMP */ |
| 428 | 1079 { |
| 1080 int i; | |
| 3734 | 1081 DECLARE_EISTRING (key); |
| 1082 DECLARE_EISTRING (text); | |
| 428 | 1083 |
| 1084 for (i = 0 ; i < info_ptr->num_text ; i++) | |
| 1085 { | |
| 1086 /* How paranoid do I have to be about no trailing NULLs, and | |
| 1087 using (int)info_ptr->text[i].text_length, and strncpy and a temp | |
| 1088 string somewhere? */ | |
| 3734 | 1089 eireset(key); |
| 1090 eireset(text); | |
| 1091 eicpy_ext(key, info_ptr->text[i].key, Qbinary); | |
| 1092 eicpy_ext(text, info_ptr->text[i].text, Qbinary); | |
| 428 | 1093 |
| 1094 warn_when_safe (Qpng, Qinfo, "%s - %s", | |
| 3734 | 1095 eidata(key), eidata(text)); |
| 428 | 1096 } |
| 1097 } | |
| 1098 | |
|
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4953
diff
changeset
|
1099 xfree (row_pointers); |
| 428 | 1100 } |
| 1101 | |
| 1102 /* now instantiate */ | |
| 442 | 1103 MAYBE_DEVMETH (DOMAIN_XDEVICE (ii->domain), |
| 428 | 1104 init_image_instance_from_eimage, |
| 1105 (ii, width, height, 1, unwind.eimage, dest_mask, | |
| 2959 | 1106 instantiator, pointer_fg, pointer_bg, domain)); |
| 428 | 1107 |
| 1108 /* This will clean up everything else. */ | |
| 771 | 1109 unbind_to (speccount); |
| 428 | 1110 } |
| 1111 | |
| 1112 #endif /* HAVE_PNG */ | |
| 1113 | |
| 1114 | |
| 1115 #ifdef HAVE_TIFF | |
| 1116 #include "tiffio.h" | |
| 1117 | |
| 1118 /********************************************************************** | |
| 1119 * TIFF * | |
| 1120 **********************************************************************/ | |
| 1121 static void | |
| 1122 tiff_validate (Lisp_Object instantiator) | |
| 1123 { | |
| 1124 file_or_data_must_be_present (instantiator); | |
| 1125 } | |
| 1126 | |
| 1127 static Lisp_Object | |
| 442 | 1128 tiff_normalize (Lisp_Object inst, Lisp_Object console_type, |
| 2286 | 1129 Lisp_Object UNUSED (dest_mask)) |
| 428 | 1130 { |
| 1131 return simple_image_type_normalize (inst, console_type, Qtiff); | |
| 1132 } | |
| 1133 | |
| 1134 static int | |
| 1135 tiff_possible_dest_types (void) | |
| 1136 { | |
| 1137 return IMAGE_COLOR_PIXMAP_MASK; | |
| 1138 } | |
| 1139 | |
| 1140 struct tiff_unwind_data | |
| 1141 { | |
| 2367 | 1142 Binbyte *eimage; |
| 428 | 1143 /* Object that holds the decoded data from a TIFF file */ |
| 1144 TIFF *tiff; | |
| 1145 }; | |
| 1146 | |
| 1147 static Lisp_Object | |
| 1148 tiff_instantiate_unwind (Lisp_Object unwind_obj) | |
| 1149 { | |
| 1150 struct tiff_unwind_data *data = | |
| 1151 (struct tiff_unwind_data *) get_opaque_ptr (unwind_obj); | |
| 1152 | |
| 1153 free_opaque_ptr (unwind_obj); | |
| 1154 if (data->tiff) | |
| 1155 { | |
|
5169
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5024
diff
changeset
|
1156 TIFFClose (data->tiff); |
|
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5024
diff
changeset
|
1157 data->tiff = 0; |
| 428 | 1158 } |
| 1159 if (data->eimage) | |
|
5169
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5024
diff
changeset
|
1160 { |
|
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5024
diff
changeset
|
1161 xfree (data->eimage); |
|
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5024
diff
changeset
|
1162 data->eimage = 0; |
|
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5024
diff
changeset
|
1163 } |
| 428 | 1164 |
| 1165 return Qnil; | |
| 1166 } | |
| 1167 | |
| 1168 typedef struct tiff_memory_storage | |
| 1169 { | |
| 2367 | 1170 Binbyte *bytes; /* The data */ |
| 665 | 1171 Bytecount len; /* How big is it? */ |
| 1172 Bytecount index; /* Where are we? */ | |
| 428 | 1173 } tiff_memory_storage; |
| 1174 | |
| 1175 static size_t | |
| 647 | 1176 tiff_memory_read (thandle_t data, tdata_t buf, tsize_t size) |
| 428 | 1177 { |
| 647 | 1178 tiff_memory_storage *mem = (tiff_memory_storage *) data; |
| 428 | 1179 |
| 665 | 1180 if ((Bytecount) size > (mem->len - mem->index)) |
| 428 | 1181 return (size_t) -1; |
| 647 | 1182 memcpy (buf, mem->bytes + mem->index, size); |
| 428 | 1183 mem->index = mem->index + size; |
| 1184 return size; | |
| 1185 } | |
| 1186 | |
| 647 | 1187 static size_t |
| 2286 | 1188 tiff_memory_write (thandle_t UNUSED (data), tdata_t UNUSED (buf), |
| 1189 tsize_t UNUSED (size)) | |
| 428 | 1190 { |
| 2500 | 1191 ABORT(); |
| 2270 | 1192 return 0; |
| 428 | 1193 } |
| 1194 | |
| 647 | 1195 static toff_t |
| 1196 tiff_memory_seek (thandle_t data, toff_t off, int whence) | |
| 428 | 1197 { |
| 647 | 1198 tiff_memory_storage *mem = (tiff_memory_storage *) data; |
| 428 | 1199 int newidx; |
| 647 | 1200 switch(whence) |
| 1201 { | |
| 1202 case SEEK_SET: | |
| 1203 newidx = off; | |
| 1204 break; | |
| 1205 case SEEK_END: | |
| 1206 newidx = mem->len + off; | |
| 1207 break; | |
| 1208 case SEEK_CUR: | |
| 1209 newidx = mem->index + off; | |
| 1210 break; | |
| 1211 default: | |
| 1212 fprintf (stderr, "Eh? invalid seek mode in tiff_memory_seek\n"); | |
| 1213 return (toff_t) -1; | |
| 1214 } | |
| 428 | 1215 |
| 1216 if ((newidx > mem->len) || (newidx < 0)) | |
| 593 | 1217 return (toff_t) -1; |
| 428 | 1218 |
| 1219 mem->index = newidx; | |
| 1220 return newidx; | |
| 1221 } | |
| 1222 | |
| 1223 static int | |
| 2286 | 1224 tiff_memory_close (thandle_t UNUSED (data)) |
| 428 | 1225 { |
| 1226 return 0; | |
| 1227 } | |
| 1228 | |
| 1229 static int | |
| 2286 | 1230 tiff_map_noop (thandle_t UNUSED (data), tdata_t* UNUSED (pbase), |
| 1231 toff_t* UNUSED (psize)) | |
| 428 | 1232 { |
| 1233 return 0; | |
| 1234 } | |
| 1235 | |
| 1236 static void | |
| 2286 | 1237 tiff_unmap_noop (thandle_t UNUSED (data), tdata_t UNUSED (pbase), |
| 1238 toff_t UNUSED (psize)) | |
| 428 | 1239 { |
| 1240 return; | |
| 1241 } | |
| 1242 | |
| 1243 static toff_t | |
| 647 | 1244 tiff_memory_size (thandle_t data) |
| 428 | 1245 { |
| 1246 tiff_memory_storage *mem = (tiff_memory_storage*)data; | |
| 1247 return mem->len; | |
| 1248 } | |
| 1249 | |
| 1250 struct tiff_error_struct | |
| 1251 { | |
| 438 | 1252 #ifdef HAVE_VSNPRINTF |
| 428 | 1253 char err_str[256]; |
| 1254 #else | |
| 1255 char err_str[1024]; /* return the error string */ | |
| 1256 #endif | |
| 1257 jmp_buf setjmp_buffer; /* for return to caller */ | |
| 1258 }; | |
| 1259 | |
| 1260 /* jh 98/03/12 - ###This struct for passing data to the error functions | |
| 1261 is an ugly hack caused by the fact that libtiff (as of v3.4) doesn't | |
| 1262 have any place to store error func data. This should be rectified | |
| 1263 before XEmacs gets threads! */ | |
| 1264 static struct tiff_error_struct tiff_err_data; | |
| 1265 | |
| 1266 static void | |
| 2286 | 1267 tiff_error_func (const char *UNUSED (module), const char *fmt, ...) |
| 428 | 1268 { |
| 1269 va_list vargs; | |
| 1270 | |
| 1271 va_start (vargs, fmt); | |
| 438 | 1272 #ifdef HAVE_VSNPRINTF |
| 428 | 1273 vsnprintf (tiff_err_data.err_str, 255, fmt, vargs); |
| 1274 #else | |
| 1275 /* pray this doesn't overflow... */ | |
| 1276 vsprintf (tiff_err_data.err_str, fmt, vargs); | |
| 1277 #endif | |
| 1278 va_end (vargs); | |
| 1279 /* return to setjmp point */ | |
| 1280 longjmp (tiff_err_data.setjmp_buffer, 1); | |
| 1281 } | |
| 1282 | |
| 1283 static void | |
| 647 | 1284 tiff_warning_func (const char *module, const char *fmt, ...) |
| 428 | 1285 { |
| 1286 va_list vargs; | |
| 438 | 1287 #ifdef HAVE_VSNPRINTF |
| 428 | 1288 char warn_str[256]; |
| 1289 #else | |
| 1290 char warn_str[1024]; | |
| 1291 #endif | |
| 3734 | 1292 DECLARE_EISTRING (eimodule); |
| 1293 DECLARE_EISTRING (eiwarnstr); | |
| 428 | 1294 |
| 1295 va_start (vargs, fmt); | |
| 438 | 1296 #ifdef HAVE_VSNPRINTF |
| 428 | 1297 vsnprintf (warn_str, 255, fmt, vargs); |
| 1298 #else | |
| 1299 vsprintf (warn_str, fmt, vargs); | |
| 1300 #endif | |
| 1301 va_end (vargs); | |
| 3734 | 1302 |
| 1303 eicpy_ext(eimodule, module, Qbinary); | |
| 1304 eicpy_ext(eiwarnstr, warn_str, Qbinary); | |
| 1305 | |
| 428 | 1306 warn_when_safe (Qtiff, Qinfo, "%s - %s", |
| 3734 | 1307 eidata(eimodule), |
| 1308 eidata(eiwarnstr)); | |
| 428 | 1309 } |
| 1310 | |
| 1311 static void | |
| 1312 tiff_instantiate (Lisp_Object image_instance, Lisp_Object instantiator, | |
| 2959 | 1313 Lisp_Object pointer_fg, Lisp_Object pointer_bg, |
| 428 | 1314 int dest_mask, Lisp_Object domain) |
| 1315 { | |
| 440 | 1316 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance); |
| 428 | 1317 tiff_memory_storage mem_struct; |
| 1318 /* It is OK for the unwind data to be local to this function, | |
| 1319 because the unwind-protect is always executed when this | |
| 1320 stack frame is still valid. */ | |
| 1321 struct tiff_unwind_data unwind; | |
| 1322 int speccount = specpdl_depth (); | |
| 1323 uint32 width, height; | |
| 1324 | |
| 1325 xzero (unwind); | |
| 1326 record_unwind_protect (tiff_instantiate_unwind, make_opaque_ptr (&unwind)); | |
| 1327 | |
| 1328 /* set up error facilities */ | |
| 1329 if (setjmp (tiff_err_data.setjmp_buffer)) | |
| 1330 { | |
| 1331 /* An error was signaled. No clean up is needed, as unwind handles that | |
| 1332 for us. Just pass the error along. */ | |
| 1333 signal_image_error_2 ("TIFF decoding error", | |
|
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
1334 build_extstring (tiff_err_data.err_str, |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
1335 Qerror_message_encoding), |
| 428 | 1336 instantiator); |
| 1337 } | |
| 1338 TIFFSetErrorHandler ((TIFFErrorHandler)tiff_error_func); | |
| 1339 TIFFSetWarningHandler ((TIFFErrorHandler)tiff_warning_func); | |
| 1340 { | |
| 1341 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data); | |
| 2367 | 1342 Binbyte *bytes; |
| 665 | 1343 Bytecount len; |
| 428 | 1344 |
| 1345 uint32 *raster; | |
| 2367 | 1346 Binbyte *ep; |
|
4646
6c6bfdb80a0c
Prevent integer overflow and subsequent crashes when attempting to load large
Jerry James <james@xemacs.org>
parents:
4326
diff
changeset
|
1347 UINT_64_BIT pixels_sq; |
| 428 | 1348 |
| 1349 assert (!NILP (data)); | |
| 1350 | |
| 1351 /* #### This is a definite problem under Mule due to the amount of | |
| 1352 stack data it might allocate. Think about Lstreams... */ | |
|
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4953
diff
changeset
|
1353 LISP_STRING_TO_SIZED_EXTERNAL (data, bytes, len, Qbinary); |
| 428 | 1354 mem_struct.bytes = bytes; |
| 1355 mem_struct.len = len; | |
| 1356 mem_struct.index = 0; | |
| 1357 | |
| 442 | 1358 unwind.tiff = TIFFClientOpen ("memfile", "r", (thandle_t) &mem_struct, |
| 428 | 1359 (TIFFReadWriteProc)tiff_memory_read, |
| 1360 (TIFFReadWriteProc)tiff_memory_write, | |
| 1361 tiff_memory_seek, tiff_memory_close, tiff_memory_size, | |
| 1362 tiff_map_noop, tiff_unmap_noop); | |
| 1363 if (!unwind.tiff) | |
| 440 | 1364 signal_image_error ("Insufficient memory to instantiate TIFF image", instantiator); |
| 428 | 1365 |
| 1366 TIFFGetField (unwind.tiff, TIFFTAG_IMAGEWIDTH, &width); | |
| 1367 TIFFGetField (unwind.tiff, TIFFTAG_IMAGELENGTH, &height); | |
|
4646
6c6bfdb80a0c
Prevent integer overflow and subsequent crashes when attempting to load large
Jerry James <james@xemacs.org>
parents:
4326
diff
changeset
|
1368 pixels_sq = (UINT_64_BIT) width * (UINT_64_BIT) height; |
|
6c6bfdb80a0c
Prevent integer overflow and subsequent crashes when attempting to load large
Jerry James <james@xemacs.org>
parents:
4326
diff
changeset
|
1369 if (pixels_sq >= 1 << 29) |
|
6c6bfdb80a0c
Prevent integer overflow and subsequent crashes when attempting to load large
Jerry James <james@xemacs.org>
parents:
4326
diff
changeset
|
1370 signal_image_error ("TIFF image too large to instantiate", instantiator); |
|
4682
648f4a0dac3e
Fix build problems on WIN32 platforms caused by the large image crash fix.
Jerry James <james@xemacs.org>
parents:
4646
diff
changeset
|
1371 unwind.eimage = xnew_binbytes ((size_t) pixels_sq * 3); |
| 428 | 1372 |
| 440 | 1373 /* #### This is little more than proof-of-concept/function testing. |
| 428 | 1374 It needs to be reimplemented via scanline reads for both memory |
| 1375 compactness. */ | |
|
4646
6c6bfdb80a0c
Prevent integer overflow and subsequent crashes when attempting to load large
Jerry James <james@xemacs.org>
parents:
4326
diff
changeset
|
1376 raster = (uint32*) _TIFFmalloc ((tsize_t) (pixels_sq * sizeof (uint32))); |
| 428 | 1377 if (raster != NULL) |
| 1378 { | |
| 647 | 1379 int i, j; |
| 428 | 1380 uint32 *rp; |
| 1381 ep = unwind.eimage; | |
| 1382 rp = raster; | |
| 1383 if (TIFFReadRGBAImage (unwind.tiff, width, height, raster, 0)) | |
| 1384 { | |
| 1385 for (i = height - 1; i >= 0; i--) | |
| 1386 { | |
| 1387 /* This is to get around weirdness in the libtiff library where properly | |
| 1388 made TIFFs will come out upside down. libtiff bug or jhod-brainlock? */ | |
| 1389 rp = raster + (i * width); | |
| 647 | 1390 for (j = 0; j < (int) width; j++) |
| 428 | 1391 { |
| 2367 | 1392 *ep++ = (Binbyte)TIFFGetR(*rp); |
| 1393 *ep++ = (Binbyte)TIFFGetG(*rp); | |
| 1394 *ep++ = (Binbyte)TIFFGetB(*rp); | |
| 428 | 1395 rp++; |
| 1396 } | |
| 1397 } | |
| 1398 } | |
| 1399 _TIFFfree (raster); | |
| 1400 } else | |
| 1401 signal_image_error ("Unable to allocate memory for TIFFReadRGBA", instantiator); | |
| 1402 | |
| 1403 } | |
| 1404 | |
| 1405 /* now instantiate */ | |
| 442 | 1406 MAYBE_DEVMETH (DOMAIN_XDEVICE (ii->domain), |
| 428 | 1407 init_image_instance_from_eimage, |
| 1408 (ii, width, height, 1, unwind.eimage, dest_mask, | |
| 2959 | 1409 instantiator, pointer_fg, pointer_bg, domain)); |
| 428 | 1410 |
| 771 | 1411 unbind_to (speccount); |
| 428 | 1412 } |
| 1413 | |
| 1414 #endif /* HAVE_TIFF */ | |
| 1415 | |
| 1416 | |
| 1417 /************************************************************************/ | |
| 1418 /* initialization */ | |
| 1419 /************************************************************************/ | |
| 1420 | |
| 1421 void | |
| 1422 syms_of_glyphs_eimage (void) | |
| 1423 { | |
| 1424 } | |
| 1425 | |
| 1426 void | |
| 1427 image_instantiator_format_create_glyphs_eimage (void) | |
| 1428 { | |
| 1429 /* image-instantiator types */ | |
| 1430 #ifdef HAVE_JPEG | |
| 1431 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (jpeg, "jpeg"); | |
| 1432 | |
| 1433 IIFORMAT_HAS_METHOD (jpeg, validate); | |
| 1434 IIFORMAT_HAS_METHOD (jpeg, normalize); | |
| 1435 IIFORMAT_HAS_METHOD (jpeg, possible_dest_types); | |
| 1436 IIFORMAT_HAS_METHOD (jpeg, instantiate); | |
| 1437 | |
| 1438 IIFORMAT_VALID_KEYWORD (jpeg, Q_data, check_valid_string); | |
| 1439 IIFORMAT_VALID_KEYWORD (jpeg, Q_file, check_valid_string); | |
| 1440 #endif | |
| 1441 | |
| 1442 #ifdef HAVE_GIF | |
| 1443 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (gif, "gif"); | |
| 1444 | |
| 1445 IIFORMAT_HAS_METHOD (gif, validate); | |
| 1446 IIFORMAT_HAS_METHOD (gif, normalize); | |
| 1447 IIFORMAT_HAS_METHOD (gif, possible_dest_types); | |
| 1448 IIFORMAT_HAS_METHOD (gif, instantiate); | |
| 1449 | |
| 1450 IIFORMAT_VALID_KEYWORD (gif, Q_data, check_valid_string); | |
| 1451 IIFORMAT_VALID_KEYWORD (gif, Q_file, check_valid_string); | |
| 1452 #endif | |
| 1453 | |
| 1454 #ifdef HAVE_PNG | |
| 1455 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (png, "png"); | |
| 1456 | |
| 1457 IIFORMAT_HAS_METHOD (png, validate); | |
| 1458 IIFORMAT_HAS_METHOD (png, normalize); | |
| 1459 IIFORMAT_HAS_METHOD (png, possible_dest_types); | |
| 1460 IIFORMAT_HAS_METHOD (png, instantiate); | |
| 1461 | |
| 1462 IIFORMAT_VALID_KEYWORD (png, Q_data, check_valid_string); | |
| 1463 IIFORMAT_VALID_KEYWORD (png, Q_file, check_valid_string); | |
| 1464 #endif | |
| 1465 | |
| 1466 #ifdef HAVE_TIFF | |
| 1467 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (tiff, "tiff"); | |
| 1468 | |
| 1469 IIFORMAT_HAS_METHOD (tiff, validate); | |
| 1470 IIFORMAT_HAS_METHOD (tiff, normalize); | |
| 1471 IIFORMAT_HAS_METHOD (tiff, possible_dest_types); | |
| 1472 IIFORMAT_HAS_METHOD (tiff, instantiate); | |
| 1473 | |
| 1474 IIFORMAT_VALID_KEYWORD (tiff, Q_data, check_valid_string); | |
| 1475 IIFORMAT_VALID_KEYWORD (tiff, Q_file, check_valid_string); | |
| 1476 #endif | |
| 1477 | |
| 1478 } | |
| 1479 | |
| 1480 void | |
| 1481 vars_of_glyphs_eimage (void) | |
| 1482 { | |
| 1483 #ifdef HAVE_JPEG | |
| 1484 Fprovide (Qjpeg); | |
| 1485 #endif | |
| 1486 | |
| 1487 #ifdef HAVE_GIF | |
| 1488 Fprovide (Qgif); | |
| 1489 #endif | |
| 1490 | |
| 1491 #ifdef HAVE_PNG | |
| 1492 Fprovide (Qpng); | |
| 1493 #endif | |
| 1494 | |
| 1495 #ifdef HAVE_TIFF | |
| 1496 Fprovide (Qtiff); | |
| 1497 #endif | |
| 1498 | |
| 1499 } |
