@ai-ecoverse/py-pillow 12.3.0-2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (217) hide show
  1. package/LICENSE +30 -0
  2. package/README.md +4 -0
  3. package/lib/python3.14/site-packages/PIL/AvifImagePlugin.py +295 -0
  4. package/lib/python3.14/site-packages/PIL/BdfFontFile.py +124 -0
  5. package/lib/python3.14/site-packages/PIL/BlpImagePlugin.py +498 -0
  6. package/lib/python3.14/site-packages/PIL/BmpImagePlugin.py +514 -0
  7. package/lib/python3.14/site-packages/PIL/BufrStubImagePlugin.py +72 -0
  8. package/lib/python3.14/site-packages/PIL/ContainerIO.py +173 -0
  9. package/lib/python3.14/site-packages/PIL/CurImagePlugin.py +103 -0
  10. package/lib/python3.14/site-packages/PIL/DcxImagePlugin.py +84 -0
  11. package/lib/python3.14/site-packages/PIL/DdsImagePlugin.py +632 -0
  12. package/lib/python3.14/site-packages/PIL/EpsImagePlugin.py +484 -0
  13. package/lib/python3.14/site-packages/PIL/ExifTags.py +384 -0
  14. package/lib/python3.14/site-packages/PIL/FitsImagePlugin.py +153 -0
  15. package/lib/python3.14/site-packages/PIL/FliImagePlugin.py +184 -0
  16. package/lib/python3.14/site-packages/PIL/FontFile.py +160 -0
  17. package/lib/python3.14/site-packages/PIL/FpxImagePlugin.py +262 -0
  18. package/lib/python3.14/site-packages/PIL/FtexImagePlugin.py +115 -0
  19. package/lib/python3.14/site-packages/PIL/GbrImagePlugin.py +103 -0
  20. package/lib/python3.14/site-packages/PIL/GdImageFile.py +104 -0
  21. package/lib/python3.14/site-packages/PIL/GifImagePlugin.py +1223 -0
  22. package/lib/python3.14/site-packages/PIL/GimpGradientFile.py +154 -0
  23. package/lib/python3.14/site-packages/PIL/GimpPaletteFile.py +75 -0
  24. package/lib/python3.14/site-packages/PIL/GribStubImagePlugin.py +72 -0
  25. package/lib/python3.14/site-packages/PIL/Hdf5StubImagePlugin.py +72 -0
  26. package/lib/python3.14/site-packages/PIL/IcnsImagePlugin.py +401 -0
  27. package/lib/python3.14/site-packages/PIL/IcoImagePlugin.py +396 -0
  28. package/lib/python3.14/site-packages/PIL/ImImagePlugin.py +390 -0
  29. package/lib/python3.14/site-packages/PIL/Image.py +4385 -0
  30. package/lib/python3.14/site-packages/PIL/ImageChops.py +311 -0
  31. package/lib/python3.14/site-packages/PIL/ImageCms.py +1078 -0
  32. package/lib/python3.14/site-packages/PIL/ImageColor.py +320 -0
  33. package/lib/python3.14/site-packages/PIL/ImageDraw.py +1002 -0
  34. package/lib/python3.14/site-packages/PIL/ImageDraw2.py +244 -0
  35. package/lib/python3.14/site-packages/PIL/ImageEnhance.py +113 -0
  36. package/lib/python3.14/site-packages/PIL/ImageFile.py +938 -0
  37. package/lib/python3.14/site-packages/PIL/ImageFilter.py +617 -0
  38. package/lib/python3.14/site-packages/PIL/ImageFont.py +1330 -0
  39. package/lib/python3.14/site-packages/PIL/ImageGrab.py +234 -0
  40. package/lib/python3.14/site-packages/PIL/ImageMath.py +314 -0
  41. package/lib/python3.14/site-packages/PIL/ImageMode.py +85 -0
  42. package/lib/python3.14/site-packages/PIL/ImageMorph.py +317 -0
  43. package/lib/python3.14/site-packages/PIL/ImageOps.py +749 -0
  44. package/lib/python3.14/site-packages/PIL/ImagePalette.py +290 -0
  45. package/lib/python3.14/site-packages/PIL/ImagePath.py +20 -0
  46. package/lib/python3.14/site-packages/PIL/ImageQt.py +219 -0
  47. package/lib/python3.14/site-packages/PIL/ImageSequence.py +88 -0
  48. package/lib/python3.14/site-packages/PIL/ImageShow.py +367 -0
  49. package/lib/python3.14/site-packages/PIL/ImageStat.py +167 -0
  50. package/lib/python3.14/site-packages/PIL/ImageText.py +509 -0
  51. package/lib/python3.14/site-packages/PIL/ImageTk.py +266 -0
  52. package/lib/python3.14/site-packages/PIL/ImageTransform.py +136 -0
  53. package/lib/python3.14/site-packages/PIL/ImageWin.py +247 -0
  54. package/lib/python3.14/site-packages/PIL/ImtImagePlugin.py +103 -0
  55. package/lib/python3.14/site-packages/PIL/IptcImagePlugin.py +226 -0
  56. package/lib/python3.14/site-packages/PIL/Jpeg2KImagePlugin.py +466 -0
  57. package/lib/python3.14/site-packages/PIL/JpegImagePlugin.py +889 -0
  58. package/lib/python3.14/site-packages/PIL/JpegPresets.py +242 -0
  59. package/lib/python3.14/site-packages/PIL/McIdasImagePlugin.py +78 -0
  60. package/lib/python3.14/site-packages/PIL/MicImagePlugin.py +103 -0
  61. package/lib/python3.14/site-packages/PIL/MpegImagePlugin.py +84 -0
  62. package/lib/python3.14/site-packages/PIL/MpoImagePlugin.py +203 -0
  63. package/lib/python3.14/site-packages/PIL/MspImagePlugin.py +200 -0
  64. package/lib/python3.14/site-packages/PIL/PSDraw.py +238 -0
  65. package/lib/python3.14/site-packages/PIL/PaletteFile.py +54 -0
  66. package/lib/python3.14/site-packages/PIL/PalmImagePlugin.py +217 -0
  67. package/lib/python3.14/site-packages/PIL/PcdImagePlugin.py +68 -0
  68. package/lib/python3.14/site-packages/PIL/PcfFontFile.py +256 -0
  69. package/lib/python3.14/site-packages/PIL/PcxImagePlugin.py +232 -0
  70. package/lib/python3.14/site-packages/PIL/PdfImagePlugin.py +315 -0
  71. package/lib/python3.14/site-packages/PIL/PdfParser.py +1092 -0
  72. package/lib/python3.14/site-packages/PIL/PixarImagePlugin.py +72 -0
  73. package/lib/python3.14/site-packages/PIL/PngImagePlugin.py +1578 -0
  74. package/lib/python3.14/site-packages/PIL/PpmImagePlugin.py +375 -0
  75. package/lib/python3.14/site-packages/PIL/PsdImagePlugin.py +339 -0
  76. package/lib/python3.14/site-packages/PIL/QoiImagePlugin.py +235 -0
  77. package/lib/python3.14/site-packages/PIL/SgiImagePlugin.py +231 -0
  78. package/lib/python3.14/site-packages/PIL/SpiderImagePlugin.py +332 -0
  79. package/lib/python3.14/site-packages/PIL/SunImagePlugin.py +145 -0
  80. package/lib/python3.14/site-packages/PIL/TarIO.py +61 -0
  81. package/lib/python3.14/site-packages/PIL/TgaImagePlugin.py +284 -0
  82. package/lib/python3.14/site-packages/PIL/TiffImagePlugin.py +2354 -0
  83. package/lib/python3.14/site-packages/PIL/TiffTags.py +566 -0
  84. package/lib/python3.14/site-packages/PIL/WalImageFile.py +129 -0
  85. package/lib/python3.14/site-packages/PIL/WebPImagePlugin.py +322 -0
  86. package/lib/python3.14/site-packages/PIL/WmfImagePlugin.py +183 -0
  87. package/lib/python3.14/site-packages/PIL/XVThumbImagePlugin.py +83 -0
  88. package/lib/python3.14/site-packages/PIL/XbmImagePlugin.py +98 -0
  89. package/lib/python3.14/site-packages/PIL/XpmImagePlugin.py +157 -0
  90. package/lib/python3.14/site-packages/PIL/__init__.py +87 -0
  91. package/lib/python3.14/site-packages/PIL/__main__.py +7 -0
  92. package/lib/python3.14/site-packages/PIL/__pycache__/AvifImagePlugin.cpython-314.pyc +0 -0
  93. package/lib/python3.14/site-packages/PIL/__pycache__/BdfFontFile.cpython-314.pyc +0 -0
  94. package/lib/python3.14/site-packages/PIL/__pycache__/BlpImagePlugin.cpython-314.pyc +0 -0
  95. package/lib/python3.14/site-packages/PIL/__pycache__/BmpImagePlugin.cpython-314.pyc +0 -0
  96. package/lib/python3.14/site-packages/PIL/__pycache__/BufrStubImagePlugin.cpython-314.pyc +0 -0
  97. package/lib/python3.14/site-packages/PIL/__pycache__/ContainerIO.cpython-314.pyc +0 -0
  98. package/lib/python3.14/site-packages/PIL/__pycache__/CurImagePlugin.cpython-314.pyc +0 -0
  99. package/lib/python3.14/site-packages/PIL/__pycache__/DcxImagePlugin.cpython-314.pyc +0 -0
  100. package/lib/python3.14/site-packages/PIL/__pycache__/DdsImagePlugin.cpython-314.pyc +0 -0
  101. package/lib/python3.14/site-packages/PIL/__pycache__/EpsImagePlugin.cpython-314.pyc +0 -0
  102. package/lib/python3.14/site-packages/PIL/__pycache__/ExifTags.cpython-314.pyc +0 -0
  103. package/lib/python3.14/site-packages/PIL/__pycache__/FitsImagePlugin.cpython-314.pyc +0 -0
  104. package/lib/python3.14/site-packages/PIL/__pycache__/FliImagePlugin.cpython-314.pyc +0 -0
  105. package/lib/python3.14/site-packages/PIL/__pycache__/FontFile.cpython-314.pyc +0 -0
  106. package/lib/python3.14/site-packages/PIL/__pycache__/FpxImagePlugin.cpython-314.pyc +0 -0
  107. package/lib/python3.14/site-packages/PIL/__pycache__/FtexImagePlugin.cpython-314.pyc +0 -0
  108. package/lib/python3.14/site-packages/PIL/__pycache__/GbrImagePlugin.cpython-314.pyc +0 -0
  109. package/lib/python3.14/site-packages/PIL/__pycache__/GdImageFile.cpython-314.pyc +0 -0
  110. package/lib/python3.14/site-packages/PIL/__pycache__/GifImagePlugin.cpython-314.pyc +0 -0
  111. package/lib/python3.14/site-packages/PIL/__pycache__/GimpGradientFile.cpython-314.pyc +0 -0
  112. package/lib/python3.14/site-packages/PIL/__pycache__/GimpPaletteFile.cpython-314.pyc +0 -0
  113. package/lib/python3.14/site-packages/PIL/__pycache__/GribStubImagePlugin.cpython-314.pyc +0 -0
  114. package/lib/python3.14/site-packages/PIL/__pycache__/Hdf5StubImagePlugin.cpython-314.pyc +0 -0
  115. package/lib/python3.14/site-packages/PIL/__pycache__/IcnsImagePlugin.cpython-314.pyc +0 -0
  116. package/lib/python3.14/site-packages/PIL/__pycache__/IcoImagePlugin.cpython-314.pyc +0 -0
  117. package/lib/python3.14/site-packages/PIL/__pycache__/ImImagePlugin.cpython-314.pyc +0 -0
  118. package/lib/python3.14/site-packages/PIL/__pycache__/Image.cpython-314.pyc +0 -0
  119. package/lib/python3.14/site-packages/PIL/__pycache__/ImageChops.cpython-314.pyc +0 -0
  120. package/lib/python3.14/site-packages/PIL/__pycache__/ImageCms.cpython-314.pyc +0 -0
  121. package/lib/python3.14/site-packages/PIL/__pycache__/ImageColor.cpython-314.pyc +0 -0
  122. package/lib/python3.14/site-packages/PIL/__pycache__/ImageDraw.cpython-314.pyc +0 -0
  123. package/lib/python3.14/site-packages/PIL/__pycache__/ImageDraw2.cpython-314.pyc +0 -0
  124. package/lib/python3.14/site-packages/PIL/__pycache__/ImageEnhance.cpython-314.pyc +0 -0
  125. package/lib/python3.14/site-packages/PIL/__pycache__/ImageFile.cpython-314.pyc +0 -0
  126. package/lib/python3.14/site-packages/PIL/__pycache__/ImageFilter.cpython-314.pyc +0 -0
  127. package/lib/python3.14/site-packages/PIL/__pycache__/ImageFont.cpython-314.pyc +0 -0
  128. package/lib/python3.14/site-packages/PIL/__pycache__/ImageGrab.cpython-314.pyc +0 -0
  129. package/lib/python3.14/site-packages/PIL/__pycache__/ImageMath.cpython-314.pyc +0 -0
  130. package/lib/python3.14/site-packages/PIL/__pycache__/ImageMode.cpython-314.pyc +0 -0
  131. package/lib/python3.14/site-packages/PIL/__pycache__/ImageMorph.cpython-314.pyc +0 -0
  132. package/lib/python3.14/site-packages/PIL/__pycache__/ImageOps.cpython-314.pyc +0 -0
  133. package/lib/python3.14/site-packages/PIL/__pycache__/ImagePalette.cpython-314.pyc +0 -0
  134. package/lib/python3.14/site-packages/PIL/__pycache__/ImagePath.cpython-314.pyc +0 -0
  135. package/lib/python3.14/site-packages/PIL/__pycache__/ImageQt.cpython-314.pyc +0 -0
  136. package/lib/python3.14/site-packages/PIL/__pycache__/ImageSequence.cpython-314.pyc +0 -0
  137. package/lib/python3.14/site-packages/PIL/__pycache__/ImageShow.cpython-314.pyc +0 -0
  138. package/lib/python3.14/site-packages/PIL/__pycache__/ImageStat.cpython-314.pyc +0 -0
  139. package/lib/python3.14/site-packages/PIL/__pycache__/ImageText.cpython-314.pyc +0 -0
  140. package/lib/python3.14/site-packages/PIL/__pycache__/ImageTk.cpython-314.pyc +0 -0
  141. package/lib/python3.14/site-packages/PIL/__pycache__/ImageTransform.cpython-314.pyc +0 -0
  142. package/lib/python3.14/site-packages/PIL/__pycache__/ImageWin.cpython-314.pyc +0 -0
  143. package/lib/python3.14/site-packages/PIL/__pycache__/ImtImagePlugin.cpython-314.pyc +0 -0
  144. package/lib/python3.14/site-packages/PIL/__pycache__/IptcImagePlugin.cpython-314.pyc +0 -0
  145. package/lib/python3.14/site-packages/PIL/__pycache__/Jpeg2KImagePlugin.cpython-314.pyc +0 -0
  146. package/lib/python3.14/site-packages/PIL/__pycache__/JpegImagePlugin.cpython-314.pyc +0 -0
  147. package/lib/python3.14/site-packages/PIL/__pycache__/JpegPresets.cpython-314.pyc +0 -0
  148. package/lib/python3.14/site-packages/PIL/__pycache__/McIdasImagePlugin.cpython-314.pyc +0 -0
  149. package/lib/python3.14/site-packages/PIL/__pycache__/MicImagePlugin.cpython-314.pyc +0 -0
  150. package/lib/python3.14/site-packages/PIL/__pycache__/MpegImagePlugin.cpython-314.pyc +0 -0
  151. package/lib/python3.14/site-packages/PIL/__pycache__/MpoImagePlugin.cpython-314.pyc +0 -0
  152. package/lib/python3.14/site-packages/PIL/__pycache__/MspImagePlugin.cpython-314.pyc +0 -0
  153. package/lib/python3.14/site-packages/PIL/__pycache__/PSDraw.cpython-314.pyc +0 -0
  154. package/lib/python3.14/site-packages/PIL/__pycache__/PaletteFile.cpython-314.pyc +0 -0
  155. package/lib/python3.14/site-packages/PIL/__pycache__/PalmImagePlugin.cpython-314.pyc +0 -0
  156. package/lib/python3.14/site-packages/PIL/__pycache__/PcdImagePlugin.cpython-314.pyc +0 -0
  157. package/lib/python3.14/site-packages/PIL/__pycache__/PcfFontFile.cpython-314.pyc +0 -0
  158. package/lib/python3.14/site-packages/PIL/__pycache__/PcxImagePlugin.cpython-314.pyc +0 -0
  159. package/lib/python3.14/site-packages/PIL/__pycache__/PdfImagePlugin.cpython-314.pyc +0 -0
  160. package/lib/python3.14/site-packages/PIL/__pycache__/PdfParser.cpython-314.pyc +0 -0
  161. package/lib/python3.14/site-packages/PIL/__pycache__/PixarImagePlugin.cpython-314.pyc +0 -0
  162. package/lib/python3.14/site-packages/PIL/__pycache__/PngImagePlugin.cpython-314.pyc +0 -0
  163. package/lib/python3.14/site-packages/PIL/__pycache__/PpmImagePlugin.cpython-314.pyc +0 -0
  164. package/lib/python3.14/site-packages/PIL/__pycache__/PsdImagePlugin.cpython-314.pyc +0 -0
  165. package/lib/python3.14/site-packages/PIL/__pycache__/QoiImagePlugin.cpython-314.pyc +0 -0
  166. package/lib/python3.14/site-packages/PIL/__pycache__/SgiImagePlugin.cpython-314.pyc +0 -0
  167. package/lib/python3.14/site-packages/PIL/__pycache__/SpiderImagePlugin.cpython-314.pyc +0 -0
  168. package/lib/python3.14/site-packages/PIL/__pycache__/SunImagePlugin.cpython-314.pyc +0 -0
  169. package/lib/python3.14/site-packages/PIL/__pycache__/TarIO.cpython-314.pyc +0 -0
  170. package/lib/python3.14/site-packages/PIL/__pycache__/TgaImagePlugin.cpython-314.pyc +0 -0
  171. package/lib/python3.14/site-packages/PIL/__pycache__/TiffImagePlugin.cpython-314.pyc +0 -0
  172. package/lib/python3.14/site-packages/PIL/__pycache__/TiffTags.cpython-314.pyc +0 -0
  173. package/lib/python3.14/site-packages/PIL/__pycache__/WalImageFile.cpython-314.pyc +0 -0
  174. package/lib/python3.14/site-packages/PIL/__pycache__/WebPImagePlugin.cpython-314.pyc +0 -0
  175. package/lib/python3.14/site-packages/PIL/__pycache__/WmfImagePlugin.cpython-314.pyc +0 -0
  176. package/lib/python3.14/site-packages/PIL/__pycache__/XVThumbImagePlugin.cpython-314.pyc +0 -0
  177. package/lib/python3.14/site-packages/PIL/__pycache__/XbmImagePlugin.cpython-314.pyc +0 -0
  178. package/lib/python3.14/site-packages/PIL/__pycache__/XpmImagePlugin.cpython-314.pyc +0 -0
  179. package/lib/python3.14/site-packages/PIL/__pycache__/__init__.cpython-314.pyc +0 -0
  180. package/lib/python3.14/site-packages/PIL/__pycache__/__main__.cpython-314.pyc +0 -0
  181. package/lib/python3.14/site-packages/PIL/__pycache__/_binary.cpython-314.pyc +0 -0
  182. package/lib/python3.14/site-packages/PIL/__pycache__/_deprecate.cpython-314.pyc +0 -0
  183. package/lib/python3.14/site-packages/PIL/__pycache__/_tkinter_finder.cpython-314.pyc +0 -0
  184. package/lib/python3.14/site-packages/PIL/__pycache__/_typing.cpython-314.pyc +0 -0
  185. package/lib/python3.14/site-packages/PIL/__pycache__/_util.cpython-314.pyc +0 -0
  186. package/lib/python3.14/site-packages/PIL/__pycache__/_version.cpython-314.pyc +0 -0
  187. package/lib/python3.14/site-packages/PIL/__pycache__/features.cpython-314.pyc +0 -0
  188. package/lib/python3.14/site-packages/PIL/__pycache__/report.cpython-314.pyc +0 -0
  189. package/lib/python3.14/site-packages/PIL/_avif.pyi +3 -0
  190. package/lib/python3.14/site-packages/PIL/_binary.py +113 -0
  191. package/lib/python3.14/site-packages/PIL/_deprecate.py +72 -0
  192. package/lib/python3.14/site-packages/PIL/_imaging.cpython-314-wasm32-wasix.so +0 -0
  193. package/lib/python3.14/site-packages/PIL/_imaging.pyi +31 -0
  194. package/lib/python3.14/site-packages/PIL/_imagingcms.pyi +143 -0
  195. package/lib/python3.14/site-packages/PIL/_imagingft.cpython-314-wasm32-wasix.so +0 -0
  196. package/lib/python3.14/site-packages/PIL/_imagingft.pyi +70 -0
  197. package/lib/python3.14/site-packages/PIL/_imagingmath.cpython-314-wasm32-wasix.so +0 -0
  198. package/lib/python3.14/site-packages/PIL/_imagingmath.pyi +3 -0
  199. package/lib/python3.14/site-packages/PIL/_imagingmorph.cpython-314-wasm32-wasix.so +0 -0
  200. package/lib/python3.14/site-packages/PIL/_imagingmorph.pyi +3 -0
  201. package/lib/python3.14/site-packages/PIL/_imagingtk.cpython-314-wasm32-wasix.so +0 -0
  202. package/lib/python3.14/site-packages/PIL/_imagingtk.pyi +3 -0
  203. package/lib/python3.14/site-packages/PIL/_tkinter_finder.py +20 -0
  204. package/lib/python3.14/site-packages/PIL/_typing.py +45 -0
  205. package/lib/python3.14/site-packages/PIL/_util.py +29 -0
  206. package/lib/python3.14/site-packages/PIL/_version.py +4 -0
  207. package/lib/python3.14/site-packages/PIL/_webp.pyi +3 -0
  208. package/lib/python3.14/site-packages/PIL/features.py +343 -0
  209. package/lib/python3.14/site-packages/PIL/py.typed +0 -0
  210. package/lib/python3.14/site-packages/PIL/report.py +5 -0
  211. package/lib/python3.14/site-packages/pillow-12.3.0.dist-info/METADATA +180 -0
  212. package/lib/python3.14/site-packages/pillow-12.3.0.dist-info/RECORD +117 -0
  213. package/lib/python3.14/site-packages/pillow-12.3.0.dist-info/WHEEL +5 -0
  214. package/lib/python3.14/site-packages/pillow-12.3.0.dist-info/licenses/LICENSE +30 -0
  215. package/lib/python3.14/site-packages/pillow-12.3.0.dist-info/top_level.txt +1 -0
  216. package/lib/python3.14/site-packages/pillow-12.3.0.dist-info/zip-safe +1 -0
  217. package/package.json +46 -0
@@ -0,0 +1,1078 @@
1
+ # The Python Imaging Library.
2
+ # $Id$
3
+
4
+ # Optional color management support, based on Kevin Cazabon's PyCMS
5
+ # library.
6
+
7
+ # Originally released under LGPL. Graciously donated to PIL in
8
+ # March 2009, for distribution under the standard PIL license
9
+
10
+ # History:
11
+
12
+ # 2009-03-08 fl Added to PIL.
13
+
14
+ # Copyright (C) 2002-2003 Kevin Cazabon
15
+ # Copyright (c) 2009 by Fredrik Lundh
16
+ # Copyright (c) 2013 by Eric Soroos
17
+
18
+ # See the README file for information on usage and redistribution. See
19
+ # below for the original description.
20
+ from __future__ import annotations
21
+
22
+ import operator
23
+ import sys
24
+ from enum import IntEnum, IntFlag
25
+ from functools import reduce
26
+ from typing import Any, Literal, SupportsFloat, SupportsInt, Union
27
+
28
+ from . import Image
29
+ from ._deprecate import deprecate
30
+ from ._typing import SupportsRead
31
+
32
+ try:
33
+ from . import _imagingcms as core
34
+
35
+ _CmsProfileCompatible = Union[
36
+ str, SupportsRead[bytes], core.CmsProfile, "ImageCmsProfile"
37
+ ]
38
+ except ImportError as ex:
39
+ # Allow error import for doc purposes, but error out when accessing
40
+ # anything in core.
41
+ from ._util import DeferredError
42
+
43
+ core = DeferredError.new(ex)
44
+
45
+ _DESCRIPTION = """
46
+ pyCMS
47
+
48
+ a Python / PIL interface to the littleCMS ICC Color Management System
49
+ Copyright (C) 2002-2003 Kevin Cazabon
50
+ kevin@cazabon.com
51
+ https://www.cazabon.com
52
+
53
+ pyCMS home page: https://www.cazabon.com/pyCMS
54
+ littleCMS home page: https://www.littlecms.com
55
+ (littleCMS is Copyright (C) 1998-2001 Marti Maria)
56
+
57
+ Originally released under LGPL. Graciously donated to PIL in
58
+ March 2009, for distribution under the standard PIL license
59
+
60
+ The pyCMS.py module provides a "clean" interface between Python/PIL and
61
+ pyCMSdll, taking care of some of the more complex handling of the direct
62
+ pyCMSdll functions, as well as error-checking and making sure that all
63
+ relevant data is kept together.
64
+
65
+ While it is possible to call pyCMSdll functions directly, it's not highly
66
+ recommended.
67
+
68
+ Version History:
69
+
70
+ 1.0.0 pil Oct 2013 Port to LCMS 2.
71
+
72
+ 0.1.0 pil mod March 10, 2009
73
+
74
+ Renamed display profile to proof profile. The proof
75
+ profile is the profile of the device that is being
76
+ simulated, not the profile of the device which is
77
+ actually used to display/print the final simulation
78
+ (that'd be the output profile) - also see LCMSAPI.txt
79
+ input colorspace -> using 'renderingIntent' -> proof
80
+ colorspace -> using 'proofRenderingIntent' -> output
81
+ colorspace
82
+
83
+ Added LCMS FLAGS support.
84
+ Added FLAGS["SOFTPROOFING"] as default flag for
85
+ buildProofTransform (otherwise the proof profile/intent
86
+ would be ignored).
87
+
88
+ 0.1.0 pil March 2009 - added to PIL, as PIL.ImageCms
89
+
90
+ 0.0.2 alpha Jan 6, 2002
91
+
92
+ Added try/except statements around type() checks of
93
+ potential CObjects... Python won't let you use type()
94
+ on them, and raises a TypeError (stupid, if you ask
95
+ me!)
96
+
97
+ Added buildProofTransformFromOpenProfiles() function.
98
+ Additional fixes in DLL, see DLL code for details.
99
+
100
+ 0.0.1 alpha first public release, Dec. 26, 2002
101
+
102
+ Known to-do list with current version (of Python interface, not pyCMSdll):
103
+
104
+ none
105
+
106
+ """
107
+
108
+ _VERSION = "1.0.0 pil"
109
+
110
+
111
+ # --------------------------------------------------------------------.
112
+
113
+
114
+ #
115
+ # intent/direction values
116
+
117
+
118
+ class Intent(IntEnum):
119
+ PERCEPTUAL = 0
120
+ RELATIVE_COLORIMETRIC = 1
121
+ SATURATION = 2
122
+ ABSOLUTE_COLORIMETRIC = 3
123
+
124
+
125
+ class Direction(IntEnum):
126
+ INPUT = 0
127
+ OUTPUT = 1
128
+ PROOF = 2
129
+
130
+
131
+ #
132
+ # flags
133
+
134
+
135
+ class Flags(IntFlag):
136
+ """Flags and documentation are taken from ``lcms2.h``."""
137
+
138
+ NONE = 0
139
+ NOCACHE = 0x0040
140
+ """Inhibit 1-pixel cache"""
141
+ NOOPTIMIZE = 0x0100
142
+ """Inhibit optimizations"""
143
+ NULLTRANSFORM = 0x0200
144
+ """Don't transform anyway"""
145
+ GAMUTCHECK = 0x1000
146
+ """Out of Gamut alarm"""
147
+ SOFTPROOFING = 0x4000
148
+ """Do softproofing"""
149
+ BLACKPOINTCOMPENSATION = 0x2000
150
+ NOWHITEONWHITEFIXUP = 0x0004
151
+ """Don't fix scum dot"""
152
+ HIGHRESPRECALC = 0x0400
153
+ """Use more memory to give better accuracy"""
154
+ LOWRESPRECALC = 0x0800
155
+ """Use less memory to minimize resources"""
156
+ # this should be 8BITS_DEVICELINK, but that is not a valid name in Python:
157
+ USE_8BITS_DEVICELINK = 0x0008
158
+ """Create 8 bits devicelinks"""
159
+ GUESSDEVICECLASS = 0x0020
160
+ """Guess device class (for ``transform2devicelink``)"""
161
+ KEEP_SEQUENCE = 0x0080
162
+ """Keep profile sequence for devicelink creation"""
163
+ FORCE_CLUT = 0x0002
164
+ """Force CLUT optimization"""
165
+ CLUT_POST_LINEARIZATION = 0x0001
166
+ """create postlinearization tables if possible"""
167
+ CLUT_PRE_LINEARIZATION = 0x0010
168
+ """create prelinearization tables if possible"""
169
+ NONEGATIVES = 0x8000
170
+ """Prevent negative numbers in floating point transforms"""
171
+ COPY_ALPHA = 0x04000000
172
+ """Alpha channels are copied on ``cmsDoTransform()``"""
173
+ NODEFAULTRESOURCEDEF = 0x01000000
174
+
175
+ _GRIDPOINTS_1 = 1 << 16
176
+ _GRIDPOINTS_2 = 2 << 16
177
+ _GRIDPOINTS_4 = 4 << 16
178
+ _GRIDPOINTS_8 = 8 << 16
179
+ _GRIDPOINTS_16 = 16 << 16
180
+ _GRIDPOINTS_32 = 32 << 16
181
+ _GRIDPOINTS_64 = 64 << 16
182
+ _GRIDPOINTS_128 = 128 << 16
183
+
184
+ @staticmethod
185
+ def GRIDPOINTS(n: int) -> Flags:
186
+ """
187
+ Fine-tune control over number of gridpoints
188
+
189
+ :param n: :py:class:`int` in range ``0 <= n <= 255``
190
+ """
191
+ return Flags.NONE | ((n & 0xFF) << 16)
192
+
193
+
194
+ _MAX_FLAG = reduce(operator.or_, Flags)
195
+
196
+
197
+ _FLAGS = {
198
+ "MATRIXINPUT": 1,
199
+ "MATRIXOUTPUT": 2,
200
+ "MATRIXONLY": (1 | 2),
201
+ "NOWHITEONWHITEFIXUP": 4, # Don't hot fix scum dot
202
+ # Don't create prelinearization tables on precalculated transforms
203
+ # (internal use):
204
+ "NOPRELINEARIZATION": 16,
205
+ "GUESSDEVICECLASS": 32, # Guess device class (for transform2devicelink)
206
+ "NOTCACHE": 64, # Inhibit 1-pixel cache
207
+ "NOTPRECALC": 256,
208
+ "NULLTRANSFORM": 512, # Don't transform anyway
209
+ "HIGHRESPRECALC": 1024, # Use more memory to give better accuracy
210
+ "LOWRESPRECALC": 2048, # Use less memory to minimize resources
211
+ "WHITEBLACKCOMPENSATION": 8192,
212
+ "BLACKPOINTCOMPENSATION": 8192,
213
+ "GAMUTCHECK": 4096, # Out of Gamut alarm
214
+ "SOFTPROOFING": 16384, # Do softproofing
215
+ "PRESERVEBLACK": 32768, # Black preservation
216
+ "NODEFAULTRESOURCEDEF": 16777216, # CRD special
217
+ "GRIDPOINTS": lambda n: (n & 0xFF) << 16, # Gridpoints
218
+ }
219
+
220
+
221
+ # --------------------------------------------------------------------.
222
+ # Experimental PIL-level API
223
+ # --------------------------------------------------------------------.
224
+
225
+ ##
226
+ # Profile.
227
+
228
+
229
+ class ImageCmsProfile:
230
+ def __init__(self, profile: str | SupportsRead[bytes] | core.CmsProfile) -> None:
231
+ """
232
+ :param profile: Either a string representing a filename,
233
+ a file like object containing a profile or a
234
+ low-level profile object
235
+
236
+ """
237
+ self.filename: str | None = None
238
+
239
+ if isinstance(profile, str):
240
+ if sys.platform == "win32":
241
+ profile_bytes_path = profile.encode()
242
+ try:
243
+ profile_bytes_path.decode("ascii")
244
+ except UnicodeDecodeError:
245
+ with open(profile, "rb") as f:
246
+ self.profile = core.profile_frombytes(f.read())
247
+ return
248
+ self.filename = profile
249
+ self.profile = core.profile_open(profile)
250
+ elif hasattr(profile, "read"):
251
+ self.profile = core.profile_frombytes(profile.read())
252
+ elif isinstance(profile, core.CmsProfile):
253
+ self.profile = profile
254
+ else:
255
+ msg = "Invalid type for Profile" # type: ignore[unreachable]
256
+ raise TypeError(msg)
257
+
258
+ def __getattr__(self, name: str) -> Any:
259
+ if name in ("product_name", "product_info"):
260
+ deprecate(f"ImageCms.ImageCmsProfile.{name}", 13)
261
+ return None
262
+ msg = f"'{self.__class__.__name__}' object has no attribute '{name}'"
263
+ raise AttributeError(msg)
264
+
265
+ def tobytes(self) -> bytes:
266
+ """
267
+ Returns the profile in a format suitable for embedding in
268
+ saved images.
269
+
270
+ :returns: a bytes object containing the ICC profile.
271
+ """
272
+
273
+ return core.profile_tobytes(self.profile)
274
+
275
+
276
+ class ImageCmsTransform(Image.ImagePointHandler):
277
+ """
278
+ Transform. This can be used with the procedural API, or with the standard
279
+ :py:func:`~PIL.Image.Image.point` method.
280
+
281
+ Will return the output profile in the ``output.info['icc_profile']``.
282
+ """
283
+
284
+ def __init__(
285
+ self,
286
+ input: ImageCmsProfile,
287
+ output: ImageCmsProfile,
288
+ input_mode: str,
289
+ output_mode: str,
290
+ intent: Intent = Intent.PERCEPTUAL,
291
+ proof: ImageCmsProfile | None = None,
292
+ proof_intent: Intent = Intent.ABSOLUTE_COLORIMETRIC,
293
+ flags: Flags = Flags.NONE,
294
+ ):
295
+ if proof is None:
296
+ self.transform = core.buildTransform(
297
+ input.profile, output.profile, input_mode, output_mode, intent, flags
298
+ )
299
+ else:
300
+ self.transform = core.buildProofTransform(
301
+ input.profile,
302
+ output.profile,
303
+ proof.profile,
304
+ input_mode,
305
+ output_mode,
306
+ intent,
307
+ proof_intent,
308
+ flags,
309
+ )
310
+ # Note: inputMode and outputMode are for pyCMS compatibility only
311
+ self.input_mode = self.inputMode = input_mode
312
+ self.output_mode = self.outputMode = output_mode
313
+
314
+ self.output_profile = output
315
+
316
+ def point(self, im: Image.Image) -> Image.Image:
317
+ return self.apply(im)
318
+
319
+ def apply(self, im: Image.Image, imOut: Image.Image | None = None) -> Image.Image:
320
+ if im.mode != self.input_mode:
321
+ msg = "mode mismatch"
322
+ raise ValueError(msg)
323
+ if imOut is not None:
324
+ if imOut.mode != self.output_mode:
325
+ msg = "mode mismatch"
326
+ raise ValueError(msg)
327
+ else:
328
+ imOut = Image.new(self.output_mode, im.size, None)
329
+ self.transform.apply(im.getim(), imOut.getim())
330
+ imOut.info["icc_profile"] = self.output_profile.tobytes()
331
+ return imOut
332
+
333
+ def apply_in_place(self, im: Image.Image) -> Image.Image:
334
+ return self.apply(im, im)
335
+
336
+
337
+ def get_display_profile(handle: SupportsInt | None = None) -> ImageCmsProfile | None:
338
+ """
339
+ (experimental) Fetches the profile for the current display device.
340
+
341
+ :returns: ``None`` if the profile is not known.
342
+ """
343
+
344
+ if sys.platform != "win32":
345
+ return None
346
+
347
+ from . import ImageWin # type: ignore[unused-ignore, unreachable]
348
+
349
+ if isinstance(handle, ImageWin.HDC):
350
+ profile = core.get_display_profile_win32(int(handle), 1)
351
+ else:
352
+ profile = core.get_display_profile_win32(int(handle or 0))
353
+ if profile is None:
354
+ return None
355
+ return ImageCmsProfile(profile)
356
+
357
+
358
+ # --------------------------------------------------------------------.
359
+ # pyCMS compatible layer
360
+ # --------------------------------------------------------------------.
361
+
362
+
363
+ class PyCMSError(Exception):
364
+ """(pyCMS) Exception class.
365
+ This is used for all errors in the pyCMS API."""
366
+
367
+ pass
368
+
369
+
370
+ def profileToProfile(
371
+ im: Image.Image,
372
+ inputProfile: _CmsProfileCompatible,
373
+ outputProfile: _CmsProfileCompatible,
374
+ renderingIntent: Intent = Intent.PERCEPTUAL,
375
+ outputMode: str | None = None,
376
+ inPlace: bool = False,
377
+ flags: Flags = Flags.NONE,
378
+ ) -> Image.Image | None:
379
+ """
380
+ (pyCMS) Applies an ICC transformation to a given image, mapping from
381
+ ``inputProfile`` to ``outputProfile``.
382
+
383
+ If the input or output profiles specified are not valid filenames, a
384
+ :exc:`PyCMSError` will be raised. If ``inPlace`` is ``True`` and
385
+ ``outputMode != im.mode``, a :exc:`PyCMSError` will be raised.
386
+ If an error occurs during application of the profiles,
387
+ a :exc:`PyCMSError` will be raised.
388
+ If ``outputMode`` is not a mode supported by the ``outputProfile`` (or by pyCMS),
389
+ a :exc:`PyCMSError` will be raised.
390
+
391
+ This function applies an ICC transformation to im from ``inputProfile``'s
392
+ color space to ``outputProfile``'s color space using the specified rendering
393
+ intent to decide how to handle out-of-gamut colors.
394
+
395
+ ``outputMode`` can be used to specify that a color mode conversion is to
396
+ be done using these profiles, but the specified profiles must be able
397
+ to handle that mode. I.e., if converting im from RGB to CMYK using
398
+ profiles, the input profile must handle RGB data, and the output
399
+ profile must handle CMYK data.
400
+
401
+ :param im: An open :py:class:`~PIL.Image.Image` object (i.e. Image.new(...)
402
+ or Image.open(...), etc.)
403
+ :param inputProfile: String, as a valid filename path to the ICC input
404
+ profile you wish to use for this image, or a profile object
405
+ :param outputProfile: String, as a valid filename path to the ICC output
406
+ profile you wish to use for this image, or a profile object
407
+ :param renderingIntent: Integer (0-3) specifying the rendering intent you
408
+ wish to use for the transform
409
+
410
+ ImageCms.Intent.PERCEPTUAL = 0 (DEFAULT)
411
+ ImageCms.Intent.RELATIVE_COLORIMETRIC = 1
412
+ ImageCms.Intent.SATURATION = 2
413
+ ImageCms.Intent.ABSOLUTE_COLORIMETRIC = 3
414
+
415
+ see the pyCMS documentation for details on rendering intents and what
416
+ they do.
417
+ :param outputMode: A valid PIL mode for the output image (i.e. "RGB",
418
+ "CMYK", etc.). Note: if rendering the image "inPlace", outputMode
419
+ MUST be the same mode as the input, or omitted completely. If
420
+ omitted, the outputMode will be the same as the mode of the input
421
+ image (im.mode)
422
+ :param inPlace: Boolean. If ``True``, the original image is modified in-place,
423
+ and ``None`` is returned. If ``False`` (default), a new
424
+ :py:class:`~PIL.Image.Image` object is returned with the transform applied.
425
+ :param flags: Integer (0-...) specifying additional flags
426
+ :returns: Either None or a new :py:class:`~PIL.Image.Image` object, depending on
427
+ the value of ``inPlace``
428
+ :exception PyCMSError:
429
+ """
430
+
431
+ if outputMode is None:
432
+ outputMode = im.mode
433
+
434
+ if not isinstance(renderingIntent, int) or not (0 <= renderingIntent <= 3):
435
+ msg = "renderingIntent must be an integer between 0 and 3"
436
+ raise PyCMSError(msg)
437
+
438
+ if not isinstance(flags, int) or not (0 <= flags <= _MAX_FLAG):
439
+ msg = f"flags must be an integer between 0 and {_MAX_FLAG}"
440
+ raise PyCMSError(msg)
441
+
442
+ try:
443
+ if not isinstance(inputProfile, ImageCmsProfile):
444
+ inputProfile = ImageCmsProfile(inputProfile)
445
+ if not isinstance(outputProfile, ImageCmsProfile):
446
+ outputProfile = ImageCmsProfile(outputProfile)
447
+ transform = ImageCmsTransform(
448
+ inputProfile,
449
+ outputProfile,
450
+ im.mode,
451
+ outputMode,
452
+ renderingIntent,
453
+ flags=flags,
454
+ )
455
+ if inPlace:
456
+ transform.apply_in_place(im)
457
+ imOut = None
458
+ else:
459
+ imOut = transform.apply(im)
460
+ except (OSError, TypeError, ValueError) as v:
461
+ raise PyCMSError(v) from v
462
+
463
+ return imOut
464
+
465
+
466
+ def getOpenProfile(
467
+ profileFilename: str | SupportsRead[bytes] | core.CmsProfile,
468
+ ) -> ImageCmsProfile:
469
+ """
470
+ (pyCMS) Opens an ICC profile file.
471
+
472
+ The PyCMSProfile object can be passed back into pyCMS for use in creating
473
+ transforms and such (as in ImageCms.buildTransformFromOpenProfiles()).
474
+
475
+ If ``profileFilename`` is not a valid filename for an ICC profile,
476
+ a :exc:`PyCMSError` will be raised.
477
+
478
+ :param profileFilename: String, as a valid filename path to the ICC profile
479
+ you wish to open, or a file-like object.
480
+ :returns: A CmsProfile class object.
481
+ :exception PyCMSError:
482
+ """
483
+
484
+ try:
485
+ return ImageCmsProfile(profileFilename)
486
+ except (OSError, TypeError, ValueError) as v:
487
+ raise PyCMSError(v) from v
488
+
489
+
490
+ def buildTransform(
491
+ inputProfile: _CmsProfileCompatible,
492
+ outputProfile: _CmsProfileCompatible,
493
+ inMode: str,
494
+ outMode: str,
495
+ renderingIntent: Intent = Intent.PERCEPTUAL,
496
+ flags: Flags = Flags.NONE,
497
+ ) -> ImageCmsTransform:
498
+ """
499
+ (pyCMS) Builds an ICC transform mapping from the ``inputProfile`` to the
500
+ ``outputProfile``. Use applyTransform to apply the transform to a given
501
+ image.
502
+
503
+ If the input or output profiles specified are not valid filenames, a
504
+ :exc:`PyCMSError` will be raised. If an error occurs during creation
505
+ of the transform, a :exc:`PyCMSError` will be raised.
506
+
507
+ If ``inMode`` or ``outMode`` are not a mode supported by the ``outputProfile``
508
+ (or by pyCMS), a :exc:`PyCMSError` will be raised.
509
+
510
+ This function builds and returns an ICC transform from the ``inputProfile``
511
+ to the ``outputProfile`` using the ``renderingIntent`` to determine what to do
512
+ with out-of-gamut colors. It will ONLY work for converting images that
513
+ are in ``inMode`` to images that are in ``outMode`` color format (PIL mode,
514
+ i.e. "RGB", "RGBA", "CMYK", etc.).
515
+
516
+ Building the transform is a fair part of the overhead in
517
+ ImageCms.profileToProfile(), so if you're planning on converting multiple
518
+ images using the same input/output settings, this can save you time.
519
+ Once you have a transform object, it can be used with
520
+ ImageCms.applyProfile() to convert images without the need to re-compute
521
+ the lookup table for the transform.
522
+
523
+ The reason pyCMS returns a class object rather than a handle directly
524
+ to the transform is that it needs to keep track of the PIL input/output
525
+ modes that the transform is meant for. These attributes are stored in
526
+ the ``inMode`` and ``outMode`` attributes of the object (which can be
527
+ manually overridden if you really want to, but I don't know of any
528
+ time that would be of use, or would even work).
529
+
530
+ :param inputProfile: String, as a valid filename path to the ICC input
531
+ profile you wish to use for this transform, or a profile object
532
+ :param outputProfile: String, as a valid filename path to the ICC output
533
+ profile you wish to use for this transform, or a profile object
534
+ :param inMode: String, as a valid PIL mode that the appropriate profile
535
+ also supports (i.e. "RGB", "RGBA", "CMYK", etc.)
536
+ :param outMode: String, as a valid PIL mode that the appropriate profile
537
+ also supports (i.e. "RGB", "RGBA", "CMYK", etc.)
538
+ :param renderingIntent: Integer (0-3) specifying the rendering intent you
539
+ wish to use for the transform
540
+
541
+ ImageCms.Intent.PERCEPTUAL = 0 (DEFAULT)
542
+ ImageCms.Intent.RELATIVE_COLORIMETRIC = 1
543
+ ImageCms.Intent.SATURATION = 2
544
+ ImageCms.Intent.ABSOLUTE_COLORIMETRIC = 3
545
+
546
+ see the pyCMS documentation for details on rendering intents and what
547
+ they do.
548
+ :param flags: Integer (0-...) specifying additional flags
549
+ :returns: A CmsTransform class object.
550
+ :exception PyCMSError:
551
+ """
552
+
553
+ if not isinstance(renderingIntent, int) or not (0 <= renderingIntent <= 3):
554
+ msg = "renderingIntent must be an integer between 0 and 3"
555
+ raise PyCMSError(msg)
556
+
557
+ if not isinstance(flags, int) or not (0 <= flags <= _MAX_FLAG):
558
+ msg = f"flags must be an integer between 0 and {_MAX_FLAG}"
559
+ raise PyCMSError(msg)
560
+
561
+ try:
562
+ if not isinstance(inputProfile, ImageCmsProfile):
563
+ inputProfile = ImageCmsProfile(inputProfile)
564
+ if not isinstance(outputProfile, ImageCmsProfile):
565
+ outputProfile = ImageCmsProfile(outputProfile)
566
+ return ImageCmsTransform(
567
+ inputProfile, outputProfile, inMode, outMode, renderingIntent, flags=flags
568
+ )
569
+ except (OSError, TypeError, ValueError) as v:
570
+ raise PyCMSError(v) from v
571
+
572
+
573
+ def buildProofTransform(
574
+ inputProfile: _CmsProfileCompatible,
575
+ outputProfile: _CmsProfileCompatible,
576
+ proofProfile: _CmsProfileCompatible,
577
+ inMode: str,
578
+ outMode: str,
579
+ renderingIntent: Intent = Intent.PERCEPTUAL,
580
+ proofRenderingIntent: Intent = Intent.ABSOLUTE_COLORIMETRIC,
581
+ flags: Flags = Flags.SOFTPROOFING,
582
+ ) -> ImageCmsTransform:
583
+ """
584
+ (pyCMS) Builds an ICC transform mapping from the ``inputProfile`` to the
585
+ ``outputProfile``, but tries to simulate the result that would be
586
+ obtained on the ``proofProfile`` device.
587
+
588
+ If the input, output, or proof profiles specified are not valid
589
+ filenames, a :exc:`PyCMSError` will be raised.
590
+
591
+ If an error occurs during creation of the transform,
592
+ a :exc:`PyCMSError` will be raised.
593
+
594
+ If ``inMode`` or ``outMode`` are not a mode supported by the ``outputProfile``
595
+ (or by pyCMS), a :exc:`PyCMSError` will be raised.
596
+
597
+ This function builds and returns an ICC transform from the ``inputProfile``
598
+ to the ``outputProfile``, but tries to simulate the result that would be
599
+ obtained on the ``proofProfile`` device using ``renderingIntent`` and
600
+ ``proofRenderingIntent`` to determine what to do with out-of-gamut
601
+ colors. This is known as "soft-proofing". It will ONLY work for
602
+ converting images that are in ``inMode`` to images that are in outMode
603
+ color format (PIL mode, i.e. "RGB", "RGBA", "CMYK", etc.).
604
+
605
+ Usage of the resulting transform object is exactly the same as with
606
+ ImageCms.buildTransform().
607
+
608
+ Proof profiling is generally used when using an output device to get a
609
+ good idea of what the final printed/displayed image would look like on
610
+ the ``proofProfile`` device when it's quicker and easier to use the
611
+ output device for judging color. Generally, this means that the
612
+ output device is a monitor, or a dye-sub printer (etc.), and the simulated
613
+ device is something more expensive, complicated, or time consuming
614
+ (making it difficult to make a real print for color judgement purposes).
615
+
616
+ Soft-proofing basically functions by adjusting the colors on the
617
+ output device to match the colors of the device being simulated. However,
618
+ when the simulated device has a much wider gamut than the output
619
+ device, you may obtain marginal results.
620
+
621
+ :param inputProfile: String, as a valid filename path to the ICC input
622
+ profile you wish to use for this transform, or a profile object
623
+ :param outputProfile: String, as a valid filename path to the ICC output
624
+ (monitor, usually) profile you wish to use for this transform, or a
625
+ profile object
626
+ :param proofProfile: String, as a valid filename path to the ICC proof
627
+ profile you wish to use for this transform, or a profile object
628
+ :param inMode: String, as a valid PIL mode that the appropriate profile
629
+ also supports (i.e. "RGB", "RGBA", "CMYK", etc.)
630
+ :param outMode: String, as a valid PIL mode that the appropriate profile
631
+ also supports (i.e. "RGB", "RGBA", "CMYK", etc.)
632
+ :param renderingIntent: Integer (0-3) specifying the rendering intent you
633
+ wish to use for the input->proof (simulated) transform
634
+
635
+ ImageCms.Intent.PERCEPTUAL = 0 (DEFAULT)
636
+ ImageCms.Intent.RELATIVE_COLORIMETRIC = 1
637
+ ImageCms.Intent.SATURATION = 2
638
+ ImageCms.Intent.ABSOLUTE_COLORIMETRIC = 3
639
+
640
+ see the pyCMS documentation for details on rendering intents and what
641
+ they do.
642
+ :param proofRenderingIntent: Integer (0-3) specifying the rendering intent
643
+ you wish to use for proof->output transform
644
+
645
+ ImageCms.Intent.PERCEPTUAL = 0 (DEFAULT)
646
+ ImageCms.Intent.RELATIVE_COLORIMETRIC = 1
647
+ ImageCms.Intent.SATURATION = 2
648
+ ImageCms.Intent.ABSOLUTE_COLORIMETRIC = 3
649
+
650
+ see the pyCMS documentation for details on rendering intents and what
651
+ they do.
652
+ :param flags: Integer (0-...) specifying additional flags
653
+ :returns: A CmsTransform class object.
654
+ :exception PyCMSError:
655
+ """
656
+
657
+ if not isinstance(renderingIntent, int) or not (0 <= renderingIntent <= 3):
658
+ msg = "renderingIntent must be an integer between 0 and 3"
659
+ raise PyCMSError(msg)
660
+
661
+ if not isinstance(flags, int) or not (0 <= flags <= _MAX_FLAG):
662
+ msg = f"flags must be an integer between 0 and {_MAX_FLAG}"
663
+ raise PyCMSError(msg)
664
+
665
+ try:
666
+ if not isinstance(inputProfile, ImageCmsProfile):
667
+ inputProfile = ImageCmsProfile(inputProfile)
668
+ if not isinstance(outputProfile, ImageCmsProfile):
669
+ outputProfile = ImageCmsProfile(outputProfile)
670
+ if not isinstance(proofProfile, ImageCmsProfile):
671
+ proofProfile = ImageCmsProfile(proofProfile)
672
+ return ImageCmsTransform(
673
+ inputProfile,
674
+ outputProfile,
675
+ inMode,
676
+ outMode,
677
+ renderingIntent,
678
+ proofProfile,
679
+ proofRenderingIntent,
680
+ flags,
681
+ )
682
+ except (OSError, TypeError, ValueError) as v:
683
+ raise PyCMSError(v) from v
684
+
685
+
686
+ buildTransformFromOpenProfiles = buildTransform
687
+ buildProofTransformFromOpenProfiles = buildProofTransform
688
+
689
+
690
+ def applyTransform(
691
+ im: Image.Image, transform: ImageCmsTransform, inPlace: bool = False
692
+ ) -> Image.Image | None:
693
+ """
694
+ (pyCMS) Applies a transform to a given image.
695
+
696
+ If ``im.mode != transform.input_mode``, a :exc:`PyCMSError` is raised.
697
+
698
+ If ``inPlace`` is ``True`` and ``transform.input_mode != transform.output_mode``, a
699
+ :exc:`PyCMSError` is raised.
700
+
701
+ If ``im.mode``, ``transform.input_mode`` or ``transform.output_mode`` is not
702
+ supported by pyCMSdll or the profiles you used for the transform, a
703
+ :exc:`PyCMSError` is raised.
704
+
705
+ If an error occurs while the transform is being applied,
706
+ a :exc:`PyCMSError` is raised.
707
+
708
+ This function applies a pre-calculated transform (from
709
+ ImageCms.buildTransform() or ImageCms.buildTransformFromOpenProfiles())
710
+ to an image. The transform can be used for multiple images, saving
711
+ considerable calculation time if doing the same conversion multiple times.
712
+
713
+ If you want to modify im in-place instead of receiving a new image as
714
+ the return value, set ``inPlace`` to ``True``. This can only be done if
715
+ ``transform.input_mode`` and ``transform.output_mode`` are the same, because we
716
+ can't change the mode in-place (the buffer sizes for some modes are
717
+ different). The default behavior is to return a new :py:class:`~PIL.Image.Image`
718
+ object of the same dimensions in mode ``transform.output_mode``.
719
+
720
+ :param im: An :py:class:`~PIL.Image.Image` object, and ``im.mode`` must be the same
721
+ as the ``input_mode`` supported by the transform.
722
+ :param transform: A valid CmsTransform class object
723
+ :param inPlace: Bool. If ``True``, ``im`` is modified in place and ``None`` is
724
+ returned, if ``False``, a new :py:class:`~PIL.Image.Image` object with the
725
+ transform applied is returned (and ``im`` is not changed). The default is
726
+ ``False``.
727
+ :returns: Either ``None``, or a new :py:class:`~PIL.Image.Image` object,
728
+ depending on the value of ``inPlace``. The profile will be returned in
729
+ the image's ``info['icc_profile']``.
730
+ :exception PyCMSError:
731
+ """
732
+
733
+ try:
734
+ if inPlace:
735
+ transform.apply_in_place(im)
736
+ imOut = None
737
+ else:
738
+ imOut = transform.apply(im)
739
+ except (TypeError, ValueError) as v:
740
+ raise PyCMSError(v) from v
741
+
742
+ return imOut
743
+
744
+
745
+ def createProfile(
746
+ colorSpace: Literal["LAB", "XYZ", "sRGB"], colorTemp: SupportsFloat = 0
747
+ ) -> core.CmsProfile:
748
+ """
749
+ (pyCMS) Creates a profile.
750
+
751
+ If colorSpace not in ``["LAB", "XYZ", "sRGB"]``,
752
+ a :exc:`PyCMSError` is raised.
753
+
754
+ If using LAB and ``colorTemp`` is not a positive integer,
755
+ a :exc:`PyCMSError` is raised.
756
+
757
+ If an error occurs while creating the profile,
758
+ a :exc:`PyCMSError` is raised.
759
+
760
+ Use this function to create common profiles on-the-fly instead of
761
+ having to supply a profile on disk and knowing the path to it. It
762
+ returns a normal CmsProfile object that can be passed to
763
+ ImageCms.buildTransformFromOpenProfiles() to create a transform to apply
764
+ to images.
765
+
766
+ :param colorSpace: String, the color space of the profile you wish to
767
+ create.
768
+ Currently only "LAB", "XYZ", and "sRGB" are supported.
769
+ :param colorTemp: Positive number for the white point for the profile, in
770
+ degrees Kelvin (i.e. 5000, 6500, 9600, etc.). The default is for D50
771
+ illuminant if omitted (5000k). colorTemp is ONLY applied to LAB
772
+ profiles, and is ignored for XYZ and sRGB.
773
+ :returns: A CmsProfile class object
774
+ :exception PyCMSError:
775
+ """
776
+
777
+ if colorSpace not in ["LAB", "XYZ", "sRGB"]:
778
+ msg = (
779
+ f"Color space not supported for on-the-fly profile creation ({colorSpace})"
780
+ )
781
+ raise PyCMSError(msg)
782
+
783
+ if colorSpace == "LAB":
784
+ try:
785
+ colorTemp = float(colorTemp)
786
+ except (TypeError, ValueError) as e:
787
+ msg = f'Color temperature must be numeric, "{colorTemp}" not valid'
788
+ raise PyCMSError(msg) from e
789
+
790
+ try:
791
+ return core.createProfile(colorSpace, colorTemp)
792
+ except (TypeError, ValueError) as v:
793
+ raise PyCMSError(v) from v
794
+
795
+
796
+ def getProfileName(profile: _CmsProfileCompatible) -> str:
797
+ """
798
+
799
+ (pyCMS) Gets the internal product name for the given profile.
800
+
801
+ If ``profile`` isn't a valid CmsProfile object or filename to a profile,
802
+ a :exc:`PyCMSError` is raised If an error occurs while trying
803
+ to obtain the name tag, a :exc:`PyCMSError` is raised.
804
+
805
+ Use this function to obtain the INTERNAL name of the profile (stored
806
+ in an ICC tag in the profile itself), usually the one used when the
807
+ profile was originally created. Sometimes this tag also contains
808
+ additional information supplied by the creator.
809
+
810
+ :param profile: EITHER a valid CmsProfile object, OR a string of the
811
+ filename of an ICC profile.
812
+ :returns: A string containing the internal name of the profile as stored
813
+ in an ICC tag.
814
+ :exception PyCMSError:
815
+ """
816
+
817
+ try:
818
+ # add an extra newline to preserve pyCMS compatibility
819
+ if not isinstance(profile, ImageCmsProfile):
820
+ profile = ImageCmsProfile(profile)
821
+ # do it in python, not c.
822
+ # // name was "%s - %s" (model, manufacturer) || Description ,
823
+ # // but if the Model and Manufacturer were the same or the model
824
+ # // was long, Just the model, in 1.x
825
+ model = profile.profile.model
826
+ manufacturer = profile.profile.manufacturer
827
+
828
+ if not (model or manufacturer):
829
+ return (profile.profile.profile_description or "") + "\n"
830
+ if not manufacturer or (model and len(model) > 30):
831
+ return f"{model}\n"
832
+ return f"{model} - {manufacturer}\n"
833
+
834
+ except (AttributeError, OSError, TypeError, ValueError) as v:
835
+ raise PyCMSError(v) from v
836
+
837
+
838
+ def getProfileInfo(profile: _CmsProfileCompatible) -> str:
839
+ """
840
+ (pyCMS) Gets the internal product information for the given profile.
841
+
842
+ If ``profile`` isn't a valid CmsProfile object or filename to a profile,
843
+ a :exc:`PyCMSError` is raised.
844
+
845
+ If an error occurs while trying to obtain the info tag,
846
+ a :exc:`PyCMSError` is raised.
847
+
848
+ Use this function to obtain the information stored in the profile's
849
+ info tag. This often contains details about the profile, and how it
850
+ was created, as supplied by the creator.
851
+
852
+ :param profile: EITHER a valid CmsProfile object, OR a string of the
853
+ filename of an ICC profile.
854
+ :returns: A string containing the internal profile information stored in
855
+ an ICC tag.
856
+ :exception PyCMSError:
857
+ """
858
+
859
+ try:
860
+ if not isinstance(profile, ImageCmsProfile):
861
+ profile = ImageCmsProfile(profile)
862
+ # add an extra newline to preserve pyCMS compatibility
863
+ # Python, not C. the white point bits weren't working well,
864
+ # so skipping.
865
+ # info was description \r\n\r\n copyright \r\n\r\n K007 tag \r\n\r\n whitepoint
866
+ description = profile.profile.profile_description
867
+ cpright = profile.profile.copyright
868
+ elements = [element for element in (description, cpright) if element]
869
+ return "\r\n\r\n".join(elements) + "\r\n\r\n"
870
+
871
+ except (AttributeError, OSError, TypeError, ValueError) as v:
872
+ raise PyCMSError(v) from v
873
+
874
+
875
+ def getProfileCopyright(profile: _CmsProfileCompatible) -> str:
876
+ """
877
+ (pyCMS) Gets the copyright for the given profile.
878
+
879
+ If ``profile`` isn't a valid CmsProfile object or filename to a profile, a
880
+ :exc:`PyCMSError` is raised.
881
+
882
+ If an error occurs while trying to obtain the copyright tag,
883
+ a :exc:`PyCMSError` is raised.
884
+
885
+ Use this function to obtain the information stored in the profile's
886
+ copyright tag.
887
+
888
+ :param profile: EITHER a valid CmsProfile object, OR a string of the
889
+ filename of an ICC profile.
890
+ :returns: A string containing the internal profile information stored in
891
+ an ICC tag.
892
+ :exception PyCMSError:
893
+ """
894
+ try:
895
+ # add an extra newline to preserve pyCMS compatibility
896
+ if not isinstance(profile, ImageCmsProfile):
897
+ profile = ImageCmsProfile(profile)
898
+ return (profile.profile.copyright or "") + "\n"
899
+ except (AttributeError, OSError, TypeError, ValueError) as v:
900
+ raise PyCMSError(v) from v
901
+
902
+
903
+ def getProfileManufacturer(profile: _CmsProfileCompatible) -> str:
904
+ """
905
+ (pyCMS) Gets the manufacturer for the given profile.
906
+
907
+ If ``profile`` isn't a valid CmsProfile object or filename to a profile, a
908
+ :exc:`PyCMSError` is raised.
909
+
910
+ If an error occurs while trying to obtain the manufacturer tag, a
911
+ :exc:`PyCMSError` is raised.
912
+
913
+ Use this function to obtain the information stored in the profile's
914
+ manufacturer tag.
915
+
916
+ :param profile: EITHER a valid CmsProfile object, OR a string of the
917
+ filename of an ICC profile.
918
+ :returns: A string containing the internal profile information stored in
919
+ an ICC tag.
920
+ :exception PyCMSError:
921
+ """
922
+ try:
923
+ # add an extra newline to preserve pyCMS compatibility
924
+ if not isinstance(profile, ImageCmsProfile):
925
+ profile = ImageCmsProfile(profile)
926
+ return (profile.profile.manufacturer or "") + "\n"
927
+ except (AttributeError, OSError, TypeError, ValueError) as v:
928
+ raise PyCMSError(v) from v
929
+
930
+
931
+ def getProfileModel(profile: _CmsProfileCompatible) -> str:
932
+ """
933
+ (pyCMS) Gets the model for the given profile.
934
+
935
+ If ``profile`` isn't a valid CmsProfile object or filename to a profile, a
936
+ :exc:`PyCMSError` is raised.
937
+
938
+ If an error occurs while trying to obtain the model tag,
939
+ a :exc:`PyCMSError` is raised.
940
+
941
+ Use this function to obtain the information stored in the profile's
942
+ model tag.
943
+
944
+ :param profile: EITHER a valid CmsProfile object, OR a string of the
945
+ filename of an ICC profile.
946
+ :returns: A string containing the internal profile information stored in
947
+ an ICC tag.
948
+ :exception PyCMSError:
949
+ """
950
+
951
+ try:
952
+ # add an extra newline to preserve pyCMS compatibility
953
+ if not isinstance(profile, ImageCmsProfile):
954
+ profile = ImageCmsProfile(profile)
955
+ return (profile.profile.model or "") + "\n"
956
+ except (AttributeError, OSError, TypeError, ValueError) as v:
957
+ raise PyCMSError(v) from v
958
+
959
+
960
+ def getProfileDescription(profile: _CmsProfileCompatible) -> str:
961
+ """
962
+ (pyCMS) Gets the description for the given profile.
963
+
964
+ If ``profile`` isn't a valid CmsProfile object or filename to a profile, a
965
+ :exc:`PyCMSError` is raised.
966
+
967
+ If an error occurs while trying to obtain the description tag,
968
+ a :exc:`PyCMSError` is raised.
969
+
970
+ Use this function to obtain the information stored in the profile's
971
+ description tag.
972
+
973
+ :param profile: EITHER a valid CmsProfile object, OR a string of the
974
+ filename of an ICC profile.
975
+ :returns: A string containing the internal profile information stored in an
976
+ ICC tag.
977
+ :exception PyCMSError:
978
+ """
979
+
980
+ try:
981
+ # add an extra newline to preserve pyCMS compatibility
982
+ if not isinstance(profile, ImageCmsProfile):
983
+ profile = ImageCmsProfile(profile)
984
+ return (profile.profile.profile_description or "") + "\n"
985
+ except (AttributeError, OSError, TypeError, ValueError) as v:
986
+ raise PyCMSError(v) from v
987
+
988
+
989
+ def getDefaultIntent(profile: _CmsProfileCompatible) -> int:
990
+ """
991
+ (pyCMS) Gets the default intent name for the given profile.
992
+
993
+ If ``profile`` isn't a valid CmsProfile object or filename to a profile, a
994
+ :exc:`PyCMSError` is raised.
995
+
996
+ If an error occurs while trying to obtain the default intent, a
997
+ :exc:`PyCMSError` is raised.
998
+
999
+ Use this function to determine the default (and usually best optimized)
1000
+ rendering intent for this profile. Most profiles support multiple
1001
+ rendering intents, but are intended mostly for one type of conversion.
1002
+ If you wish to use a different intent than returned, use
1003
+ ImageCms.isIntentSupported() to verify it will work first.
1004
+
1005
+ :param profile: EITHER a valid CmsProfile object, OR a string of the
1006
+ filename of an ICC profile.
1007
+ :returns: Integer 0-3 specifying the default rendering intent for this
1008
+ profile.
1009
+
1010
+ ImageCms.Intent.PERCEPTUAL = 0 (DEFAULT)
1011
+ ImageCms.Intent.RELATIVE_COLORIMETRIC = 1
1012
+ ImageCms.Intent.SATURATION = 2
1013
+ ImageCms.Intent.ABSOLUTE_COLORIMETRIC = 3
1014
+
1015
+ see the pyCMS documentation for details on rendering intents and what
1016
+ they do.
1017
+ :exception PyCMSError:
1018
+ """
1019
+
1020
+ try:
1021
+ if not isinstance(profile, ImageCmsProfile):
1022
+ profile = ImageCmsProfile(profile)
1023
+ return profile.profile.rendering_intent
1024
+ except (AttributeError, OSError, TypeError, ValueError) as v:
1025
+ raise PyCMSError(v) from v
1026
+
1027
+
1028
+ def isIntentSupported(
1029
+ profile: _CmsProfileCompatible, intent: Intent, direction: Direction
1030
+ ) -> Literal[-1, 1]:
1031
+ """
1032
+ (pyCMS) Checks if a given intent is supported.
1033
+
1034
+ Use this function to verify that you can use your desired
1035
+ ``intent`` with ``profile``, and that ``profile`` can be used for the
1036
+ input/output/proof profile as you desire.
1037
+
1038
+ Some profiles are created specifically for one "direction", can cannot
1039
+ be used for others. Some profiles can only be used for certain
1040
+ rendering intents, so it's best to either verify this before trying
1041
+ to create a transform with them (using this function), or catch the
1042
+ potential :exc:`PyCMSError` that will occur if they don't
1043
+ support the modes you select.
1044
+
1045
+ :param profile: EITHER a valid CmsProfile object, OR a string of the
1046
+ filename of an ICC profile.
1047
+ :param intent: Integer (0-3) specifying the rendering intent you wish to
1048
+ use with this profile
1049
+
1050
+ ImageCms.Intent.PERCEPTUAL = 0 (DEFAULT)
1051
+ ImageCms.Intent.RELATIVE_COLORIMETRIC = 1
1052
+ ImageCms.Intent.SATURATION = 2
1053
+ ImageCms.Intent.ABSOLUTE_COLORIMETRIC = 3
1054
+
1055
+ see the pyCMS documentation for details on rendering intents and what
1056
+ they do.
1057
+ :param direction: Integer specifying if the profile is to be used for
1058
+ input, output, or proof
1059
+
1060
+ INPUT = 0 (or use ImageCms.Direction.INPUT)
1061
+ OUTPUT = 1 (or use ImageCms.Direction.OUTPUT)
1062
+ PROOF = 2 (or use ImageCms.Direction.PROOF)
1063
+
1064
+ :returns: 1 if the intent/direction are supported, -1 if they are not.
1065
+ :exception PyCMSError:
1066
+ """
1067
+
1068
+ try:
1069
+ if not isinstance(profile, ImageCmsProfile):
1070
+ profile = ImageCmsProfile(profile)
1071
+ # FIXME: I get different results for the same data w. different
1072
+ # compilers. Bug in LittleCMS or in the binding?
1073
+ if profile.profile.is_intent_supported(intent, direction):
1074
+ return 1
1075
+ else:
1076
+ return -1
1077
+ except (AttributeError, OSError, TypeError, ValueError) as v:
1078
+ raise PyCMSError(v) from v