annotate src/glyphs-eimage.c @ 408:501cfd01ee6d r21-2-34

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