|
1 | 1 | import glob |
| 2 | +import io |
2 | 3 | import os |
3 | 4 | import random |
4 | 5 | import sys |
5 | 6 | import unittest |
6 | 7 |
|
7 | 8 | import AppKit # type: ignore |
8 | 9 | import PIL |
| 10 | +from PIL import ImageCms |
9 | 11 | from testSupport import ( |
10 | 12 | DrawBotBaseTest, |
11 | 13 | StdOutCollector, |
@@ -444,6 +446,55 @@ def test_formattedStringURL_svg(self): |
444 | 446 | readData(path), readData(expectedPath), "Files %r and %s are not the same" % (path, expectedPath) |
445 | 447 | ) |
446 | 448 |
|
| 449 | + def test_export_color_space_cmyk(self): |
| 450 | + drawBot.newDrawing() |
| 451 | + drawBot.size(1000, 1000) |
| 452 | + drawBot.cmykFill(1, 0, 0, 0) |
| 453 | + drawBot.rect(0, 0, 250, 1000) |
| 454 | + drawBot.cmykFill(0, 1, 0, 0) |
| 455 | + drawBot.rect(250, 0, 250, 1000) |
| 456 | + drawBot.cmykFill(0, 0, 1, 0) |
| 457 | + drawBot.rect(500, 0, 250, 1000) |
| 458 | + drawBot.cmykFill(0, 0, 0, 1) |
| 459 | + drawBot.rect(750, 0, 250, 1000) |
| 460 | + |
| 461 | + rgba_path = os.path.join(tempTestDataDir, "cmyk_export_default.tiff") |
| 462 | + cmyk_path = os.path.join(tempTestDataDir, "cmyk_export_with_color_space.tiff") |
| 463 | + cmyk_with_profile_path = os.path.join(tempTestDataDir, "cmyk_export_with_color_space_and_profile.tiff") |
| 464 | + |
| 465 | + drawBot.saveImage(rgba_path) |
| 466 | + drawBot.saveImage(cmyk_path, colorSpace="CMYK") |
| 467 | + |
| 468 | + icc_data = AppKit.NSData.dataWithContentsOfFile_("/System/Library/ColorSync/Profiles/Generic CMYK Profile.icc") |
| 469 | + drawBot.saveImage(cmyk_with_profile_path, colorSpace="CMYK", imageColorSyncProfileData=icc_data) |
| 470 | + |
| 471 | + drawBot.endDrawing() |
| 472 | + |
| 473 | + rgba_image = PIL.Image.open(rgba_path) |
| 474 | + self.assertEqual(rgba_image.mode, "RGBA") |
| 475 | + |
| 476 | + rgba_image_profile = ImageCms.ImageCmsProfile( |
| 477 | + io.BytesIO(rgba_image.info.get("icc_profile")) |
| 478 | + ) |
| 479 | + self.assertEqual( |
| 480 | + rgba_image_profile.profile.profile_description, |
| 481 | + "Generic RGB Profile" |
| 482 | + ) |
| 483 | + |
| 484 | + cmyk_image = PIL.Image.open(cmyk_path) |
| 485 | + self.assertEqual(cmyk_image.mode, "CMYK") |
| 486 | + self.assertIsNone(cmyk_image.info.get("icc_profile")) |
| 487 | + |
| 488 | + cmyk_with_profile_image = PIL.Image.open(cmyk_with_profile_path) |
| 489 | + self.assertEqual(cmyk_with_profile_image.mode, "CMYK") |
| 490 | + cmyk_with_profile_image_profile = ImageCms.ImageCmsProfile( |
| 491 | + io.BytesIO(cmyk_with_profile_image.info.get("icc_profile")) |
| 492 | + ) |
| 493 | + self.assertEqual( |
| 494 | + cmyk_with_profile_image_profile.profile.profile_description, |
| 495 | + "Generic CMYK Profile" |
| 496 | + ) |
| 497 | + |
447 | 498 |
|
448 | 499 | if __name__ == "__main__": |
449 | 500 | import doctest |
|
0 commit comments