@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.
- package/LICENSE +30 -0
- package/README.md +4 -0
- package/lib/python3.14/site-packages/PIL/AvifImagePlugin.py +295 -0
- package/lib/python3.14/site-packages/PIL/BdfFontFile.py +124 -0
- package/lib/python3.14/site-packages/PIL/BlpImagePlugin.py +498 -0
- package/lib/python3.14/site-packages/PIL/BmpImagePlugin.py +514 -0
- package/lib/python3.14/site-packages/PIL/BufrStubImagePlugin.py +72 -0
- package/lib/python3.14/site-packages/PIL/ContainerIO.py +173 -0
- package/lib/python3.14/site-packages/PIL/CurImagePlugin.py +103 -0
- package/lib/python3.14/site-packages/PIL/DcxImagePlugin.py +84 -0
- package/lib/python3.14/site-packages/PIL/DdsImagePlugin.py +632 -0
- package/lib/python3.14/site-packages/PIL/EpsImagePlugin.py +484 -0
- package/lib/python3.14/site-packages/PIL/ExifTags.py +384 -0
- package/lib/python3.14/site-packages/PIL/FitsImagePlugin.py +153 -0
- package/lib/python3.14/site-packages/PIL/FliImagePlugin.py +184 -0
- package/lib/python3.14/site-packages/PIL/FontFile.py +160 -0
- package/lib/python3.14/site-packages/PIL/FpxImagePlugin.py +262 -0
- package/lib/python3.14/site-packages/PIL/FtexImagePlugin.py +115 -0
- package/lib/python3.14/site-packages/PIL/GbrImagePlugin.py +103 -0
- package/lib/python3.14/site-packages/PIL/GdImageFile.py +104 -0
- package/lib/python3.14/site-packages/PIL/GifImagePlugin.py +1223 -0
- package/lib/python3.14/site-packages/PIL/GimpGradientFile.py +154 -0
- package/lib/python3.14/site-packages/PIL/GimpPaletteFile.py +75 -0
- package/lib/python3.14/site-packages/PIL/GribStubImagePlugin.py +72 -0
- package/lib/python3.14/site-packages/PIL/Hdf5StubImagePlugin.py +72 -0
- package/lib/python3.14/site-packages/PIL/IcnsImagePlugin.py +401 -0
- package/lib/python3.14/site-packages/PIL/IcoImagePlugin.py +396 -0
- package/lib/python3.14/site-packages/PIL/ImImagePlugin.py +390 -0
- package/lib/python3.14/site-packages/PIL/Image.py +4385 -0
- package/lib/python3.14/site-packages/PIL/ImageChops.py +311 -0
- package/lib/python3.14/site-packages/PIL/ImageCms.py +1078 -0
- package/lib/python3.14/site-packages/PIL/ImageColor.py +320 -0
- package/lib/python3.14/site-packages/PIL/ImageDraw.py +1002 -0
- package/lib/python3.14/site-packages/PIL/ImageDraw2.py +244 -0
- package/lib/python3.14/site-packages/PIL/ImageEnhance.py +113 -0
- package/lib/python3.14/site-packages/PIL/ImageFile.py +938 -0
- package/lib/python3.14/site-packages/PIL/ImageFilter.py +617 -0
- package/lib/python3.14/site-packages/PIL/ImageFont.py +1330 -0
- package/lib/python3.14/site-packages/PIL/ImageGrab.py +234 -0
- package/lib/python3.14/site-packages/PIL/ImageMath.py +314 -0
- package/lib/python3.14/site-packages/PIL/ImageMode.py +85 -0
- package/lib/python3.14/site-packages/PIL/ImageMorph.py +317 -0
- package/lib/python3.14/site-packages/PIL/ImageOps.py +749 -0
- package/lib/python3.14/site-packages/PIL/ImagePalette.py +290 -0
- package/lib/python3.14/site-packages/PIL/ImagePath.py +20 -0
- package/lib/python3.14/site-packages/PIL/ImageQt.py +219 -0
- package/lib/python3.14/site-packages/PIL/ImageSequence.py +88 -0
- package/lib/python3.14/site-packages/PIL/ImageShow.py +367 -0
- package/lib/python3.14/site-packages/PIL/ImageStat.py +167 -0
- package/lib/python3.14/site-packages/PIL/ImageText.py +509 -0
- package/lib/python3.14/site-packages/PIL/ImageTk.py +266 -0
- package/lib/python3.14/site-packages/PIL/ImageTransform.py +136 -0
- package/lib/python3.14/site-packages/PIL/ImageWin.py +247 -0
- package/lib/python3.14/site-packages/PIL/ImtImagePlugin.py +103 -0
- package/lib/python3.14/site-packages/PIL/IptcImagePlugin.py +226 -0
- package/lib/python3.14/site-packages/PIL/Jpeg2KImagePlugin.py +466 -0
- package/lib/python3.14/site-packages/PIL/JpegImagePlugin.py +889 -0
- package/lib/python3.14/site-packages/PIL/JpegPresets.py +242 -0
- package/lib/python3.14/site-packages/PIL/McIdasImagePlugin.py +78 -0
- package/lib/python3.14/site-packages/PIL/MicImagePlugin.py +103 -0
- package/lib/python3.14/site-packages/PIL/MpegImagePlugin.py +84 -0
- package/lib/python3.14/site-packages/PIL/MpoImagePlugin.py +203 -0
- package/lib/python3.14/site-packages/PIL/MspImagePlugin.py +200 -0
- package/lib/python3.14/site-packages/PIL/PSDraw.py +238 -0
- package/lib/python3.14/site-packages/PIL/PaletteFile.py +54 -0
- package/lib/python3.14/site-packages/PIL/PalmImagePlugin.py +217 -0
- package/lib/python3.14/site-packages/PIL/PcdImagePlugin.py +68 -0
- package/lib/python3.14/site-packages/PIL/PcfFontFile.py +256 -0
- package/lib/python3.14/site-packages/PIL/PcxImagePlugin.py +232 -0
- package/lib/python3.14/site-packages/PIL/PdfImagePlugin.py +315 -0
- package/lib/python3.14/site-packages/PIL/PdfParser.py +1092 -0
- package/lib/python3.14/site-packages/PIL/PixarImagePlugin.py +72 -0
- package/lib/python3.14/site-packages/PIL/PngImagePlugin.py +1578 -0
- package/lib/python3.14/site-packages/PIL/PpmImagePlugin.py +375 -0
- package/lib/python3.14/site-packages/PIL/PsdImagePlugin.py +339 -0
- package/lib/python3.14/site-packages/PIL/QoiImagePlugin.py +235 -0
- package/lib/python3.14/site-packages/PIL/SgiImagePlugin.py +231 -0
- package/lib/python3.14/site-packages/PIL/SpiderImagePlugin.py +332 -0
- package/lib/python3.14/site-packages/PIL/SunImagePlugin.py +145 -0
- package/lib/python3.14/site-packages/PIL/TarIO.py +61 -0
- package/lib/python3.14/site-packages/PIL/TgaImagePlugin.py +284 -0
- package/lib/python3.14/site-packages/PIL/TiffImagePlugin.py +2354 -0
- package/lib/python3.14/site-packages/PIL/TiffTags.py +566 -0
- package/lib/python3.14/site-packages/PIL/WalImageFile.py +129 -0
- package/lib/python3.14/site-packages/PIL/WebPImagePlugin.py +322 -0
- package/lib/python3.14/site-packages/PIL/WmfImagePlugin.py +183 -0
- package/lib/python3.14/site-packages/PIL/XVThumbImagePlugin.py +83 -0
- package/lib/python3.14/site-packages/PIL/XbmImagePlugin.py +98 -0
- package/lib/python3.14/site-packages/PIL/XpmImagePlugin.py +157 -0
- package/lib/python3.14/site-packages/PIL/__init__.py +87 -0
- package/lib/python3.14/site-packages/PIL/__main__.py +7 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/AvifImagePlugin.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/BdfFontFile.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/BlpImagePlugin.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/BmpImagePlugin.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/BufrStubImagePlugin.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/ContainerIO.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/CurImagePlugin.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/DcxImagePlugin.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/DdsImagePlugin.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/EpsImagePlugin.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/ExifTags.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/FitsImagePlugin.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/FliImagePlugin.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/FontFile.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/FpxImagePlugin.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/FtexImagePlugin.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/GbrImagePlugin.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/GdImageFile.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/GifImagePlugin.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/GimpGradientFile.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/GimpPaletteFile.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/GribStubImagePlugin.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/Hdf5StubImagePlugin.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/IcnsImagePlugin.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/IcoImagePlugin.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/ImImagePlugin.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/Image.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/ImageChops.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/ImageCms.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/ImageColor.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/ImageDraw.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/ImageDraw2.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/ImageEnhance.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/ImageFile.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/ImageFilter.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/ImageFont.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/ImageGrab.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/ImageMath.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/ImageMode.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/ImageMorph.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/ImageOps.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/ImagePalette.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/ImagePath.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/ImageQt.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/ImageSequence.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/ImageShow.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/ImageStat.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/ImageText.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/ImageTk.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/ImageTransform.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/ImageWin.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/ImtImagePlugin.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/IptcImagePlugin.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/Jpeg2KImagePlugin.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/JpegImagePlugin.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/JpegPresets.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/McIdasImagePlugin.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/MicImagePlugin.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/MpegImagePlugin.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/MpoImagePlugin.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/MspImagePlugin.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/PSDraw.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/PaletteFile.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/PalmImagePlugin.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/PcdImagePlugin.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/PcfFontFile.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/PcxImagePlugin.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/PdfImagePlugin.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/PdfParser.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/PixarImagePlugin.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/PngImagePlugin.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/PpmImagePlugin.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/PsdImagePlugin.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/QoiImagePlugin.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/SgiImagePlugin.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/SpiderImagePlugin.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/SunImagePlugin.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/TarIO.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/TgaImagePlugin.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/TiffImagePlugin.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/TiffTags.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/WalImageFile.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/WebPImagePlugin.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/WmfImagePlugin.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/XVThumbImagePlugin.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/XbmImagePlugin.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/XpmImagePlugin.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/__init__.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/__main__.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/_binary.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/_deprecate.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/_tkinter_finder.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/_typing.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/_util.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/_version.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/features.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/__pycache__/report.cpython-314.pyc +0 -0
- package/lib/python3.14/site-packages/PIL/_avif.pyi +3 -0
- package/lib/python3.14/site-packages/PIL/_binary.py +113 -0
- package/lib/python3.14/site-packages/PIL/_deprecate.py +72 -0
- package/lib/python3.14/site-packages/PIL/_imaging.cpython-314-wasm32-wasix.so +0 -0
- package/lib/python3.14/site-packages/PIL/_imaging.pyi +31 -0
- package/lib/python3.14/site-packages/PIL/_imagingcms.pyi +143 -0
- package/lib/python3.14/site-packages/PIL/_imagingft.cpython-314-wasm32-wasix.so +0 -0
- package/lib/python3.14/site-packages/PIL/_imagingft.pyi +70 -0
- package/lib/python3.14/site-packages/PIL/_imagingmath.cpython-314-wasm32-wasix.so +0 -0
- package/lib/python3.14/site-packages/PIL/_imagingmath.pyi +3 -0
- package/lib/python3.14/site-packages/PIL/_imagingmorph.cpython-314-wasm32-wasix.so +0 -0
- package/lib/python3.14/site-packages/PIL/_imagingmorph.pyi +3 -0
- package/lib/python3.14/site-packages/PIL/_imagingtk.cpython-314-wasm32-wasix.so +0 -0
- package/lib/python3.14/site-packages/PIL/_imagingtk.pyi +3 -0
- package/lib/python3.14/site-packages/PIL/_tkinter_finder.py +20 -0
- package/lib/python3.14/site-packages/PIL/_typing.py +45 -0
- package/lib/python3.14/site-packages/PIL/_util.py +29 -0
- package/lib/python3.14/site-packages/PIL/_version.py +4 -0
- package/lib/python3.14/site-packages/PIL/_webp.pyi +3 -0
- package/lib/python3.14/site-packages/PIL/features.py +343 -0
- package/lib/python3.14/site-packages/PIL/py.typed +0 -0
- package/lib/python3.14/site-packages/PIL/report.py +5 -0
- package/lib/python3.14/site-packages/pillow-12.3.0.dist-info/METADATA +180 -0
- package/lib/python3.14/site-packages/pillow-12.3.0.dist-info/RECORD +117 -0
- package/lib/python3.14/site-packages/pillow-12.3.0.dist-info/WHEEL +5 -0
- package/lib/python3.14/site-packages/pillow-12.3.0.dist-info/licenses/LICENSE +30 -0
- package/lib/python3.14/site-packages/pillow-12.3.0.dist-info/top_level.txt +1 -0
- package/lib/python3.14/site-packages/pillow-12.3.0.dist-info/zip-safe +1 -0
- package/package.json +46 -0
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
#
|
|
2
|
+
# The Python Imaging Library.
|
|
3
|
+
# $Id$
|
|
4
|
+
#
|
|
5
|
+
# a Tk display interface
|
|
6
|
+
#
|
|
7
|
+
# History:
|
|
8
|
+
# 96-04-08 fl Created
|
|
9
|
+
# 96-09-06 fl Added getimage method
|
|
10
|
+
# 96-11-01 fl Rewritten, removed image attribute and crop method
|
|
11
|
+
# 97-05-09 fl Use PyImagingPaste method instead of image type
|
|
12
|
+
# 97-05-12 fl Minor tweaks to match the IFUNC95 interface
|
|
13
|
+
# 97-05-17 fl Support the "pilbitmap" booster patch
|
|
14
|
+
# 97-06-05 fl Added file= and data= argument to image constructors
|
|
15
|
+
# 98-03-09 fl Added width and height methods to Image classes
|
|
16
|
+
# 98-07-02 fl Use default mode for "P" images without palette attribute
|
|
17
|
+
# 98-07-02 fl Explicitly destroy Tkinter image objects
|
|
18
|
+
# 99-07-24 fl Support multiple Tk interpreters (from Greg Couch)
|
|
19
|
+
# 99-07-26 fl Automatically hook into Tkinter (if possible)
|
|
20
|
+
# 99-08-15 fl Hook uses _imagingtk instead of _imaging
|
|
21
|
+
#
|
|
22
|
+
# Copyright (c) 1997-1999 by Secret Labs AB
|
|
23
|
+
# Copyright (c) 1996-1997 by Fredrik Lundh
|
|
24
|
+
#
|
|
25
|
+
# See the README file for information on usage and redistribution.
|
|
26
|
+
#
|
|
27
|
+
from __future__ import annotations
|
|
28
|
+
|
|
29
|
+
import tkinter
|
|
30
|
+
from io import BytesIO
|
|
31
|
+
from typing import Any
|
|
32
|
+
|
|
33
|
+
from . import Image, ImageFile
|
|
34
|
+
|
|
35
|
+
TYPE_CHECKING = False
|
|
36
|
+
if TYPE_CHECKING:
|
|
37
|
+
from ._typing import CapsuleType
|
|
38
|
+
|
|
39
|
+
# --------------------------------------------------------------------
|
|
40
|
+
# Check for Tkinter interface hooks
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _get_image_from_kw(kw: dict[str, Any]) -> ImageFile.ImageFile | None:
|
|
44
|
+
source = None
|
|
45
|
+
if "file" in kw:
|
|
46
|
+
source = kw.pop("file")
|
|
47
|
+
elif "data" in kw:
|
|
48
|
+
source = BytesIO(kw.pop("data"))
|
|
49
|
+
if not source:
|
|
50
|
+
return None
|
|
51
|
+
return Image.open(source)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _pyimagingtkcall(
|
|
55
|
+
command: str, photo: PhotoImage | tkinter.PhotoImage, ptr: CapsuleType
|
|
56
|
+
) -> None:
|
|
57
|
+
tk = photo.tk
|
|
58
|
+
try:
|
|
59
|
+
tk.call(command, photo, repr(ptr))
|
|
60
|
+
except tkinter.TclError:
|
|
61
|
+
# activate Tkinter hook
|
|
62
|
+
# may raise an error if it cannot attach to Tkinter
|
|
63
|
+
from . import _imagingtk
|
|
64
|
+
|
|
65
|
+
_imagingtk.tkinit(tk.interpaddr())
|
|
66
|
+
tk.call(command, photo, repr(ptr))
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
# --------------------------------------------------------------------
|
|
70
|
+
# PhotoImage
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class PhotoImage:
|
|
74
|
+
"""
|
|
75
|
+
A Tkinter-compatible photo image. This can be used
|
|
76
|
+
everywhere Tkinter expects an image object. If the image is an RGBA
|
|
77
|
+
image, pixels having alpha 0 are treated as transparent.
|
|
78
|
+
|
|
79
|
+
The constructor takes either a PIL image, or a mode and a size.
|
|
80
|
+
Alternatively, you can use the ``file`` or ``data`` options to initialize
|
|
81
|
+
the photo image object.
|
|
82
|
+
|
|
83
|
+
:param image: Either a PIL image, or a mode string. If a mode string is
|
|
84
|
+
used, a size must also be given.
|
|
85
|
+
:param size: If the first argument is a mode string, this defines the size
|
|
86
|
+
of the image.
|
|
87
|
+
:keyword file: A filename to load the image from (using
|
|
88
|
+
``Image.open(file)``).
|
|
89
|
+
:keyword data: An 8-bit string containing image data (as loaded from an
|
|
90
|
+
image file).
|
|
91
|
+
"""
|
|
92
|
+
|
|
93
|
+
def __init__(
|
|
94
|
+
self,
|
|
95
|
+
image: Image.Image | str | None = None,
|
|
96
|
+
size: tuple[int, int] | None = None,
|
|
97
|
+
**kw: Any,
|
|
98
|
+
) -> None:
|
|
99
|
+
# Tk compatibility: file or data
|
|
100
|
+
if image is None:
|
|
101
|
+
image = _get_image_from_kw(kw)
|
|
102
|
+
|
|
103
|
+
if image is None:
|
|
104
|
+
msg = "Image is required"
|
|
105
|
+
raise ValueError(msg)
|
|
106
|
+
elif isinstance(image, str):
|
|
107
|
+
mode = image
|
|
108
|
+
image = None
|
|
109
|
+
|
|
110
|
+
if size is None:
|
|
111
|
+
msg = "If first argument is mode, size is required"
|
|
112
|
+
raise ValueError(msg)
|
|
113
|
+
else:
|
|
114
|
+
# got an image instead of a mode
|
|
115
|
+
mode = image.mode
|
|
116
|
+
if mode == "P":
|
|
117
|
+
# palette mapped data
|
|
118
|
+
image.apply_transparency()
|
|
119
|
+
image.load()
|
|
120
|
+
mode = image.palette.mode if image.palette else "RGB"
|
|
121
|
+
size = image.size
|
|
122
|
+
kw["width"], kw["height"] = size
|
|
123
|
+
|
|
124
|
+
if mode not in ["1", "L", "RGB", "RGBA"]:
|
|
125
|
+
mode = Image.getmodebase(mode)
|
|
126
|
+
|
|
127
|
+
self.__mode = mode
|
|
128
|
+
self.__size = size
|
|
129
|
+
self.__photo = tkinter.PhotoImage(**kw)
|
|
130
|
+
self.tk = self.__photo.tk
|
|
131
|
+
if image:
|
|
132
|
+
self.paste(image)
|
|
133
|
+
|
|
134
|
+
def __del__(self) -> None:
|
|
135
|
+
try:
|
|
136
|
+
name = self.__photo.name
|
|
137
|
+
except AttributeError:
|
|
138
|
+
return
|
|
139
|
+
self.__photo.name = None
|
|
140
|
+
try:
|
|
141
|
+
self.__photo.tk.call("image", "delete", name)
|
|
142
|
+
except Exception:
|
|
143
|
+
pass # ignore internal errors
|
|
144
|
+
|
|
145
|
+
def __str__(self) -> str:
|
|
146
|
+
"""
|
|
147
|
+
Get the Tkinter photo image identifier. This method is automatically
|
|
148
|
+
called by Tkinter whenever a PhotoImage object is passed to a Tkinter
|
|
149
|
+
method.
|
|
150
|
+
|
|
151
|
+
:return: A Tkinter photo image identifier (a string).
|
|
152
|
+
"""
|
|
153
|
+
return str(self.__photo)
|
|
154
|
+
|
|
155
|
+
def width(self) -> int:
|
|
156
|
+
"""
|
|
157
|
+
Get the width of the image.
|
|
158
|
+
|
|
159
|
+
:return: The width, in pixels.
|
|
160
|
+
"""
|
|
161
|
+
return self.__size[0]
|
|
162
|
+
|
|
163
|
+
def height(self) -> int:
|
|
164
|
+
"""
|
|
165
|
+
Get the height of the image.
|
|
166
|
+
|
|
167
|
+
:return: The height, in pixels.
|
|
168
|
+
"""
|
|
169
|
+
return self.__size[1]
|
|
170
|
+
|
|
171
|
+
def paste(self, im: Image.Image) -> None:
|
|
172
|
+
"""
|
|
173
|
+
Paste a PIL image into the photo image. Note that this can
|
|
174
|
+
be very slow if the photo image is displayed.
|
|
175
|
+
|
|
176
|
+
:param im: A PIL image. The size must match the target region. If the
|
|
177
|
+
mode does not match, the image is converted to the mode of
|
|
178
|
+
the bitmap image.
|
|
179
|
+
"""
|
|
180
|
+
# convert to blittable
|
|
181
|
+
ptr = im.getim()
|
|
182
|
+
image = im.im
|
|
183
|
+
if not image.isblock() or im.mode != self.__mode:
|
|
184
|
+
block = Image.core.new_block(self.__mode, im.size)
|
|
185
|
+
image.convert2(block, image) # convert directly between buffers
|
|
186
|
+
ptr = block.ptr
|
|
187
|
+
|
|
188
|
+
_pyimagingtkcall("PyImagingPhoto", self.__photo, ptr)
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
# --------------------------------------------------------------------
|
|
192
|
+
# BitmapImage
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
class BitmapImage:
|
|
196
|
+
"""
|
|
197
|
+
A Tkinter-compatible bitmap image. This can be used everywhere Tkinter
|
|
198
|
+
expects an image object.
|
|
199
|
+
|
|
200
|
+
The given image must have mode "1". Pixels having value 0 are treated as
|
|
201
|
+
transparent. Options, if any, are passed on to Tkinter. The most commonly
|
|
202
|
+
used option is ``foreground``, which is used to specify the color for the
|
|
203
|
+
non-transparent parts. See the Tkinter documentation for information on
|
|
204
|
+
how to specify colours.
|
|
205
|
+
|
|
206
|
+
:param image: A PIL image.
|
|
207
|
+
"""
|
|
208
|
+
|
|
209
|
+
def __init__(self, image: Image.Image | None = None, **kw: Any) -> None:
|
|
210
|
+
# Tk compatibility: file or data
|
|
211
|
+
if image is None:
|
|
212
|
+
image = _get_image_from_kw(kw)
|
|
213
|
+
|
|
214
|
+
if image is None:
|
|
215
|
+
msg = "Image is required"
|
|
216
|
+
raise ValueError(msg)
|
|
217
|
+
self.__mode = image.mode
|
|
218
|
+
self.__size = image.size
|
|
219
|
+
|
|
220
|
+
self.__photo = tkinter.BitmapImage(data=image.tobitmap(), **kw)
|
|
221
|
+
|
|
222
|
+
def __del__(self) -> None:
|
|
223
|
+
try:
|
|
224
|
+
name = self.__photo.name
|
|
225
|
+
except AttributeError:
|
|
226
|
+
return
|
|
227
|
+
self.__photo.name = None
|
|
228
|
+
try:
|
|
229
|
+
self.__photo.tk.call("image", "delete", name)
|
|
230
|
+
except Exception:
|
|
231
|
+
pass # ignore internal errors
|
|
232
|
+
|
|
233
|
+
def width(self) -> int:
|
|
234
|
+
"""
|
|
235
|
+
Get the width of the image.
|
|
236
|
+
|
|
237
|
+
:return: The width, in pixels.
|
|
238
|
+
"""
|
|
239
|
+
return self.__size[0]
|
|
240
|
+
|
|
241
|
+
def height(self) -> int:
|
|
242
|
+
"""
|
|
243
|
+
Get the height of the image.
|
|
244
|
+
|
|
245
|
+
:return: The height, in pixels.
|
|
246
|
+
"""
|
|
247
|
+
return self.__size[1]
|
|
248
|
+
|
|
249
|
+
def __str__(self) -> str:
|
|
250
|
+
"""
|
|
251
|
+
Get the Tkinter bitmap image identifier. This method is automatically
|
|
252
|
+
called by Tkinter whenever a BitmapImage object is passed to a Tkinter
|
|
253
|
+
method.
|
|
254
|
+
|
|
255
|
+
:return: A Tkinter bitmap image identifier (a string).
|
|
256
|
+
"""
|
|
257
|
+
return str(self.__photo)
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
def getimage(photo: PhotoImage) -> Image.Image:
|
|
261
|
+
"""Copies the contents of a PhotoImage to a PIL image memory."""
|
|
262
|
+
im = Image.new("RGBA", (photo.width(), photo.height()))
|
|
263
|
+
|
|
264
|
+
_pyimagingtkcall("PyImagingPhotoGet", photo, im.getim())
|
|
265
|
+
|
|
266
|
+
return im
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
#
|
|
2
|
+
# The Python Imaging Library.
|
|
3
|
+
# $Id$
|
|
4
|
+
#
|
|
5
|
+
# transform wrappers
|
|
6
|
+
#
|
|
7
|
+
# History:
|
|
8
|
+
# 2002-04-08 fl Created
|
|
9
|
+
#
|
|
10
|
+
# Copyright (c) 2002 by Secret Labs AB
|
|
11
|
+
# Copyright (c) 2002 by Fredrik Lundh
|
|
12
|
+
#
|
|
13
|
+
# See the README file for information on usage and redistribution.
|
|
14
|
+
#
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
from collections.abc import Sequence
|
|
18
|
+
from typing import Any
|
|
19
|
+
|
|
20
|
+
from . import Image
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class Transform(Image.ImageTransformHandler):
|
|
24
|
+
"""Base class for other transforms defined in :py:mod:`~PIL.ImageTransform`."""
|
|
25
|
+
|
|
26
|
+
method: Image.Transform
|
|
27
|
+
|
|
28
|
+
def __init__(self, data: Sequence[Any]) -> None:
|
|
29
|
+
self.data = data
|
|
30
|
+
|
|
31
|
+
def getdata(self) -> tuple[Image.Transform, Sequence[int]]:
|
|
32
|
+
return self.method, self.data
|
|
33
|
+
|
|
34
|
+
def transform(
|
|
35
|
+
self,
|
|
36
|
+
size: tuple[int, int],
|
|
37
|
+
image: Image.Image,
|
|
38
|
+
**options: Any,
|
|
39
|
+
) -> Image.Image:
|
|
40
|
+
"""Perform the transform. Called from :py:meth:`.Image.transform`."""
|
|
41
|
+
# can be overridden
|
|
42
|
+
method, data = self.getdata()
|
|
43
|
+
return image.transform(size, method, data, **options)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class AffineTransform(Transform):
|
|
47
|
+
"""
|
|
48
|
+
Define an affine image transform.
|
|
49
|
+
|
|
50
|
+
This function takes a 6-tuple (a, b, c, d, e, f) which contain the first
|
|
51
|
+
two rows from the inverse of an affine transform matrix. For each pixel
|
|
52
|
+
(x, y) in the output image, the new value is taken from a position (a x +
|
|
53
|
+
b y + c, d x + e y + f) in the input image, rounded to nearest pixel.
|
|
54
|
+
|
|
55
|
+
This function can be used to scale, translate, rotate, and shear the
|
|
56
|
+
original image.
|
|
57
|
+
|
|
58
|
+
See :py:meth:`.Image.transform`
|
|
59
|
+
|
|
60
|
+
:param matrix: A 6-tuple (a, b, c, d, e, f) containing the first two rows
|
|
61
|
+
from the inverse of an affine transform matrix.
|
|
62
|
+
"""
|
|
63
|
+
|
|
64
|
+
method = Image.Transform.AFFINE
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
class PerspectiveTransform(Transform):
|
|
68
|
+
"""
|
|
69
|
+
Define a perspective image transform.
|
|
70
|
+
|
|
71
|
+
This function takes an 8-tuple (a, b, c, d, e, f, g, h). For each pixel
|
|
72
|
+
(x, y) in the output image, the new value is taken from a position
|
|
73
|
+
((a x + b y + c) / (g x + h y + 1), (d x + e y + f) / (g x + h y + 1)) in
|
|
74
|
+
the input image, rounded to nearest pixel.
|
|
75
|
+
|
|
76
|
+
This function can be used to scale, translate, rotate, and shear the
|
|
77
|
+
original image.
|
|
78
|
+
|
|
79
|
+
See :py:meth:`.Image.transform`
|
|
80
|
+
|
|
81
|
+
:param matrix: An 8-tuple (a, b, c, d, e, f, g, h).
|
|
82
|
+
"""
|
|
83
|
+
|
|
84
|
+
method = Image.Transform.PERSPECTIVE
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
class ExtentTransform(Transform):
|
|
88
|
+
"""
|
|
89
|
+
Define a transform to extract a subregion from an image.
|
|
90
|
+
|
|
91
|
+
Maps a rectangle (defined by two corners) from the image to a rectangle of
|
|
92
|
+
the given size. The resulting image will contain data sampled from between
|
|
93
|
+
the corners, such that (x0, y0) in the input image will end up at (0,0) in
|
|
94
|
+
the output image, and (x1, y1) at size.
|
|
95
|
+
|
|
96
|
+
This method can be used to crop, stretch, shrink, or mirror an arbitrary
|
|
97
|
+
rectangle in the current image. It is slightly slower than crop, but about
|
|
98
|
+
as fast as a corresponding resize operation.
|
|
99
|
+
|
|
100
|
+
See :py:meth:`.Image.transform`
|
|
101
|
+
|
|
102
|
+
:param bbox: A 4-tuple (x0, y0, x1, y1) which specifies two points in the
|
|
103
|
+
input image's coordinate system. See :ref:`coordinate-system`.
|
|
104
|
+
"""
|
|
105
|
+
|
|
106
|
+
method = Image.Transform.EXTENT
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
class QuadTransform(Transform):
|
|
110
|
+
"""
|
|
111
|
+
Define a quad image transform.
|
|
112
|
+
|
|
113
|
+
Maps a quadrilateral (a region defined by four corners) from the image to a
|
|
114
|
+
rectangle of the given size.
|
|
115
|
+
|
|
116
|
+
See :py:meth:`.Image.transform`
|
|
117
|
+
|
|
118
|
+
:param xy: An 8-tuple (x0, y0, x1, y1, x2, y2, x3, y3) which contain the
|
|
119
|
+
upper left, lower left, lower right, and upper right corner of the
|
|
120
|
+
source quadrilateral.
|
|
121
|
+
"""
|
|
122
|
+
|
|
123
|
+
method = Image.Transform.QUAD
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
class MeshTransform(Transform):
|
|
127
|
+
"""
|
|
128
|
+
Define a mesh image transform. A mesh transform consists of one or more
|
|
129
|
+
individual quad transforms.
|
|
130
|
+
|
|
131
|
+
See :py:meth:`.Image.transform`
|
|
132
|
+
|
|
133
|
+
:param data: A list of (bbox, quad) tuples.
|
|
134
|
+
"""
|
|
135
|
+
|
|
136
|
+
method = Image.Transform.MESH
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
#
|
|
2
|
+
# The Python Imaging Library.
|
|
3
|
+
# $Id$
|
|
4
|
+
#
|
|
5
|
+
# a Windows DIB display interface
|
|
6
|
+
#
|
|
7
|
+
# History:
|
|
8
|
+
# 1996-05-20 fl Created
|
|
9
|
+
# 1996-09-20 fl Fixed subregion exposure
|
|
10
|
+
# 1997-09-21 fl Added draw primitive (for tzPrint)
|
|
11
|
+
# 2003-05-21 fl Added experimental Window/ImageWindow classes
|
|
12
|
+
# 2003-09-05 fl Added fromstring/tostring methods
|
|
13
|
+
#
|
|
14
|
+
# Copyright (c) Secret Labs AB 1997-2003.
|
|
15
|
+
# Copyright (c) Fredrik Lundh 1996-2003.
|
|
16
|
+
#
|
|
17
|
+
# See the README file for information on usage and redistribution.
|
|
18
|
+
#
|
|
19
|
+
from __future__ import annotations
|
|
20
|
+
|
|
21
|
+
from . import Image
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class HDC:
|
|
25
|
+
"""
|
|
26
|
+
Wraps an HDC integer. The resulting object can be passed to the
|
|
27
|
+
:py:meth:`~PIL.ImageWin.Dib.draw` and :py:meth:`~PIL.ImageWin.Dib.expose`
|
|
28
|
+
methods.
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
def __init__(self, dc: int) -> None:
|
|
32
|
+
self.dc = dc
|
|
33
|
+
|
|
34
|
+
def __int__(self) -> int:
|
|
35
|
+
return self.dc
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class HWND:
|
|
39
|
+
"""
|
|
40
|
+
Wraps an HWND integer. The resulting object can be passed to the
|
|
41
|
+
:py:meth:`~PIL.ImageWin.Dib.draw` and :py:meth:`~PIL.ImageWin.Dib.expose`
|
|
42
|
+
methods, instead of a DC.
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
def __init__(self, wnd: int) -> None:
|
|
46
|
+
self.wnd = wnd
|
|
47
|
+
|
|
48
|
+
def __int__(self) -> int:
|
|
49
|
+
return self.wnd
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class Dib:
|
|
53
|
+
"""
|
|
54
|
+
A Windows bitmap with the given mode and size. The mode can be one of "1",
|
|
55
|
+
"L", "P", or "RGB".
|
|
56
|
+
|
|
57
|
+
If the display requires a palette, this constructor creates a suitable
|
|
58
|
+
palette and associates it with the image. For an "L" image, 128 graylevels
|
|
59
|
+
are allocated. For an "RGB" image, a 6x6x6 colour cube is used, together
|
|
60
|
+
with 20 graylevels.
|
|
61
|
+
|
|
62
|
+
To make sure that palettes work properly under Windows, you must call the
|
|
63
|
+
``palette`` method upon certain events from Windows.
|
|
64
|
+
|
|
65
|
+
:param image: Either a PIL image, or a mode string. If a mode string is
|
|
66
|
+
used, a size must also be given. The mode can be one of "1",
|
|
67
|
+
"L", "P", or "RGB".
|
|
68
|
+
:param size: If the first argument is a mode string, this
|
|
69
|
+
defines the size of the image.
|
|
70
|
+
"""
|
|
71
|
+
|
|
72
|
+
def __init__(
|
|
73
|
+
self, image: Image.Image | str, size: tuple[int, int] | None = None
|
|
74
|
+
) -> None:
|
|
75
|
+
if isinstance(image, str):
|
|
76
|
+
mode = image
|
|
77
|
+
image = ""
|
|
78
|
+
if size is None:
|
|
79
|
+
msg = "If first argument is mode, size is required"
|
|
80
|
+
raise ValueError(msg)
|
|
81
|
+
else:
|
|
82
|
+
mode = image.mode
|
|
83
|
+
size = image.size
|
|
84
|
+
if mode not in ["1", "L", "P", "RGB"]:
|
|
85
|
+
mode = Image.getmodebase(mode)
|
|
86
|
+
self.image = Image.core.display(mode, size)
|
|
87
|
+
self.mode = mode
|
|
88
|
+
self.size = size
|
|
89
|
+
if image:
|
|
90
|
+
assert not isinstance(image, str)
|
|
91
|
+
self.paste(image)
|
|
92
|
+
|
|
93
|
+
def expose(self, handle: int | HDC | HWND) -> None:
|
|
94
|
+
"""
|
|
95
|
+
Copy the bitmap contents to a device context.
|
|
96
|
+
|
|
97
|
+
:param handle: Device context (HDC), cast to a Python integer, or an
|
|
98
|
+
HDC or HWND instance. In PythonWin, you can use
|
|
99
|
+
``CDC.GetHandleAttrib()`` to get a suitable handle.
|
|
100
|
+
"""
|
|
101
|
+
handle_int = int(handle)
|
|
102
|
+
if isinstance(handle, HWND):
|
|
103
|
+
dc = self.image.getdc(handle_int)
|
|
104
|
+
try:
|
|
105
|
+
self.image.expose(dc)
|
|
106
|
+
finally:
|
|
107
|
+
self.image.releasedc(handle_int, dc)
|
|
108
|
+
else:
|
|
109
|
+
self.image.expose(handle_int)
|
|
110
|
+
|
|
111
|
+
def draw(
|
|
112
|
+
self,
|
|
113
|
+
handle: int | HDC | HWND,
|
|
114
|
+
dst: tuple[int, int, int, int],
|
|
115
|
+
src: tuple[int, int, int, int] | None = None,
|
|
116
|
+
) -> None:
|
|
117
|
+
"""
|
|
118
|
+
Same as expose, but allows you to specify where to draw the image, and
|
|
119
|
+
what part of it to draw.
|
|
120
|
+
|
|
121
|
+
The destination and source areas are given as 4-tuple rectangles. If
|
|
122
|
+
the source is omitted, the entire image is copied. If the source and
|
|
123
|
+
the destination have different sizes, the image is resized as
|
|
124
|
+
necessary.
|
|
125
|
+
"""
|
|
126
|
+
if src is None:
|
|
127
|
+
src = (0, 0) + self.size
|
|
128
|
+
handle_int = int(handle)
|
|
129
|
+
if isinstance(handle, HWND):
|
|
130
|
+
dc = self.image.getdc(handle_int)
|
|
131
|
+
try:
|
|
132
|
+
self.image.draw(dc, dst, src)
|
|
133
|
+
finally:
|
|
134
|
+
self.image.releasedc(handle_int, dc)
|
|
135
|
+
else:
|
|
136
|
+
self.image.draw(handle_int, dst, src)
|
|
137
|
+
|
|
138
|
+
def query_palette(self, handle: int | HDC | HWND) -> int:
|
|
139
|
+
"""
|
|
140
|
+
Installs the palette associated with the image in the given device
|
|
141
|
+
context.
|
|
142
|
+
|
|
143
|
+
This method should be called upon **QUERYNEWPALETTE** and
|
|
144
|
+
**PALETTECHANGED** events from Windows. If this method returns a
|
|
145
|
+
non-zero value, one or more display palette entries were changed, and
|
|
146
|
+
the image should be redrawn.
|
|
147
|
+
|
|
148
|
+
:param handle: Device context (HDC), cast to a Python integer, or an
|
|
149
|
+
HDC or HWND instance.
|
|
150
|
+
:return: The number of entries that were changed (if one or more entries,
|
|
151
|
+
this indicates that the image should be redrawn).
|
|
152
|
+
"""
|
|
153
|
+
handle_int = int(handle)
|
|
154
|
+
if isinstance(handle, HWND):
|
|
155
|
+
handle = self.image.getdc(handle_int)
|
|
156
|
+
try:
|
|
157
|
+
result = self.image.query_palette(handle)
|
|
158
|
+
finally:
|
|
159
|
+
self.image.releasedc(handle, handle)
|
|
160
|
+
else:
|
|
161
|
+
result = self.image.query_palette(handle_int)
|
|
162
|
+
return result
|
|
163
|
+
|
|
164
|
+
def paste(
|
|
165
|
+
self, im: Image.Image, box: tuple[int, int, int, int] | None = None
|
|
166
|
+
) -> None:
|
|
167
|
+
"""
|
|
168
|
+
Paste a PIL image into the bitmap image.
|
|
169
|
+
|
|
170
|
+
:param im: A PIL image. The size must match the target region.
|
|
171
|
+
If the mode does not match, the image is converted to the
|
|
172
|
+
mode of the bitmap image.
|
|
173
|
+
:param box: A 4-tuple defining the left, upper, right, and
|
|
174
|
+
lower pixel coordinate. See :ref:`coordinate-system`. If
|
|
175
|
+
None is given instead of a tuple, all of the image is
|
|
176
|
+
assumed.
|
|
177
|
+
"""
|
|
178
|
+
im.load()
|
|
179
|
+
if self.mode != im.mode:
|
|
180
|
+
im = im.convert(self.mode)
|
|
181
|
+
if box:
|
|
182
|
+
self.image.paste(im.im, box)
|
|
183
|
+
else:
|
|
184
|
+
self.image.paste(im.im)
|
|
185
|
+
|
|
186
|
+
def frombytes(self, buffer: bytes | memoryview) -> None:
|
|
187
|
+
"""
|
|
188
|
+
Load display memory contents from byte data.
|
|
189
|
+
|
|
190
|
+
:param buffer: A buffer containing display data (usually
|
|
191
|
+
data returned from :py:func:`~PIL.ImageWin.Dib.tobytes`)
|
|
192
|
+
"""
|
|
193
|
+
self.image.frombytes(buffer)
|
|
194
|
+
|
|
195
|
+
def tobytes(self) -> bytes:
|
|
196
|
+
"""
|
|
197
|
+
Copy display memory contents to bytes object.
|
|
198
|
+
|
|
199
|
+
:return: A bytes object containing display data.
|
|
200
|
+
"""
|
|
201
|
+
return self.image.tobytes()
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
class Window:
|
|
205
|
+
"""Create a Window with the given title size."""
|
|
206
|
+
|
|
207
|
+
def __init__(
|
|
208
|
+
self, title: str = "PIL", width: int | None = None, height: int | None = None
|
|
209
|
+
) -> None:
|
|
210
|
+
self.hwnd = Image.core.createwindow(
|
|
211
|
+
title, self.__dispatcher, width or 0, height or 0
|
|
212
|
+
)
|
|
213
|
+
|
|
214
|
+
def __dispatcher(self, action: str, *args: int) -> None:
|
|
215
|
+
getattr(self, f"ui_handle_{action}")(*args)
|
|
216
|
+
|
|
217
|
+
def ui_handle_clear(self, dc: int, x0: int, y0: int, x1: int, y1: int) -> None:
|
|
218
|
+
pass
|
|
219
|
+
|
|
220
|
+
def ui_handle_damage(self, x0: int, y0: int, x1: int, y1: int) -> None:
|
|
221
|
+
pass
|
|
222
|
+
|
|
223
|
+
def ui_handle_destroy(self) -> None:
|
|
224
|
+
pass
|
|
225
|
+
|
|
226
|
+
def ui_handle_repair(self, dc: int, x0: int, y0: int, x1: int, y1: int) -> None:
|
|
227
|
+
pass
|
|
228
|
+
|
|
229
|
+
def ui_handle_resize(self, width: int, height: int) -> None:
|
|
230
|
+
pass
|
|
231
|
+
|
|
232
|
+
def mainloop(self) -> None:
|
|
233
|
+
Image.core.eventloop()
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
class ImageWindow(Window):
|
|
237
|
+
"""Create an image window which displays the given image."""
|
|
238
|
+
|
|
239
|
+
def __init__(self, image: Image.Image | Dib, title: str = "PIL") -> None:
|
|
240
|
+
if not isinstance(image, Dib):
|
|
241
|
+
image = Dib(image)
|
|
242
|
+
self.image = image
|
|
243
|
+
width, height = image.size
|
|
244
|
+
super().__init__(title, width=width, height=height)
|
|
245
|
+
|
|
246
|
+
def ui_handle_repair(self, dc: int, x0: int, y0: int, x1: int, y1: int) -> None:
|
|
247
|
+
self.image.draw(dc, (x0, y0, x1, y1))
|