Skip to content

Commit

Permalink
Merge pull request #1043 from girder/harden-iccprofileinfo
Browse files Browse the repository at this point in the history
Harden showing ICC profile information in girder
  • Loading branch information
manthey authored Jan 30, 2023
2 parents 8f45539 + 73d0a20 commit 1b34e47
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## 1.20.0

### Features
- ICC color profile support ([#1037](../../pull/1037))
- ICC color profile support ([#1037](../../pull/1037), [#1043](../../pull/1043))

### Improvements
- Speed up generating tiles for some multi source files ([#1035](../../pull/1035))
Expand Down
5 changes: 1 addition & 4 deletions girder/girder_large_image/models/image_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import json
import pickle

import PIL.ImageCms
import pymongo
from girder_jobs.constants import JobStatus
from girder_jobs.models.job import Job
Expand Down Expand Up @@ -248,9 +247,7 @@ def getInternalMetadata(self, item, **kwargs):
tileSource = self._loadTileSource(item, **kwargs)
result = tileSource.getInternalMetadata() or {}
if tileSource.getICCProfiles():
result['iccprofiles'] = [
PIL.ImageCms.getProfileInfo(prof).strip() or 'present' if prof else None
for prof in tileSource.getICCProfiles()]
result['iccprofiles'] = tileSource.getICCProfiles(onlyInfo=True)
result['tilesource'] = tileSource.name
return result

Expand Down
8 changes: 7 additions & 1 deletion large_image/tilesource/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1193,13 +1193,15 @@ def _applyStyleFunction(self, image, sc, stage, function=None):
self.logger.exception('Failed to execute style function %s' % function['name'])
return image

def getICCProfiles(self, idx=None):
def getICCProfiles(self, idx=None, onlyInfo=False):
"""
Get a list of all ICC profiles that are available for the source, or
get a specific profile.
:param idx: a 0-based index into the profiles to get one profile, or
None to get a list of all profiles.
:param onlyInfo: if idx is None and this is true, just return the
profile information.
:returns: either one or a list of PIL.ImageCms.CmsProfile objects, or
None if no profiles are available. If a list, entries in the list
may be None.
Expand All @@ -1217,6 +1219,10 @@ def getICCProfiles(self, idx=None):
if idx == pidx:
return prof
results.append(prof)
if onlyInfo:
results = [
PIL.ImageCms.getProfileInfo(prof).strip() or 'present'
if prof else None for prof in results]
return results

def _applyICCProfile(self, sc, frame):
Expand Down

0 comments on commit 1b34e47

Please sign in to comment.