@@ -140,20 +140,17 @@ JPEGImageIO::CanReadFile(const char * file)
140
140
jerr.pub .error_exit = itk_jpeg_error_exit;
141
141
// for any output message call itk_jpeg_output_message
142
142
jerr.pub .output_message = itk_jpeg_output_message;
143
- // set the jump point, if there is a jpeg error or warning
144
- // this will evaluate to true
143
+ // set the jump point
145
144
if (setjmp (jerr.setjmp_buffer ))
146
145
{
147
- // clean up
148
146
jpeg_destroy_decompress (&cinfo);
149
- // this is not a valid jpeg file
150
147
return false ;
151
148
}
152
- /* Now we can initialize the JPEG decompression object. */
149
+ // initialize the JPEG decompression object
153
150
jpeg_create_decompress (&cinfo);
154
- /* Step 2: specify data source (eg, a file) */
151
+ // specify data source
155
152
jpeg_stdio_src (&cinfo, JPEGfp.m_FilePointer );
156
- /* Step 3: read file parameters with jpeg_read_header() */
153
+ // read file parameters
157
154
jpeg_read_header (&cinfo, TRUE );
158
155
159
156
// if no errors have occurred yet, then it must be jpeg
@@ -191,10 +188,8 @@ JPEGImageIO::Read(void * buffer)
191
188
jerr.pub .output_message = itk_jpeg_output_message;
192
189
if (setjmp (jerr.setjmp_buffer ))
193
190
{
194
- // clean up
195
191
jpeg_destroy_decompress (&cinfo);
196
192
itkExceptionMacro (" libjpeg could not read file: " << this ->GetFileName ());
197
- // this is not a valid jpeg file
198
193
}
199
194
200
195
jpeg_create_decompress (&cinfo);
@@ -205,8 +200,8 @@ JPEGImageIO::Read(void * buffer)
205
200
// read the header
206
201
jpeg_read_header (&cinfo, TRUE );
207
202
208
- // jpeg_calc_output_dimensions was used in ReadImageInformation,
209
- // has to be used here too to ensure same parameters
203
+ // jpeg_calc_output_dimensions used in ReadImageInformation,
204
+ // so has to be used here too
210
205
jpeg_calc_output_dimensions (&cinfo);
211
206
212
207
// prepare to read the bulk data
@@ -251,7 +246,7 @@ JPEGImageIO::JPEGImageIO()
251
246
#if BITS_IN_JSAMPLE == 8
252
247
m_ComponentType = IOComponentEnum::UCHAR;
253
248
#else
254
- # error
249
+ # error "JPEG files with more than 8 bits per sample are not supported"
255
250
#endif
256
251
m_UseCompression = false ;
257
252
this ->Self ::SetQuality (95 );
@@ -308,9 +303,7 @@ JPEGImageIO::ReadImageInformation()
308
303
jerr.pub .error_exit = itk_jpeg_error_exit;
309
304
if (setjmp (jerr.setjmp_buffer ))
310
305
{
311
- // clean up
312
306
jpeg_destroy_decompress (&cinfo);
313
- // this is not a valid jpeg file
314
307
itkExceptionMacro (" Error JPEGImageIO could not open file: " << this ->GetFileName ());
315
308
}
316
309
jpeg_create_decompress (&cinfo);
@@ -321,11 +314,10 @@ JPEGImageIO::ReadImageInformation()
321
314
// read the header
322
315
jpeg_read_header (&cinfo, TRUE );
323
316
324
- // calculate cinfo.output_components
317
+ // jpeg_calc_output_dimensions to calculate cinfo.output_components
325
318
jpeg_calc_output_dimensions (&cinfo);
326
- if ((static_cast <unsigned long long >(cinfo.output_width ) * cinfo.output_height * cinfo.output_components ) >
327
- 0xffffffff &&
328
- sizeof (size_t ) < 8 )
319
+ if (sizeof (void *) < 8 && (static_cast <unsigned long long >(cinfo.output_width ) * cinfo.output_height *
320
+ cinfo.output_components ) > 0xffffffff )
329
321
{
330
322
jpeg_destroy_decompress (&cinfo);
331
323
itkExceptionMacro (<< " JPEG image is too big " << this ->GetFileName ());
0 commit comments