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