annotate src/glyphs-eimage.c @ 593:5fd7ba8b56e7

[xemacs-hg @ 2001-05-31 12:45:27 by ben] xemacs-faq.texi: Major rewrite. Update all MS Windows info to current. Redo section 6.1 almost completely. Incorporate sections 1 and 2 of Hrvoje's FAQ. etags.el: Fix infloop when going up to the root. s\cygwin32.h: Don't unilaterally include ntplay, but only when we're compiling with native sound (look in configure now). event-msw.c: Fix yet more problems with C-g handling. Implement debug-mswindows-events. event-stream.c, events.h, signal.c, sysdep.h: Rearrange the signal-handling code to eliminate the former spaghetti logic paths in it. Document clearly what "low-level" and "high-level" timeouts are. Rename some functions with unclear names (e.g. "...alarm...") to names that reflect what they actually do (e.g. "...async_timeout..."). Fix numerous bugs discovered in the process. console-x.h, event-Xt.c, event-msw.c, frame-x.c: Hopefully make XEmacs properly maintain the "iconified" state on frames at all times. This should fix the "can't delete a frame with C-x 5 0 when there's another iconified frame out there" bug. Put a notice in of further changes that should probably be made to clean up the frame-visibility support. (especially directed at Jan Vroonhof) lisp.h, miscplay.c: Rename SBufbyte to CBufbyte to avoid a misleading name. Eliminate UChar, which is not used anywhere and contributes no semantic info. Add a comment about the documentation-only properties of the char/unsigned char typedefs. Add SChar_Binary as an explicitly `signed' version of Char_Binary and put back the `signed' declarations in miscplay.c. alloc.c: Use char typedefs. console-msw.c, device-msw.c, dialog-msw.c, editfns.c, fileio.c, glyphs-eimage.c, menubar-msw.c, ntplay.c, objects-msw.c, realpath.c, redisplay-msw.c, select-msw.c, syswindows.h, win32.c: Eliminate numerous C++ errors. frame-msw.c: Eliminate numerous C++ errors and Mule-ize. glyphs-msw.c: Eliminate numerous C++ errors and use char typedefs. configure.in: Fix problems detecting both native and Linux sound on Cygwin when compiled with --with-msw=no. Rearrange file-coding handling a bit to avoid warning when compiling with Mule. configure.in, configure.usage, INSTALL: Document XEMACS_CC and corresponding compiler option --xemacs-compiler. Explain how to build xemacs using a C++ compiler.
author ben
date Thu, 31 May 2001 12:45:41 +0000
parents abe6d1db359e
children 373ced43e288
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5 Copyright (C) 1995, 1996 Ben Wing
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27 /* Original author: Jamie Zawinski for 19.8
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 font-truename stuff added by Jamie Zawinski for 19.10
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 subwindow support added by Chuck Thompson
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 additional XPM support added by Chuck Thompson
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 initial X-Face support added by Stig
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 rewritten/restructured by Ben Wing for 19.12/19.13
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 GIF/JPEG support added by Ben Wing for 19.14
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 PNG support added by Bill Perry for 19.14
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 Improved GIF/JPEG support added by Bill Perry for 19.14
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 Cleanup/simplification of error handling by Ben Wing for 19.14
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 Pointer/icon overhaul, more restructuring by Ben Wing for 19.14
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 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
39 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
40 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
41 TIFF code by Jareth Hein for 21.0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 Generalization for ms-windows by Andy Piper for 21.0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 TODO:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 Convert images.el to C and stick it in here?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 #include <config.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 #include "lisp.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 #include "lstream.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 #include "console.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 #include "device.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 #include "faces.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 #include "glyphs.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 #include "objects.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 #include "buffer.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 #include "frame.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 #include "opaque.h"
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
59 #include "window.h"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 #include "sysfile.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 #ifdef HAVE_PNG
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 #ifdef __cplusplus
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 extern "C" {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 #include <png.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 #ifdef __cplusplus
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 #include <setjmp.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 #ifdef FILE_CODING
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 #include "file-coding.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 #ifdef HAVE_TIFF
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 DEFINE_IMAGE_INSTANTIATOR_FORMAT (tiff);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 Lisp_Object Qtiff;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 #ifdef HAVE_JPEG
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 DEFINE_IMAGE_INSTANTIATOR_FORMAT (jpeg);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 Lisp_Object Qjpeg;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 #ifdef HAVE_GIF
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 DEFINE_IMAGE_INSTANTIATOR_FORMAT (gif);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 Lisp_Object Qgif;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 #ifdef HAVE_PNG
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 DEFINE_IMAGE_INSTANTIATOR_FORMAT (png);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 Lisp_Object Qpng;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 #endif
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 #ifdef HAVE_JPEG
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 /**********************************************************************
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 * JPEG *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 **********************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 #ifdef __cplusplus
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 extern "C" {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 #include <jpeglib.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 #include <jerror.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 #ifdef __cplusplus
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 /*#define USE_TEMP_FILES_FOR_JPEG_IMAGES 1*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 jpeg_validate (Lisp_Object instantiator)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 file_or_data_must_be_present (instantiator);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 static Lisp_Object
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
122 jpeg_normalize (Lisp_Object inst, Lisp_Object console_type,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
123 Lisp_Object dest_mask)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 return simple_image_type_normalize (inst, console_type, Qjpeg);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 jpeg_possible_dest_types (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 return IMAGE_COLOR_PIXMAP_MASK;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 /* To survive the otherwise baffling complexity of making sure
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 everything gets cleaned up in the presence of an error, we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 use an unwind_protect(). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 struct jpeg_unwind_data
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 /* Stream that we need to close */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 FILE *instream;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 /* Object that holds state info for JPEG decoding */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 struct jpeg_decompress_struct *cinfo_ptr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 /* EImage data */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 unsigned char *eimage;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 };
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 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 jpeg_instantiate_unwind (Lisp_Object unwind_obj)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 struct jpeg_unwind_data *data =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 (struct jpeg_unwind_data *) get_opaque_ptr (unwind_obj);
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 free_opaque_ptr (unwind_obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 if (data->cinfo_ptr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 jpeg_destroy_decompress (data->cinfo_ptr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 if (data->instream)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 fclose (data->instream);
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 if (data->eimage) xfree (data->eimage);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 * ERROR HANDLING:
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 * The JPEG library's standard error handler (jerror.c) is divided into
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 * several "methods" which you can override individually. This lets you
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 * adjust the behavior without duplicating a lot of code, which you might
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 * have to update with each future release.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 * 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
175 * 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
176 * rather than calling exit() as the standard error_exit method does.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 * 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
179 * 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
180 * 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
181 * longjmp(). But we need to make the setjmp buffer accessible to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 * 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
183 * 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
184 * were making a subclass of the regular error handler.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 * Here's the extended error handler struct:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 struct my_jpeg_error_mgr
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 struct jpeg_error_mgr pub; /* "public" fields */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 jmp_buf setjmp_buffer; /* for return to caller */
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 #if defined(JPEG_LIB_VERSION) && (JPEG_LIB_VERSION >= 61)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 METHODDEF(void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 METHODDEF void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 our_init_source (j_decompress_ptr cinfo)
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 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 #if defined(JPEG_LIB_VERSION) && (JPEG_LIB_VERSION >= 61)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 METHODDEF(boolean)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 METHODDEF boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 our_fill_input_buffer (j_decompress_ptr cinfo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 /* Insert a fake EOI marker */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 struct jpeg_source_mgr *src = cinfo->src;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 static JOCTET buffer[2];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 buffer[0] = (JOCTET) 0xFF;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 buffer[1] = (JOCTET) JPEG_EOI;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 src->next_input_byte = buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 src->bytes_in_buffer = 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 return TRUE;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 our_skip_input_data (j_decompress_ptr cinfo, long num_bytes)
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 struct jpeg_source_mgr *src = NULL;
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 src = (struct jpeg_source_mgr *) cinfo->src;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 if (!src)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 } else if (num_bytes > src->bytes_in_buffer)
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 ERREXIT(cinfo, JERR_INPUT_EOF);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 /*NOTREACHED*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 }
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 src->bytes_in_buffer -= num_bytes;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 src->next_input_byte += num_bytes;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 #if defined(JPEG_LIB_VERSION) && (JPEG_LIB_VERSION >= 61)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 METHODDEF(void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 METHODDEF void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 our_term_source (j_decompress_ptr cinfo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 typedef struct
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 pub;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 } our_jpeg_source_mgr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 jpeg_memory_src (j_decompress_ptr cinfo, JOCTET *data, unsigned int len)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 struct jpeg_source_mgr *src;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 if (cinfo->src == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 { /* first time for this JPEG object? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 cinfo->src = (struct jpeg_source_mgr *)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 sizeof(our_jpeg_source_mgr));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 src = (struct jpeg_source_mgr *) cinfo->src;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 src->next_input_byte = data;
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 src = (struct jpeg_source_mgr *) cinfo->src;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 src->init_source = our_init_source;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 src->fill_input_buffer = our_fill_input_buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 src->skip_input_data = our_skip_input_data;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 src->resync_to_restart = jpeg_resync_to_restart; /* use default method */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 src->term_source = our_term_source;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 src->bytes_in_buffer = len;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 src->next_input_byte = data;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 #if defined(JPEG_LIB_VERSION) && (JPEG_LIB_VERSION >= 61)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 METHODDEF(void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 METHODDEF void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 my_jpeg_error_exit (j_common_ptr cinfo)
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 /* 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
292 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
293
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 /* Return control to the setjmp point */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 longjmp (myerr->setjmp_buffer, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 #if defined(JPEG_LIB_VERSION) && (JPEG_LIB_VERSION >= 61)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 METHODDEF(void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 METHODDEF void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 my_jpeg_output_message (j_common_ptr cinfo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 char buffer[JMSG_LENGTH_MAX];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 /* Create the message */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 (*cinfo->err->format_message) (cinfo, buffer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 warn_when_safe (Qjpeg, Qinfo, "%s", buffer);
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 /* 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
313 source code and from gif_instantiate() */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 jpeg_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 int dest_mask, Lisp_Object domain)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
319 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 /* 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
321 because the unwind-protect is always executed when this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 stack frame is still valid. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 struct jpeg_unwind_data unwind;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 int speccount = specpdl_depth ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 /* This struct contains the JPEG decompression parameters and pointers to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 * working space (which is allocated as needed by the JPEG library).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 struct jpeg_decompress_struct cinfo;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 /* We use our private extension JPEG error handler.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 * 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
332 * struct, to avoid dangling-pointer problems.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 struct my_jpeg_error_mgr jerr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 /* Step -1: First record our unwind-protect, which will clean up after
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 any exit, normal or not */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 xzero (unwind);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 record_unwind_protect (jpeg_instantiate_unwind, make_opaque_ptr (&unwind));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 /* Step 1: allocate and initialize JPEG decompression object */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 /* We set up the normal JPEG error routines, then override error_exit. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 cinfo.err = jpeg_std_error (&jerr.pub);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 jerr.pub.error_exit = my_jpeg_error_exit;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 jerr.pub.output_message = my_jpeg_output_message;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 /* Establish the setjmp return context for my_error_exit to use. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 if (setjmp (jerr.setjmp_buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 /* If we get here, the JPEG code has signaled an error.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 * 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
354 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 Lisp_Object errstring;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 char buffer[JMSG_LENGTH_MAX];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 /* Create the message */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 (*cinfo.err->format_message) ((j_common_ptr) &cinfo, buffer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 errstring = build_string (buffer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 signal_image_error_2 ("JPEG decoding error",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 errstring, instantiator);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 }
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 /* Now we can initialize the JPEG decompression object. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 jpeg_create_decompress (&cinfo);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 unwind.cinfo_ptr = &cinfo;
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 /* Step 2: specify data source (eg, a file) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
377 const Extbyte *bytes;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378 Extcount len;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 /* #### This is a definite problem under Mule due to the amount of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 stack data it might allocate. Need to be able to convert and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 write out to a file. */
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
383 TO_EXTERNAL_FORMAT (LISP_STRING, data, ALLOCA, (bytes, len), Qbinary);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 jpeg_memory_src (&cinfo, (JOCTET *) bytes, len);
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 /* Step 3: read file parameters with jpeg_read_header() */
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 jpeg_read_header (&cinfo, TRUE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 /* We can ignore the return value from jpeg_read_header since
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 * (a) suspension is not possible with the stdio data source, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 * (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
393 * See libjpeg.doc for more info.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 */
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 int jpeg_gray = 0; /* if we're dealing with a grayscale */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 /* Step 4: set parameters for decompression. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 /* Now that we're using EImages, send all data as 24bit color.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 The backend routine will take care of any necessary reductions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 We do have to handle the grayscale case ourselves, however. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 if (cinfo.jpeg_color_space == JCS_GRAYSCALE)
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 cinfo.out_color_space = JCS_GRAYSCALE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 jpeg_gray = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 /* we're relying on the jpeg driver to do any other conversions,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 or signal an error if the conversion isn't supported. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 cinfo.out_color_space = JCS_RGB;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 }
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 /* Step 5: Start decompressor */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 jpeg_start_decompress (&cinfo);
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 /* Step 6: Read in the data and put into EImage format (8bit RGB triples)*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 unwind.eimage = (unsigned char*) xmalloc (cinfo.output_width * cinfo.output_height * 3);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 if (!unwind.eimage)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 signal_image_error("Unable to allocate enough memory for image", instantiator);
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 JSAMPARRAY row_buffer; /* Output row buffer */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 JSAMPLE *jp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 int row_stride; /* physical row width in output buffer */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 unsigned char *op = unwind.eimage;
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 /* 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
431 * the data. After jpeg_start_decompress() we have the correct scaled
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 * output image dimensions available
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 * We need to make an output work buffer of the right size.
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 /* JSAMPLEs per row in output buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 row_stride = cinfo.output_width * cinfo.output_components;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 /* 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
438 with image */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 row_buffer = ((*cinfo.mem->alloc_sarray)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 ((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 /* 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
443 * loop counter, so that we don't have to keep track ourselves.
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 while (cinfo.output_scanline < cinfo.output_height)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449 /* jpeg_read_scanlines expects an array of pointers to scanlines.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 * 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
451 * more than one scanline at a time if that's more convenient.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453 (void) jpeg_read_scanlines (&cinfo, row_buffer, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 jp = row_buffer[0];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455 for (i = 0; i < cinfo.output_width; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 int clr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 if (jpeg_gray)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 unsigned char val;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 #if (BITS_IN_JSAMPLE == 8)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 val = (unsigned char)*jp++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 #else /* other option is 12 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 val = (unsigned char)(*jp++ >> 4);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 for (clr = 0; clr < 3; clr++) /* copy the same value into RGB */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 *op++ = val;
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 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 for (clr = 0; clr < 3; clr++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 #if (BITS_IN_JSAMPLE == 8)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 *op++ = (unsigned char)*jp++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 #else /* other option is 12 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 *op++ = (unsigned char)(*jp++ >> 4);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 }
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 }
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 }
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 /* Step 6.5: Create the pixmap and set up the image instance */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 /* now instantiate */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
485 MAYBE_DEVMETH (DOMAIN_XDEVICE (ii->domain),
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486 init_image_instance_from_eimage,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 (ii, cinfo.output_width, cinfo.output_height, 1,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488 unwind.eimage, dest_mask,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 instantiator, domain));
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 /* Step 7: Finish decompression */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 jpeg_finish_decompress (&cinfo);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 /* We can ignore the return value since suspension is not possible
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 * with the stdio data source.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498 /* And we're done! */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499 /* This will clean up everything else. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500 unbind_to (speccount, Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 }
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 #endif /* HAVE_JPEG */
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 #ifdef HAVE_GIF
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 /**********************************************************************
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507 * GIF *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 **********************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 #include "gifrlib.h"
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 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 gif_validate (Lisp_Object instantiator)
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 file_or_data_must_be_present (instantiator);
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 static Lisp_Object
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
519 gif_normalize (Lisp_Object inst, Lisp_Object console_type,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
520 Lisp_Object dest_mask)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 return simple_image_type_normalize (inst, console_type, Qgif);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523 }
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 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 gif_possible_dest_types (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 return IMAGE_COLOR_PIXMAP_MASK;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529 }
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 /* To survive the otherwise baffling complexity of making sure
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 everything gets cleaned up in the presence of an error, we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533 use an unwind_protect(). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535 struct gif_unwind_data
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 unsigned char *eimage;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 /* Object that holds the decoded data from a GIF file */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 GifFileType *giffile;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 gif_instantiate_unwind (Lisp_Object unwind_obj)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 struct gif_unwind_data *data =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546 (struct gif_unwind_data *) get_opaque_ptr (unwind_obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 free_opaque_ptr (unwind_obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 if (data->giffile)
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 DGifCloseFile (data->giffile);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552 GifFree(data->giffile);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554 if (data->eimage) xfree(data->eimage);
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 Qnil;
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 typedef struct gif_memory_storage
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561 Extbyte *bytes; /* The data */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562 Extcount len; /* How big is it? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563 int index; /* Where are we? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564 } gif_memory_storage;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566 static size_t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567 gif_read_from_memory(GifByteType *buf, size_t size, VoidPtr data)
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 gif_memory_storage *mem = (gif_memory_storage*)data;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571 if (size > (mem->len - mem->index))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572 return (size_t) -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573 memcpy(buf, mem->bytes + mem->index, size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574 mem->index = mem->index + size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
575 return size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579 gif_memory_close(VoidPtr data)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
580 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
582 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584 struct gif_error_struct
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
586 const char *err_str; /* return the error string */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 jmp_buf setjmp_buffer; /* for return to caller */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590 static void
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
591 gif_error_func(const char *err_str, VoidPtr error_ptr)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593 struct gif_error_struct *error_data = (struct gif_error_struct*)error_ptr;
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 to setjmp point */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
596 error_data->err_str = err_str;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597 longjmp (error_data->setjmp_buffer, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601 gif_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 int dest_mask, Lisp_Object domain)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
605 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606 /* 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
607 because the unwind-protect is always executed when this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608 stack frame is still valid. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609 struct gif_unwind_data unwind;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 int speccount = specpdl_depth ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611 gif_memory_storage mem_struct;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 struct gif_error_struct gif_err;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613 Extbyte *bytes;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614 Extcount len;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615 int height = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616 int width = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618 xzero (unwind);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619 record_unwind_protect (gif_instantiate_unwind, make_opaque_ptr (&unwind));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621 /* 1. Now decode the data. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626 assert (!NILP (data));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628 if (!(unwind.giffile = GifSetup()))
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
629 signal_image_error ("Insufficient memory to instantiate GIF image", instantiator);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631 /* set up error facilities */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632 if (setjmp(gif_err.setjmp_buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
633 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634 /* 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
635 for us. Just pass the error along. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636 Lisp_Object errstring;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637 errstring = build_string (gif_err.err_str);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 signal_image_error_2 ("GIF decoding error", errstring, instantiator);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
639 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
640 GifSetErrorFunc(unwind.giffile, (Gif_error_func)gif_error_func, (VoidPtr)&gif_err);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
642 TO_EXTERNAL_FORMAT (LISP_STRING, data, ALLOCA, (bytes, len), Qbinary);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 mem_struct.bytes = bytes;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 mem_struct.len = len;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645 mem_struct.index = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646 GifSetReadFunc(unwind.giffile, gif_read_from_memory, (VoidPtr)&mem_struct);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647 GifSetCloseFunc(unwind.giffile, gif_memory_close, (VoidPtr)&mem_struct);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
648 DGifInitRead(unwind.giffile);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650 /* Then slurp the image into memory, decoding along the way.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651 The result is the image in a simple one-byte-per-pixel
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652 format (#### the GIF routines only support 8-bit GIFs,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653 it appears). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 DGifSlurp (unwind.giffile);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657 /* 3. Now create the EImage(s) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659 ColorMapObject *cmo = unwind.giffile->SColorMap;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660 int i, j, row, pass, interlace, slice;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661 unsigned char *eip;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662 /* interlaced gifs have rows in this order:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663 0, 8, 16, ..., 4, 12, 20, ..., 2, 6, 10, ..., 1, 3, 5, ... */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664 static int InterlacedOffset[] = { 0, 4, 2, 1 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
665 static int InterlacedJumps[] = { 8, 8, 4, 2 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
667 height = unwind.giffile->SHeight;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
668 width = unwind.giffile->SWidth;
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
669 unwind.eimage = (unsigned char*)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670 xmalloc (width * height * 3 * unwind.giffile->ImageCount);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
671 if (!unwind.eimage)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672 signal_image_error("Unable to allocate enough memory for image", instantiator);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674 /* write the data in EImage format (8bit RGB triples) */
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 for (slice = 0; slice < unwind.giffile->ImageCount; slice++)
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 /* We check here that that the current image covers the full "screen" size. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
679 if (unwind.giffile->SavedImages[slice].ImageDesc.Height != height
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
680 || unwind.giffile->SavedImages[slice].ImageDesc.Width != width
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
681 || unwind.giffile->SavedImages[slice].ImageDesc.Left != 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682 || unwind.giffile->SavedImages[slice].ImageDesc.Top != 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683 signal_image_error ("Image in GIF file is not full size",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
684 instantiator);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686 interlace = unwind.giffile->SavedImages[slice].ImageDesc.Interlace;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687 pass = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688 row = interlace ? InterlacedOffset[pass] : 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
689 eip = unwind.eimage + (width * height * 3 * slice);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690 for (i = 0; i < height; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692 if (interlace)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693 if (row >= height) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694 row = InterlacedOffset[++pass];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695 while (row >= height)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
696 row = InterlacedOffset[++pass];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698 eip = unwind.eimage + (width * height * 3 * slice) + (row * width * 3);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699 for (j = 0; j < width; j++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
700 {
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
701 unsigned char pixel =
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
702 unwind.giffile->SavedImages[slice].RasterBits[(i * width) + j];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
703 *eip++ = cmo->Colors[pixel].Red;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704 *eip++ = cmo->Colors[pixel].Green;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705 *eip++ = cmo->Colors[pixel].Blue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
707 row += interlace ? InterlacedJumps[pass] : 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
708 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
709 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
710
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
711 /* now instantiate */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
712 MAYBE_DEVMETH (DOMAIN_XDEVICE (ii->domain),
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713 init_image_instance_from_eimage,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
714 (ii, width, height, unwind.giffile->ImageCount, unwind.eimage, dest_mask,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715 instantiator, domain));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716 }
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 /* 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
719 animate the gif. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
720 if (unwind.giffile->ImageCount > 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
721 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
722 /* See if there is a timeout value. In theory there could be one
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
723 for every image - but that makes the implementation way to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
724 complicated for now so we just take the first. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
725 unsigned short timeout = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
726 Lisp_Object tid;
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 if (unwind.giffile->SavedImages[0].Function == GRAPHICS_EXT_FUNC_CODE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
729 &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730 unwind.giffile->SavedImages[0].ExtensionBlockCount)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732 timeout = (unsigned short)
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
733 ((unwind.giffile->SavedImages[0].ExtensionBlocks[0].Bytes[2] << 8) +
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734 unwind.giffile-> SavedImages[0].ExtensionBlocks[0].Bytes[1]) * 10;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 /* Too short a timeout will crucify us performance-wise. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738 tid = add_glyph_animated_timeout (timeout > 10 ? timeout : 10, image_instance);
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 if (!NILP (tid))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
741 IMAGE_INSTANCE_PIXMAP_TIMEOUT (ii) = XINT (tid);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
742 }
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
743
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
744 unbind_to (speccount, Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
745 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
746
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747 #endif /* HAVE_GIF */
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750 #ifdef HAVE_PNG
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 * PNG *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754 **********************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
756 png_validate (Lisp_Object instantiator)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758 file_or_data_must_be_present (instantiator);
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 static Lisp_Object
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
762 png_normalize (Lisp_Object inst, Lisp_Object console_type,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
763 Lisp_Object dest_mask)
428
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 return simple_image_type_normalize (inst, console_type, Qpng);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769 png_possible_dest_types (void)
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 return IMAGE_COLOR_PIXMAP_MASK;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
774 struct png_memory_storage
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
775 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
776 const Extbyte *bytes; /* The data */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
777 Extcount len; /* How big is it? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778 int index; /* Where are we? */
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782 png_read_from_memory(png_structp png_ptr, png_bytep data,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783 png_size_t length)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
784 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
785 struct png_memory_storage *tbr =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
786 (struct png_memory_storage *) png_get_io_ptr (png_ptr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
787
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
788 if (length > (tbr->len - tbr->index))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
789 png_error (png_ptr, (png_const_charp) "Read Error");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
790 memcpy (data,tbr->bytes + tbr->index,length);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
791 tbr->index = tbr->index + length;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
794 struct png_error_struct
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
795 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
796 const char *err_str;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
797 jmp_buf setjmp_buffer; /* for return to caller */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
798 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
799
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
800 /* jh 98/03/12 - #### AARRRGH! libpng includes jmp_buf inside its own
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
801 structure, and there are cases where the size can be different from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
802 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
803 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
804 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
805 go away when the lisp engine is threaded! */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806 static struct png_error_struct png_err_stct;
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 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
809 png_error_func (png_structp png_ptr, png_const_charp msg)
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 png_err_stct.err_str = msg;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
812 longjmp (png_err_stct.setjmp_buffer, 1);
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
815 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
816 png_warning_func (png_structp png_ptr, png_const_charp msg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
817 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
818 warn_when_safe (Qpng, Qinfo, "%s", msg);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
819 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
820
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
821 struct png_unwind_data
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 FILE *instream;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
824 unsigned char *eimage;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
825 png_structp png_ptr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
826 png_infop info_ptr;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
829 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830 png_instantiate_unwind (Lisp_Object unwind_obj)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832 struct png_unwind_data *data =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
833 (struct png_unwind_data *) get_opaque_ptr (unwind_obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
834
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
835 free_opaque_ptr (unwind_obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
836 if (data->png_ptr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
837 png_destroy_read_struct (&(data->png_ptr), &(data->info_ptr), (png_infopp)NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
838 if (data->instream)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
839 fclose (data->instream);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841 if (data->eimage) xfree(data->eimage);
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 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
844 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
845
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
847 png_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
848 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
849 int dest_mask, Lisp_Object domain)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850 {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
851 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
852 struct png_unwind_data unwind;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
853 int speccount = specpdl_depth ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
854 int height, width;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
855 struct png_memory_storage tbr; /* Data to be read */
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 /* PNG variables */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
858 png_structp png_ptr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
859 png_infop info_ptr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
860
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
861 /* Initialize all PNG structures */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
862 png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING, (void*)&png_err_stct,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
863 png_error_func, png_warning_func);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
864 if (!png_ptr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
865 signal_image_error ("Error obtaining memory for png_read", instantiator);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
866 info_ptr = png_create_info_struct (png_ptr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
867 if (!info_ptr)
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 png_destroy_read_struct (&png_ptr, (png_infopp)NULL, (png_infopp)NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
870 signal_image_error ("Error obtaining memory for png_read", instantiator);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
871 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
872
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
873 xzero (unwind);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
874 unwind.png_ptr = png_ptr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
875 unwind.info_ptr = info_ptr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
876
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
877 record_unwind_protect (png_instantiate_unwind, make_opaque_ptr (&unwind));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
878
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
879 /* 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
880 this file, example.c from the libpng 0.81 distribution, and the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
881 pngtopnm sources. -WMP-
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
882 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
883 /* 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
884 and is no longer usable for previous versions. jh
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
885 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
886
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
887 /* Set the jmp_buf return context for png_error ... if this returns !0, then
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
888 we ran into a problem somewhere, and need to clean up after ourselves. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
889 if (setjmp (png_err_stct.setjmp_buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
890 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
891 /* Something blew up: just display the error (cleanup happens in the unwind) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
892 signal_image_error_2 ("Error decoding PNG",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
893 build_string(png_err_stct.err_str),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
894 instantiator);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
895 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
896
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
897 /* Initialize the IO layer and read in header information */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
898 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
899 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
900 const Extbyte *bytes;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
901 Extcount len;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
902
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
903 assert (!NILP (data));
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 /* #### This is a definite problem under Mule due to the amount of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
906 stack data it might allocate. Need to think about using Lstreams */
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
907 TO_EXTERNAL_FORMAT (LISP_STRING, data, ALLOCA, (bytes, len), Qbinary);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
908 tbr.bytes = bytes;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
909 tbr.len = len;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
910 tbr.index = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
911 png_set_read_fn (png_ptr,(void *) &tbr, png_read_from_memory);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
912 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
913
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
914 png_read_info (png_ptr, info_ptr);
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 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
917 int y;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
918 unsigned char **row_pointers;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
919 height = info_ptr->height;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
920 width = info_ptr->width;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
921
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
922 /* Wow, allocate all the memory. Truly, exciting. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
923 unwind.eimage = xnew_array_and_zero (unsigned char, width * height * 3);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
924 /* libpng expects that the image buffer passed in contains a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
925 picture to draw on top of if the png has any transparencies.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
926 This could be a good place to pass that in... */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
927
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
928 row_pointers = xnew_array (png_byte *, height);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
929
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
930 for (y = 0; y < height; y++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
931 row_pointers[y] = unwind.eimage + (width * 3 * y);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
932
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
933 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
934 /* if the png specifies a background chunk, go ahead and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
935 use it, else use what we can get from the default face. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
936 png_color_16 my_background, *image_background;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
937 Lisp_Object bkgd = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
938
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
939 my_background.red = 0x7fff;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
940 my_background.green = 0x7fff;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
941 my_background.blue = 0x7fff;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
942 bkgd = FACE_BACKGROUND (Vdefault_face, domain);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
943 if (!COLOR_INSTANCEP (bkgd))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
944 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
945 warn_when_safe (Qpng, Qinfo, "Couldn't get background color!");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
946 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
947 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
948 {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
949 Lisp_Color_Instance *c;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
950 Lisp_Object rgblist;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
951
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
952 c = XCOLOR_INSTANCE (bkgd);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
953 rgblist = MAYBE_LISP_DEVMETH (XDEVICE (c->device),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
954 color_instance_rgb_components,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
955 (c));
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
956 my_background.red = (unsigned short) XINT (XCAR (rgblist));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
957 my_background.green = (unsigned short) XINT (XCAR (XCDR (rgblist)));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
958 my_background.blue = (unsigned short) XINT (XCAR (XCDR (XCDR (rgblist))));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
959 }
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 if (png_get_bKGD (png_ptr, info_ptr, &image_background))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
962 png_set_background (png_ptr, image_background,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
963 PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
964 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
965 png_set_background (png_ptr, &my_background,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
966 PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
967 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
968
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
969 /* 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
970 of image*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
971 /* convert palette images to full RGB */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
972 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
973 png_set_expand (png_ptr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
974 /* send grayscale images to RGB too */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
975 if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
976 info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
977 png_set_gray_to_rgb (png_ptr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
978 /* we can't handle alpha values */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
979 if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
980 png_set_strip_alpha (png_ptr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
981 /* tell libpng to strip 16 bit depth files down to 8 bits */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
982 if (info_ptr->bit_depth == 16)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
983 png_set_strip_16 (png_ptr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
984 /* if the image is < 8 bits, pad it out */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
985 if (info_ptr->bit_depth < 8)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
986 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
987 if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
988 png_set_expand (png_ptr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
989 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
990 png_set_packing (png_ptr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
991 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
992
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
993 png_read_image (png_ptr, row_pointers);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
994 png_read_end (png_ptr, info_ptr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
995
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
996 #ifdef PNG_SHOW_COMMENTS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
997 /* ####
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
998 * I turn this off by default now, because the !%^@#!% comments
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
999 * show up every time the image is instantiated, which can get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1000 * really really annoying. There should be some way to pass this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1001 * type of data down into the glyph code, where you can get to it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1002 * from lisp anyway. - WMP
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1003 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1004 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1005 int i;
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 for (i = 0 ; i < info_ptr->num_text ; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1008 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1009 /* How paranoid do I have to be about no trailing NULLs, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1010 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
1011 string somewhere? */
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 warn_when_safe (Qpng, Qinfo, "%s - %s",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1014 info_ptr->text[i].key,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1015 info_ptr->text[i].text);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1016 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1017 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1018 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1019
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1020 xfree (row_pointers);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1021 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1022
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1023 /* now instantiate */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1024 MAYBE_DEVMETH (DOMAIN_XDEVICE (ii->domain),
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1025 init_image_instance_from_eimage,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1026 (ii, width, height, 1, unwind.eimage, dest_mask,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1027 instantiator, domain));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1028
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1029 /* This will clean up everything else. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1030 unbind_to (speccount, Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1031 }
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 #endif /* HAVE_PNG */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1034
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1035
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1036 #ifdef HAVE_TIFF
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1037 #include "tiffio.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1038
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1039 /**********************************************************************
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1040 * TIFF *
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 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1043 tiff_validate (Lisp_Object instantiator)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1044 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1045 file_or_data_must_be_present (instantiator);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1046 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1047
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1048 static Lisp_Object
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1049 tiff_normalize (Lisp_Object inst, Lisp_Object console_type,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1050 Lisp_Object dest_mask)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1051 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1052 return simple_image_type_normalize (inst, console_type, Qtiff);
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1055 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1056 tiff_possible_dest_types (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1057 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1058 return IMAGE_COLOR_PIXMAP_MASK;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1059 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1060
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1061 struct tiff_unwind_data
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1062 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1063 unsigned char *eimage;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1064 /* Object that holds the decoded data from a TIFF file */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1065 TIFF *tiff;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1066 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1067
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1068 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1069 tiff_instantiate_unwind (Lisp_Object unwind_obj)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1070 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1071 struct tiff_unwind_data *data =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1072 (struct tiff_unwind_data *) get_opaque_ptr (unwind_obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1073
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1074 free_opaque_ptr (unwind_obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1075 if (data->tiff)
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 TIFFClose(data->tiff);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1078 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1079 if (data->eimage)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1080 xfree (data->eimage);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1081
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1082 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1083 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1084
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1085 typedef struct tiff_memory_storage
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1086 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1087 Extbyte *bytes; /* The data */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1088 Extcount len; /* How big is it? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1089 int index; /* Where are we? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1090 } tiff_memory_storage;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1091
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1092 static size_t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1093 tiff_memory_read(thandle_t data, tdata_t buf, tsize_t size)
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 tiff_memory_storage *mem = (tiff_memory_storage*)data;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1096
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1097 if (size > (mem->len - mem->index))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1098 return (size_t) -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1099 memcpy(buf, mem->bytes + mem->index, size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1100 mem->index = mem->index + size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1101 return size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1102 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1103
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1104 static size_t tiff_memory_write(thandle_t data, tdata_t buf, tsize_t size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1105 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1106 abort();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1107 return 0; /* Shut up warnings. */
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1110 static toff_t tiff_memory_seek(thandle_t data, toff_t off, int whence)
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 tiff_memory_storage *mem = (tiff_memory_storage*)data;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1113 int newidx;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1114 switch(whence) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1115 case SEEK_SET:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1116 newidx = off;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1117 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1118 case SEEK_END:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1119 newidx = mem->len + off;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1120 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1121 case SEEK_CUR:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1122 newidx = mem->index + off;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1123 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1124 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1125 fprintf(stderr,"Eh? invalid seek mode in tiff_memory_seek\n");
593
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
1126 return (toff_t) -1;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1129 if ((newidx > mem->len) || (newidx < 0))
593
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
1130 return (toff_t) -1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1131
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1132 mem->index = newidx;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1133 return newidx;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1134 }
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 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1137 tiff_memory_close(thandle_t data)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1138 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1139 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1140 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1141
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1142 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1143 tiff_map_noop(thandle_t data, tdata_t* pbase, toff_t* psize)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1144 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1145 return 0;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1148 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1149 tiff_unmap_noop(thandle_t data, tdata_t pbase, toff_t psize)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1150 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1151 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1152 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1153
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1154 static toff_t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1155 tiff_memory_size(thandle_t data)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1156 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1157 tiff_memory_storage *mem = (tiff_memory_storage*)data;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1158 return mem->len;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1159 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1160
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1161 struct tiff_error_struct
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1162 {
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
1163 #ifdef HAVE_VSNPRINTF
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1164 char err_str[256];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1165 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1166 char err_str[1024]; /* return the error string */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1167 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1168 jmp_buf setjmp_buffer; /* for return to caller */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1169 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1170
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1171 /* 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
1172 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
1173 have any place to store error func data. This should be rectified
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1174 before XEmacs gets threads! */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1175 static struct tiff_error_struct tiff_err_data;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1176
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1177 static void
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1178 tiff_error_func(const char *module, const char *fmt, ...)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1179 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1180 va_list vargs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1181
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1182 va_start (vargs, fmt);
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
1183 #ifdef HAVE_VSNPRINTF
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1184 vsnprintf (tiff_err_data.err_str, 255, fmt, vargs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1185 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1186 /* pray this doesn't overflow... */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1187 vsprintf (tiff_err_data.err_str, fmt, vargs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1188 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1189 va_end (vargs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1190 /* return to setjmp point */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1191 longjmp (tiff_err_data.setjmp_buffer, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1192 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1193
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1194 static void
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1195 tiff_warning_func(const char *module, const char *fmt, ...)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1196 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1197 va_list vargs;
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
1198 #ifdef HAVE_VSNPRINTF
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1199 char warn_str[256];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1200 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1201 char warn_str[1024];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1202 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1203
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1204 va_start (vargs, fmt);
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
1205 #ifdef HAVE_VSNPRINTF
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1206 vsnprintf (warn_str, 255, fmt, vargs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1207 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1208 vsprintf (warn_str, fmt, vargs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1209 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1210 va_end (vargs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1211 warn_when_safe (Qtiff, Qinfo, "%s - %s",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1212 module, warn_str);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1213 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1214
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1215 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1216 tiff_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1217 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1218 int dest_mask, Lisp_Object domain)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1219 {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1220 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1221 tiff_memory_storage mem_struct;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1222 /* 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
1223 because the unwind-protect is always executed when this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1224 stack frame is still valid. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1225 struct tiff_unwind_data unwind;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1226 int speccount = specpdl_depth ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1227 uint32 width, height;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1228
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1229 xzero (unwind);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1230 record_unwind_protect (tiff_instantiate_unwind, make_opaque_ptr (&unwind));
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 /* set up error facilities */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1233 if (setjmp (tiff_err_data.setjmp_buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1234 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1235 /* 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
1236 for us. Just pass the error along. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1237 signal_image_error_2 ("TIFF decoding error",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1238 build_string(tiff_err_data.err_str),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1239 instantiator);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1240 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1241 TIFFSetErrorHandler ((TIFFErrorHandler)tiff_error_func);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1242 TIFFSetWarningHandler ((TIFFErrorHandler)tiff_warning_func);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1243 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1244 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1245 Extbyte *bytes;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1246 Extcount len;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1247
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1248 uint32 *raster;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1249 unsigned char *ep;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1250
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1251 assert (!NILP (data));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1252
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1253 /* #### This is a definite problem under Mule due to the amount of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1254 stack data it might allocate. Think about Lstreams... */
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1255 TO_EXTERNAL_FORMAT (LISP_STRING, data,
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1256 ALLOCA, (bytes, len),
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1257 Qbinary);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1258 mem_struct.bytes = bytes;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1259 mem_struct.len = len;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1260 mem_struct.index = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1261
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1262 unwind.tiff = TIFFClientOpen ("memfile", "r", (thandle_t) &mem_struct,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1263 (TIFFReadWriteProc)tiff_memory_read,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1264 (TIFFReadWriteProc)tiff_memory_write,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1265 tiff_memory_seek, tiff_memory_close, tiff_memory_size,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1266 tiff_map_noop, tiff_unmap_noop);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1267 if (!unwind.tiff)
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1268 signal_image_error ("Insufficient memory to instantiate TIFF image", instantiator);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1269
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1270 TIFFGetField (unwind.tiff, TIFFTAG_IMAGEWIDTH, &width);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1271 TIFFGetField (unwind.tiff, TIFFTAG_IMAGELENGTH, &height);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1272 unwind.eimage = (unsigned char *) xmalloc (width * height * 3);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1273
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1274 /* #### This is little more than proof-of-concept/function testing.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1275 It needs to be reimplemented via scanline reads for both memory
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1276 compactness. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1277 raster = (uint32*) _TIFFmalloc (width * height * sizeof (uint32));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1278 if (raster != NULL)
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 int i,j;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1281 uint32 *rp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1282 ep = unwind.eimage;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1283 rp = raster;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1284 if (TIFFReadRGBAImage (unwind.tiff, width, height, raster, 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1285 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1286 for (i = height - 1; i >= 0; i--)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1287 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1288 /* This is to get around weirdness in the libtiff library where properly
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1289 made TIFFs will come out upside down. libtiff bug or jhod-brainlock? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1290 rp = raster + (i * width);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1291 for (j = 0; j < width; j++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1292 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1293 *ep++ = (unsigned char)TIFFGetR(*rp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1294 *ep++ = (unsigned char)TIFFGetG(*rp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1295 *ep++ = (unsigned char)TIFFGetB(*rp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1296 rp++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1297 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1298 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1299 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1300 _TIFFfree (raster);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1301 } else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1302 signal_image_error ("Unable to allocate memory for TIFFReadRGBA", instantiator);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1303
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1304 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1305
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1306 /* now instantiate */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1307 MAYBE_DEVMETH (DOMAIN_XDEVICE (ii->domain),
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1308 init_image_instance_from_eimage,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1309 (ii, width, height, 1, unwind.eimage, dest_mask,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1310 instantiator, domain));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1311
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1312 unbind_to (speccount, Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1313 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1314
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1315 #endif /* HAVE_TIFF */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1316
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1317
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1318 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1319 /* initialization */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1320 /************************************************************************/
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 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1323 syms_of_glyphs_eimage (void)
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 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1326
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1327 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1328 image_instantiator_format_create_glyphs_eimage (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1329 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1330 /* image-instantiator types */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1331 #ifdef HAVE_JPEG
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1332 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (jpeg, "jpeg");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1333
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1334 IIFORMAT_HAS_METHOD (jpeg, validate);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1335 IIFORMAT_HAS_METHOD (jpeg, normalize);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1336 IIFORMAT_HAS_METHOD (jpeg, possible_dest_types);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1337 IIFORMAT_HAS_METHOD (jpeg, instantiate);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1338
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1339 IIFORMAT_VALID_KEYWORD (jpeg, Q_data, check_valid_string);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1340 IIFORMAT_VALID_KEYWORD (jpeg, Q_file, check_valid_string);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1341 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1342
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1343 #ifdef HAVE_GIF
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1344 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (gif, "gif");
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 IIFORMAT_HAS_METHOD (gif, validate);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1347 IIFORMAT_HAS_METHOD (gif, normalize);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1348 IIFORMAT_HAS_METHOD (gif, possible_dest_types);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1349 IIFORMAT_HAS_METHOD (gif, instantiate);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1350
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1351 IIFORMAT_VALID_KEYWORD (gif, Q_data, check_valid_string);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1352 IIFORMAT_VALID_KEYWORD (gif, Q_file, check_valid_string);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1353 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1354
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1355 #ifdef HAVE_PNG
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1356 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (png, "png");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1357
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1358 IIFORMAT_HAS_METHOD (png, validate);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1359 IIFORMAT_HAS_METHOD (png, normalize);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1360 IIFORMAT_HAS_METHOD (png, possible_dest_types);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1361 IIFORMAT_HAS_METHOD (png, instantiate);
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 IIFORMAT_VALID_KEYWORD (png, Q_data, check_valid_string);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1364 IIFORMAT_VALID_KEYWORD (png, Q_file, check_valid_string);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1365 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1366
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1367 #ifdef HAVE_TIFF
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1368 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (tiff, "tiff");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1369
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1370 IIFORMAT_HAS_METHOD (tiff, validate);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1371 IIFORMAT_HAS_METHOD (tiff, normalize);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1372 IIFORMAT_HAS_METHOD (tiff, possible_dest_types);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1373 IIFORMAT_HAS_METHOD (tiff, instantiate);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1374
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1375 IIFORMAT_VALID_KEYWORD (tiff, Q_data, check_valid_string);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1376 IIFORMAT_VALID_KEYWORD (tiff, Q_file, check_valid_string);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1377 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1378
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1379 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1380
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1381 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1382 vars_of_glyphs_eimage (void)
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 #ifdef HAVE_JPEG
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1385 Fprovide (Qjpeg);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1386 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1387
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1388 #ifdef HAVE_GIF
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1389 Fprovide (Qgif);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1390 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1391
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1392 #ifdef HAVE_PNG
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1393 Fprovide (Qpng);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1394 #endif
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 #ifdef HAVE_TIFF
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1397 Fprovide (Qtiff);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1398 #endif
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 }