@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,103 @@
1
+ #
2
+ # The Python Imaging Library.
3
+ # $Id$
4
+ #
5
+ # IM Tools support for PIL
6
+ #
7
+ # history:
8
+ # 1996-05-27 fl Created (read 8-bit images only)
9
+ # 2001-02-17 fl Use 're' instead of 'regex' (Python 2.1) (0.2)
10
+ #
11
+ # Copyright (c) Secret Labs AB 1997-2001.
12
+ # Copyright (c) Fredrik Lundh 1996-2001.
13
+ #
14
+ # See the README file for information on usage and redistribution.
15
+ #
16
+ from __future__ import annotations
17
+
18
+ import re
19
+
20
+ from . import Image, ImageFile
21
+
22
+ #
23
+ # --------------------------------------------------------------------
24
+
25
+ field = re.compile(rb"([a-z]*) ([^ \r\n]*)")
26
+
27
+
28
+ ##
29
+ # Image plugin for IM Tools images.
30
+
31
+
32
+ class ImtImageFile(ImageFile.ImageFile):
33
+ format = "IMT"
34
+ format_description = "IM Tools"
35
+
36
+ def _open(self) -> None:
37
+ # Quick rejection: if there's not a LF among the first
38
+ # 100 bytes, this is (probably) not a text header.
39
+
40
+ assert self.fp is not None
41
+
42
+ buffer = self.fp.read(100)
43
+ if b"\n" not in buffer:
44
+ msg = "not an IM file"
45
+ raise SyntaxError(msg)
46
+
47
+ xsize = ysize = 0
48
+
49
+ while True:
50
+ if buffer:
51
+ s = buffer[:1]
52
+ buffer = buffer[1:]
53
+ else:
54
+ s = self.fp.read(1)
55
+ if not s:
56
+ break
57
+
58
+ if s == b"\x0c":
59
+ # image data begins
60
+ self.tile = [
61
+ ImageFile._Tile(
62
+ "raw",
63
+ (0, 0) + self.size,
64
+ self.fp.tell() - len(buffer),
65
+ self.mode,
66
+ )
67
+ ]
68
+
69
+ break
70
+
71
+ else:
72
+ # read key/value pair
73
+ if b"\n" not in buffer:
74
+ buffer += self.fp.read(100)
75
+ lines = buffer.split(b"\n")
76
+ s += lines.pop(0)
77
+ buffer = b"\n".join(lines)
78
+ if len(s) == 1 or len(s) > 100:
79
+ break
80
+ if s[0] == ord(b"*"):
81
+ continue # comment
82
+
83
+ m = field.match(s)
84
+ if not m:
85
+ break
86
+ k, v = m.group(1, 2)
87
+ if k == b"width":
88
+ xsize = int(v)
89
+ self._size = xsize, ysize
90
+ elif k == b"height":
91
+ ysize = int(v)
92
+ self._size = xsize, ysize
93
+ elif k == b"pixel" and v == b"n8":
94
+ self._mode = "L"
95
+
96
+
97
+ #
98
+ # --------------------------------------------------------------------
99
+
100
+ Image.register_open(ImtImageFile.format, ImtImageFile)
101
+
102
+ #
103
+ # no extension registered (".im" is simply too common)
@@ -0,0 +1,226 @@
1
+ #
2
+ # The Python Imaging Library.
3
+ # $Id$
4
+ #
5
+ # IPTC/NAA file handling
6
+ #
7
+ # history:
8
+ # 1995-10-01 fl Created
9
+ # 1998-03-09 fl Cleaned up and added to PIL
10
+ # 2002-06-18 fl Added getiptcinfo helper
11
+ #
12
+ # Copyright (c) Secret Labs AB 1997-2002.
13
+ # Copyright (c) Fredrik Lundh 1995.
14
+ #
15
+ # See the README file for information on usage and redistribution.
16
+ #
17
+ from __future__ import annotations
18
+
19
+ from io import BytesIO
20
+ from typing import cast
21
+
22
+ from . import Image, ImageFile
23
+ from ._binary import i16be as i16
24
+ from ._binary import i32be as i32
25
+
26
+ COMPRESSION = {1: "raw", 5: "jpeg"}
27
+
28
+
29
+ #
30
+ # Helpers
31
+
32
+
33
+ def _i(c: bytes) -> int:
34
+ return i32((b"\0\0\0\0" + c)[-4:])
35
+
36
+
37
+ ##
38
+ # Image plugin for IPTC/NAA datastreams. To read IPTC/NAA fields
39
+ # from TIFF and JPEG files, use the <b>getiptcinfo</b> function.
40
+
41
+
42
+ class IptcImageFile(ImageFile.ImageFile):
43
+ format = "IPTC"
44
+ format_description = "IPTC/NAA"
45
+
46
+ def getint(self, key: tuple[int, int]) -> int:
47
+ return _i(self.info[key])
48
+
49
+ def field(self) -> tuple[tuple[int, int] | None, int]:
50
+ #
51
+ # get a IPTC field header
52
+ assert self.fp is not None
53
+ s = self.fp.read(5)
54
+ if not s.strip(b"\x00"):
55
+ return None, 0
56
+
57
+ tag = s[1], s[2]
58
+
59
+ # syntax
60
+ if s[0] != 0x1C or tag[0] not in [1, 2, 3, 4, 5, 6, 7, 8, 9, 240]:
61
+ msg = "invalid IPTC/NAA file"
62
+ raise SyntaxError(msg)
63
+
64
+ # field size
65
+ size = s[3]
66
+ if size > 132:
67
+ msg = "illegal field length in IPTC/NAA file"
68
+ raise OSError(msg)
69
+ elif size == 128:
70
+ size = 0
71
+ elif size > 128:
72
+ size = _i(self.fp.read(size - 128))
73
+ else:
74
+ size = i16(s, 3)
75
+
76
+ return tag, size
77
+
78
+ def _open(self) -> None:
79
+ # load descriptive fields
80
+ assert self.fp is not None
81
+ while True:
82
+ offset = self.fp.tell()
83
+ tag, size = self.field()
84
+ if not tag or tag == (8, 10):
85
+ break
86
+ if size:
87
+ tagdata = self.fp.read(size)
88
+ else:
89
+ tagdata = None
90
+ if tag in self.info:
91
+ if isinstance(self.info[tag], list):
92
+ self.info[tag].append(tagdata)
93
+ else:
94
+ self.info[tag] = [self.info[tag], tagdata]
95
+ else:
96
+ self.info[tag] = tagdata
97
+
98
+ # mode
99
+ layers = self.info[(3, 60)][0]
100
+ component = self.info[(3, 60)][1]
101
+ if layers == 1 and not component:
102
+ self._mode = "L"
103
+ band = None
104
+ else:
105
+ if layers == 3 and component:
106
+ self._mode = "RGB"
107
+ elif layers == 4 and component:
108
+ self._mode = "CMYK"
109
+ if (3, 65) in self.info:
110
+ band = self.info[(3, 65)][0] - 1
111
+ else:
112
+ band = 0
113
+
114
+ # size
115
+ self._size = self.getint((3, 20)), self.getint((3, 30))
116
+
117
+ # compression
118
+ try:
119
+ compression = COMPRESSION[self.getint((3, 120))]
120
+ except KeyError as e:
121
+ msg = "Unknown IPTC image compression"
122
+ raise OSError(msg) from e
123
+
124
+ # tile
125
+ if tag == (8, 10):
126
+ self.tile = [
127
+ ImageFile._Tile("iptc", (0, 0) + self.size, offset, (compression, band))
128
+ ]
129
+
130
+ def load(self) -> Image.core.PixelAccess | None:
131
+ if self.tile:
132
+ args = self.tile[0].args
133
+ assert isinstance(args, tuple)
134
+ compression, band = args
135
+
136
+ assert self.fp is not None
137
+ self.fp.seek(self.tile[0].offset)
138
+
139
+ # Copy image data to temporary file
140
+ o = BytesIO()
141
+ if compression == "raw":
142
+ # To simplify access to the extracted file,
143
+ # prepend a PPM header
144
+ o.write(b"P5\n%d %d\n255\n" % self.size)
145
+ while True:
146
+ type, size = self.field()
147
+ if type != (8, 10):
148
+ break
149
+ while size > 0:
150
+ s = self.fp.read(min(size, 8192))
151
+ if not s:
152
+ break
153
+ o.write(s)
154
+ size -= len(s)
155
+
156
+ with Image.open(o) as _im:
157
+ if band is not None:
158
+ bands = [Image.new("L", _im.size)] * Image.getmodebands(self.mode)
159
+ bands[band] = _im
160
+ im = Image.merge(self.mode, bands)
161
+ else:
162
+ im = _im
163
+ im.load()
164
+ self.im = im.im
165
+ self.tile = []
166
+ return ImageFile.ImageFile.load(self)
167
+
168
+
169
+ Image.register_open(IptcImageFile.format, IptcImageFile)
170
+
171
+ Image.register_extension(IptcImageFile.format, ".iim")
172
+
173
+
174
+ def getiptcinfo(
175
+ im: ImageFile.ImageFile,
176
+ ) -> dict[tuple[int, int], bytes | list[bytes]] | None:
177
+ """
178
+ Get IPTC information from TIFF, JPEG, or IPTC file.
179
+
180
+ :param im: An image containing IPTC data.
181
+ :returns: A dictionary containing IPTC information, or None if
182
+ no IPTC information block was found.
183
+ """
184
+ from . import JpegImagePlugin, TiffImagePlugin
185
+
186
+ data = None
187
+
188
+ if isinstance(im, IptcImageFile):
189
+ # return info dictionary right away
190
+ return {k: v for k, v in im.info.items() if isinstance(k, tuple)}
191
+
192
+ elif isinstance(im, JpegImagePlugin.JpegImageFile):
193
+ # extract the IPTC/NAA resource
194
+ photoshop = im.info.get("photoshop")
195
+ if photoshop:
196
+ data = photoshop.get(0x0404)
197
+
198
+ elif isinstance(im, TiffImagePlugin.TiffImageFile):
199
+ # get raw data from the IPTC/NAA tag (PhotoShop tags the data
200
+ # as 4-byte integers, so we cannot use the get method...)
201
+ try:
202
+ data = im.tag_v2._tagdata[TiffImagePlugin.IPTC_NAA_CHUNK]
203
+ except KeyError:
204
+ pass
205
+
206
+ if data is None:
207
+ return None # no properties
208
+
209
+ # create an IptcImagePlugin object without initializing it
210
+ class FakeImage:
211
+ pass
212
+
213
+ fake_im = FakeImage()
214
+ fake_im.__class__ = IptcImageFile # type: ignore[assignment]
215
+ iptc_im = cast(IptcImageFile, fake_im)
216
+
217
+ # parse the IPTC information chunk
218
+ iptc_im.info = {}
219
+ iptc_im.fp = BytesIO(data)
220
+
221
+ try:
222
+ iptc_im._open()
223
+ except (IndexError, KeyError):
224
+ pass # expected failure
225
+
226
+ return {k: v for k, v in iptc_im.info.items() if isinstance(k, tuple)}