Spaces:
Sleeping
Sleeping
Commit
·
ffaa9fc
1
Parent(s):
eaf3284
Upload folder using huggingface_hub
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +61 -0
- .github/workflows/update_space.yml +28 -0
- Lib/site-packages/CHANGELOG.md +621 -0
- Lib/site-packages/GitPython-3.1.30.dist-info/AUTHORS +54 -0
- Lib/site-packages/GitPython-3.1.30.dist-info/INSTALLER +1 -0
- Lib/site-packages/GitPython-3.1.30.dist-info/LICENSE +30 -0
- Lib/site-packages/GitPython-3.1.30.dist-info/METADATA +33 -0
- Lib/site-packages/GitPython-3.1.30.dist-info/RECORD +83 -0
- Lib/site-packages/GitPython-3.1.30.dist-info/REQUESTED +0 -0
- Lib/site-packages/GitPython-3.1.30.dist-info/WHEEL +5 -0
- Lib/site-packages/GitPython-3.1.30.dist-info/top_level.txt +1 -0
- Lib/site-packages/Jinja2-3.1.2.dist-info/INSTALLER +1 -0
- Lib/site-packages/Jinja2-3.1.2.dist-info/LICENSE.rst +28 -0
- Lib/site-packages/Jinja2-3.1.2.dist-info/METADATA +113 -0
- Lib/site-packages/Jinja2-3.1.2.dist-info/RECORD +58 -0
- Lib/site-packages/Jinja2-3.1.2.dist-info/WHEEL +5 -0
- Lib/site-packages/Jinja2-3.1.2.dist-info/entry_points.txt +2 -0
- Lib/site-packages/Jinja2-3.1.2.dist-info/top_level.txt +1 -0
- Lib/site-packages/Markdown-3.4.3.dist-info/INSTALLER +1 -0
- Lib/site-packages/Markdown-3.4.3.dist-info/LICENSE.md +29 -0
- Lib/site-packages/Markdown-3.4.3.dist-info/METADATA +137 -0
- Lib/site-packages/Markdown-3.4.3.dist-info/RECORD +74 -0
- Lib/site-packages/Markdown-3.4.3.dist-info/WHEEL +5 -0
- Lib/site-packages/Markdown-3.4.3.dist-info/entry_points.txt +22 -0
- Lib/site-packages/Markdown-3.4.3.dist-info/top_level.txt +1 -0
- Lib/site-packages/MarkupSafe-2.1.3.dist-info/INSTALLER +1 -0
- Lib/site-packages/MarkupSafe-2.1.3.dist-info/LICENSE.rst +28 -0
- Lib/site-packages/MarkupSafe-2.1.3.dist-info/METADATA +93 -0
- Lib/site-packages/MarkupSafe-2.1.3.dist-info/RECORD +14 -0
- Lib/site-packages/MarkupSafe-2.1.3.dist-info/WHEEL +5 -0
- Lib/site-packages/MarkupSafe-2.1.3.dist-info/top_level.txt +1 -0
- Lib/site-packages/PIL/BdfFontFile.py +122 -0
- Lib/site-packages/PIL/BlpImagePlugin.py +488 -0
- Lib/site-packages/PIL/BmpImagePlugin.py +471 -0
- Lib/site-packages/PIL/BufrStubImagePlugin.py +73 -0
- Lib/site-packages/PIL/ContainerIO.py +120 -0
- Lib/site-packages/PIL/CurImagePlugin.py +75 -0
- Lib/site-packages/PIL/DcxImagePlugin.py +79 -0
- Lib/site-packages/PIL/DdsImagePlugin.py +291 -0
- Lib/site-packages/PIL/EpsImagePlugin.py +460 -0
- Lib/site-packages/PIL/ExifTags.py +380 -0
- Lib/site-packages/PIL/FitsImagePlugin.py +73 -0
- Lib/site-packages/PIL/FitsStubImagePlugin.py +76 -0
- Lib/site-packages/PIL/FliImagePlugin.py +171 -0
- Lib/site-packages/PIL/FontFile.py +110 -0
- Lib/site-packages/PIL/FpxImagePlugin.py +253 -0
- Lib/site-packages/PIL/FtexImagePlugin.py +125 -0
- Lib/site-packages/PIL/GbrImagePlugin.py +102 -0
- Lib/site-packages/PIL/GdImageFile.py +97 -0
- Lib/site-packages/PIL/GifImagePlugin.py +1064 -0
.gitattributes
CHANGED
@@ -33,3 +33,64 @@ 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 |
+
Lib/site-packages/altair/vegalite/v5/schema/__pycache__/core.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
37 |
+
Lib/site-packages/cv2/cv2.pyd filter=lfs diff=lfs merge=lfs -text
|
38 |
+
Lib/site-packages/cv2/opencv_videoio_ffmpeg480_64.dll filter=lfs diff=lfs merge=lfs -text
|
39 |
+
Lib/site-packages/google/protobuf/pyext/_message.cp310-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
40 |
+
Lib/site-packages/gradio/templates/cdn/assets/index-b22f1d20.js.map filter=lfs diff=lfs merge=lfs -text
|
41 |
+
Lib/site-packages/gradio/templates/frontend/assets/index-e33e7339.js.map filter=lfs diff=lfs merge=lfs -text
|
42 |
+
Lib/site-packages/grpc/_cython/cygrpc.cp310-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
43 |
+
Lib/site-packages/llvmlite/binding/llvmlite.dll filter=lfs diff=lfs merge=lfs -text
|
44 |
+
Lib/site-packages/numpy/.libs/libopenblas.FB5AE2TYXYH2IJRDKGDGQ3XBKLKTF43H.gfortran-win_amd64.dll filter=lfs diff=lfs merge=lfs -text
|
45 |
+
Lib/site-packages/numpy/core/_multiarray_umath.cp310-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
46 |
+
Lib/site-packages/numpy/core/_simd.cp310-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
47 |
+
Lib/site-packages/pandas/_libs/algos.cp310-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
48 |
+
Lib/site-packages/pandas/_libs/groupby.cp310-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
49 |
+
Lib/site-packages/pandas/_libs/hashtable.cp310-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
50 |
+
Lib/site-packages/pandas/_libs/join.cp310-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
51 |
+
Lib/site-packages/PIL/_imaging.cp310-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
52 |
+
Lib/site-packages/PIL/_imagingft.cp310-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
53 |
+
Lib/site-packages/scipy/fft/_pocketfft/pypocketfft.cp310-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
54 |
+
Lib/site-packages/scipy/interpolate/_rbfinterp_pythran.cp310-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
55 |
+
Lib/site-packages/scipy/linalg/_flapack.cp310-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
56 |
+
Lib/site-packages/scipy/misc/face.dat filter=lfs diff=lfs merge=lfs -text
|
57 |
+
Lib/site-packages/scipy/optimize/_group_columns.cp310-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
58 |
+
Lib/site-packages/scipy/optimize/_highs/_highs_wrapper.cp310-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
59 |
+
Lib/site-packages/scipy/signal/_max_len_seq_inner.cp310-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
60 |
+
Lib/site-packages/scipy/signal/_spectral.cp310-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
61 |
+
Lib/site-packages/scipy/sparse/_sparsetools.cp310-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
62 |
+
Lib/site-packages/scipy/spatial/_ckdtree.cp310-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
63 |
+
Lib/site-packages/scipy/spatial/_distance_pybind.cp310-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
64 |
+
Lib/site-packages/scipy/spatial/_qhull.cp310-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
65 |
+
Lib/site-packages/scipy/special/_ufuncs.cp310-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
66 |
+
Lib/site-packages/scipy/special/_ufuncs_cxx.cp310-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
67 |
+
Lib/site-packages/scipy/special/cython_special.cp310-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
68 |
+
Lib/site-packages/scipy/stats/_boost/beta_ufunc.cp310-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
69 |
+
Lib/site-packages/scipy/stats/_boost/binom_ufunc.cp310-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
70 |
+
Lib/site-packages/scipy/stats/_boost/invgauss_ufunc.cp310-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
71 |
+
Lib/site-packages/scipy/stats/_boost/nbinom_ufunc.cp310-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
72 |
+
Lib/site-packages/scipy/stats/_boost/ncf_ufunc.cp310-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
73 |
+
Lib/site-packages/scipy/stats/_boost/nct_ufunc.cp310-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
74 |
+
Lib/site-packages/scipy/stats/_boost/ncx2_ufunc.cp310-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
75 |
+
Lib/site-packages/scipy/stats/_stats_pythran.cp310-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
76 |
+
Lib/site-packages/scipy/stats/_unuran/unuran_wrapper.cp310-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
77 |
+
Lib/site-packages/scipy.libs/libopenblas_v0.3.20-571-g3dec11c6-gcc_10_3_0-c2315440d6b6cef5037bad648efc8c59.dll filter=lfs diff=lfs merge=lfs -text
|
78 |
+
Lib/site-packages/sentencepiece/_sentencepiece.cp310-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
79 |
+
Lib/site-packages/skimage/filters/rank/generic_cy.cp310-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
80 |
+
Lib/site-packages/tokenizers/tokenizers.cp310-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
81 |
+
Lib/site-packages/torch/bin/fbgemm.dll filter=lfs diff=lfs merge=lfs -text
|
82 |
+
Lib/site-packages/torch/bin/protoc.exe filter=lfs diff=lfs merge=lfs -text
|
83 |
+
Lib/site-packages/torch/lib/dnnl.lib filter=lfs diff=lfs merge=lfs -text
|
84 |
+
Lib/site-packages/torch/lib/fbgemm.dll filter=lfs diff=lfs merge=lfs -text
|
85 |
+
Lib/site-packages/torch/lib/fbgemm.lib filter=lfs diff=lfs merge=lfs -text
|
86 |
+
Lib/site-packages/torch/lib/kineto.lib filter=lfs diff=lfs merge=lfs -text
|
87 |
+
Lib/site-packages/torch/lib/libiomp5md.dll filter=lfs diff=lfs merge=lfs -text
|
88 |
+
Lib/site-packages/torch/lib/libprotobuf-lite.lib filter=lfs diff=lfs merge=lfs -text
|
89 |
+
Lib/site-packages/torch/lib/libprotobuf.lib filter=lfs diff=lfs merge=lfs -text
|
90 |
+
Lib/site-packages/torch/lib/libprotoc.lib filter=lfs diff=lfs merge=lfs -text
|
91 |
+
Lib/site-packages/torch/lib/torch_cpu.dll filter=lfs diff=lfs merge=lfs -text
|
92 |
+
Lib/site-packages/torch/lib/torch_cpu.lib filter=lfs diff=lfs merge=lfs -text
|
93 |
+
Lib/site-packages/torch/lib/torch_python.dll filter=lfs diff=lfs merge=lfs -text
|
94 |
+
Lib/site-packages/torch/lib/XNNPACK.lib filter=lfs diff=lfs merge=lfs -text
|
95 |
+
Lib/site-packages/torch_directml/DirectML.dll filter=lfs diff=lfs merge=lfs -text
|
96 |
+
Lib/site-packages/torch_directml_native.cp310-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
.github/workflows/update_space.yml
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: Run Python script
|
2 |
+
|
3 |
+
on:
|
4 |
+
push:
|
5 |
+
branches:
|
6 |
+
- main
|
7 |
+
|
8 |
+
jobs:
|
9 |
+
build:
|
10 |
+
runs-on: ubuntu-latest
|
11 |
+
|
12 |
+
steps:
|
13 |
+
- name: Checkout
|
14 |
+
uses: actions/checkout@v2
|
15 |
+
|
16 |
+
- name: Set up Python
|
17 |
+
uses: actions/setup-python@v2
|
18 |
+
with:
|
19 |
+
python-version: '3.9'
|
20 |
+
|
21 |
+
- name: Install Gradio
|
22 |
+
run: python -m pip install gradio
|
23 |
+
|
24 |
+
- name: Log in to Hugging Face
|
25 |
+
run: python -c 'import huggingface_hub; huggingface_hub.login(token="${{ secrets.hf_token }}")'
|
26 |
+
|
27 |
+
- name: Deploy to Spaces
|
28 |
+
run: gradio deploy
|
Lib/site-packages/CHANGELOG.md
ADDED
@@ -0,0 +1,621 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
## Version 6.1.1 (February 9, 2022)
|
2 |
+
|
3 |
+
- Updated the heuristic to fix the letter ß in UTF-8/MacRoman mojibake,
|
4 |
+
which had regressed since version 5.6.
|
5 |
+
|
6 |
+
- Packaging fixes to pyproject.toml.
|
7 |
+
|
8 |
+
## Version 6.1 (February 9, 2022)
|
9 |
+
|
10 |
+
- Updated the heuristic to fix the letter Ñ with more confidence.
|
11 |
+
|
12 |
+
- Fixed type annotations and added py.typed.
|
13 |
+
|
14 |
+
- ftfy is packaged using Poetry now, and wheels are created and uploaded to
|
15 |
+
PyPI.
|
16 |
+
|
17 |
+
## Version 6.0.3 (May 14, 2021)
|
18 |
+
|
19 |
+
- Allow the keyword argument `fix_entities` as a deprecated alias for
|
20 |
+
`unescape_html`, raising a warning.
|
21 |
+
|
22 |
+
- `ftfy.formatting` functions now disregard ANSI terminal escapes when
|
23 |
+
calculating text width.
|
24 |
+
|
25 |
+
|
26 |
+
## Version 6.0.2 (May 4, 2021)
|
27 |
+
|
28 |
+
This version is purely a cosmetic change, updating the maintainer's e-mail
|
29 |
+
address and the project's canonical location on GitHub.
|
30 |
+
|
31 |
+
|
32 |
+
## Version 6.0.1 (April 12, 2021)
|
33 |
+
|
34 |
+
- The `remove_terminal_escapes` step was accidentally not being used. This
|
35 |
+
version restores it.
|
36 |
+
|
37 |
+
- Specified in setup.py that ftfy 6 requires Python 3.6 or later.
|
38 |
+
|
39 |
+
- Use a lighter link color when the docs are viewed in dark mode.
|
40 |
+
|
41 |
+
## Version 6.0 (April 2, 2021)
|
42 |
+
|
43 |
+
- New function: `ftfy.fix_and_explain()` can describe all the transformations
|
44 |
+
that happen when fixing a string. This is similar to what
|
45 |
+
`ftfy.fixes.fix_encoding_and_explain()` did in previous versions, but it
|
46 |
+
can fix more than the encoding.
|
47 |
+
|
48 |
+
- `fix_and_explain()` and `fix_encoding_and_explain()` are now in the top-level
|
49 |
+
ftfy module.
|
50 |
+
|
51 |
+
- Changed the heuristic entirely. ftfy no longer needs to categorize every
|
52 |
+
Unicode character, but only characters that are expected to appear in
|
53 |
+
mojibake.
|
54 |
+
|
55 |
+
- Because of the new heuristic, ftfy will no longer have to release a new
|
56 |
+
version for every new version of Unicode. It should also run faster and
|
57 |
+
use less RAM when imported.
|
58 |
+
|
59 |
+
- The heuristic `ftfy.badness.is_bad(text)` can be used to determine whether
|
60 |
+
there appears to be mojibake in a string. Some users were already using
|
61 |
+
the old function `sequence_weirdness()` for that, but this one is actually
|
62 |
+
designed for that purpose.
|
63 |
+
|
64 |
+
- Instead of a pile of named keyword arguments, ftfy functions now take in
|
65 |
+
a TextFixerConfig object. The keyword arguments still work, and become
|
66 |
+
settings that override the defaults in TextFixerConfig.
|
67 |
+
|
68 |
+
- Added support for UTF-8 mixups with Windows-1253 and Windows-1254.
|
69 |
+
|
70 |
+
- Overhauled the documentation: https://ftfy.readthedocs.org
|
71 |
+
|
72 |
+
## Version 5.9 (February 10, 2021)
|
73 |
+
|
74 |
+
This version is brought to you by the letter à and the number 0xC3.
|
75 |
+
|
76 |
+
- Tweaked the heuristic to decode, for example, "Ã " as the letter "à"
|
77 |
+
more often.
|
78 |
+
|
79 |
+
- This combines with the non-breaking-space fixer to decode "Ã " as "à" as
|
80 |
+
well. However, in many cases, the text " Ã " was intended to be " à ",
|
81 |
+
preserving the space -- the underlying mojibake had two spaces after it, but
|
82 |
+
the Web coalesced them into one. We detect this case based on common French
|
83 |
+
and Portuguese words, and preserve the space when it appears intended.
|
84 |
+
|
85 |
+
Thanks to @zehavoc for bringing to my attention how common this case is.
|
86 |
+
|
87 |
+
- Updated the data file of Unicode character categories to Unicode 13, as
|
88 |
+
used in Python 3.9. (No matter what version of Python you're on, ftfy uses
|
89 |
+
the same data.)
|
90 |
+
|
91 |
+
## Version 5.8 (July 17, 2020)
|
92 |
+
|
93 |
+
- Improved detection of UTF-8 mojibake of Greek, Cyrillic, Hebrew, and Arabic
|
94 |
+
scripts.
|
95 |
+
|
96 |
+
- Fixed the undeclared dependency on setuptools by removing the use of
|
97 |
+
`pkg_resources`.
|
98 |
+
|
99 |
+
## Version 5.7 (February 18, 2020)
|
100 |
+
|
101 |
+
- Updated the data file of Unicode character categories to Unicode 12.1, as
|
102 |
+
used in Python 3.8. (No matter what version of Python you're on, ftfy uses
|
103 |
+
the same data.)
|
104 |
+
|
105 |
+
- Corrected an omission where short sequences involving the ACUTE ACCENT
|
106 |
+
character were not being fixed.
|
107 |
+
|
108 |
+
## Version 5.6 (August 7, 2019)
|
109 |
+
|
110 |
+
- The `unescape_html` function now supports all the HTML5 entities that appear
|
111 |
+
in `html.entities.html5`, including those with long names such as
|
112 |
+
`˝`.
|
113 |
+
|
114 |
+
- Unescaping of numeric HTML entities now uses the standard library's
|
115 |
+
`html.unescape`, making edge cases consistent.
|
116 |
+
|
117 |
+
(The reason we don't run `html.unescape` on all text is that it's not always
|
118 |
+
appropriate to apply, and can lead to false positive fixes. The text
|
119 |
+
"This&NotThat" should not have "&Not" replaced by a symbol, as
|
120 |
+
`html.unescape` would do.)
|
121 |
+
|
122 |
+
- On top of Python's support for HTML5 entities, ftfy will also convert HTML
|
123 |
+
escapes of common Latin capital letters that are (nonstandardly) written
|
124 |
+
in all caps, such as `Ñ` for `Ñ`.
|
125 |
+
|
126 |
+
|
127 |
+
## Version 5.5.1 (September 14, 2018)
|
128 |
+
|
129 |
+
- Added Python 3.7 support.
|
130 |
+
|
131 |
+
- Updated the data file of Unicode character categories to Unicode 11, as used
|
132 |
+
in Python 3.7.0. (No matter what version of Python you're on, ftfy uses the
|
133 |
+
same data.)
|
134 |
+
|
135 |
+
|
136 |
+
## Version 5.5 (September 6, 2018)
|
137 |
+
|
138 |
+
- Recent versions have emphasized making a reasonable attempt to fix short,
|
139 |
+
common mojibake sequences, such as `û`. In this version, we've expanded the
|
140 |
+
heuristics to recognize these sequences in MacRoman as well as Windows-125x
|
141 |
+
encodings.
|
142 |
+
|
143 |
+
- A related rule for fixing isolated Windows-1252/UTF-8 mixups, even when they
|
144 |
+
were inconsistent with the rest of the string, claimed to work on Latin-1/UTF-8
|
145 |
+
mixups as well, but in practice it didn't. We've made the rule more robust.
|
146 |
+
|
147 |
+
- Fixed a failure when testing the CLI on Windows.
|
148 |
+
|
149 |
+
- Removed the `pytest-runner` invocation from setup.py, as it created complex
|
150 |
+
dependencies that would stop setup.py from working in some environments.
|
151 |
+
The `pytest` command still works fine. `pytest-runner` is just too clever.
|
152 |
+
|
153 |
+
|
154 |
+
## Version 5.4.1 (June 14, 2018)
|
155 |
+
|
156 |
+
- Fixed a bug in the `setup.py` metadata.
|
157 |
+
|
158 |
+
This bug was causing ftfy, a package that fixes encoding mismatches, to not
|
159 |
+
install in some environments due to an encoding mismatch. (We were really
|
160 |
+
putting the "meta" in "metadata" here.)
|
161 |
+
|
162 |
+
|
163 |
+
## Version 5.4 (June 1, 2018)
|
164 |
+
|
165 |
+
- ftfy was still too conservative about fixing short mojibake sequences,
|
166 |
+
such as "août" -> "août", when the broken version contained punctuation
|
167 |
+
such as curly or angle quotation marks.
|
168 |
+
|
169 |
+
The new heuristic observes in some cases that, even if quotation marks are
|
170 |
+
expected to appear next to letters, it is strange to have an accented capital
|
171 |
+
A before the quotation mark and more letters after the quotation mark.
|
172 |
+
|
173 |
+
- Provides better metadata for the new PyPI.
|
174 |
+
|
175 |
+
- Switched from nosetests to pytest.
|
176 |
+
|
177 |
+
|
178 |
+
## Version 5.3 (January 25, 2018)
|
179 |
+
|
180 |
+
- A heuristic has been too conservative since version 4.2, causing a regression
|
181 |
+
compared to previous versions: ftfy would fail to fix mojibake of common
|
182 |
+
characters such as `á` when seen in isolation. A new heuristic now makes it
|
183 |
+
possible to fix more of these common cases with less evidence.
|
184 |
+
|
185 |
+
|
186 |
+
## Version 5.2 (November 27, 2017)
|
187 |
+
|
188 |
+
- The command-line tool will not accept the same filename as its input
|
189 |
+
and output. (Previously, this would write a zero-length file.)
|
190 |
+
|
191 |
+
- The `uncurl_quotes` fixer, which replaces curly quotes with straight quotes,
|
192 |
+
now also replaces MODIFIER LETTER APOSTROPHE.
|
193 |
+
|
194 |
+
- Codepoints that contain two Latin characters crammed together for legacy
|
195 |
+
encoding reasons are replaced by those two separate characters, even in NFC
|
196 |
+
mode. We formerly did this just with ligatures such as `fi` and `IJ`, but now
|
197 |
+
this includes the Afrikaans digraph `ʼn` and Serbian/Croatian digraphs such as
|
198 |
+
`dž`.
|
199 |
+
|
200 |
+
|
201 |
+
## Version 5.1.1 and 4.4.3 (May 15, 2017)
|
202 |
+
|
203 |
+
These releases fix two unrelated problems with the tests, one in each version.
|
204 |
+
|
205 |
+
- v5.1.1: fixed the CLI tests (which are new in v5) so that they pass
|
206 |
+
on Windows, as long as the Python output encoding is UTF-8.
|
207 |
+
|
208 |
+
- v4.4.3: added the `# coding: utf-8` declaration to two files that were
|
209 |
+
missing it, so that tests can run on Python 2.
|
210 |
+
|
211 |
+
## Version 5.1 (April 7, 2017)
|
212 |
+
|
213 |
+
- Removed the dependency on `html5lib` by dropping support for Python 3.2.
|
214 |
+
|
215 |
+
We previously used the dictionary `html5lib.constants.entities` to decode
|
216 |
+
HTML entities. In Python 3.3 and later, that exact dictionary is now in the
|
217 |
+
standard library as `html.entities.html5`.
|
218 |
+
|
219 |
+
- Moved many test cases about how particular text should be fixed into
|
220 |
+
`test_cases.json`, which may ease porting to other languages.
|
221 |
+
|
222 |
+
The functionality of this version remains the same as 5.0.2 and 4.4.2.
|
223 |
+
|
224 |
+
|
225 |
+
## Version 5.0.2 and 4.4.2 (March 21, 2017)
|
226 |
+
|
227 |
+
Added a `MANIFEST.in` that puts files such as the license file and this
|
228 |
+
changelog inside the source distribution.
|
229 |
+
|
230 |
+
|
231 |
+
## Version 5.0.1 and 4.4.1 (March 10, 2017)
|
232 |
+
|
233 |
+
Bug fix:
|
234 |
+
|
235 |
+
- The `unescape_html` fixer will decode entities between `€` and `Ÿ`
|
236 |
+
as what they would be in Windows-1252, even without the help of
|
237 |
+
`fix_encoding`.
|
238 |
+
|
239 |
+
This better matches what Web browsers do, and fixes a regression that version
|
240 |
+
4.4 introduced in an example that uses `…` as an ellipsis.
|
241 |
+
|
242 |
+
|
243 |
+
## Version 5.0 (February 17, 2017)
|
244 |
+
|
245 |
+
Breaking changes:
|
246 |
+
|
247 |
+
- Dropped support for Python 2. If you need Python 2 support, you should get
|
248 |
+
version 4.4, which has the same features as this version.
|
249 |
+
|
250 |
+
- The top-level functions require their arguments to be given as keyword
|
251 |
+
arguments.
|
252 |
+
|
253 |
+
Version 5.0 also now has tests for the command-line invocation of ftfy.
|
254 |
+
|
255 |
+
|
256 |
+
## Version 4.4.0 (February 17, 2017)
|
257 |
+
|
258 |
+
Heuristic changes:
|
259 |
+
|
260 |
+
- ftfy can now fix mojibake involving the Windows-1250 or ISO-8859-2 encodings.
|
261 |
+
|
262 |
+
- The `fix_entities` fixer is now applied after `fix_encoding`. This makes
|
263 |
+
more situations resolvable when both fixes are needed.
|
264 |
+
|
265 |
+
- With a few exceptions for commonly-used characters such as `^`, it is now
|
266 |
+
considered "weird" whenever a diacritic appears in non-combining form,
|
267 |
+
such as the diaeresis character `¨`.
|
268 |
+
|
269 |
+
- It is also now weird when IPA phonetic letters, besides `ə`, appear next to
|
270 |
+
capital letters.
|
271 |
+
|
272 |
+
- These changes to the heuristics, and others we've made in recent versions,
|
273 |
+
let us lower the "cost" for fixing mojibake in some encodings, causing them
|
274 |
+
to be fixed in more cases.
|
275 |
+
|
276 |
+
|
277 |
+
## Version 4.3.1 (January 12, 2017)
|
278 |
+
|
279 |
+
Bug fix:
|
280 |
+
|
281 |
+
- `remove_control_chars` was removing U+0D ('\r') prematurely. That's the
|
282 |
+
job of `fix_line_breaks`.
|
283 |
+
|
284 |
+
|
285 |
+
## Version 4.3.0 (December 29, 2016)
|
286 |
+
|
287 |
+
ftfy has gotten by for four years without dependencies on other Python
|
288 |
+
libraries, but now we can spare ourselves some code and some maintenance burden
|
289 |
+
by delegating certain tasks to other libraries that already solve them well.
|
290 |
+
This version now depends on the `html5lib` and `wcwidth` libraries.
|
291 |
+
|
292 |
+
Feature changes:
|
293 |
+
|
294 |
+
- The `remove_control_chars` fixer will now remove some non-ASCII control
|
295 |
+
characters as well, such as deprecated Arabic control characters and
|
296 |
+
byte-order marks. Bidirectional controls are still left as is.
|
297 |
+
|
298 |
+
This should have no impact on well-formed text, while cleaning up many
|
299 |
+
characters that the Unicode Consortium deems "not suitable for markup"
|
300 |
+
(see Unicode Technical Report #20).
|
301 |
+
|
302 |
+
- The `unescape_html` fixer uses a more thorough list of HTML entities,
|
303 |
+
which it imports from `html5lib`.
|
304 |
+
|
305 |
+
- `ftfy.formatting` now uses `wcwidth` to compute the width that a string
|
306 |
+
will occupy in a text console.
|
307 |
+
|
308 |
+
Heuristic changes:
|
309 |
+
|
310 |
+
- Updated the data file of Unicode character categories to Unicode 9, as used
|
311 |
+
in Python 3.6.0. (No matter what version of Python you're on, ftfy uses the
|
312 |
+
same data.)
|
313 |
+
|
314 |
+
Pending deprecations:
|
315 |
+
|
316 |
+
- The `remove_bom` option will become deprecated in 5.0, because it has been
|
317 |
+
superseded by `remove_control_chars`.
|
318 |
+
|
319 |
+
- ftfy 5.0 will remove the previously deprecated name `fix_text_encoding`. It
|
320 |
+
was renamed to `fix_encoding` in 4.0.
|
321 |
+
|
322 |
+
- ftfy 5.0 will require Python 3.2 or later, as planned. Python 2 users, please
|
323 |
+
specify `ftfy < 5` in your dependencies if you haven't already.
|
324 |
+
|
325 |
+
|
326 |
+
## Version 4.2.0 (September 28, 2016)
|
327 |
+
|
328 |
+
Heuristic changes:
|
329 |
+
|
330 |
+
- Math symbols next to currency symbols are no longer considered 'weird' by the
|
331 |
+
heuristic. This fixes a false positive where text that involved the
|
332 |
+
multiplication sign and British pounds or euros (as in '5×£35') could turn
|
333 |
+
into Hebrew letters.
|
334 |
+
|
335 |
+
- A heuristic that used to be a bonus for certain punctuation now also gives a
|
336 |
+
bonus to successfully decoding other common codepoints, such as the
|
337 |
+
non-breaking space, the degree sign, and the byte order mark.
|
338 |
+
|
339 |
+
- In version 4.0, we tried to "future-proof" the categorization of emoji (as a
|
340 |
+
kind of symbol) to include codepoints that would likely be assigned to emoji
|
341 |
+
later. The future happened, and there are even more emoji than we expected.
|
342 |
+
We have expanded the range to include those emoji, too.
|
343 |
+
|
344 |
+
ftfy is still mostly based on information from Unicode 8 (as Python 3.5 is),
|
345 |
+
but this expanded range should include the emoji from Unicode 9 and 10.
|
346 |
+
|
347 |
+
- Emoji are increasingly being modified by variation selectors and skin-tone
|
348 |
+
modifiers. Those codepoints are now grouped with 'symbols' in ftfy, so they
|
349 |
+
fit right in with emoji, instead of being considered 'marks' as their Unicode
|
350 |
+
category would suggest.
|
351 |
+
|
352 |
+
This enables fixing mojibake that involves iOS's new diverse emoji.
|
353 |
+
|
354 |
+
- An old heuristic that wasn't necessary anymore considered Latin text with
|
355 |
+
high-numbered codepoints to be 'weird', but this is normal in languages such
|
356 |
+
as Vietnamese and Azerbaijani. This does not seem to have caused any false
|
357 |
+
positives, but it caused ftfy to be too reluctant to fix some cases of broken
|
358 |
+
text in those languages.
|
359 |
+
|
360 |
+
The heuristic has been changed, and all languages that use Latin letters
|
361 |
+
should be on even footing now.
|
362 |
+
|
363 |
+
|
364 |
+
## Version 4.1.1 (April 13, 2016)
|
365 |
+
|
366 |
+
- Bug fix: in the command-line interface, the `-e` option had no effect on
|
367 |
+
Python 3 when using standard input. Now, it correctly lets you specify
|
368 |
+
a different encoding for standard input.
|
369 |
+
|
370 |
+
|
371 |
+
## Version 4.1.0 (February 25, 2016)
|
372 |
+
|
373 |
+
Heuristic changes:
|
374 |
+
|
375 |
+
- ftfy can now deal with "lossy" mojibake. If your text has been run through
|
376 |
+
a strict Windows-1252 decoder, such as the one in Python, it may contain
|
377 |
+
the replacement character � (U+FFFD) where there were bytes that are
|
378 |
+
unassigned in Windows-1252.
|
379 |
+
|
380 |
+
Although ftfy won't recover the lost information, it can now detect this
|
381 |
+
situation, replace the entire lossy character with �, and decode the rest of
|
382 |
+
the characters. Previous versions would be unable to fix any string that
|
383 |
+
contained U+FFFD.
|
384 |
+
|
385 |
+
As an example, text in curly quotes that gets corrupted `“ like this �`
|
386 |
+
now gets fixed to be `“ like this �`.
|
387 |
+
|
388 |
+
- Updated the data file of Unicode character categories to Unicode 8.0, as used
|
389 |
+
in Python 3.5.0. (No matter what version of Python you're on, ftfy uses the
|
390 |
+
same data.)
|
391 |
+
|
392 |
+
- Heuristics now count characters such as `~` and `^` as punctuation instead
|
393 |
+
of wacky math symbols, improving the detection of mojibake in some edge cases.
|
394 |
+
|
395 |
+
New features:
|
396 |
+
|
397 |
+
- A new module, `ftfy.formatting`, can be used to justify Unicode text in a
|
398 |
+
monospaced terminal. It takes into account that each character can take up
|
399 |
+
anywhere from 0 to 2 character cells.
|
400 |
+
|
401 |
+
- Internally, the `utf-8-variants` codec was simplified and optimized.
|
402 |
+
|
403 |
+
|
404 |
+
## Version 4.0.0 (April 10, 2015)
|
405 |
+
|
406 |
+
Breaking changes:
|
407 |
+
|
408 |
+
- The default normalization form is now NFC, not NFKC. NFKC replaces a large
|
409 |
+
number of characters with 'equivalent' characters, and some of these
|
410 |
+
replacements are useful, but some are not desirable to do by default.
|
411 |
+
|
412 |
+
- The `fix_text` function has some new options that perform more targeted
|
413 |
+
operations that are part of NFKC normalization, such as
|
414 |
+
`fix_character_width`, without requiring hitting all your text with the huge
|
415 |
+
mallet that is NFKC.
|
416 |
+
|
417 |
+
- If you were already using NFC normalization, or in general if you want to
|
418 |
+
preserve the *spacing* of CJK text, you should be sure to set
|
419 |
+
`fix_character_width=False`.
|
420 |
+
|
421 |
+
- The `remove_unsafe_private_use` parameter has been removed entirely, after
|
422 |
+
two versions of deprecation. The function name `fix_bad_encoding` is also
|
423 |
+
gone.
|
424 |
+
|
425 |
+
New features:
|
426 |
+
|
427 |
+
- Fixers for strange new forms of mojibake, including particularly clear cases
|
428 |
+
of mixed UTF-8 and Windows-1252.
|
429 |
+
|
430 |
+
- New heuristics, so that ftfy can fix more stuff, while maintaining
|
431 |
+
approximately zero false positives.
|
432 |
+
|
433 |
+
- The command-line tool trusts you to know what encoding your *input* is in,
|
434 |
+
and assumes UTF-8 by default. You can still tell it to guess with the `-g`
|
435 |
+
option.
|
436 |
+
|
437 |
+
- The command-line tool can be configured with options, and can be used as a
|
438 |
+
pipe.
|
439 |
+
|
440 |
+
- Recognizes characters that are new in Unicode 7.0, as well as emoji from
|
441 |
+
Unicode 8.0+ that may already be in use on iOS.
|
442 |
+
|
443 |
+
Deprecations:
|
444 |
+
|
445 |
+
- `fix_text_encoding` is being renamed again, for conciseness and consistency.
|
446 |
+
It's now simply called `fix_encoding`. The name `fix_text_encoding` is
|
447 |
+
available but emits a warning.
|
448 |
+
|
449 |
+
Pending deprecations:
|
450 |
+
|
451 |
+
- Python 2.6 support is largely coincidental.
|
452 |
+
|
453 |
+
- Python 2.7 support is on notice. If you use Python 2, be sure to pin a
|
454 |
+
version of ftfy less than 5.0 in your requirements.
|
455 |
+
|
456 |
+
|
457 |
+
## Version 3.4.0 (January 15, 2015)
|
458 |
+
|
459 |
+
New features:
|
460 |
+
|
461 |
+
- `ftfy.fixes.fix_surrogates` will fix all 16-bit surrogate codepoints,
|
462 |
+
which would otherwise break various encoding and output functions.
|
463 |
+
|
464 |
+
Deprecations:
|
465 |
+
|
466 |
+
- `remove_unsafe_private_use` emits a warning, and will disappear in the
|
467 |
+
next minor or major version.
|
468 |
+
|
469 |
+
|
470 |
+
## Version 3.3.1 (December 12, 2014)
|
471 |
+
|
472 |
+
This version restores compatibility with Python 2.6.
|
473 |
+
|
474 |
+
|
475 |
+
## Version 3.3.0 (August 16, 2014)
|
476 |
+
|
477 |
+
Heuristic changes:
|
478 |
+
|
479 |
+
- Certain symbols are marked as "ending punctuation" that may naturally occur
|
480 |
+
after letters. When they follow an accented capital letter and look like
|
481 |
+
mojibake, they will not be "fixed" without further evidence.
|
482 |
+
An example is that "MARQUÉ…" will become "MARQUÉ...", and not "MARQUɅ".
|
483 |
+
|
484 |
+
New features:
|
485 |
+
|
486 |
+
- `ftfy.explain_unicode` is a diagnostic function that shows you what's going
|
487 |
+
on in a Unicode string. It shows you a table with each code point in
|
488 |
+
hexadecimal, its glyph, its name, and its Unicode category.
|
489 |
+
|
490 |
+
- `ftfy.fixes.decode_escapes` adds a feature missing from the standard library:
|
491 |
+
it lets you decode a Unicode string with backslashed escape sequences in it
|
492 |
+
(such as "\u2014") the same way that Python itself would.
|
493 |
+
|
494 |
+
- `ftfy.streamtester` is a release of the code that I use to test ftfy on
|
495 |
+
an endless stream of real-world data from Twitter. With the new heuristics,
|
496 |
+
the false positive rate of ftfy is about 1 per 6 million tweets. (See
|
497 |
+
the "Accuracy" section of the documentation.)
|
498 |
+
|
499 |
+
Deprecations:
|
500 |
+
|
501 |
+
- Python 2.6 is no longer supported.
|
502 |
+
|
503 |
+
- `remove_unsafe_private_use` is no longer needed in any current version of
|
504 |
+
Python. This fixer will disappear in a later version of ftfy.
|
505 |
+
|
506 |
+
|
507 |
+
## Version 3.2.0 (June 27, 2014)
|
508 |
+
|
509 |
+
- `fix_line_breaks` fixes three additional characters that are considered line
|
510 |
+
breaks in some environments, such as Javascript, and Python's "codecs"
|
511 |
+
library. These are all now replaced with \n:
|
512 |
+
|
513 |
+
U+0085 <control>, with alias "NEXT LINE"
|
514 |
+
U+2028 LINE SEPARATOR
|
515 |
+
U+2029 PARAGRAPH SEPARATOR
|
516 |
+
|
517 |
+
|
518 |
+
## Version 3.1.3 (May 15, 2014)
|
519 |
+
|
520 |
+
- Fix `utf-8-variants` so it never outputs surrogate codepoints, even on
|
521 |
+
Python 2 where that would otherwise be possible.
|
522 |
+
|
523 |
+
|
524 |
+
## Version 3.1.2 (January 29, 2014)
|
525 |
+
|
526 |
+
- Fix bug in 3.1.1 where strings with backslashes in them could never be fixed
|
527 |
+
|
528 |
+
|
529 |
+
## Version 3.1.1 (January 29, 2014)
|
530 |
+
|
531 |
+
- Add the `ftfy.bad_codecs` package, which registers new codecs that can
|
532 |
+
decoding things that Python may otherwise refuse to decode:
|
533 |
+
|
534 |
+
- `utf-8-variants`, which decodes CESU-8 and its Java lookalike
|
535 |
+
|
536 |
+
- `sloppy-windows-*`, which decodes character-map encodings while treating
|
537 |
+
unmapped characters as Latin-1
|
538 |
+
|
539 |
+
- Simplify the code using `ftfy.bad_codecs`.
|
540 |
+
|
541 |
+
|
542 |
+
## Version 3.0.6 (November 5, 2013)
|
543 |
+
|
544 |
+
- `fix_entities` can now be True, False, or 'auto'. The new case is True, which
|
545 |
+
will decode all entities, even in text that already contains angle brackets.
|
546 |
+
This may also be faster, because it doesn't have to check.
|
547 |
+
- `build_data.py` will refuse to run on Python < 3.3, to prevent building
|
548 |
+
an inconsistent data file.
|
549 |
+
|
550 |
+
|
551 |
+
## Version 3.0.5 (November 1, 2013)
|
552 |
+
|
553 |
+
- Fix the arguments to `fix_file`, because they were totally wrong.
|
554 |
+
|
555 |
+
|
556 |
+
## Version 3.0.4 (October 1, 2013)
|
557 |
+
|
558 |
+
- Restore compatibility with Python 2.6.
|
559 |
+
|
560 |
+
|
561 |
+
## Version 3.0.3 (September 9, 2013)
|
562 |
+
|
563 |
+
- Fixed an ugly regular expression bug that prevented ftfy from importing on a
|
564 |
+
narrow build of Python.
|
565 |
+
|
566 |
+
|
567 |
+
## Version 3.0.2 (September 4, 2013)
|
568 |
+
|
569 |
+
- Fixed some false positives.
|
570 |
+
|
571 |
+
- Basically, 3.0.1 was too eager to treat text as MacRoman or cp437 when
|
572 |
+
three consecutive characters coincidentally decoded as UTF-8. Increased the
|
573 |
+
cost of those encodings so that they have to successfully decode multiple
|
574 |
+
UTF-8 characters.
|
575 |
+
|
576 |
+
- See `tests/test_real_tweets.py` for the new test cases that were added as a
|
577 |
+
result.
|
578 |
+
|
579 |
+
|
580 |
+
## Version 3.0.1 (August 30, 2013)
|
581 |
+
|
582 |
+
- Fix bug in `fix_java_encoding` that led to only the first instance of
|
583 |
+
CESU-8 badness per line being fixed
|
584 |
+
- Add a fixer that removes unassigned characters that can break Python 3.3
|
585 |
+
(http://bugs.python.org/issue18183)
|
586 |
+
|
587 |
+
|
588 |
+
## Version 3.0 (August 26, 2013)
|
589 |
+
|
590 |
+
- Generally runs faster
|
591 |
+
- Idempotent
|
592 |
+
- Simplified decoding logic
|
593 |
+
- Understands more encodings and more kinds of mistakes
|
594 |
+
- Takes options that enable or disable particular normalization steps
|
595 |
+
- Long line handling: now the time-consuming step (`fix_text_encoding`) will be
|
596 |
+
consistently skipped on long lines, but all other fixes will apply
|
597 |
+
- Tested on millions of examples from Twitter, ensuring a near-zero rate of
|
598 |
+
false positives
|
599 |
+
|
600 |
+
|
601 |
+
## Version 2.0.2 (June 20, 2013)
|
602 |
+
|
603 |
+
- Fix breaking up of long lines, so it can't go into an infinite loop
|
604 |
+
|
605 |
+
|
606 |
+
## Version 2.0.1 (March 19, 2013)
|
607 |
+
|
608 |
+
- Restored Python 2.6 support
|
609 |
+
|
610 |
+
|
611 |
+
## Version 2.0 (January 30, 2013)
|
612 |
+
|
613 |
+
- Python 3 support
|
614 |
+
- Use fast Python built-ins to speed up fixes
|
615 |
+
- Bugfixes
|
616 |
+
|
617 |
+
|
618 |
+
## Version 1.0 (August 24, 2012)
|
619 |
+
|
620 |
+
- Made into its own package with no dependencies, instead of a part of
|
621 |
+
`metanl`
|
Lib/site-packages/GitPython-3.1.30.dist-info/AUTHORS
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
GitPython was originally written by Michael Trier.
|
2 |
+
GitPython 0.2 was partially (re)written by Sebastian Thiel, based on 0.1.6 and git-dulwich.
|
3 |
+
|
4 |
+
Contributors are:
|
5 |
+
|
6 |
+
-Michael Trier <mtrier _at_ gmail.com>
|
7 |
+
-Alan Briolat
|
8 |
+
-Florian Apolloner <florian _at_ apolloner.eu>
|
9 |
+
-David Aguilar <davvid _at_ gmail.com>
|
10 |
+
-Jelmer Vernooij <jelmer _at_ samba.org>
|
11 |
+
-Steve Frécinaux <code _at_ istique.net>
|
12 |
+
-Kai Lautaportti <kai _at_ lautaportti.fi>
|
13 |
+
-Paul Sowden <paul _at_ idontsmoke.co.uk>
|
14 |
+
-Sebastian Thiel <byronimo _at_ gmail.com>
|
15 |
+
-Jonathan Chu <jonathan.chu _at_ me.com>
|
16 |
+
-Vincent Driessen <me _at_ nvie.com>
|
17 |
+
-Phil Elson <pelson _dot_ pub _at_ gmail.com>
|
18 |
+
-Bernard `Guyzmo` Pratz <[email protected]>
|
19 |
+
-Timothy B. Hartman <tbhartman _at_ gmail.com>
|
20 |
+
-Konstantin Popov <konstantin.popov.89 _at_ yandex.ru>
|
21 |
+
-Peter Jones <pjones _at_ redhat.com>
|
22 |
+
-Anson Mansfield <anson.mansfield _at_ gmail.com>
|
23 |
+
-Ken Odegard <ken.odegard _at_ gmail.com>
|
24 |
+
-Alexis Horgix Chotard
|
25 |
+
-Piotr Babij <piotr.babij _at_ gmail.com>
|
26 |
+
-Mikuláš Poul <mikulaspoul _at_ gmail.com>
|
27 |
+
-Charles Bouchard-Légaré <cblegare.atl _at_ ntis.ca>
|
28 |
+
-Yaroslav Halchenko <debian _at_ onerussian.com>
|
29 |
+
-Tim Swast <swast _at_ google.com>
|
30 |
+
-William Luc Ritchie
|
31 |
+
-David Host <hostdm _at_ outlook.com>
|
32 |
+
-A. Jesse Jiryu Davis <jesse _at_ emptysquare.net>
|
33 |
+
-Steven Whitman <ninloot _at_ gmail.com>
|
34 |
+
-Stefan Stancu <stefan.stancu _at_ gmail.com>
|
35 |
+
-César Izurieta <cesar _at_ caih.org>
|
36 |
+
-Arthur Milchior <arthur _at_ milchior.fr>
|
37 |
+
-Anil Khatri <anil.soccer.khatri _at_ gmail.com>
|
38 |
+
-JJ Graham <thetwoj _at_ gmail.com>
|
39 |
+
-Ben Thayer <ben _at_ benthayer.com>
|
40 |
+
-Dries Kennes <admin _at_ dries007.net>
|
41 |
+
-Pratik Anurag <panurag247365 _at_ gmail.com>
|
42 |
+
-Harmon <harmon.public _at_ gmail.com>
|
43 |
+
-Liam Beguin <liambeguin _at_ gmail.com>
|
44 |
+
-Ram Rachum <ram _at_ rachum.com>
|
45 |
+
-Alba Mendez <me _at_ alba.sh>
|
46 |
+
-Robert Westman <robert _at_ byteflux.io>
|
47 |
+
-Hugo van Kemenade
|
48 |
+
-Hiroki Tokunaga <tokusan441 _at_ gmail.com>
|
49 |
+
-Julien Mauroy <pro.julien.mauroy _at_ gmail.com>
|
50 |
+
-Patrick Gerard
|
51 |
+
-Luke Twist <[email protected]>
|
52 |
+
-Joseph Hale <me _at_ jhale.dev>
|
53 |
+
-Santos Gallegos <stsewd _at_ proton.me>
|
54 |
+
Portions derived from other open source works and are clearly marked.
|
Lib/site-packages/GitPython-3.1.30.dist-info/INSTALLER
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
pip
|
Lib/site-packages/GitPython-3.1.30.dist-info/LICENSE
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Copyright (C) 2008, 2009 Michael Trier and contributors
|
2 |
+
All rights reserved.
|
3 |
+
|
4 |
+
Redistribution and use in source and binary forms, with or without
|
5 |
+
modification, are permitted provided that the following conditions
|
6 |
+
are met:
|
7 |
+
|
8 |
+
* Redistributions of source code must retain the above copyright
|
9 |
+
notice, this list of conditions and the following disclaimer.
|
10 |
+
|
11 |
+
* Redistributions in binary form must reproduce the above copyright
|
12 |
+
notice, this list of conditions and the following disclaimer in the
|
13 |
+
documentation and/or other materials provided with the distribution.
|
14 |
+
|
15 |
+
* Neither the name of the GitPython project nor the names of
|
16 |
+
its contributors may be used to endorse or promote products derived
|
17 |
+
from this software without specific prior written permission.
|
18 |
+
|
19 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
20 |
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
21 |
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
22 |
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
23 |
+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
24 |
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
25 |
+
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
26 |
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
27 |
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
28 |
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29 |
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30 |
+
|
Lib/site-packages/GitPython-3.1.30.dist-info/METADATA
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Metadata-Version: 2.1
|
2 |
+
Name: GitPython
|
3 |
+
Version: 3.1.30
|
4 |
+
Summary: GitPython is a python library used to interact with Git repositories
|
5 |
+
Home-page: https://github.com/gitpython-developers/GitPython
|
6 |
+
Author: Sebastian Thiel, Michael Trier
|
7 |
+
Author-email: [email protected], [email protected]
|
8 |
+
License: BSD
|
9 |
+
Platform: UNKNOWN
|
10 |
+
Classifier: Development Status :: 5 - Production/Stable
|
11 |
+
Classifier: Environment :: Console
|
12 |
+
Classifier: Intended Audience :: Developers
|
13 |
+
Classifier: License :: OSI Approved :: BSD License
|
14 |
+
Classifier: Operating System :: OS Independent
|
15 |
+
Classifier: Operating System :: POSIX
|
16 |
+
Classifier: Operating System :: Microsoft :: Windows
|
17 |
+
Classifier: Operating System :: MacOS :: MacOS X
|
18 |
+
Classifier: Typing :: Typed
|
19 |
+
Classifier: Programming Language :: Python
|
20 |
+
Classifier: Programming Language :: Python :: 3
|
21 |
+
Classifier: Programming Language :: Python :: 3.7
|
22 |
+
Classifier: Programming Language :: Python :: 3.8
|
23 |
+
Classifier: Programming Language :: Python :: 3.9
|
24 |
+
Classifier: Programming Language :: Python :: 3.10
|
25 |
+
Requires-Python: >=3.7
|
26 |
+
Description-Content-Type: text/markdown
|
27 |
+
License-File: LICENSE
|
28 |
+
License-File: AUTHORS
|
29 |
+
Requires-Dist: gitdb (<5,>=4.0.1)
|
30 |
+
Requires-Dist: typing-extensions (>=3.7.4.3) ; python_version < "3.8"
|
31 |
+
|
32 |
+
GitPython is a python library used to interact with Git repositories
|
33 |
+
|
Lib/site-packages/GitPython-3.1.30.dist-info/RECORD
ADDED
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
GitPython-3.1.30.dist-info/AUTHORS,sha256=0F09KKrRmwH3zJ4gqo1tJMVlalC9bSunDNKlRvR6q2c,2158
|
2 |
+
GitPython-3.1.30.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
3 |
+
GitPython-3.1.30.dist-info/LICENSE,sha256=_WV__CzvY9JceMq3gI1BTdA6KC5jiTSR_RHDL5i-Z_s,1521
|
4 |
+
GitPython-3.1.30.dist-info/METADATA,sha256=sfBdL9phnpQUe_vUWoU98Lzf7Ci1wPO_GbXIfJPHnWo,1289
|
5 |
+
GitPython-3.1.30.dist-info/RECORD,,
|
6 |
+
GitPython-3.1.30.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
7 |
+
GitPython-3.1.30.dist-info/WHEEL,sha256=ewwEueio1C2XeHTvT17n8dZUJgOvyCWCt0WVNLClP9o,92
|
8 |
+
GitPython-3.1.30.dist-info/top_level.txt,sha256=0hzDuIp8obv624V3GmbqsagBWkk8ohtGU-Bc1PmTT0o,4
|
9 |
+
git/__init__.py,sha256=FvFbZFYaehC7EraP5CWE1LVE2i3i5fsGrwDdcrHjWYc,2342
|
10 |
+
git/__pycache__/__init__.cpython-310.pyc,,
|
11 |
+
git/__pycache__/cmd.cpython-310.pyc,,
|
12 |
+
git/__pycache__/compat.cpython-310.pyc,,
|
13 |
+
git/__pycache__/config.cpython-310.pyc,,
|
14 |
+
git/__pycache__/db.cpython-310.pyc,,
|
15 |
+
git/__pycache__/diff.cpython-310.pyc,,
|
16 |
+
git/__pycache__/exc.cpython-310.pyc,,
|
17 |
+
git/__pycache__/remote.cpython-310.pyc,,
|
18 |
+
git/__pycache__/types.cpython-310.pyc,,
|
19 |
+
git/__pycache__/util.cpython-310.pyc,,
|
20 |
+
git/cmd.py,sha256=giSgsNT1hqaOUkrvs_FCEchaDph_OQnBMmgRjhoG--s,53745
|
21 |
+
git/compat.py,sha256=3wWLkD9QrZvLiV6NtNxJILwGrLE2nw_SoLqaTEPH364,2256
|
22 |
+
git/config.py,sha256=OBczU5iAqalA8pMXmBF9zqeHjmo-yikppNqQwS_kO1M,34553
|
23 |
+
git/db.py,sha256=dEs2Bn-iDuHyero9afw8mrXHrLE7_CDExv943iWU9WI,2244
|
24 |
+
git/diff.py,sha256=-ZjBAja7Unmddu5ErIWkHJ9grEGeFu9fwOTxSL4PhGg,23310
|
25 |
+
git/exc.py,sha256=ys5ZYuvzvNN3TfcB5R_bUNRy3OEvURS5pJMdfy0Iws4,6446
|
26 |
+
git/index/__init__.py,sha256=43ovvVNocVRNiQd4fLqvUMuGGmwhBQ9SsiQ46vkvk1E,89
|
27 |
+
git/index/__pycache__/__init__.cpython-310.pyc,,
|
28 |
+
git/index/__pycache__/base.cpython-310.pyc,,
|
29 |
+
git/index/__pycache__/fun.cpython-310.pyc,,
|
30 |
+
git/index/__pycache__/typ.cpython-310.pyc,,
|
31 |
+
git/index/__pycache__/util.cpython-310.pyc,,
|
32 |
+
git/index/base.py,sha256=3o8bp4WcHa1eWfr_VNIU6Hh5uSzbN8mMOxMt2FWUxew,57519
|
33 |
+
git/index/fun.py,sha256=wL9DqjGKEdslU-2y0xjHXN_AexB8cKA19qhYizH-XB0,16395
|
34 |
+
git/index/typ.py,sha256=QnyWeqzU7_xnyiwOki5W633Jp9g5COqEf6B4PeW3hK8,6252
|
35 |
+
git/index/util.py,sha256=ISsWZjGiflooNr6XtElP4AhWUxQOakouvgeXC2PEepI,3475
|
36 |
+
git/objects/__init__.py,sha256=NW8HBfdZvBYe9W6IjMWafSj_DVlV2REmmrpWKrHkGVw,692
|
37 |
+
git/objects/__pycache__/__init__.cpython-310.pyc,,
|
38 |
+
git/objects/__pycache__/base.cpython-310.pyc,,
|
39 |
+
git/objects/__pycache__/blob.cpython-310.pyc,,
|
40 |
+
git/objects/__pycache__/commit.cpython-310.pyc,,
|
41 |
+
git/objects/__pycache__/fun.cpython-310.pyc,,
|
42 |
+
git/objects/__pycache__/tag.cpython-310.pyc,,
|
43 |
+
git/objects/__pycache__/tree.cpython-310.pyc,,
|
44 |
+
git/objects/__pycache__/util.cpython-310.pyc,,
|
45 |
+
git/objects/base.py,sha256=2sxMJgc-GKuWpKfiQIvlrrB7fWmEqIHZqJBXj7D2kKg,7856
|
46 |
+
git/objects/blob.py,sha256=FIbZTYniJ7nLsdrHuwhagFVs9tYoUIyXodRaHYLaQqs,986
|
47 |
+
git/objects/commit.py,sha256=vDQhBP1job-2C3dyHJM-y4d7vWOXnXuz0dxLlucdBjw,27270
|
48 |
+
git/objects/fun.py,sha256=JaiYEn8OOyBWo0u8vZ4jqVpe2Tn6w8usmbaKUYOOd5o,8610
|
49 |
+
git/objects/submodule/__init__.py,sha256=OsMeiex7cG6ev2f35IaJ5csH-eXchSoNKCt4HXUG5Ws,93
|
50 |
+
git/objects/submodule/__pycache__/__init__.cpython-310.pyc,,
|
51 |
+
git/objects/submodule/__pycache__/base.cpython-310.pyc,,
|
52 |
+
git/objects/submodule/__pycache__/root.cpython-310.pyc,,
|
53 |
+
git/objects/submodule/__pycache__/util.cpython-310.pyc,,
|
54 |
+
git/objects/submodule/base.py,sha256=GFgU8M0p-ojAqHsfWJ7_VMx23JE0FKaZdqW7SESYyNA,61023
|
55 |
+
git/objects/submodule/root.py,sha256=Ev_RnGzv4hi3UqEFMHuSR-uGR7kYpwOgwZFUG31X-Hc,19568
|
56 |
+
git/objects/submodule/util.py,sha256=u2zQGFWBmryqET0XWf9BuiY1OOgWB8YCU3Wz0xdp4E4,3380
|
57 |
+
git/objects/tag.py,sha256=ZXOLK_lV9E5G2aDl5t0hYDN2hhIhGF23HILHBnZgRX0,3840
|
58 |
+
git/objects/tree.py,sha256=kGgSnOIc9UhjPMUmTghc4yxxB9_1wdjeApEKWundvyQ,14228
|
59 |
+
git/objects/util.py,sha256=2rJhOrBgr_cXwE3-0AIKP3KrvJUMaztswEVvvv-meH4,22234
|
60 |
+
git/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
61 |
+
git/refs/__init__.py,sha256=PMF97jMUcivbCCEJnl2zTs-YtECNFp8rL8GHK8AitXU,203
|
62 |
+
git/refs/__pycache__/__init__.cpython-310.pyc,,
|
63 |
+
git/refs/__pycache__/head.cpython-310.pyc,,
|
64 |
+
git/refs/__pycache__/log.cpython-310.pyc,,
|
65 |
+
git/refs/__pycache__/reference.cpython-310.pyc,,
|
66 |
+
git/refs/__pycache__/remote.cpython-310.pyc,,
|
67 |
+
git/refs/__pycache__/symbolic.cpython-310.pyc,,
|
68 |
+
git/refs/__pycache__/tag.cpython-310.pyc,,
|
69 |
+
git/refs/head.py,sha256=rZ4LbFd05Gs9sAuSU5VQRDmJZfrwMwWtBpLlmiUQ-Zg,9756
|
70 |
+
git/refs/log.py,sha256=N8C00wvCoERgll8FPvAgPjrIi-nJLGWPAy3ctBnDCEM,11890
|
71 |
+
git/refs/reference.py,sha256=mKGI3YEoLPLbOdn8nX4XuRbFfE4zRBnJOET-dculg18,5413
|
72 |
+
git/refs/remote.py,sha256=E63Bh5ig1GYrk6FE46iNtS5P6ZgODyPXot8eJw-mxts,2556
|
73 |
+
git/refs/symbolic.py,sha256=XwfeYr1Zp-fuHAoGuVAXKk4EYlsuUMVu99OjJWuWDTQ,29967
|
74 |
+
git/refs/tag.py,sha256=FNoCZ3BdDl2i5kD3si2P9hoXU9rDAZ_YK0Rn84TmKT8,4419
|
75 |
+
git/remote.py,sha256=IUducN9ldq4zAdhbpgD3bAP61jZYviimkpllt9UlHIM,44276
|
76 |
+
git/repo/__init__.py,sha256=XMpdeowJRtTEd80jAcrKSQfMu2JZGMfPlpuIYHG2ZCk,80
|
77 |
+
git/repo/__pycache__/__init__.cpython-310.pyc,,
|
78 |
+
git/repo/__pycache__/base.cpython-310.pyc,,
|
79 |
+
git/repo/__pycache__/fun.cpython-310.pyc,,
|
80 |
+
git/repo/base.py,sha256=Z-iSc2iq3sV30MUj9tUSmcpp2Yg_WW0J-CoipwtqaCM,54313
|
81 |
+
git/repo/fun.py,sha256=7ZERvwfKFJV7lpP-EROwc_QffBKu3jZmpnDIrGCgAjE,12929
|
82 |
+
git/types.py,sha256=bA4El-NC7YNwQ9jNtkbWgT0QmmAfVs4PVSwBOE_D1Bo,3020
|
83 |
+
git/util.py,sha256=Szo7d9uXJB0ql-x9paWYmt7KQR5ZmLxe0Tsf0R_ZEB4,39858
|
Lib/site-packages/GitPython-3.1.30.dist-info/REQUESTED
ADDED
File without changes
|
Lib/site-packages/GitPython-3.1.30.dist-info/WHEEL
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Wheel-Version: 1.0
|
2 |
+
Generator: bdist_wheel (0.37.0)
|
3 |
+
Root-Is-Purelib: true
|
4 |
+
Tag: py3-none-any
|
5 |
+
|
Lib/site-packages/GitPython-3.1.30.dist-info/top_level.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
git
|
Lib/site-packages/Jinja2-3.1.2.dist-info/INSTALLER
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
pip
|
Lib/site-packages/Jinja2-3.1.2.dist-info/LICENSE.rst
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Copyright 2007 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.
|
Lib/site-packages/Jinja2-3.1.2.dist-info/METADATA
ADDED
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Metadata-Version: 2.1
|
2 |
+
Name: Jinja2
|
3 |
+
Version: 3.1.2
|
4 |
+
Summary: A very fast and expressive template engine.
|
5 |
+
Home-page: https://palletsprojects.com/p/jinja/
|
6 |
+
Author: Armin Ronacher
|
7 |
+
Author-email: [email protected]
|
8 |
+
Maintainer: Pallets
|
9 |
+
Maintainer-email: [email protected]
|
10 |
+
License: BSD-3-Clause
|
11 |
+
Project-URL: Donate, https://palletsprojects.com/donate
|
12 |
+
Project-URL: Documentation, https://jinja.palletsprojects.com/
|
13 |
+
Project-URL: Changes, https://jinja.palletsprojects.com/changes/
|
14 |
+
Project-URL: Source Code, https://github.com/pallets/jinja/
|
15 |
+
Project-URL: Issue Tracker, https://github.com/pallets/jinja/issues/
|
16 |
+
Project-URL: Twitter, https://twitter.com/PalletsTeam
|
17 |
+
Project-URL: Chat, https://discord.gg/pallets
|
18 |
+
Platform: UNKNOWN
|
19 |
+
Classifier: Development Status :: 5 - Production/Stable
|
20 |
+
Classifier: Environment :: Web Environment
|
21 |
+
Classifier: Intended Audience :: Developers
|
22 |
+
Classifier: License :: OSI Approved :: BSD License
|
23 |
+
Classifier: Operating System :: OS Independent
|
24 |
+
Classifier: Programming Language :: Python
|
25 |
+
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
|
26 |
+
Classifier: Topic :: Text Processing :: Markup :: HTML
|
27 |
+
Requires-Python: >=3.7
|
28 |
+
Description-Content-Type: text/x-rst
|
29 |
+
License-File: LICENSE.rst
|
30 |
+
Requires-Dist: MarkupSafe (>=2.0)
|
31 |
+
Provides-Extra: i18n
|
32 |
+
Requires-Dist: Babel (>=2.7) ; extra == 'i18n'
|
33 |
+
|
34 |
+
Jinja
|
35 |
+
=====
|
36 |
+
|
37 |
+
Jinja is a fast, expressive, extensible templating engine. Special
|
38 |
+
placeholders in the template allow writing code similar to Python
|
39 |
+
syntax. Then the template is passed data to render the final document.
|
40 |
+
|
41 |
+
It includes:
|
42 |
+
|
43 |
+
- Template inheritance and inclusion.
|
44 |
+
- Define and import macros within templates.
|
45 |
+
- HTML templates can use autoescaping to prevent XSS from untrusted
|
46 |
+
user input.
|
47 |
+
- A sandboxed environment can safely render untrusted templates.
|
48 |
+
- AsyncIO support for generating templates and calling async
|
49 |
+
functions.
|
50 |
+
- I18N support with Babel.
|
51 |
+
- Templates are compiled to optimized Python code just-in-time and
|
52 |
+
cached, or can be compiled ahead-of-time.
|
53 |
+
- Exceptions point to the correct line in templates to make debugging
|
54 |
+
easier.
|
55 |
+
- Extensible filters, tests, functions, and even syntax.
|
56 |
+
|
57 |
+
Jinja's philosophy is that while application logic belongs in Python if
|
58 |
+
possible, it shouldn't make the template designer's job difficult by
|
59 |
+
restricting functionality too much.
|
60 |
+
|
61 |
+
|
62 |
+
Installing
|
63 |
+
----------
|
64 |
+
|
65 |
+
Install and update using `pip`_:
|
66 |
+
|
67 |
+
.. code-block:: text
|
68 |
+
|
69 |
+
$ pip install -U Jinja2
|
70 |
+
|
71 |
+
.. _pip: https://pip.pypa.io/en/stable/getting-started/
|
72 |
+
|
73 |
+
|
74 |
+
In A Nutshell
|
75 |
+
-------------
|
76 |
+
|
77 |
+
.. code-block:: jinja
|
78 |
+
|
79 |
+
{% extends "base.html" %}
|
80 |
+
{% block title %}Members{% endblock %}
|
81 |
+
{% block content %}
|
82 |
+
<ul>
|
83 |
+
{% for user in users %}
|
84 |
+
<li><a href="{{ user.url }}">{{ user.username }}</a></li>
|
85 |
+
{% endfor %}
|
86 |
+
</ul>
|
87 |
+
{% endblock %}
|
88 |
+
|
89 |
+
|
90 |
+
Donate
|
91 |
+
------
|
92 |
+
|
93 |
+
The Pallets organization develops and supports Jinja and other popular
|
94 |
+
packages. In order to grow the community of contributors and users, and
|
95 |
+
allow the maintainers to devote more time to the projects, `please
|
96 |
+
donate today`_.
|
97 |
+
|
98 |
+
.. _please donate today: https://palletsprojects.com/donate
|
99 |
+
|
100 |
+
|
101 |
+
Links
|
102 |
+
-----
|
103 |
+
|
104 |
+
- Documentation: https://jinja.palletsprojects.com/
|
105 |
+
- Changes: https://jinja.palletsprojects.com/changes/
|
106 |
+
- PyPI Releases: https://pypi.org/project/Jinja2/
|
107 |
+
- Source Code: https://github.com/pallets/jinja/
|
108 |
+
- Issue Tracker: https://github.com/pallets/jinja/issues/
|
109 |
+
- Website: https://palletsprojects.com/p/jinja/
|
110 |
+
- Twitter: https://twitter.com/PalletsTeam
|
111 |
+
- Chat: https://discord.gg/pallets
|
112 |
+
|
113 |
+
|
Lib/site-packages/Jinja2-3.1.2.dist-info/RECORD
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Jinja2-3.1.2.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
2 |
+
Jinja2-3.1.2.dist-info/LICENSE.rst,sha256=O0nc7kEF6ze6wQ-vG-JgQI_oXSUrjp3y4JefweCUQ3s,1475
|
3 |
+
Jinja2-3.1.2.dist-info/METADATA,sha256=PZ6v2SIidMNixR7MRUX9f7ZWsPwtXanknqiZUmRbh4U,3539
|
4 |
+
Jinja2-3.1.2.dist-info/RECORD,,
|
5 |
+
Jinja2-3.1.2.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
|
6 |
+
Jinja2-3.1.2.dist-info/entry_points.txt,sha256=zRd62fbqIyfUpsRtU7EVIFyiu1tPwfgO7EvPErnxgTE,59
|
7 |
+
Jinja2-3.1.2.dist-info/top_level.txt,sha256=PkeVWtLb3-CqjWi1fO29OCbj55EhX_chhKrCdrVe_zs,7
|
8 |
+
jinja2/__init__.py,sha256=8vGduD8ytwgD6GDSqpYc2m3aU-T7PKOAddvVXgGr_Fs,1927
|
9 |
+
jinja2/__pycache__/__init__.cpython-310.pyc,,
|
10 |
+
jinja2/__pycache__/_identifier.cpython-310.pyc,,
|
11 |
+
jinja2/__pycache__/async_utils.cpython-310.pyc,,
|
12 |
+
jinja2/__pycache__/bccache.cpython-310.pyc,,
|
13 |
+
jinja2/__pycache__/compiler.cpython-310.pyc,,
|
14 |
+
jinja2/__pycache__/constants.cpython-310.pyc,,
|
15 |
+
jinja2/__pycache__/debug.cpython-310.pyc,,
|
16 |
+
jinja2/__pycache__/defaults.cpython-310.pyc,,
|
17 |
+
jinja2/__pycache__/environment.cpython-310.pyc,,
|
18 |
+
jinja2/__pycache__/exceptions.cpython-310.pyc,,
|
19 |
+
jinja2/__pycache__/ext.cpython-310.pyc,,
|
20 |
+
jinja2/__pycache__/filters.cpython-310.pyc,,
|
21 |
+
jinja2/__pycache__/idtracking.cpython-310.pyc,,
|
22 |
+
jinja2/__pycache__/lexer.cpython-310.pyc,,
|
23 |
+
jinja2/__pycache__/loaders.cpython-310.pyc,,
|
24 |
+
jinja2/__pycache__/meta.cpython-310.pyc,,
|
25 |
+
jinja2/__pycache__/nativetypes.cpython-310.pyc,,
|
26 |
+
jinja2/__pycache__/nodes.cpython-310.pyc,,
|
27 |
+
jinja2/__pycache__/optimizer.cpython-310.pyc,,
|
28 |
+
jinja2/__pycache__/parser.cpython-310.pyc,,
|
29 |
+
jinja2/__pycache__/runtime.cpython-310.pyc,,
|
30 |
+
jinja2/__pycache__/sandbox.cpython-310.pyc,,
|
31 |
+
jinja2/__pycache__/tests.cpython-310.pyc,,
|
32 |
+
jinja2/__pycache__/utils.cpython-310.pyc,,
|
33 |
+
jinja2/__pycache__/visitor.cpython-310.pyc,,
|
34 |
+
jinja2/_identifier.py,sha256=_zYctNKzRqlk_murTNlzrju1FFJL7Va_Ijqqd7ii2lU,1958
|
35 |
+
jinja2/async_utils.py,sha256=dHlbTeaxFPtAOQEYOGYh_PHcDT0rsDaUJAFDl_0XtTg,2472
|
36 |
+
jinja2/bccache.py,sha256=mhz5xtLxCcHRAa56azOhphIAe19u1we0ojifNMClDio,14061
|
37 |
+
jinja2/compiler.py,sha256=Gs-N8ThJ7OWK4-reKoO8Wh1ZXz95MVphBKNVf75qBr8,72172
|
38 |
+
jinja2/constants.py,sha256=GMoFydBF_kdpaRKPoM5cl5MviquVRLVyZtfp5-16jg0,1433
|
39 |
+
jinja2/debug.py,sha256=iWJ432RadxJNnaMOPrjIDInz50UEgni3_HKuFXi2vuQ,6299
|
40 |
+
jinja2/defaults.py,sha256=boBcSw78h-lp20YbaXSJsqkAI2uN_mD_TtCydpeq5wU,1267
|
41 |
+
jinja2/environment.py,sha256=6uHIcc7ZblqOMdx_uYNKqRnnwAF0_nzbyeMP9FFtuh4,61349
|
42 |
+
jinja2/exceptions.py,sha256=ioHeHrWwCWNaXX1inHmHVblvc4haO7AXsjCp3GfWvx0,5071
|
43 |
+
jinja2/ext.py,sha256=ivr3P7LKbddiXDVez20EflcO3q2aHQwz9P_PgWGHVqE,31502
|
44 |
+
jinja2/filters.py,sha256=9js1V-h2RlyW90IhLiBGLM2U-k6SCy2F4BUUMgB3K9Q,53509
|
45 |
+
jinja2/idtracking.py,sha256=GfNmadir4oDALVxzn3DL9YInhJDr69ebXeA2ygfuCGA,10704
|
46 |
+
jinja2/lexer.py,sha256=DW2nX9zk-6MWp65YR2bqqj0xqCvLtD-u9NWT8AnFRxQ,29726
|
47 |
+
jinja2/loaders.py,sha256=BfptfvTVpClUd-leMkHczdyPNYFzp_n7PKOJ98iyHOg,23207
|
48 |
+
jinja2/meta.py,sha256=GNPEvifmSaU3CMxlbheBOZjeZ277HThOPUTf1RkppKQ,4396
|
49 |
+
jinja2/nativetypes.py,sha256=DXgORDPRmVWgy034H0xL8eF7qYoK3DrMxs-935d0Fzk,4226
|
50 |
+
jinja2/nodes.py,sha256=i34GPRAZexXMT6bwuf5SEyvdmS-bRCy9KMjwN5O6pjk,34550
|
51 |
+
jinja2/optimizer.py,sha256=tHkMwXxfZkbfA1KmLcqmBMSaz7RLIvvItrJcPoXTyD8,1650
|
52 |
+
jinja2/parser.py,sha256=nHd-DFHbiygvfaPtm9rcQXJChZG7DPsWfiEsqfwKerY,39595
|
53 |
+
jinja2/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
54 |
+
jinja2/runtime.py,sha256=5CmD5BjbEJxSiDNTFBeKCaq8qU4aYD2v6q2EluyExms,33476
|
55 |
+
jinja2/sandbox.py,sha256=Y0xZeXQnH6EX5VjaV2YixESxoepnRbW_3UeQosaBU3M,14584
|
56 |
+
jinja2/tests.py,sha256=Am5Z6Lmfr2XaH_npIfJJ8MdXtWsbLjMULZJulTAj30E,5905
|
57 |
+
jinja2/utils.py,sha256=u9jXESxGn8ATZNVolwmkjUVu4SA-tLgV0W7PcSfPfdQ,23965
|
58 |
+
jinja2/visitor.py,sha256=MH14C6yq24G_KVtWzjwaI7Wg14PCJIYlWW1kpkxYak0,3568
|
Lib/site-packages/Jinja2-3.1.2.dist-info/WHEEL
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Wheel-Version: 1.0
|
2 |
+
Generator: bdist_wheel (0.37.1)
|
3 |
+
Root-Is-Purelib: true
|
4 |
+
Tag: py3-none-any
|
5 |
+
|
Lib/site-packages/Jinja2-3.1.2.dist-info/entry_points.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
[babel.extractors]
|
2 |
+
jinja2 = jinja2.ext:babel_extract[i18n]
|
Lib/site-packages/Jinja2-3.1.2.dist-info/top_level.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
jinja2
|
Lib/site-packages/Markdown-3.4.3.dist-info/INSTALLER
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
pip
|
Lib/site-packages/Markdown-3.4.3.dist-info/LICENSE.md
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Copyright 2007, 2008 The Python Markdown Project (v. 1.7 and later)
|
2 |
+
Copyright 2004, 2005, 2006 Yuri Takhteyev (v. 0.2-1.6b)
|
3 |
+
Copyright 2004 Manfred Stienstra (the original version)
|
4 |
+
|
5 |
+
All rights reserved.
|
6 |
+
|
7 |
+
Redistribution and use in source and binary forms, with or without
|
8 |
+
modification, are permitted provided that the following conditions are met:
|
9 |
+
|
10 |
+
* Redistributions of source code must retain the above copyright
|
11 |
+
notice, this list of conditions and the following disclaimer.
|
12 |
+
* Redistributions in binary form must reproduce the above copyright
|
13 |
+
notice, this list of conditions and the following disclaimer in the
|
14 |
+
documentation and/or other materials provided with the distribution.
|
15 |
+
* Neither the name of the Python Markdown Project nor the
|
16 |
+
names of its contributors may be used to endorse or promote products
|
17 |
+
derived from this software without specific prior written permission.
|
18 |
+
|
19 |
+
THIS SOFTWARE IS PROVIDED BY THE PYTHON MARKDOWN PROJECT ''AS IS'' AND ANY
|
20 |
+
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
21 |
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
22 |
+
DISCLAIMED. IN NO EVENT SHALL ANY CONTRIBUTORS TO THE PYTHON MARKDOWN PROJECT
|
23 |
+
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
24 |
+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
25 |
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
26 |
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
27 |
+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
28 |
+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
29 |
+
POSSIBILITY OF SUCH DAMAGE.
|
Lib/site-packages/Markdown-3.4.3.dist-info/METADATA
ADDED
@@ -0,0 +1,137 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Metadata-Version: 2.1
|
2 |
+
Name: Markdown
|
3 |
+
Version: 3.4.3
|
4 |
+
Summary: Python implementation of John Gruber's Markdown.
|
5 |
+
Author: Manfred Stienstra, Yuri Takhteyev
|
6 |
+
Author-email: Waylan limberg <[email protected]>
|
7 |
+
Maintainer: Isaac Muse
|
8 |
+
Maintainer-email: Waylan Limberg <[email protected]>
|
9 |
+
License: Copyright 2007, 2008 The Python Markdown Project (v. 1.7 and later)
|
10 |
+
Copyright 2004, 2005, 2006 Yuri Takhteyev (v. 0.2-1.6b)
|
11 |
+
Copyright 2004 Manfred Stienstra (the original version)
|
12 |
+
|
13 |
+
All rights reserved.
|
14 |
+
|
15 |
+
Redistribution and use in source and binary forms, with or without
|
16 |
+
modification, are permitted provided that the following conditions are met:
|
17 |
+
|
18 |
+
* Redistributions of source code must retain the above copyright
|
19 |
+
notice, this list of conditions and the following disclaimer.
|
20 |
+
* Redistributions in binary form must reproduce the above copyright
|
21 |
+
notice, this list of conditions and the following disclaimer in the
|
22 |
+
documentation and/or other materials provided with the distribution.
|
23 |
+
* Neither the name of the Python Markdown Project nor the
|
24 |
+
names of its contributors may be used to endorse or promote products
|
25 |
+
derived from this software without specific prior written permission.
|
26 |
+
|
27 |
+
THIS SOFTWARE IS PROVIDED BY THE PYTHON MARKDOWN PROJECT ''AS IS'' AND ANY
|
28 |
+
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
29 |
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
30 |
+
DISCLAIMED. IN NO EVENT SHALL ANY CONTRIBUTORS TO THE PYTHON MARKDOWN PROJECT
|
31 |
+
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
32 |
+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
33 |
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
34 |
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
35 |
+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
36 |
+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
37 |
+
POSSIBILITY OF SUCH DAMAGE.
|
38 |
+
|
39 |
+
Project-URL: Homepage, https://Python-Markdown.github.io/
|
40 |
+
Project-URL: Documentation, https://Python-Markdown.github.io/
|
41 |
+
Project-URL: Repository, https://github.com/Python-Markdown/markdown
|
42 |
+
Project-URL: Issue Tracker, https://github.com/Python-Markdown/markdown/issues
|
43 |
+
Project-URL: Changelog, https://github.com/Python-Markdown/markdown/blob/master/docs/change_log/index.md
|
44 |
+
Keywords: markdown,markdown-parser,python-markdown,markdown-to-html
|
45 |
+
Classifier: Development Status :: 5 - Production/Stable
|
46 |
+
Classifier: License :: OSI Approved :: BSD License
|
47 |
+
Classifier: Operating System :: OS Independent
|
48 |
+
Classifier: Programming Language :: Python
|
49 |
+
Classifier: Programming Language :: Python :: 3
|
50 |
+
Classifier: Programming Language :: Python :: 3.7
|
51 |
+
Classifier: Programming Language :: Python :: 3.8
|
52 |
+
Classifier: Programming Language :: Python :: 3.9
|
53 |
+
Classifier: Programming Language :: Python :: 3.10
|
54 |
+
Classifier: Programming Language :: Python :: 3.11
|
55 |
+
Classifier: Programming Language :: Python :: 3 :: Only
|
56 |
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
57 |
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
58 |
+
Classifier: Topic :: Communications :: Email :: Filters
|
59 |
+
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content :: CGI Tools/Libraries
|
60 |
+
Classifier: Topic :: Internet :: WWW/HTTP :: Site Management
|
61 |
+
Classifier: Topic :: Software Development :: Documentation
|
62 |
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
63 |
+
Classifier: Topic :: Text Processing :: Filters
|
64 |
+
Classifier: Topic :: Text Processing :: Markup :: HTML
|
65 |
+
Classifier: Topic :: Text Processing :: Markup :: Markdown
|
66 |
+
Requires-Python: >=3.7
|
67 |
+
Description-Content-Type: text/markdown
|
68 |
+
License-File: LICENSE.md
|
69 |
+
Requires-Dist: importlib-metadata (>=4.4) ; python_version < "3.10"
|
70 |
+
Provides-Extra: testing
|
71 |
+
Requires-Dist: coverage ; extra == 'testing'
|
72 |
+
Requires-Dist: pyyaml ; extra == 'testing'
|
73 |
+
|
74 |
+
[Python-Markdown][]
|
75 |
+
===================
|
76 |
+
|
77 |
+
[![Build Status][build-button]][build]
|
78 |
+
[![Coverage Status][codecov-button]][codecov]
|
79 |
+
[![Latest Version][mdversion-button]][md-pypi]
|
80 |
+
[![Python Versions][pyversion-button]][md-pypi]
|
81 |
+
[![BSD License][bsdlicense-button]][bsdlicense]
|
82 |
+
[![Code of Conduct][codeofconduct-button]][Code of Conduct]
|
83 |
+
|
84 |
+
[build-button]: https://github.com/Python-Markdown/markdown/workflows/CI/badge.svg?event=push
|
85 |
+
[build]: https://github.com/Python-Markdown/markdown/actions?query=workflow%3ACI+event%3Apush
|
86 |
+
[codecov-button]: https://codecov.io/gh/Python-Markdown/markdown/branch/master/graph/badge.svg
|
87 |
+
[codecov]: https://codecov.io/gh/Python-Markdown/markdown
|
88 |
+
[mdversion-button]: https://img.shields.io/pypi/v/Markdown.svg
|
89 |
+
[md-pypi]: https://pypi.org/project/Markdown/
|
90 |
+
[pyversion-button]: https://img.shields.io/pypi/pyversions/Markdown.svg
|
91 |
+
[bsdlicense-button]: https://img.shields.io/badge/license-BSD-yellow.svg
|
92 |
+
[bsdlicense]: https://opensource.org/licenses/BSD-3-Clause
|
93 |
+
[codeofconduct-button]: https://img.shields.io/badge/code%20of%20conduct-contributor%20covenant-green.svg?style=flat-square
|
94 |
+
[Code of Conduct]: https://github.com/Python-Markdown/markdown/blob/master/CODE_OF_CONDUCT.md
|
95 |
+
|
96 |
+
This is a Python implementation of John Gruber's [Markdown][].
|
97 |
+
It is almost completely compliant with the reference implementation,
|
98 |
+
though there are a few known issues. See [Features][] for information
|
99 |
+
on what exactly is supported and what is not. Additional features are
|
100 |
+
supported by the [Available Extensions][].
|
101 |
+
|
102 |
+
[Python-Markdown]: https://Python-Markdown.github.io/
|
103 |
+
[Markdown]: https://daringfireball.net/projects/markdown/
|
104 |
+
[Features]: https://Python-Markdown.github.io#Features
|
105 |
+
[Available Extensions]: https://Python-Markdown.github.io/extensions
|
106 |
+
|
107 |
+
Documentation
|
108 |
+
-------------
|
109 |
+
|
110 |
+
```bash
|
111 |
+
pip install markdown
|
112 |
+
```
|
113 |
+
```python
|
114 |
+
import markdown
|
115 |
+
html = markdown.markdown(your_text_string)
|
116 |
+
```
|
117 |
+
|
118 |
+
For more advanced [installation] and [usage] documentation, see the `docs/` directory
|
119 |
+
of the distribution or the project website at <https://Python-Markdown.github.io/>.
|
120 |
+
|
121 |
+
[installation]: https://python-markdown.github.io/install/
|
122 |
+
[usage]: https://python-markdown.github.io/reference/
|
123 |
+
|
124 |
+
See the change log at <https://Python-Markdown.github.io/change_log>.
|
125 |
+
|
126 |
+
Support
|
127 |
+
-------
|
128 |
+
|
129 |
+
You may report bugs, ask for help, and discuss various other issues on the [bug tracker][].
|
130 |
+
|
131 |
+
[bug tracker]: https://github.com/Python-Markdown/markdown/issues
|
132 |
+
|
133 |
+
Code of Conduct
|
134 |
+
---------------
|
135 |
+
|
136 |
+
Everyone interacting in the Python-Markdown project's code bases, issue trackers,
|
137 |
+
and mailing lists is expected to follow the [Code of Conduct].
|
Lib/site-packages/Markdown-3.4.3.dist-info/RECORD
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
../../Scripts/markdown_py.exe,sha256=LOOR5iJXZCUOlYulhkVJPsXKZ0mLp7q6IRS7FWNXzns,108443
|
2 |
+
Markdown-3.4.3.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
3 |
+
Markdown-3.4.3.dist-info/LICENSE.md,sha256=bxGTy2NHGOZcOlN9biXr1hSCDsDvaTz8EiSBEmONZNo,1645
|
4 |
+
Markdown-3.4.3.dist-info/METADATA,sha256=B6fHm2ZWqYz1dl3MkMGyqiMPjtwXUwQaDSYIGXjSlaQ,6683
|
5 |
+
Markdown-3.4.3.dist-info/RECORD,,
|
6 |
+
Markdown-3.4.3.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
|
7 |
+
Markdown-3.4.3.dist-info/entry_points.txt,sha256=lMEyiiA_ZZyfPCBlDviBl-SiU0cfoeuEKpwxw361sKQ,1102
|
8 |
+
Markdown-3.4.3.dist-info/top_level.txt,sha256=IAxs8x618RXoH1uCqeLLxXsDefJvE_mIibr_M4sOlyk,9
|
9 |
+
markdown/__init__.py,sha256=XBsIkhLRPtAIiCAHaiPSu03JaKbHPYqO4bfD0hq6VVo,1013
|
10 |
+
markdown/__main__.py,sha256=JX1057VoovH3NA5uH5nQdQE8b0kXoeT79ZxCzFoL_kg,5803
|
11 |
+
markdown/__meta__.py,sha256=ZjYt0yeRFc5hMbElNpxk0iCfLDWPsRc-I3OO3KTteyw,1630
|
12 |
+
markdown/__pycache__/__init__.cpython-310.pyc,,
|
13 |
+
markdown/__pycache__/__main__.cpython-310.pyc,,
|
14 |
+
markdown/__pycache__/__meta__.cpython-310.pyc,,
|
15 |
+
markdown/__pycache__/blockparser.cpython-310.pyc,,
|
16 |
+
markdown/__pycache__/blockprocessors.cpython-310.pyc,,
|
17 |
+
markdown/__pycache__/core.cpython-310.pyc,,
|
18 |
+
markdown/__pycache__/htmlparser.cpython-310.pyc,,
|
19 |
+
markdown/__pycache__/inlinepatterns.cpython-310.pyc,,
|
20 |
+
markdown/__pycache__/postprocessors.cpython-310.pyc,,
|
21 |
+
markdown/__pycache__/preprocessors.cpython-310.pyc,,
|
22 |
+
markdown/__pycache__/serializers.cpython-310.pyc,,
|
23 |
+
markdown/__pycache__/test_tools.cpython-310.pyc,,
|
24 |
+
markdown/__pycache__/treeprocessors.cpython-310.pyc,,
|
25 |
+
markdown/__pycache__/util.cpython-310.pyc,,
|
26 |
+
markdown/blockparser.py,sha256=_KzFFkinAJ9LXlNP0vEc765enYUWBF7qlgxn9HSYFSk,4147
|
27 |
+
markdown/blockprocessors.py,sha256=sUHIdAsGGAEN443TusbiNOWYt38DsHV-RqJdGjumIFc,24893
|
28 |
+
markdown/core.py,sha256=fHSJjsuru2XUhYhO3ZbGElYWywATEbYolAQiu89YWBo,14652
|
29 |
+
markdown/extensions/__init__.py,sha256=8ZiiJLpbTSfp0aohALi4KbxoD9S34pxUAAIfAxbuj4E,2852
|
30 |
+
markdown/extensions/__pycache__/__init__.cpython-310.pyc,,
|
31 |
+
markdown/extensions/__pycache__/abbr.cpython-310.pyc,,
|
32 |
+
markdown/extensions/__pycache__/admonition.cpython-310.pyc,,
|
33 |
+
markdown/extensions/__pycache__/attr_list.cpython-310.pyc,,
|
34 |
+
markdown/extensions/__pycache__/codehilite.cpython-310.pyc,,
|
35 |
+
markdown/extensions/__pycache__/def_list.cpython-310.pyc,,
|
36 |
+
markdown/extensions/__pycache__/extra.cpython-310.pyc,,
|
37 |
+
markdown/extensions/__pycache__/fenced_code.cpython-310.pyc,,
|
38 |
+
markdown/extensions/__pycache__/footnotes.cpython-310.pyc,,
|
39 |
+
markdown/extensions/__pycache__/legacy_attrs.cpython-310.pyc,,
|
40 |
+
markdown/extensions/__pycache__/legacy_em.cpython-310.pyc,,
|
41 |
+
markdown/extensions/__pycache__/md_in_html.cpython-310.pyc,,
|
42 |
+
markdown/extensions/__pycache__/meta.cpython-310.pyc,,
|
43 |
+
markdown/extensions/__pycache__/nl2br.cpython-310.pyc,,
|
44 |
+
markdown/extensions/__pycache__/sane_lists.cpython-310.pyc,,
|
45 |
+
markdown/extensions/__pycache__/smarty.cpython-310.pyc,,
|
46 |
+
markdown/extensions/__pycache__/tables.cpython-310.pyc,,
|
47 |
+
markdown/extensions/__pycache__/toc.cpython-310.pyc,,
|
48 |
+
markdown/extensions/__pycache__/wikilinks.cpython-310.pyc,,
|
49 |
+
markdown/extensions/abbr.py,sha256=5TNU5ml6-H1n-fztEkgUphSTvp5yKCXaiPZMrVuRFvo,3186
|
50 |
+
markdown/extensions/admonition.py,sha256=INIecvdzQ7RLmgP8M-N6AZJ5uMd6dBfh9Uj6YibgNLk,5847
|
51 |
+
markdown/extensions/attr_list.py,sha256=nhKFY_u6BVyKW2oMUeC4wEjqFNGpDSnNXqaohuF6M7I,5988
|
52 |
+
markdown/extensions/codehilite.py,sha256=4q-ciXhIfdWGT0XxOIGpyCdTUqHvYDaBotwgbI4lckw,12906
|
53 |
+
markdown/extensions/def_list.py,sha256=HKStriCfwosWRjHgiph6hHIHwGjasEaE6UYW-_hstVo,3635
|
54 |
+
markdown/extensions/extra.py,sha256=ruwYAcbIaFxAmcT4pLoaRdw8Ok6sFTYWza7OAstcvtI,1831
|
55 |
+
markdown/extensions/fenced_code.py,sha256=Hd2RDaRWcCd4aI9fedoI6EElPmIVrD2BlvXdhRV64ik,7209
|
56 |
+
markdown/extensions/footnotes.py,sha256=eKUddjDuCAlyw0JWWzVVgGPRxOf_MVaU2GtDYP9bEgI,15851
|
57 |
+
markdown/extensions/legacy_attrs.py,sha256=qx4d8c_mxt0JZ7wP9Sfskvi3cZN-OtDGTFCi4gapZ74,2547
|
58 |
+
markdown/extensions/legacy_em.py,sha256=8mtzOGYu_FXKO7DrBVr_5v5ZH6ru1yv1TiobYBEFV5Q,1582
|
59 |
+
markdown/extensions/md_in_html.py,sha256=F4CUIa2DjDPLEIuJCbmbw9jL1mbFloPhraedynZL9Ig,15829
|
60 |
+
markdown/extensions/meta.py,sha256=EUfkzM7l7UpH__Or9K3pl8ldVddwndlCZWA3d712RAE,2331
|
61 |
+
markdown/extensions/nl2br.py,sha256=wAqTNOuf2L1NzlEvEqoID70n9y-aiYaGLkuyQk3CD0w,783
|
62 |
+
markdown/extensions/sane_lists.py,sha256=ZQmCf-247KBexVG0fc62nDvokGkV6W1uavYbieNKSG4,1505
|
63 |
+
markdown/extensions/smarty.py,sha256=4_7XB2SOWFAmG2z54F2j1P0SIsPXj4Xj2nUfQTcXMBM,10093
|
64 |
+
markdown/extensions/tables.py,sha256=3bkYFbiss78smyl4o4Dgfanno9CTMri7B7j-GTeUUHk,8107
|
65 |
+
markdown/extensions/toc.py,sha256=BOD97tUsEzHmsC7HoKQjuLNGN6NoLD8-WmlUs-26oXs,14332
|
66 |
+
markdown/extensions/wikilinks.py,sha256=GkgT9BY7b1-qW--dIwFAhC9V20RoeF13b7CFdw_V21Q,2812
|
67 |
+
markdown/htmlparser.py,sha256=k-jyjX7ADfL-bk3vyu-VDOXOWJBdMGooHeCJ0Id9Ge0,13038
|
68 |
+
markdown/inlinepatterns.py,sha256=JJB5Az1F4LPXlpiriIGw4NO9MMcskt7edU26LnAFs6w,29654
|
69 |
+
markdown/postprocessors.py,sha256=d3OZdZWaTJ3tpTPTGFR6xjcqoVOs28jsx8QdNHr2IUM,4320
|
70 |
+
markdown/preprocessors.py,sha256=-s8QGHGlX7JAIJTfCivuc-CVwTLWs0IyEU94YUT2IvQ,2742
|
71 |
+
markdown/serializers.py,sha256=_wQl-iJrPSUEQ4Q1owWYqN9qceVh6TOlAOH_i44BKAQ,6540
|
72 |
+
markdown/test_tools.py,sha256=Iht9NMNtDgtrMCNdjkMN9EWXjgsJjaFzJQVvzxo1Da0,8363
|
73 |
+
markdown/treeprocessors.py,sha256=MBnV7RyIvsLshRbkYA91EgtJX43i1wlkdca-Xfjt5jk,16240
|
74 |
+
markdown/util.py,sha256=aRtmgc-ZeiWKPSKRtqYMWElGg4qFVju-UNDhh9mANcI,11647
|
Lib/site-packages/Markdown-3.4.3.dist-info/WHEEL
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Wheel-Version: 1.0
|
2 |
+
Generator: bdist_wheel (0.40.0)
|
3 |
+
Root-Is-Purelib: true
|
4 |
+
Tag: py3-none-any
|
5 |
+
|
Lib/site-packages/Markdown-3.4.3.dist-info/entry_points.txt
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[console_scripts]
|
2 |
+
markdown_py = markdown.__main__:run
|
3 |
+
|
4 |
+
[markdown.extensions]
|
5 |
+
abbr = markdown.extensions.abbr:AbbrExtension
|
6 |
+
admonition = markdown.extensions.admonition:AdmonitionExtension
|
7 |
+
attr_list = markdown.extensions.attr_list:AttrListExtension
|
8 |
+
codehilite = markdown.extensions.codehilite:CodeHiliteExtension
|
9 |
+
def_list = markdown.extensions.def_list:DefListExtension
|
10 |
+
extra = markdown.extensions.extra:ExtraExtension
|
11 |
+
fenced_code = markdown.extensions.fenced_code:FencedCodeExtension
|
12 |
+
footnotes = markdown.extensions.footnotes:FootnoteExtension
|
13 |
+
legacy_attrs = markdown.extensions.legacy_attrs:LegacyAttrExtension
|
14 |
+
legacy_em = markdown.extensions.legacy_em:LegacyEmExtension
|
15 |
+
md_in_html = markdown.extensions.md_in_html:MarkdownInHtmlExtension
|
16 |
+
meta = markdown.extensions.meta:MetaExtension
|
17 |
+
nl2br = markdown.extensions.nl2br:Nl2BrExtension
|
18 |
+
sane_lists = markdown.extensions.sane_lists:SaneListExtension
|
19 |
+
smarty = markdown.extensions.smarty:SmartyExtension
|
20 |
+
tables = markdown.extensions.tables:TableExtension
|
21 |
+
toc = markdown.extensions.toc:TocExtension
|
22 |
+
wikilinks = markdown.extensions.wikilinks:WikiLinkExtension
|
Lib/site-packages/Markdown-3.4.3.dist-info/top_level.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
markdown
|
Lib/site-packages/MarkupSafe-2.1.3.dist-info/INSTALLER
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
pip
|
Lib/site-packages/MarkupSafe-2.1.3.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.
|
Lib/site-packages/MarkupSafe-2.1.3.dist-info/METADATA
ADDED
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Metadata-Version: 2.1
|
2 |
+
Name: MarkupSafe
|
3 |
+
Version: 2.1.3
|
4 |
+
Summary: Safely add untrusted strings to HTML/XML markup.
|
5 |
+
Home-page: https://palletsprojects.com/p/markupsafe/
|
6 |
+
Maintainer: Pallets
|
7 |
+
Maintainer-email: [email protected]
|
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
|
Lib/site-packages/MarkupSafe-2.1.3.dist-info/RECORD
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
MarkupSafe-2.1.3.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
2 |
+
MarkupSafe-2.1.3.dist-info/LICENSE.rst,sha256=RjHsDbX9kKVH4zaBcmTGeYIUM4FG-KyUtKV_lu6MnsQ,1503
|
3 |
+
MarkupSafe-2.1.3.dist-info/METADATA,sha256=5gU_TQw6eHpTaqkI6SPeZje6KTPlJPAV82uNiL3naKE,3096
|
4 |
+
MarkupSafe-2.1.3.dist-info/RECORD,,
|
5 |
+
MarkupSafe-2.1.3.dist-info/WHEEL,sha256=jrOhEbqKwvzRFSJcbYXlJCyVkgVdHg4_7__YHrdTUfw,102
|
6 |
+
MarkupSafe-2.1.3.dist-info/top_level.txt,sha256=qy0Plje5IJuvsCBjejJyhDCjEAdcDLK_2agVcex8Z6U,11
|
7 |
+
markupsafe/__init__.py,sha256=GsRaSTjrhvg6c88PnPJNqm4MafU_mFatfXz4-h80-Qc,10642
|
8 |
+
markupsafe/__pycache__/__init__.cpython-310.pyc,,
|
9 |
+
markupsafe/__pycache__/_native.cpython-310.pyc,,
|
10 |
+
markupsafe/_native.py,sha256=_Q7UsXCOvgdonCgqG3l5asANI6eo50EKnDM-mlwEC5M,1776
|
11 |
+
markupsafe/_speedups.c,sha256=n3jzzaJwXcoN8nTFyA53f3vSqsWK2vujI-v6QYifjhQ,7403
|
12 |
+
markupsafe/_speedups.cp310-win_amd64.pyd,sha256=nlgDO0l-guuFD-w6o7YZey0yek5iNTBpKjJrVebhZpI,15872
|
13 |
+
markupsafe/_speedups.pyi,sha256=f5QtwIOP0eLrxh2v5p6SmaYmlcHIGIfmz0DovaqL0OU,238
|
14 |
+
markupsafe/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
Lib/site-packages/MarkupSafe-2.1.3.dist-info/WHEEL
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Wheel-Version: 1.0
|
2 |
+
Generator: bdist_wheel (0.40.0)
|
3 |
+
Root-Is-Purelib: false
|
4 |
+
Tag: cp310-cp310-win_amd64
|
5 |
+
|
Lib/site-packages/MarkupSafe-2.1.3.dist-info/top_level.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
markupsafe
|
Lib/site-packages/PIL/BdfFontFile.py
ADDED
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
|
24 |
+
|
25 |
+
from . import FontFile, Image
|
26 |
+
|
27 |
+
bdf_slant = {
|
28 |
+
"R": "Roman",
|
29 |
+
"I": "Italic",
|
30 |
+
"O": "Oblique",
|
31 |
+
"RI": "Reverse Italic",
|
32 |
+
"RO": "Reverse Oblique",
|
33 |
+
"OT": "Other",
|
34 |
+
}
|
35 |
+
|
36 |
+
bdf_spacing = {"P": "Proportional", "M": "Monospaced", "C": "Cell"}
|
37 |
+
|
38 |
+
|
39 |
+
def bdf_char(f):
|
40 |
+
# skip to STARTCHAR
|
41 |
+
while True:
|
42 |
+
s = f.readline()
|
43 |
+
if not s:
|
44 |
+
return None
|
45 |
+
if s[:9] == b"STARTCHAR":
|
46 |
+
break
|
47 |
+
id = s[9:].strip().decode("ascii")
|
48 |
+
|
49 |
+
# load symbol properties
|
50 |
+
props = {}
|
51 |
+
while True:
|
52 |
+
s = f.readline()
|
53 |
+
if not s or s[:6] == b"BITMAP":
|
54 |
+
break
|
55 |
+
i = s.find(b" ")
|
56 |
+
props[s[:i].decode("ascii")] = s[i + 1 : -1].decode("ascii")
|
57 |
+
|
58 |
+
# load bitmap
|
59 |
+
bitmap = []
|
60 |
+
while True:
|
61 |
+
s = f.readline()
|
62 |
+
if not s or s[:7] == b"ENDCHAR":
|
63 |
+
break
|
64 |
+
bitmap.append(s[:-1])
|
65 |
+
bitmap = b"".join(bitmap)
|
66 |
+
|
67 |
+
# The word BBX
|
68 |
+
# followed by the width in x (BBw), height in y (BBh),
|
69 |
+
# and x and y displacement (BBxoff0, BByoff0)
|
70 |
+
# of the lower left corner from the origin of the character.
|
71 |
+
width, height, x_disp, y_disp = [int(p) for p in props["BBX"].split()]
|
72 |
+
|
73 |
+
# The word DWIDTH
|
74 |
+
# followed by the width in x and y of the character in device pixels.
|
75 |
+
dwx, dwy = [int(p) for p in props["DWIDTH"].split()]
|
76 |
+
|
77 |
+
bbox = (
|
78 |
+
(dwx, dwy),
|
79 |
+
(x_disp, -y_disp - height, width + x_disp, -y_disp),
|
80 |
+
(0, 0, width, height),
|
81 |
+
)
|
82 |
+
|
83 |
+
try:
|
84 |
+
im = Image.frombytes("1", (width, height), bitmap, "hex", "1")
|
85 |
+
except ValueError:
|
86 |
+
# deal with zero-width characters
|
87 |
+
im = Image.new("1", (width, height))
|
88 |
+
|
89 |
+
return id, int(props["ENCODING"]), bbox, im
|
90 |
+
|
91 |
+
|
92 |
+
class BdfFontFile(FontFile.FontFile):
|
93 |
+
"""Font file plugin for the X11 BDF format."""
|
94 |
+
|
95 |
+
def __init__(self, fp):
|
96 |
+
super().__init__()
|
97 |
+
|
98 |
+
s = fp.readline()
|
99 |
+
if s[:13] != b"STARTFONT 2.1":
|
100 |
+
msg = "not a valid BDF file"
|
101 |
+
raise SyntaxError(msg)
|
102 |
+
|
103 |
+
props = {}
|
104 |
+
comments = []
|
105 |
+
|
106 |
+
while True:
|
107 |
+
s = fp.readline()
|
108 |
+
if not s or s[:13] == b"ENDPROPERTIES":
|
109 |
+
break
|
110 |
+
i = s.find(b" ")
|
111 |
+
props[s[:i].decode("ascii")] = s[i + 1 : -1].decode("ascii")
|
112 |
+
if s[:i] in [b"COMMENT", b"COPYRIGHT"]:
|
113 |
+
if s.find(b"LogicalFontDescription") < 0:
|
114 |
+
comments.append(s[i + 1 : -1].decode("ascii"))
|
115 |
+
|
116 |
+
while True:
|
117 |
+
c = bdf_char(fp)
|
118 |
+
if not c:
|
119 |
+
break
|
120 |
+
id, ch, (xy, dst, src), im = c
|
121 |
+
if 0 <= ch < len(self.glyph):
|
122 |
+
self.glyph[ch] = xy, dst, src, im
|
Lib/site-packages/PIL/BlpImagePlugin.py
ADDED
@@ -0,0 +1,488 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
Blizzard Mipmap Format (.blp)
|
3 |
+
Jerome Leclanche <[email protected]>
|
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 |
+
import os
|
33 |
+
import struct
|
34 |
+
from enum import IntEnum
|
35 |
+
from io import BytesIO
|
36 |
+
|
37 |
+
from . import Image, ImageFile
|
38 |
+
from ._deprecate import deprecate
|
39 |
+
|
40 |
+
|
41 |
+
class Format(IntEnum):
|
42 |
+
JPEG = 0
|
43 |
+
|
44 |
+
|
45 |
+
class Encoding(IntEnum):
|
46 |
+
UNCOMPRESSED = 1
|
47 |
+
DXT = 2
|
48 |
+
UNCOMPRESSED_RAW_BGRA = 3
|
49 |
+
|
50 |
+
|
51 |
+
class AlphaEncoding(IntEnum):
|
52 |
+
DXT1 = 0
|
53 |
+
DXT3 = 1
|
54 |
+
DXT5 = 7
|
55 |
+
|
56 |
+
|
57 |
+
def __getattr__(name):
|
58 |
+
for enum, prefix in {
|
59 |
+
Format: "BLP_FORMAT_",
|
60 |
+
Encoding: "BLP_ENCODING_",
|
61 |
+
AlphaEncoding: "BLP_ALPHA_ENCODING_",
|
62 |
+
}.items():
|
63 |
+
if name.startswith(prefix):
|
64 |
+
name = name[len(prefix) :]
|
65 |
+
if name in enum.__members__:
|
66 |
+
deprecate(f"{prefix}{name}", 10, f"{enum.__name__}.{name}")
|
67 |
+
return enum[name]
|
68 |
+
msg = f"module '{__name__}' has no attribute '{name}'"
|
69 |
+
raise AttributeError(msg)
|
70 |
+
|
71 |
+
|
72 |
+
def unpack_565(i):
|
73 |
+
return ((i >> 11) & 0x1F) << 3, ((i >> 5) & 0x3F) << 2, (i & 0x1F) << 3
|
74 |
+
|
75 |
+
|
76 |
+
def decode_dxt1(data, alpha=False):
|
77 |
+
"""
|
78 |
+
input: one "row" of data (i.e. will produce 4*width pixels)
|
79 |
+
"""
|
80 |
+
|
81 |
+
blocks = len(data) // 8 # number of blocks in row
|
82 |
+
ret = (bytearray(), bytearray(), bytearray(), bytearray())
|
83 |
+
|
84 |
+
for block in range(blocks):
|
85 |
+
# Decode next 8-byte block.
|
86 |
+
idx = block * 8
|
87 |
+
color0, color1, bits = struct.unpack_from("<HHI", data, idx)
|
88 |
+
|
89 |
+
r0, g0, b0 = unpack_565(color0)
|
90 |
+
r1, g1, b1 = unpack_565(color1)
|
91 |
+
|
92 |
+
# Decode this block into 4x4 pixels
|
93 |
+
# Accumulate the results onto our 4 row accumulators
|
94 |
+
for j in range(4):
|
95 |
+
for i in range(4):
|
96 |
+
# get next control op and generate a pixel
|
97 |
+
|
98 |
+
control = bits & 3
|
99 |
+
bits = bits >> 2
|
100 |
+
|
101 |
+
a = 0xFF
|
102 |
+
if control == 0:
|
103 |
+
r, g, b = r0, g0, b0
|
104 |
+
elif control == 1:
|
105 |
+
r, g, b = r1, g1, b1
|
106 |
+
elif control == 2:
|
107 |
+
if color0 > color1:
|
108 |
+
r = (2 * r0 + r1) // 3
|
109 |
+
g = (2 * g0 + g1) // 3
|
110 |
+
b = (2 * b0 + b1) // 3
|
111 |
+
else:
|
112 |
+
r = (r0 + r1) // 2
|
113 |
+
g = (g0 + g1) // 2
|
114 |
+
b = (b0 + b1) // 2
|
115 |
+
elif control == 3:
|
116 |
+
if color0 > color1:
|
117 |
+
r = (2 * r1 + r0) // 3
|
118 |
+
g = (2 * g1 + g0) // 3
|
119 |
+
b = (2 * b1 + b0) // 3
|
120 |
+
else:
|
121 |
+
r, g, b, a = 0, 0, 0, 0
|
122 |
+
|
123 |
+
if alpha:
|
124 |
+
ret[j].extend([r, g, b, a])
|
125 |
+
else:
|
126 |
+
ret[j].extend([r, g, b])
|
127 |
+
|
128 |
+
return ret
|
129 |
+
|
130 |
+
|
131 |
+
def decode_dxt3(data):
|
132 |
+
"""
|
133 |
+
input: one "row" of data (i.e. will produce 4*width pixels)
|
134 |
+
"""
|
135 |
+
|
136 |
+
blocks = len(data) // 16 # number of blocks in row
|
137 |
+
ret = (bytearray(), bytearray(), bytearray(), bytearray())
|
138 |
+
|
139 |
+
for block in range(blocks):
|
140 |
+
idx = block * 16
|
141 |
+
block = data[idx : idx + 16]
|
142 |
+
# Decode next 16-byte block.
|
143 |
+
bits = struct.unpack_from("<8B", block)
|
144 |
+
color0, color1 = struct.unpack_from("<HH", block, 8)
|
145 |
+
|
146 |
+
(code,) = struct.unpack_from("<I", block, 12)
|
147 |
+
|
148 |
+
r0, g0, b0 = unpack_565(color0)
|
149 |
+
r1, g1, b1 = unpack_565(color1)
|
150 |
+
|
151 |
+
for j in range(4):
|
152 |
+
high = False # Do we want the higher bits?
|
153 |
+
for i in range(4):
|
154 |
+
alphacode_index = (4 * j + i) // 2
|
155 |
+
a = bits[alphacode_index]
|
156 |
+
if high:
|
157 |
+
high = False
|
158 |
+
a >>= 4
|
159 |
+
else:
|
160 |
+
high = True
|
161 |
+
a &= 0xF
|
162 |
+
a *= 17 # We get a value between 0 and 15
|
163 |
+
|
164 |
+
color_code = (code >> 2 * (4 * j + i)) & 0x03
|
165 |
+
|
166 |
+
if color_code == 0:
|
167 |
+
r, g, b = r0, g0, b0
|
168 |
+
elif color_code == 1:
|
169 |
+
r, g, b = r1, g1, b1
|
170 |
+
elif color_code == 2:
|
171 |
+
r = (2 * r0 + r1) // 3
|
172 |
+
g = (2 * g0 + g1) // 3
|
173 |
+
b = (2 * b0 + b1) // 3
|
174 |
+
elif color_code == 3:
|
175 |
+
r = (2 * r1 + r0) // 3
|
176 |
+
g = (2 * g1 + g0) // 3
|
177 |
+
b = (2 * b1 + b0) // 3
|
178 |
+
|
179 |
+
ret[j].extend([r, g, b, a])
|
180 |
+
|
181 |
+
return ret
|
182 |
+
|
183 |
+
|
184 |
+
def decode_dxt5(data):
|
185 |
+
"""
|
186 |
+
input: one "row" of data (i.e. will produce 4 * width pixels)
|
187 |
+
"""
|
188 |
+
|
189 |
+
blocks = len(data) // 16 # number of blocks in row
|
190 |
+
ret = (bytearray(), bytearray(), bytearray(), bytearray())
|
191 |
+
|
192 |
+
for block in range(blocks):
|
193 |
+
idx = block * 16
|
194 |
+
block = data[idx : idx + 16]
|
195 |
+
# Decode next 16-byte block.
|
196 |
+
a0, a1 = struct.unpack_from("<BB", block)
|
197 |
+
|
198 |
+
bits = struct.unpack_from("<6B", block, 2)
|
199 |
+
alphacode1 = bits[2] | (bits[3] << 8) | (bits[4] << 16) | (bits[5] << 24)
|
200 |
+
alphacode2 = bits[0] | (bits[1] << 8)
|
201 |
+
|
202 |
+
color0, color1 = struct.unpack_from("<HH", block, 8)
|
203 |
+
|
204 |
+
(code,) = struct.unpack_from("<I", block, 12)
|
205 |
+
|
206 |
+
r0, g0, b0 = unpack_565(color0)
|
207 |
+
r1, g1, b1 = unpack_565(color1)
|
208 |
+
|
209 |
+
for j in range(4):
|
210 |
+
for i in range(4):
|
211 |
+
# get next control op and generate a pixel
|
212 |
+
alphacode_index = 3 * (4 * j + i)
|
213 |
+
|
214 |
+
if alphacode_index <= 12:
|
215 |
+
alphacode = (alphacode2 >> alphacode_index) & 0x07
|
216 |
+
elif alphacode_index == 15:
|
217 |
+
alphacode = (alphacode2 >> 15) | ((alphacode1 << 1) & 0x06)
|
218 |
+
else: # alphacode_index >= 18 and alphacode_index <= 45
|
219 |
+
alphacode = (alphacode1 >> (alphacode_index - 16)) & 0x07
|
220 |
+
|
221 |
+
if alphacode == 0:
|
222 |
+
a = a0
|
223 |
+
elif alphacode == 1:
|
224 |
+
a = a1
|
225 |
+
elif a0 > a1:
|
226 |
+
a = ((8 - alphacode) * a0 + (alphacode - 1) * a1) // 7
|
227 |
+
elif alphacode == 6:
|
228 |
+
a = 0
|
229 |
+
elif alphacode == 7:
|
230 |
+
a = 255
|
231 |
+
else:
|
232 |
+
a = ((6 - alphacode) * a0 + (alphacode - 1) * a1) // 5
|
233 |
+
|
234 |
+
color_code = (code >> 2 * (4 * j + i)) & 0x03
|
235 |
+
|
236 |
+
if color_code == 0:
|
237 |
+
r, g, b = r0, g0, b0
|
238 |
+
elif color_code == 1:
|
239 |
+
r, g, b = r1, g1, b1
|
240 |
+
elif color_code == 2:
|
241 |
+
r = (2 * r0 + r1) // 3
|
242 |
+
g = (2 * g0 + g1) // 3
|
243 |
+
b = (2 * b0 + b1) // 3
|
244 |
+
elif color_code == 3:
|
245 |
+
r = (2 * r1 + r0) // 3
|
246 |
+
g = (2 * g1 + g0) // 3
|
247 |
+
b = (2 * b1 + b0) // 3
|
248 |
+
|
249 |
+
ret[j].extend([r, g, b, a])
|
250 |
+
|
251 |
+
return ret
|
252 |
+
|
253 |
+
|
254 |
+
class BLPFormatError(NotImplementedError):
|
255 |
+
pass
|
256 |
+
|
257 |
+
|
258 |
+
def _accept(prefix):
|
259 |
+
return prefix[:4] in (b"BLP1", b"BLP2")
|
260 |
+
|
261 |
+
|
262 |
+
class BlpImageFile(ImageFile.ImageFile):
|
263 |
+
"""
|
264 |
+
Blizzard Mipmap Format
|
265 |
+
"""
|
266 |
+
|
267 |
+
format = "BLP"
|
268 |
+
format_description = "Blizzard Mipmap Format"
|
269 |
+
|
270 |
+
def _open(self):
|
271 |
+
self.magic = self.fp.read(4)
|
272 |
+
|
273 |
+
self.fp.seek(5, os.SEEK_CUR)
|
274 |
+
(self._blp_alpha_depth,) = struct.unpack("<b", self.fp.read(1))
|
275 |
+
|
276 |
+
self.fp.seek(2, os.SEEK_CUR)
|
277 |
+
self._size = struct.unpack("<II", self.fp.read(8))
|
278 |
+
|
279 |
+
if self.magic in (b"BLP1", b"BLP2"):
|
280 |
+
decoder = self.magic.decode()
|
281 |
+
else:
|
282 |
+
msg = f"Bad BLP magic {repr(self.magic)}"
|
283 |
+
raise BLPFormatError(msg)
|
284 |
+
|
285 |
+
self.mode = "RGBA" if self._blp_alpha_depth else "RGB"
|
286 |
+
self.tile = [(decoder, (0, 0) + self.size, 0, (self.mode, 0, 1))]
|
287 |
+
|
288 |
+
|
289 |
+
class _BLPBaseDecoder(ImageFile.PyDecoder):
|
290 |
+
_pulls_fd = True
|
291 |
+
|
292 |
+
def decode(self, buffer):
|
293 |
+
try:
|
294 |
+
self._read_blp_header()
|
295 |
+
self._load()
|
296 |
+
except struct.error as e:
|
297 |
+
msg = "Truncated BLP file"
|
298 |
+
raise OSError(msg) from e
|
299 |
+
return -1, 0
|
300 |
+
|
301 |
+
def _read_blp_header(self):
|
302 |
+
self.fd.seek(4)
|
303 |
+
(self._blp_compression,) = struct.unpack("<i", self._safe_read(4))
|
304 |
+
|
305 |
+
(self._blp_encoding,) = struct.unpack("<b", self._safe_read(1))
|
306 |
+
(self._blp_alpha_depth,) = struct.unpack("<b", self._safe_read(1))
|
307 |
+
(self._blp_alpha_encoding,) = struct.unpack("<b", self._safe_read(1))
|
308 |
+
self.fd.seek(1, os.SEEK_CUR) # mips
|
309 |
+
|
310 |
+
self.size = struct.unpack("<II", self._safe_read(8))
|
311 |
+
|
312 |
+
if isinstance(self, BLP1Decoder):
|
313 |
+
# Only present for BLP1
|
314 |
+
(self._blp_encoding,) = struct.unpack("<i", self._safe_read(4))
|
315 |
+
self.fd.seek(4, os.SEEK_CUR) # subtype
|
316 |
+
|
317 |
+
self._blp_offsets = struct.unpack("<16I", self._safe_read(16 * 4))
|
318 |
+
self._blp_lengths = struct.unpack("<16I", self._safe_read(16 * 4))
|
319 |
+
|
320 |
+
def _safe_read(self, length):
|
321 |
+
return ImageFile._safe_read(self.fd, length)
|
322 |
+
|
323 |
+
def _read_palette(self):
|
324 |
+
ret = []
|
325 |
+
for i in range(256):
|
326 |
+
try:
|
327 |
+
b, g, r, a = struct.unpack("<4B", self._safe_read(4))
|
328 |
+
except struct.error:
|
329 |
+
break
|
330 |
+
ret.append((b, g, r, a))
|
331 |
+
return ret
|
332 |
+
|
333 |
+
def _read_bgra(self, palette):
|
334 |
+
data = bytearray()
|
335 |
+
_data = BytesIO(self._safe_read(self._blp_lengths[0]))
|
336 |
+
while True:
|
337 |
+
try:
|
338 |
+
(offset,) = struct.unpack("<B", _data.read(1))
|
339 |
+
except struct.error:
|
340 |
+
break
|
341 |
+
b, g, r, a = palette[offset]
|
342 |
+
d = (r, g, b)
|
343 |
+
if self._blp_alpha_depth:
|
344 |
+
d += (a,)
|
345 |
+
data.extend(d)
|
346 |
+
return data
|
347 |
+
|
348 |
+
|
349 |
+
class BLP1Decoder(_BLPBaseDecoder):
|
350 |
+
def _load(self):
|
351 |
+
if self._blp_compression == Format.JPEG:
|
352 |
+
self._decode_jpeg_stream()
|
353 |
+
|
354 |
+
elif self._blp_compression == 1:
|
355 |
+
if self._blp_encoding in (4, 5):
|
356 |
+
palette = self._read_palette()
|
357 |
+
data = self._read_bgra(palette)
|
358 |
+
self.set_as_raw(bytes(data))
|
359 |
+
else:
|
360 |
+
msg = f"Unsupported BLP encoding {repr(self._blp_encoding)}"
|
361 |
+
raise BLPFormatError(msg)
|
362 |
+
else:
|
363 |
+
msg = f"Unsupported BLP compression {repr(self._blp_encoding)}"
|
364 |
+
raise BLPFormatError(msg)
|
365 |
+
|
366 |
+
def _decode_jpeg_stream(self):
|
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 |
+
self._safe_read(self._blp_offsets[0] - self.fd.tell()) # What IS this?
|
372 |
+
data = self._safe_read(self._blp_lengths[0])
|
373 |
+
data = jpeg_header + data
|
374 |
+
data = BytesIO(data)
|
375 |
+
image = JpegImageFile(data)
|
376 |
+
Image._decompression_bomb_check(image.size)
|
377 |
+
if image.mode == "CMYK":
|
378 |
+
decoder_name, extents, offset, args = image.tile[0]
|
379 |
+
image.tile = [(decoder_name, extents, offset, (args[0], "CMYK"))]
|
380 |
+
r, g, b = image.convert("RGB").split()
|
381 |
+
image = Image.merge("RGB", (b, g, r))
|
382 |
+
self.set_as_raw(image.tobytes())
|
383 |
+
|
384 |
+
|
385 |
+
class BLP2Decoder(_BLPBaseDecoder):
|
386 |
+
def _load(self):
|
387 |
+
palette = self._read_palette()
|
388 |
+
|
389 |
+
self.fd.seek(self._blp_offsets[0])
|
390 |
+
|
391 |
+
if self._blp_compression == 1:
|
392 |
+
# Uncompressed or DirectX compression
|
393 |
+
|
394 |
+
if self._blp_encoding == Encoding.UNCOMPRESSED:
|
395 |
+
data = self._read_bgra(palette)
|
396 |
+
|
397 |
+
elif self._blp_encoding == Encoding.DXT:
|
398 |
+
data = bytearray()
|
399 |
+
if self._blp_alpha_encoding == AlphaEncoding.DXT1:
|
400 |
+
linesize = (self.size[0] + 3) // 4 * 8
|
401 |
+
for yb in range((self.size[1] + 3) // 4):
|
402 |
+
for d in decode_dxt1(
|
403 |
+
self._safe_read(linesize), alpha=bool(self._blp_alpha_depth)
|
404 |
+
):
|
405 |
+
data += d
|
406 |
+
|
407 |
+
elif self._blp_alpha_encoding == AlphaEncoding.DXT3:
|
408 |
+
linesize = (self.size[0] + 3) // 4 * 16
|
409 |
+
for yb in range((self.size[1] + 3) // 4):
|
410 |
+
for d in decode_dxt3(self._safe_read(linesize)):
|
411 |
+
data += d
|
412 |
+
|
413 |
+
elif self._blp_alpha_encoding == AlphaEncoding.DXT5:
|
414 |
+
linesize = (self.size[0] + 3) // 4 * 16
|
415 |
+
for yb in range((self.size[1] + 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._blp_alpha_encoding)}"
|
420 |
+
raise BLPFormatError(msg)
|
421 |
+
else:
|
422 |
+
msg = f"Unknown BLP encoding {repr(self._blp_encoding)}"
|
423 |
+
raise BLPFormatError(msg)
|
424 |
+
|
425 |
+
else:
|
426 |
+
msg = f"Unknown BLP compression {repr(self._blp_compression)}"
|
427 |
+
raise BLPFormatError(msg)
|
428 |
+
|
429 |
+
self.set_as_raw(bytes(data))
|
430 |
+
|
431 |
+
|
432 |
+
class BLPEncoder(ImageFile.PyEncoder):
|
433 |
+
_pushes_fd = True
|
434 |
+
|
435 |
+
def _write_palette(self):
|
436 |
+
data = b""
|
437 |
+
palette = self.im.getpalette("RGBA", "RGBA")
|
438 |
+
for i in range(256):
|
439 |
+
r, g, b, a = palette[i * 4 : (i + 1) * 4]
|
440 |
+
data += struct.pack("<4B", b, g, r, a)
|
441 |
+
return data
|
442 |
+
|
443 |
+
def encode(self, bufsize):
|
444 |
+
palette_data = self._write_palette()
|
445 |
+
|
446 |
+
offset = 20 + 16 * 4 * 2 + len(palette_data)
|
447 |
+
data = struct.pack("<16I", offset, *((0,) * 15))
|
448 |
+
|
449 |
+
w, h = self.im.size
|
450 |
+
data += struct.pack("<16I", w * h, *((0,) * 15))
|
451 |
+
|
452 |
+
data += palette_data
|
453 |
+
|
454 |
+
for y in range(h):
|
455 |
+
for x in range(w):
|
456 |
+
data += struct.pack("<B", self.im.getpixel((x, y)))
|
457 |
+
|
458 |
+
return len(data), 0, data
|
459 |
+
|
460 |
+
|
461 |
+
def _save(im, fp, filename, save_all=False):
|
462 |
+
if im.mode != "P":
|
463 |
+
msg = "Unsupported BLP image mode"
|
464 |
+
raise ValueError(msg)
|
465 |
+
|
466 |
+
magic = b"BLP1" if im.encoderinfo.get("blp_version") == "BLP1" else b"BLP2"
|
467 |
+
fp.write(magic)
|
468 |
+
|
469 |
+
fp.write(struct.pack("<i", 1)) # Uncompressed or DirectX compression
|
470 |
+
fp.write(struct.pack("<b", Encoding.UNCOMPRESSED))
|
471 |
+
fp.write(struct.pack("<b", 1 if im.palette.mode == "RGBA" else 0))
|
472 |
+
fp.write(struct.pack("<b", 0)) # alpha encoding
|
473 |
+
fp.write(struct.pack("<b", 0)) # mips
|
474 |
+
fp.write(struct.pack("<II", *im.size))
|
475 |
+
if magic == b"BLP1":
|
476 |
+
fp.write(struct.pack("<i", 5))
|
477 |
+
fp.write(struct.pack("<i", 0))
|
478 |
+
|
479 |
+
ImageFile._save(im, fp, [("BLP", (0, 0) + im.size, 0, im.mode)])
|
480 |
+
|
481 |
+
|
482 |
+
Image.register_open(BlpImageFile.format, BlpImageFile, _accept)
|
483 |
+
Image.register_extension(BlpImageFile.format, ".blp")
|
484 |
+
Image.register_decoder("BLP1", BLP1Decoder)
|
485 |
+
Image.register_decoder("BLP2", BLP2Decoder)
|
486 |
+
|
487 |
+
Image.register_save(BlpImageFile.format, _save)
|
488 |
+
Image.register_encoder("BLP", BLPEncoder)
|
Lib/site-packages/PIL/BmpImagePlugin.py
ADDED
@@ -0,0 +1,471 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
|
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 |
+
greyscale = True
|
234 |
+
indices = (
|
235 |
+
(0, 255)
|
236 |
+
if file_info["colors"] == 2
|
237 |
+
else list(range(file_info["colors"]))
|
238 |
+
)
|
239 |
+
|
240 |
+
# ----------------- Check if greyscale 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 |
+
greyscale = False
|
245 |
+
|
246 |
+
# ------- If all colors are grey, white or black, ditch palette
|
247 |
+
if greyscale:
|
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 |
+
while len(data) < self.state.xsize * self.state.ysize:
|
295 |
+
pixels = self.fd.read(1)
|
296 |
+
byte = self.fd.read(1)
|
297 |
+
if not pixels or not byte:
|
298 |
+
break
|
299 |
+
num_pixels = pixels[0]
|
300 |
+
if num_pixels:
|
301 |
+
# encoded mode
|
302 |
+
if x + num_pixels > self.state.xsize:
|
303 |
+
# Too much data for row
|
304 |
+
num_pixels = max(0, self.state.xsize - x)
|
305 |
+
if rle4:
|
306 |
+
first_pixel = o8(byte[0] >> 4)
|
307 |
+
second_pixel = o8(byte[0] & 0x0F)
|
308 |
+
for index in range(num_pixels):
|
309 |
+
if index % 2 == 0:
|
310 |
+
data += first_pixel
|
311 |
+
else:
|
312 |
+
data += second_pixel
|
313 |
+
else:
|
314 |
+
data += byte * num_pixels
|
315 |
+
x += num_pixels
|
316 |
+
else:
|
317 |
+
if byte[0] == 0:
|
318 |
+
# end of line
|
319 |
+
while len(data) % self.state.xsize != 0:
|
320 |
+
data += b"\x00"
|
321 |
+
x = 0
|
322 |
+
elif byte[0] == 1:
|
323 |
+
# end of bitmap
|
324 |
+
break
|
325 |
+
elif byte[0] == 2:
|
326 |
+
# delta
|
327 |
+
bytes_read = self.fd.read(2)
|
328 |
+
if len(bytes_read) < 2:
|
329 |
+
break
|
330 |
+
right, up = self.fd.read(2)
|
331 |
+
data += b"\x00" * (right + up * self.state.xsize)
|
332 |
+
x = len(data) % self.state.xsize
|
333 |
+
else:
|
334 |
+
# absolute mode
|
335 |
+
if rle4:
|
336 |
+
# 2 pixels per byte
|
337 |
+
byte_count = byte[0] // 2
|
338 |
+
bytes_read = self.fd.read(byte_count)
|
339 |
+
for byte_read in bytes_read:
|
340 |
+
data += o8(byte_read >> 4)
|
341 |
+
data += o8(byte_read & 0x0F)
|
342 |
+
else:
|
343 |
+
byte_count = byte[0]
|
344 |
+
bytes_read = self.fd.read(byte_count)
|
345 |
+
data += bytes_read
|
346 |
+
if len(bytes_read) < byte_count:
|
347 |
+
break
|
348 |
+
x += byte[0]
|
349 |
+
|
350 |
+
# align to 16-bit word boundary
|
351 |
+
if self.fd.tell() % 2 != 0:
|
352 |
+
self.fd.seek(1, os.SEEK_CUR)
|
353 |
+
rawmode = "L" if self.mode == "L" else "P"
|
354 |
+
self.set_as_raw(bytes(data), (rawmode, 0, self.args[-1]))
|
355 |
+
return -1, 0
|
356 |
+
|
357 |
+
|
358 |
+
# =============================================================================
|
359 |
+
# Image plugin for the DIB format (BMP alias)
|
360 |
+
# =============================================================================
|
361 |
+
class DibImageFile(BmpImageFile):
|
362 |
+
format = "DIB"
|
363 |
+
format_description = "Windows Bitmap"
|
364 |
+
|
365 |
+
def _open(self):
|
366 |
+
self._bitmap()
|
367 |
+
|
368 |
+
|
369 |
+
#
|
370 |
+
# --------------------------------------------------------------------
|
371 |
+
# Write BMP file
|
372 |
+
|
373 |
+
|
374 |
+
SAVE = {
|
375 |
+
"1": ("1", 1, 2),
|
376 |
+
"L": ("L", 8, 256),
|
377 |
+
"P": ("P", 8, 256),
|
378 |
+
"RGB": ("BGR", 24, 0),
|
379 |
+
"RGBA": ("BGRA", 32, 0),
|
380 |
+
}
|
381 |
+
|
382 |
+
|
383 |
+
def _dib_save(im, fp, filename):
|
384 |
+
_save(im, fp, filename, False)
|
385 |
+
|
386 |
+
|
387 |
+
def _save(im, fp, filename, bitmap_header=True):
|
388 |
+
try:
|
389 |
+
rawmode, bits, colors = SAVE[im.mode]
|
390 |
+
except KeyError as e:
|
391 |
+
msg = f"cannot write mode {im.mode} as BMP"
|
392 |
+
raise OSError(msg) from e
|
393 |
+
|
394 |
+
info = im.encoderinfo
|
395 |
+
|
396 |
+
dpi = info.get("dpi", (96, 96))
|
397 |
+
|
398 |
+
# 1 meter == 39.3701 inches
|
399 |
+
ppm = tuple(map(lambda x: int(x * 39.3701 + 0.5), dpi))
|
400 |
+
|
401 |
+
stride = ((im.size[0] * bits + 7) // 8 + 3) & (~3)
|
402 |
+
header = 40 # or 64 for OS/2 version 2
|
403 |
+
image = stride * im.size[1]
|
404 |
+
|
405 |
+
if im.mode == "1":
|
406 |
+
palette = b"".join(o8(i) * 4 for i in (0, 255))
|
407 |
+
elif im.mode == "L":
|
408 |
+
palette = b"".join(o8(i) * 4 for i in range(256))
|
409 |
+
elif im.mode == "P":
|
410 |
+
palette = im.im.getpalette("RGB", "BGRX")
|
411 |
+
colors = len(palette) // 4
|
412 |
+
else:
|
413 |
+
palette = None
|
414 |
+
|
415 |
+
# bitmap header
|
416 |
+
if bitmap_header:
|
417 |
+
offset = 14 + header + colors * 4
|
418 |
+
file_size = offset + image
|
419 |
+
if file_size > 2**32 - 1:
|
420 |
+
msg = "File size is too large for the BMP format"
|
421 |
+
raise ValueError(msg)
|
422 |
+
fp.write(
|
423 |
+
b"BM" # file type (magic)
|
424 |
+
+ o32(file_size) # file size
|
425 |
+
+ o32(0) # reserved
|
426 |
+
+ o32(offset) # image data offset
|
427 |
+
)
|
428 |
+
|
429 |
+
# bitmap info header
|
430 |
+
fp.write(
|
431 |
+
o32(header) # info header size
|
432 |
+
+ o32(im.size[0]) # width
|
433 |
+
+ o32(im.size[1]) # height
|
434 |
+
+ o16(1) # planes
|
435 |
+
+ o16(bits) # depth
|
436 |
+
+ o32(0) # compression (0=uncompressed)
|
437 |
+
+ o32(image) # size of bitmap
|
438 |
+
+ o32(ppm[0]) # resolution
|
439 |
+
+ o32(ppm[1]) # resolution
|
440 |
+
+ o32(colors) # colors used
|
441 |
+
+ o32(colors) # colors important
|
442 |
+
)
|
443 |
+
|
444 |
+
fp.write(b"\0" * (header - 40)) # padding (for OS/2 format)
|
445 |
+
|
446 |
+
if palette:
|
447 |
+
fp.write(palette)
|
448 |
+
|
449 |
+
ImageFile._save(im, fp, [("raw", (0, 0) + im.size, 0, (rawmode, stride, -1))])
|
450 |
+
|
451 |
+
|
452 |
+
#
|
453 |
+
# --------------------------------------------------------------------
|
454 |
+
# Registry
|
455 |
+
|
456 |
+
|
457 |
+
Image.register_open(BmpImageFile.format, BmpImageFile, _accept)
|
458 |
+
Image.register_save(BmpImageFile.format, _save)
|
459 |
+
|
460 |
+
Image.register_extension(BmpImageFile.format, ".bmp")
|
461 |
+
|
462 |
+
Image.register_mime(BmpImageFile.format, "image/bmp")
|
463 |
+
|
464 |
+
Image.register_decoder("bmp_rle", BmpRleDecoder)
|
465 |
+
|
466 |
+
Image.register_open(DibImageFile.format, DibImageFile, _dib_accept)
|
467 |
+
Image.register_save(DibImageFile.format, _dib_save)
|
468 |
+
|
469 |
+
Image.register_extension(DibImageFile.format, ".dib")
|
470 |
+
|
471 |
+
Image.register_mime(DibImageFile.format, "image/bmp")
|
Lib/site-packages/PIL/BufrStubImagePlugin.py
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
|
12 |
+
from . import Image, ImageFile
|
13 |
+
|
14 |
+
_handler = None
|
15 |
+
|
16 |
+
|
17 |
+
def register_handler(handler):
|
18 |
+
"""
|
19 |
+
Install application-specific BUFR image handler.
|
20 |
+
|
21 |
+
:param handler: Handler object.
|
22 |
+
"""
|
23 |
+
global _handler
|
24 |
+
_handler = handler
|
25 |
+
|
26 |
+
|
27 |
+
# --------------------------------------------------------------------
|
28 |
+
# Image adapter
|
29 |
+
|
30 |
+
|
31 |
+
def _accept(prefix):
|
32 |
+
return prefix[:4] == b"BUFR" or prefix[:4] == b"ZCZC"
|
33 |
+
|
34 |
+
|
35 |
+
class BufrStubImageFile(ImageFile.StubImageFile):
|
36 |
+
format = "BUFR"
|
37 |
+
format_description = "BUFR"
|
38 |
+
|
39 |
+
def _open(self):
|
40 |
+
offset = self.fp.tell()
|
41 |
+
|
42 |
+
if not _accept(self.fp.read(4)):
|
43 |
+
msg = "Not a BUFR file"
|
44 |
+
raise SyntaxError(msg)
|
45 |
+
|
46 |
+
self.fp.seek(offset)
|
47 |
+
|
48 |
+
# make something up
|
49 |
+
self.mode = "F"
|
50 |
+
self._size = 1, 1
|
51 |
+
|
52 |
+
loader = self._load()
|
53 |
+
if loader:
|
54 |
+
loader.open(self)
|
55 |
+
|
56 |
+
def _load(self):
|
57 |
+
return _handler
|
58 |
+
|
59 |
+
|
60 |
+
def _save(im, fp, filename):
|
61 |
+
if _handler is None or not hasattr(_handler, "save"):
|
62 |
+
msg = "BUFR save handler not installed"
|
63 |
+
raise OSError(msg)
|
64 |
+
_handler.save(im, fp, filename)
|
65 |
+
|
66 |
+
|
67 |
+
# --------------------------------------------------------------------
|
68 |
+
# Registry
|
69 |
+
|
70 |
+
Image.register_open(BufrStubImageFile.format, BufrStubImageFile, _accept)
|
71 |
+
Image.register_save(BufrStubImageFile.format, _save)
|
72 |
+
|
73 |
+
Image.register_extension(BufrStubImageFile.format, ".bufr")
|
Lib/site-packages/PIL/ContainerIO.py
ADDED
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#
|
2 |
+
# The Python Imaging Library.
|
3 |
+
# $Id$
|
4 |
+
#
|
5 |
+
# a class to read from a container file
|
6 |
+
#
|
7 |
+
# History:
|
8 |
+
# 1995-06-18 fl Created
|
9 |
+
# 1995-09-07 fl Added readline(), readlines()
|
10 |
+
#
|
11 |
+
# Copyright (c) 1997-2001 by Secret Labs AB
|
12 |
+
# Copyright (c) 1995 by Fredrik Lundh
|
13 |
+
#
|
14 |
+
# See the README file for information on usage and redistribution.
|
15 |
+
#
|
16 |
+
|
17 |
+
|
18 |
+
import io
|
19 |
+
|
20 |
+
|
21 |
+
class ContainerIO:
|
22 |
+
"""
|
23 |
+
A file object that provides read access to a part of an existing
|
24 |
+
file (for example a TAR file).
|
25 |
+
"""
|
26 |
+
|
27 |
+
def __init__(self, file, offset, length):
|
28 |
+
"""
|
29 |
+
Create file object.
|
30 |
+
|
31 |
+
:param file: Existing file.
|
32 |
+
:param offset: Start of region, in bytes.
|
33 |
+
:param length: Size of region, in bytes.
|
34 |
+
"""
|
35 |
+
self.fh = file
|
36 |
+
self.pos = 0
|
37 |
+
self.offset = offset
|
38 |
+
self.length = length
|
39 |
+
self.fh.seek(offset)
|
40 |
+
|
41 |
+
##
|
42 |
+
# Always false.
|
43 |
+
|
44 |
+
def isatty(self):
|
45 |
+
return False
|
46 |
+
|
47 |
+
def seek(self, offset, mode=io.SEEK_SET):
|
48 |
+
"""
|
49 |
+
Move file pointer.
|
50 |
+
|
51 |
+
:param offset: Offset in bytes.
|
52 |
+
:param mode: Starting position. Use 0 for beginning of region, 1
|
53 |
+
for current offset, and 2 for end of region. You cannot move
|
54 |
+
the pointer outside the defined region.
|
55 |
+
"""
|
56 |
+
if mode == 1:
|
57 |
+
self.pos = self.pos + offset
|
58 |
+
elif mode == 2:
|
59 |
+
self.pos = self.length + offset
|
60 |
+
else:
|
61 |
+
self.pos = offset
|
62 |
+
# clamp
|
63 |
+
self.pos = max(0, min(self.pos, self.length))
|
64 |
+
self.fh.seek(self.offset + self.pos)
|
65 |
+
|
66 |
+
def tell(self):
|
67 |
+
"""
|
68 |
+
Get current file pointer.
|
69 |
+
|
70 |
+
:returns: Offset from start of region, in bytes.
|
71 |
+
"""
|
72 |
+
return self.pos
|
73 |
+
|
74 |
+
def read(self, n=0):
|
75 |
+
"""
|
76 |
+
Read data.
|
77 |
+
|
78 |
+
:param n: Number of bytes to read. If omitted or zero,
|
79 |
+
read until end of region.
|
80 |
+
:returns: An 8-bit string.
|
81 |
+
"""
|
82 |
+
if n:
|
83 |
+
n = min(n, self.length - self.pos)
|
84 |
+
else:
|
85 |
+
n = self.length - self.pos
|
86 |
+
if not n: # EOF
|
87 |
+
return b"" if "b" in self.fh.mode else ""
|
88 |
+
self.pos = self.pos + n
|
89 |
+
return self.fh.read(n)
|
90 |
+
|
91 |
+
def readline(self):
|
92 |
+
"""
|
93 |
+
Read a line of text.
|
94 |
+
|
95 |
+
:returns: An 8-bit string.
|
96 |
+
"""
|
97 |
+
s = b"" if "b" in self.fh.mode else ""
|
98 |
+
newline_character = b"\n" if "b" in self.fh.mode else "\n"
|
99 |
+
while True:
|
100 |
+
c = self.read(1)
|
101 |
+
if not c:
|
102 |
+
break
|
103 |
+
s = s + c
|
104 |
+
if c == newline_character:
|
105 |
+
break
|
106 |
+
return s
|
107 |
+
|
108 |
+
def readlines(self):
|
109 |
+
"""
|
110 |
+
Read multiple lines of text.
|
111 |
+
|
112 |
+
:returns: A list of 8-bit strings.
|
113 |
+
"""
|
114 |
+
lines = []
|
115 |
+
while True:
|
116 |
+
s = self.readline()
|
117 |
+
if not s:
|
118 |
+
break
|
119 |
+
lines.append(s)
|
120 |
+
return lines
|
Lib/site-packages/PIL/CurImagePlugin.py
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#
|
2 |
+
# The Python Imaging Library.
|
3 |
+
# $Id$
|
4 |
+
#
|
5 |
+
# Windows Cursor support for PIL
|
6 |
+
#
|
7 |
+
# notes:
|
8 |
+
# uses BmpImagePlugin.py to read the bitmap data.
|
9 |
+
#
|
10 |
+
# history:
|
11 |
+
# 96-05-27 fl Created
|
12 |
+
#
|
13 |
+
# Copyright (c) Secret Labs AB 1997.
|
14 |
+
# Copyright (c) Fredrik Lundh 1996.
|
15 |
+
#
|
16 |
+
# See the README file for information on usage and redistribution.
|
17 |
+
#
|
18 |
+
from . import BmpImagePlugin, Image
|
19 |
+
from ._binary import i16le as i16
|
20 |
+
from ._binary import i32le as i32
|
21 |
+
|
22 |
+
#
|
23 |
+
# --------------------------------------------------------------------
|
24 |
+
|
25 |
+
|
26 |
+
def _accept(prefix):
|
27 |
+
return prefix[:4] == b"\0\0\2\0"
|
28 |
+
|
29 |
+
|
30 |
+
##
|
31 |
+
# Image plugin for Windows Cursor files.
|
32 |
+
|
33 |
+
|
34 |
+
class CurImageFile(BmpImagePlugin.BmpImageFile):
|
35 |
+
format = "CUR"
|
36 |
+
format_description = "Windows Cursor"
|
37 |
+
|
38 |
+
def _open(self):
|
39 |
+
offset = self.fp.tell()
|
40 |
+
|
41 |
+
# check magic
|
42 |
+
s = self.fp.read(6)
|
43 |
+
if not _accept(s):
|
44 |
+
msg = "not a CUR file"
|
45 |
+
raise SyntaxError(msg)
|
46 |
+
|
47 |
+
# pick the largest cursor in the file
|
48 |
+
m = b""
|
49 |
+
for i in range(i16(s, 4)):
|
50 |
+
s = self.fp.read(16)
|
51 |
+
if not m:
|
52 |
+
m = s
|
53 |
+
elif s[0] > m[0] and s[1] > m[1]:
|
54 |
+
m = s
|
55 |
+
if not m:
|
56 |
+
msg = "No cursors were found"
|
57 |
+
raise TypeError(msg)
|
58 |
+
|
59 |
+
# load as bitmap
|
60 |
+
self._bitmap(i32(m, 12) + offset)
|
61 |
+
|
62 |
+
# patch up the bitmap height
|
63 |
+
self._size = self.size[0], self.size[1] // 2
|
64 |
+
d, e, o, a = self.tile[0]
|
65 |
+
self.tile[0] = d, (0, 0) + self.size, o, a
|
66 |
+
|
67 |
+
return
|
68 |
+
|
69 |
+
|
70 |
+
#
|
71 |
+
# --------------------------------------------------------------------
|
72 |
+
|
73 |
+
Image.register_open(CurImageFile.format, CurImageFile, _accept)
|
74 |
+
|
75 |
+
Image.register_extension(CurImageFile.format, ".cur")
|
Lib/site-packages/PIL/DcxImagePlugin.py
ADDED
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#
|
2 |
+
# The Python Imaging Library.
|
3 |
+
# $Id$
|
4 |
+
#
|
5 |
+
# DCX file handling
|
6 |
+
#
|
7 |
+
# DCX is a container file format defined by Intel, commonly used
|
8 |
+
# for fax applications. Each DCX file consists of a directory
|
9 |
+
# (a list of file offsets) followed by a set of (usually 1-bit)
|
10 |
+
# PCX files.
|
11 |
+
#
|
12 |
+
# History:
|
13 |
+
# 1995-09-09 fl Created
|
14 |
+
# 1996-03-20 fl Properly derived from PcxImageFile.
|
15 |
+
# 1998-07-15 fl Renamed offset attribute to avoid name clash
|
16 |
+
# 2002-07-30 fl Fixed file handling
|
17 |
+
#
|
18 |
+
# Copyright (c) 1997-98 by Secret Labs AB.
|
19 |
+
# Copyright (c) 1995-96 by Fredrik Lundh.
|
20 |
+
#
|
21 |
+
# See the README file for information on usage and redistribution.
|
22 |
+
#
|
23 |
+
|
24 |
+
from . import Image
|
25 |
+
from ._binary import i32le as i32
|
26 |
+
from .PcxImagePlugin import PcxImageFile
|
27 |
+
|
28 |
+
MAGIC = 0x3ADE68B1 # QUIZ: what's this value, then?
|
29 |
+
|
30 |
+
|
31 |
+
def _accept(prefix):
|
32 |
+
return len(prefix) >= 4 and i32(prefix) == MAGIC
|
33 |
+
|
34 |
+
|
35 |
+
##
|
36 |
+
# Image plugin for the Intel DCX format.
|
37 |
+
|
38 |
+
|
39 |
+
class DcxImageFile(PcxImageFile):
|
40 |
+
format = "DCX"
|
41 |
+
format_description = "Intel DCX"
|
42 |
+
_close_exclusive_fp_after_loading = False
|
43 |
+
|
44 |
+
def _open(self):
|
45 |
+
# Header
|
46 |
+
s = self.fp.read(4)
|
47 |
+
if not _accept(s):
|
48 |
+
msg = "not a DCX file"
|
49 |
+
raise SyntaxError(msg)
|
50 |
+
|
51 |
+
# Component directory
|
52 |
+
self._offset = []
|
53 |
+
for i in range(1024):
|
54 |
+
offset = i32(self.fp.read(4))
|
55 |
+
if not offset:
|
56 |
+
break
|
57 |
+
self._offset.append(offset)
|
58 |
+
|
59 |
+
self._fp = self.fp
|
60 |
+
self.frame = None
|
61 |
+
self.n_frames = len(self._offset)
|
62 |
+
self.is_animated = self.n_frames > 1
|
63 |
+
self.seek(0)
|
64 |
+
|
65 |
+
def seek(self, frame):
|
66 |
+
if not self._seek_check(frame):
|
67 |
+
return
|
68 |
+
self.frame = frame
|
69 |
+
self.fp = self._fp
|
70 |
+
self.fp.seek(self._offset[frame])
|
71 |
+
PcxImageFile._open(self)
|
72 |
+
|
73 |
+
def tell(self):
|
74 |
+
return self.frame
|
75 |
+
|
76 |
+
|
77 |
+
Image.register_open(DcxImageFile.format, DcxImageFile, _accept)
|
78 |
+
|
79 |
+
Image.register_extension(DcxImageFile.format, ".dcx")
|
Lib/site-packages/PIL/DdsImagePlugin.py
ADDED
@@ -0,0 +1,291 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
A Pillow loader for .dds files (S3TC-compressed aka DXTC)
|
3 |
+
Jerome Leclanche <[email protected]>
|
4 |
+
|
5 |
+
Documentation:
|
6 |
+
https://web.archive.org/web/20170802060935/http://oss.sgi.com/projects/ogl-sample/registry/EXT/texture_compression_s3tc.txt
|
7 |
+
|
8 |
+
The contents of this file are hereby released in the public domain (CC0)
|
9 |
+
Full text of the CC0 license:
|
10 |
+
https://creativecommons.org/publicdomain/zero/1.0/
|
11 |
+
"""
|
12 |
+
|
13 |
+
import struct
|
14 |
+
from io import BytesIO
|
15 |
+
|
16 |
+
from . import Image, ImageFile
|
17 |
+
from ._binary import o32le as o32
|
18 |
+
|
19 |
+
# Magic ("DDS ")
|
20 |
+
DDS_MAGIC = 0x20534444
|
21 |
+
|
22 |
+
# DDS flags
|
23 |
+
DDSD_CAPS = 0x1
|
24 |
+
DDSD_HEIGHT = 0x2
|
25 |
+
DDSD_WIDTH = 0x4
|
26 |
+
DDSD_PITCH = 0x8
|
27 |
+
DDSD_PIXELFORMAT = 0x1000
|
28 |
+
DDSD_MIPMAPCOUNT = 0x20000
|
29 |
+
DDSD_LINEARSIZE = 0x80000
|
30 |
+
DDSD_DEPTH = 0x800000
|
31 |
+
|
32 |
+
# DDS caps
|
33 |
+
DDSCAPS_COMPLEX = 0x8
|
34 |
+
DDSCAPS_TEXTURE = 0x1000
|
35 |
+
DDSCAPS_MIPMAP = 0x400000
|
36 |
+
|
37 |
+
DDSCAPS2_CUBEMAP = 0x200
|
38 |
+
DDSCAPS2_CUBEMAP_POSITIVEX = 0x400
|
39 |
+
DDSCAPS2_CUBEMAP_NEGATIVEX = 0x800
|
40 |
+
DDSCAPS2_CUBEMAP_POSITIVEY = 0x1000
|
41 |
+
DDSCAPS2_CUBEMAP_NEGATIVEY = 0x2000
|
42 |
+
DDSCAPS2_CUBEMAP_POSITIVEZ = 0x4000
|
43 |
+
DDSCAPS2_CUBEMAP_NEGATIVEZ = 0x8000
|
44 |
+
DDSCAPS2_VOLUME = 0x200000
|
45 |
+
|
46 |
+
# Pixel Format
|
47 |
+
DDPF_ALPHAPIXELS = 0x1
|
48 |
+
DDPF_ALPHA = 0x2
|
49 |
+
DDPF_FOURCC = 0x4
|
50 |
+
DDPF_PALETTEINDEXED8 = 0x20
|
51 |
+
DDPF_RGB = 0x40
|
52 |
+
DDPF_LUMINANCE = 0x20000
|
53 |
+
|
54 |
+
|
55 |
+
# dds.h
|
56 |
+
|
57 |
+
DDS_FOURCC = DDPF_FOURCC
|
58 |
+
DDS_RGB = DDPF_RGB
|
59 |
+
DDS_RGBA = DDPF_RGB | DDPF_ALPHAPIXELS
|
60 |
+
DDS_LUMINANCE = DDPF_LUMINANCE
|
61 |
+
DDS_LUMINANCEA = DDPF_LUMINANCE | DDPF_ALPHAPIXELS
|
62 |
+
DDS_ALPHA = DDPF_ALPHA
|
63 |
+
DDS_PAL8 = DDPF_PALETTEINDEXED8
|
64 |
+
|
65 |
+
DDS_HEADER_FLAGS_TEXTURE = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT
|
66 |
+
DDS_HEADER_FLAGS_MIPMAP = DDSD_MIPMAPCOUNT
|
67 |
+
DDS_HEADER_FLAGS_VOLUME = DDSD_DEPTH
|
68 |
+
DDS_HEADER_FLAGS_PITCH = DDSD_PITCH
|
69 |
+
DDS_HEADER_FLAGS_LINEARSIZE = DDSD_LINEARSIZE
|
70 |
+
|
71 |
+
DDS_HEIGHT = DDSD_HEIGHT
|
72 |
+
DDS_WIDTH = DDSD_WIDTH
|
73 |
+
|
74 |
+
DDS_SURFACE_FLAGS_TEXTURE = DDSCAPS_TEXTURE
|
75 |
+
DDS_SURFACE_FLAGS_MIPMAP = DDSCAPS_COMPLEX | DDSCAPS_MIPMAP
|
76 |
+
DDS_SURFACE_FLAGS_CUBEMAP = DDSCAPS_COMPLEX
|
77 |
+
|
78 |
+
DDS_CUBEMAP_POSITIVEX = DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEX
|
79 |
+
DDS_CUBEMAP_NEGATIVEX = DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEX
|
80 |
+
DDS_CUBEMAP_POSITIVEY = DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEY
|
81 |
+
DDS_CUBEMAP_NEGATIVEY = DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEY
|
82 |
+
DDS_CUBEMAP_POSITIVEZ = DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEZ
|
83 |
+
DDS_CUBEMAP_NEGATIVEZ = DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEZ
|
84 |
+
|
85 |
+
|
86 |
+
# DXT1
|
87 |
+
DXT1_FOURCC = 0x31545844
|
88 |
+
|
89 |
+
# DXT3
|
90 |
+
DXT3_FOURCC = 0x33545844
|
91 |
+
|
92 |
+
# DXT5
|
93 |
+
DXT5_FOURCC = 0x35545844
|
94 |
+
|
95 |
+
|
96 |
+
# dxgiformat.h
|
97 |
+
|
98 |
+
DXGI_FORMAT_R8G8B8A8_TYPELESS = 27
|
99 |
+
DXGI_FORMAT_R8G8B8A8_UNORM = 28
|
100 |
+
DXGI_FORMAT_R8G8B8A8_UNORM_SRGB = 29
|
101 |
+
DXGI_FORMAT_BC5_TYPELESS = 82
|
102 |
+
DXGI_FORMAT_BC5_UNORM = 83
|
103 |
+
DXGI_FORMAT_BC5_SNORM = 84
|
104 |
+
DXGI_FORMAT_BC6H_UF16 = 95
|
105 |
+
DXGI_FORMAT_BC6H_SF16 = 96
|
106 |
+
DXGI_FORMAT_BC7_TYPELESS = 97
|
107 |
+
DXGI_FORMAT_BC7_UNORM = 98
|
108 |
+
DXGI_FORMAT_BC7_UNORM_SRGB = 99
|
109 |
+
|
110 |
+
|
111 |
+
class DdsImageFile(ImageFile.ImageFile):
|
112 |
+
format = "DDS"
|
113 |
+
format_description = "DirectDraw Surface"
|
114 |
+
|
115 |
+
def _open(self):
|
116 |
+
if not _accept(self.fp.read(4)):
|
117 |
+
msg = "not a DDS file"
|
118 |
+
raise SyntaxError(msg)
|
119 |
+
(header_size,) = struct.unpack("<I", self.fp.read(4))
|
120 |
+
if header_size != 124:
|
121 |
+
msg = f"Unsupported header size {repr(header_size)}"
|
122 |
+
raise OSError(msg)
|
123 |
+
header_bytes = self.fp.read(header_size - 4)
|
124 |
+
if len(header_bytes) != 120:
|
125 |
+
msg = f"Incomplete header: {len(header_bytes)} bytes"
|
126 |
+
raise OSError(msg)
|
127 |
+
header = BytesIO(header_bytes)
|
128 |
+
|
129 |
+
flags, height, width = struct.unpack("<3I", header.read(12))
|
130 |
+
self._size = (width, height)
|
131 |
+
self.mode = "RGBA"
|
132 |
+
|
133 |
+
pitch, depth, mipmaps = struct.unpack("<3I", header.read(12))
|
134 |
+
struct.unpack("<11I", header.read(44)) # reserved
|
135 |
+
|
136 |
+
# pixel format
|
137 |
+
pfsize, pfflags = struct.unpack("<2I", header.read(8))
|
138 |
+
fourcc = header.read(4)
|
139 |
+
(bitcount,) = struct.unpack("<I", header.read(4))
|
140 |
+
masks = struct.unpack("<4I", header.read(16))
|
141 |
+
if pfflags & DDPF_LUMINANCE:
|
142 |
+
# Texture contains uncompressed L or LA data
|
143 |
+
if pfflags & DDPF_ALPHAPIXELS:
|
144 |
+
self.mode = "LA"
|
145 |
+
else:
|
146 |
+
self.mode = "L"
|
147 |
+
|
148 |
+
self.tile = [("raw", (0, 0) + self.size, 0, (self.mode, 0, 1))]
|
149 |
+
elif pfflags & DDPF_RGB:
|
150 |
+
# Texture contains uncompressed RGB data
|
151 |
+
masks = {mask: ["R", "G", "B", "A"][i] for i, mask in enumerate(masks)}
|
152 |
+
rawmode = ""
|
153 |
+
if pfflags & DDPF_ALPHAPIXELS:
|
154 |
+
rawmode += masks[0xFF000000]
|
155 |
+
else:
|
156 |
+
self.mode = "RGB"
|
157 |
+
rawmode += masks[0xFF0000] + masks[0xFF00] + masks[0xFF]
|
158 |
+
|
159 |
+
self.tile = [("raw", (0, 0) + self.size, 0, (rawmode[::-1], 0, 1))]
|
160 |
+
else:
|
161 |
+
data_start = header_size + 4
|
162 |
+
n = 0
|
163 |
+
if fourcc == b"DXT1":
|
164 |
+
self.pixel_format = "DXT1"
|
165 |
+
n = 1
|
166 |
+
elif fourcc == b"DXT3":
|
167 |
+
self.pixel_format = "DXT3"
|
168 |
+
n = 2
|
169 |
+
elif fourcc == b"DXT5":
|
170 |
+
self.pixel_format = "DXT5"
|
171 |
+
n = 3
|
172 |
+
elif fourcc == b"ATI1":
|
173 |
+
self.pixel_format = "BC4"
|
174 |
+
n = 4
|
175 |
+
self.mode = "L"
|
176 |
+
elif fourcc == b"ATI2":
|
177 |
+
self.pixel_format = "BC5"
|
178 |
+
n = 5
|
179 |
+
self.mode = "RGB"
|
180 |
+
elif fourcc == b"BC5S":
|
181 |
+
self.pixel_format = "BC5S"
|
182 |
+
n = 5
|
183 |
+
self.mode = "RGB"
|
184 |
+
elif fourcc == b"DX10":
|
185 |
+
data_start += 20
|
186 |
+
# ignoring flags which pertain to volume textures and cubemaps
|
187 |
+
(dxgi_format,) = struct.unpack("<I", self.fp.read(4))
|
188 |
+
self.fp.read(16)
|
189 |
+
if dxgi_format in (DXGI_FORMAT_BC5_TYPELESS, DXGI_FORMAT_BC5_UNORM):
|
190 |
+
self.pixel_format = "BC5"
|
191 |
+
n = 5
|
192 |
+
self.mode = "RGB"
|
193 |
+
elif dxgi_format == DXGI_FORMAT_BC5_SNORM:
|
194 |
+
self.pixel_format = "BC5S"
|
195 |
+
n = 5
|
196 |
+
self.mode = "RGB"
|
197 |
+
elif dxgi_format == DXGI_FORMAT_BC6H_UF16:
|
198 |
+
self.pixel_format = "BC6H"
|
199 |
+
n = 6
|
200 |
+
self.mode = "RGB"
|
201 |
+
elif dxgi_format == DXGI_FORMAT_BC6H_SF16:
|
202 |
+
self.pixel_format = "BC6HS"
|
203 |
+
n = 6
|
204 |
+
self.mode = "RGB"
|
205 |
+
elif dxgi_format in (DXGI_FORMAT_BC7_TYPELESS, DXGI_FORMAT_BC7_UNORM):
|
206 |
+
self.pixel_format = "BC7"
|
207 |
+
n = 7
|
208 |
+
elif dxgi_format == DXGI_FORMAT_BC7_UNORM_SRGB:
|
209 |
+
self.pixel_format = "BC7"
|
210 |
+
self.info["gamma"] = 1 / 2.2
|
211 |
+
n = 7
|
212 |
+
elif dxgi_format in (
|
213 |
+
DXGI_FORMAT_R8G8B8A8_TYPELESS,
|
214 |
+
DXGI_FORMAT_R8G8B8A8_UNORM,
|
215 |
+
DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
|
216 |
+
):
|
217 |
+
self.tile = [("raw", (0, 0) + self.size, 0, ("RGBA", 0, 1))]
|
218 |
+
if dxgi_format == DXGI_FORMAT_R8G8B8A8_UNORM_SRGB:
|
219 |
+
self.info["gamma"] = 1 / 2.2
|
220 |
+
return
|
221 |
+
else:
|
222 |
+
msg = f"Unimplemented DXGI format {dxgi_format}"
|
223 |
+
raise NotImplementedError(msg)
|
224 |
+
else:
|
225 |
+
msg = f"Unimplemented pixel format {repr(fourcc)}"
|
226 |
+
raise NotImplementedError(msg)
|
227 |
+
|
228 |
+
self.tile = [
|
229 |
+
("bcn", (0, 0) + self.size, data_start, (n, self.pixel_format))
|
230 |
+
]
|
231 |
+
|
232 |
+
def load_seek(self, pos):
|
233 |
+
pass
|
234 |
+
|
235 |
+
|
236 |
+
def _save(im, fp, filename):
|
237 |
+
if im.mode not in ("RGB", "RGBA", "L", "LA"):
|
238 |
+
msg = f"cannot write mode {im.mode} as DDS"
|
239 |
+
raise OSError(msg)
|
240 |
+
|
241 |
+
rawmode = im.mode
|
242 |
+
masks = [0xFF0000, 0xFF00, 0xFF]
|
243 |
+
if im.mode in ("L", "LA"):
|
244 |
+
pixel_flags = DDPF_LUMINANCE
|
245 |
+
else:
|
246 |
+
pixel_flags = DDPF_RGB
|
247 |
+
rawmode = rawmode[::-1]
|
248 |
+
if im.mode in ("LA", "RGBA"):
|
249 |
+
pixel_flags |= DDPF_ALPHAPIXELS
|
250 |
+
masks.append(0xFF000000)
|
251 |
+
|
252 |
+
bitcount = len(masks) * 8
|
253 |
+
while len(masks) < 4:
|
254 |
+
masks.append(0)
|
255 |
+
|
256 |
+
fp.write(
|
257 |
+
o32(DDS_MAGIC)
|
258 |
+
+ o32(124) # header size
|
259 |
+
+ o32(
|
260 |
+
DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PITCH | DDSD_PIXELFORMAT
|
261 |
+
) # flags
|
262 |
+
+ o32(im.height)
|
263 |
+
+ o32(im.width)
|
264 |
+
+ o32((im.width * bitcount + 7) // 8) # pitch
|
265 |
+
+ o32(0) # depth
|
266 |
+
+ o32(0) # mipmaps
|
267 |
+
+ o32(0) * 11 # reserved
|
268 |
+
+ o32(32) # pfsize
|
269 |
+
+ o32(pixel_flags) # pfflags
|
270 |
+
+ o32(0) # fourcc
|
271 |
+
+ o32(bitcount) # bitcount
|
272 |
+
+ b"".join(o32(mask) for mask in masks) # rgbabitmask
|
273 |
+
+ o32(DDSCAPS_TEXTURE) # dwCaps
|
274 |
+
+ o32(0) # dwCaps2
|
275 |
+
+ o32(0) # dwCaps3
|
276 |
+
+ o32(0) # dwCaps4
|
277 |
+
+ o32(0) # dwReserved2
|
278 |
+
)
|
279 |
+
if im.mode == "RGBA":
|
280 |
+
r, g, b, a = im.split()
|
281 |
+
im = Image.merge("RGBA", (a, r, g, b))
|
282 |
+
ImageFile._save(im, fp, [("raw", (0, 0) + im.size, 0, (rawmode, 0, 1))])
|
283 |
+
|
284 |
+
|
285 |
+
def _accept(prefix):
|
286 |
+
return prefix[:4] == b"DDS "
|
287 |
+
|
288 |
+
|
289 |
+
Image.register_open(DdsImageFile.format, DdsImageFile, _accept)
|
290 |
+
Image.register_save(DdsImageFile.format, _save)
|
291 |
+
Image.register_extension(DdsImageFile.format, ".dds")
|
Lib/site-packages/PIL/EpsImagePlugin.py
ADDED
@@ -0,0 +1,460 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#
|
2 |
+
# The Python Imaging Library.
|
3 |
+
# $Id$
|
4 |
+
#
|
5 |
+
# EPS file handling
|
6 |
+
#
|
7 |
+
# History:
|
8 |
+
# 1995-09-01 fl Created (0.1)
|
9 |
+
# 1996-05-18 fl Don't choke on "atend" fields, Ghostscript interface (0.2)
|
10 |
+
# 1996-08-22 fl Don't choke on floating point BoundingBox values
|
11 |
+
# 1996-08-23 fl Handle files from Macintosh (0.3)
|
12 |
+
# 2001-02-17 fl Use 're' instead of 'regex' (Python 2.1) (0.4)
|
13 |
+
# 2003-09-07 fl Check gs.close status (from Federico Di Gregorio) (0.5)
|
14 |
+
# 2014-05-07 e Handling of EPS with binary preview and fixed resolution
|
15 |
+
# resizing
|
16 |
+
#
|
17 |
+
# Copyright (c) 1997-2003 by Secret Labs AB.
|
18 |
+
# Copyright (c) 1995-2003 by Fredrik Lundh
|
19 |
+
#
|
20 |
+
# See the README file for information on usage and redistribution.
|
21 |
+
#
|
22 |
+
|
23 |
+
import io
|
24 |
+
import os
|
25 |
+
import re
|
26 |
+
import subprocess
|
27 |
+
import sys
|
28 |
+
import tempfile
|
29 |
+
|
30 |
+
from . import Image, ImageFile
|
31 |
+
from ._binary import i32le as i32
|
32 |
+
from ._deprecate import deprecate
|
33 |
+
|
34 |
+
# --------------------------------------------------------------------
|
35 |
+
|
36 |
+
|
37 |
+
split = re.compile(r"^%%([^:]*):[ \t]*(.*)[ \t]*$")
|
38 |
+
field = re.compile(r"^%[%!\w]([^:]*)[ \t]*$")
|
39 |
+
|
40 |
+
gs_windows_binary = None
|
41 |
+
if sys.platform.startswith("win"):
|
42 |
+
import shutil
|
43 |
+
|
44 |
+
for binary in ("gswin32c", "gswin64c", "gs"):
|
45 |
+
if shutil.which(binary) is not None:
|
46 |
+
gs_windows_binary = binary
|
47 |
+
break
|
48 |
+
else:
|
49 |
+
gs_windows_binary = False
|
50 |
+
|
51 |
+
|
52 |
+
def has_ghostscript():
|
53 |
+
if gs_windows_binary:
|
54 |
+
return True
|
55 |
+
if not sys.platform.startswith("win"):
|
56 |
+
try:
|
57 |
+
subprocess.check_call(["gs", "--version"], stdout=subprocess.DEVNULL)
|
58 |
+
return True
|
59 |
+
except OSError:
|
60 |
+
# No Ghostscript
|
61 |
+
pass
|
62 |
+
return False
|
63 |
+
|
64 |
+
|
65 |
+
def Ghostscript(tile, size, fp, scale=1, transparency=False):
|
66 |
+
"""Render an image using Ghostscript"""
|
67 |
+
|
68 |
+
# Unpack decoder tile
|
69 |
+
decoder, tile, offset, data = tile[0]
|
70 |
+
length, bbox = data
|
71 |
+
|
72 |
+
# Hack to support hi-res rendering
|
73 |
+
scale = int(scale) or 1
|
74 |
+
# orig_size = size
|
75 |
+
# orig_bbox = bbox
|
76 |
+
size = (size[0] * scale, size[1] * scale)
|
77 |
+
# resolution is dependent on bbox and size
|
78 |
+
res = (
|
79 |
+
72.0 * size[0] / (bbox[2] - bbox[0]),
|
80 |
+
72.0 * size[1] / (bbox[3] - bbox[1]),
|
81 |
+
)
|
82 |
+
|
83 |
+
out_fd, outfile = tempfile.mkstemp()
|
84 |
+
os.close(out_fd)
|
85 |
+
|
86 |
+
infile_temp = None
|
87 |
+
if hasattr(fp, "name") and os.path.exists(fp.name):
|
88 |
+
infile = fp.name
|
89 |
+
else:
|
90 |
+
in_fd, infile_temp = tempfile.mkstemp()
|
91 |
+
os.close(in_fd)
|
92 |
+
infile = infile_temp
|
93 |
+
|
94 |
+
# Ignore length and offset!
|
95 |
+
# Ghostscript can read it
|
96 |
+
# Copy whole file to read in Ghostscript
|
97 |
+
with open(infile_temp, "wb") as f:
|
98 |
+
# fetch length of fp
|
99 |
+
fp.seek(0, io.SEEK_END)
|
100 |
+
fsize = fp.tell()
|
101 |
+
# ensure start position
|
102 |
+
# go back
|
103 |
+
fp.seek(0)
|
104 |
+
lengthfile = fsize
|
105 |
+
while lengthfile > 0:
|
106 |
+
s = fp.read(min(lengthfile, 100 * 1024))
|
107 |
+
if not s:
|
108 |
+
break
|
109 |
+
lengthfile -= len(s)
|
110 |
+
f.write(s)
|
111 |
+
|
112 |
+
device = "pngalpha" if transparency else "ppmraw"
|
113 |
+
|
114 |
+
# Build Ghostscript command
|
115 |
+
command = [
|
116 |
+
"gs",
|
117 |
+
"-q", # quiet mode
|
118 |
+
"-g%dx%d" % size, # set output geometry (pixels)
|
119 |
+
"-r%fx%f" % res, # set input DPI (dots per inch)
|
120 |
+
"-dBATCH", # exit after processing
|
121 |
+
"-dNOPAUSE", # don't pause between pages
|
122 |
+
"-dSAFER", # safe mode
|
123 |
+
f"-sDEVICE={device}",
|
124 |
+
f"-sOutputFile={outfile}", # output file
|
125 |
+
# adjust for image origin
|
126 |
+
"-c",
|
127 |
+
f"{-bbox[0]} {-bbox[1]} translate",
|
128 |
+
"-f",
|
129 |
+
infile, # input file
|
130 |
+
# showpage (see https://bugs.ghostscript.com/show_bug.cgi?id=698272)
|
131 |
+
"-c",
|
132 |
+
"showpage",
|
133 |
+
]
|
134 |
+
|
135 |
+
if gs_windows_binary is not None:
|
136 |
+
if not gs_windows_binary:
|
137 |
+
msg = "Unable to locate Ghostscript on paths"
|
138 |
+
raise OSError(msg)
|
139 |
+
command[0] = gs_windows_binary
|
140 |
+
|
141 |
+
# push data through Ghostscript
|
142 |
+
try:
|
143 |
+
startupinfo = None
|
144 |
+
if sys.platform.startswith("win"):
|
145 |
+
startupinfo = subprocess.STARTUPINFO()
|
146 |
+
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
|
147 |
+
subprocess.check_call(command, startupinfo=startupinfo)
|
148 |
+
out_im = Image.open(outfile)
|
149 |
+
out_im.load()
|
150 |
+
finally:
|
151 |
+
try:
|
152 |
+
os.unlink(outfile)
|
153 |
+
if infile_temp:
|
154 |
+
os.unlink(infile_temp)
|
155 |
+
except OSError:
|
156 |
+
pass
|
157 |
+
|
158 |
+
im = out_im.im.copy()
|
159 |
+
out_im.close()
|
160 |
+
return im
|
161 |
+
|
162 |
+
|
163 |
+
class PSFile:
|
164 |
+
"""
|
165 |
+
Wrapper for bytesio object that treats either CR or LF as end of line.
|
166 |
+
This class is no longer used internally, but kept for backwards compatibility.
|
167 |
+
"""
|
168 |
+
|
169 |
+
def __init__(self, fp):
|
170 |
+
deprecate(
|
171 |
+
"PSFile",
|
172 |
+
11,
|
173 |
+
action="If you need the functionality of this class "
|
174 |
+
"you will need to implement it yourself.",
|
175 |
+
)
|
176 |
+
self.fp = fp
|
177 |
+
self.char = None
|
178 |
+
|
179 |
+
def seek(self, offset, whence=io.SEEK_SET):
|
180 |
+
self.char = None
|
181 |
+
self.fp.seek(offset, whence)
|
182 |
+
|
183 |
+
def readline(self):
|
184 |
+
s = [self.char or b""]
|
185 |
+
self.char = None
|
186 |
+
|
187 |
+
c = self.fp.read(1)
|
188 |
+
while (c not in b"\r\n") and len(c):
|
189 |
+
s.append(c)
|
190 |
+
c = self.fp.read(1)
|
191 |
+
|
192 |
+
self.char = self.fp.read(1)
|
193 |
+
# line endings can be 1 or 2 of \r \n, in either order
|
194 |
+
if self.char in b"\r\n":
|
195 |
+
self.char = None
|
196 |
+
|
197 |
+
return b"".join(s).decode("latin-1")
|
198 |
+
|
199 |
+
|
200 |
+
def _accept(prefix):
|
201 |
+
return prefix[:4] == b"%!PS" or (len(prefix) >= 4 and i32(prefix) == 0xC6D3D0C5)
|
202 |
+
|
203 |
+
|
204 |
+
##
|
205 |
+
# Image plugin for Encapsulated PostScript. This plugin supports only
|
206 |
+
# a few variants of this format.
|
207 |
+
|
208 |
+
|
209 |
+
class EpsImageFile(ImageFile.ImageFile):
|
210 |
+
"""EPS File Parser for the Python Imaging Library"""
|
211 |
+
|
212 |
+
format = "EPS"
|
213 |
+
format_description = "Encapsulated Postscript"
|
214 |
+
|
215 |
+
mode_map = {1: "L", 2: "LAB", 3: "RGB", 4: "CMYK"}
|
216 |
+
|
217 |
+
def _open(self):
|
218 |
+
(length, offset) = self._find_offset(self.fp)
|
219 |
+
|
220 |
+
# go to offset - start of "%!PS"
|
221 |
+
self.fp.seek(offset)
|
222 |
+
|
223 |
+
self.mode = "RGB"
|
224 |
+
self._size = None
|
225 |
+
|
226 |
+
byte_arr = bytearray(255)
|
227 |
+
bytes_mv = memoryview(byte_arr)
|
228 |
+
bytes_read = 0
|
229 |
+
reading_comments = True
|
230 |
+
|
231 |
+
def check_required_header_comments():
|
232 |
+
if "PS-Adobe" not in self.info:
|
233 |
+
msg = 'EPS header missing "%!PS-Adobe" comment'
|
234 |
+
raise SyntaxError(msg)
|
235 |
+
if "BoundingBox" not in self.info:
|
236 |
+
msg = 'EPS header missing "%%BoundingBox" comment'
|
237 |
+
raise SyntaxError(msg)
|
238 |
+
|
239 |
+
while True:
|
240 |
+
byte = self.fp.read(1)
|
241 |
+
if byte == b"":
|
242 |
+
# if we didn't read a byte we must be at the end of the file
|
243 |
+
if bytes_read == 0:
|
244 |
+
break
|
245 |
+
elif byte in b"\r\n":
|
246 |
+
# if we read a line ending character, ignore it and parse what
|
247 |
+
# we have already read. if we haven't read any other characters,
|
248 |
+
# continue reading
|
249 |
+
if bytes_read == 0:
|
250 |
+
continue
|
251 |
+
else:
|
252 |
+
# ASCII/hexadecimal lines in an EPS file must not exceed
|
253 |
+
# 255 characters, not including line ending characters
|
254 |
+
if bytes_read >= 255:
|
255 |
+
# only enforce this for lines starting with a "%",
|
256 |
+
# otherwise assume it's binary data
|
257 |
+
if byte_arr[0] == ord("%"):
|
258 |
+
msg = "not an EPS file"
|
259 |
+
raise SyntaxError(msg)
|
260 |
+
else:
|
261 |
+
if reading_comments:
|
262 |
+
check_required_header_comments()
|
263 |
+
reading_comments = False
|
264 |
+
# reset bytes_read so we can keep reading
|
265 |
+
# data until the end of the line
|
266 |
+
bytes_read = 0
|
267 |
+
byte_arr[bytes_read] = byte[0]
|
268 |
+
bytes_read += 1
|
269 |
+
continue
|
270 |
+
|
271 |
+
if reading_comments:
|
272 |
+
# Load EPS header
|
273 |
+
|
274 |
+
# if this line doesn't start with a "%",
|
275 |
+
# or does start with "%%EndComments",
|
276 |
+
# then we've reached the end of the header/comments
|
277 |
+
if byte_arr[0] != ord("%") or bytes_mv[:13] == b"%%EndComments":
|
278 |
+
check_required_header_comments()
|
279 |
+
reading_comments = False
|
280 |
+
continue
|
281 |
+
|
282 |
+
s = str(bytes_mv[:bytes_read], "latin-1")
|
283 |
+
|
284 |
+
try:
|
285 |
+
m = split.match(s)
|
286 |
+
except re.error as e:
|
287 |
+
msg = "not an EPS file"
|
288 |
+
raise SyntaxError(msg) from e
|
289 |
+
|
290 |
+
if m:
|
291 |
+
k, v = m.group(1, 2)
|
292 |
+
self.info[k] = v
|
293 |
+
if k == "BoundingBox":
|
294 |
+
try:
|
295 |
+
# Note: The DSC spec says that BoundingBox
|
296 |
+
# fields should be integers, but some drivers
|
297 |
+
# put floating point values there anyway.
|
298 |
+
box = [int(float(i)) for i in v.split()]
|
299 |
+
self._size = box[2] - box[0], box[3] - box[1]
|
300 |
+
self.tile = [
|
301 |
+
("eps", (0, 0) + self.size, offset, (length, box))
|
302 |
+
]
|
303 |
+
except Exception:
|
304 |
+
pass
|
305 |
+
else:
|
306 |
+
m = field.match(s)
|
307 |
+
if m:
|
308 |
+
k = m.group(1)
|
309 |
+
if k[:8] == "PS-Adobe":
|
310 |
+
self.info["PS-Adobe"] = k[9:]
|
311 |
+
else:
|
312 |
+
self.info[k] = ""
|
313 |
+
elif s[0] == "%":
|
314 |
+
# handle non-DSC PostScript comments that some
|
315 |
+
# tools mistakenly put in the Comments section
|
316 |
+
pass
|
317 |
+
else:
|
318 |
+
msg = "bad EPS header"
|
319 |
+
raise OSError(msg)
|
320 |
+
elif bytes_mv[:11] == b"%ImageData:":
|
321 |
+
# Check for an "ImageData" descriptor
|
322 |
+
# https://www.adobe.com/devnet-apps/photoshop/fileformatashtml/#50577413_pgfId-1035096
|
323 |
+
|
324 |
+
# Values:
|
325 |
+
# columns
|
326 |
+
# rows
|
327 |
+
# bit depth (1 or 8)
|
328 |
+
# mode (1: L, 2: LAB, 3: RGB, 4: CMYK)
|
329 |
+
# number of padding channels
|
330 |
+
# block size (number of bytes per row per channel)
|
331 |
+
# binary/ascii (1: binary, 2: ascii)
|
332 |
+
# data start identifier (the image data follows after a single line
|
333 |
+
# consisting only of this quoted value)
|
334 |
+
image_data_values = byte_arr[11:bytes_read].split(None, 7)
|
335 |
+
columns, rows, bit_depth, mode_id = [
|
336 |
+
int(value) for value in image_data_values[:4]
|
337 |
+
]
|
338 |
+
|
339 |
+
if bit_depth == 1:
|
340 |
+
self.mode = "1"
|
341 |
+
elif bit_depth == 8:
|
342 |
+
try:
|
343 |
+
self.mode = self.mode_map[mode_id]
|
344 |
+
except ValueError:
|
345 |
+
break
|
346 |
+
else:
|
347 |
+
break
|
348 |
+
|
349 |
+
self._size = columns, rows
|
350 |
+
return
|
351 |
+
|
352 |
+
bytes_read = 0
|
353 |
+
|
354 |
+
check_required_header_comments()
|
355 |
+
|
356 |
+
if not self._size:
|
357 |
+
self._size = 1, 1 # errors if this isn't set. why (1,1)?
|
358 |
+
msg = "cannot determine EPS bounding box"
|
359 |
+
raise OSError(msg)
|
360 |
+
|
361 |
+
def _find_offset(self, fp):
|
362 |
+
s = fp.read(4)
|
363 |
+
|
364 |
+
if s == b"%!PS":
|
365 |
+
# for HEAD without binary preview
|
366 |
+
fp.seek(0, io.SEEK_END)
|
367 |
+
length = fp.tell()
|
368 |
+
offset = 0
|
369 |
+
elif i32(s) == 0xC6D3D0C5:
|
370 |
+
# FIX for: Some EPS file not handled correctly / issue #302
|
371 |
+
# EPS can contain binary data
|
372 |
+
# or start directly with latin coding
|
373 |
+
# more info see:
|
374 |
+
# https://web.archive.org/web/20160528181353/http://partners.adobe.com/public/developer/en/ps/5002.EPSF_Spec.pdf
|
375 |
+
s = fp.read(8)
|
376 |
+
offset = i32(s)
|
377 |
+
length = i32(s, 4)
|
378 |
+
else:
|
379 |
+
msg = "not an EPS file"
|
380 |
+
raise SyntaxError(msg)
|
381 |
+
|
382 |
+
return length, offset
|
383 |
+
|
384 |
+
def load(self, scale=1, transparency=False):
|
385 |
+
# Load EPS via Ghostscript
|
386 |
+
if self.tile:
|
387 |
+
self.im = Ghostscript(self.tile, self.size, self.fp, scale, transparency)
|
388 |
+
self.mode = self.im.mode
|
389 |
+
self._size = self.im.size
|
390 |
+
self.tile = []
|
391 |
+
return Image.Image.load(self)
|
392 |
+
|
393 |
+
def load_seek(self, *args, **kwargs):
|
394 |
+
# we can't incrementally load, so force ImageFile.parser to
|
395 |
+
# use our custom load method by defining this method.
|
396 |
+
pass
|
397 |
+
|
398 |
+
|
399 |
+
# --------------------------------------------------------------------
|
400 |
+
|
401 |
+
|
402 |
+
def _save(im, fp, filename, eps=1):
|
403 |
+
"""EPS Writer for the Python Imaging Library."""
|
404 |
+
|
405 |
+
# make sure image data is available
|
406 |
+
im.load()
|
407 |
+
|
408 |
+
# determine PostScript image mode
|
409 |
+
if im.mode == "L":
|
410 |
+
operator = (8, 1, b"image")
|
411 |
+
elif im.mode == "RGB":
|
412 |
+
operator = (8, 3, b"false 3 colorimage")
|
413 |
+
elif im.mode == "CMYK":
|
414 |
+
operator = (8, 4, b"false 4 colorimage")
|
415 |
+
else:
|
416 |
+
msg = "image mode is not supported"
|
417 |
+
raise ValueError(msg)
|
418 |
+
|
419 |
+
if eps:
|
420 |
+
# write EPS header
|
421 |
+
fp.write(b"%!PS-Adobe-3.0 EPSF-3.0\n")
|
422 |
+
fp.write(b"%%Creator: PIL 0.1 EpsEncode\n")
|
423 |
+
# fp.write("%%CreationDate: %s"...)
|
424 |
+
fp.write(b"%%%%BoundingBox: 0 0 %d %d\n" % im.size)
|
425 |
+
fp.write(b"%%Pages: 1\n")
|
426 |
+
fp.write(b"%%EndComments\n")
|
427 |
+
fp.write(b"%%Page: 1 1\n")
|
428 |
+
fp.write(b"%%ImageData: %d %d " % im.size)
|
429 |
+
fp.write(b'%d %d 0 1 1 "%s"\n' % operator)
|
430 |
+
|
431 |
+
# image header
|
432 |
+
fp.write(b"gsave\n")
|
433 |
+
fp.write(b"10 dict begin\n")
|
434 |
+
fp.write(b"/buf %d string def\n" % (im.size[0] * operator[1]))
|
435 |
+
fp.write(b"%d %d scale\n" % im.size)
|
436 |
+
fp.write(b"%d %d 8\n" % im.size) # <= bits
|
437 |
+
fp.write(b"[%d 0 0 -%d 0 %d]\n" % (im.size[0], im.size[1], im.size[1]))
|
438 |
+
fp.write(b"{ currentfile buf readhexstring pop } bind\n")
|
439 |
+
fp.write(operator[2] + b"\n")
|
440 |
+
if hasattr(fp, "flush"):
|
441 |
+
fp.flush()
|
442 |
+
|
443 |
+
ImageFile._save(im, fp, [("eps", (0, 0) + im.size, 0, None)])
|
444 |
+
|
445 |
+
fp.write(b"\n%%%%EndBinary\n")
|
446 |
+
fp.write(b"grestore end\n")
|
447 |
+
if hasattr(fp, "flush"):
|
448 |
+
fp.flush()
|
449 |
+
|
450 |
+
|
451 |
+
# --------------------------------------------------------------------
|
452 |
+
|
453 |
+
|
454 |
+
Image.register_open(EpsImageFile.format, EpsImageFile, _accept)
|
455 |
+
|
456 |
+
Image.register_save(EpsImageFile.format, _save)
|
457 |
+
|
458 |
+
Image.register_extensions(EpsImageFile.format, [".ps", ".eps"])
|
459 |
+
|
460 |
+
Image.register_mime(EpsImageFile.format, "application/postscript")
|
Lib/site-packages/PIL/ExifTags.py
ADDED
@@ -0,0 +1,380 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#
|
2 |
+
# The Python Imaging Library.
|
3 |
+
# $Id$
|
4 |
+
#
|
5 |
+
# EXIF tags
|
6 |
+
#
|
7 |
+
# Copyright (c) 2003 by Secret Labs AB
|
8 |
+
#
|
9 |
+
# See the README file for information on usage and redistribution.
|
10 |
+
#
|
11 |
+
|
12 |
+
"""
|
13 |
+
This module provides constants and clear-text names for various
|
14 |
+
well-known EXIF tags.
|
15 |
+
"""
|
16 |
+
|
17 |
+
from enum import IntEnum
|
18 |
+
|
19 |
+
|
20 |
+
class Base(IntEnum):
|
21 |
+
# possibly incomplete
|
22 |
+
InteropIndex = 0x0001
|
23 |
+
ProcessingSoftware = 0x000B
|
24 |
+
NewSubfileType = 0x00FE
|
25 |
+
SubfileType = 0x00FF
|
26 |
+
ImageWidth = 0x0100
|
27 |
+
ImageLength = 0x0101
|
28 |
+
BitsPerSample = 0x0102
|
29 |
+
Compression = 0x0103
|
30 |
+
PhotometricInterpretation = 0x0106
|
31 |
+
Thresholding = 0x0107
|
32 |
+
CellWidth = 0x0108
|
33 |
+
CellLength = 0x0109
|
34 |
+
FillOrder = 0x010A
|
35 |
+
DocumentName = 0x010D
|
36 |
+
ImageDescription = 0x010E
|
37 |
+
Make = 0x010F
|
38 |
+
Model = 0x0110
|
39 |
+
StripOffsets = 0x0111
|
40 |
+
Orientation = 0x0112
|
41 |
+
SamplesPerPixel = 0x0115
|
42 |
+
RowsPerStrip = 0x0116
|
43 |
+
StripByteCounts = 0x0117
|
44 |
+
MinSampleValue = 0x0118
|
45 |
+
MaxSampleValue = 0x0119
|
46 |
+
XResolution = 0x011A
|
47 |
+
YResolution = 0x011B
|
48 |
+
PlanarConfiguration = 0x011C
|
49 |
+
PageName = 0x011D
|
50 |
+
FreeOffsets = 0x0120
|
51 |
+
FreeByteCounts = 0x0121
|
52 |
+
GrayResponseUnit = 0x0122
|
53 |
+
GrayResponseCurve = 0x0123
|
54 |
+
T4Options = 0x0124
|
55 |
+
T6Options = 0x0125
|
56 |
+
ResolutionUnit = 0x0128
|
57 |
+
PageNumber = 0x0129
|
58 |
+
TransferFunction = 0x012D
|
59 |
+
Software = 0x0131
|
60 |
+
DateTime = 0x0132
|
61 |
+
Artist = 0x013B
|
62 |
+
HostComputer = 0x013C
|
63 |
+
Predictor = 0x013D
|
64 |
+
WhitePoint = 0x013E
|
65 |
+
PrimaryChromaticities = 0x013F
|
66 |
+
ColorMap = 0x0140
|
67 |
+
HalftoneHints = 0x0141
|
68 |
+
TileWidth = 0x0142
|
69 |
+
TileLength = 0x0143
|
70 |
+
TileOffsets = 0x0144
|
71 |
+
TileByteCounts = 0x0145
|
72 |
+
SubIFDs = 0x014A
|
73 |
+
InkSet = 0x014C
|
74 |
+
InkNames = 0x014D
|
75 |
+
NumberOfInks = 0x014E
|
76 |
+
DotRange = 0x0150
|
77 |
+
TargetPrinter = 0x0151
|
78 |
+
ExtraSamples = 0x0152
|
79 |
+
SampleFormat = 0x0153
|
80 |
+
SMinSampleValue = 0x0154
|
81 |
+
SMaxSampleValue = 0x0155
|
82 |
+
TransferRange = 0x0156
|
83 |
+
ClipPath = 0x0157
|
84 |
+
XClipPathUnits = 0x0158
|
85 |
+
YClipPathUnits = 0x0159
|
86 |
+
Indexed = 0x015A
|
87 |
+
JPEGTables = 0x015B
|
88 |
+
OPIProxy = 0x015F
|
89 |
+
JPEGProc = 0x0200
|
90 |
+
JpegIFOffset = 0x0201
|
91 |
+
JpegIFByteCount = 0x0202
|
92 |
+
JpegRestartInterval = 0x0203
|
93 |
+
JpegLosslessPredictors = 0x0205
|
94 |
+
JpegPointTransforms = 0x0206
|
95 |
+
JpegQTables = 0x0207
|
96 |
+
JpegDCTables = 0x0208
|
97 |
+
JpegACTables = 0x0209
|
98 |
+
YCbCrCoefficients = 0x0211
|
99 |
+
YCbCrSubSampling = 0x0212
|
100 |
+
YCbCrPositioning = 0x0213
|
101 |
+
ReferenceBlackWhite = 0x0214
|
102 |
+
XMLPacket = 0x02BC
|
103 |
+
RelatedImageFileFormat = 0x1000
|
104 |
+
RelatedImageWidth = 0x1001
|
105 |
+
RelatedImageLength = 0x1002
|
106 |
+
Rating = 0x4746
|
107 |
+
RatingPercent = 0x4749
|
108 |
+
ImageID = 0x800D
|
109 |
+
CFARepeatPatternDim = 0x828D
|
110 |
+
BatteryLevel = 0x828F
|
111 |
+
Copyright = 0x8298
|
112 |
+
ExposureTime = 0x829A
|
113 |
+
FNumber = 0x829D
|
114 |
+
IPTCNAA = 0x83BB
|
115 |
+
ImageResources = 0x8649
|
116 |
+
ExifOffset = 0x8769
|
117 |
+
InterColorProfile = 0x8773
|
118 |
+
ExposureProgram = 0x8822
|
119 |
+
SpectralSensitivity = 0x8824
|
120 |
+
GPSInfo = 0x8825
|
121 |
+
ISOSpeedRatings = 0x8827
|
122 |
+
OECF = 0x8828
|
123 |
+
Interlace = 0x8829
|
124 |
+
TimeZoneOffset = 0x882A
|
125 |
+
SelfTimerMode = 0x882B
|
126 |
+
SensitivityType = 0x8830
|
127 |
+
StandardOutputSensitivity = 0x8831
|
128 |
+
RecommendedExposureIndex = 0x8832
|
129 |
+
ISOSpeed = 0x8833
|
130 |
+
ISOSpeedLatitudeyyy = 0x8834
|
131 |
+
ISOSpeedLatitudezzz = 0x8835
|
132 |
+
ExifVersion = 0x9000
|
133 |
+
DateTimeOriginal = 0x9003
|
134 |
+
DateTimeDigitized = 0x9004
|
135 |
+
OffsetTime = 0x9010
|
136 |
+
OffsetTimeOriginal = 0x9011
|
137 |
+
OffsetTimeDigitized = 0x9012
|
138 |
+
ComponentsConfiguration = 0x9101
|
139 |
+
CompressedBitsPerPixel = 0x9102
|
140 |
+
ShutterSpeedValue = 0x9201
|
141 |
+
ApertureValue = 0x9202
|
142 |
+
BrightnessValue = 0x9203
|
143 |
+
ExposureBiasValue = 0x9204
|
144 |
+
MaxApertureValue = 0x9205
|
145 |
+
SubjectDistance = 0x9206
|
146 |
+
MeteringMode = 0x9207
|
147 |
+
LightSource = 0x9208
|
148 |
+
Flash = 0x9209
|
149 |
+
FocalLength = 0x920A
|
150 |
+
Noise = 0x920D
|
151 |
+
ImageNumber = 0x9211
|
152 |
+
SecurityClassification = 0x9212
|
153 |
+
ImageHistory = 0x9213
|
154 |
+
TIFFEPStandardID = 0x9216
|
155 |
+
MakerNote = 0x927C
|
156 |
+
UserComment = 0x9286
|
157 |
+
SubsecTime = 0x9290
|
158 |
+
SubsecTimeOriginal = 0x9291
|
159 |
+
SubsecTimeDigitized = 0x9292
|
160 |
+
AmbientTemperature = 0x9400
|
161 |
+
Humidity = 0x9401
|
162 |
+
Pressure = 0x9402
|
163 |
+
WaterDepth = 0x9403
|
164 |
+
Acceleration = 0x9404
|
165 |
+
CameraElevationAngle = 0x9405
|
166 |
+
XPTitle = 0x9C9B
|
167 |
+
XPComment = 0x9C9C
|
168 |
+
XPAuthor = 0x9C9D
|
169 |
+
XPKeywords = 0x9C9E
|
170 |
+
XPSubject = 0x9C9F
|
171 |
+
FlashPixVersion = 0xA000
|
172 |
+
ColorSpace = 0xA001
|
173 |
+
ExifImageWidth = 0xA002
|
174 |
+
ExifImageHeight = 0xA003
|
175 |
+
RelatedSoundFile = 0xA004
|
176 |
+
ExifInteroperabilityOffset = 0xA005
|
177 |
+
FlashEnergy = 0xA20B
|
178 |
+
SpatialFrequencyResponse = 0xA20C
|
179 |
+
FocalPlaneXResolution = 0xA20E
|
180 |
+
FocalPlaneYResolution = 0xA20F
|
181 |
+
FocalPlaneResolutionUnit = 0xA210
|
182 |
+
SubjectLocation = 0xA214
|
183 |
+
ExposureIndex = 0xA215
|
184 |
+
SensingMethod = 0xA217
|
185 |
+
FileSource = 0xA300
|
186 |
+
SceneType = 0xA301
|
187 |
+
CFAPattern = 0xA302
|
188 |
+
CustomRendered = 0xA401
|
189 |
+
ExposureMode = 0xA402
|
190 |
+
WhiteBalance = 0xA403
|
191 |
+
DigitalZoomRatio = 0xA404
|
192 |
+
FocalLengthIn35mmFilm = 0xA405
|
193 |
+
SceneCaptureType = 0xA406
|
194 |
+
GainControl = 0xA407
|
195 |
+
Contrast = 0xA408
|
196 |
+
Saturation = 0xA409
|
197 |
+
Sharpness = 0xA40A
|
198 |
+
DeviceSettingDescription = 0xA40B
|
199 |
+
SubjectDistanceRange = 0xA40C
|
200 |
+
ImageUniqueID = 0xA420
|
201 |
+
CameraOwnerName = 0xA430
|
202 |
+
BodySerialNumber = 0xA431
|
203 |
+
LensSpecification = 0xA432
|
204 |
+
LensMake = 0xA433
|
205 |
+
LensModel = 0xA434
|
206 |
+
LensSerialNumber = 0xA435
|
207 |
+
CompositeImage = 0xA460
|
208 |
+
CompositeImageCount = 0xA461
|
209 |
+
CompositeImageExposureTimes = 0xA462
|
210 |
+
Gamma = 0xA500
|
211 |
+
PrintImageMatching = 0xC4A5
|
212 |
+
DNGVersion = 0xC612
|
213 |
+
DNGBackwardVersion = 0xC613
|
214 |
+
UniqueCameraModel = 0xC614
|
215 |
+
LocalizedCameraModel = 0xC615
|
216 |
+
CFAPlaneColor = 0xC616
|
217 |
+
CFALayout = 0xC617
|
218 |
+
LinearizationTable = 0xC618
|
219 |
+
BlackLevelRepeatDim = 0xC619
|
220 |
+
BlackLevel = 0xC61A
|
221 |
+
BlackLevelDeltaH = 0xC61B
|
222 |
+
BlackLevelDeltaV = 0xC61C
|
223 |
+
WhiteLevel = 0xC61D
|
224 |
+
DefaultScale = 0xC61E
|
225 |
+
DefaultCropOrigin = 0xC61F
|
226 |
+
DefaultCropSize = 0xC620
|
227 |
+
ColorMatrix1 = 0xC621
|
228 |
+
ColorMatrix2 = 0xC622
|
229 |
+
CameraCalibration1 = 0xC623
|
230 |
+
CameraCalibration2 = 0xC624
|
231 |
+
ReductionMatrix1 = 0xC625
|
232 |
+
ReductionMatrix2 = 0xC626
|
233 |
+
AnalogBalance = 0xC627
|
234 |
+
AsShotNeutral = 0xC628
|
235 |
+
AsShotWhiteXY = 0xC629
|
236 |
+
BaselineExposure = 0xC62A
|
237 |
+
BaselineNoise = 0xC62B
|
238 |
+
BaselineSharpness = 0xC62C
|
239 |
+
BayerGreenSplit = 0xC62D
|
240 |
+
LinearResponseLimit = 0xC62E
|
241 |
+
CameraSerialNumber = 0xC62F
|
242 |
+
LensInfo = 0xC630
|
243 |
+
ChromaBlurRadius = 0xC631
|
244 |
+
AntiAliasStrength = 0xC632
|
245 |
+
ShadowScale = 0xC633
|
246 |
+
DNGPrivateData = 0xC634
|
247 |
+
MakerNoteSafety = 0xC635
|
248 |
+
CalibrationIlluminant1 = 0xC65A
|
249 |
+
CalibrationIlluminant2 = 0xC65B
|
250 |
+
BestQualityScale = 0xC65C
|
251 |
+
RawDataUniqueID = 0xC65D
|
252 |
+
OriginalRawFileName = 0xC68B
|
253 |
+
OriginalRawFileData = 0xC68C
|
254 |
+
ActiveArea = 0xC68D
|
255 |
+
MaskedAreas = 0xC68E
|
256 |
+
AsShotICCProfile = 0xC68F
|
257 |
+
AsShotPreProfileMatrix = 0xC690
|
258 |
+
CurrentICCProfile = 0xC691
|
259 |
+
CurrentPreProfileMatrix = 0xC692
|
260 |
+
ColorimetricReference = 0xC6BF
|
261 |
+
CameraCalibrationSignature = 0xC6F3
|
262 |
+
ProfileCalibrationSignature = 0xC6F4
|
263 |
+
AsShotProfileName = 0xC6F6
|
264 |
+
NoiseReductionApplied = 0xC6F7
|
265 |
+
ProfileName = 0xC6F8
|
266 |
+
ProfileHueSatMapDims = 0xC6F9
|
267 |
+
ProfileHueSatMapData1 = 0xC6FA
|
268 |
+
ProfileHueSatMapData2 = 0xC6FB
|
269 |
+
ProfileToneCurve = 0xC6FC
|
270 |
+
ProfileEmbedPolicy = 0xC6FD
|
271 |
+
ProfileCopyright = 0xC6FE
|
272 |
+
ForwardMatrix1 = 0xC714
|
273 |
+
ForwardMatrix2 = 0xC715
|
274 |
+
PreviewApplicationName = 0xC716
|
275 |
+
PreviewApplicationVersion = 0xC717
|
276 |
+
PreviewSettingsName = 0xC718
|
277 |
+
PreviewSettingsDigest = 0xC719
|
278 |
+
PreviewColorSpace = 0xC71A
|
279 |
+
PreviewDateTime = 0xC71B
|
280 |
+
RawImageDigest = 0xC71C
|
281 |
+
OriginalRawFileDigest = 0xC71D
|
282 |
+
SubTileBlockSize = 0xC71E
|
283 |
+
RowInterleaveFactor = 0xC71F
|
284 |
+
ProfileLookTableDims = 0xC725
|
285 |
+
ProfileLookTableData = 0xC726
|
286 |
+
OpcodeList1 = 0xC740
|
287 |
+
OpcodeList2 = 0xC741
|
288 |
+
OpcodeList3 = 0xC74E
|
289 |
+
NoiseProfile = 0xC761
|
290 |
+
|
291 |
+
|
292 |
+
"""Maps EXIF tags to tag names."""
|
293 |
+
TAGS = {
|
294 |
+
**{i.value: i.name for i in Base},
|
295 |
+
0x920C: "SpatialFrequencyResponse",
|
296 |
+
0x9214: "SubjectLocation",
|
297 |
+
0x9215: "ExposureIndex",
|
298 |
+
0x828E: "CFAPattern",
|
299 |
+
0x920B: "FlashEnergy",
|
300 |
+
0x9216: "TIFF/EPStandardID",
|
301 |
+
}
|
302 |
+
|
303 |
+
|
304 |
+
class GPS(IntEnum):
|
305 |
+
GPSVersionID = 0
|
306 |
+
GPSLatitudeRef = 1
|
307 |
+
GPSLatitude = 2
|
308 |
+
GPSLongitudeRef = 3
|
309 |
+
GPSLongitude = 4
|
310 |
+
GPSAltitudeRef = 5
|
311 |
+
GPSAltitude = 6
|
312 |
+
GPSTimeStamp = 7
|
313 |
+
GPSSatellites = 8
|
314 |
+
GPSStatus = 9
|
315 |
+
GPSMeasureMode = 10
|
316 |
+
GPSDOP = 11
|
317 |
+
GPSSpeedRef = 12
|
318 |
+
GPSSpeed = 13
|
319 |
+
GPSTrackRef = 14
|
320 |
+
GPSTrack = 15
|
321 |
+
GPSImgDirectionRef = 16
|
322 |
+
GPSImgDirection = 17
|
323 |
+
GPSMapDatum = 18
|
324 |
+
GPSDestLatitudeRef = 19
|
325 |
+
GPSDestLatitude = 20
|
326 |
+
GPSDestLongitudeRef = 21
|
327 |
+
GPSDestLongitude = 22
|
328 |
+
GPSDestBearingRef = 23
|
329 |
+
GPSDestBearing = 24
|
330 |
+
GPSDestDistanceRef = 25
|
331 |
+
GPSDestDistance = 26
|
332 |
+
GPSProcessingMethod = 27
|
333 |
+
GPSAreaInformation = 28
|
334 |
+
GPSDateStamp = 29
|
335 |
+
GPSDifferential = 30
|
336 |
+
GPSHPositioningError = 31
|
337 |
+
|
338 |
+
|
339 |
+
"""Maps EXIF GPS tags to tag names."""
|
340 |
+
GPSTAGS = {i.value: i.name for i in GPS}
|
341 |
+
|
342 |
+
|
343 |
+
class Interop(IntEnum):
|
344 |
+
InteropIndex = 1
|
345 |
+
InteropVersion = 2
|
346 |
+
RelatedImageFileFormat = 4096
|
347 |
+
RelatedImageWidth = 4097
|
348 |
+
RleatedImageHeight = 4098
|
349 |
+
|
350 |
+
|
351 |
+
class IFD(IntEnum):
|
352 |
+
Exif = 34665
|
353 |
+
GPSInfo = 34853
|
354 |
+
Makernote = 37500
|
355 |
+
Interop = 40965
|
356 |
+
IFD1 = -1
|
357 |
+
|
358 |
+
|
359 |
+
class LightSource(IntEnum):
|
360 |
+
Unknown = 0
|
361 |
+
Daylight = 1
|
362 |
+
Fluorescent = 2
|
363 |
+
Tungsten = 3
|
364 |
+
Flash = 4
|
365 |
+
Fine = 9
|
366 |
+
Cloudy = 10
|
367 |
+
Shade = 11
|
368 |
+
DaylightFluorescent = 12
|
369 |
+
DayWhiteFluorescent = 13
|
370 |
+
CoolWhiteFluorescent = 14
|
371 |
+
WhiteFluorescent = 15
|
372 |
+
StandardLightA = 17
|
373 |
+
StandardLightB = 18
|
374 |
+
StandardLightC = 19
|
375 |
+
D55 = 20
|
376 |
+
D65 = 21
|
377 |
+
D75 = 22
|
378 |
+
D50 = 23
|
379 |
+
ISO = 24
|
380 |
+
Other = 255
|
Lib/site-packages/PIL/FitsImagePlugin.py
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#
|
2 |
+
# The Python Imaging Library
|
3 |
+
# $Id$
|
4 |
+
#
|
5 |
+
# FITS file handling
|
6 |
+
#
|
7 |
+
# Copyright (c) 1998-2003 by Fredrik Lundh
|
8 |
+
#
|
9 |
+
# See the README file for information on usage and redistribution.
|
10 |
+
#
|
11 |
+
|
12 |
+
import math
|
13 |
+
|
14 |
+
from . import Image, ImageFile
|
15 |
+
|
16 |
+
|
17 |
+
def _accept(prefix):
|
18 |
+
return prefix[:6] == b"SIMPLE"
|
19 |
+
|
20 |
+
|
21 |
+
class FitsImageFile(ImageFile.ImageFile):
|
22 |
+
format = "FITS"
|
23 |
+
format_description = "FITS"
|
24 |
+
|
25 |
+
def _open(self):
|
26 |
+
headers = {}
|
27 |
+
while True:
|
28 |
+
header = self.fp.read(80)
|
29 |
+
if not header:
|
30 |
+
msg = "Truncated FITS file"
|
31 |
+
raise OSError(msg)
|
32 |
+
keyword = header[:8].strip()
|
33 |
+
if keyword == b"END":
|
34 |
+
break
|
35 |
+
value = header[8:].split(b"/")[0].strip()
|
36 |
+
if value.startswith(b"="):
|
37 |
+
value = value[1:].strip()
|
38 |
+
if not headers and (not _accept(keyword) or value != b"T"):
|
39 |
+
msg = "Not a FITS file"
|
40 |
+
raise SyntaxError(msg)
|
41 |
+
headers[keyword] = value
|
42 |
+
|
43 |
+
naxis = int(headers[b"NAXIS"])
|
44 |
+
if naxis == 0:
|
45 |
+
msg = "No image data"
|
46 |
+
raise ValueError(msg)
|
47 |
+
elif naxis == 1:
|
48 |
+
self._size = 1, int(headers[b"NAXIS1"])
|
49 |
+
else:
|
50 |
+
self._size = int(headers[b"NAXIS1"]), int(headers[b"NAXIS2"])
|
51 |
+
|
52 |
+
number_of_bits = int(headers[b"BITPIX"])
|
53 |
+
if number_of_bits == 8:
|
54 |
+
self.mode = "L"
|
55 |
+
elif number_of_bits == 16:
|
56 |
+
self.mode = "I"
|
57 |
+
# rawmode = "I;16S"
|
58 |
+
elif number_of_bits == 32:
|
59 |
+
self.mode = "I"
|
60 |
+
elif number_of_bits in (-32, -64):
|
61 |
+
self.mode = "F"
|
62 |
+
# rawmode = "F" if number_of_bits == -32 else "F;64F"
|
63 |
+
|
64 |
+
offset = math.ceil(self.fp.tell() / 2880) * 2880
|
65 |
+
self.tile = [("raw", (0, 0) + self.size, offset, (self.mode, 0, -1))]
|
66 |
+
|
67 |
+
|
68 |
+
# --------------------------------------------------------------------
|
69 |
+
# Registry
|
70 |
+
|
71 |
+
Image.register_open(FitsImageFile.format, FitsImageFile, _accept)
|
72 |
+
|
73 |
+
Image.register_extensions(FitsImageFile.format, [".fit", ".fits"])
|
Lib/site-packages/PIL/FitsStubImagePlugin.py
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#
|
2 |
+
# The Python Imaging Library
|
3 |
+
# $Id$
|
4 |
+
#
|
5 |
+
# FITS stub adapter
|
6 |
+
#
|
7 |
+
# Copyright (c) 1998-2003 by Fredrik Lundh
|
8 |
+
#
|
9 |
+
# See the README file for information on usage and redistribution.
|
10 |
+
#
|
11 |
+
|
12 |
+
from . import FitsImagePlugin, Image, ImageFile
|
13 |
+
from ._deprecate import deprecate
|
14 |
+
|
15 |
+
_handler = None
|
16 |
+
|
17 |
+
|
18 |
+
def register_handler(handler):
|
19 |
+
"""
|
20 |
+
Install application-specific FITS image handler.
|
21 |
+
|
22 |
+
:param handler: Handler object.
|
23 |
+
"""
|
24 |
+
global _handler
|
25 |
+
_handler = handler
|
26 |
+
|
27 |
+
deprecate(
|
28 |
+
"FitsStubImagePlugin",
|
29 |
+
10,
|
30 |
+
action="FITS images can now be read without "
|
31 |
+
"a handler through FitsImagePlugin instead",
|
32 |
+
)
|
33 |
+
|
34 |
+
# Override FitsImagePlugin with this handler
|
35 |
+
# for backwards compatibility
|
36 |
+
try:
|
37 |
+
Image.ID.remove(FITSStubImageFile.format)
|
38 |
+
except ValueError:
|
39 |
+
pass
|
40 |
+
|
41 |
+
Image.register_open(
|
42 |
+
FITSStubImageFile.format, FITSStubImageFile, FitsImagePlugin._accept
|
43 |
+
)
|
44 |
+
|
45 |
+
|
46 |
+
class FITSStubImageFile(ImageFile.StubImageFile):
|
47 |
+
format = FitsImagePlugin.FitsImageFile.format
|
48 |
+
format_description = FitsImagePlugin.FitsImageFile.format_description
|
49 |
+
|
50 |
+
def _open(self):
|
51 |
+
offset = self.fp.tell()
|
52 |
+
|
53 |
+
im = FitsImagePlugin.FitsImageFile(self.fp)
|
54 |
+
self._size = im.size
|
55 |
+
self.mode = im.mode
|
56 |
+
self.tile = []
|
57 |
+
|
58 |
+
self.fp.seek(offset)
|
59 |
+
|
60 |
+
loader = self._load()
|
61 |
+
if loader:
|
62 |
+
loader.open(self)
|
63 |
+
|
64 |
+
def _load(self):
|
65 |
+
return _handler
|
66 |
+
|
67 |
+
|
68 |
+
def _save(im, fp, filename):
|
69 |
+
msg = "FITS save handler not installed"
|
70 |
+
raise OSError(msg)
|
71 |
+
|
72 |
+
|
73 |
+
# --------------------------------------------------------------------
|
74 |
+
# Registry
|
75 |
+
|
76 |
+
Image.register_save(FITSStubImageFile.format, _save)
|
Lib/site-packages/PIL/FliImagePlugin.py
ADDED
@@ -0,0 +1,171 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#
|
2 |
+
# The Python Imaging Library.
|
3 |
+
# $Id$
|
4 |
+
#
|
5 |
+
# FLI/FLC file handling.
|
6 |
+
#
|
7 |
+
# History:
|
8 |
+
# 95-09-01 fl Created
|
9 |
+
# 97-01-03 fl Fixed parser, setup decoder tile
|
10 |
+
# 98-07-15 fl Renamed offset attribute to avoid name clash
|
11 |
+
#
|
12 |
+
# Copyright (c) Secret Labs AB 1997-98.
|
13 |
+
# Copyright (c) Fredrik Lundh 1995-97.
|
14 |
+
#
|
15 |
+
# See the README file for information on usage and redistribution.
|
16 |
+
#
|
17 |
+
|
18 |
+
import os
|
19 |
+
|
20 |
+
from . import Image, ImageFile, ImagePalette
|
21 |
+
from ._binary import i16le as i16
|
22 |
+
from ._binary import i32le as i32
|
23 |
+
from ._binary import o8
|
24 |
+
|
25 |
+
#
|
26 |
+
# decoder
|
27 |
+
|
28 |
+
|
29 |
+
def _accept(prefix):
|
30 |
+
return (
|
31 |
+
len(prefix) >= 6
|
32 |
+
and i16(prefix, 4) in [0xAF11, 0xAF12]
|
33 |
+
and i16(prefix, 14) in [0, 3] # flags
|
34 |
+
)
|
35 |
+
|
36 |
+
|
37 |
+
##
|
38 |
+
# Image plugin for the FLI/FLC animation format. Use the <b>seek</b>
|
39 |
+
# method to load individual frames.
|
40 |
+
|
41 |
+
|
42 |
+
class FliImageFile(ImageFile.ImageFile):
|
43 |
+
format = "FLI"
|
44 |
+
format_description = "Autodesk FLI/FLC Animation"
|
45 |
+
_close_exclusive_fp_after_loading = False
|
46 |
+
|
47 |
+
def _open(self):
|
48 |
+
# HEAD
|
49 |
+
s = self.fp.read(128)
|
50 |
+
if not (_accept(s) and s[20:22] == b"\x00\x00"):
|
51 |
+
msg = "not an FLI/FLC file"
|
52 |
+
raise SyntaxError(msg)
|
53 |
+
|
54 |
+
# frames
|
55 |
+
self.n_frames = i16(s, 6)
|
56 |
+
self.is_animated = self.n_frames > 1
|
57 |
+
|
58 |
+
# image characteristics
|
59 |
+
self.mode = "P"
|
60 |
+
self._size = i16(s, 8), i16(s, 10)
|
61 |
+
|
62 |
+
# animation speed
|
63 |
+
duration = i32(s, 16)
|
64 |
+
magic = i16(s, 4)
|
65 |
+
if magic == 0xAF11:
|
66 |
+
duration = (duration * 1000) // 70
|
67 |
+
self.info["duration"] = duration
|
68 |
+
|
69 |
+
# look for palette
|
70 |
+
palette = [(a, a, a) for a in range(256)]
|
71 |
+
|
72 |
+
s = self.fp.read(16)
|
73 |
+
|
74 |
+
self.__offset = 128
|
75 |
+
|
76 |
+
if i16(s, 4) == 0xF100:
|
77 |
+
# prefix chunk; ignore it
|
78 |
+
self.__offset = self.__offset + i32(s)
|
79 |
+
s = self.fp.read(16)
|
80 |
+
|
81 |
+
if i16(s, 4) == 0xF1FA:
|
82 |
+
# look for palette chunk
|
83 |
+
number_of_subchunks = i16(s, 6)
|
84 |
+
chunk_size = None
|
85 |
+
for _ in range(number_of_subchunks):
|
86 |
+
if chunk_size is not None:
|
87 |
+
self.fp.seek(chunk_size - 6, os.SEEK_CUR)
|
88 |
+
s = self.fp.read(6)
|
89 |
+
chunk_type = i16(s, 4)
|
90 |
+
if chunk_type in (4, 11):
|
91 |
+
self._palette(palette, 2 if chunk_type == 11 else 0)
|
92 |
+
break
|
93 |
+
chunk_size = i32(s)
|
94 |
+
if not chunk_size:
|
95 |
+
break
|
96 |
+
|
97 |
+
palette = [o8(r) + o8(g) + o8(b) for (r, g, b) in palette]
|
98 |
+
self.palette = ImagePalette.raw("RGB", b"".join(palette))
|
99 |
+
|
100 |
+
# set things up to decode first frame
|
101 |
+
self.__frame = -1
|
102 |
+
self._fp = self.fp
|
103 |
+
self.__rewind = self.fp.tell()
|
104 |
+
self.seek(0)
|
105 |
+
|
106 |
+
def _palette(self, palette, shift):
|
107 |
+
# load palette
|
108 |
+
|
109 |
+
i = 0
|
110 |
+
for e in range(i16(self.fp.read(2))):
|
111 |
+
s = self.fp.read(2)
|
112 |
+
i = i + s[0]
|
113 |
+
n = s[1]
|
114 |
+
if n == 0:
|
115 |
+
n = 256
|
116 |
+
s = self.fp.read(n * 3)
|
117 |
+
for n in range(0, len(s), 3):
|
118 |
+
r = s[n] << shift
|
119 |
+
g = s[n + 1] << shift
|
120 |
+
b = s[n + 2] << shift
|
121 |
+
palette[i] = (r, g, b)
|
122 |
+
i += 1
|
123 |
+
|
124 |
+
def seek(self, frame):
|
125 |
+
if not self._seek_check(frame):
|
126 |
+
return
|
127 |
+
if frame < self.__frame:
|
128 |
+
self._seek(0)
|
129 |
+
|
130 |
+
for f in range(self.__frame + 1, frame + 1):
|
131 |
+
self._seek(f)
|
132 |
+
|
133 |
+
def _seek(self, frame):
|
134 |
+
if frame == 0:
|
135 |
+
self.__frame = -1
|
136 |
+
self._fp.seek(self.__rewind)
|
137 |
+
self.__offset = 128
|
138 |
+
else:
|
139 |
+
# ensure that the previous frame was loaded
|
140 |
+
self.load()
|
141 |
+
|
142 |
+
if frame != self.__frame + 1:
|
143 |
+
msg = f"cannot seek to frame {frame}"
|
144 |
+
raise ValueError(msg)
|
145 |
+
self.__frame = frame
|
146 |
+
|
147 |
+
# move to next frame
|
148 |
+
self.fp = self._fp
|
149 |
+
self.fp.seek(self.__offset)
|
150 |
+
|
151 |
+
s = self.fp.read(4)
|
152 |
+
if not s:
|
153 |
+
raise EOFError
|
154 |
+
|
155 |
+
framesize = i32(s)
|
156 |
+
|
157 |
+
self.decodermaxblock = framesize
|
158 |
+
self.tile = [("fli", (0, 0) + self.size, self.__offset, None)]
|
159 |
+
|
160 |
+
self.__offset += framesize
|
161 |
+
|
162 |
+
def tell(self):
|
163 |
+
return self.__frame
|
164 |
+
|
165 |
+
|
166 |
+
#
|
167 |
+
# registry
|
168 |
+
|
169 |
+
Image.register_open(FliImageFile.format, FliImageFile, _accept)
|
170 |
+
|
171 |
+
Image.register_extensions(FliImageFile.format, [".fli", ".flc"])
|
Lib/site-packages/PIL/FontFile.py
ADDED
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#
|
2 |
+
# The Python Imaging Library
|
3 |
+
# $Id$
|
4 |
+
#
|
5 |
+
# base class for raster font file parsers
|
6 |
+
#
|
7 |
+
# history:
|
8 |
+
# 1997-06-05 fl created
|
9 |
+
# 1997-08-19 fl restrict image width
|
10 |
+
#
|
11 |
+
# Copyright (c) 1997-1998 by Secret Labs AB
|
12 |
+
# Copyright (c) 1997-1998 by Fredrik Lundh
|
13 |
+
#
|
14 |
+
# See the README file for information on usage and redistribution.
|
15 |
+
#
|
16 |
+
|
17 |
+
|
18 |
+
import os
|
19 |
+
|
20 |
+
from . import Image, _binary
|
21 |
+
|
22 |
+
WIDTH = 800
|
23 |
+
|
24 |
+
|
25 |
+
def puti16(fp, values):
|
26 |
+
"""Write network order (big-endian) 16-bit sequence"""
|
27 |
+
for v in values:
|
28 |
+
if v < 0:
|
29 |
+
v += 65536
|
30 |
+
fp.write(_binary.o16be(v))
|
31 |
+
|
32 |
+
|
33 |
+
class FontFile:
|
34 |
+
"""Base class for raster font file handlers."""
|
35 |
+
|
36 |
+
bitmap = None
|
37 |
+
|
38 |
+
def __init__(self):
|
39 |
+
self.info = {}
|
40 |
+
self.glyph = [None] * 256
|
41 |
+
|
42 |
+
def __getitem__(self, ix):
|
43 |
+
return self.glyph[ix]
|
44 |
+
|
45 |
+
def compile(self):
|
46 |
+
"""Create metrics and bitmap"""
|
47 |
+
|
48 |
+
if self.bitmap:
|
49 |
+
return
|
50 |
+
|
51 |
+
# create bitmap large enough to hold all data
|
52 |
+
h = w = maxwidth = 0
|
53 |
+
lines = 1
|
54 |
+
for glyph in self:
|
55 |
+
if glyph:
|
56 |
+
d, dst, src, im = glyph
|
57 |
+
h = max(h, src[3] - src[1])
|
58 |
+
w = w + (src[2] - src[0])
|
59 |
+
if w > WIDTH:
|
60 |
+
lines += 1
|
61 |
+
w = src[2] - src[0]
|
62 |
+
maxwidth = max(maxwidth, w)
|
63 |
+
|
64 |
+
xsize = maxwidth
|
65 |
+
ysize = lines * h
|
66 |
+
|
67 |
+
if xsize == 0 and ysize == 0:
|
68 |
+
return ""
|
69 |
+
|
70 |
+
self.ysize = h
|
71 |
+
|
72 |
+
# paste glyphs into bitmap
|
73 |
+
self.bitmap = Image.new("1", (xsize, ysize))
|
74 |
+
self.metrics = [None] * 256
|
75 |
+
x = y = 0
|
76 |
+
for i in range(256):
|
77 |
+
glyph = self[i]
|
78 |
+
if glyph:
|
79 |
+
d, dst, src, im = glyph
|
80 |
+
xx = src[2] - src[0]
|
81 |
+
# yy = src[3] - src[1]
|
82 |
+
x0, y0 = x, y
|
83 |
+
x = x + xx
|
84 |
+
if x > WIDTH:
|
85 |
+
x, y = 0, y + h
|
86 |
+
x0, y0 = x, y
|
87 |
+
x = xx
|
88 |
+
s = src[0] + x0, src[1] + y0, src[2] + x0, src[3] + y0
|
89 |
+
self.bitmap.paste(im.crop(src), s)
|
90 |
+
self.metrics[i] = d, dst, s
|
91 |
+
|
92 |
+
def save(self, filename):
|
93 |
+
"""Save font"""
|
94 |
+
|
95 |
+
self.compile()
|
96 |
+
|
97 |
+
# font data
|
98 |
+
self.bitmap.save(os.path.splitext(filename)[0] + ".pbm", "PNG")
|
99 |
+
|
100 |
+
# font metrics
|
101 |
+
with open(os.path.splitext(filename)[0] + ".pil", "wb") as fp:
|
102 |
+
fp.write(b"PILfont\n")
|
103 |
+
fp.write(f";;;;;;{self.ysize};\n".encode("ascii")) # HACK!!!
|
104 |
+
fp.write(b"DATA\n")
|
105 |
+
for id in range(256):
|
106 |
+
m = self.metrics[id]
|
107 |
+
if not m:
|
108 |
+
puti16(fp, [0] * 10)
|
109 |
+
else:
|
110 |
+
puti16(fp, m[0] + m[1] + m[2])
|
Lib/site-packages/PIL/FpxImagePlugin.py
ADDED
@@ -0,0 +1,253 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#
|
2 |
+
# THIS IS WORK IN PROGRESS
|
3 |
+
#
|
4 |
+
# The Python Imaging Library.
|
5 |
+
# $Id$
|
6 |
+
#
|
7 |
+
# FlashPix support for PIL
|
8 |
+
#
|
9 |
+
# History:
|
10 |
+
# 97-01-25 fl Created (reads uncompressed RGB images only)
|
11 |
+
#
|
12 |
+
# Copyright (c) Secret Labs AB 1997.
|
13 |
+
# Copyright (c) Fredrik Lundh 1997.
|
14 |
+
#
|
15 |
+
# See the README file for information on usage and redistribution.
|
16 |
+
#
|
17 |
+
import olefile
|
18 |
+
|
19 |
+
from . import Image, ImageFile
|
20 |
+
from ._binary import i32le as i32
|
21 |
+
|
22 |
+
# we map from colour field tuples to (mode, rawmode) descriptors
|
23 |
+
MODES = {
|
24 |
+
# opacity
|
25 |
+
(0x00007FFE,): ("A", "L"),
|
26 |
+
# monochrome
|
27 |
+
(0x00010000,): ("L", "L"),
|
28 |
+
(0x00018000, 0x00017FFE): ("RGBA", "LA"),
|
29 |
+
# photo YCC
|
30 |
+
(0x00020000, 0x00020001, 0x00020002): ("RGB", "YCC;P"),
|
31 |
+
(0x00028000, 0x00028001, 0x00028002, 0x00027FFE): ("RGBA", "YCCA;P"),
|
32 |
+
# standard RGB (NIFRGB)
|
33 |
+
(0x00030000, 0x00030001, 0x00030002): ("RGB", "RGB"),
|
34 |
+
(0x00038000, 0x00038001, 0x00038002, 0x00037FFE): ("RGBA", "RGBA"),
|
35 |
+
}
|
36 |
+
|
37 |
+
|
38 |
+
#
|
39 |
+
# --------------------------------------------------------------------
|
40 |
+
|
41 |
+
|
42 |
+
def _accept(prefix):
|
43 |
+
return prefix[:8] == olefile.MAGIC
|
44 |
+
|
45 |
+
|
46 |
+
##
|
47 |
+
# Image plugin for the FlashPix images.
|
48 |
+
|
49 |
+
|
50 |
+
class FpxImageFile(ImageFile.ImageFile):
|
51 |
+
format = "FPX"
|
52 |
+
format_description = "FlashPix"
|
53 |
+
|
54 |
+
def _open(self):
|
55 |
+
#
|
56 |
+
# read the OLE directory and see if this is a likely
|
57 |
+
# to be a FlashPix file
|
58 |
+
|
59 |
+
try:
|
60 |
+
self.ole = olefile.OleFileIO(self.fp)
|
61 |
+
except OSError as e:
|
62 |
+
msg = "not an FPX file; invalid OLE file"
|
63 |
+
raise SyntaxError(msg) from e
|
64 |
+
|
65 |
+
if self.ole.root.clsid != "56616700-C154-11CE-8553-00AA00A1F95B":
|
66 |
+
msg = "not an FPX file; bad root CLSID"
|
67 |
+
raise SyntaxError(msg)
|
68 |
+
|
69 |
+
self._open_index(1)
|
70 |
+
|
71 |
+
def _open_index(self, index=1):
|
72 |
+
#
|
73 |
+
# get the Image Contents Property Set
|
74 |
+
|
75 |
+
prop = self.ole.getproperties(
|
76 |
+
[f"Data Object Store {index:06d}", "\005Image Contents"]
|
77 |
+
)
|
78 |
+
|
79 |
+
# size (highest resolution)
|
80 |
+
|
81 |
+
self._size = prop[0x1000002], prop[0x1000003]
|
82 |
+
|
83 |
+
size = max(self.size)
|
84 |
+
i = 1
|
85 |
+
while size > 64:
|
86 |
+
size = size / 2
|
87 |
+
i += 1
|
88 |
+
self.maxid = i - 1
|
89 |
+
|
90 |
+
# mode. instead of using a single field for this, flashpix
|
91 |
+
# requires you to specify the mode for each channel in each
|
92 |
+
# resolution subimage, and leaves it to the decoder to make
|
93 |
+
# sure that they all match. for now, we'll cheat and assume
|
94 |
+
# that this is always the case.
|
95 |
+
|
96 |
+
id = self.maxid << 16
|
97 |
+
|
98 |
+
s = prop[0x2000002 | id]
|
99 |
+
|
100 |
+
colors = []
|
101 |
+
bands = i32(s, 4)
|
102 |
+
if bands > 4:
|
103 |
+
msg = "Invalid number of bands"
|
104 |
+
raise OSError(msg)
|
105 |
+
for i in range(bands):
|
106 |
+
# note: for now, we ignore the "uncalibrated" flag
|
107 |
+
colors.append(i32(s, 8 + i * 4) & 0x7FFFFFFF)
|
108 |
+
|
109 |
+
self.mode, self.rawmode = MODES[tuple(colors)]
|
110 |
+
|
111 |
+
# load JPEG tables, if any
|
112 |
+
self.jpeg = {}
|
113 |
+
for i in range(256):
|
114 |
+
id = 0x3000001 | (i << 16)
|
115 |
+
if id in prop:
|
116 |
+
self.jpeg[i] = prop[id]
|
117 |
+
|
118 |
+
self._open_subimage(1, self.maxid)
|
119 |
+
|
120 |
+
def _open_subimage(self, index=1, subimage=0):
|
121 |
+
#
|
122 |
+
# setup tile descriptors for a given subimage
|
123 |
+
|
124 |
+
stream = [
|
125 |
+
f"Data Object Store {index:06d}",
|
126 |
+
f"Resolution {subimage:04d}",
|
127 |
+
"Subimage 0000 Header",
|
128 |
+
]
|
129 |
+
|
130 |
+
fp = self.ole.openstream(stream)
|
131 |
+
|
132 |
+
# skip prefix
|
133 |
+
fp.read(28)
|
134 |
+
|
135 |
+
# header stream
|
136 |
+
s = fp.read(36)
|
137 |
+
|
138 |
+
size = i32(s, 4), i32(s, 8)
|
139 |
+
# tilecount = i32(s, 12)
|
140 |
+
tilesize = i32(s, 16), i32(s, 20)
|
141 |
+
# channels = i32(s, 24)
|
142 |
+
offset = i32(s, 28)
|
143 |
+
length = i32(s, 32)
|
144 |
+
|
145 |
+
if size != self.size:
|
146 |
+
msg = "subimage mismatch"
|
147 |
+
raise OSError(msg)
|
148 |
+
|
149 |
+
# get tile descriptors
|
150 |
+
fp.seek(28 + offset)
|
151 |
+
s = fp.read(i32(s, 12) * length)
|
152 |
+
|
153 |
+
x = y = 0
|
154 |
+
xsize, ysize = size
|
155 |
+
xtile, ytile = tilesize
|
156 |
+
self.tile = []
|
157 |
+
|
158 |
+
for i in range(0, len(s), length):
|
159 |
+
x1 = min(xsize, x + xtile)
|
160 |
+
y1 = min(ysize, y + ytile)
|
161 |
+
|
162 |
+
compression = i32(s, i + 8)
|
163 |
+
|
164 |
+
if compression == 0:
|
165 |
+
self.tile.append(
|
166 |
+
(
|
167 |
+
"raw",
|
168 |
+
(x, y, x1, y1),
|
169 |
+
i32(s, i) + 28,
|
170 |
+
(self.rawmode,),
|
171 |
+
)
|
172 |
+
)
|
173 |
+
|
174 |
+
elif compression == 1:
|
175 |
+
# FIXME: the fill decoder is not implemented
|
176 |
+
self.tile.append(
|
177 |
+
(
|
178 |
+
"fill",
|
179 |
+
(x, y, x1, y1),
|
180 |
+
i32(s, i) + 28,
|
181 |
+
(self.rawmode, s[12:16]),
|
182 |
+
)
|
183 |
+
)
|
184 |
+
|
185 |
+
elif compression == 2:
|
186 |
+
internal_color_conversion = s[14]
|
187 |
+
jpeg_tables = s[15]
|
188 |
+
rawmode = self.rawmode
|
189 |
+
|
190 |
+
if internal_color_conversion:
|
191 |
+
# The image is stored as usual (usually YCbCr).
|
192 |
+
if rawmode == "RGBA":
|
193 |
+
# For "RGBA", data is stored as YCbCrA based on
|
194 |
+
# negative RGB. The following trick works around
|
195 |
+
# this problem :
|
196 |
+
jpegmode, rawmode = "YCbCrK", "CMYK"
|
197 |
+
else:
|
198 |
+
jpegmode = None # let the decoder decide
|
199 |
+
|
200 |
+
else:
|
201 |
+
# The image is stored as defined by rawmode
|
202 |
+
jpegmode = rawmode
|
203 |
+
|
204 |
+
self.tile.append(
|
205 |
+
(
|
206 |
+
"jpeg",
|
207 |
+
(x, y, x1, y1),
|
208 |
+
i32(s, i) + 28,
|
209 |
+
(rawmode, jpegmode),
|
210 |
+
)
|
211 |
+
)
|
212 |
+
|
213 |
+
# FIXME: jpeg tables are tile dependent; the prefix
|
214 |
+
# data must be placed in the tile descriptor itself!
|
215 |
+
|
216 |
+
if jpeg_tables:
|
217 |
+
self.tile_prefix = self.jpeg[jpeg_tables]
|
218 |
+
|
219 |
+
else:
|
220 |
+
msg = "unknown/invalid compression"
|
221 |
+
raise OSError(msg)
|
222 |
+
|
223 |
+
x = x + xtile
|
224 |
+
if x >= xsize:
|
225 |
+
x, y = 0, y + ytile
|
226 |
+
if y >= ysize:
|
227 |
+
break # isn't really required
|
228 |
+
|
229 |
+
self.stream = stream
|
230 |
+
self.fp = None
|
231 |
+
|
232 |
+
def load(self):
|
233 |
+
if not self.fp:
|
234 |
+
self.fp = self.ole.openstream(self.stream[:2] + ["Subimage 0000 Data"])
|
235 |
+
|
236 |
+
return ImageFile.ImageFile.load(self)
|
237 |
+
|
238 |
+
def close(self):
|
239 |
+
self.ole.close()
|
240 |
+
super().close()
|
241 |
+
|
242 |
+
def __exit__(self, *args):
|
243 |
+
self.ole.close()
|
244 |
+
super().__exit__()
|
245 |
+
|
246 |
+
|
247 |
+
#
|
248 |
+
# --------------------------------------------------------------------
|
249 |
+
|
250 |
+
|
251 |
+
Image.register_open(FpxImageFile.format, FpxImageFile, _accept)
|
252 |
+
|
253 |
+
Image.register_extension(FpxImageFile.format, ".fpx")
|
Lib/site-packages/PIL/FtexImagePlugin.py
ADDED
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
A Pillow loader for .ftc and .ftu files (FTEX)
|
3 |
+
Jerome Leclanche <[email protected]>
|
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 |
+
Independence War 2: Edge Of Chaos - Texture File Format - 16 October 2001
|
10 |
+
|
11 |
+
The textures used for 3D objects in Independence War 2: Edge Of Chaos are in a
|
12 |
+
packed custom format called FTEX. This file format uses file extensions FTC
|
13 |
+
and FTU.
|
14 |
+
* FTC files are compressed textures (using standard texture compression).
|
15 |
+
* FTU files are not compressed.
|
16 |
+
Texture File Format
|
17 |
+
The FTC and FTU texture files both use the same format. This
|
18 |
+
has the following structure:
|
19 |
+
{header}
|
20 |
+
{format_directory}
|
21 |
+
{data}
|
22 |
+
Where:
|
23 |
+
{header} = {
|
24 |
+
u32:magic,
|
25 |
+
u32:version,
|
26 |
+
u32:width,
|
27 |
+
u32:height,
|
28 |
+
u32:mipmap_count,
|
29 |
+
u32:format_count
|
30 |
+
}
|
31 |
+
|
32 |
+
* The "magic" number is "FTEX".
|
33 |
+
* "width" and "height" are the dimensions of the texture.
|
34 |
+
* "mipmap_count" is the number of mipmaps in the texture.
|
35 |
+
* "format_count" is the number of texture formats (different versions of the
|
36 |
+
same texture) in this file.
|
37 |
+
|
38 |
+
{format_directory} = format_count * { u32:format, u32:where }
|
39 |
+
|
40 |
+
The format value is 0 for DXT1 compressed textures and 1 for 24-bit RGB
|
41 |
+
uncompressed textures.
|
42 |
+
The texture data for a format starts at the position "where" in the file.
|
43 |
+
|
44 |
+
Each set of texture data in the file has the following structure:
|
45 |
+
{data} = format_count * { u32:mipmap_size, mipmap_size * { u8 } }
|
46 |
+
* "mipmap_size" is the number of bytes in that mip level. For compressed
|
47 |
+
textures this is the size of the texture data compressed with DXT1. For 24 bit
|
48 |
+
uncompressed textures, this is 3 * width * height. Following this are the image
|
49 |
+
bytes for that mipmap level.
|
50 |
+
|
51 |
+
Note: All data is stored in little-Endian (Intel) byte order.
|
52 |
+
"""
|
53 |
+
|
54 |
+
import struct
|
55 |
+
from enum import IntEnum
|
56 |
+
from io import BytesIO
|
57 |
+
|
58 |
+
from . import Image, ImageFile
|
59 |
+
from ._deprecate import deprecate
|
60 |
+
|
61 |
+
MAGIC = b"FTEX"
|
62 |
+
|
63 |
+
|
64 |
+
class Format(IntEnum):
|
65 |
+
DXT1 = 0
|
66 |
+
UNCOMPRESSED = 1
|
67 |
+
|
68 |
+
|
69 |
+
def __getattr__(name):
|
70 |
+
for enum, prefix in {Format: "FORMAT_"}.items():
|
71 |
+
if name.startswith(prefix):
|
72 |
+
name = name[len(prefix) :]
|
73 |
+
if name in enum.__members__:
|
74 |
+
deprecate(f"{prefix}{name}", 10, f"{enum.__name__}.{name}")
|
75 |
+
return enum[name]
|
76 |
+
msg = f"module '{__name__}' has no attribute '{name}'"
|
77 |
+
raise AttributeError(msg)
|
78 |
+
|
79 |
+
|
80 |
+
class FtexImageFile(ImageFile.ImageFile):
|
81 |
+
format = "FTEX"
|
82 |
+
format_description = "Texture File Format (IW2:EOC)"
|
83 |
+
|
84 |
+
def _open(self):
|
85 |
+
if not _accept(self.fp.read(4)):
|
86 |
+
msg = "not an FTEX file"
|
87 |
+
raise SyntaxError(msg)
|
88 |
+
struct.unpack("<i", self.fp.read(4)) # version
|
89 |
+
self._size = struct.unpack("<2i", self.fp.read(8))
|
90 |
+
mipmap_count, format_count = struct.unpack("<2i", self.fp.read(8))
|
91 |
+
|
92 |
+
self.mode = "RGB"
|
93 |
+
|
94 |
+
# Only support single-format files.
|
95 |
+
# I don't know of any multi-format file.
|
96 |
+
assert format_count == 1
|
97 |
+
|
98 |
+
format, where = struct.unpack("<2i", self.fp.read(8))
|
99 |
+
self.fp.seek(where)
|
100 |
+
(mipmap_size,) = struct.unpack("<i", self.fp.read(4))
|
101 |
+
|
102 |
+
data = self.fp.read(mipmap_size)
|
103 |
+
|
104 |
+
if format == Format.DXT1:
|
105 |
+
self.mode = "RGBA"
|
106 |
+
self.tile = [("bcn", (0, 0) + self.size, 0, 1)]
|
107 |
+
elif format == Format.UNCOMPRESSED:
|
108 |
+
self.tile = [("raw", (0, 0) + self.size, 0, ("RGB", 0, 1))]
|
109 |
+
else:
|
110 |
+
msg = f"Invalid texture compression format: {repr(format)}"
|
111 |
+
raise ValueError(msg)
|
112 |
+
|
113 |
+
self.fp.close()
|
114 |
+
self.fp = BytesIO(data)
|
115 |
+
|
116 |
+
def load_seek(self, pos):
|
117 |
+
pass
|
118 |
+
|
119 |
+
|
120 |
+
def _accept(prefix):
|
121 |
+
return prefix[:4] == MAGIC
|
122 |
+
|
123 |
+
|
124 |
+
Image.register_open(FtexImageFile.format, FtexImageFile, _accept)
|
125 |
+
Image.register_extensions(FtexImageFile.format, [".ftc", ".ftu"])
|
Lib/site-packages/PIL/GbrImagePlugin.py
ADDED
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#
|
2 |
+
# The Python Imaging Library
|
3 |
+
#
|
4 |
+
# load a GIMP brush file
|
5 |
+
#
|
6 |
+
# History:
|
7 |
+
# 96-03-14 fl Created
|
8 |
+
# 16-01-08 es Version 2
|
9 |
+
#
|
10 |
+
# Copyright (c) Secret Labs AB 1997.
|
11 |
+
# Copyright (c) Fredrik Lundh 1996.
|
12 |
+
# Copyright (c) Eric Soroos 2016.
|
13 |
+
#
|
14 |
+
# See the README file for information on usage and redistribution.
|
15 |
+
#
|
16 |
+
#
|
17 |
+
# See https://github.com/GNOME/gimp/blob/mainline/devel-docs/gbr.txt for
|
18 |
+
# format documentation.
|
19 |
+
#
|
20 |
+
# This code Interprets version 1 and 2 .gbr files.
|
21 |
+
# Version 1 files are obsolete, and should not be used for new
|
22 |
+
# brushes.
|
23 |
+
# Version 2 files are saved by GIMP v2.8 (at least)
|
24 |
+
# Version 3 files have a format specifier of 18 for 16bit floats in
|
25 |
+
# the color depth field. This is currently unsupported by Pillow.
|
26 |
+
|
27 |
+
from . import Image, ImageFile
|
28 |
+
from ._binary import i32be as i32
|
29 |
+
|
30 |
+
|
31 |
+
def _accept(prefix):
|
32 |
+
return len(prefix) >= 8 and i32(prefix, 0) >= 20 and i32(prefix, 4) in (1, 2)
|
33 |
+
|
34 |
+
|
35 |
+
##
|
36 |
+
# Image plugin for the GIMP brush format.
|
37 |
+
|
38 |
+
|
39 |
+
class GbrImageFile(ImageFile.ImageFile):
|
40 |
+
format = "GBR"
|
41 |
+
format_description = "GIMP brush file"
|
42 |
+
|
43 |
+
def _open(self):
|
44 |
+
header_size = i32(self.fp.read(4))
|
45 |
+
if header_size < 20:
|
46 |
+
msg = "not a GIMP brush"
|
47 |
+
raise SyntaxError(msg)
|
48 |
+
version = i32(self.fp.read(4))
|
49 |
+
if version not in (1, 2):
|
50 |
+
msg = f"Unsupported GIMP brush version: {version}"
|
51 |
+
raise SyntaxError(msg)
|
52 |
+
|
53 |
+
width = i32(self.fp.read(4))
|
54 |
+
height = i32(self.fp.read(4))
|
55 |
+
color_depth = i32(self.fp.read(4))
|
56 |
+
if width <= 0 or height <= 0:
|
57 |
+
msg = "not a GIMP brush"
|
58 |
+
raise SyntaxError(msg)
|
59 |
+
if color_depth not in (1, 4):
|
60 |
+
msg = f"Unsupported GIMP brush color depth: {color_depth}"
|
61 |
+
raise SyntaxError(msg)
|
62 |
+
|
63 |
+
if version == 1:
|
64 |
+
comment_length = header_size - 20
|
65 |
+
else:
|
66 |
+
comment_length = header_size - 28
|
67 |
+
magic_number = self.fp.read(4)
|
68 |
+
if magic_number != b"GIMP":
|
69 |
+
msg = "not a GIMP brush, bad magic number"
|
70 |
+
raise SyntaxError(msg)
|
71 |
+
self.info["spacing"] = i32(self.fp.read(4))
|
72 |
+
|
73 |
+
comment = self.fp.read(comment_length)[:-1]
|
74 |
+
|
75 |
+
if color_depth == 1:
|
76 |
+
self.mode = "L"
|
77 |
+
else:
|
78 |
+
self.mode = "RGBA"
|
79 |
+
|
80 |
+
self._size = width, height
|
81 |
+
|
82 |
+
self.info["comment"] = comment
|
83 |
+
|
84 |
+
# Image might not be small
|
85 |
+
Image._decompression_bomb_check(self.size)
|
86 |
+
|
87 |
+
# Data is an uncompressed block of w * h * bytes/pixel
|
88 |
+
self._data_size = width * height * color_depth
|
89 |
+
|
90 |
+
def load(self):
|
91 |
+
if not self.im:
|
92 |
+
self.im = Image.core.new(self.mode, self.size)
|
93 |
+
self.frombytes(self.fp.read(self._data_size))
|
94 |
+
return Image.Image.load(self)
|
95 |
+
|
96 |
+
|
97 |
+
#
|
98 |
+
# registry
|
99 |
+
|
100 |
+
|
101 |
+
Image.register_open(GbrImageFile.format, GbrImageFile, _accept)
|
102 |
+
Image.register_extension(GbrImageFile.format, ".gbr")
|
Lib/site-packages/PIL/GdImageFile.py
ADDED
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#
|
2 |
+
# The Python Imaging Library.
|
3 |
+
# $Id$
|
4 |
+
#
|
5 |
+
# GD file handling
|
6 |
+
#
|
7 |
+
# History:
|
8 |
+
# 1996-04-12 fl Created
|
9 |
+
#
|
10 |
+
# Copyright (c) 1997 by Secret Labs AB.
|
11 |
+
# Copyright (c) 1996 by Fredrik Lundh.
|
12 |
+
#
|
13 |
+
# See the README file for information on usage and redistribution.
|
14 |
+
#
|
15 |
+
|
16 |
+
|
17 |
+
"""
|
18 |
+
.. note::
|
19 |
+
This format cannot be automatically recognized, so the
|
20 |
+
class is not registered for use with :py:func:`PIL.Image.open()`. To open a
|
21 |
+
gd file, use the :py:func:`PIL.GdImageFile.open()` function instead.
|
22 |
+
|
23 |
+
.. warning::
|
24 |
+
THE GD FORMAT IS NOT DESIGNED FOR DATA INTERCHANGE. This
|
25 |
+
implementation is provided for convenience and demonstrational
|
26 |
+
purposes only.
|
27 |
+
"""
|
28 |
+
|
29 |
+
|
30 |
+
from . import ImageFile, ImagePalette, UnidentifiedImageError
|
31 |
+
from ._binary import i16be as i16
|
32 |
+
from ._binary import i32be as i32
|
33 |
+
|
34 |
+
|
35 |
+
class GdImageFile(ImageFile.ImageFile):
|
36 |
+
"""
|
37 |
+
Image plugin for the GD uncompressed format. Note that this format
|
38 |
+
is not supported by the standard :py:func:`PIL.Image.open()` function. To use
|
39 |
+
this plugin, you have to import the :py:mod:`PIL.GdImageFile` module and
|
40 |
+
use the :py:func:`PIL.GdImageFile.open()` function.
|
41 |
+
"""
|
42 |
+
|
43 |
+
format = "GD"
|
44 |
+
format_description = "GD uncompressed images"
|
45 |
+
|
46 |
+
def _open(self):
|
47 |
+
# Header
|
48 |
+
s = self.fp.read(1037)
|
49 |
+
|
50 |
+
if not i16(s) in [65534, 65535]:
|
51 |
+
msg = "Not a valid GD 2.x .gd file"
|
52 |
+
raise SyntaxError(msg)
|
53 |
+
|
54 |
+
self.mode = "L" # FIXME: "P"
|
55 |
+
self._size = i16(s, 2), i16(s, 4)
|
56 |
+
|
57 |
+
true_color = s[6]
|
58 |
+
true_color_offset = 2 if true_color else 0
|
59 |
+
|
60 |
+
# transparency index
|
61 |
+
tindex = i32(s, 7 + true_color_offset)
|
62 |
+
if tindex < 256:
|
63 |
+
self.info["transparency"] = tindex
|
64 |
+
|
65 |
+
self.palette = ImagePalette.raw(
|
66 |
+
"XBGR", s[7 + true_color_offset + 4 : 7 + true_color_offset + 4 + 256 * 4]
|
67 |
+
)
|
68 |
+
|
69 |
+
self.tile = [
|
70 |
+
(
|
71 |
+
"raw",
|
72 |
+
(0, 0) + self.size,
|
73 |
+
7 + true_color_offset + 4 + 256 * 4,
|
74 |
+
("L", 0, 1),
|
75 |
+
)
|
76 |
+
]
|
77 |
+
|
78 |
+
|
79 |
+
def open(fp, mode="r"):
|
80 |
+
"""
|
81 |
+
Load texture from a GD image file.
|
82 |
+
|
83 |
+
:param fp: GD file name, or an opened file handle.
|
84 |
+
:param mode: Optional mode. In this version, if the mode argument
|
85 |
+
is given, it must be "r".
|
86 |
+
:returns: An image instance.
|
87 |
+
:raises OSError: If the image could not be read.
|
88 |
+
"""
|
89 |
+
if mode != "r":
|
90 |
+
msg = "bad mode"
|
91 |
+
raise ValueError(msg)
|
92 |
+
|
93 |
+
try:
|
94 |
+
return GdImageFile(fp)
|
95 |
+
except SyntaxError as e:
|
96 |
+
msg = "cannot identify this image file"
|
97 |
+
raise UnidentifiedImageError(msg) from e
|
Lib/site-packages/PIL/GifImagePlugin.py
ADDED
@@ -0,0 +1,1064 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#
|
2 |
+
# The Python Imaging Library.
|
3 |
+
# $Id$
|
4 |
+
#
|
5 |
+
# GIF file handling
|
6 |
+
#
|
7 |
+
# History:
|
8 |
+
# 1995-09-01 fl Created
|
9 |
+
# 1996-12-14 fl Added interlace support
|
10 |
+
# 1996-12-30 fl Added animation support
|
11 |
+
# 1997-01-05 fl Added write support, fixed local colour map bug
|
12 |
+
# 1997-02-23 fl Make sure to load raster data in getdata()
|
13 |
+
# 1997-07-05 fl Support external decoder (0.4)
|
14 |
+
# 1998-07-09 fl Handle all modes when saving (0.5)
|
15 |
+
# 1998-07-15 fl Renamed offset attribute to avoid name clash
|
16 |
+
# 2001-04-16 fl Added rewind support (seek to frame 0) (0.6)
|
17 |
+
# 2001-04-17 fl Added palette optimization (0.7)
|
18 |
+
# 2002-06-06 fl Added transparency support for save (0.8)
|
19 |
+
# 2004-02-24 fl Disable interlacing for small images
|
20 |
+
#
|
21 |
+
# Copyright (c) 1997-2004 by Secret Labs AB
|
22 |
+
# Copyright (c) 1995-2004 by Fredrik Lundh
|
23 |
+
#
|
24 |
+
# See the README file for information on usage and redistribution.
|
25 |
+
#
|
26 |
+
|
27 |
+
import itertools
|
28 |
+
import math
|
29 |
+
import os
|
30 |
+
import subprocess
|
31 |
+
from enum import IntEnum
|
32 |
+
|
33 |
+
from . import Image, ImageChops, ImageFile, ImagePalette, ImageSequence
|
34 |
+
from ._binary import i16le as i16
|
35 |
+
from ._binary import o8
|
36 |
+
from ._binary import o16le as o16
|
37 |
+
|
38 |
+
|
39 |
+
class LoadingStrategy(IntEnum):
|
40 |
+
""".. versionadded:: 9.1.0"""
|
41 |
+
|
42 |
+
RGB_AFTER_FIRST = 0
|
43 |
+
RGB_AFTER_DIFFERENT_PALETTE_ONLY = 1
|
44 |
+
RGB_ALWAYS = 2
|
45 |
+
|
46 |
+
|
47 |
+
#: .. versionadded:: 9.1.0
|
48 |
+
LOADING_STRATEGY = LoadingStrategy.RGB_AFTER_FIRST
|
49 |
+
|
50 |
+
# --------------------------------------------------------------------
|
51 |
+
# Identify/read GIF files
|
52 |
+
|
53 |
+
|
54 |
+
def _accept(prefix):
|
55 |
+
return prefix[:6] in [b"GIF87a", b"GIF89a"]
|
56 |
+
|
57 |
+
|
58 |
+
##
|
59 |
+
# Image plugin for GIF images. This plugin supports both GIF87 and
|
60 |
+
# GIF89 images.
|
61 |
+
|
62 |
+
|
63 |
+
class GifImageFile(ImageFile.ImageFile):
|
64 |
+
format = "GIF"
|
65 |
+
format_description = "Compuserve GIF"
|
66 |
+
_close_exclusive_fp_after_loading = False
|
67 |
+
|
68 |
+
global_palette = None
|
69 |
+
|
70 |
+
def data(self):
|
71 |
+
s = self.fp.read(1)
|
72 |
+
if s and s[0]:
|
73 |
+
return self.fp.read(s[0])
|
74 |
+
return None
|
75 |
+
|
76 |
+
def _is_palette_needed(self, p):
|
77 |
+
for i in range(0, len(p), 3):
|
78 |
+
if not (i // 3 == p[i] == p[i + 1] == p[i + 2]):
|
79 |
+
return True
|
80 |
+
return False
|
81 |
+
|
82 |
+
def _open(self):
|
83 |
+
# Screen
|
84 |
+
s = self.fp.read(13)
|
85 |
+
if not _accept(s):
|
86 |
+
msg = "not a GIF file"
|
87 |
+
raise SyntaxError(msg)
|
88 |
+
|
89 |
+
self.info["version"] = s[:6]
|
90 |
+
self._size = i16(s, 6), i16(s, 8)
|
91 |
+
self.tile = []
|
92 |
+
flags = s[10]
|
93 |
+
bits = (flags & 7) + 1
|
94 |
+
|
95 |
+
if flags & 128:
|
96 |
+
# get global palette
|
97 |
+
self.info["background"] = s[11]
|
98 |
+
# check if palette contains colour indices
|
99 |
+
p = self.fp.read(3 << bits)
|
100 |
+
if self._is_palette_needed(p):
|
101 |
+
p = ImagePalette.raw("RGB", p)
|
102 |
+
self.global_palette = self.palette = p
|
103 |
+
|
104 |
+
self._fp = self.fp # FIXME: hack
|
105 |
+
self.__rewind = self.fp.tell()
|
106 |
+
self._n_frames = None
|
107 |
+
self._is_animated = None
|
108 |
+
self._seek(0) # get ready to read first frame
|
109 |
+
|
110 |
+
@property
|
111 |
+
def n_frames(self):
|
112 |
+
if self._n_frames is None:
|
113 |
+
current = self.tell()
|
114 |
+
try:
|
115 |
+
while True:
|
116 |
+
self._seek(self.tell() + 1, False)
|
117 |
+
except EOFError:
|
118 |
+
self._n_frames = self.tell() + 1
|
119 |
+
self.seek(current)
|
120 |
+
return self._n_frames
|
121 |
+
|
122 |
+
@property
|
123 |
+
def is_animated(self):
|
124 |
+
if self._is_animated is None:
|
125 |
+
if self._n_frames is not None:
|
126 |
+
self._is_animated = self._n_frames != 1
|
127 |
+
else:
|
128 |
+
current = self.tell()
|
129 |
+
if current:
|
130 |
+
self._is_animated = True
|
131 |
+
else:
|
132 |
+
try:
|
133 |
+
self._seek(1, False)
|
134 |
+
self._is_animated = True
|
135 |
+
except EOFError:
|
136 |
+
self._is_animated = False
|
137 |
+
|
138 |
+
self.seek(current)
|
139 |
+
return self._is_animated
|
140 |
+
|
141 |
+
def seek(self, frame):
|
142 |
+
if not self._seek_check(frame):
|
143 |
+
return
|
144 |
+
if frame < self.__frame:
|
145 |
+
self.im = None
|
146 |
+
self._seek(0)
|
147 |
+
|
148 |
+
last_frame = self.__frame
|
149 |
+
for f in range(self.__frame + 1, frame + 1):
|
150 |
+
try:
|
151 |
+
self._seek(f)
|
152 |
+
except EOFError as e:
|
153 |
+
self.seek(last_frame)
|
154 |
+
msg = "no more images in GIF file"
|
155 |
+
raise EOFError(msg) from e
|
156 |
+
|
157 |
+
def _seek(self, frame, update_image=True):
|
158 |
+
if frame == 0:
|
159 |
+
# rewind
|
160 |
+
self.__offset = 0
|
161 |
+
self.dispose = None
|
162 |
+
self.__frame = -1
|
163 |
+
self._fp.seek(self.__rewind)
|
164 |
+
self.disposal_method = 0
|
165 |
+
if "comment" in self.info:
|
166 |
+
del self.info["comment"]
|
167 |
+
else:
|
168 |
+
# ensure that the previous frame was loaded
|
169 |
+
if self.tile and update_image:
|
170 |
+
self.load()
|
171 |
+
|
172 |
+
if frame != self.__frame + 1:
|
173 |
+
msg = f"cannot seek to frame {frame}"
|
174 |
+
raise ValueError(msg)
|
175 |
+
|
176 |
+
self.fp = self._fp
|
177 |
+
if self.__offset:
|
178 |
+
# backup to last frame
|
179 |
+
self.fp.seek(self.__offset)
|
180 |
+
while self.data():
|
181 |
+
pass
|
182 |
+
self.__offset = 0
|
183 |
+
|
184 |
+
s = self.fp.read(1)
|
185 |
+
if not s or s == b";":
|
186 |
+
raise EOFError
|
187 |
+
|
188 |
+
palette = None
|
189 |
+
|
190 |
+
info = {}
|
191 |
+
frame_transparency = None
|
192 |
+
interlace = None
|
193 |
+
frame_dispose_extent = None
|
194 |
+
while True:
|
195 |
+
if not s:
|
196 |
+
s = self.fp.read(1)
|
197 |
+
if not s or s == b";":
|
198 |
+
break
|
199 |
+
|
200 |
+
elif s == b"!":
|
201 |
+
#
|
202 |
+
# extensions
|
203 |
+
#
|
204 |
+
s = self.fp.read(1)
|
205 |
+
block = self.data()
|
206 |
+
if s[0] == 249:
|
207 |
+
#
|
208 |
+
# graphic control extension
|
209 |
+
#
|
210 |
+
flags = block[0]
|
211 |
+
if flags & 1:
|
212 |
+
frame_transparency = block[3]
|
213 |
+
info["duration"] = i16(block, 1) * 10
|
214 |
+
|
215 |
+
# disposal method - find the value of bits 4 - 6
|
216 |
+
dispose_bits = 0b00011100 & flags
|
217 |
+
dispose_bits = dispose_bits >> 2
|
218 |
+
if dispose_bits:
|
219 |
+
# only set the dispose if it is not
|
220 |
+
# unspecified. I'm not sure if this is
|
221 |
+
# correct, but it seems to prevent the last
|
222 |
+
# frame from looking odd for some animations
|
223 |
+
self.disposal_method = dispose_bits
|
224 |
+
elif s[0] == 254:
|
225 |
+
#
|
226 |
+
# comment extension
|
227 |
+
#
|
228 |
+
comment = b""
|
229 |
+
|
230 |
+
# Read this comment block
|
231 |
+
while block:
|
232 |
+
comment += block
|
233 |
+
block = self.data()
|
234 |
+
|
235 |
+
if "comment" in info:
|
236 |
+
# If multiple comment blocks in frame, separate with \n
|
237 |
+
info["comment"] += b"\n" + comment
|
238 |
+
else:
|
239 |
+
info["comment"] = comment
|
240 |
+
s = None
|
241 |
+
continue
|
242 |
+
elif s[0] == 255 and frame == 0:
|
243 |
+
#
|
244 |
+
# application extension
|
245 |
+
#
|
246 |
+
info["extension"] = block, self.fp.tell()
|
247 |
+
if block[:11] == b"NETSCAPE2.0":
|
248 |
+
block = self.data()
|
249 |
+
if len(block) >= 3 and block[0] == 1:
|
250 |
+
self.info["loop"] = i16(block, 1)
|
251 |
+
while self.data():
|
252 |
+
pass
|
253 |
+
|
254 |
+
elif s == b",":
|
255 |
+
#
|
256 |
+
# local image
|
257 |
+
#
|
258 |
+
s = self.fp.read(9)
|
259 |
+
|
260 |
+
# extent
|
261 |
+
x0, y0 = i16(s, 0), i16(s, 2)
|
262 |
+
x1, y1 = x0 + i16(s, 4), y0 + i16(s, 6)
|
263 |
+
if (x1 > self.size[0] or y1 > self.size[1]) and update_image:
|
264 |
+
self._size = max(x1, self.size[0]), max(y1, self.size[1])
|
265 |
+
Image._decompression_bomb_check(self._size)
|
266 |
+
frame_dispose_extent = x0, y0, x1, y1
|
267 |
+
flags = s[8]
|
268 |
+
|
269 |
+
interlace = (flags & 64) != 0
|
270 |
+
|
271 |
+
if flags & 128:
|
272 |
+
bits = (flags & 7) + 1
|
273 |
+
p = self.fp.read(3 << bits)
|
274 |
+
if self._is_palette_needed(p):
|
275 |
+
palette = ImagePalette.raw("RGB", p)
|
276 |
+
else:
|
277 |
+
palette = False
|
278 |
+
|
279 |
+
# image data
|
280 |
+
bits = self.fp.read(1)[0]
|
281 |
+
self.__offset = self.fp.tell()
|
282 |
+
break
|
283 |
+
|
284 |
+
else:
|
285 |
+
pass
|
286 |
+
# raise OSError, "illegal GIF tag `%x`" % s[0]
|
287 |
+
s = None
|
288 |
+
|
289 |
+
if interlace is None:
|
290 |
+
# self._fp = None
|
291 |
+
raise EOFError
|
292 |
+
|
293 |
+
self.__frame = frame
|
294 |
+
if not update_image:
|
295 |
+
return
|
296 |
+
|
297 |
+
self.tile = []
|
298 |
+
|
299 |
+
if self.dispose:
|
300 |
+
self.im.paste(self.dispose, self.dispose_extent)
|
301 |
+
|
302 |
+
self._frame_palette = palette if palette is not None else self.global_palette
|
303 |
+
self._frame_transparency = frame_transparency
|
304 |
+
if frame == 0:
|
305 |
+
if self._frame_palette:
|
306 |
+
if LOADING_STRATEGY == LoadingStrategy.RGB_ALWAYS:
|
307 |
+
self.mode = "RGBA" if frame_transparency is not None else "RGB"
|
308 |
+
else:
|
309 |
+
self.mode = "P"
|
310 |
+
else:
|
311 |
+
self.mode = "L"
|
312 |
+
|
313 |
+
if not palette and self.global_palette:
|
314 |
+
from copy import copy
|
315 |
+
|
316 |
+
palette = copy(self.global_palette)
|
317 |
+
self.palette = palette
|
318 |
+
else:
|
319 |
+
if self.mode == "P":
|
320 |
+
if (
|
321 |
+
LOADING_STRATEGY != LoadingStrategy.RGB_AFTER_DIFFERENT_PALETTE_ONLY
|
322 |
+
or palette
|
323 |
+
):
|
324 |
+
self.pyaccess = None
|
325 |
+
if "transparency" in self.info:
|
326 |
+
self.im.putpalettealpha(self.info["transparency"], 0)
|
327 |
+
self.im = self.im.convert("RGBA", Image.Dither.FLOYDSTEINBERG)
|
328 |
+
self.mode = "RGBA"
|
329 |
+
del self.info["transparency"]
|
330 |
+
else:
|
331 |
+
self.mode = "RGB"
|
332 |
+
self.im = self.im.convert("RGB", Image.Dither.FLOYDSTEINBERG)
|
333 |
+
|
334 |
+
def _rgb(color):
|
335 |
+
if self._frame_palette:
|
336 |
+
color = tuple(self._frame_palette.palette[color * 3 : color * 3 + 3])
|
337 |
+
else:
|
338 |
+
color = (color, color, color)
|
339 |
+
return color
|
340 |
+
|
341 |
+
self.dispose_extent = frame_dispose_extent
|
342 |
+
try:
|
343 |
+
if self.disposal_method < 2:
|
344 |
+
# do not dispose or none specified
|
345 |
+
self.dispose = None
|
346 |
+
elif self.disposal_method == 2:
|
347 |
+
# replace with background colour
|
348 |
+
|
349 |
+
# only dispose the extent in this frame
|
350 |
+
x0, y0, x1, y1 = self.dispose_extent
|
351 |
+
dispose_size = (x1 - x0, y1 - y0)
|
352 |
+
|
353 |
+
Image._decompression_bomb_check(dispose_size)
|
354 |
+
|
355 |
+
# by convention, attempt to use transparency first
|
356 |
+
dispose_mode = "P"
|
357 |
+
color = self.info.get("transparency", frame_transparency)
|
358 |
+
if color is not None:
|
359 |
+
if self.mode in ("RGB", "RGBA"):
|
360 |
+
dispose_mode = "RGBA"
|
361 |
+
color = _rgb(color) + (0,)
|
362 |
+
else:
|
363 |
+
color = self.info.get("background", 0)
|
364 |
+
if self.mode in ("RGB", "RGBA"):
|
365 |
+
dispose_mode = "RGB"
|
366 |
+
color = _rgb(color)
|
367 |
+
self.dispose = Image.core.fill(dispose_mode, dispose_size, color)
|
368 |
+
else:
|
369 |
+
# replace with previous contents
|
370 |
+
if self.im is not None:
|
371 |
+
# only dispose the extent in this frame
|
372 |
+
self.dispose = self._crop(self.im, self.dispose_extent)
|
373 |
+
elif frame_transparency is not None:
|
374 |
+
x0, y0, x1, y1 = self.dispose_extent
|
375 |
+
dispose_size = (x1 - x0, y1 - y0)
|
376 |
+
|
377 |
+
Image._decompression_bomb_check(dispose_size)
|
378 |
+
dispose_mode = "P"
|
379 |
+
color = frame_transparency
|
380 |
+
if self.mode in ("RGB", "RGBA"):
|
381 |
+
dispose_mode = "RGBA"
|
382 |
+
color = _rgb(frame_transparency) + (0,)
|
383 |
+
self.dispose = Image.core.fill(dispose_mode, dispose_size, color)
|
384 |
+
except AttributeError:
|
385 |
+
pass
|
386 |
+
|
387 |
+
if interlace is not None:
|
388 |
+
transparency = -1
|
389 |
+
if frame_transparency is not None:
|
390 |
+
if frame == 0:
|
391 |
+
if LOADING_STRATEGY != LoadingStrategy.RGB_ALWAYS:
|
392 |
+
self.info["transparency"] = frame_transparency
|
393 |
+
elif self.mode not in ("RGB", "RGBA"):
|
394 |
+
transparency = frame_transparency
|
395 |
+
self.tile = [
|
396 |
+
(
|
397 |
+
"gif",
|
398 |
+
(x0, y0, x1, y1),
|
399 |
+
self.__offset,
|
400 |
+
(bits, interlace, transparency),
|
401 |
+
)
|
402 |
+
]
|
403 |
+
|
404 |
+
if info.get("comment"):
|
405 |
+
self.info["comment"] = info["comment"]
|
406 |
+
for k in ["duration", "extension"]:
|
407 |
+
if k in info:
|
408 |
+
self.info[k] = info[k]
|
409 |
+
elif k in self.info:
|
410 |
+
del self.info[k]
|
411 |
+
|
412 |
+
def load_prepare(self):
|
413 |
+
temp_mode = "P" if self._frame_palette else "L"
|
414 |
+
self._prev_im = None
|
415 |
+
if self.__frame == 0:
|
416 |
+
if self._frame_transparency is not None:
|
417 |
+
self.im = Image.core.fill(
|
418 |
+
temp_mode, self.size, self._frame_transparency
|
419 |
+
)
|
420 |
+
elif self.mode in ("RGB", "RGBA"):
|
421 |
+
self._prev_im = self.im
|
422 |
+
if self._frame_palette:
|
423 |
+
self.im = Image.core.fill("P", self.size, self._frame_transparency or 0)
|
424 |
+
self.im.putpalette(*self._frame_palette.getdata())
|
425 |
+
else:
|
426 |
+
self.im = None
|
427 |
+
self.mode = temp_mode
|
428 |
+
self._frame_palette = None
|
429 |
+
|
430 |
+
super().load_prepare()
|
431 |
+
|
432 |
+
def load_end(self):
|
433 |
+
if self.__frame == 0:
|
434 |
+
if self.mode == "P" and LOADING_STRATEGY == LoadingStrategy.RGB_ALWAYS:
|
435 |
+
if self._frame_transparency is not None:
|
436 |
+
self.im.putpalettealpha(self._frame_transparency, 0)
|
437 |
+
self.mode = "RGBA"
|
438 |
+
else:
|
439 |
+
self.mode = "RGB"
|
440 |
+
self.im = self.im.convert(self.mode, Image.Dither.FLOYDSTEINBERG)
|
441 |
+
return
|
442 |
+
if not self._prev_im:
|
443 |
+
return
|
444 |
+
if self._frame_transparency is not None:
|
445 |
+
self.im.putpalettealpha(self._frame_transparency, 0)
|
446 |
+
frame_im = self.im.convert("RGBA")
|
447 |
+
else:
|
448 |
+
frame_im = self.im.convert("RGB")
|
449 |
+
frame_im = self._crop(frame_im, self.dispose_extent)
|
450 |
+
|
451 |
+
self.im = self._prev_im
|
452 |
+
self.mode = self.im.mode
|
453 |
+
if frame_im.mode == "RGBA":
|
454 |
+
self.im.paste(frame_im, self.dispose_extent, frame_im)
|
455 |
+
else:
|
456 |
+
self.im.paste(frame_im, self.dispose_extent)
|
457 |
+
|
458 |
+
def tell(self):
|
459 |
+
return self.__frame
|
460 |
+
|
461 |
+
|
462 |
+
# --------------------------------------------------------------------
|
463 |
+
# Write GIF files
|
464 |
+
|
465 |
+
|
466 |
+
RAWMODE = {"1": "L", "L": "L", "P": "P"}
|
467 |
+
|
468 |
+
|
469 |
+
def _normalize_mode(im):
|
470 |
+
"""
|
471 |
+
Takes an image (or frame), returns an image in a mode that is appropriate
|
472 |
+
for saving in a Gif.
|
473 |
+
|
474 |
+
It may return the original image, or it may return an image converted to
|
475 |
+
palette or 'L' mode.
|
476 |
+
|
477 |
+
:param im: Image object
|
478 |
+
:returns: Image object
|
479 |
+
"""
|
480 |
+
if im.mode in RAWMODE:
|
481 |
+
im.load()
|
482 |
+
return im
|
483 |
+
if Image.getmodebase(im.mode) == "RGB":
|
484 |
+
im = im.convert("P", palette=Image.Palette.ADAPTIVE)
|
485 |
+
if im.palette.mode == "RGBA":
|
486 |
+
for rgba in im.palette.colors:
|
487 |
+
if rgba[3] == 0:
|
488 |
+
im.info["transparency"] = im.palette.colors[rgba]
|
489 |
+
break
|
490 |
+
return im
|
491 |
+
return im.convert("L")
|
492 |
+
|
493 |
+
|
494 |
+
def _normalize_palette(im, palette, info):
|
495 |
+
"""
|
496 |
+
Normalizes the palette for image.
|
497 |
+
- Sets the palette to the incoming palette, if provided.
|
498 |
+
- Ensures that there's a palette for L mode images
|
499 |
+
- Optimizes the palette if necessary/desired.
|
500 |
+
|
501 |
+
:param im: Image object
|
502 |
+
:param palette: bytes object containing the source palette, or ....
|
503 |
+
:param info: encoderinfo
|
504 |
+
:returns: Image object
|
505 |
+
"""
|
506 |
+
source_palette = None
|
507 |
+
if palette:
|
508 |
+
# a bytes palette
|
509 |
+
if isinstance(palette, (bytes, bytearray, list)):
|
510 |
+
source_palette = bytearray(palette[:768])
|
511 |
+
if isinstance(palette, ImagePalette.ImagePalette):
|
512 |
+
source_palette = bytearray(palette.palette)
|
513 |
+
|
514 |
+
if im.mode == "P":
|
515 |
+
if not source_palette:
|
516 |
+
source_palette = im.im.getpalette("RGB")[:768]
|
517 |
+
else: # L-mode
|
518 |
+
if not source_palette:
|
519 |
+
source_palette = bytearray(i // 3 for i in range(768))
|
520 |
+
im.palette = ImagePalette.ImagePalette("RGB", palette=source_palette)
|
521 |
+
|
522 |
+
if palette:
|
523 |
+
used_palette_colors = []
|
524 |
+
for i in range(0, len(source_palette), 3):
|
525 |
+
source_color = tuple(source_palette[i : i + 3])
|
526 |
+
index = im.palette.colors.get(source_color)
|
527 |
+
if index in used_palette_colors:
|
528 |
+
index = None
|
529 |
+
used_palette_colors.append(index)
|
530 |
+
for i, index in enumerate(used_palette_colors):
|
531 |
+
if index is None:
|
532 |
+
for j in range(len(used_palette_colors)):
|
533 |
+
if j not in used_palette_colors:
|
534 |
+
used_palette_colors[i] = j
|
535 |
+
break
|
536 |
+
im = im.remap_palette(used_palette_colors)
|
537 |
+
else:
|
538 |
+
used_palette_colors = _get_optimize(im, info)
|
539 |
+
if used_palette_colors is not None:
|
540 |
+
return im.remap_palette(used_palette_colors, source_palette)
|
541 |
+
|
542 |
+
im.palette.palette = source_palette
|
543 |
+
return im
|
544 |
+
|
545 |
+
|
546 |
+
def _write_single_frame(im, fp, palette):
|
547 |
+
im_out = _normalize_mode(im)
|
548 |
+
for k, v in im_out.info.items():
|
549 |
+
im.encoderinfo.setdefault(k, v)
|
550 |
+
im_out = _normalize_palette(im_out, palette, im.encoderinfo)
|
551 |
+
|
552 |
+
for s in _get_global_header(im_out, im.encoderinfo):
|
553 |
+
fp.write(s)
|
554 |
+
|
555 |
+
# local image header
|
556 |
+
flags = 0
|
557 |
+
if get_interlace(im):
|
558 |
+
flags = flags | 64
|
559 |
+
_write_local_header(fp, im, (0, 0), flags)
|
560 |
+
|
561 |
+
im_out.encoderconfig = (8, get_interlace(im))
|
562 |
+
ImageFile._save(im_out, fp, [("gif", (0, 0) + im.size, 0, RAWMODE[im_out.mode])])
|
563 |
+
|
564 |
+
fp.write(b"\0") # end of image data
|
565 |
+
|
566 |
+
|
567 |
+
def _getbbox(base_im, im_frame):
|
568 |
+
if _get_palette_bytes(im_frame) == _get_palette_bytes(base_im):
|
569 |
+
delta = ImageChops.subtract_modulo(im_frame, base_im)
|
570 |
+
else:
|
571 |
+
delta = ImageChops.subtract_modulo(
|
572 |
+
im_frame.convert("RGB"), base_im.convert("RGB")
|
573 |
+
)
|
574 |
+
return delta.getbbox()
|
575 |
+
|
576 |
+
|
577 |
+
def _write_multiple_frames(im, fp, palette):
|
578 |
+
duration = im.encoderinfo.get("duration")
|
579 |
+
disposal = im.encoderinfo.get("disposal", im.info.get("disposal"))
|
580 |
+
|
581 |
+
im_frames = []
|
582 |
+
frame_count = 0
|
583 |
+
background_im = None
|
584 |
+
for imSequence in itertools.chain([im], im.encoderinfo.get("append_images", [])):
|
585 |
+
for im_frame in ImageSequence.Iterator(imSequence):
|
586 |
+
# a copy is required here since seek can still mutate the image
|
587 |
+
im_frame = _normalize_mode(im_frame.copy())
|
588 |
+
if frame_count == 0:
|
589 |
+
for k, v in im_frame.info.items():
|
590 |
+
if k == "transparency":
|
591 |
+
continue
|
592 |
+
im.encoderinfo.setdefault(k, v)
|
593 |
+
|
594 |
+
encoderinfo = im.encoderinfo.copy()
|
595 |
+
im_frame = _normalize_palette(im_frame, palette, encoderinfo)
|
596 |
+
if "transparency" in im_frame.info:
|
597 |
+
encoderinfo.setdefault("transparency", im_frame.info["transparency"])
|
598 |
+
if isinstance(duration, (list, tuple)):
|
599 |
+
encoderinfo["duration"] = duration[frame_count]
|
600 |
+
elif duration is None and "duration" in im_frame.info:
|
601 |
+
encoderinfo["duration"] = im_frame.info["duration"]
|
602 |
+
if isinstance(disposal, (list, tuple)):
|
603 |
+
encoderinfo["disposal"] = disposal[frame_count]
|
604 |
+
frame_count += 1
|
605 |
+
|
606 |
+
if im_frames:
|
607 |
+
# delta frame
|
608 |
+
previous = im_frames[-1]
|
609 |
+
bbox = _getbbox(previous["im"], im_frame)
|
610 |
+
if not bbox:
|
611 |
+
# This frame is identical to the previous frame
|
612 |
+
if encoderinfo.get("duration"):
|
613 |
+
previous["encoderinfo"]["duration"] += encoderinfo["duration"]
|
614 |
+
continue
|
615 |
+
if encoderinfo.get("disposal") == 2:
|
616 |
+
if background_im is None:
|
617 |
+
color = im.encoderinfo.get(
|
618 |
+
"transparency", im.info.get("transparency", (0, 0, 0))
|
619 |
+
)
|
620 |
+
background = _get_background(im_frame, color)
|
621 |
+
background_im = Image.new("P", im_frame.size, background)
|
622 |
+
background_im.putpalette(im_frames[0]["im"].palette)
|
623 |
+
bbox = _getbbox(background_im, im_frame)
|
624 |
+
else:
|
625 |
+
bbox = None
|
626 |
+
im_frames.append({"im": im_frame, "bbox": bbox, "encoderinfo": encoderinfo})
|
627 |
+
|
628 |
+
if len(im_frames) > 1:
|
629 |
+
for frame_data in im_frames:
|
630 |
+
im_frame = frame_data["im"]
|
631 |
+
if not frame_data["bbox"]:
|
632 |
+
# global header
|
633 |
+
for s in _get_global_header(im_frame, frame_data["encoderinfo"]):
|
634 |
+
fp.write(s)
|
635 |
+
offset = (0, 0)
|
636 |
+
else:
|
637 |
+
# compress difference
|
638 |
+
if not palette:
|
639 |
+
frame_data["encoderinfo"]["include_color_table"] = True
|
640 |
+
|
641 |
+
im_frame = im_frame.crop(frame_data["bbox"])
|
642 |
+
offset = frame_data["bbox"][:2]
|
643 |
+
_write_frame_data(fp, im_frame, offset, frame_data["encoderinfo"])
|
644 |
+
return True
|
645 |
+
elif "duration" in im.encoderinfo and isinstance(
|
646 |
+
im.encoderinfo["duration"], (list, tuple)
|
647 |
+
):
|
648 |
+
# Since multiple frames will not be written, add together the frame durations
|
649 |
+
im.encoderinfo["duration"] = sum(im.encoderinfo["duration"])
|
650 |
+
|
651 |
+
|
652 |
+
def _save_all(im, fp, filename):
|
653 |
+
_save(im, fp, filename, save_all=True)
|
654 |
+
|
655 |
+
|
656 |
+
def _save(im, fp, filename, save_all=False):
|
657 |
+
# header
|
658 |
+
if "palette" in im.encoderinfo or "palette" in im.info:
|
659 |
+
palette = im.encoderinfo.get("palette", im.info.get("palette"))
|
660 |
+
else:
|
661 |
+
palette = None
|
662 |
+
im.encoderinfo["optimize"] = im.encoderinfo.get("optimize", True)
|
663 |
+
|
664 |
+
if not save_all or not _write_multiple_frames(im, fp, palette):
|
665 |
+
_write_single_frame(im, fp, palette)
|
666 |
+
|
667 |
+
fp.write(b";") # end of file
|
668 |
+
|
669 |
+
if hasattr(fp, "flush"):
|
670 |
+
fp.flush()
|
671 |
+
|
672 |
+
|
673 |
+
def get_interlace(im):
|
674 |
+
interlace = im.encoderinfo.get("interlace", 1)
|
675 |
+
|
676 |
+
# workaround for @PIL153
|
677 |
+
if min(im.size) < 16:
|
678 |
+
interlace = 0
|
679 |
+
|
680 |
+
return interlace
|
681 |
+
|
682 |
+
|
683 |
+
def _write_local_header(fp, im, offset, flags):
|
684 |
+
transparent_color_exists = False
|
685 |
+
try:
|
686 |
+
if "transparency" in im.encoderinfo:
|
687 |
+
transparency = im.encoderinfo["transparency"]
|
688 |
+
else:
|
689 |
+
transparency = im.info["transparency"]
|
690 |
+
transparency = int(transparency)
|
691 |
+
except (KeyError, ValueError):
|
692 |
+
pass
|
693 |
+
else:
|
694 |
+
# optimize the block away if transparent color is not used
|
695 |
+
transparent_color_exists = True
|
696 |
+
|
697 |
+
used_palette_colors = _get_optimize(im, im.encoderinfo)
|
698 |
+
if used_palette_colors is not None:
|
699 |
+
# adjust the transparency index after optimize
|
700 |
+
try:
|
701 |
+
transparency = used_palette_colors.index(transparency)
|
702 |
+
except ValueError:
|
703 |
+
transparent_color_exists = False
|
704 |
+
|
705 |
+
if "duration" in im.encoderinfo:
|
706 |
+
duration = int(im.encoderinfo["duration"] / 10)
|
707 |
+
else:
|
708 |
+
duration = 0
|
709 |
+
|
710 |
+
disposal = int(im.encoderinfo.get("disposal", 0))
|
711 |
+
|
712 |
+
if transparent_color_exists or duration != 0 or disposal:
|
713 |
+
packed_flag = 1 if transparent_color_exists else 0
|
714 |
+
packed_flag |= disposal << 2
|
715 |
+
if not transparent_color_exists:
|
716 |
+
transparency = 0
|
717 |
+
|
718 |
+
fp.write(
|
719 |
+
b"!"
|
720 |
+
+ o8(249) # extension intro
|
721 |
+
+ o8(4) # length
|
722 |
+
+ o8(packed_flag) # packed fields
|
723 |
+
+ o16(duration) # duration
|
724 |
+
+ o8(transparency) # transparency index
|
725 |
+
+ o8(0)
|
726 |
+
)
|
727 |
+
|
728 |
+
include_color_table = im.encoderinfo.get("include_color_table")
|
729 |
+
if include_color_table:
|
730 |
+
palette_bytes = _get_palette_bytes(im)
|
731 |
+
color_table_size = _get_color_table_size(palette_bytes)
|
732 |
+
if color_table_size:
|
733 |
+
flags = flags | 128 # local color table flag
|
734 |
+
flags = flags | color_table_size
|
735 |
+
|
736 |
+
fp.write(
|
737 |
+
b","
|
738 |
+
+ o16(offset[0]) # offset
|
739 |
+
+ o16(offset[1])
|
740 |
+
+ o16(im.size[0]) # size
|
741 |
+
+ o16(im.size[1])
|
742 |
+
+ o8(flags) # flags
|
743 |
+
)
|
744 |
+
if include_color_table and color_table_size:
|
745 |
+
fp.write(_get_header_palette(palette_bytes))
|
746 |
+
fp.write(o8(8)) # bits
|
747 |
+
|
748 |
+
|
749 |
+
def _save_netpbm(im, fp, filename):
|
750 |
+
# Unused by default.
|
751 |
+
# To use, uncomment the register_save call at the end of the file.
|
752 |
+
#
|
753 |
+
# If you need real GIF compression and/or RGB quantization, you
|
754 |
+
# can use the external NETPBM/PBMPLUS utilities. See comments
|
755 |
+
# below for information on how to enable this.
|
756 |
+
tempfile = im._dump()
|
757 |
+
|
758 |
+
try:
|
759 |
+
with open(filename, "wb") as f:
|
760 |
+
if im.mode != "RGB":
|
761 |
+
subprocess.check_call(
|
762 |
+
["ppmtogif", tempfile], stdout=f, stderr=subprocess.DEVNULL
|
763 |
+
)
|
764 |
+
else:
|
765 |
+
# Pipe ppmquant output into ppmtogif
|
766 |
+
# "ppmquant 256 %s | ppmtogif > %s" % (tempfile, filename)
|
767 |
+
quant_cmd = ["ppmquant", "256", tempfile]
|
768 |
+
togif_cmd = ["ppmtogif"]
|
769 |
+
quant_proc = subprocess.Popen(
|
770 |
+
quant_cmd, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL
|
771 |
+
)
|
772 |
+
togif_proc = subprocess.Popen(
|
773 |
+
togif_cmd,
|
774 |
+
stdin=quant_proc.stdout,
|
775 |
+
stdout=f,
|
776 |
+
stderr=subprocess.DEVNULL,
|
777 |
+
)
|
778 |
+
|
779 |
+
# Allow ppmquant to receive SIGPIPE if ppmtogif exits
|
780 |
+
quant_proc.stdout.close()
|
781 |
+
|
782 |
+
retcode = quant_proc.wait()
|
783 |
+
if retcode:
|
784 |
+
raise subprocess.CalledProcessError(retcode, quant_cmd)
|
785 |
+
|
786 |
+
retcode = togif_proc.wait()
|
787 |
+
if retcode:
|
788 |
+
raise subprocess.CalledProcessError(retcode, togif_cmd)
|
789 |
+
finally:
|
790 |
+
try:
|
791 |
+
os.unlink(tempfile)
|
792 |
+
except OSError:
|
793 |
+
pass
|
794 |
+
|
795 |
+
|
796 |
+
# Force optimization so that we can test performance against
|
797 |
+
# cases where it took lots of memory and time previously.
|
798 |
+
_FORCE_OPTIMIZE = False
|
799 |
+
|
800 |
+
|
801 |
+
def _get_optimize(im, info):
|
802 |
+
"""
|
803 |
+
Palette optimization is a potentially expensive operation.
|
804 |
+
|
805 |
+
This function determines if the palette should be optimized using
|
806 |
+
some heuristics, then returns the list of palette entries in use.
|
807 |
+
|
808 |
+
:param im: Image object
|
809 |
+
:param info: encoderinfo
|
810 |
+
:returns: list of indexes of palette entries in use, or None
|
811 |
+
"""
|
812 |
+
if im.mode in ("P", "L") and info and info.get("optimize", 0):
|
813 |
+
# Potentially expensive operation.
|
814 |
+
|
815 |
+
# The palette saves 3 bytes per color not used, but palette
|
816 |
+
# lengths are restricted to 3*(2**N) bytes. Max saving would
|
817 |
+
# be 768 -> 6 bytes if we went all the way down to 2 colors.
|
818 |
+
# * If we're over 128 colors, we can't save any space.
|
819 |
+
# * If there aren't any holes, it's not worth collapsing.
|
820 |
+
# * If we have a 'large' image, the palette is in the noise.
|
821 |
+
|
822 |
+
# create the new palette if not every color is used
|
823 |
+
optimise = _FORCE_OPTIMIZE or im.mode == "L"
|
824 |
+
if optimise or im.width * im.height < 512 * 512:
|
825 |
+
# check which colors are used
|
826 |
+
used_palette_colors = []
|
827 |
+
for i, count in enumerate(im.histogram()):
|
828 |
+
if count:
|
829 |
+
used_palette_colors.append(i)
|
830 |
+
|
831 |
+
if optimise or max(used_palette_colors) >= len(used_palette_colors):
|
832 |
+
return used_palette_colors
|
833 |
+
|
834 |
+
num_palette_colors = len(im.palette.palette) // Image.getmodebands(
|
835 |
+
im.palette.mode
|
836 |
+
)
|
837 |
+
current_palette_size = 1 << (num_palette_colors - 1).bit_length()
|
838 |
+
if (
|
839 |
+
# check that the palette would become smaller when saved
|
840 |
+
len(used_palette_colors) <= current_palette_size // 2
|
841 |
+
# check that the palette is not already the smallest possible size
|
842 |
+
and current_palette_size > 2
|
843 |
+
):
|
844 |
+
return used_palette_colors
|
845 |
+
|
846 |
+
|
847 |
+
def _get_color_table_size(palette_bytes):
|
848 |
+
# calculate the palette size for the header
|
849 |
+
if not palette_bytes:
|
850 |
+
return 0
|
851 |
+
elif len(palette_bytes) < 9:
|
852 |
+
return 1
|
853 |
+
else:
|
854 |
+
return math.ceil(math.log(len(palette_bytes) // 3, 2)) - 1
|
855 |
+
|
856 |
+
|
857 |
+
def _get_header_palette(palette_bytes):
|
858 |
+
"""
|
859 |
+
Returns the palette, null padded to the next power of 2 (*3) bytes
|
860 |
+
suitable for direct inclusion in the GIF header
|
861 |
+
|
862 |
+
:param palette_bytes: Unpadded palette bytes, in RGBRGB form
|
863 |
+
:returns: Null padded palette
|
864 |
+
"""
|
865 |
+
color_table_size = _get_color_table_size(palette_bytes)
|
866 |
+
|
867 |
+
# add the missing amount of bytes
|
868 |
+
# the palette has to be 2<<n in size
|
869 |
+
actual_target_size_diff = (2 << color_table_size) - len(palette_bytes) // 3
|
870 |
+
if actual_target_size_diff > 0:
|
871 |
+
palette_bytes += o8(0) * 3 * actual_target_size_diff
|
872 |
+
return palette_bytes
|
873 |
+
|
874 |
+
|
875 |
+
def _get_palette_bytes(im):
|
876 |
+
"""
|
877 |
+
Gets the palette for inclusion in the gif header
|
878 |
+
|
879 |
+
:param im: Image object
|
880 |
+
:returns: Bytes, len<=768 suitable for inclusion in gif header
|
881 |
+
"""
|
882 |
+
return im.palette.palette
|
883 |
+
|
884 |
+
|
885 |
+
def _get_background(im, info_background):
|
886 |
+
background = 0
|
887 |
+
if info_background:
|
888 |
+
if isinstance(info_background, tuple):
|
889 |
+
# WebPImagePlugin stores an RGBA value in info["background"]
|
890 |
+
# So it must be converted to the same format as GifImagePlugin's
|
891 |
+
# info["background"] - a global color table index
|
892 |
+
try:
|
893 |
+
background = im.palette.getcolor(info_background, im)
|
894 |
+
except ValueError as e:
|
895 |
+
if str(e) not in (
|
896 |
+
# If all 256 colors are in use,
|
897 |
+
# then there is no need for the background color
|
898 |
+
"cannot allocate more than 256 colors",
|
899 |
+
# Ignore non-opaque WebP background
|
900 |
+
"cannot add non-opaque RGBA color to RGB palette",
|
901 |
+
):
|
902 |
+
raise
|
903 |
+
else:
|
904 |
+
background = info_background
|
905 |
+
return background
|
906 |
+
|
907 |
+
|
908 |
+
def _get_global_header(im, info):
|
909 |
+
"""Return a list of strings representing a GIF header"""
|
910 |
+
|
911 |
+
# Header Block
|
912 |
+
# https://www.matthewflickinger.com/lab/whatsinagif/bits_and_bytes.asp
|
913 |
+
|
914 |
+
version = b"87a"
|
915 |
+
if im.info.get("version") == b"89a" or (
|
916 |
+
info
|
917 |
+
and (
|
918 |
+
"transparency" in info
|
919 |
+
or "loop" in info
|
920 |
+
or info.get("duration")
|
921 |
+
or info.get("comment")
|
922 |
+
)
|
923 |
+
):
|
924 |
+
version = b"89a"
|
925 |
+
|
926 |
+
background = _get_background(im, info.get("background"))
|
927 |
+
|
928 |
+
palette_bytes = _get_palette_bytes(im)
|
929 |
+
color_table_size = _get_color_table_size(palette_bytes)
|
930 |
+
|
931 |
+
header = [
|
932 |
+
b"GIF" # signature
|
933 |
+
+ version # version
|
934 |
+
+ o16(im.size[0]) # canvas width
|
935 |
+
+ o16(im.size[1]), # canvas height
|
936 |
+
# Logical Screen Descriptor
|
937 |
+
# size of global color table + global color table flag
|
938 |
+
o8(color_table_size + 128), # packed fields
|
939 |
+
# background + reserved/aspect
|
940 |
+
o8(background) + o8(0),
|
941 |
+
# Global Color Table
|
942 |
+
_get_header_palette(palette_bytes),
|
943 |
+
]
|
944 |
+
if "loop" in info:
|
945 |
+
header.append(
|
946 |
+
b"!"
|
947 |
+
+ o8(255) # extension intro
|
948 |
+
+ o8(11)
|
949 |
+
+ b"NETSCAPE2.0"
|
950 |
+
+ o8(3)
|
951 |
+
+ o8(1)
|
952 |
+
+ o16(info["loop"]) # number of loops
|
953 |
+
+ o8(0)
|
954 |
+
)
|
955 |
+
if info.get("comment"):
|
956 |
+
comment_block = b"!" + o8(254) # extension intro
|
957 |
+
|
958 |
+
comment = info["comment"]
|
959 |
+
if isinstance(comment, str):
|
960 |
+
comment = comment.encode()
|
961 |
+
for i in range(0, len(comment), 255):
|
962 |
+
subblock = comment[i : i + 255]
|
963 |
+
comment_block += o8(len(subblock)) + subblock
|
964 |
+
|
965 |
+
comment_block += o8(0)
|
966 |
+
header.append(comment_block)
|
967 |
+
return header
|
968 |
+
|
969 |
+
|
970 |
+
def _write_frame_data(fp, im_frame, offset, params):
|
971 |
+
try:
|
972 |
+
im_frame.encoderinfo = params
|
973 |
+
|
974 |
+
# local image header
|
975 |
+
_write_local_header(fp, im_frame, offset, 0)
|
976 |
+
|
977 |
+
ImageFile._save(
|
978 |
+
im_frame, fp, [("gif", (0, 0) + im_frame.size, 0, RAWMODE[im_frame.mode])]
|
979 |
+
)
|
980 |
+
|
981 |
+
fp.write(b"\0") # end of image data
|
982 |
+
finally:
|
983 |
+
del im_frame.encoderinfo
|
984 |
+
|
985 |
+
|
986 |
+
# --------------------------------------------------------------------
|
987 |
+
# Legacy GIF utilities
|
988 |
+
|
989 |
+
|
990 |
+
def getheader(im, palette=None, info=None):
|
991 |
+
"""
|
992 |
+
Legacy Method to get Gif data from image.
|
993 |
+
|
994 |
+
Warning:: May modify image data.
|
995 |
+
|
996 |
+
:param im: Image object
|
997 |
+
:param palette: bytes object containing the source palette, or ....
|
998 |
+
:param info: encoderinfo
|
999 |
+
:returns: tuple of(list of header items, optimized palette)
|
1000 |
+
|
1001 |
+
"""
|
1002 |
+
used_palette_colors = _get_optimize(im, info)
|
1003 |
+
|
1004 |
+
if info is None:
|
1005 |
+
info = {}
|
1006 |
+
|
1007 |
+
if "background" not in info and "background" in im.info:
|
1008 |
+
info["background"] = im.info["background"]
|
1009 |
+
|
1010 |
+
im_mod = _normalize_palette(im, palette, info)
|
1011 |
+
im.palette = im_mod.palette
|
1012 |
+
im.im = im_mod.im
|
1013 |
+
header = _get_global_header(im, info)
|
1014 |
+
|
1015 |
+
return header, used_palette_colors
|
1016 |
+
|
1017 |
+
|
1018 |
+
def getdata(im, offset=(0, 0), **params):
|
1019 |
+
"""
|
1020 |
+
Legacy Method
|
1021 |
+
|
1022 |
+
Return a list of strings representing this image.
|
1023 |
+
The first string is a local image header, the rest contains
|
1024 |
+
encoded image data.
|
1025 |
+
|
1026 |
+
To specify duration, add the time in milliseconds,
|
1027 |
+
e.g. ``getdata(im_frame, duration=1000)``
|
1028 |
+
|
1029 |
+
:param im: Image object
|
1030 |
+
:param offset: Tuple of (x, y) pixels. Defaults to (0, 0)
|
1031 |
+
:param \\**params: e.g. duration or other encoder info parameters
|
1032 |
+
:returns: List of bytes containing GIF encoded frame data
|
1033 |
+
|
1034 |
+
"""
|
1035 |
+
|
1036 |
+
class Collector:
|
1037 |
+
data = []
|
1038 |
+
|
1039 |
+
def write(self, data):
|
1040 |
+
self.data.append(data)
|
1041 |
+
|
1042 |
+
im.load() # make sure raster data is available
|
1043 |
+
|
1044 |
+
fp = Collector()
|
1045 |
+
|
1046 |
+
_write_frame_data(fp, im, offset, params)
|
1047 |
+
|
1048 |
+
return fp.data
|
1049 |
+
|
1050 |
+
|
1051 |
+
# --------------------------------------------------------------------
|
1052 |
+
# Registry
|
1053 |
+
|
1054 |
+
Image.register_open(GifImageFile.format, GifImageFile, _accept)
|
1055 |
+
Image.register_save(GifImageFile.format, _save)
|
1056 |
+
Image.register_save_all(GifImageFile.format, _save_all)
|
1057 |
+
Image.register_extension(GifImageFile.format, ".gif")
|
1058 |
+
Image.register_mime(GifImageFile.format, "image/gif")
|
1059 |
+
|
1060 |
+
#
|
1061 |
+
# Uncomment the following line if you wish to use NETPBM/PBMPLUS
|
1062 |
+
# instead of the built-in "uncompressed" GIF encoder
|
1063 |
+
|
1064 |
+
# Image.register_save(GifImageFile.format, _save_netpbm)
|