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