20
20
#include < OpenImageIO/imagebufalgo.h>
21
21
#include < OpenImageIO/tiffutils.h>
22
22
23
- #include " jpeg_memory_src.h"
23
+ // #include "jpeg_memory_src.h"
24
24
#include " psd_pvt.h"
25
25
26
26
OIIO_PLUGIN_NAMESPACE_BEGIN
@@ -265,13 +265,6 @@ class PSDInput final : public ImageInput {
265
265
266
266
// Load thumbnail resource, used for resources 1033 and 1036
267
267
bool load_resource_thumbnail (uint32_t length, bool isBGR);
268
- // For thumbnail loading
269
- struct thumbnail_error_mgr {
270
- jpeg_error_mgr pub;
271
- jmp_buf setjmp_buffer;
272
- };
273
- METHODDEF (void )
274
- thumbnail_error_exit (j_common_ptr cinfo);
275
268
276
269
// Layers
277
270
bool load_layers ();
@@ -1270,9 +1263,6 @@ PSDInput::load_resource_thumbnail(uint32_t length, bool isBGR)
1270
1263
uint32_t compressed_size;
1271
1264
uint16_t bpp;
1272
1265
uint16_t planes;
1273
- int stride;
1274
- jpeg_decompress_struct cinfo;
1275
- thumbnail_error_mgr jerr;
1276
1266
uint32_t jpeg_length = length - 28 ;
1277
1267
1278
1268
bool ok = read_bige<uint32_t >(format) && read_bige<uint32_t >(width)
@@ -1312,40 +1302,13 @@ PSDInput::load_resource_thumbnail(uint32_t length, bool isBGR)
1312
1302
return false ;
1313
1303
}
1314
1304
1315
- cinfo.err = jpeg_std_error (&jerr.pub );
1316
- jerr.pub .error_exit = thumbnail_error_exit;
1317
- if (setjmp (jerr.setjmp_buffer )) {
1318
- jpeg_destroy_decompress (&cinfo);
1319
- errorfmt (" [Image Resource] [JPEG Thumbnail] libjpeg error" );
1320
- return false ;
1321
- }
1322
1305
std::string jpeg_data (jpeg_length, ' \0 ' );
1323
1306
if (!ioread (&jpeg_data[0 ], jpeg_length))
1324
1307
return false ;
1325
1308
1326
- jpeg_create_decompress (&cinfo);
1327
- jpeg_memory_src (&cinfo, (unsigned char *)&jpeg_data[0 ], jpeg_length);
1328
- jpeg_read_header (&cinfo, TRUE );
1329
- jpeg_start_decompress (&cinfo);
1330
- stride = cinfo.output_width * cinfo.output_components ;
1331
- ImageSpec thumbspec (cinfo.output_width , cinfo.output_height , 3 , TypeUInt8);
1332
- m_thumbnail.reset (thumbspec);
1333
- // jpeg_destroy_decompress will deallocate this
1334
- JSAMPLE** buffer = (*cinfo.mem ->alloc_sarray )((j_common_ptr)&cinfo,
1335
- JPOOL_IMAGE, stride, 1 );
1336
- while (cinfo.output_scanline < cinfo.output_height ) {
1337
- if (jpeg_read_scanlines (&cinfo, buffer, 1 ) != 1 ) {
1338
- jpeg_finish_decompress (&cinfo);
1339
- jpeg_destroy_decompress (&cinfo);
1340
- errorfmt (" [Image Resource] [JPEG Thumbnail] libjpeg error" );
1341
- return false ;
1342
- }
1343
- m_thumbnail.get_pixels (ROI (0 , width, cinfo.output_scanline ,
1344
- cinfo.output_scanline + 1 , 0 , 1 , 0 , 3 ),
1345
- TypeUInt8, buffer[0 ]);
1346
- }
1347
- jpeg_finish_decompress (&cinfo);
1348
- jpeg_destroy_decompress (&cinfo);
1309
+ Filesystem::IOMemReader thumbblob (jpeg_data.data (), jpeg_length);
1310
+ m_thumbnail = ImageBuf (" thumbnail.jpg" , 0 , 0 , nullptr , nullptr , &thumbblob);
1311
+ m_thumbnail.read (0 , 0 , true );
1349
1312
1350
1313
// Set these attributes for the merged composite only (subimage 0)
1351
1314
composite_attribute (" thumbnail_width" , (int )width);
@@ -1358,15 +1321,6 @@ PSDInput::load_resource_thumbnail(uint32_t length, bool isBGR)
1358
1321
1359
1322
1360
1323
1361
- void
1362
- PSDInput::thumbnail_error_exit (j_common_ptr cinfo)
1363
- {
1364
- thumbnail_error_mgr* mgr = (thumbnail_error_mgr*)cinfo->err ;
1365
- longjmp (mgr->setjmp_buffer , 1 );
1366
- }
1367
-
1368
-
1369
-
1370
1324
bool
1371
1325
PSDInput::load_layers ()
1372
1326
{
0 commit comments