@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,242 @@
|
|
|
1
|
+
"""
|
|
2
|
+
JPEG quality settings equivalent to the Photoshop settings.
|
|
3
|
+
Can be used when saving JPEG files.
|
|
4
|
+
|
|
5
|
+
The following presets are available by default:
|
|
6
|
+
``web_low``, ``web_medium``, ``web_high``, ``web_very_high``, ``web_maximum``,
|
|
7
|
+
``low``, ``medium``, ``high``, ``maximum``.
|
|
8
|
+
More presets can be added to the :py:data:`presets` dict if needed.
|
|
9
|
+
|
|
10
|
+
To apply the preset, specify::
|
|
11
|
+
|
|
12
|
+
quality="preset_name"
|
|
13
|
+
|
|
14
|
+
To apply only the quantization table::
|
|
15
|
+
|
|
16
|
+
qtables="preset_name"
|
|
17
|
+
|
|
18
|
+
To apply only the subsampling setting::
|
|
19
|
+
|
|
20
|
+
subsampling="preset_name"
|
|
21
|
+
|
|
22
|
+
Example::
|
|
23
|
+
|
|
24
|
+
im.save("image_name.jpg", quality="web_high")
|
|
25
|
+
|
|
26
|
+
Subsampling
|
|
27
|
+
-----------
|
|
28
|
+
|
|
29
|
+
Subsampling is the practice of encoding images by implementing less resolution
|
|
30
|
+
for chroma information than for luma information.
|
|
31
|
+
(ref.: https://en.wikipedia.org/wiki/Chroma_subsampling)
|
|
32
|
+
|
|
33
|
+
Possible subsampling values are 0, 1 and 2 that correspond to 4:4:4, 4:2:2 and
|
|
34
|
+
4:2:0.
|
|
35
|
+
|
|
36
|
+
You can get the subsampling of a JPEG with the
|
|
37
|
+
:func:`.JpegImagePlugin.get_sampling` function.
|
|
38
|
+
|
|
39
|
+
In JPEG compressed data a JPEG marker is used instead of an EXIF tag.
|
|
40
|
+
(ref.: https://exiv2.org/tags.html)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
Quantization tables
|
|
44
|
+
-------------------
|
|
45
|
+
|
|
46
|
+
They are values use by the DCT (Discrete cosine transform) to remove
|
|
47
|
+
*unnecessary* information from the image (the lossy part of the compression).
|
|
48
|
+
(ref.: https://en.wikipedia.org/wiki/Quantization_matrix#Quantization_matrices,
|
|
49
|
+
https://en.wikipedia.org/wiki/JPEG#Quantization)
|
|
50
|
+
|
|
51
|
+
You can get the quantization tables of a JPEG with::
|
|
52
|
+
|
|
53
|
+
im.quantization
|
|
54
|
+
|
|
55
|
+
This will return a dict with a number of lists. You can pass this dict
|
|
56
|
+
directly as the qtables argument when saving a JPEG.
|
|
57
|
+
|
|
58
|
+
The quantization table format in presets is a list with sublists. These formats
|
|
59
|
+
are interchangeable.
|
|
60
|
+
|
|
61
|
+
Libjpeg ref.:
|
|
62
|
+
https://web.archive.org/web/20120328125543/http://www.jpegcameras.com/libjpeg/libjpeg-3.html
|
|
63
|
+
|
|
64
|
+
"""
|
|
65
|
+
|
|
66
|
+
from __future__ import annotations
|
|
67
|
+
|
|
68
|
+
# fmt: off
|
|
69
|
+
presets = {
|
|
70
|
+
'web_low': {'subsampling': 2, # "4:2:0"
|
|
71
|
+
'quantization': [
|
|
72
|
+
[20, 16, 25, 39, 50, 46, 62, 68,
|
|
73
|
+
16, 18, 23, 38, 38, 53, 65, 68,
|
|
74
|
+
25, 23, 31, 38, 53, 65, 68, 68,
|
|
75
|
+
39, 38, 38, 53, 65, 68, 68, 68,
|
|
76
|
+
50, 38, 53, 65, 68, 68, 68, 68,
|
|
77
|
+
46, 53, 65, 68, 68, 68, 68, 68,
|
|
78
|
+
62, 65, 68, 68, 68, 68, 68, 68,
|
|
79
|
+
68, 68, 68, 68, 68, 68, 68, 68],
|
|
80
|
+
[21, 25, 32, 38, 54, 68, 68, 68,
|
|
81
|
+
25, 28, 24, 38, 54, 68, 68, 68,
|
|
82
|
+
32, 24, 32, 43, 66, 68, 68, 68,
|
|
83
|
+
38, 38, 43, 53, 68, 68, 68, 68,
|
|
84
|
+
54, 54, 66, 68, 68, 68, 68, 68,
|
|
85
|
+
68, 68, 68, 68, 68, 68, 68, 68,
|
|
86
|
+
68, 68, 68, 68, 68, 68, 68, 68,
|
|
87
|
+
68, 68, 68, 68, 68, 68, 68, 68]
|
|
88
|
+
]},
|
|
89
|
+
'web_medium': {'subsampling': 2, # "4:2:0"
|
|
90
|
+
'quantization': [
|
|
91
|
+
[16, 11, 11, 16, 23, 27, 31, 30,
|
|
92
|
+
11, 12, 12, 15, 20, 23, 23, 30,
|
|
93
|
+
11, 12, 13, 16, 23, 26, 35, 47,
|
|
94
|
+
16, 15, 16, 23, 26, 37, 47, 64,
|
|
95
|
+
23, 20, 23, 26, 39, 51, 64, 64,
|
|
96
|
+
27, 23, 26, 37, 51, 64, 64, 64,
|
|
97
|
+
31, 23, 35, 47, 64, 64, 64, 64,
|
|
98
|
+
30, 30, 47, 64, 64, 64, 64, 64],
|
|
99
|
+
[17, 15, 17, 21, 20, 26, 38, 48,
|
|
100
|
+
15, 19, 18, 17, 20, 26, 35, 43,
|
|
101
|
+
17, 18, 20, 22, 26, 30, 46, 53,
|
|
102
|
+
21, 17, 22, 28, 30, 39, 53, 64,
|
|
103
|
+
20, 20, 26, 30, 39, 48, 64, 64,
|
|
104
|
+
26, 26, 30, 39, 48, 63, 64, 64,
|
|
105
|
+
38, 35, 46, 53, 64, 64, 64, 64,
|
|
106
|
+
48, 43, 53, 64, 64, 64, 64, 64]
|
|
107
|
+
]},
|
|
108
|
+
'web_high': {'subsampling': 0, # "4:4:4"
|
|
109
|
+
'quantization': [
|
|
110
|
+
[6, 4, 4, 6, 9, 11, 12, 16,
|
|
111
|
+
4, 5, 5, 6, 8, 10, 12, 12,
|
|
112
|
+
4, 5, 5, 6, 10, 12, 14, 19,
|
|
113
|
+
6, 6, 6, 11, 12, 15, 19, 28,
|
|
114
|
+
9, 8, 10, 12, 16, 20, 27, 31,
|
|
115
|
+
11, 10, 12, 15, 20, 27, 31, 31,
|
|
116
|
+
12, 12, 14, 19, 27, 31, 31, 31,
|
|
117
|
+
16, 12, 19, 28, 31, 31, 31, 31],
|
|
118
|
+
[7, 7, 13, 24, 26, 31, 31, 31,
|
|
119
|
+
7, 12, 16, 21, 31, 31, 31, 31,
|
|
120
|
+
13, 16, 17, 31, 31, 31, 31, 31,
|
|
121
|
+
24, 21, 31, 31, 31, 31, 31, 31,
|
|
122
|
+
26, 31, 31, 31, 31, 31, 31, 31,
|
|
123
|
+
31, 31, 31, 31, 31, 31, 31, 31,
|
|
124
|
+
31, 31, 31, 31, 31, 31, 31, 31,
|
|
125
|
+
31, 31, 31, 31, 31, 31, 31, 31]
|
|
126
|
+
]},
|
|
127
|
+
'web_very_high': {'subsampling': 0, # "4:4:4"
|
|
128
|
+
'quantization': [
|
|
129
|
+
[2, 2, 2, 2, 3, 4, 5, 6,
|
|
130
|
+
2, 2, 2, 2, 3, 4, 5, 6,
|
|
131
|
+
2, 2, 2, 2, 4, 5, 7, 9,
|
|
132
|
+
2, 2, 2, 4, 5, 7, 9, 12,
|
|
133
|
+
3, 3, 4, 5, 8, 10, 12, 12,
|
|
134
|
+
4, 4, 5, 7, 10, 12, 12, 12,
|
|
135
|
+
5, 5, 7, 9, 12, 12, 12, 12,
|
|
136
|
+
6, 6, 9, 12, 12, 12, 12, 12],
|
|
137
|
+
[3, 3, 5, 9, 13, 15, 15, 15,
|
|
138
|
+
3, 4, 6, 11, 14, 12, 12, 12,
|
|
139
|
+
5, 6, 9, 14, 12, 12, 12, 12,
|
|
140
|
+
9, 11, 14, 12, 12, 12, 12, 12,
|
|
141
|
+
13, 14, 12, 12, 12, 12, 12, 12,
|
|
142
|
+
15, 12, 12, 12, 12, 12, 12, 12,
|
|
143
|
+
15, 12, 12, 12, 12, 12, 12, 12,
|
|
144
|
+
15, 12, 12, 12, 12, 12, 12, 12]
|
|
145
|
+
]},
|
|
146
|
+
'web_maximum': {'subsampling': 0, # "4:4:4"
|
|
147
|
+
'quantization': [
|
|
148
|
+
[1, 1, 1, 1, 1, 1, 1, 1,
|
|
149
|
+
1, 1, 1, 1, 1, 1, 1, 1,
|
|
150
|
+
1, 1, 1, 1, 1, 1, 1, 2,
|
|
151
|
+
1, 1, 1, 1, 1, 1, 2, 2,
|
|
152
|
+
1, 1, 1, 1, 1, 2, 2, 3,
|
|
153
|
+
1, 1, 1, 1, 2, 2, 3, 3,
|
|
154
|
+
1, 1, 1, 2, 2, 3, 3, 3,
|
|
155
|
+
1, 1, 2, 2, 3, 3, 3, 3],
|
|
156
|
+
[1, 1, 1, 2, 2, 3, 3, 3,
|
|
157
|
+
1, 1, 1, 2, 3, 3, 3, 3,
|
|
158
|
+
1, 1, 1, 3, 3, 3, 3, 3,
|
|
159
|
+
2, 2, 3, 3, 3, 3, 3, 3,
|
|
160
|
+
2, 3, 3, 3, 3, 3, 3, 3,
|
|
161
|
+
3, 3, 3, 3, 3, 3, 3, 3,
|
|
162
|
+
3, 3, 3, 3, 3, 3, 3, 3,
|
|
163
|
+
3, 3, 3, 3, 3, 3, 3, 3]
|
|
164
|
+
]},
|
|
165
|
+
'low': {'subsampling': 2, # "4:2:0"
|
|
166
|
+
'quantization': [
|
|
167
|
+
[18, 14, 14, 21, 30, 35, 34, 17,
|
|
168
|
+
14, 16, 16, 19, 26, 23, 12, 12,
|
|
169
|
+
14, 16, 17, 21, 23, 12, 12, 12,
|
|
170
|
+
21, 19, 21, 23, 12, 12, 12, 12,
|
|
171
|
+
30, 26, 23, 12, 12, 12, 12, 12,
|
|
172
|
+
35, 23, 12, 12, 12, 12, 12, 12,
|
|
173
|
+
34, 12, 12, 12, 12, 12, 12, 12,
|
|
174
|
+
17, 12, 12, 12, 12, 12, 12, 12],
|
|
175
|
+
[20, 19, 22, 27, 20, 20, 17, 17,
|
|
176
|
+
19, 25, 23, 14, 14, 12, 12, 12,
|
|
177
|
+
22, 23, 14, 14, 12, 12, 12, 12,
|
|
178
|
+
27, 14, 14, 12, 12, 12, 12, 12,
|
|
179
|
+
20, 14, 12, 12, 12, 12, 12, 12,
|
|
180
|
+
20, 12, 12, 12, 12, 12, 12, 12,
|
|
181
|
+
17, 12, 12, 12, 12, 12, 12, 12,
|
|
182
|
+
17, 12, 12, 12, 12, 12, 12, 12]
|
|
183
|
+
]},
|
|
184
|
+
'medium': {'subsampling': 2, # "4:2:0"
|
|
185
|
+
'quantization': [
|
|
186
|
+
[12, 8, 8, 12, 17, 21, 24, 17,
|
|
187
|
+
8, 9, 9, 11, 15, 19, 12, 12,
|
|
188
|
+
8, 9, 10, 12, 19, 12, 12, 12,
|
|
189
|
+
12, 11, 12, 21, 12, 12, 12, 12,
|
|
190
|
+
17, 15, 19, 12, 12, 12, 12, 12,
|
|
191
|
+
21, 19, 12, 12, 12, 12, 12, 12,
|
|
192
|
+
24, 12, 12, 12, 12, 12, 12, 12,
|
|
193
|
+
17, 12, 12, 12, 12, 12, 12, 12],
|
|
194
|
+
[13, 11, 13, 16, 20, 20, 17, 17,
|
|
195
|
+
11, 14, 14, 14, 14, 12, 12, 12,
|
|
196
|
+
13, 14, 14, 14, 12, 12, 12, 12,
|
|
197
|
+
16, 14, 14, 12, 12, 12, 12, 12,
|
|
198
|
+
20, 14, 12, 12, 12, 12, 12, 12,
|
|
199
|
+
20, 12, 12, 12, 12, 12, 12, 12,
|
|
200
|
+
17, 12, 12, 12, 12, 12, 12, 12,
|
|
201
|
+
17, 12, 12, 12, 12, 12, 12, 12]
|
|
202
|
+
]},
|
|
203
|
+
'high': {'subsampling': 0, # "4:4:4"
|
|
204
|
+
'quantization': [
|
|
205
|
+
[6, 4, 4, 6, 9, 11, 12, 16,
|
|
206
|
+
4, 5, 5, 6, 8, 10, 12, 12,
|
|
207
|
+
4, 5, 5, 6, 10, 12, 12, 12,
|
|
208
|
+
6, 6, 6, 11, 12, 12, 12, 12,
|
|
209
|
+
9, 8, 10, 12, 12, 12, 12, 12,
|
|
210
|
+
11, 10, 12, 12, 12, 12, 12, 12,
|
|
211
|
+
12, 12, 12, 12, 12, 12, 12, 12,
|
|
212
|
+
16, 12, 12, 12, 12, 12, 12, 12],
|
|
213
|
+
[7, 7, 13, 24, 20, 20, 17, 17,
|
|
214
|
+
7, 12, 16, 14, 14, 12, 12, 12,
|
|
215
|
+
13, 16, 14, 14, 12, 12, 12, 12,
|
|
216
|
+
24, 14, 14, 12, 12, 12, 12, 12,
|
|
217
|
+
20, 14, 12, 12, 12, 12, 12, 12,
|
|
218
|
+
20, 12, 12, 12, 12, 12, 12, 12,
|
|
219
|
+
17, 12, 12, 12, 12, 12, 12, 12,
|
|
220
|
+
17, 12, 12, 12, 12, 12, 12, 12]
|
|
221
|
+
]},
|
|
222
|
+
'maximum': {'subsampling': 0, # "4:4:4"
|
|
223
|
+
'quantization': [
|
|
224
|
+
[2, 2, 2, 2, 3, 4, 5, 6,
|
|
225
|
+
2, 2, 2, 2, 3, 4, 5, 6,
|
|
226
|
+
2, 2, 2, 2, 4, 5, 7, 9,
|
|
227
|
+
2, 2, 2, 4, 5, 7, 9, 12,
|
|
228
|
+
3, 3, 4, 5, 8, 10, 12, 12,
|
|
229
|
+
4, 4, 5, 7, 10, 12, 12, 12,
|
|
230
|
+
5, 5, 7, 9, 12, 12, 12, 12,
|
|
231
|
+
6, 6, 9, 12, 12, 12, 12, 12],
|
|
232
|
+
[3, 3, 5, 9, 13, 15, 15, 15,
|
|
233
|
+
3, 4, 6, 10, 14, 12, 12, 12,
|
|
234
|
+
5, 6, 9, 14, 12, 12, 12, 12,
|
|
235
|
+
9, 10, 14, 12, 12, 12, 12, 12,
|
|
236
|
+
13, 14, 12, 12, 12, 12, 12, 12,
|
|
237
|
+
15, 12, 12, 12, 12, 12, 12, 12,
|
|
238
|
+
15, 12, 12, 12, 12, 12, 12, 12,
|
|
239
|
+
15, 12, 12, 12, 12, 12, 12, 12]
|
|
240
|
+
]},
|
|
241
|
+
}
|
|
242
|
+
# fmt: on
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
#
|
|
2
|
+
# The Python Imaging Library.
|
|
3
|
+
# $Id$
|
|
4
|
+
#
|
|
5
|
+
# Basic McIdas support for PIL
|
|
6
|
+
#
|
|
7
|
+
# History:
|
|
8
|
+
# 1997-05-05 fl Created (8-bit images only)
|
|
9
|
+
# 2009-03-08 fl Added 16/32-bit support.
|
|
10
|
+
#
|
|
11
|
+
# Thanks to Richard Jones and Craig Swank for specs and samples.
|
|
12
|
+
#
|
|
13
|
+
# Copyright (c) Secret Labs AB 1997.
|
|
14
|
+
# Copyright (c) Fredrik Lundh 1997.
|
|
15
|
+
#
|
|
16
|
+
# See the README file for information on usage and redistribution.
|
|
17
|
+
#
|
|
18
|
+
from __future__ import annotations
|
|
19
|
+
|
|
20
|
+
import struct
|
|
21
|
+
|
|
22
|
+
from . import Image, ImageFile
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _accept(prefix: bytes) -> bool:
|
|
26
|
+
return prefix.startswith(b"\x00\x00\x00\x00\x00\x00\x00\x04")
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
##
|
|
30
|
+
# Image plugin for McIdas area images.
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class McIdasImageFile(ImageFile.ImageFile):
|
|
34
|
+
format = "MCIDAS"
|
|
35
|
+
format_description = "McIdas area file"
|
|
36
|
+
|
|
37
|
+
def _open(self) -> None:
|
|
38
|
+
# parse area file directory
|
|
39
|
+
assert self.fp is not None
|
|
40
|
+
|
|
41
|
+
s = self.fp.read(256)
|
|
42
|
+
if not _accept(s) or len(s) != 256:
|
|
43
|
+
msg = "not an McIdas area file"
|
|
44
|
+
raise SyntaxError(msg)
|
|
45
|
+
|
|
46
|
+
self.area_descriptor_raw = s
|
|
47
|
+
self.area_descriptor = w = [0, *struct.unpack("!64i", s)]
|
|
48
|
+
|
|
49
|
+
# get mode
|
|
50
|
+
if w[11] == 1:
|
|
51
|
+
mode = rawmode = "L"
|
|
52
|
+
elif w[11] == 2:
|
|
53
|
+
mode = rawmode = "I;16B"
|
|
54
|
+
elif w[11] == 4:
|
|
55
|
+
# FIXME: add memory map support
|
|
56
|
+
mode = "I"
|
|
57
|
+
rawmode = "I;32B"
|
|
58
|
+
else:
|
|
59
|
+
msg = "unsupported McIdas format"
|
|
60
|
+
raise SyntaxError(msg)
|
|
61
|
+
|
|
62
|
+
self._mode = mode
|
|
63
|
+
self._size = w[10], w[9]
|
|
64
|
+
|
|
65
|
+
offset = w[34] + w[15]
|
|
66
|
+
stride = w[15] + w[10] * w[11] * w[14]
|
|
67
|
+
|
|
68
|
+
self.tile = [
|
|
69
|
+
ImageFile._Tile("raw", (0, 0) + self.size, offset, (rawmode, stride, 1))
|
|
70
|
+
]
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
# --------------------------------------------------------------------
|
|
74
|
+
# registry
|
|
75
|
+
|
|
76
|
+
Image.register_open(McIdasImageFile.format, McIdasImageFile, _accept)
|
|
77
|
+
|
|
78
|
+
# no default extension
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
#
|
|
2
|
+
# The Python Imaging Library.
|
|
3
|
+
# $Id$
|
|
4
|
+
#
|
|
5
|
+
# Microsoft Image Composer support for PIL
|
|
6
|
+
#
|
|
7
|
+
# Notes:
|
|
8
|
+
# uses TiffImagePlugin.py to read the actual image streams
|
|
9
|
+
#
|
|
10
|
+
# History:
|
|
11
|
+
# 97-01-20 fl Created
|
|
12
|
+
#
|
|
13
|
+
# Copyright (c) Secret Labs AB 1997.
|
|
14
|
+
# Copyright (c) Fredrik Lundh 1997.
|
|
15
|
+
#
|
|
16
|
+
# See the README file for information on usage and redistribution.
|
|
17
|
+
#
|
|
18
|
+
from __future__ import annotations
|
|
19
|
+
|
|
20
|
+
import olefile
|
|
21
|
+
|
|
22
|
+
from . import Image, TiffImagePlugin
|
|
23
|
+
|
|
24
|
+
#
|
|
25
|
+
# --------------------------------------------------------------------
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _accept(prefix: bytes) -> bool:
|
|
29
|
+
return prefix.startswith(olefile.MAGIC)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
##
|
|
33
|
+
# Image plugin for Microsoft's Image Composer file format.
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class MicImageFile(TiffImagePlugin.TiffImageFile):
|
|
37
|
+
format = "MIC"
|
|
38
|
+
format_description = "Microsoft Image Composer"
|
|
39
|
+
_close_exclusive_fp_after_loading = False
|
|
40
|
+
|
|
41
|
+
def _open(self) -> None:
|
|
42
|
+
# read the OLE directory and see if this is a likely
|
|
43
|
+
# to be a Microsoft Image Composer file
|
|
44
|
+
|
|
45
|
+
try:
|
|
46
|
+
self.ole = olefile.OleFileIO(self.fp)
|
|
47
|
+
except OSError as e:
|
|
48
|
+
msg = "not an MIC file; invalid OLE file"
|
|
49
|
+
raise SyntaxError(msg) from e
|
|
50
|
+
|
|
51
|
+
# find ACI subfiles with Image members (maybe not the
|
|
52
|
+
# best way to identify MIC files, but what the... ;-)
|
|
53
|
+
|
|
54
|
+
self.images = [
|
|
55
|
+
path
|
|
56
|
+
for path in self.ole.listdir()
|
|
57
|
+
if path[1:] and path[0].endswith(".ACI") and path[1] == "Image"
|
|
58
|
+
]
|
|
59
|
+
|
|
60
|
+
# if we didn't find any images, this is probably not
|
|
61
|
+
# an MIC file.
|
|
62
|
+
if not self.images:
|
|
63
|
+
msg = "not an MIC file; no image entries"
|
|
64
|
+
raise SyntaxError(msg)
|
|
65
|
+
|
|
66
|
+
self.frame = -1
|
|
67
|
+
self._n_frames = len(self.images)
|
|
68
|
+
self.is_animated = self._n_frames > 1
|
|
69
|
+
|
|
70
|
+
assert self.fp is not None
|
|
71
|
+
self.__fp = self.fp
|
|
72
|
+
self.seek(0)
|
|
73
|
+
|
|
74
|
+
def seek(self, frame: int) -> None:
|
|
75
|
+
if not self._seek_check(frame):
|
|
76
|
+
return
|
|
77
|
+
filename = self.images[frame]
|
|
78
|
+
self.fp = self.ole.openstream(filename)
|
|
79
|
+
|
|
80
|
+
TiffImagePlugin.TiffImageFile._open(self)
|
|
81
|
+
|
|
82
|
+
self.frame = frame
|
|
83
|
+
|
|
84
|
+
def tell(self) -> int:
|
|
85
|
+
return self.frame
|
|
86
|
+
|
|
87
|
+
def close(self) -> None:
|
|
88
|
+
self.__fp.close()
|
|
89
|
+
self.ole.close()
|
|
90
|
+
super().close()
|
|
91
|
+
|
|
92
|
+
def __exit__(self, *args: object) -> None:
|
|
93
|
+
self.__fp.close()
|
|
94
|
+
self.ole.close()
|
|
95
|
+
super().__exit__()
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
#
|
|
99
|
+
# --------------------------------------------------------------------
|
|
100
|
+
|
|
101
|
+
Image.register_open(MicImageFile.format, MicImageFile, _accept)
|
|
102
|
+
|
|
103
|
+
Image.register_extension(MicImageFile.format, ".mic")
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
#
|
|
2
|
+
# The Python Imaging Library.
|
|
3
|
+
# $Id$
|
|
4
|
+
#
|
|
5
|
+
# MPEG file handling
|
|
6
|
+
#
|
|
7
|
+
# History:
|
|
8
|
+
# 95-09-09 fl Created
|
|
9
|
+
#
|
|
10
|
+
# Copyright (c) Secret Labs AB 1997.
|
|
11
|
+
# Copyright (c) Fredrik Lundh 1995.
|
|
12
|
+
#
|
|
13
|
+
# See the README file for information on usage and redistribution.
|
|
14
|
+
#
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
from . import Image, ImageFile
|
|
18
|
+
from ._binary import i8
|
|
19
|
+
from ._typing import SupportsRead
|
|
20
|
+
|
|
21
|
+
#
|
|
22
|
+
# Bitstream parser
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class BitStream:
|
|
26
|
+
def __init__(self, fp: SupportsRead[bytes]) -> None:
|
|
27
|
+
self.fp = fp
|
|
28
|
+
self.bits = 0
|
|
29
|
+
self.bitbuffer = 0
|
|
30
|
+
|
|
31
|
+
def next(self) -> int:
|
|
32
|
+
return i8(self.fp.read(1))
|
|
33
|
+
|
|
34
|
+
def peek(self, bits: int) -> int:
|
|
35
|
+
while self.bits < bits:
|
|
36
|
+
self.bitbuffer = (self.bitbuffer << 8) + self.next()
|
|
37
|
+
self.bits += 8
|
|
38
|
+
return self.bitbuffer >> (self.bits - bits) & (1 << bits) - 1
|
|
39
|
+
|
|
40
|
+
def skip(self, bits: int) -> None:
|
|
41
|
+
while self.bits < bits:
|
|
42
|
+
self.bitbuffer = (self.bitbuffer << 8) + i8(self.fp.read(1))
|
|
43
|
+
self.bits += 8
|
|
44
|
+
self.bits = self.bits - bits
|
|
45
|
+
|
|
46
|
+
def read(self, bits: int) -> int:
|
|
47
|
+
v = self.peek(bits)
|
|
48
|
+
self.bits = self.bits - bits
|
|
49
|
+
return v
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def _accept(prefix: bytes) -> bool:
|
|
53
|
+
return prefix.startswith(b"\x00\x00\x01\xb3")
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
##
|
|
57
|
+
# Image plugin for MPEG streams. This plugin can identify a stream,
|
|
58
|
+
# but it cannot read it.
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
class MpegImageFile(ImageFile.ImageFile):
|
|
62
|
+
format = "MPEG"
|
|
63
|
+
format_description = "MPEG"
|
|
64
|
+
|
|
65
|
+
def _open(self) -> None:
|
|
66
|
+
assert self.fp is not None
|
|
67
|
+
|
|
68
|
+
s = BitStream(self.fp)
|
|
69
|
+
if s.read(32) != 0x1B3:
|
|
70
|
+
msg = "not an MPEG file"
|
|
71
|
+
raise SyntaxError(msg)
|
|
72
|
+
|
|
73
|
+
self._mode = "RGB"
|
|
74
|
+
self._size = s.read(12), s.read(12)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
# --------------------------------------------------------------------
|
|
78
|
+
# Registry stuff
|
|
79
|
+
|
|
80
|
+
Image.register_open(MpegImageFile.format, MpegImageFile, _accept)
|
|
81
|
+
|
|
82
|
+
Image.register_extensions(MpegImageFile.format, [".mpg", ".mpeg"])
|
|
83
|
+
|
|
84
|
+
Image.register_mime(MpegImageFile.format, "video/mpeg")
|