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