author | Claus Gittinger <cg@exept.de> |
Mon, 12 Dec 2011 21:19:08 +0100 | |
changeset 2971 | 07bd4e98036e |
parent 2768 | 38e9b42f2af8 |
child 2972 | c9b3ef795181 |
permissions | -rw-r--r-- |
6 | 1 |
" |
2 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
28 | 3 |
All Rights Reserved |
6 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
1558
1ae43779327f
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
1094
diff
changeset
|
12 |
"{ Package: 'stx:libview2' }" |
1ae43779327f
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
1094
diff
changeset
|
13 |
|
2 | 14 |
ImageReader subclass:#JPEGReader |
537 | 15 |
instanceVariableNames:'jpeg_decompress_struct jpeg_error_mgr_struct colorComponents |
2971
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
16 |
forceGrayscale forceDitherMode app1SegmentHandler' |
576 | 17 |
classVariableNames:'ErrorPrinting' |
199 | 18 |
poolDictionaries:'' |
1745
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1698
diff
changeset
|
19 |
category:'Graphics-Images-Readers' |
2 | 20 |
! |
21 |
||
522 | 22 |
!JPEGReader primitiveDefinitions! |
23 |
%{ |
|
24 |
||
25 |
/* |
|
26 |
* includes, defines, structure definitions |
|
27 |
* and typedefs come here. |
|
28 |
*/ |
|
29 |
||
528 | 30 |
#include <stdio.h> |
31 |
||
542 | 32 |
#ifdef sunos |
33 |
# include <sys/types.h> |
|
528 | 34 |
#endif |
35 |
||
542 | 36 |
#include <jpeglib.h> |
37 |
#include <jerror.h> |
|
38 |
||
534 | 39 |
struct my_error_mgr { |
40 |
struct jpeg_error_mgr pub; |
|
41 |
jmp_buf setjmp_buffer; |
|
42 |
}; |
|
43 |
||
528 | 44 |
%} |
45 |
! ! |
|
46 |
||
47 |
!JPEGReader primitiveFunctions! |
|
48 |
%{ |
|
49 |
||
1061
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
50 |
/* |
528 | 51 |
* any local C (helper) functions |
52 |
* come here (please, define as static) |
|
53 |
*/ |
|
54 |
||
1061
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
55 |
static |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
56 |
my_error_exit(cinfo) |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
57 |
j_common_ptr cinfo; |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
58 |
{ |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
59 |
struct my_error_mgr *myerrPtr = (struct my_error_mgr *) cinfo->err; |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
60 |
|
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
61 |
if (@global(ErrorPrinting) == true) { |
2283 | 62 |
console_fprintf(stderr, "JPEGReader [warning]: jpeg error\n"); |
1061
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
63 |
} |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
64 |
longjmp(myerrPtr->setjmp_buffer, 1); |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
65 |
} |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
66 |
|
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
67 |
static |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
68 |
my_output_message(cinfo) |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
69 |
j_common_ptr cinfo; |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
70 |
{ |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
71 |
char buffer[JMSG_LENGTH_MAX]; |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
72 |
|
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
73 |
if (@global(ErrorPrinting) == true) { |
2283 | 74 |
console_fprintf(stderr, "libJPEG [error]: "); |
1061
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
75 |
|
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
76 |
/* Create the message */ |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
77 |
(*cinfo->err->format_message) (cinfo, buffer); |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
78 |
|
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
79 |
/* Send it to stderr, adding a newline */ |
2283 | 80 |
console_fprintf(stderr, "%s\n", buffer); |
1061
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
81 |
} |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
82 |
} |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
83 |
|
528 | 84 |
/* |
85 |
* Optional progress monitor: display a percent-done figure on stderr. |
|
86 |
*/ |
|
87 |
||
88 |
#ifdef PROGRESS_REPORT |
|
89 |
||
90 |
void |
|
91 |
JPG_progress_monitor (j_common_ptr cinfo) |
|
92 |
{ |
|
93 |
cd_progress_ptr prog = (cd_progress_ptr) cinfo->progress; |
|
94 |
int total_passes = prog->pub.total_passes + prog->total_extra_passes; |
|
95 |
int percent_done = (int) (prog->pub.pass_counter*100L/prog->pub.pass_limit); |
|
96 |
||
97 |
if (percent_done != prog->percent_done) { |
|
98 |
prog->percent_done = percent_done; |
|
99 |
if (total_passes > 1) { |
|
2283 | 100 |
console_fprintf("\rPass %d/%d: %3d%% ", |
1061
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
101 |
prog->pub.completed_passes + prog->completed_extra_passes + 1, |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
102 |
total_passes, percent_done); |
528 | 103 |
} else { |
2283 | 104 |
console_fprintf("\r %3d%% ", percent_done); |
528 | 105 |
} |
2283 | 106 |
console_fflush(stderr); |
528 | 107 |
} |
108 |
} |
|
109 |
||
110 |
||
111 |
void |
|
112 |
JPG_start_progress_monitor (j_common_ptr cinfo, cd_progress_ptr progress) |
|
113 |
{ |
|
114 |
/* Enable progress display, unless trace output is on */ |
|
115 |
if (cinfo->err->trace_level == 0) { |
|
116 |
progress->pub.progress_monitor = progress_monitor; |
|
117 |
progress->completed_extra_passes = 0; |
|
118 |
progress->total_extra_passes = 0; |
|
119 |
progress->percent_done = -1; |
|
120 |
cinfo->progress = &progress->pub; |
|
121 |
} |
|
122 |
} |
|
123 |
||
124 |
||
125 |
void |
|
126 |
JPG_end_progress_monitor (j_common_ptr cinfo) |
|
127 |
{ |
|
128 |
/* Clear away progress display */ |
|
129 |
if (cinfo->err->trace_level == 0) { |
|
2283 | 130 |
console_fprintf(stderr, "\r \r"); |
528 | 131 |
} |
132 |
} |
|
133 |
||
2971
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
134 |
#endif /* PROGRESS_REPORT */ |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
135 |
|
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
136 |
|
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
137 |
/* fetch a byte from the stream */ |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
138 |
unsigned int |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
139 |
JPG_jpeg_getc (j_decompress_ptr cinfo) |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
140 |
/* Read next byte */ |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
141 |
{ |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
142 |
struct jpeg_source_mgr *datasrc = cinfo->src; |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
143 |
|
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
144 |
if (datasrc->bytes_in_buffer == 0) { |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
145 |
if (! (*datasrc->fill_input_buffer) (cinfo)) |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
146 |
return -1; |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
147 |
} |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
148 |
datasrc->bytes_in_buffer--; |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
149 |
return (*datasrc->next_input_byte++) & 0xFF; |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
150 |
} |
522 | 151 |
|
152 |
%} |
|
153 |
! ! |
|
154 |
||
21 | 155 |
!JPEGReader class methodsFor:'documentation'! |
156 |
||
157 |
copyright |
|
158 |
" |
|
159 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
28 | 160 |
All Rights Reserved |
16 | 161 |
|
21 | 162 |
This software is furnished under a license and may be used |
163 |
only in accordance with the terms of that license and with the |
|
164 |
inclusion of the above copyright notice. This software may not |
|
165 |
be provided or otherwise made available to, or used by, any |
|
166 |
other person. No title to or ownership of the software is |
|
167 |
hereby transferred. |
|
168 |
" |
|
169 |
! |
|
16 | 170 |
|
21 | 171 |
documentation |
172 |
" |
|
173 |
Reader for JPEG images. |
|
199 | 174 |
|
532 | 175 |
This uses the libpeg library to read the image |
199 | 176 |
|
177 |
Only reading of files is supported. |
|
178 |
||
179 |
[See also:] |
|
1061
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
180 |
Image Form Icon |
2282 | 181 |
BlitImageReader FaceReader GIFReader PBMReader PCXReader |
182 |
ST80FormReader SunRasterReader TargaReader TIFFReader WindowsIconReader |
|
183 |
XBMReader XPMReader XWDReader |
|
21 | 184 |
" |
185 |
! ! |
|
16 | 186 |
|
28 | 187 |
!JPEGReader class methodsFor:'initialization'! |
188 |
||
189 |
initialize |
|
199 | 190 |
"install myself in the Image classes fileFormat table |
398 | 191 |
for the `.jpg' and '.jpeg' extensions." |
199 | 192 |
|
647 | 193 |
MIMETypes defineImageType:'image/jpeg' suffix:'jpg' reader:self. |
194 |
MIMETypes defineImageType:nil suffix:'jpeg' reader:self. |
|
199 | 195 |
|
398 | 196 |
"Modified: 1.2.1997 / 15:01:55 / cg" |
28 | 197 |
! ! |
198 |
||
522 | 199 |
!JPEGReader class methodsFor:'testing'! |
200 |
||
2768 | 201 |
isValidImageFile:aFilenameOrString |
522 | 202 |
"return true, if aFileName contains a JPG image. |
203 |
Only look at the files name here ..." |
|
204 |
||
2768 | 205 |
|suffix| |
206 |
||
207 |
suffix := aFilenameOrString asFilename suffix asLowercase. |
|
208 |
^ suffix = 'jpg' or:[suffix = 'jpeg']. |
|
522 | 209 |
|
210 |
"Created: 11.4.1997 / 16:26:25 / cg" |
|
2768 | 211 |
|
212 |
" |
|
213 |
self isValidImageFile:'xxx.jpg' |
|
214 |
" |
|
2 | 215 |
! ! |
199 | 216 |
|
528 | 217 |
!JPEGReader methodsFor:'accessing'! |
218 |
||
2971
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
219 |
app1SegmentHandler:aBlock |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
220 |
"set a handler block for app1 segment data (geolocation in exif format)" |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
221 |
|
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
222 |
app1SegmentHandler := aBlock |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
223 |
! |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
224 |
|
528 | 225 |
forceDitherMode:something |
226 |
"set the dither mode, to one of #none or #ordered" |
|
227 |
||
228 |
forceDitherMode := something. |
|
229 |
||
230 |
"Modified: 16.4.1997 / 20:34:59 / cg" |
|
231 |
! |
|
232 |
||
233 |
forceGrayscale:something |
|
234 |
"set the forceGrayscale mode; if true, grayScale images are |
|
235 |
returned, even if the input contains a color image." |
|
236 |
||
237 |
forceGrayscale := something. |
|
238 |
||
239 |
"Created: 16.4.1997 / 20:33:44 / cg" |
|
240 |
"Modified: 16.4.1997 / 20:34:29 / cg" |
|
241 |
! ! |
|
242 |
||
243 |
!JPEGReader methodsFor:'private'! |
|
244 |
||
2971
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
245 |
app1SegmentCallback |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
246 |
"return a callback function which invokes the app1SegmentHandlerBlock if defined. |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
247 |
This will be called to handle the exif segment, containing geolocation tags. |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
248 |
Return nil, if there is no handler blcok defined" |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
249 |
|
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
250 |
|cb| |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
251 |
|
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
252 |
app1SegmentHandler isNil ifTrue:[^ nil]. |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
253 |
|
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
254 |
cb := ExternalFunctionCallback new. |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
255 |
cb returnType:#bool argumentTypes:#(pointer). |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
256 |
cb generateClosure. |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
257 |
cb action:[:args | self fetchApp1SegmentData. true]. |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
258 |
^ cb code. 'can be passed to C'. |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
259 |
! |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
260 |
|
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
261 |
fetchApp1SegmentData |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
262 |
|byte1 byte2 count| |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
263 |
|
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
264 |
byte1 := self jpeg_getc. |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
265 |
byte2 := self jpeg_getc. |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
266 |
count := (byte1 bitShift:8) + byte2. "/ msb first |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
267 |
count := count - 2. "/ count itself is included |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
268 |
data := ByteArray new:count. |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
269 |
1 to: count do:[:i | |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
270 |
data at:i put:(self jpeg_getc). |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
271 |
]. |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
272 |
self halt. |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
273 |
app1SegmentHandler value:data. |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
274 |
! |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
275 |
|
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
276 |
jpeg_getc |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
277 |
%{ |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
278 |
OBJ j_d_s = __INST(jpeg_decompress_struct); |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
279 |
|
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
280 |
if (__isExternalBytesLike(j_d_s)) { |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
281 |
struct jpeg_decompress_struct *cinfoPtr; |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
282 |
int byte; |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
283 |
|
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
284 |
cinfoPtr = (struct jpeg_decompress_struct *)(__externalBytesAddress(j_d_s)); |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
285 |
|
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
286 |
byte = JPG_jpeg_getc (cinfoPtr); |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
287 |
RETURN( __MKSMALLINT(byte) ); |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
288 |
} |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
289 |
%}. |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
290 |
self primitiveFailed |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
291 |
! |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
292 |
|
528 | 293 |
create_jpeg_decompress_struct |
2971
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
294 |
|errMgrStructSize decompressStructSize fp errorOccurred app1SegmentCallbackFunction| |
528 | 295 |
|
296 |
fp := inStream filePointer. |
|
297 |
fp isNil ifTrue:[ |
|
1061
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
298 |
self error:'can only read from an external stream'. |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
299 |
^ self. |
528 | 300 |
]. |
301 |
||
2971
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
302 |
app1SegmentCallbackFunction := self app1SegmentCallback. |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
303 |
|
528 | 304 |
%{ |
2050 | 305 |
errMgrStructSize = __mkSmallInteger(sizeof(struct my_error_mgr)); |
306 |
decompressStructSize = __mkSmallInteger(sizeof(struct jpeg_decompress_struct)); |
|
528 | 307 |
%}. |
308 |
||
532 | 309 |
jpeg_error_mgr_struct := ExternalBytes unprotectedNew:errMgrStructSize. |
310 |
jpeg_decompress_struct := ExternalBytes unprotectedNew:decompressStructSize. |
|
534 | 311 |
errorOccurred := false. |
528 | 312 |
|
1698 | 313 |
%{ /* STACK: 400000 */ |
528 | 314 |
struct jpeg_decompress_struct *cinfoPtr; |
534 | 315 |
struct my_error_mgr *jerrPtr; |
528 | 316 |
OBJ j_e_m = __INST(jpeg_error_mgr_struct); |
317 |
OBJ j_d_s = __INST(jpeg_decompress_struct); |
|
318 |
FILE *f = __FILEVal(fp); |
|
319 |
||
1747
90a5fcae4b4b
also handle subclasses of externalBytes
Claus Gittinger <cg@exept.de>
parents:
1745
diff
changeset
|
320 |
if (__isExternalBytesLike(j_d_s) |
90a5fcae4b4b
also handle subclasses of externalBytes
Claus Gittinger <cg@exept.de>
parents:
1745
diff
changeset
|
321 |
&& __isExternalBytesLike(j_e_m)) { |
1061
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
322 |
cinfoPtr = (struct jpeg_decompress_struct *)(__externalBytesAddress(j_d_s)); |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
323 |
jerrPtr = (struct my_error_mgr *)(__externalBytesAddress(j_e_m)); |
528 | 324 |
|
2282 | 325 |
/* |
1061
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
326 |
* Initialize the JPEG decompression object with default error handling. |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
327 |
*/ |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
328 |
cinfoPtr->err = jpeg_std_error(jerrPtr); |
528 | 329 |
|
534 | 330 |
/* |
331 |
* prepare to handle errors smoothly ... |
|
332 |
*/ |
|
333 |
jerrPtr->pub.error_exit = my_error_exit; |
|
334 |
if (setjmp(jerrPtr->setjmp_buffer)) { |
|
2282 | 335 |
/* |
534 | 336 |
* error occurred ... |
337 |
*/ |
|
338 |
jpeg_destroy_decompress(cinfoPtr); |
|
339 |
RETURN (false); |
|
340 |
} |
|
341 |
||
1061
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
342 |
/* |
1747
90a5fcae4b4b
also handle subclasses of externalBytes
Claus Gittinger <cg@exept.de>
parents:
1745
diff
changeset
|
343 |
* use my message print function |
90a5fcae4b4b
also handle subclasses of externalBytes
Claus Gittinger <cg@exept.de>
parents:
1745
diff
changeset
|
344 |
*/ |
1061
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
345 |
jerrPtr->pub.output_message = my_output_message; |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
346 |
|
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
347 |
jpeg_create_decompress(cinfoPtr); |
528 | 348 |
#if 0 |
2282 | 349 |
/* |
1061
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
350 |
* Insert custom COM marker processor. |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
351 |
*/ |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
352 |
jpeg_set_marker_processor(cinfoPtr, JPEG_COM, COM_handler); |
528 | 353 |
#endif |
2971
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
354 |
if (app1SegmentCallbackFunction != nil) { |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
355 |
jpeg_marker_parser_method cb = NULL; |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
356 |
|
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
357 |
if (__isExternalFunction(app1SegmentCallbackFunction)) { |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
358 |
cb = (jpeg_marker_parser_method)__externalFunctionVal(app1SegmentCallbackFunction); |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
359 |
} else if (__isExternalAddress(app1SegmentCallbackFunction)) { |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
360 |
cb = (jpeg_marker_parser_method)__externalAddressVal(app1SegmentCallbackFunction); |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
361 |
} else { |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
362 |
/* ignore, but should report an error... */ |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
363 |
} |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
364 |
jpeg_set_marker_processor(cinfoPtr, JPEG_APP0+1, cb); |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
365 |
} |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
366 |
|
1061
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
367 |
cinfoPtr->err->trace_level = 0; |
528 | 368 |
|
369 |
#if 0 |
|
1061
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
370 |
/* colors setting */ |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
371 |
cinfoPtr->desired_number_of_colors = val; |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
372 |
cinfoPtr->quantize_colors = TRUE; |
528 | 373 |
#endif |
374 |
#if 0 |
|
1061
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
375 |
/* dct setting */ |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
376 |
cinfoPtr->dct_method = JDCT_ISLOW; |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
377 |
or: cinfoPtr->dct_method = JDCT_IFAST; |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
378 |
or: cinfoPtr->dct_method = JDCT_FLOAT; |
528 | 379 |
#endif |
380 |
||
1061
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
381 |
/* dither setting */ |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
382 |
cinfoPtr->dither_mode = JDITHER_FS; |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
383 |
if (__INST(forceDitherMode) == @symbol(none)) { |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
384 |
cinfoPtr->dither_mode = JDITHER_NONE; |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
385 |
} else { |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
386 |
if (__INST(forceDitherMode) == @symbol(ordered)) { |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
387 |
cinfoPtr->dither_mode = JDITHER_ORDERED; |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
388 |
} |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
389 |
} |
528 | 390 |
|
391 |
#if 0 |
|
1061
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
392 |
/* fast setting */ |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
393 |
cinfoPtr->two_pass_quantize = FALSE; |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
394 |
cinfoPtr->dither_mode = JDITHER_ORDERED; |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
395 |
cinfoPtr->desired_number_of_colors = 216; |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
396 |
cinfoPtr->dct_method = JDCT_FASTEST; |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
397 |
cinfoPtr->do_fancy_upsampling = FALSE; |
528 | 398 |
#endif |
399 |
||
1061
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
400 |
if (__INST(forceGrayscale) == true) { |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
401 |
/* grayscale setting */ |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
402 |
cinfoPtr->out_color_space = JCS_GRAYSCALE; |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
403 |
} |
528 | 404 |
|
405 |
#if 0 |
|
1061
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
406 |
/* maxmemory setting */ |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
407 |
cinfoPtr->mem->max_memory_to_use = lval * 1000L; |
528 | 408 |
#endif |
534 | 409 |
|
528 | 410 |
#if 0 |
1061
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
411 |
/* nosmooth setting */ |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
412 |
cinfoPtr->do_fancy_upsampling = FALSE; |
528 | 413 |
#endif |
534 | 414 |
|
528 | 415 |
#if 0 |
1061
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
416 |
/* onepass setting */ |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
417 |
cinfoPtr->two_pass_quantize = FALSE; |
528 | 418 |
#endif |
419 |
||
1061
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
420 |
/* Specify data source for decompression */ |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
421 |
jpeg_stdio_src(cinfoPtr, f); |
528 | 422 |
|
1061
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
423 |
/* Read file header, set default decompression parameters */ |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
424 |
(void) jpeg_read_header(cinfoPtr, TRUE); |
528 | 425 |
|
1061
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
426 |
/* Calculate output image dimensions so we can allocate space */ |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
427 |
jpeg_calc_output_dimensions(cinfoPtr); |
528 | 428 |
|
2050 | 429 |
__INST(width) = __mkSmallInteger(cinfoPtr->output_width); |
430 |
__INST(height) = __mkSmallInteger(cinfoPtr->output_height); |
|
431 |
__INST(colorComponents) = __mkSmallInteger(cinfoPtr->output_components); |
|
528 | 432 |
|
433 |
#if 0 |
|
1061
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
434 |
/* could now set additional values in cinfo |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
435 |
* (colormap) |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
436 |
*/ |
528 | 437 |
#endif |
534 | 438 |
|
528 | 439 |
} |
534 | 440 |
%}. |
441 |
^ true |
|
528 | 442 |
! |
443 |
||
444 |
decompressChunkInto:aByteArray startingAt:index |
|
1698 | 445 |
%{ /* STACK: 400000 */ |
528 | 446 |
struct jpeg_decompress_struct *cinfoPtr; |
534 | 447 |
struct my_error_mgr *jerrPtr; |
1061
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
448 |
char *rowPtr = NULL; |
528 | 449 |
OBJ j_d_s = __INST(jpeg_decompress_struct); |
534 | 450 |
OBJ j_e_m = __INST(jpeg_error_mgr_struct); |
528 | 451 |
int num_scanlines; |
452 |
char *rowPointers[4]; |
|
453 |
||
1061
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
454 |
|
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
455 |
if (__isByteArray(aByteArray)) { |
1747
90a5fcae4b4b
also handle subclasses of externalBytes
Claus Gittinger <cg@exept.de>
parents:
1745
diff
changeset
|
456 |
rowPtr = (char *)(__ByteArrayInstPtr(aByteArray)->ba_element); |
90a5fcae4b4b
also handle subclasses of externalBytes
Claus Gittinger <cg@exept.de>
parents:
1745
diff
changeset
|
457 |
} else if (__isExternalBytesLike(aByteArray)) { |
90a5fcae4b4b
also handle subclasses of externalBytes
Claus Gittinger <cg@exept.de>
parents:
1745
diff
changeset
|
458 |
rowPtr = __externalBytesAddress(aByteArray); |
1061
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
459 |
} |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
460 |
|
1747
90a5fcae4b4b
also handle subclasses of externalBytes
Claus Gittinger <cg@exept.de>
parents:
1745
diff
changeset
|
461 |
if (__isExternalBytesLike(j_d_s) |
1061
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
462 |
&& (rowPtr != NULL) |
1747
90a5fcae4b4b
also handle subclasses of externalBytes
Claus Gittinger <cg@exept.de>
parents:
1745
diff
changeset
|
463 |
&& __isExternalBytesLike(j_e_m)) { |
1061
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
464 |
cinfoPtr = (struct jpeg_decompress_struct *)(__externalBytesAddress(j_d_s)); |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
465 |
jerrPtr = (struct my_error_mgr *)(__externalBytesAddress(j_e_m)); |
528 | 466 |
|
1061
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
467 |
rowPtr += __intVal(index) - 1; |
528 | 468 |
|
1061
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
469 |
rowPointers[0] = rowPtr; |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
470 |
rowPointers[1] = NULL; |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
471 |
rowPointers[2] = NULL; |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
472 |
rowPointers[3] = NULL; |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
473 |
|
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
474 |
if (cinfoPtr->output_scanline < cinfoPtr->output_height) { |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
475 |
if (setjmp(jerrPtr->setjmp_buffer)) { |
2282 | 476 |
/* |
1061
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
477 |
* error occurred ... |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
478 |
*/ |
534 | 479 |
jpeg_destroy_decompress(cinfoPtr); |
2050 | 480 |
RETURN (__mkSmallInteger(-1)); |
534 | 481 |
} |
2282 | 482 |
num_scanlines = jpeg_read_scanlines(cinfoPtr, |
1061
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
483 |
rowPointers, |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
484 |
1); |
2050 | 485 |
RETURN (__mkSmallInteger(num_scanlines)); |
1061
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
486 |
} |
2050 | 487 |
RETURN (__mkSmallInteger(0)); |
528 | 488 |
} |
489 |
%}. |
|
1061
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
490 |
self halt:'bad arguments'. |
528 | 491 |
! |
492 |
||
493 |
finish_decompress |
|
1698 | 494 |
%{ /* STACK: 400000 */ |
536 | 495 |
struct jpeg_decompress_struct *cinfoPtr; |
534 | 496 |
struct my_error_mgr *jerrPtr; |
528 | 497 |
OBJ j_d_s = __INST(jpeg_decompress_struct); |
534 | 498 |
OBJ j_e_m = __INST(jpeg_error_mgr_struct); |
528 | 499 |
|
1747
90a5fcae4b4b
also handle subclasses of externalBytes
Claus Gittinger <cg@exept.de>
parents:
1745
diff
changeset
|
500 |
if (__isExternalBytesLike(j_d_s) |
90a5fcae4b4b
also handle subclasses of externalBytes
Claus Gittinger <cg@exept.de>
parents:
1745
diff
changeset
|
501 |
&& __isExternalBytesLike(j_e_m)) { |
1061
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
502 |
cinfoPtr = (struct jpeg_decompress_struct *)(__externalBytesAddress(j_d_s)); |
534 | 503 |
jerrPtr = (struct my_error_mgr *)(__externalBytesAddress(j_e_m)); |
528 | 504 |
|
534 | 505 |
if (setjmp(jerrPtr->setjmp_buffer)) { |
506 |
jpeg_destroy_decompress(cinfoPtr); |
|
507 |
RETURN (false); |
|
508 |
} |
|
509 |
||
1061
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
510 |
/* finish decompressor */ |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
511 |
(void) jpeg_finish_decompress(cinfoPtr); |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
512 |
(void) jpeg_destroy_decompress(cinfoPtr); |
534 | 513 |
RETURN (true); |
528 | 514 |
} |
515 |
%} |
|
516 |
! |
|
517 |
||
535 | 518 |
get_error_message |
519 |
%{ |
|
536 | 520 |
struct jpeg_decompress_struct *cinfoPtr; |
535 | 521 |
OBJ j_d_s = __INST(jpeg_decompress_struct); |
522 |
char buffer[JMSG_LENGTH_MAX+1]; |
|
523 |
||
1747
90a5fcae4b4b
also handle subclasses of externalBytes
Claus Gittinger <cg@exept.de>
parents:
1745
diff
changeset
|
524 |
if (__isExternalBytesLike(j_d_s)) { |
536 | 525 |
cinfoPtr = (struct jpeg_decompress_struct *)(__externalBytesAddress(j_d_s)); |
535 | 526 |
|
527 |
(*cinfoPtr->err->format_message) (cinfoPtr, buffer); |
|
528 |
buffer[JMSG_LENGTH_MAX] = '\0'; |
|
529 |
RETURN ( __MKSTRING(buffer)); |
|
530 |
} |
|
531 |
%}. |
|
532 |
^ nil |
|
533 |
! |
|
534 |
||
528 | 535 |
start_decompress |
1698 | 536 |
%{ /* STACK: 400000 */ |
536 | 537 |
struct jpeg_decompress_struct *cinfoPtr; |
534 | 538 |
struct my_error_mgr *jerrPtr; |
528 | 539 |
OBJ j_d_s = __INST(jpeg_decompress_struct); |
534 | 540 |
OBJ j_e_m = __INST(jpeg_error_mgr_struct); |
528 | 541 |
|
1747
90a5fcae4b4b
also handle subclasses of externalBytes
Claus Gittinger <cg@exept.de>
parents:
1745
diff
changeset
|
542 |
if (__isExternalBytesLike(j_d_s) |
90a5fcae4b4b
also handle subclasses of externalBytes
Claus Gittinger <cg@exept.de>
parents:
1745
diff
changeset
|
543 |
&& __isExternalBytesLike(j_e_m)) { |
1061
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
544 |
cinfoPtr = (struct jpeg_decompress_struct *)(__externalBytesAddress(j_d_s)); |
534 | 545 |
jerrPtr = (struct my_error_mgr *)(__externalBytesAddress(j_e_m)); |
546 |
||
547 |
if (setjmp(jerrPtr->setjmp_buffer)) { |
|
548 |
jpeg_destroy_decompress(cinfoPtr); |
|
549 |
RETURN (false); |
|
550 |
} |
|
528 | 551 |
|
1061
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
552 |
/* Start decompressor */ |
e487ecc3d506
define my own error printing function (req'd to avoid bad
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
553 |
(void) jpeg_start_decompress(cinfoPtr); |
534 | 554 |
RETURN (true); |
528 | 555 |
} |
556 |
%} |
|
557 |
! ! |
|
558 |
||
1805 | 559 |
!JPEGReader methodsFor:'reading'! |
528 | 560 |
|
561 |
fromStream:aStream |
|
562 |
"read a JPG image from a stream" |
|
563 |
||
951
de8417214dfd
read from an internal stream (save to tempfile, then read)
Claus Gittinger <cg@exept.de>
parents:
895
diff
changeset
|
564 |
|dataIdx bytesPerRow returnCode pos1 ok tmpFile s| |
528 | 565 |
|
895
ebac67edf08e
check for inStream being an external stream.
Claus Gittinger <cg@exept.de>
parents:
669
diff
changeset
|
566 |
aStream isExternalStream ifFalse:[ |
2971
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
567 |
"/ libJpeg can only handle real OS-streams |
951
de8417214dfd
read from an internal stream (save to tempfile, then read)
Claus Gittinger <cg@exept.de>
parents:
895
diff
changeset
|
568 |
|
2971
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
569 |
tmpFile := Filename newTemporary. |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
570 |
[ |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
571 |
s := tmpFile writeStream binary. |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
572 |
s nextPutAll:aStream contents. |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
573 |
s close. |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
574 |
s := tmpFile readStream binary. |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
575 |
^ self fromStream:s. |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
576 |
] ensure:[ |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
577 |
s notNil ifTrue:[s close]. |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
578 |
tmpFile delete. |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
579 |
]. |
2282 | 580 |
|
2971
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
581 |
"/ 'JPEGReader [info]: can only read from real streams' infoPrintCR. |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
582 |
"/ ^ nil |
895
ebac67edf08e
check for inStream being an external stream.
Claus Gittinger <cg@exept.de>
parents:
669
diff
changeset
|
583 |
]. |
ebac67edf08e
check for inStream being an external stream.
Claus Gittinger <cg@exept.de>
parents:
669
diff
changeset
|
584 |
|
528 | 585 |
inStream := aStream. |
669
d38a796ad10b
care for files with 128 byte header before actual image
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
586 |
pos1 := inStream position. |
528 | 587 |
|
895
ebac67edf08e
check for inStream being an external stream.
Claus Gittinger <cg@exept.de>
parents:
669
diff
changeset
|
588 |
|
535 | 589 |
(self create_jpeg_decompress_struct not |
590 |
or:[self start_decompress not]) ifTrue:[ |
|
2971
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
591 |
ok := false. |
669
d38a796ad10b
care for files with 128 byte header before actual image
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
592 |
|
2971
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
593 |
"/ if there was no SOI marker, |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
594 |
"/ try again, skipping first 128 bytes |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
595 |
"/ (seems to be generated by some jpg writers) |
669
d38a796ad10b
care for files with 128 byte header before actual image
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
596 |
|
2971
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
597 |
inStream position:pos1. |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
598 |
((inStream nextByte ~~ 16rFF) |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
599 |
or:[inStream nextByte ~~ 16rD8]) ifTrue:[ |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
600 |
inStream position:pos1 + 128. |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
601 |
((inStream nextByte == 16rFF) |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
602 |
and:[inStream nextByte == 16rD8]) ifTrue:[ |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
603 |
inStream position:pos1 + 128. |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
604 |
ok := self create_jpeg_decompress_struct |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
605 |
and:[self start_decompress] |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
606 |
]. |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
607 |
]. |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
608 |
ok ifFalse:[ |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
609 |
'JPEGReader [info]: ' infoPrint. self get_error_message infoPrintCR. |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
610 |
^ nil |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
611 |
] |
535 | 612 |
]. |
528 | 613 |
|
614 |
data := ByteArray uninitializedNew:(width * height * colorComponents). |
|
615 |
dataIdx := 1. |
|
616 |
bytesPerRow := colorComponents * width. |
|
617 |
||
534 | 618 |
[(returnCode := self decompressChunkInto:data startingAt:dataIdx) > 0] whileTrue:[ |
2971
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
619 |
"/ got a row in the buffer ... |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
620 |
dataIdx := dataIdx + bytesPerRow |
2282 | 621 |
]. |
534 | 622 |
returnCode < 0 ifTrue:[ |
2971
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
623 |
'JPEGReader [info]: ' infoPrint. self get_error_message infoPrintCR. |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
624 |
^ nil |
534 | 625 |
]. |
528 | 626 |
|
535 | 627 |
(self finish_decompress) ifFalse:[ |
2971
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
628 |
'JPEGReader [info]: ' infoPrint. self get_error_message infoPrintCR. |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
629 |
^ nil |
535 | 630 |
]. |
528 | 631 |
|
632 |
colorComponents == 3 ifTrue:[ |
|
2971
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
633 |
photometric := #rgb. |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
634 |
samplesPerPixel := 3. |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
635 |
bitsPerSample := #(8 8 8). |
528 | 636 |
] ifFalse:[ |
2971
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
637 |
photometric := #blackIs0. |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
638 |
samplesPerPixel := 1. |
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
639 |
bitsPerSample := #(8). |
528 | 640 |
]. |
641 |
||
642 |
" |
|
2768 | 643 |
JPEGReader fromFile:'../../support/libjpeg-7/testimg.jpg' |
528 | 644 |
" |
645 |
" |
|
646 |
|stream reader| |
|
647 |
||
2768 | 648 |
stream := '../../support/libjpeg-7/testimg.jpg' asFilename readStream. |
528 | 649 |
reader := JPEGReader new. |
650 |
reader forceGrayscale:true. |
|
651 |
reader forceDitherMode:#ordered. |
|
652 |
reader fromStream:stream. |
|
653 |
^ reader image |
|
654 |
" |
|
655 |
||
895
ebac67edf08e
check for inStream being an external stream.
Claus Gittinger <cg@exept.de>
parents:
669
diff
changeset
|
656 |
"Modified: / 4.4.1998 / 18:48:46 / cg" |
528 | 657 |
! ! |
658 |
||
199 | 659 |
!JPEGReader class methodsFor:'documentation'! |
660 |
||
661 |
version |
|
2971
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
662 |
^ '$Header: /cvs/stx/stx/libview2/JPEGReader.st,v 1.51 2011-12-12 20:19:08 cg Exp $' |
2768 | 663 |
! |
664 |
||
665 |
version_CVS |
|
2971
07bd4e98036e
hooks to extract Exif (Geolocation) data.
Claus Gittinger <cg@exept.de>
parents:
2768
diff
changeset
|
666 |
^ '$Header: /cvs/stx/stx/libview2/JPEGReader.st,v 1.51 2011-12-12 20:19:08 cg Exp $' |
199 | 667 |
! ! |
1745
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1698
diff
changeset
|
668 |
|
199 | 669 |
JPEGReader initialize! |