@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,498 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Blizzard Mipmap Format (.blp)
|
|
3
|
+
Jerome Leclanche <jerome@leclan.ch>
|
|
4
|
+
|
|
5
|
+
The contents of this file are hereby released in the public domain (CC0)
|
|
6
|
+
Full text of the CC0 license:
|
|
7
|
+
https://creativecommons.org/publicdomain/zero/1.0/
|
|
8
|
+
|
|
9
|
+
BLP1 files, used mostly in Warcraft III, are not fully supported.
|
|
10
|
+
All types of BLP2 files used in World of Warcraft are supported.
|
|
11
|
+
|
|
12
|
+
The BLP file structure consists of a header, up to 16 mipmaps of the
|
|
13
|
+
texture
|
|
14
|
+
|
|
15
|
+
Texture sizes must be powers of two, though the two dimensions do
|
|
16
|
+
not have to be equal; 512x256 is valid, but 512x200 is not.
|
|
17
|
+
The first mipmap (mipmap #0) is the full size image; each subsequent
|
|
18
|
+
mipmap halves both dimensions. The final mipmap should be 1x1.
|
|
19
|
+
|
|
20
|
+
BLP files come in many different flavours:
|
|
21
|
+
* JPEG-compressed (type == 0) - only supported for BLP1.
|
|
22
|
+
* RAW images (type == 1, encoding == 1). Each mipmap is stored as an
|
|
23
|
+
array of 8-bit values, one per pixel, left to right, top to bottom.
|
|
24
|
+
Each value is an index to the palette.
|
|
25
|
+
* DXT-compressed (type == 1, encoding == 2):
|
|
26
|
+
- DXT1 compression is used if alpha_encoding == 0.
|
|
27
|
+
- An additional alpha bit is used if alpha_depth == 1.
|
|
28
|
+
- DXT3 compression is used if alpha_encoding == 1.
|
|
29
|
+
- DXT5 compression is used if alpha_encoding == 7.
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
from __future__ import annotations
|
|
33
|
+
|
|
34
|
+
import abc
|
|
35
|
+
import os
|
|
36
|
+
import struct
|
|
37
|
+
from enum import IntEnum
|
|
38
|
+
from io import BytesIO
|
|
39
|
+
from typing import IO
|
|
40
|
+
|
|
41
|
+
from . import Image, ImageFile
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class Format(IntEnum):
|
|
45
|
+
JPEG = 0
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class Encoding(IntEnum):
|
|
49
|
+
UNCOMPRESSED = 1
|
|
50
|
+
DXT = 2
|
|
51
|
+
UNCOMPRESSED_RAW_BGRA = 3
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class AlphaEncoding(IntEnum):
|
|
55
|
+
DXT1 = 0
|
|
56
|
+
DXT3 = 1
|
|
57
|
+
DXT5 = 7
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def unpack_565(i: int) -> tuple[int, int, int]:
|
|
61
|
+
return ((i >> 11) & 0x1F) << 3, ((i >> 5) & 0x3F) << 2, (i & 0x1F) << 3
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def decode_dxt1(
|
|
65
|
+
data: bytes, alpha: bool = False
|
|
66
|
+
) -> tuple[bytearray, bytearray, bytearray, bytearray]:
|
|
67
|
+
"""
|
|
68
|
+
input: one "row" of data (i.e. will produce 4*width pixels)
|
|
69
|
+
"""
|
|
70
|
+
|
|
71
|
+
blocks = len(data) // 8 # number of blocks in row
|
|
72
|
+
ret = (bytearray(), bytearray(), bytearray(), bytearray())
|
|
73
|
+
|
|
74
|
+
for block_index in range(blocks):
|
|
75
|
+
# Decode next 8-byte block.
|
|
76
|
+
idx = block_index * 8
|
|
77
|
+
color0, color1, bits = struct.unpack_from("<HHI", data, idx)
|
|
78
|
+
|
|
79
|
+
r0, g0, b0 = unpack_565(color0)
|
|
80
|
+
r1, g1, b1 = unpack_565(color1)
|
|
81
|
+
|
|
82
|
+
# Decode this block into 4x4 pixels
|
|
83
|
+
# Accumulate the results onto our 4 row accumulators
|
|
84
|
+
for j in range(4):
|
|
85
|
+
for i in range(4):
|
|
86
|
+
# get next control op and generate a pixel
|
|
87
|
+
|
|
88
|
+
control = bits & 3
|
|
89
|
+
bits = bits >> 2
|
|
90
|
+
|
|
91
|
+
a = 0xFF
|
|
92
|
+
if control == 0:
|
|
93
|
+
r, g, b = r0, g0, b0
|
|
94
|
+
elif control == 1:
|
|
95
|
+
r, g, b = r1, g1, b1
|
|
96
|
+
elif control == 2:
|
|
97
|
+
if color0 > color1:
|
|
98
|
+
r = (2 * r0 + r1) // 3
|
|
99
|
+
g = (2 * g0 + g1) // 3
|
|
100
|
+
b = (2 * b0 + b1) // 3
|
|
101
|
+
else:
|
|
102
|
+
r = (r0 + r1) // 2
|
|
103
|
+
g = (g0 + g1) // 2
|
|
104
|
+
b = (b0 + b1) // 2
|
|
105
|
+
elif control == 3:
|
|
106
|
+
if color0 > color1:
|
|
107
|
+
r = (2 * r1 + r0) // 3
|
|
108
|
+
g = (2 * g1 + g0) // 3
|
|
109
|
+
b = (2 * b1 + b0) // 3
|
|
110
|
+
else:
|
|
111
|
+
r, g, b, a = 0, 0, 0, 0
|
|
112
|
+
|
|
113
|
+
if alpha:
|
|
114
|
+
ret[j].extend([r, g, b, a])
|
|
115
|
+
else:
|
|
116
|
+
ret[j].extend([r, g, b])
|
|
117
|
+
|
|
118
|
+
return ret
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def decode_dxt3(data: bytes) -> tuple[bytearray, bytearray, bytearray, bytearray]:
|
|
122
|
+
"""
|
|
123
|
+
input: one "row" of data (i.e. will produce 4*width pixels)
|
|
124
|
+
"""
|
|
125
|
+
|
|
126
|
+
blocks = len(data) // 16 # number of blocks in row
|
|
127
|
+
ret = (bytearray(), bytearray(), bytearray(), bytearray())
|
|
128
|
+
|
|
129
|
+
for block_index in range(blocks):
|
|
130
|
+
idx = block_index * 16
|
|
131
|
+
block = data[idx : idx + 16]
|
|
132
|
+
# Decode next 16-byte block.
|
|
133
|
+
bits = struct.unpack_from("<8B", block)
|
|
134
|
+
color0, color1 = struct.unpack_from("<HH", block, 8)
|
|
135
|
+
|
|
136
|
+
(code,) = struct.unpack_from("<I", block, 12)
|
|
137
|
+
|
|
138
|
+
r0, g0, b0 = unpack_565(color0)
|
|
139
|
+
r1, g1, b1 = unpack_565(color1)
|
|
140
|
+
|
|
141
|
+
for j in range(4):
|
|
142
|
+
high = False # Do we want the higher bits?
|
|
143
|
+
for i in range(4):
|
|
144
|
+
alphacode_index = (4 * j + i) // 2
|
|
145
|
+
a = bits[alphacode_index]
|
|
146
|
+
if high:
|
|
147
|
+
high = False
|
|
148
|
+
a >>= 4
|
|
149
|
+
else:
|
|
150
|
+
high = True
|
|
151
|
+
a &= 0xF
|
|
152
|
+
a *= 17 # We get a value between 0 and 15
|
|
153
|
+
|
|
154
|
+
color_code = (code >> 2 * (4 * j + i)) & 0x03
|
|
155
|
+
|
|
156
|
+
if color_code == 0:
|
|
157
|
+
r, g, b = r0, g0, b0
|
|
158
|
+
elif color_code == 1:
|
|
159
|
+
r, g, b = r1, g1, b1
|
|
160
|
+
elif color_code == 2:
|
|
161
|
+
r = (2 * r0 + r1) // 3
|
|
162
|
+
g = (2 * g0 + g1) // 3
|
|
163
|
+
b = (2 * b0 + b1) // 3
|
|
164
|
+
elif color_code == 3:
|
|
165
|
+
r = (2 * r1 + r0) // 3
|
|
166
|
+
g = (2 * g1 + g0) // 3
|
|
167
|
+
b = (2 * b1 + b0) // 3
|
|
168
|
+
|
|
169
|
+
ret[j].extend([r, g, b, a])
|
|
170
|
+
|
|
171
|
+
return ret
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def decode_dxt5(data: bytes) -> tuple[bytearray, bytearray, bytearray, bytearray]:
|
|
175
|
+
"""
|
|
176
|
+
input: one "row" of data (i.e. will produce 4 * width pixels)
|
|
177
|
+
"""
|
|
178
|
+
|
|
179
|
+
blocks = len(data) // 16 # number of blocks in row
|
|
180
|
+
ret = (bytearray(), bytearray(), bytearray(), bytearray())
|
|
181
|
+
|
|
182
|
+
for block_index in range(blocks):
|
|
183
|
+
idx = block_index * 16
|
|
184
|
+
block = data[idx : idx + 16]
|
|
185
|
+
# Decode next 16-byte block.
|
|
186
|
+
a0, a1 = struct.unpack_from("<BB", block)
|
|
187
|
+
|
|
188
|
+
bits = struct.unpack_from("<6B", block, 2)
|
|
189
|
+
alphacode1 = bits[2] | (bits[3] << 8) | (bits[4] << 16) | (bits[5] << 24)
|
|
190
|
+
alphacode2 = bits[0] | (bits[1] << 8)
|
|
191
|
+
|
|
192
|
+
color0, color1 = struct.unpack_from("<HH", block, 8)
|
|
193
|
+
|
|
194
|
+
(code,) = struct.unpack_from("<I", block, 12)
|
|
195
|
+
|
|
196
|
+
r0, g0, b0 = unpack_565(color0)
|
|
197
|
+
r1, g1, b1 = unpack_565(color1)
|
|
198
|
+
|
|
199
|
+
for j in range(4):
|
|
200
|
+
for i in range(4):
|
|
201
|
+
# get next control op and generate a pixel
|
|
202
|
+
alphacode_index = 3 * (4 * j + i)
|
|
203
|
+
|
|
204
|
+
if alphacode_index <= 12:
|
|
205
|
+
alphacode = (alphacode2 >> alphacode_index) & 0x07
|
|
206
|
+
elif alphacode_index == 15:
|
|
207
|
+
alphacode = (alphacode2 >> 15) | ((alphacode1 << 1) & 0x06)
|
|
208
|
+
else: # alphacode_index >= 18 and alphacode_index <= 45
|
|
209
|
+
alphacode = (alphacode1 >> (alphacode_index - 16)) & 0x07
|
|
210
|
+
|
|
211
|
+
if alphacode == 0:
|
|
212
|
+
a = a0
|
|
213
|
+
elif alphacode == 1:
|
|
214
|
+
a = a1
|
|
215
|
+
elif a0 > a1:
|
|
216
|
+
a = ((8 - alphacode) * a0 + (alphacode - 1) * a1) // 7
|
|
217
|
+
elif alphacode == 6:
|
|
218
|
+
a = 0
|
|
219
|
+
elif alphacode == 7:
|
|
220
|
+
a = 255
|
|
221
|
+
else:
|
|
222
|
+
a = ((6 - alphacode) * a0 + (alphacode - 1) * a1) // 5
|
|
223
|
+
|
|
224
|
+
color_code = (code >> 2 * (4 * j + i)) & 0x03
|
|
225
|
+
|
|
226
|
+
if color_code == 0:
|
|
227
|
+
r, g, b = r0, g0, b0
|
|
228
|
+
elif color_code == 1:
|
|
229
|
+
r, g, b = r1, g1, b1
|
|
230
|
+
elif color_code == 2:
|
|
231
|
+
r = (2 * r0 + r1) // 3
|
|
232
|
+
g = (2 * g0 + g1) // 3
|
|
233
|
+
b = (2 * b0 + b1) // 3
|
|
234
|
+
elif color_code == 3:
|
|
235
|
+
r = (2 * r1 + r0) // 3
|
|
236
|
+
g = (2 * g1 + g0) // 3
|
|
237
|
+
b = (2 * b1 + b0) // 3
|
|
238
|
+
|
|
239
|
+
ret[j].extend([r, g, b, a])
|
|
240
|
+
|
|
241
|
+
return ret
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
class BLPFormatError(NotImplementedError):
|
|
245
|
+
pass
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
def _accept(prefix: bytes) -> bool:
|
|
249
|
+
return prefix.startswith((b"BLP1", b"BLP2"))
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
class BlpImageFile(ImageFile.ImageFile):
|
|
253
|
+
"""
|
|
254
|
+
Blizzard Mipmap Format
|
|
255
|
+
"""
|
|
256
|
+
|
|
257
|
+
format = "BLP"
|
|
258
|
+
format_description = "Blizzard Mipmap Format"
|
|
259
|
+
|
|
260
|
+
def _open(self) -> None:
|
|
261
|
+
assert self.fp is not None
|
|
262
|
+
self.magic = self.fp.read(4)
|
|
263
|
+
if not _accept(self.magic):
|
|
264
|
+
msg = f"Bad BLP magic {repr(self.magic)}"
|
|
265
|
+
raise BLPFormatError(msg)
|
|
266
|
+
|
|
267
|
+
compression = struct.unpack("<i", self.fp.read(4))[0]
|
|
268
|
+
if self.magic == b"BLP1":
|
|
269
|
+
alpha = struct.unpack("<I", self.fp.read(4))[0] != 0
|
|
270
|
+
else:
|
|
271
|
+
encoding = struct.unpack("<b", self.fp.read(1))[0]
|
|
272
|
+
alpha = struct.unpack("<b", self.fp.read(1))[0] != 0
|
|
273
|
+
alpha_encoding = struct.unpack("<b", self.fp.read(1))[0]
|
|
274
|
+
self.fp.seek(1, os.SEEK_CUR) # mips
|
|
275
|
+
|
|
276
|
+
self._size = struct.unpack("<II", self.fp.read(8))
|
|
277
|
+
|
|
278
|
+
args: tuple[int, int, bool] | tuple[int, int, bool, int]
|
|
279
|
+
if self.magic == b"BLP1":
|
|
280
|
+
encoding = struct.unpack("<i", self.fp.read(4))[0]
|
|
281
|
+
self.fp.seek(4, os.SEEK_CUR) # subtype
|
|
282
|
+
|
|
283
|
+
args = (compression, encoding, alpha)
|
|
284
|
+
offset = 28
|
|
285
|
+
else:
|
|
286
|
+
args = (compression, encoding, alpha, alpha_encoding)
|
|
287
|
+
offset = 20
|
|
288
|
+
|
|
289
|
+
decoder = self.magic.decode()
|
|
290
|
+
|
|
291
|
+
self._mode = "RGBA" if alpha else "RGB"
|
|
292
|
+
self.tile = [ImageFile._Tile(decoder, (0, 0) + self.size, offset, args)]
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
class _BLPBaseDecoder(abc.ABC, ImageFile.PyDecoder):
|
|
296
|
+
_pulls_fd = True
|
|
297
|
+
|
|
298
|
+
def decode(self, buffer: Image.DecoderInput) -> tuple[int, int]:
|
|
299
|
+
try:
|
|
300
|
+
self._read_header()
|
|
301
|
+
self._load()
|
|
302
|
+
except struct.error as e:
|
|
303
|
+
msg = "Truncated BLP file"
|
|
304
|
+
raise OSError(msg) from e
|
|
305
|
+
return -1, 0
|
|
306
|
+
|
|
307
|
+
@abc.abstractmethod
|
|
308
|
+
def _load(self) -> None:
|
|
309
|
+
pass
|
|
310
|
+
|
|
311
|
+
def _read_header(self) -> None:
|
|
312
|
+
self._offsets = struct.unpack("<16I", self._safe_read(16 * 4))
|
|
313
|
+
self._lengths = struct.unpack("<16I", self._safe_read(16 * 4))
|
|
314
|
+
|
|
315
|
+
def _safe_read(self, length: int) -> bytes:
|
|
316
|
+
assert self.fd is not None
|
|
317
|
+
return ImageFile._safe_read(self.fd, length)
|
|
318
|
+
|
|
319
|
+
def _read_palette(self) -> list[tuple[int, int, int, int]]:
|
|
320
|
+
ret = []
|
|
321
|
+
for i in range(256):
|
|
322
|
+
try:
|
|
323
|
+
b, g, r, a = struct.unpack("<4B", self._safe_read(4))
|
|
324
|
+
except struct.error:
|
|
325
|
+
break
|
|
326
|
+
ret.append((b, g, r, a))
|
|
327
|
+
return ret
|
|
328
|
+
|
|
329
|
+
def _read_bgra(
|
|
330
|
+
self, palette: list[tuple[int, int, int, int]], alpha: bool
|
|
331
|
+
) -> bytearray:
|
|
332
|
+
data = bytearray()
|
|
333
|
+
_data = BytesIO(self._safe_read(self._lengths[0]))
|
|
334
|
+
while True:
|
|
335
|
+
try:
|
|
336
|
+
(offset,) = struct.unpack("<B", _data.read(1))
|
|
337
|
+
except struct.error:
|
|
338
|
+
break
|
|
339
|
+
b, g, r, a = palette[offset]
|
|
340
|
+
d: tuple[int, ...] = (r, g, b)
|
|
341
|
+
if alpha:
|
|
342
|
+
d += (a,)
|
|
343
|
+
data.extend(d)
|
|
344
|
+
return data
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
class BLP1Decoder(_BLPBaseDecoder):
|
|
348
|
+
def _load(self) -> None:
|
|
349
|
+
self._compression, self._encoding, alpha = self.args
|
|
350
|
+
|
|
351
|
+
if self._compression == Format.JPEG:
|
|
352
|
+
self._decode_jpeg_stream()
|
|
353
|
+
|
|
354
|
+
elif self._compression == 1:
|
|
355
|
+
if self._encoding in (4, 5):
|
|
356
|
+
palette = self._read_palette()
|
|
357
|
+
data = self._read_bgra(palette, alpha)
|
|
358
|
+
self.set_as_raw(data)
|
|
359
|
+
else:
|
|
360
|
+
msg = f"Unsupported BLP encoding {repr(self._encoding)}"
|
|
361
|
+
raise BLPFormatError(msg)
|
|
362
|
+
else:
|
|
363
|
+
msg = f"Unsupported BLP compression {repr(self._encoding)}"
|
|
364
|
+
raise BLPFormatError(msg)
|
|
365
|
+
|
|
366
|
+
def _decode_jpeg_stream(self) -> None:
|
|
367
|
+
from .JpegImagePlugin import JpegImageFile
|
|
368
|
+
|
|
369
|
+
(jpeg_header_size,) = struct.unpack("<I", self._safe_read(4))
|
|
370
|
+
jpeg_header = self._safe_read(jpeg_header_size)
|
|
371
|
+
assert self.fd is not None
|
|
372
|
+
self._safe_read(self._offsets[0] - self.fd.tell()) # What IS this?
|
|
373
|
+
data = self._safe_read(self._lengths[0])
|
|
374
|
+
data = jpeg_header + data
|
|
375
|
+
image = JpegImageFile(BytesIO(data))
|
|
376
|
+
Image._decompression_bomb_check(image.size)
|
|
377
|
+
if image.mode == "CMYK":
|
|
378
|
+
args = image.tile[0].args
|
|
379
|
+
assert isinstance(args, tuple)
|
|
380
|
+
image.tile = [image.tile[0]._replace(args=(args[0], "CMYK"))]
|
|
381
|
+
self.set_as_raw(image.convert("RGB").tobytes(), "BGR")
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
class BLP2Decoder(_BLPBaseDecoder):
|
|
385
|
+
def _load(self) -> None:
|
|
386
|
+
self._compression, self._encoding, alpha, self._alpha_encoding = self.args
|
|
387
|
+
|
|
388
|
+
palette = self._read_palette()
|
|
389
|
+
|
|
390
|
+
assert self.fd is not None
|
|
391
|
+
self.fd.seek(self._offsets[0])
|
|
392
|
+
|
|
393
|
+
if self._compression == 1:
|
|
394
|
+
# Uncompressed or DirectX compression
|
|
395
|
+
|
|
396
|
+
if self._encoding == Encoding.UNCOMPRESSED:
|
|
397
|
+
data = self._read_bgra(palette, alpha)
|
|
398
|
+
|
|
399
|
+
elif self._encoding == Encoding.DXT:
|
|
400
|
+
data = bytearray()
|
|
401
|
+
if self._alpha_encoding == AlphaEncoding.DXT1:
|
|
402
|
+
linesize = (self.state.xsize + 3) // 4 * 8
|
|
403
|
+
for yb in range((self.state.ysize + 3) // 4):
|
|
404
|
+
for d in decode_dxt1(self._safe_read(linesize), alpha):
|
|
405
|
+
data += d
|
|
406
|
+
|
|
407
|
+
elif self._alpha_encoding == AlphaEncoding.DXT3:
|
|
408
|
+
linesize = (self.state.xsize + 3) // 4 * 16
|
|
409
|
+
for yb in range((self.state.ysize + 3) // 4):
|
|
410
|
+
for d in decode_dxt3(self._safe_read(linesize)):
|
|
411
|
+
data += d
|
|
412
|
+
|
|
413
|
+
elif self._alpha_encoding == AlphaEncoding.DXT5:
|
|
414
|
+
linesize = (self.state.xsize + 3) // 4 * 16
|
|
415
|
+
for yb in range((self.state.ysize + 3) // 4):
|
|
416
|
+
for d in decode_dxt5(self._safe_read(linesize)):
|
|
417
|
+
data += d
|
|
418
|
+
else:
|
|
419
|
+
msg = f"Unsupported alpha encoding {repr(self._alpha_encoding)}"
|
|
420
|
+
raise BLPFormatError(msg)
|
|
421
|
+
else:
|
|
422
|
+
msg = f"Unknown BLP encoding {repr(self._encoding)}"
|
|
423
|
+
raise BLPFormatError(msg)
|
|
424
|
+
|
|
425
|
+
else:
|
|
426
|
+
msg = f"Unknown BLP compression {repr(self._compression)}"
|
|
427
|
+
raise BLPFormatError(msg)
|
|
428
|
+
|
|
429
|
+
self.set_as_raw(data)
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
class BLPEncoder(ImageFile.PyEncoder):
|
|
433
|
+
_pushes_fd = True
|
|
434
|
+
|
|
435
|
+
def _write_palette(self) -> bytes:
|
|
436
|
+
data = b""
|
|
437
|
+
assert self.im is not None
|
|
438
|
+
palette = self.im.getpalette("RGBA", "RGBA")
|
|
439
|
+
for i in range(len(palette) // 4):
|
|
440
|
+
r, g, b, a = palette[i * 4 : (i + 1) * 4]
|
|
441
|
+
data += struct.pack("<4B", b, g, r, a)
|
|
442
|
+
while len(data) < 256 * 4:
|
|
443
|
+
data += b"\x00" * 4
|
|
444
|
+
return data
|
|
445
|
+
|
|
446
|
+
def encode(self, bufsize: int) -> tuple[int, int, bytes]:
|
|
447
|
+
palette_data = self._write_palette()
|
|
448
|
+
|
|
449
|
+
offset = 20 + 16 * 4 * 2 + len(palette_data)
|
|
450
|
+
data = struct.pack("<16I", offset, *((0,) * 15))
|
|
451
|
+
|
|
452
|
+
assert self.im is not None
|
|
453
|
+
w, h = self.im.size
|
|
454
|
+
data += struct.pack("<16I", w * h, *((0,) * 15))
|
|
455
|
+
|
|
456
|
+
data += palette_data
|
|
457
|
+
|
|
458
|
+
for y in range(h):
|
|
459
|
+
for x in range(w):
|
|
460
|
+
data += struct.pack("<B", self.im.getpixel((x, y)))
|
|
461
|
+
|
|
462
|
+
return len(data), 0, data
|
|
463
|
+
|
|
464
|
+
|
|
465
|
+
def _save(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None:
|
|
466
|
+
if im.mode != "P":
|
|
467
|
+
msg = "Unsupported BLP image mode"
|
|
468
|
+
raise ValueError(msg)
|
|
469
|
+
|
|
470
|
+
magic = b"BLP1" if im.encoderinfo.get("blp_version") == "BLP1" else b"BLP2"
|
|
471
|
+
fp.write(magic)
|
|
472
|
+
|
|
473
|
+
assert im.palette is not None
|
|
474
|
+
fp.write(struct.pack("<i", 1)) # Uncompressed or DirectX compression
|
|
475
|
+
|
|
476
|
+
alpha_depth = 1 if im.palette.mode == "RGBA" else 0
|
|
477
|
+
if magic == b"BLP1":
|
|
478
|
+
fp.write(struct.pack("<L", alpha_depth))
|
|
479
|
+
else:
|
|
480
|
+
fp.write(struct.pack("<b", Encoding.UNCOMPRESSED))
|
|
481
|
+
fp.write(struct.pack("<b", alpha_depth))
|
|
482
|
+
fp.write(struct.pack("<b", 0)) # alpha encoding
|
|
483
|
+
fp.write(struct.pack("<b", 0)) # mips
|
|
484
|
+
fp.write(struct.pack("<II", *im.size))
|
|
485
|
+
if magic == b"BLP1":
|
|
486
|
+
fp.write(struct.pack("<i", 5))
|
|
487
|
+
fp.write(struct.pack("<i", 0))
|
|
488
|
+
|
|
489
|
+
ImageFile._save(im, fp, [ImageFile._Tile("BLP", (0, 0) + im.size, 0, im.mode)])
|
|
490
|
+
|
|
491
|
+
|
|
492
|
+
Image.register_open(BlpImageFile.format, BlpImageFile, _accept)
|
|
493
|
+
Image.register_extension(BlpImageFile.format, ".blp")
|
|
494
|
+
Image.register_decoder("BLP1", BLP1Decoder)
|
|
495
|
+
Image.register_decoder("BLP2", BLP2Decoder)
|
|
496
|
+
|
|
497
|
+
Image.register_save(BlpImageFile.format, _save)
|
|
498
|
+
Image.register_encoder("BLP", BLPEncoder)
|