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