Upload folder using huggingface_hub
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +33 -0
- .venv/bin/dotenv +8 -0
- .venv/bin/email_validator +8 -0
- .venv/bin/f2py +8 -0
- .venv/bin/fastapi +8 -0
- .venv/bin/fonttools +8 -0
- .venv/bin/gradio +8 -0
- .venv/bin/httpx +8 -0
- .venv/bin/huggingface-cli +8 -0
- .venv/bin/jsonschema +8 -0
- .venv/bin/markdown-it +8 -0
- .venv/bin/normalizer +8 -0
- .venv/bin/numpy-config +8 -0
- .venv/bin/pyftmerge +8 -0
- .venv/bin/pyftsubset +8 -0
- .venv/bin/pygmentize +8 -0
- .venv/bin/ruff +3 -0
- .venv/bin/tqdm +8 -0
- .venv/bin/ttx +8 -0
- .venv/bin/typer +8 -0
- .venv/bin/upload_theme +8 -0
- .venv/bin/uvicorn +8 -0
- .venv/bin/watchfiles +8 -0
- .venv/lib/python3.11/site-packages/MarkupSafe-2.1.5.dist-info/INSTALLER +1 -0
- .venv/lib/python3.11/site-packages/MarkupSafe-2.1.5.dist-info/LICENSE.rst +28 -0
- .venv/lib/python3.11/site-packages/MarkupSafe-2.1.5.dist-info/METADATA +93 -0
- .venv/lib/python3.11/site-packages/MarkupSafe-2.1.5.dist-info/RECORD +14 -0
- .venv/lib/python3.11/site-packages/MarkupSafe-2.1.5.dist-info/WHEEL +5 -0
- .venv/lib/python3.11/site-packages/MarkupSafe-2.1.5.dist-info/top_level.txt +1 -0
- .venv/lib/python3.11/site-packages/PIL/.dylibs/libXau.6.0.0.dylib +0 -0
- .venv/lib/python3.11/site-packages/PIL/.dylibs/libbrotlicommon.1.1.0.dylib +0 -0
- .venv/lib/python3.11/site-packages/PIL/.dylibs/libbrotlidec.1.1.0.dylib +0 -0
- .venv/lib/python3.11/site-packages/PIL/.dylibs/libfreetype.6.dylib +3 -0
- .venv/lib/python3.11/site-packages/PIL/.dylibs/libharfbuzz.0.dylib +3 -0
- .venv/lib/python3.11/site-packages/PIL/.dylibs/libjpeg.62.4.0.dylib +0 -0
- .venv/lib/python3.11/site-packages/PIL/.dylibs/liblcms2.2.dylib +0 -0
- .venv/lib/python3.11/site-packages/PIL/.dylibs/liblzma.5.dylib +0 -0
- .venv/lib/python3.11/site-packages/PIL/.dylibs/libopenjp2.2.5.2.dylib +0 -0
- .venv/lib/python3.11/site-packages/PIL/.dylibs/libpng16.16.dylib +0 -0
- .venv/lib/python3.11/site-packages/PIL/.dylibs/libsharpyuv.0.dylib +0 -0
- .venv/lib/python3.11/site-packages/PIL/.dylibs/libtiff.6.dylib +0 -0
- .venv/lib/python3.11/site-packages/PIL/.dylibs/libwebp.7.dylib +0 -0
- .venv/lib/python3.11/site-packages/PIL/.dylibs/libwebpdemux.2.dylib +0 -0
- .venv/lib/python3.11/site-packages/PIL/.dylibs/libwebpmux.3.dylib +0 -0
- .venv/lib/python3.11/site-packages/PIL/.dylibs/libxcb.1.dylib +0 -0
- .venv/lib/python3.11/site-packages/PIL/.dylibs/libz.1.3.1.dylib +0 -0
- .venv/lib/python3.11/site-packages/PIL/BdfFontFile.py +133 -0
- .venv/lib/python3.11/site-packages/PIL/BlpImagePlugin.py +476 -0
- .venv/lib/python3.11/site-packages/PIL/BmpImagePlugin.py +472 -0
- .venv/lib/python3.11/site-packages/PIL/BufrStubImagePlugin.py +74 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,36 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
.venv/bin/ruff filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
.venv/lib/python3.11/site-packages/PIL/.dylibs/libfreetype.6.dylib filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
.venv/lib/python3.11/site-packages/PIL/.dylibs/libharfbuzz.0.dylib filter=lfs diff=lfs merge=lfs -text
|
| 39 |
+
.venv/lib/python3.11/site-packages/altair/vegalite/v5/schema/__pycache__/channels.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
| 40 |
+
.venv/lib/python3.11/site-packages/altair/vegalite/v5/schema/__pycache__/core.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
| 41 |
+
.venv/lib/python3.11/site-packages/cv2/.dylibs/libSvtAv1Enc.1.8.0.dylib filter=lfs diff=lfs merge=lfs -text
|
| 42 |
+
.venv/lib/python3.11/site-packages/cv2/.dylibs/libX11.6.dylib filter=lfs diff=lfs merge=lfs -text
|
| 43 |
+
.venv/lib/python3.11/site-packages/cv2/.dylibs/libaom.3.8.0.dylib filter=lfs diff=lfs merge=lfs -text
|
| 44 |
+
.venv/lib/python3.11/site-packages/cv2/.dylibs/libavcodec.60.3.100.dylib filter=lfs diff=lfs merge=lfs -text
|
| 45 |
+
.venv/lib/python3.11/site-packages/cv2/.dylibs/libavformat.60.3.100.dylib filter=lfs diff=lfs merge=lfs -text
|
| 46 |
+
.venv/lib/python3.11/site-packages/cv2/.dylibs/libcrypto.3.dylib filter=lfs diff=lfs merge=lfs -text
|
| 47 |
+
.venv/lib/python3.11/site-packages/cv2/.dylibs/libgnutls.30.dylib filter=lfs diff=lfs merge=lfs -text
|
| 48 |
+
.venv/lib/python3.11/site-packages/cv2/.dylibs/libjxl.0.8.2.dylib filter=lfs diff=lfs merge=lfs -text
|
| 49 |
+
.venv/lib/python3.11/site-packages/cv2/.dylibs/libp11-kit.0.dylib filter=lfs diff=lfs merge=lfs -text
|
| 50 |
+
.venv/lib/python3.11/site-packages/cv2/.dylibs/librav1e.0.6.6.dylib filter=lfs diff=lfs merge=lfs -text
|
| 51 |
+
.venv/lib/python3.11/site-packages/cv2/.dylibs/libunistring.5.dylib filter=lfs diff=lfs merge=lfs -text
|
| 52 |
+
.venv/lib/python3.11/site-packages/cv2/.dylibs/libvpx.8.dylib filter=lfs diff=lfs merge=lfs -text
|
| 53 |
+
.venv/lib/python3.11/site-packages/cv2/.dylibs/libx264.164.dylib filter=lfs diff=lfs merge=lfs -text
|
| 54 |
+
.venv/lib/python3.11/site-packages/cv2/.dylibs/libx265.199.dylib filter=lfs diff=lfs merge=lfs -text
|
| 55 |
+
.venv/lib/python3.11/site-packages/cv2/cv2.abi3.so filter=lfs diff=lfs merge=lfs -text
|
| 56 |
+
.venv/lib/python3.11/site-packages/cv2/libOrbbecSDK.1.9.4.dylib filter=lfs diff=lfs merge=lfs -text
|
| 57 |
+
.venv/lib/python3.11/site-packages/cv2/libOrbbecSDK.1.9.dylib filter=lfs diff=lfs merge=lfs -text
|
| 58 |
+
.venv/lib/python3.11/site-packages/cv2/libOrbbecSDK.dylib filter=lfs diff=lfs merge=lfs -text
|
| 59 |
+
.venv/lib/python3.11/site-packages/gradio/frpc_darwin_arm64_v0.2 filter=lfs diff=lfs merge=lfs -text
|
| 60 |
+
.venv/lib/python3.11/site-packages/gradio/templates/frontend/assets/Index-CUTYDExL.js.map filter=lfs diff=lfs merge=lfs -text
|
| 61 |
+
.venv/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-darwin.so filter=lfs diff=lfs merge=lfs -text
|
| 62 |
+
.venv/lib/python3.11/site-packages/pandas/_libs/algos.cpython-311-darwin.so filter=lfs diff=lfs merge=lfs -text
|
| 63 |
+
.venv/lib/python3.11/site-packages/pandas/_libs/groupby.cpython-311-darwin.so filter=lfs diff=lfs merge=lfs -text
|
| 64 |
+
.venv/lib/python3.11/site-packages/pandas/_libs/hashtable.cpython-311-darwin.so filter=lfs diff=lfs merge=lfs -text
|
| 65 |
+
.venv/lib/python3.11/site-packages/pandas/_libs/interval.cpython-311-darwin.so filter=lfs diff=lfs merge=lfs -text
|
| 66 |
+
.venv/lib/python3.11/site-packages/pandas/_libs/join.cpython-311-darwin.so filter=lfs diff=lfs merge=lfs -text
|
| 67 |
+
.venv/lib/python3.11/site-packages/pydantic_core/_pydantic_core.cpython-311-darwin.so filter=lfs diff=lfs merge=lfs -text
|
| 68 |
+
.venv/lib/python3.11/site-packages/uvloop/loop.cpython-311-darwin.so filter=lfs diff=lfs merge=lfs -text
|
.venv/bin/dotenv
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/Users/push/push/traffic_backend/.venv/bin/python
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from dotenv.__main__ import cli
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(cli())
|
.venv/bin/email_validator
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/Users/push/push/traffic_backend/.venv/bin/python
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from email_validator.__main__ import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
.venv/bin/f2py
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/Users/push/push/traffic_backend/.venv/bin/python
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from numpy.f2py.f2py2e import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
.venv/bin/fastapi
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/Users/push/push/traffic_backend/.venv/bin/python
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from fastapi_cli.cli import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
.venv/bin/fonttools
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/Users/push/push/traffic_backend/.venv/bin/python
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from fontTools.__main__ import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
.venv/bin/gradio
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/Users/push/push/traffic_backend/.venv/bin/python
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from gradio.cli import cli
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(cli())
|
.venv/bin/httpx
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/Users/push/push/traffic_backend/.venv/bin/python
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from httpx import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
.venv/bin/huggingface-cli
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/Users/push/push/traffic_backend/.venv/bin/python
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from huggingface_hub.commands.huggingface_cli import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
.venv/bin/jsonschema
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/Users/push/push/traffic_backend/.venv/bin/python
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from jsonschema.cli import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
.venv/bin/markdown-it
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/Users/push/push/traffic_backend/.venv/bin/python
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from markdown_it.cli.parse import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
.venv/bin/normalizer
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/Users/push/push/traffic_backend/.venv/bin/python
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from charset_normalizer.cli import cli_detect
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(cli_detect())
|
.venv/bin/numpy-config
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/Users/push/push/traffic_backend/.venv/bin/python
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from numpy._configtool import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
.venv/bin/pyftmerge
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/Users/push/push/traffic_backend/.venv/bin/python
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from fontTools.merge import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
.venv/bin/pyftsubset
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/Users/push/push/traffic_backend/.venv/bin/python
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from fontTools.subset import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
.venv/bin/pygmentize
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/Users/push/push/traffic_backend/.venv/bin/python
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from pygments.cmdline import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
.venv/bin/ruff
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:80b0c7f3d9a3c5d397370137f77f0c5c21c85dd134ca2823738f57bed1ec04bd
|
| 3 |
+
size 20874088
|
.venv/bin/tqdm
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/Users/push/push/traffic_backend/.venv/bin/python
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from tqdm.cli import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
.venv/bin/ttx
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/Users/push/push/traffic_backend/.venv/bin/python
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from fontTools.ttx import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
.venv/bin/typer
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/Users/push/push/traffic_backend/.venv/bin/python
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from typer.cli import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
.venv/bin/upload_theme
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/Users/push/push/traffic_backend/.venv/bin/python
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from gradio.themes.upload_theme import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
.venv/bin/uvicorn
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/Users/push/push/traffic_backend/.venv/bin/python
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from uvicorn.main import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
.venv/bin/watchfiles
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/Users/push/push/traffic_backend/.venv/bin/python
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from watchfiles.cli import cli
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(cli())
|
.venv/lib/python3.11/site-packages/MarkupSafe-2.1.5.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
pip
|
.venv/lib/python3.11/site-packages/MarkupSafe-2.1.5.dist-info/LICENSE.rst
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Copyright 2010 Pallets
|
| 2 |
+
|
| 3 |
+
Redistribution and use in source and binary forms, with or without
|
| 4 |
+
modification, are permitted provided that the following conditions are
|
| 5 |
+
met:
|
| 6 |
+
|
| 7 |
+
1. Redistributions of source code must retain the above copyright
|
| 8 |
+
notice, this list of conditions and the following disclaimer.
|
| 9 |
+
|
| 10 |
+
2. Redistributions in binary form must reproduce the above copyright
|
| 11 |
+
notice, this list of conditions and the following disclaimer in the
|
| 12 |
+
documentation and/or other materials provided with the distribution.
|
| 13 |
+
|
| 14 |
+
3. Neither the name of the copyright holder nor the names of its
|
| 15 |
+
contributors may be used to endorse or promote products derived from
|
| 16 |
+
this software without specific prior written permission.
|
| 17 |
+
|
| 18 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 19 |
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 20 |
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
| 21 |
+
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| 22 |
+
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| 23 |
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
| 24 |
+
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
| 25 |
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
| 26 |
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
| 27 |
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
| 28 |
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
.venv/lib/python3.11/site-packages/MarkupSafe-2.1.5.dist-info/METADATA
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.1
|
| 2 |
+
Name: MarkupSafe
|
| 3 |
+
Version: 2.1.5
|
| 4 |
+
Summary: Safely add untrusted strings to HTML/XML markup.
|
| 5 |
+
Home-page: https://palletsprojects.com/p/markupsafe/
|
| 6 |
+
Maintainer: Pallets
|
| 7 |
+
Maintainer-email: contact@palletsprojects.com
|
| 8 |
+
License: BSD-3-Clause
|
| 9 |
+
Project-URL: Donate, https://palletsprojects.com/donate
|
| 10 |
+
Project-URL: Documentation, https://markupsafe.palletsprojects.com/
|
| 11 |
+
Project-URL: Changes, https://markupsafe.palletsprojects.com/changes/
|
| 12 |
+
Project-URL: Source Code, https://github.com/pallets/markupsafe/
|
| 13 |
+
Project-URL: Issue Tracker, https://github.com/pallets/markupsafe/issues/
|
| 14 |
+
Project-URL: Chat, https://discord.gg/pallets
|
| 15 |
+
Classifier: Development Status :: 5 - Production/Stable
|
| 16 |
+
Classifier: Environment :: Web Environment
|
| 17 |
+
Classifier: Intended Audience :: Developers
|
| 18 |
+
Classifier: License :: OSI Approved :: BSD License
|
| 19 |
+
Classifier: Operating System :: OS Independent
|
| 20 |
+
Classifier: Programming Language :: Python
|
| 21 |
+
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
|
| 22 |
+
Classifier: Topic :: Text Processing :: Markup :: HTML
|
| 23 |
+
Requires-Python: >=3.7
|
| 24 |
+
Description-Content-Type: text/x-rst
|
| 25 |
+
License-File: LICENSE.rst
|
| 26 |
+
|
| 27 |
+
MarkupSafe
|
| 28 |
+
==========
|
| 29 |
+
|
| 30 |
+
MarkupSafe implements a text object that escapes characters so it is
|
| 31 |
+
safe to use in HTML and XML. Characters that have special meanings are
|
| 32 |
+
replaced so that they display as the actual characters. This mitigates
|
| 33 |
+
injection attacks, meaning untrusted user input can safely be displayed
|
| 34 |
+
on a page.
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
Installing
|
| 38 |
+
----------
|
| 39 |
+
|
| 40 |
+
Install and update using `pip`_:
|
| 41 |
+
|
| 42 |
+
.. code-block:: text
|
| 43 |
+
|
| 44 |
+
pip install -U MarkupSafe
|
| 45 |
+
|
| 46 |
+
.. _pip: https://pip.pypa.io/en/stable/getting-started/
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
Examples
|
| 50 |
+
--------
|
| 51 |
+
|
| 52 |
+
.. code-block:: pycon
|
| 53 |
+
|
| 54 |
+
>>> from markupsafe import Markup, escape
|
| 55 |
+
|
| 56 |
+
>>> # escape replaces special characters and wraps in Markup
|
| 57 |
+
>>> escape("<script>alert(document.cookie);</script>")
|
| 58 |
+
Markup('<script>alert(document.cookie);</script>')
|
| 59 |
+
|
| 60 |
+
>>> # wrap in Markup to mark text "safe" and prevent escaping
|
| 61 |
+
>>> Markup("<strong>Hello</strong>")
|
| 62 |
+
Markup('<strong>hello</strong>')
|
| 63 |
+
|
| 64 |
+
>>> escape(Markup("<strong>Hello</strong>"))
|
| 65 |
+
Markup('<strong>hello</strong>')
|
| 66 |
+
|
| 67 |
+
>>> # Markup is a str subclass
|
| 68 |
+
>>> # methods and operators escape their arguments
|
| 69 |
+
>>> template = Markup("Hello <em>{name}</em>")
|
| 70 |
+
>>> template.format(name='"World"')
|
| 71 |
+
Markup('Hello <em>"World"</em>')
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
Donate
|
| 75 |
+
------
|
| 76 |
+
|
| 77 |
+
The Pallets organization develops and supports MarkupSafe and other
|
| 78 |
+
popular packages. In order to grow the community of contributors and
|
| 79 |
+
users, and allow the maintainers to devote more time to the projects,
|
| 80 |
+
`please donate today`_.
|
| 81 |
+
|
| 82 |
+
.. _please donate today: https://palletsprojects.com/donate
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
Links
|
| 86 |
+
-----
|
| 87 |
+
|
| 88 |
+
- Documentation: https://markupsafe.palletsprojects.com/
|
| 89 |
+
- Changes: https://markupsafe.palletsprojects.com/changes/
|
| 90 |
+
- PyPI Releases: https://pypi.org/project/MarkupSafe/
|
| 91 |
+
- Source Code: https://github.com/pallets/markupsafe/
|
| 92 |
+
- Issue Tracker: https://github.com/pallets/markupsafe/issues/
|
| 93 |
+
- Chat: https://discord.gg/pallets
|
.venv/lib/python3.11/site-packages/MarkupSafe-2.1.5.dist-info/RECORD
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MarkupSafe-2.1.5.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
| 2 |
+
MarkupSafe-2.1.5.dist-info/LICENSE.rst,sha256=SJqOEQhQntmKN7uYPhHg9-HTHwvY-Zp5yESOf_N9B-o,1475
|
| 3 |
+
MarkupSafe-2.1.5.dist-info/METADATA,sha256=2dRDPam6OZLfpX0wg1JN5P3u9arqACxVSfdGmsJU7o8,3003
|
| 4 |
+
MarkupSafe-2.1.5.dist-info/RECORD,,
|
| 5 |
+
MarkupSafe-2.1.5.dist-info/WHEEL,sha256=Jjzc6ISFgDOOsYxK3rGIIgg_gPHXRI2MDFtRxyygFgU,115
|
| 6 |
+
MarkupSafe-2.1.5.dist-info/top_level.txt,sha256=qy0Plje5IJuvsCBjejJyhDCjEAdcDLK_2agVcex8Z6U,11
|
| 7 |
+
markupsafe/__init__.py,sha256=r7VOTjUq7EMQ4v3p4R1LoVOGJg6ysfYRncLr34laRBs,10958
|
| 8 |
+
markupsafe/__pycache__/__init__.cpython-311.pyc,,
|
| 9 |
+
markupsafe/__pycache__/_native.cpython-311.pyc,,
|
| 10 |
+
markupsafe/_native.py,sha256=GR86Qvo_GcgKmKreA1WmYN9ud17OFwkww8E-fiW-57s,1713
|
| 11 |
+
markupsafe/_speedups.c,sha256=X2XvQVtIdcK4Usz70BvkzoOfjTCmQlDkkjYSn-swE0g,7083
|
| 12 |
+
markupsafe/_speedups.cpython-311-darwin.so,sha256=IDqfQnyjAd2Y15LBPbXpZPSBjstu6YWSjwT5dP2LeHk,117484
|
| 13 |
+
markupsafe/_speedups.pyi,sha256=vfMCsOgbAXRNLUXkyuyonG8uEWKYU4PDqNuMaDELAYw,229
|
| 14 |
+
markupsafe/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
.venv/lib/python3.11/site-packages/MarkupSafe-2.1.5.dist-info/WHEEL
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Wheel-Version: 1.0
|
| 2 |
+
Generator: bdist_wheel (0.42.0)
|
| 3 |
+
Root-Is-Purelib: false
|
| 4 |
+
Tag: cp311-cp311-macosx_10_9_universal2
|
| 5 |
+
|
.venv/lib/python3.11/site-packages/MarkupSafe-2.1.5.dist-info/top_level.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
markupsafe
|
.venv/lib/python3.11/site-packages/PIL/.dylibs/libXau.6.0.0.dylib
ADDED
|
Binary file (70 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/PIL/.dylibs/libbrotlicommon.1.1.0.dylib
ADDED
|
Binary file (201 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/PIL/.dylibs/libbrotlidec.1.1.0.dylib
ADDED
|
Binary file (105 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/PIL/.dylibs/libfreetype.6.dylib
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:df34aceaadba2f9ea588c0f77d290002e98d74bc52e2831cbc6ea5e57a747786
|
| 3 |
+
size 1208416
|
.venv/lib/python3.11/site-packages/PIL/.dylibs/libharfbuzz.0.dylib
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d819fe78012b05a021edb13369ac0a3a8f7ba615360e09dc8cc3d300134da372
|
| 3 |
+
size 4359792
|
.venv/lib/python3.11/site-packages/PIL/.dylibs/libjpeg.62.4.0.dylib
ADDED
|
Binary file (620 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/PIL/.dylibs/liblcms2.2.dylib
ADDED
|
Binary file (557 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/PIL/.dylibs/liblzma.5.dylib
ADDED
|
Binary file (341 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/PIL/.dylibs/libopenjp2.2.5.2.dylib
ADDED
|
Binary file (699 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/PIL/.dylibs/libpng16.16.dylib
ADDED
|
Binary file (361 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/PIL/.dylibs/libsharpyuv.0.dylib
ADDED
|
Binary file (85.9 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/PIL/.dylibs/libtiff.6.dylib
ADDED
|
Binary file (803 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/PIL/.dylibs/libwebp.7.dylib
ADDED
|
Binary file (515 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/PIL/.dylibs/libwebpdemux.2.dylib
ADDED
|
Binary file (69.9 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/PIL/.dylibs/libwebpmux.3.dylib
ADDED
|
Binary file (106 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/PIL/.dylibs/libxcb.1.dylib
ADDED
|
Binary file (278 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/PIL/.dylibs/libz.1.3.1.dylib
ADDED
|
Binary file (175 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/PIL/BdfFontFile.py
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#
|
| 2 |
+
# The Python Imaging Library
|
| 3 |
+
# $Id$
|
| 4 |
+
#
|
| 5 |
+
# bitmap distribution font (bdf) file parser
|
| 6 |
+
#
|
| 7 |
+
# history:
|
| 8 |
+
# 1996-05-16 fl created (as bdf2pil)
|
| 9 |
+
# 1997-08-25 fl converted to FontFile driver
|
| 10 |
+
# 2001-05-25 fl removed bogus __init__ call
|
| 11 |
+
# 2002-11-20 fl robustification (from Kevin Cazabon, Dmitry Vasiliev)
|
| 12 |
+
# 2003-04-22 fl more robustification (from Graham Dumpleton)
|
| 13 |
+
#
|
| 14 |
+
# Copyright (c) 1997-2003 by Secret Labs AB.
|
| 15 |
+
# Copyright (c) 1997-2003 by Fredrik Lundh.
|
| 16 |
+
#
|
| 17 |
+
# See the README file for information on usage and redistribution.
|
| 18 |
+
#
|
| 19 |
+
|
| 20 |
+
"""
|
| 21 |
+
Parse X Bitmap Distribution Format (BDF)
|
| 22 |
+
"""
|
| 23 |
+
from __future__ import annotations
|
| 24 |
+
|
| 25 |
+
from typing import BinaryIO
|
| 26 |
+
|
| 27 |
+
from . import FontFile, Image
|
| 28 |
+
|
| 29 |
+
bdf_slant = {
|
| 30 |
+
"R": "Roman",
|
| 31 |
+
"I": "Italic",
|
| 32 |
+
"O": "Oblique",
|
| 33 |
+
"RI": "Reverse Italic",
|
| 34 |
+
"RO": "Reverse Oblique",
|
| 35 |
+
"OT": "Other",
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
bdf_spacing = {"P": "Proportional", "M": "Monospaced", "C": "Cell"}
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def bdf_char(
|
| 42 |
+
f: BinaryIO,
|
| 43 |
+
) -> (
|
| 44 |
+
tuple[
|
| 45 |
+
str,
|
| 46 |
+
int,
|
| 47 |
+
tuple[tuple[int, int], tuple[int, int, int, int], tuple[int, int, int, int]],
|
| 48 |
+
Image.Image,
|
| 49 |
+
]
|
| 50 |
+
| None
|
| 51 |
+
):
|
| 52 |
+
# skip to STARTCHAR
|
| 53 |
+
while True:
|
| 54 |
+
s = f.readline()
|
| 55 |
+
if not s:
|
| 56 |
+
return None
|
| 57 |
+
if s[:9] == b"STARTCHAR":
|
| 58 |
+
break
|
| 59 |
+
id = s[9:].strip().decode("ascii")
|
| 60 |
+
|
| 61 |
+
# load symbol properties
|
| 62 |
+
props = {}
|
| 63 |
+
while True:
|
| 64 |
+
s = f.readline()
|
| 65 |
+
if not s or s[:6] == b"BITMAP":
|
| 66 |
+
break
|
| 67 |
+
i = s.find(b" ")
|
| 68 |
+
props[s[:i].decode("ascii")] = s[i + 1 : -1].decode("ascii")
|
| 69 |
+
|
| 70 |
+
# load bitmap
|
| 71 |
+
bitmap = bytearray()
|
| 72 |
+
while True:
|
| 73 |
+
s = f.readline()
|
| 74 |
+
if not s or s[:7] == b"ENDCHAR":
|
| 75 |
+
break
|
| 76 |
+
bitmap += s[:-1]
|
| 77 |
+
|
| 78 |
+
# The word BBX
|
| 79 |
+
# followed by the width in x (BBw), height in y (BBh),
|
| 80 |
+
# and x and y displacement (BBxoff0, BByoff0)
|
| 81 |
+
# of the lower left corner from the origin of the character.
|
| 82 |
+
width, height, x_disp, y_disp = (int(p) for p in props["BBX"].split())
|
| 83 |
+
|
| 84 |
+
# The word DWIDTH
|
| 85 |
+
# followed by the width in x and y of the character in device pixels.
|
| 86 |
+
dwx, dwy = (int(p) for p in props["DWIDTH"].split())
|
| 87 |
+
|
| 88 |
+
bbox = (
|
| 89 |
+
(dwx, dwy),
|
| 90 |
+
(x_disp, -y_disp - height, width + x_disp, -y_disp),
|
| 91 |
+
(0, 0, width, height),
|
| 92 |
+
)
|
| 93 |
+
|
| 94 |
+
try:
|
| 95 |
+
im = Image.frombytes("1", (width, height), bitmap, "hex", "1")
|
| 96 |
+
except ValueError:
|
| 97 |
+
# deal with zero-width characters
|
| 98 |
+
im = Image.new("1", (width, height))
|
| 99 |
+
|
| 100 |
+
return id, int(props["ENCODING"]), bbox, im
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
class BdfFontFile(FontFile.FontFile):
|
| 104 |
+
"""Font file plugin for the X11 BDF format."""
|
| 105 |
+
|
| 106 |
+
def __init__(self, fp: BinaryIO):
|
| 107 |
+
super().__init__()
|
| 108 |
+
|
| 109 |
+
s = fp.readline()
|
| 110 |
+
if s[:13] != b"STARTFONT 2.1":
|
| 111 |
+
msg = "not a valid BDF file"
|
| 112 |
+
raise SyntaxError(msg)
|
| 113 |
+
|
| 114 |
+
props = {}
|
| 115 |
+
comments = []
|
| 116 |
+
|
| 117 |
+
while True:
|
| 118 |
+
s = fp.readline()
|
| 119 |
+
if not s or s[:13] == b"ENDPROPERTIES":
|
| 120 |
+
break
|
| 121 |
+
i = s.find(b" ")
|
| 122 |
+
props[s[:i].decode("ascii")] = s[i + 1 : -1].decode("ascii")
|
| 123 |
+
if s[:i] in [b"COMMENT", b"COPYRIGHT"]:
|
| 124 |
+
if s.find(b"LogicalFontDescription") < 0:
|
| 125 |
+
comments.append(s[i + 1 : -1].decode("ascii"))
|
| 126 |
+
|
| 127 |
+
while True:
|
| 128 |
+
c = bdf_char(fp)
|
| 129 |
+
if not c:
|
| 130 |
+
break
|
| 131 |
+
id, ch, (xy, dst, src), im = c
|
| 132 |
+
if 0 <= ch < len(self.glyph):
|
| 133 |
+
self.glyph[ch] = xy, dst, src, im
|
.venv/lib/python3.11/site-packages/PIL/BlpImagePlugin.py
ADDED
|
@@ -0,0 +1,476 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 os
|
| 35 |
+
import struct
|
| 36 |
+
from enum import IntEnum
|
| 37 |
+
from io import BytesIO
|
| 38 |
+
|
| 39 |
+
from . import Image, ImageFile
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
class Format(IntEnum):
|
| 43 |
+
JPEG = 0
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
class Encoding(IntEnum):
|
| 47 |
+
UNCOMPRESSED = 1
|
| 48 |
+
DXT = 2
|
| 49 |
+
UNCOMPRESSED_RAW_BGRA = 3
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
class AlphaEncoding(IntEnum):
|
| 53 |
+
DXT1 = 0
|
| 54 |
+
DXT3 = 1
|
| 55 |
+
DXT5 = 7
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
def unpack_565(i):
|
| 59 |
+
return ((i >> 11) & 0x1F) << 3, ((i >> 5) & 0x3F) << 2, (i & 0x1F) << 3
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
def decode_dxt1(data, alpha=False):
|
| 63 |
+
"""
|
| 64 |
+
input: one "row" of data (i.e. will produce 4*width pixels)
|
| 65 |
+
"""
|
| 66 |
+
|
| 67 |
+
blocks = len(data) // 8 # number of blocks in row
|
| 68 |
+
ret = (bytearray(), bytearray(), bytearray(), bytearray())
|
| 69 |
+
|
| 70 |
+
for block in range(blocks):
|
| 71 |
+
# Decode next 8-byte block.
|
| 72 |
+
idx = block * 8
|
| 73 |
+
color0, color1, bits = struct.unpack_from("<HHI", data, idx)
|
| 74 |
+
|
| 75 |
+
r0, g0, b0 = unpack_565(color0)
|
| 76 |
+
r1, g1, b1 = unpack_565(color1)
|
| 77 |
+
|
| 78 |
+
# Decode this block into 4x4 pixels
|
| 79 |
+
# Accumulate the results onto our 4 row accumulators
|
| 80 |
+
for j in range(4):
|
| 81 |
+
for i in range(4):
|
| 82 |
+
# get next control op and generate a pixel
|
| 83 |
+
|
| 84 |
+
control = bits & 3
|
| 85 |
+
bits = bits >> 2
|
| 86 |
+
|
| 87 |
+
a = 0xFF
|
| 88 |
+
if control == 0:
|
| 89 |
+
r, g, b = r0, g0, b0
|
| 90 |
+
elif control == 1:
|
| 91 |
+
r, g, b = r1, g1, b1
|
| 92 |
+
elif control == 2:
|
| 93 |
+
if color0 > color1:
|
| 94 |
+
r = (2 * r0 + r1) // 3
|
| 95 |
+
g = (2 * g0 + g1) // 3
|
| 96 |
+
b = (2 * b0 + b1) // 3
|
| 97 |
+
else:
|
| 98 |
+
r = (r0 + r1) // 2
|
| 99 |
+
g = (g0 + g1) // 2
|
| 100 |
+
b = (b0 + b1) // 2
|
| 101 |
+
elif control == 3:
|
| 102 |
+
if color0 > color1:
|
| 103 |
+
r = (2 * r1 + r0) // 3
|
| 104 |
+
g = (2 * g1 + g0) // 3
|
| 105 |
+
b = (2 * b1 + b0) // 3
|
| 106 |
+
else:
|
| 107 |
+
r, g, b, a = 0, 0, 0, 0
|
| 108 |
+
|
| 109 |
+
if alpha:
|
| 110 |
+
ret[j].extend([r, g, b, a])
|
| 111 |
+
else:
|
| 112 |
+
ret[j].extend([r, g, b])
|
| 113 |
+
|
| 114 |
+
return ret
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
def decode_dxt3(data):
|
| 118 |
+
"""
|
| 119 |
+
input: one "row" of data (i.e. will produce 4*width pixels)
|
| 120 |
+
"""
|
| 121 |
+
|
| 122 |
+
blocks = len(data) // 16 # number of blocks in row
|
| 123 |
+
ret = (bytearray(), bytearray(), bytearray(), bytearray())
|
| 124 |
+
|
| 125 |
+
for block in range(blocks):
|
| 126 |
+
idx = block * 16
|
| 127 |
+
block = data[idx : idx + 16]
|
| 128 |
+
# Decode next 16-byte block.
|
| 129 |
+
bits = struct.unpack_from("<8B", block)
|
| 130 |
+
color0, color1 = struct.unpack_from("<HH", block, 8)
|
| 131 |
+
|
| 132 |
+
(code,) = struct.unpack_from("<I", block, 12)
|
| 133 |
+
|
| 134 |
+
r0, g0, b0 = unpack_565(color0)
|
| 135 |
+
r1, g1, b1 = unpack_565(color1)
|
| 136 |
+
|
| 137 |
+
for j in range(4):
|
| 138 |
+
high = False # Do we want the higher bits?
|
| 139 |
+
for i in range(4):
|
| 140 |
+
alphacode_index = (4 * j + i) // 2
|
| 141 |
+
a = bits[alphacode_index]
|
| 142 |
+
if high:
|
| 143 |
+
high = False
|
| 144 |
+
a >>= 4
|
| 145 |
+
else:
|
| 146 |
+
high = True
|
| 147 |
+
a &= 0xF
|
| 148 |
+
a *= 17 # We get a value between 0 and 15
|
| 149 |
+
|
| 150 |
+
color_code = (code >> 2 * (4 * j + i)) & 0x03
|
| 151 |
+
|
| 152 |
+
if color_code == 0:
|
| 153 |
+
r, g, b = r0, g0, b0
|
| 154 |
+
elif color_code == 1:
|
| 155 |
+
r, g, b = r1, g1, b1
|
| 156 |
+
elif color_code == 2:
|
| 157 |
+
r = (2 * r0 + r1) // 3
|
| 158 |
+
g = (2 * g0 + g1) // 3
|
| 159 |
+
b = (2 * b0 + b1) // 3
|
| 160 |
+
elif color_code == 3:
|
| 161 |
+
r = (2 * r1 + r0) // 3
|
| 162 |
+
g = (2 * g1 + g0) // 3
|
| 163 |
+
b = (2 * b1 + b0) // 3
|
| 164 |
+
|
| 165 |
+
ret[j].extend([r, g, b, a])
|
| 166 |
+
|
| 167 |
+
return ret
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
def decode_dxt5(data):
|
| 171 |
+
"""
|
| 172 |
+
input: one "row" of data (i.e. will produce 4 * width pixels)
|
| 173 |
+
"""
|
| 174 |
+
|
| 175 |
+
blocks = len(data) // 16 # number of blocks in row
|
| 176 |
+
ret = (bytearray(), bytearray(), bytearray(), bytearray())
|
| 177 |
+
|
| 178 |
+
for block in range(blocks):
|
| 179 |
+
idx = block * 16
|
| 180 |
+
block = data[idx : idx + 16]
|
| 181 |
+
# Decode next 16-byte block.
|
| 182 |
+
a0, a1 = struct.unpack_from("<BB", block)
|
| 183 |
+
|
| 184 |
+
bits = struct.unpack_from("<6B", block, 2)
|
| 185 |
+
alphacode1 = bits[2] | (bits[3] << 8) | (bits[4] << 16) | (bits[5] << 24)
|
| 186 |
+
alphacode2 = bits[0] | (bits[1] << 8)
|
| 187 |
+
|
| 188 |
+
color0, color1 = struct.unpack_from("<HH", block, 8)
|
| 189 |
+
|
| 190 |
+
(code,) = struct.unpack_from("<I", block, 12)
|
| 191 |
+
|
| 192 |
+
r0, g0, b0 = unpack_565(color0)
|
| 193 |
+
r1, g1, b1 = unpack_565(color1)
|
| 194 |
+
|
| 195 |
+
for j in range(4):
|
| 196 |
+
for i in range(4):
|
| 197 |
+
# get next control op and generate a pixel
|
| 198 |
+
alphacode_index = 3 * (4 * j + i)
|
| 199 |
+
|
| 200 |
+
if alphacode_index <= 12:
|
| 201 |
+
alphacode = (alphacode2 >> alphacode_index) & 0x07
|
| 202 |
+
elif alphacode_index == 15:
|
| 203 |
+
alphacode = (alphacode2 >> 15) | ((alphacode1 << 1) & 0x06)
|
| 204 |
+
else: # alphacode_index >= 18 and alphacode_index <= 45
|
| 205 |
+
alphacode = (alphacode1 >> (alphacode_index - 16)) & 0x07
|
| 206 |
+
|
| 207 |
+
if alphacode == 0:
|
| 208 |
+
a = a0
|
| 209 |
+
elif alphacode == 1:
|
| 210 |
+
a = a1
|
| 211 |
+
elif a0 > a1:
|
| 212 |
+
a = ((8 - alphacode) * a0 + (alphacode - 1) * a1) // 7
|
| 213 |
+
elif alphacode == 6:
|
| 214 |
+
a = 0
|
| 215 |
+
elif alphacode == 7:
|
| 216 |
+
a = 255
|
| 217 |
+
else:
|
| 218 |
+
a = ((6 - alphacode) * a0 + (alphacode - 1) * a1) // 5
|
| 219 |
+
|
| 220 |
+
color_code = (code >> 2 * (4 * j + i)) & 0x03
|
| 221 |
+
|
| 222 |
+
if color_code == 0:
|
| 223 |
+
r, g, b = r0, g0, b0
|
| 224 |
+
elif color_code == 1:
|
| 225 |
+
r, g, b = r1, g1, b1
|
| 226 |
+
elif color_code == 2:
|
| 227 |
+
r = (2 * r0 + r1) // 3
|
| 228 |
+
g = (2 * g0 + g1) // 3
|
| 229 |
+
b = (2 * b0 + b1) // 3
|
| 230 |
+
elif color_code == 3:
|
| 231 |
+
r = (2 * r1 + r0) // 3
|
| 232 |
+
g = (2 * g1 + g0) // 3
|
| 233 |
+
b = (2 * b1 + b0) // 3
|
| 234 |
+
|
| 235 |
+
ret[j].extend([r, g, b, a])
|
| 236 |
+
|
| 237 |
+
return ret
|
| 238 |
+
|
| 239 |
+
|
| 240 |
+
class BLPFormatError(NotImplementedError):
|
| 241 |
+
pass
|
| 242 |
+
|
| 243 |
+
|
| 244 |
+
def _accept(prefix):
|
| 245 |
+
return prefix[:4] in (b"BLP1", b"BLP2")
|
| 246 |
+
|
| 247 |
+
|
| 248 |
+
class BlpImageFile(ImageFile.ImageFile):
|
| 249 |
+
"""
|
| 250 |
+
Blizzard Mipmap Format
|
| 251 |
+
"""
|
| 252 |
+
|
| 253 |
+
format = "BLP"
|
| 254 |
+
format_description = "Blizzard Mipmap Format"
|
| 255 |
+
|
| 256 |
+
def _open(self):
|
| 257 |
+
self.magic = self.fp.read(4)
|
| 258 |
+
|
| 259 |
+
self.fp.seek(5, os.SEEK_CUR)
|
| 260 |
+
(self._blp_alpha_depth,) = struct.unpack("<b", self.fp.read(1))
|
| 261 |
+
|
| 262 |
+
self.fp.seek(2, os.SEEK_CUR)
|
| 263 |
+
self._size = struct.unpack("<II", self.fp.read(8))
|
| 264 |
+
|
| 265 |
+
if self.magic in (b"BLP1", b"BLP2"):
|
| 266 |
+
decoder = self.magic.decode()
|
| 267 |
+
else:
|
| 268 |
+
msg = f"Bad BLP magic {repr(self.magic)}"
|
| 269 |
+
raise BLPFormatError(msg)
|
| 270 |
+
|
| 271 |
+
self._mode = "RGBA" if self._blp_alpha_depth else "RGB"
|
| 272 |
+
self.tile = [(decoder, (0, 0) + self.size, 0, (self.mode, 0, 1))]
|
| 273 |
+
|
| 274 |
+
|
| 275 |
+
class _BLPBaseDecoder(ImageFile.PyDecoder):
|
| 276 |
+
_pulls_fd = True
|
| 277 |
+
|
| 278 |
+
def decode(self, buffer):
|
| 279 |
+
try:
|
| 280 |
+
self._read_blp_header()
|
| 281 |
+
self._load()
|
| 282 |
+
except struct.error as e:
|
| 283 |
+
msg = "Truncated BLP file"
|
| 284 |
+
raise OSError(msg) from e
|
| 285 |
+
return -1, 0
|
| 286 |
+
|
| 287 |
+
def _read_blp_header(self):
|
| 288 |
+
self.fd.seek(4)
|
| 289 |
+
(self._blp_compression,) = struct.unpack("<i", self._safe_read(4))
|
| 290 |
+
|
| 291 |
+
(self._blp_encoding,) = struct.unpack("<b", self._safe_read(1))
|
| 292 |
+
(self._blp_alpha_depth,) = struct.unpack("<b", self._safe_read(1))
|
| 293 |
+
(self._blp_alpha_encoding,) = struct.unpack("<b", self._safe_read(1))
|
| 294 |
+
self.fd.seek(1, os.SEEK_CUR) # mips
|
| 295 |
+
|
| 296 |
+
self.size = struct.unpack("<II", self._safe_read(8))
|
| 297 |
+
|
| 298 |
+
if isinstance(self, BLP1Decoder):
|
| 299 |
+
# Only present for BLP1
|
| 300 |
+
(self._blp_encoding,) = struct.unpack("<i", self._safe_read(4))
|
| 301 |
+
self.fd.seek(4, os.SEEK_CUR) # subtype
|
| 302 |
+
|
| 303 |
+
self._blp_offsets = struct.unpack("<16I", self._safe_read(16 * 4))
|
| 304 |
+
self._blp_lengths = struct.unpack("<16I", self._safe_read(16 * 4))
|
| 305 |
+
|
| 306 |
+
def _safe_read(self, length):
|
| 307 |
+
return ImageFile._safe_read(self.fd, length)
|
| 308 |
+
|
| 309 |
+
def _read_palette(self):
|
| 310 |
+
ret = []
|
| 311 |
+
for i in range(256):
|
| 312 |
+
try:
|
| 313 |
+
b, g, r, a = struct.unpack("<4B", self._safe_read(4))
|
| 314 |
+
except struct.error:
|
| 315 |
+
break
|
| 316 |
+
ret.append((b, g, r, a))
|
| 317 |
+
return ret
|
| 318 |
+
|
| 319 |
+
def _read_bgra(self, palette):
|
| 320 |
+
data = bytearray()
|
| 321 |
+
_data = BytesIO(self._safe_read(self._blp_lengths[0]))
|
| 322 |
+
while True:
|
| 323 |
+
try:
|
| 324 |
+
(offset,) = struct.unpack("<B", _data.read(1))
|
| 325 |
+
except struct.error:
|
| 326 |
+
break
|
| 327 |
+
b, g, r, a = palette[offset]
|
| 328 |
+
d = (r, g, b)
|
| 329 |
+
if self._blp_alpha_depth:
|
| 330 |
+
d += (a,)
|
| 331 |
+
data.extend(d)
|
| 332 |
+
return data
|
| 333 |
+
|
| 334 |
+
|
| 335 |
+
class BLP1Decoder(_BLPBaseDecoder):
|
| 336 |
+
def _load(self):
|
| 337 |
+
if self._blp_compression == Format.JPEG:
|
| 338 |
+
self._decode_jpeg_stream()
|
| 339 |
+
|
| 340 |
+
elif self._blp_compression == 1:
|
| 341 |
+
if self._blp_encoding in (4, 5):
|
| 342 |
+
palette = self._read_palette()
|
| 343 |
+
data = self._read_bgra(palette)
|
| 344 |
+
self.set_as_raw(data)
|
| 345 |
+
else:
|
| 346 |
+
msg = f"Unsupported BLP encoding {repr(self._blp_encoding)}"
|
| 347 |
+
raise BLPFormatError(msg)
|
| 348 |
+
else:
|
| 349 |
+
msg = f"Unsupported BLP compression {repr(self._blp_encoding)}"
|
| 350 |
+
raise BLPFormatError(msg)
|
| 351 |
+
|
| 352 |
+
def _decode_jpeg_stream(self):
|
| 353 |
+
from .JpegImagePlugin import JpegImageFile
|
| 354 |
+
|
| 355 |
+
(jpeg_header_size,) = struct.unpack("<I", self._safe_read(4))
|
| 356 |
+
jpeg_header = self._safe_read(jpeg_header_size)
|
| 357 |
+
self._safe_read(self._blp_offsets[0] - self.fd.tell()) # What IS this?
|
| 358 |
+
data = self._safe_read(self._blp_lengths[0])
|
| 359 |
+
data = jpeg_header + data
|
| 360 |
+
data = BytesIO(data)
|
| 361 |
+
image = JpegImageFile(data)
|
| 362 |
+
Image._decompression_bomb_check(image.size)
|
| 363 |
+
if image.mode == "CMYK":
|
| 364 |
+
decoder_name, extents, offset, args = image.tile[0]
|
| 365 |
+
image.tile = [(decoder_name, extents, offset, (args[0], "CMYK"))]
|
| 366 |
+
r, g, b = image.convert("RGB").split()
|
| 367 |
+
image = Image.merge("RGB", (b, g, r))
|
| 368 |
+
self.set_as_raw(image.tobytes())
|
| 369 |
+
|
| 370 |
+
|
| 371 |
+
class BLP2Decoder(_BLPBaseDecoder):
|
| 372 |
+
def _load(self):
|
| 373 |
+
palette = self._read_palette()
|
| 374 |
+
|
| 375 |
+
self.fd.seek(self._blp_offsets[0])
|
| 376 |
+
|
| 377 |
+
if self._blp_compression == 1:
|
| 378 |
+
# Uncompressed or DirectX compression
|
| 379 |
+
|
| 380 |
+
if self._blp_encoding == Encoding.UNCOMPRESSED:
|
| 381 |
+
data = self._read_bgra(palette)
|
| 382 |
+
|
| 383 |
+
elif self._blp_encoding == Encoding.DXT:
|
| 384 |
+
data = bytearray()
|
| 385 |
+
if self._blp_alpha_encoding == AlphaEncoding.DXT1:
|
| 386 |
+
linesize = (self.size[0] + 3) // 4 * 8
|
| 387 |
+
for yb in range((self.size[1] + 3) // 4):
|
| 388 |
+
for d in decode_dxt1(
|
| 389 |
+
self._safe_read(linesize), alpha=bool(self._blp_alpha_depth)
|
| 390 |
+
):
|
| 391 |
+
data += d
|
| 392 |
+
|
| 393 |
+
elif self._blp_alpha_encoding == AlphaEncoding.DXT3:
|
| 394 |
+
linesize = (self.size[0] + 3) // 4 * 16
|
| 395 |
+
for yb in range((self.size[1] + 3) // 4):
|
| 396 |
+
for d in decode_dxt3(self._safe_read(linesize)):
|
| 397 |
+
data += d
|
| 398 |
+
|
| 399 |
+
elif self._blp_alpha_encoding == AlphaEncoding.DXT5:
|
| 400 |
+
linesize = (self.size[0] + 3) // 4 * 16
|
| 401 |
+
for yb in range((self.size[1] + 3) // 4):
|
| 402 |
+
for d in decode_dxt5(self._safe_read(linesize)):
|
| 403 |
+
data += d
|
| 404 |
+
else:
|
| 405 |
+
msg = f"Unsupported alpha encoding {repr(self._blp_alpha_encoding)}"
|
| 406 |
+
raise BLPFormatError(msg)
|
| 407 |
+
else:
|
| 408 |
+
msg = f"Unknown BLP encoding {repr(self._blp_encoding)}"
|
| 409 |
+
raise BLPFormatError(msg)
|
| 410 |
+
|
| 411 |
+
else:
|
| 412 |
+
msg = f"Unknown BLP compression {repr(self._blp_compression)}"
|
| 413 |
+
raise BLPFormatError(msg)
|
| 414 |
+
|
| 415 |
+
self.set_as_raw(data)
|
| 416 |
+
|
| 417 |
+
|
| 418 |
+
class BLPEncoder(ImageFile.PyEncoder):
|
| 419 |
+
_pushes_fd = True
|
| 420 |
+
|
| 421 |
+
def _write_palette(self):
|
| 422 |
+
data = b""
|
| 423 |
+
palette = self.im.getpalette("RGBA", "RGBA")
|
| 424 |
+
for i in range(len(palette) // 4):
|
| 425 |
+
r, g, b, a = palette[i * 4 : (i + 1) * 4]
|
| 426 |
+
data += struct.pack("<4B", b, g, r, a)
|
| 427 |
+
while len(data) < 256 * 4:
|
| 428 |
+
data += b"\x00" * 4
|
| 429 |
+
return data
|
| 430 |
+
|
| 431 |
+
def encode(self, bufsize):
|
| 432 |
+
palette_data = self._write_palette()
|
| 433 |
+
|
| 434 |
+
offset = 20 + 16 * 4 * 2 + len(palette_data)
|
| 435 |
+
data = struct.pack("<16I", offset, *((0,) * 15))
|
| 436 |
+
|
| 437 |
+
w, h = self.im.size
|
| 438 |
+
data += struct.pack("<16I", w * h, *((0,) * 15))
|
| 439 |
+
|
| 440 |
+
data += palette_data
|
| 441 |
+
|
| 442 |
+
for y in range(h):
|
| 443 |
+
for x in range(w):
|
| 444 |
+
data += struct.pack("<B", self.im.getpixel((x, y)))
|
| 445 |
+
|
| 446 |
+
return len(data), 0, data
|
| 447 |
+
|
| 448 |
+
|
| 449 |
+
def _save(im, fp, filename):
|
| 450 |
+
if im.mode != "P":
|
| 451 |
+
msg = "Unsupported BLP image mode"
|
| 452 |
+
raise ValueError(msg)
|
| 453 |
+
|
| 454 |
+
magic = b"BLP1" if im.encoderinfo.get("blp_version") == "BLP1" else b"BLP2"
|
| 455 |
+
fp.write(magic)
|
| 456 |
+
|
| 457 |
+
fp.write(struct.pack("<i", 1)) # Uncompressed or DirectX compression
|
| 458 |
+
fp.write(struct.pack("<b", Encoding.UNCOMPRESSED))
|
| 459 |
+
fp.write(struct.pack("<b", 1 if im.palette.mode == "RGBA" else 0))
|
| 460 |
+
fp.write(struct.pack("<b", 0)) # alpha encoding
|
| 461 |
+
fp.write(struct.pack("<b", 0)) # mips
|
| 462 |
+
fp.write(struct.pack("<II", *im.size))
|
| 463 |
+
if magic == b"BLP1":
|
| 464 |
+
fp.write(struct.pack("<i", 5))
|
| 465 |
+
fp.write(struct.pack("<i", 0))
|
| 466 |
+
|
| 467 |
+
ImageFile._save(im, fp, [("BLP", (0, 0) + im.size, 0, im.mode)])
|
| 468 |
+
|
| 469 |
+
|
| 470 |
+
Image.register_open(BlpImageFile.format, BlpImageFile, _accept)
|
| 471 |
+
Image.register_extension(BlpImageFile.format, ".blp")
|
| 472 |
+
Image.register_decoder("BLP1", BLP1Decoder)
|
| 473 |
+
Image.register_decoder("BLP2", BLP2Decoder)
|
| 474 |
+
|
| 475 |
+
Image.register_save(BlpImageFile.format, _save)
|
| 476 |
+
Image.register_encoder("BLP", BLPEncoder)
|
.venv/lib/python3.11/site-packages/PIL/BmpImagePlugin.py
ADDED
|
@@ -0,0 +1,472 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#
|
| 2 |
+
# The Python Imaging Library.
|
| 3 |
+
# $Id$
|
| 4 |
+
#
|
| 5 |
+
# BMP file handler
|
| 6 |
+
#
|
| 7 |
+
# Windows (and OS/2) native bitmap storage format.
|
| 8 |
+
#
|
| 9 |
+
# history:
|
| 10 |
+
# 1995-09-01 fl Created
|
| 11 |
+
# 1996-04-30 fl Added save
|
| 12 |
+
# 1997-08-27 fl Fixed save of 1-bit images
|
| 13 |
+
# 1998-03-06 fl Load P images as L where possible
|
| 14 |
+
# 1998-07-03 fl Load P images as 1 where possible
|
| 15 |
+
# 1998-12-29 fl Handle small palettes
|
| 16 |
+
# 2002-12-30 fl Fixed load of 1-bit palette images
|
| 17 |
+
# 2003-04-21 fl Fixed load of 1-bit monochrome images
|
| 18 |
+
# 2003-04-23 fl Added limited support for BI_BITFIELDS compression
|
| 19 |
+
#
|
| 20 |
+
# Copyright (c) 1997-2003 by Secret Labs AB
|
| 21 |
+
# Copyright (c) 1995-2003 by Fredrik Lundh
|
| 22 |
+
#
|
| 23 |
+
# See the README file for information on usage and redistribution.
|
| 24 |
+
#
|
| 25 |
+
from __future__ import annotations
|
| 26 |
+
|
| 27 |
+
import os
|
| 28 |
+
|
| 29 |
+
from . import Image, ImageFile, ImagePalette
|
| 30 |
+
from ._binary import i16le as i16
|
| 31 |
+
from ._binary import i32le as i32
|
| 32 |
+
from ._binary import o8
|
| 33 |
+
from ._binary import o16le as o16
|
| 34 |
+
from ._binary import o32le as o32
|
| 35 |
+
|
| 36 |
+
#
|
| 37 |
+
# --------------------------------------------------------------------
|
| 38 |
+
# Read BMP file
|
| 39 |
+
|
| 40 |
+
BIT2MODE = {
|
| 41 |
+
# bits => mode, rawmode
|
| 42 |
+
1: ("P", "P;1"),
|
| 43 |
+
4: ("P", "P;4"),
|
| 44 |
+
8: ("P", "P"),
|
| 45 |
+
16: ("RGB", "BGR;15"),
|
| 46 |
+
24: ("RGB", "BGR"),
|
| 47 |
+
32: ("RGB", "BGRX"),
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def _accept(prefix):
|
| 52 |
+
return prefix[:2] == b"BM"
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def _dib_accept(prefix):
|
| 56 |
+
return i32(prefix) in [12, 40, 64, 108, 124]
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
# =============================================================================
|
| 60 |
+
# Image plugin for the Windows BMP format.
|
| 61 |
+
# =============================================================================
|
| 62 |
+
class BmpImageFile(ImageFile.ImageFile):
|
| 63 |
+
"""Image plugin for the Windows Bitmap format (BMP)"""
|
| 64 |
+
|
| 65 |
+
# ------------------------------------------------------------- Description
|
| 66 |
+
format_description = "Windows Bitmap"
|
| 67 |
+
format = "BMP"
|
| 68 |
+
|
| 69 |
+
# -------------------------------------------------- BMP Compression values
|
| 70 |
+
COMPRESSIONS = {"RAW": 0, "RLE8": 1, "RLE4": 2, "BITFIELDS": 3, "JPEG": 4, "PNG": 5}
|
| 71 |
+
for k, v in COMPRESSIONS.items():
|
| 72 |
+
vars()[k] = v
|
| 73 |
+
|
| 74 |
+
def _bitmap(self, header=0, offset=0):
|
| 75 |
+
"""Read relevant info about the BMP"""
|
| 76 |
+
read, seek = self.fp.read, self.fp.seek
|
| 77 |
+
if header:
|
| 78 |
+
seek(header)
|
| 79 |
+
# read bmp header size @offset 14 (this is part of the header size)
|
| 80 |
+
file_info = {"header_size": i32(read(4)), "direction": -1}
|
| 81 |
+
|
| 82 |
+
# -------------------- If requested, read header at a specific position
|
| 83 |
+
# read the rest of the bmp header, without its size
|
| 84 |
+
header_data = ImageFile._safe_read(self.fp, file_info["header_size"] - 4)
|
| 85 |
+
|
| 86 |
+
# -------------------------------------------------- IBM OS/2 Bitmap v1
|
| 87 |
+
# ----- This format has different offsets because of width/height types
|
| 88 |
+
if file_info["header_size"] == 12:
|
| 89 |
+
file_info["width"] = i16(header_data, 0)
|
| 90 |
+
file_info["height"] = i16(header_data, 2)
|
| 91 |
+
file_info["planes"] = i16(header_data, 4)
|
| 92 |
+
file_info["bits"] = i16(header_data, 6)
|
| 93 |
+
file_info["compression"] = self.RAW
|
| 94 |
+
file_info["palette_padding"] = 3
|
| 95 |
+
|
| 96 |
+
# --------------------------------------------- Windows Bitmap v2 to v5
|
| 97 |
+
# v3, OS/2 v2, v4, v5
|
| 98 |
+
elif file_info["header_size"] in (40, 64, 108, 124):
|
| 99 |
+
file_info["y_flip"] = header_data[7] == 0xFF
|
| 100 |
+
file_info["direction"] = 1 if file_info["y_flip"] else -1
|
| 101 |
+
file_info["width"] = i32(header_data, 0)
|
| 102 |
+
file_info["height"] = (
|
| 103 |
+
i32(header_data, 4)
|
| 104 |
+
if not file_info["y_flip"]
|
| 105 |
+
else 2**32 - i32(header_data, 4)
|
| 106 |
+
)
|
| 107 |
+
file_info["planes"] = i16(header_data, 8)
|
| 108 |
+
file_info["bits"] = i16(header_data, 10)
|
| 109 |
+
file_info["compression"] = i32(header_data, 12)
|
| 110 |
+
# byte size of pixel data
|
| 111 |
+
file_info["data_size"] = i32(header_data, 16)
|
| 112 |
+
file_info["pixels_per_meter"] = (
|
| 113 |
+
i32(header_data, 20),
|
| 114 |
+
i32(header_data, 24),
|
| 115 |
+
)
|
| 116 |
+
file_info["colors"] = i32(header_data, 28)
|
| 117 |
+
file_info["palette_padding"] = 4
|
| 118 |
+
self.info["dpi"] = tuple(x / 39.3701 for x in file_info["pixels_per_meter"])
|
| 119 |
+
if file_info["compression"] == self.BITFIELDS:
|
| 120 |
+
if len(header_data) >= 52:
|
| 121 |
+
for idx, mask in enumerate(
|
| 122 |
+
["r_mask", "g_mask", "b_mask", "a_mask"]
|
| 123 |
+
):
|
| 124 |
+
file_info[mask] = i32(header_data, 36 + idx * 4)
|
| 125 |
+
else:
|
| 126 |
+
# 40 byte headers only have the three components in the
|
| 127 |
+
# bitfields masks, ref:
|
| 128 |
+
# https://msdn.microsoft.com/en-us/library/windows/desktop/dd183376(v=vs.85).aspx
|
| 129 |
+
# See also
|
| 130 |
+
# https://github.com/python-pillow/Pillow/issues/1293
|
| 131 |
+
# There is a 4th component in the RGBQuad, in the alpha
|
| 132 |
+
# location, but it is listed as a reserved component,
|
| 133 |
+
# and it is not generally an alpha channel
|
| 134 |
+
file_info["a_mask"] = 0x0
|
| 135 |
+
for mask in ["r_mask", "g_mask", "b_mask"]:
|
| 136 |
+
file_info[mask] = i32(read(4))
|
| 137 |
+
file_info["rgb_mask"] = (
|
| 138 |
+
file_info["r_mask"],
|
| 139 |
+
file_info["g_mask"],
|
| 140 |
+
file_info["b_mask"],
|
| 141 |
+
)
|
| 142 |
+
file_info["rgba_mask"] = (
|
| 143 |
+
file_info["r_mask"],
|
| 144 |
+
file_info["g_mask"],
|
| 145 |
+
file_info["b_mask"],
|
| 146 |
+
file_info["a_mask"],
|
| 147 |
+
)
|
| 148 |
+
else:
|
| 149 |
+
msg = f"Unsupported BMP header type ({file_info['header_size']})"
|
| 150 |
+
raise OSError(msg)
|
| 151 |
+
|
| 152 |
+
# ------------------ Special case : header is reported 40, which
|
| 153 |
+
# ---------------------- is shorter than real size for bpp >= 16
|
| 154 |
+
self._size = file_info["width"], file_info["height"]
|
| 155 |
+
|
| 156 |
+
# ------- If color count was not found in the header, compute from bits
|
| 157 |
+
file_info["colors"] = (
|
| 158 |
+
file_info["colors"]
|
| 159 |
+
if file_info.get("colors", 0)
|
| 160 |
+
else (1 << file_info["bits"])
|
| 161 |
+
)
|
| 162 |
+
if offset == 14 + file_info["header_size"] and file_info["bits"] <= 8:
|
| 163 |
+
offset += 4 * file_info["colors"]
|
| 164 |
+
|
| 165 |
+
# ---------------------- Check bit depth for unusual unsupported values
|
| 166 |
+
self._mode, raw_mode = BIT2MODE.get(file_info["bits"], (None, None))
|
| 167 |
+
if self.mode is None:
|
| 168 |
+
msg = f"Unsupported BMP pixel depth ({file_info['bits']})"
|
| 169 |
+
raise OSError(msg)
|
| 170 |
+
|
| 171 |
+
# ---------------- Process BMP with Bitfields compression (not palette)
|
| 172 |
+
decoder_name = "raw"
|
| 173 |
+
if file_info["compression"] == self.BITFIELDS:
|
| 174 |
+
SUPPORTED = {
|
| 175 |
+
32: [
|
| 176 |
+
(0xFF0000, 0xFF00, 0xFF, 0x0),
|
| 177 |
+
(0xFF000000, 0xFF0000, 0xFF00, 0x0),
|
| 178 |
+
(0xFF000000, 0xFF0000, 0xFF00, 0xFF),
|
| 179 |
+
(0xFF, 0xFF00, 0xFF0000, 0xFF000000),
|
| 180 |
+
(0xFF0000, 0xFF00, 0xFF, 0xFF000000),
|
| 181 |
+
(0x0, 0x0, 0x0, 0x0),
|
| 182 |
+
],
|
| 183 |
+
24: [(0xFF0000, 0xFF00, 0xFF)],
|
| 184 |
+
16: [(0xF800, 0x7E0, 0x1F), (0x7C00, 0x3E0, 0x1F)],
|
| 185 |
+
}
|
| 186 |
+
MASK_MODES = {
|
| 187 |
+
(32, (0xFF0000, 0xFF00, 0xFF, 0x0)): "BGRX",
|
| 188 |
+
(32, (0xFF000000, 0xFF0000, 0xFF00, 0x0)): "XBGR",
|
| 189 |
+
(32, (0xFF000000, 0xFF0000, 0xFF00, 0xFF)): "ABGR",
|
| 190 |
+
(32, (0xFF, 0xFF00, 0xFF0000, 0xFF000000)): "RGBA",
|
| 191 |
+
(32, (0xFF0000, 0xFF00, 0xFF, 0xFF000000)): "BGRA",
|
| 192 |
+
(32, (0x0, 0x0, 0x0, 0x0)): "BGRA",
|
| 193 |
+
(24, (0xFF0000, 0xFF00, 0xFF)): "BGR",
|
| 194 |
+
(16, (0xF800, 0x7E0, 0x1F)): "BGR;16",
|
| 195 |
+
(16, (0x7C00, 0x3E0, 0x1F)): "BGR;15",
|
| 196 |
+
}
|
| 197 |
+
if file_info["bits"] in SUPPORTED:
|
| 198 |
+
if (
|
| 199 |
+
file_info["bits"] == 32
|
| 200 |
+
and file_info["rgba_mask"] in SUPPORTED[file_info["bits"]]
|
| 201 |
+
):
|
| 202 |
+
raw_mode = MASK_MODES[(file_info["bits"], file_info["rgba_mask"])]
|
| 203 |
+
self._mode = "RGBA" if "A" in raw_mode else self.mode
|
| 204 |
+
elif (
|
| 205 |
+
file_info["bits"] in (24, 16)
|
| 206 |
+
and file_info["rgb_mask"] in SUPPORTED[file_info["bits"]]
|
| 207 |
+
):
|
| 208 |
+
raw_mode = MASK_MODES[(file_info["bits"], file_info["rgb_mask"])]
|
| 209 |
+
else:
|
| 210 |
+
msg = "Unsupported BMP bitfields layout"
|
| 211 |
+
raise OSError(msg)
|
| 212 |
+
else:
|
| 213 |
+
msg = "Unsupported BMP bitfields layout"
|
| 214 |
+
raise OSError(msg)
|
| 215 |
+
elif file_info["compression"] == self.RAW:
|
| 216 |
+
if file_info["bits"] == 32 and header == 22: # 32-bit .cur offset
|
| 217 |
+
raw_mode, self._mode = "BGRA", "RGBA"
|
| 218 |
+
elif file_info["compression"] in (self.RLE8, self.RLE4):
|
| 219 |
+
decoder_name = "bmp_rle"
|
| 220 |
+
else:
|
| 221 |
+
msg = f"Unsupported BMP compression ({file_info['compression']})"
|
| 222 |
+
raise OSError(msg)
|
| 223 |
+
|
| 224 |
+
# --------------- Once the header is processed, process the palette/LUT
|
| 225 |
+
if self.mode == "P": # Paletted for 1, 4 and 8 bit images
|
| 226 |
+
# ---------------------------------------------------- 1-bit images
|
| 227 |
+
if not (0 < file_info["colors"] <= 65536):
|
| 228 |
+
msg = f"Unsupported BMP Palette size ({file_info['colors']})"
|
| 229 |
+
raise OSError(msg)
|
| 230 |
+
else:
|
| 231 |
+
padding = file_info["palette_padding"]
|
| 232 |
+
palette = read(padding * file_info["colors"])
|
| 233 |
+
grayscale = True
|
| 234 |
+
indices = (
|
| 235 |
+
(0, 255)
|
| 236 |
+
if file_info["colors"] == 2
|
| 237 |
+
else list(range(file_info["colors"]))
|
| 238 |
+
)
|
| 239 |
+
|
| 240 |
+
# ----------------- Check if grayscale and ignore palette if so
|
| 241 |
+
for ind, val in enumerate(indices):
|
| 242 |
+
rgb = palette[ind * padding : ind * padding + 3]
|
| 243 |
+
if rgb != o8(val) * 3:
|
| 244 |
+
grayscale = False
|
| 245 |
+
|
| 246 |
+
# ------- If all colors are gray, white or black, ditch palette
|
| 247 |
+
if grayscale:
|
| 248 |
+
self._mode = "1" if file_info["colors"] == 2 else "L"
|
| 249 |
+
raw_mode = self.mode
|
| 250 |
+
else:
|
| 251 |
+
self._mode = "P"
|
| 252 |
+
self.palette = ImagePalette.raw(
|
| 253 |
+
"BGRX" if padding == 4 else "BGR", palette
|
| 254 |
+
)
|
| 255 |
+
|
| 256 |
+
# ---------------------------- Finally set the tile data for the plugin
|
| 257 |
+
self.info["compression"] = file_info["compression"]
|
| 258 |
+
args = [raw_mode]
|
| 259 |
+
if decoder_name == "bmp_rle":
|
| 260 |
+
args.append(file_info["compression"] == self.RLE4)
|
| 261 |
+
else:
|
| 262 |
+
args.append(((file_info["width"] * file_info["bits"] + 31) >> 3) & (~3))
|
| 263 |
+
args.append(file_info["direction"])
|
| 264 |
+
self.tile = [
|
| 265 |
+
(
|
| 266 |
+
decoder_name,
|
| 267 |
+
(0, 0, file_info["width"], file_info["height"]),
|
| 268 |
+
offset or self.fp.tell(),
|
| 269 |
+
tuple(args),
|
| 270 |
+
)
|
| 271 |
+
]
|
| 272 |
+
|
| 273 |
+
def _open(self):
|
| 274 |
+
"""Open file, check magic number and read header"""
|
| 275 |
+
# read 14 bytes: magic number, filesize, reserved, header final offset
|
| 276 |
+
head_data = self.fp.read(14)
|
| 277 |
+
# choke if the file does not have the required magic bytes
|
| 278 |
+
if not _accept(head_data):
|
| 279 |
+
msg = "Not a BMP file"
|
| 280 |
+
raise SyntaxError(msg)
|
| 281 |
+
# read the start position of the BMP image data (u32)
|
| 282 |
+
offset = i32(head_data, 10)
|
| 283 |
+
# load bitmap information (offset=raster info)
|
| 284 |
+
self._bitmap(offset=offset)
|
| 285 |
+
|
| 286 |
+
|
| 287 |
+
class BmpRleDecoder(ImageFile.PyDecoder):
|
| 288 |
+
_pulls_fd = True
|
| 289 |
+
|
| 290 |
+
def decode(self, buffer):
|
| 291 |
+
rle4 = self.args[1]
|
| 292 |
+
data = bytearray()
|
| 293 |
+
x = 0
|
| 294 |
+
dest_length = self.state.xsize * self.state.ysize
|
| 295 |
+
while len(data) < dest_length:
|
| 296 |
+
pixels = self.fd.read(1)
|
| 297 |
+
byte = self.fd.read(1)
|
| 298 |
+
if not pixels or not byte:
|
| 299 |
+
break
|
| 300 |
+
num_pixels = pixels[0]
|
| 301 |
+
if num_pixels:
|
| 302 |
+
# encoded mode
|
| 303 |
+
if x + num_pixels > self.state.xsize:
|
| 304 |
+
# Too much data for row
|
| 305 |
+
num_pixels = max(0, self.state.xsize - x)
|
| 306 |
+
if rle4:
|
| 307 |
+
first_pixel = o8(byte[0] >> 4)
|
| 308 |
+
second_pixel = o8(byte[0] & 0x0F)
|
| 309 |
+
for index in range(num_pixels):
|
| 310 |
+
if index % 2 == 0:
|
| 311 |
+
data += first_pixel
|
| 312 |
+
else:
|
| 313 |
+
data += second_pixel
|
| 314 |
+
else:
|
| 315 |
+
data += byte * num_pixels
|
| 316 |
+
x += num_pixels
|
| 317 |
+
else:
|
| 318 |
+
if byte[0] == 0:
|
| 319 |
+
# end of line
|
| 320 |
+
while len(data) % self.state.xsize != 0:
|
| 321 |
+
data += b"\x00"
|
| 322 |
+
x = 0
|
| 323 |
+
elif byte[0] == 1:
|
| 324 |
+
# end of bitmap
|
| 325 |
+
break
|
| 326 |
+
elif byte[0] == 2:
|
| 327 |
+
# delta
|
| 328 |
+
bytes_read = self.fd.read(2)
|
| 329 |
+
if len(bytes_read) < 2:
|
| 330 |
+
break
|
| 331 |
+
right, up = self.fd.read(2)
|
| 332 |
+
data += b"\x00" * (right + up * self.state.xsize)
|
| 333 |
+
x = len(data) % self.state.xsize
|
| 334 |
+
else:
|
| 335 |
+
# absolute mode
|
| 336 |
+
if rle4:
|
| 337 |
+
# 2 pixels per byte
|
| 338 |
+
byte_count = byte[0] // 2
|
| 339 |
+
bytes_read = self.fd.read(byte_count)
|
| 340 |
+
for byte_read in bytes_read:
|
| 341 |
+
data += o8(byte_read >> 4)
|
| 342 |
+
data += o8(byte_read & 0x0F)
|
| 343 |
+
else:
|
| 344 |
+
byte_count = byte[0]
|
| 345 |
+
bytes_read = self.fd.read(byte_count)
|
| 346 |
+
data += bytes_read
|
| 347 |
+
if len(bytes_read) < byte_count:
|
| 348 |
+
break
|
| 349 |
+
x += byte[0]
|
| 350 |
+
|
| 351 |
+
# align to 16-bit word boundary
|
| 352 |
+
if self.fd.tell() % 2 != 0:
|
| 353 |
+
self.fd.seek(1, os.SEEK_CUR)
|
| 354 |
+
rawmode = "L" if self.mode == "L" else "P"
|
| 355 |
+
self.set_as_raw(bytes(data), (rawmode, 0, self.args[-1]))
|
| 356 |
+
return -1, 0
|
| 357 |
+
|
| 358 |
+
|
| 359 |
+
# =============================================================================
|
| 360 |
+
# Image plugin for the DIB format (BMP alias)
|
| 361 |
+
# =============================================================================
|
| 362 |
+
class DibImageFile(BmpImageFile):
|
| 363 |
+
format = "DIB"
|
| 364 |
+
format_description = "Windows Bitmap"
|
| 365 |
+
|
| 366 |
+
def _open(self):
|
| 367 |
+
self._bitmap()
|
| 368 |
+
|
| 369 |
+
|
| 370 |
+
#
|
| 371 |
+
# --------------------------------------------------------------------
|
| 372 |
+
# Write BMP file
|
| 373 |
+
|
| 374 |
+
|
| 375 |
+
SAVE = {
|
| 376 |
+
"1": ("1", 1, 2),
|
| 377 |
+
"L": ("L", 8, 256),
|
| 378 |
+
"P": ("P", 8, 256),
|
| 379 |
+
"RGB": ("BGR", 24, 0),
|
| 380 |
+
"RGBA": ("BGRA", 32, 0),
|
| 381 |
+
}
|
| 382 |
+
|
| 383 |
+
|
| 384 |
+
def _dib_save(im, fp, filename):
|
| 385 |
+
_save(im, fp, filename, False)
|
| 386 |
+
|
| 387 |
+
|
| 388 |
+
def _save(im, fp, filename, bitmap_header=True):
|
| 389 |
+
try:
|
| 390 |
+
rawmode, bits, colors = SAVE[im.mode]
|
| 391 |
+
except KeyError as e:
|
| 392 |
+
msg = f"cannot write mode {im.mode} as BMP"
|
| 393 |
+
raise OSError(msg) from e
|
| 394 |
+
|
| 395 |
+
info = im.encoderinfo
|
| 396 |
+
|
| 397 |
+
dpi = info.get("dpi", (96, 96))
|
| 398 |
+
|
| 399 |
+
# 1 meter == 39.3701 inches
|
| 400 |
+
ppm = tuple(int(x * 39.3701 + 0.5) for x in dpi)
|
| 401 |
+
|
| 402 |
+
stride = ((im.size[0] * bits + 7) // 8 + 3) & (~3)
|
| 403 |
+
header = 40 # or 64 for OS/2 version 2
|
| 404 |
+
image = stride * im.size[1]
|
| 405 |
+
|
| 406 |
+
if im.mode == "1":
|
| 407 |
+
palette = b"".join(o8(i) * 4 for i in (0, 255))
|
| 408 |
+
elif im.mode == "L":
|
| 409 |
+
palette = b"".join(o8(i) * 4 for i in range(256))
|
| 410 |
+
elif im.mode == "P":
|
| 411 |
+
palette = im.im.getpalette("RGB", "BGRX")
|
| 412 |
+
colors = len(palette) // 4
|
| 413 |
+
else:
|
| 414 |
+
palette = None
|
| 415 |
+
|
| 416 |
+
# bitmap header
|
| 417 |
+
if bitmap_header:
|
| 418 |
+
offset = 14 + header + colors * 4
|
| 419 |
+
file_size = offset + image
|
| 420 |
+
if file_size > 2**32 - 1:
|
| 421 |
+
msg = "File size is too large for the BMP format"
|
| 422 |
+
raise ValueError(msg)
|
| 423 |
+
fp.write(
|
| 424 |
+
b"BM" # file type (magic)
|
| 425 |
+
+ o32(file_size) # file size
|
| 426 |
+
+ o32(0) # reserved
|
| 427 |
+
+ o32(offset) # image data offset
|
| 428 |
+
)
|
| 429 |
+
|
| 430 |
+
# bitmap info header
|
| 431 |
+
fp.write(
|
| 432 |
+
o32(header) # info header size
|
| 433 |
+
+ o32(im.size[0]) # width
|
| 434 |
+
+ o32(im.size[1]) # height
|
| 435 |
+
+ o16(1) # planes
|
| 436 |
+
+ o16(bits) # depth
|
| 437 |
+
+ o32(0) # compression (0=uncompressed)
|
| 438 |
+
+ o32(image) # size of bitmap
|
| 439 |
+
+ o32(ppm[0]) # resolution
|
| 440 |
+
+ o32(ppm[1]) # resolution
|
| 441 |
+
+ o32(colors) # colors used
|
| 442 |
+
+ o32(colors) # colors important
|
| 443 |
+
)
|
| 444 |
+
|
| 445 |
+
fp.write(b"\0" * (header - 40)) # padding (for OS/2 format)
|
| 446 |
+
|
| 447 |
+
if palette:
|
| 448 |
+
fp.write(palette)
|
| 449 |
+
|
| 450 |
+
ImageFile._save(im, fp, [("raw", (0, 0) + im.size, 0, (rawmode, stride, -1))])
|
| 451 |
+
|
| 452 |
+
|
| 453 |
+
#
|
| 454 |
+
# --------------------------------------------------------------------
|
| 455 |
+
# Registry
|
| 456 |
+
|
| 457 |
+
|
| 458 |
+
Image.register_open(BmpImageFile.format, BmpImageFile, _accept)
|
| 459 |
+
Image.register_save(BmpImageFile.format, _save)
|
| 460 |
+
|
| 461 |
+
Image.register_extension(BmpImageFile.format, ".bmp")
|
| 462 |
+
|
| 463 |
+
Image.register_mime(BmpImageFile.format, "image/bmp")
|
| 464 |
+
|
| 465 |
+
Image.register_decoder("bmp_rle", BmpRleDecoder)
|
| 466 |
+
|
| 467 |
+
Image.register_open(DibImageFile.format, DibImageFile, _dib_accept)
|
| 468 |
+
Image.register_save(DibImageFile.format, _dib_save)
|
| 469 |
+
|
| 470 |
+
Image.register_extension(DibImageFile.format, ".dib")
|
| 471 |
+
|
| 472 |
+
Image.register_mime(DibImageFile.format, "image/bmp")
|
.venv/lib/python3.11/site-packages/PIL/BufrStubImagePlugin.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#
|
| 2 |
+
# The Python Imaging Library
|
| 3 |
+
# $Id$
|
| 4 |
+
#
|
| 5 |
+
# BUFR stub adapter
|
| 6 |
+
#
|
| 7 |
+
# Copyright (c) 1996-2003 by Fredrik Lundh
|
| 8 |
+
#
|
| 9 |
+
# See the README file for information on usage and redistribution.
|
| 10 |
+
#
|
| 11 |
+
from __future__ import annotations
|
| 12 |
+
|
| 13 |
+
from . import Image, ImageFile
|
| 14 |
+
|
| 15 |
+
_handler = None
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def register_handler(handler):
|
| 19 |
+
"""
|
| 20 |
+
Install application-specific BUFR image handler.
|
| 21 |
+
|
| 22 |
+
:param handler: Handler object.
|
| 23 |
+
"""
|
| 24 |
+
global _handler
|
| 25 |
+
_handler = handler
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
# --------------------------------------------------------------------
|
| 29 |
+
# Image adapter
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def _accept(prefix):
|
| 33 |
+
return prefix[:4] == b"BUFR" or prefix[:4] == b"ZCZC"
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
class BufrStubImageFile(ImageFile.StubImageFile):
|
| 37 |
+
format = "BUFR"
|
| 38 |
+
format_description = "BUFR"
|
| 39 |
+
|
| 40 |
+
def _open(self):
|
| 41 |
+
offset = self.fp.tell()
|
| 42 |
+
|
| 43 |
+
if not _accept(self.fp.read(4)):
|
| 44 |
+
msg = "Not a BUFR file"
|
| 45 |
+
raise SyntaxError(msg)
|
| 46 |
+
|
| 47 |
+
self.fp.seek(offset)
|
| 48 |
+
|
| 49 |
+
# make something up
|
| 50 |
+
self._mode = "F"
|
| 51 |
+
self._size = 1, 1
|
| 52 |
+
|
| 53 |
+
loader = self._load()
|
| 54 |
+
if loader:
|
| 55 |
+
loader.open(self)
|
| 56 |
+
|
| 57 |
+
def _load(self):
|
| 58 |
+
return _handler
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def _save(im, fp, filename):
|
| 62 |
+
if _handler is None or not hasattr(_handler, "save"):
|
| 63 |
+
msg = "BUFR save handler not installed"
|
| 64 |
+
raise OSError(msg)
|
| 65 |
+
_handler.save(im, fp, filename)
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
# --------------------------------------------------------------------
|
| 69 |
+
# Registry
|
| 70 |
+
|
| 71 |
+
Image.register_open(BufrStubImageFile.format, BufrStubImageFile, _accept)
|
| 72 |
+
Image.register_save(BufrStubImageFile.format, _save)
|
| 73 |
+
|
| 74 |
+
Image.register_extension(BufrStubImageFile.format, ".bufr")
|