From 5966278643e356957986c52679184add492bf553 Mon Sep 17 00:00:00 2001 From: wiredfool Date: Tue, 29 Jul 2014 21:20:11 -0700 Subject: [PATCH] Added im.info['icc_profile'] to results for ImageCms.applyTransform --- PIL/ImageCms.py | 4 ++++ Tests/test_imagecms.py | 14 +++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/PIL/ImageCms.py b/PIL/ImageCms.py index 9848e5ba2..e708d1dad 100644 --- a/PIL/ImageCms.py +++ b/PIL/ImageCms.py @@ -199,6 +199,8 @@ class ImageCmsTransform(Image.ImagePointHandler): self.input_mode = self.inputMode = input_mode self.output_mode = self.outputMode = output_mode + self.output_profile = output + def point(self, im): return self.apply(im) @@ -207,6 +209,7 @@ class ImageCmsTransform(Image.ImagePointHandler): if imOut is None: imOut = Image.new(self.output_mode, im.size, None) self.transform.apply(im.im.id, imOut.im.id) + imOut.info['icc_profile'] = self.output_profile.tobytes() return imOut def apply_in_place(self, im): @@ -214,6 +217,7 @@ class ImageCmsTransform(Image.ImagePointHandler): if im.mode != self.output_mode: raise ValueError("mode mismatch") # wrong output mode self.transform.apply(im.im.id, im.im.id) + im.info['icc_profile'] = self.output_profile.tobytes() return im diff --git a/Tests/test_imagecms.py b/Tests/test_imagecms.py index 74eef3037..e731c8945 100644 --- a/Tests/test_imagecms.py +++ b/Tests/test_imagecms.py @@ -2,8 +2,11 @@ from helper import unittest, PillowTestCase, lena from PIL import Image +from io import BytesIO + try: from PIL import ImageCms + from PIL.ImageCms import ImageCmsProfile ImageCms.core.profile_open except ImportError as v: # Skipped via setUp() @@ -118,7 +121,7 @@ class TestImageCms(PillowTestCase): def test_extensions(self): # extensions - from io import BytesIO + i = Image.open("Tests/images/rgb.jpg") p = ImageCms.getOpenProfile(BytesIO(i.info["icc_profile"])) self.assertEqual( @@ -196,6 +199,11 @@ class TestImageCms(PillowTestCase): # img_srgb.save('temp.srgb.tif') # visually verified vs ps. self.assert_image_similar(lena(), img_srgb, 30) + self.assertTrue(img_srgb.info['icc_profile']) + + profile = ImageCmsProfile(BytesIO(img_srgb.info['icc_profile'])) + self.assertTrue('sRGB' in ImageCms.getProfileDescription(profile)) + def test_lab_roundtrip(self): # check to see if we're at least internally consistent. @@ -205,6 +213,10 @@ class TestImageCms(PillowTestCase): t2 = ImageCms.buildTransform(pLab, SRGB, "LAB", "RGB") i = ImageCms.applyTransform(lena(), t) + + self.assertEqual(i.info['icc_profile'], + ImageCmsProfile(pLab).tobytes()) + out = ImageCms.applyTransform(i, t2) self.assert_image_similar(lena(), out, 2)