Skip to content

Commit 80a0596

Browse files
committed
aperio: use main image ICC profile for thumbnail if profile names match
The thumbnail's TIFF directory doesn't have an ICC profile, but both it and level 0's directory have properties including an ICC profile name. If the two profile names exist and are equal, use the main image's ICC profile for the thumbnail. Fixes: openslide#637 Signed-off-by: Benjamin Gilbert <[email protected]>
1 parent fe7609b commit 80a0596

File tree

6 files changed

+44
-11
lines changed

6 files changed

+44
-11
lines changed

src/openslide-vendor-aperio.c

+29-11
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ static bool add_properties(openslide_t *osr, TIFF *tiff, GError **err) {
349349
// true does not necessarily imply an image was added
350350
static bool add_associated_image(openslide_t *osr,
351351
const char *name_if_available,
352+
tdir_t *icc_dir_if_available,
352353
struct _openslide_tiffcache *tc,
353354
TIFF *tiff,
354355
GError **err) {
@@ -384,7 +385,7 @@ static bool add_associated_image(openslide_t *osr,
384385

385386
return _openslide_tiff_add_associated_image(osr, name, tc,
386387
TIFFCurrentDirectory(tiff),
387-
NULL, err);
388+
icc_dir_if_available, err);
388389
}
389390

390391
static void propagate_missing_tile(void *key, void *value G_GNUC_UNUSED,
@@ -424,6 +425,12 @@ static bool aperio_open(openslide_t *osr,
424425
return false;
425426
}
426427

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+
427434
/*
428435
* http://www.aperio.com/documents/api/Aperio_Digital_Slides_and_Third-party_data_interchange.pdf
429436
* page 14:
@@ -523,8 +530,27 @@ static bool aperio_open(openslide_t *osr,
523530
}
524531
} else {
525532
// 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)) {
528554
return false;
529555
}
530556
//g_debug("associated image: %d", dir);
@@ -539,14 +565,6 @@ static bool aperio_open(openslide_t *osr,
539565
level_array->pdata[i + 1]);
540566
}
541567

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-
550568
// get icc profile size, if present
551569
struct level *base_level = level_array->pdata[0];
552570
if (!_openslide_tiff_get_icc_profile_size(ct.tiff, base_level->tiffl.dir,
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# thumbnail ImageDescription is zero-length string
2+
base: Aperio/CMU-1.svs
3+
slide: CMU-1.svs
4+
success: true
5+
vendor: aperio
6+
properties:
7+
openslide.associated.thumbnail.icc-size: ""
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# thumbnail ICC Profile name doesn't match main image
2+
base: Aperio/CMU-1.svs
3+
slide: CMU-1.svs
4+
success: true
5+
vendor: aperio
6+
properties:
7+
openslide.associated.thumbnail.icc-size: ""

test/cases/aperio/config.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ success: true
44
vendor: aperio
55
primary: true
66
properties:
7+
openslide.associated.thumbnail.icc-size: "141992"
78
openslide.icc-size: "141992"
89
openslide.quickhash-1: 30f1a38031fc0e21d81f9d01435ac4af848f6fe2bbf8f7768184336ee5d7e796
910
openslide.vendor: aperio

0 commit comments

Comments
 (0)