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