mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-10-31 16:07:30 +03:00 
			
		
		
		
	Added im.info['icc_profile'] to results for ImageCms.applyTransform
This commit is contained in:
		
							parent
							
								
									13eb3d667a
								
							
						
					
					
						commit
						5966278643
					
				|  | @ -199,6 +199,8 @@ class ImageCmsTransform(Image.ImagePointHandler): | ||||||
|         self.input_mode = self.inputMode = input_mode |         self.input_mode = self.inputMode = input_mode | ||||||
|         self.output_mode = self.outputMode = output_mode |         self.output_mode = self.outputMode = output_mode | ||||||
| 
 | 
 | ||||||
|  |         self.output_profile = output | ||||||
|  | 
 | ||||||
|     def point(self, im): |     def point(self, im): | ||||||
|         return self.apply(im) |         return self.apply(im) | ||||||
| 
 | 
 | ||||||
|  | @ -207,6 +209,7 @@ class ImageCmsTransform(Image.ImagePointHandler): | ||||||
|         if imOut is None: |         if imOut is None: | ||||||
|             imOut = Image.new(self.output_mode, im.size, None) |             imOut = Image.new(self.output_mode, im.size, None) | ||||||
|         self.transform.apply(im.im.id, imOut.im.id) |         self.transform.apply(im.im.id, imOut.im.id) | ||||||
|  |         imOut.info['icc_profile'] = self.output_profile.tobytes() | ||||||
|         return imOut |         return imOut | ||||||
| 
 | 
 | ||||||
|     def apply_in_place(self, im): |     def apply_in_place(self, im): | ||||||
|  | @ -214,6 +217,7 @@ class ImageCmsTransform(Image.ImagePointHandler): | ||||||
|         if im.mode != self.output_mode: |         if im.mode != self.output_mode: | ||||||
|             raise ValueError("mode mismatch")  # wrong output mode |             raise ValueError("mode mismatch")  # wrong output mode | ||||||
|         self.transform.apply(im.im.id, im.im.id) |         self.transform.apply(im.im.id, im.im.id) | ||||||
|  |         im.info['icc_profile'] = self.output_profile.tobytes() | ||||||
|         return im |         return im | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -2,8 +2,11 @@ from helper import unittest, PillowTestCase, lena | ||||||
| 
 | 
 | ||||||
| from PIL import Image | from PIL import Image | ||||||
| 
 | 
 | ||||||
|  | from io import BytesIO | ||||||
|  |          | ||||||
| try: | try: | ||||||
|     from PIL import ImageCms |     from PIL import ImageCms | ||||||
|  |     from PIL.ImageCms import ImageCmsProfile | ||||||
|     ImageCms.core.profile_open |     ImageCms.core.profile_open | ||||||
| except ImportError as v: | except ImportError as v: | ||||||
|     # Skipped via setUp() |     # Skipped via setUp() | ||||||
|  | @ -118,7 +121,7 @@ class TestImageCms(PillowTestCase): | ||||||
| 
 | 
 | ||||||
|     def test_extensions(self): |     def test_extensions(self): | ||||||
|         # extensions |         # extensions | ||||||
|         from io import BytesIO | 
 | ||||||
|         i = Image.open("Tests/images/rgb.jpg") |         i = Image.open("Tests/images/rgb.jpg") | ||||||
|         p = ImageCms.getOpenProfile(BytesIO(i.info["icc_profile"])) |         p = ImageCms.getOpenProfile(BytesIO(i.info["icc_profile"])) | ||||||
|         self.assertEqual( |         self.assertEqual( | ||||||
|  | @ -196,6 +199,11 @@ class TestImageCms(PillowTestCase): | ||||||
|         # img_srgb.save('temp.srgb.tif') # visually verified vs ps. |         # img_srgb.save('temp.srgb.tif') # visually verified vs ps. | ||||||
| 
 | 
 | ||||||
|         self.assert_image_similar(lena(), img_srgb, 30) |         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): |     def test_lab_roundtrip(self): | ||||||
|         # check to see if we're at least internally consistent. |         # check to see if we're at least internally consistent. | ||||||
|  | @ -205,6 +213,10 @@ class TestImageCms(PillowTestCase): | ||||||
|         t2 = ImageCms.buildTransform(pLab, SRGB, "LAB", "RGB") |         t2 = ImageCms.buildTransform(pLab, SRGB, "LAB", "RGB") | ||||||
| 
 | 
 | ||||||
|         i = ImageCms.applyTransform(lena(), t) |         i = ImageCms.applyTransform(lena(), t) | ||||||
|  | 
 | ||||||
|  |         self.assertEqual(i.info['icc_profile'], | ||||||
|  |                          ImageCmsProfile(pLab).tobytes()) | ||||||
|  |          | ||||||
|         out = ImageCms.applyTransform(i, t2) |         out = ImageCms.applyTransform(i, t2) | ||||||
| 
 | 
 | ||||||
|         self.assert_image_similar(lena(), out, 2) |         self.assert_image_similar(lena(), out, 2) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user