@@ -349,6 +349,7 @@ static bool add_properties(openslide_t *osr, TIFF *tiff, GError **err) {
349
349
// true does not necessarily imply an image was added
350
350
static bool add_associated_image (openslide_t * osr ,
351
351
const char * name_if_available ,
352
+ tdir_t * icc_dir_if_available ,
352
353
struct _openslide_tiffcache * tc ,
353
354
TIFF * tiff ,
354
355
GError * * err ) {
@@ -384,7 +385,7 @@ static bool add_associated_image(openslide_t *osr,
384
385
385
386
return _openslide_tiff_add_associated_image (osr , name , tc ,
386
387
TIFFCurrentDirectory (tiff ),
387
- NULL , err );
388
+ icc_dir_if_available , err );
388
389
}
389
390
390
391
static void propagate_missing_tile (void * key , void * value G_GNUC_UNUSED ,
@@ -424,6 +425,12 @@ static bool aperio_open(openslide_t *osr,
424
425
return false;
425
426
}
426
427
428
+ // add properties early, since we'll need them for the thumbnail ICC
429
+ // profile
430
+ if (!add_properties (osr , ct .tiff , err )) {
431
+ return false;
432
+ }
433
+
427
434
/*
428
435
* http://www.aperio.com/documents/api/Aperio_Digital_Slides_and_Third-party_data_interchange.pdf
429
436
* page 14:
@@ -523,8 +530,27 @@ static bool aperio_open(openslide_t *osr,
523
530
}
524
531
} else {
525
532
// associated image
526
- const char * name = (dir == 1 ) ? "thumbnail" : NULL ;
527
- if (!add_associated_image (osr , name , tc , ct .tiff , err )) {
533
+ const char * name = NULL ;
534
+ g_autofree tdir_t * icc_dir = NULL ;
535
+ if (dir == 1 ) {
536
+ name = "thumbnail" ;
537
+
538
+ g_autoptr (GHashTable ) thumbnail_props = read_properties (ct .tiff , err );
539
+ if (!thumbnail_props ) {
540
+ g_prefix_error (err , "Reading thumbnail properties: " );
541
+ return false;
542
+ }
543
+ const char * main_icc_name =
544
+ g_hash_table_lookup (osr -> properties , "aperio.ICC Profile" );
545
+ const char * thumbnail_icc_name =
546
+ g_hash_table_lookup (thumbnail_props , "ICC Profile" );
547
+ if (main_icc_name && thumbnail_icc_name &&
548
+ g_str_equal (main_icc_name , thumbnail_icc_name )) {
549
+ // use ICC profile from first directory
550
+ icc_dir = g_new0 (tdir_t , 1 );
551
+ }
552
+ }
553
+ if (!add_associated_image (osr , name , icc_dir , tc , ct .tiff , err )) {
528
554
return false;
529
555
}
530
556
//g_debug("associated image: %d", dir);
@@ -539,14 +565,6 @@ static bool aperio_open(openslide_t *osr,
539
565
level_array -> pdata [i + 1 ]);
540
566
}
541
567
542
- // read properties
543
- if (!_openslide_tiff_set_dir (ct .tiff , 0 , err )) {
544
- return false;
545
- }
546
- if (!add_properties (osr , ct .tiff , err )) {
547
- return false;
548
- }
549
-
550
568
// get icc profile size, if present
551
569
struct level * base_level = level_array -> pdata [0 ];
552
570
if (!_openslide_tiff_get_icc_profile_size (ct .tiff , base_level -> tiffl .dir ,
0 commit comments