Upload folder using huggingface_hub
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +12 -0
- .pytest_cache/.gitignore +2 -0
- .pytest_cache/CACHEDIR.TAG +4 -0
- .pytest_cache/README.md +8 -0
- .pytest_cache/v/cache/lastfailed +1 -0
- .pytest_cache/v/cache/nodeids +23 -0
- .venv/bin/Activate.ps1 +247 -0
- .venv/bin/activate +70 -0
- .venv/bin/activate.csh +27 -0
- .venv/bin/activate.fish +69 -0
- .venv/bin/f2py +8 -0
- .venv/bin/find_similar_images.py +82 -0
- .venv/bin/fonttools +8 -0
- .venv/bin/ftfy +8 -0
- .venv/bin/httpx +8 -0
- .venv/bin/idna +8 -0
- .venv/bin/isympy +8 -0
- .venv/bin/normalizer +8 -0
- .venv/bin/numpy-config +8 -0
- .venv/bin/pip +8 -0
- .venv/bin/pip3 +8 -0
- .venv/bin/pip3.12 +8 -0
- .venv/bin/py.test +8 -0
- .venv/bin/pyav +8 -0
- .venv/bin/pydeprecate +8 -0
- .venv/bin/pyftmerge +8 -0
- .venv/bin/pyftsubset +8 -0
- .venv/bin/pygmentize +8 -0
- .venv/bin/pytest +8 -0
- .venv/bin/python +3 -0
- .venv/bin/python3 +3 -0
- .venv/bin/python3.12 +3 -0
- .venv/bin/torchfrtrace +8 -0
- .venv/bin/torchrun +8 -0
- .venv/bin/tqdm +8 -0
- .venv/bin/ttx +8 -0
- .venv/bin/ul +8 -0
- .venv/bin/ultralytics +8 -0
- .venv/bin/yolo +8 -0
- .venv/images/imagehash.png +3 -0
- .venv/lib/python3.12/site-packages/ImageHash-4.3.2.dist-info/INSTALLER +1 -0
- .venv/lib/python3.12/site-packages/ImageHash-4.3.2.dist-info/LICENSE +10 -0
- .venv/lib/python3.12/site-packages/ImageHash-4.3.2.dist-info/METADATA +221 -0
- .venv/lib/python3.12/site-packages/ImageHash-4.3.2.dist-info/RECORD +13 -0
- .venv/lib/python3.12/site-packages/ImageHash-4.3.2.dist-info/REQUESTED +0 -0
- .venv/lib/python3.12/site-packages/ImageHash-4.3.2.dist-info/WHEEL +6 -0
- .venv/lib/python3.12/site-packages/ImageHash-4.3.2.dist-info/top_level.txt +1 -0
- .venv/lib/python3.12/site-packages/PIL/AvifImagePlugin.py +295 -0
- .venv/lib/python3.12/site-packages/PIL/BdfFontFile.py +124 -0
- .venv/lib/python3.12/site-packages/PIL/BlpImagePlugin.py +498 -0
.gitattributes
CHANGED
|
@@ -58,3 +58,15 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 58 |
# Video files - compressed
|
| 59 |
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 60 |
*.webm filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
# Video files - compressed
|
| 59 |
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 60 |
*.webm filter=lfs diff=lfs merge=lfs -text
|
| 61 |
+
.venv/bin/python filter=lfs diff=lfs merge=lfs -text
|
| 62 |
+
.venv/bin/python3 filter=lfs diff=lfs merge=lfs -text
|
| 63 |
+
.venv/bin/python3.12 filter=lfs diff=lfs merge=lfs -text
|
| 64 |
+
.venv/lib/python3.12/site-packages/PIL/__pycache__/Image.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
|
| 65 |
+
.venv/lib/python3.12/site-packages/PIL/__pycache__/TiffImagePlugin.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
|
| 66 |
+
.venv/lib/python3.12/site-packages/PIL/_imaging.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 67 |
+
.venv/lib/python3.12/site-packages/PIL/_imagingcms.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 68 |
+
.venv/lib/python3.12/site-packages/PIL/_imagingft.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 69 |
+
.venv/lib/python3.12/site-packages/PIL/_imagingmath.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 70 |
+
.venv/lib/python3.12/site-packages/PIL/_webp.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 71 |
+
.venv/lib/python3.12/site-packages/__pycache__/pynvml.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
|
| 72 |
+
.venv/lib/python3.12/site-packages/__pycache__/typing_extensions.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
|
.pytest_cache/.gitignore
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Created by pytest automatically.
|
| 2 |
+
*
|
.pytest_cache/CACHEDIR.TAG
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Signature: 8a477f597d28d172789f06886806bc55
|
| 2 |
+
# This file is a cache directory tag created by pytest.
|
| 3 |
+
# For information about cache directory tags, see:
|
| 4 |
+
# https://bford.info/cachedir/spec.html
|
.pytest_cache/README.md
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# pytest cache directory #
|
| 2 |
+
|
| 3 |
+
This directory contains data from the pytest's cache plugin,
|
| 4 |
+
which provides the `--lf` and `--ff` options, as well as the `cache` fixture.
|
| 5 |
+
|
| 6 |
+
**Do not** commit this to version control.
|
| 7 |
+
|
| 8 |
+
See [the docs](https://docs.pytest.org/en/stable/how-to/cache.html) for more information.
|
.pytest_cache/v/cache/lastfailed
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{}
|
.pytest_cache/v/cache/nodeids
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
"tests/test_pipeline.py::TestPipeline::test_ai_metadata_validation",
|
| 3 |
+
"tests/test_pipeline.py::TestPipeline::test_cli_all_subcommand_parser",
|
| 4 |
+
"tests/test_pipeline.py::TestPipeline::test_cli_auto_subcommand_parser",
|
| 5 |
+
"tests/test_pipeline.py::TestPipeline::test_cli_split_subcommand_parser",
|
| 6 |
+
"tests/test_pipeline.py::TestPipeline::test_dedup_hashes",
|
| 7 |
+
"tests/test_pipeline.py::TestPipeline::test_manifest_image_lifecycle",
|
| 8 |
+
"tests/test_pipeline.py::TestPipeline::test_manifest_sources_and_hits",
|
| 9 |
+
"tests/test_pipeline.py::TestPipeline::test_processor",
|
| 10 |
+
"tests/test_pipeline.py::TestPipeline::test_query_builder",
|
| 11 |
+
"tests/test_pipeline.py::TestPipeline::test_splitter",
|
| 12 |
+
"tests/test_pipeline.py::TestPipeline::test_url_normalization",
|
| 13 |
+
"tests/test_pipeline.py::TestPipeline::test_validator",
|
| 14 |
+
"tests/test_purity_assay.py::test_bis_discrepancy_bands",
|
| 15 |
+
"tests/test_purity_assay.py::test_category_scrap_grade_floors",
|
| 16 |
+
"tests/test_purity_assay.py::test_desoldered_fraud_penalty[1-75.0]",
|
| 17 |
+
"tests/test_purity_assay.py::test_desoldered_fraud_penalty[2-50.0]",
|
| 18 |
+
"tests/test_purity_assay.py::test_desoldered_fraud_penalty[4-0.0]",
|
| 19 |
+
"tests/test_purity_assay.py::test_factory_unpopulated_pad_no_penalty",
|
| 20 |
+
"tests/test_purity_assay.py::test_pcb_analyzer_end_to_end",
|
| 21 |
+
"tests/test_purity_assay.py::test_pristine_board_integrity_score",
|
| 22 |
+
"tests/test_purity_assay.py::test_vernacular_voice_alerts"
|
| 23 |
+
]
|
.venv/bin/Activate.ps1
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<#
|
| 2 |
+
.Synopsis
|
| 3 |
+
Activate a Python virtual environment for the current PowerShell session.
|
| 4 |
+
|
| 5 |
+
.Description
|
| 6 |
+
Pushes the python executable for a virtual environment to the front of the
|
| 7 |
+
$Env:PATH environment variable and sets the prompt to signify that you are
|
| 8 |
+
in a Python virtual environment. Makes use of the command line switches as
|
| 9 |
+
well as the `pyvenv.cfg` file values present in the virtual environment.
|
| 10 |
+
|
| 11 |
+
.Parameter VenvDir
|
| 12 |
+
Path to the directory that contains the virtual environment to activate. The
|
| 13 |
+
default value for this is the parent of the directory that the Activate.ps1
|
| 14 |
+
script is located within.
|
| 15 |
+
|
| 16 |
+
.Parameter Prompt
|
| 17 |
+
The prompt prefix to display when this virtual environment is activated. By
|
| 18 |
+
default, this prompt is the name of the virtual environment folder (VenvDir)
|
| 19 |
+
surrounded by parentheses and followed by a single space (ie. '(.venv) ').
|
| 20 |
+
|
| 21 |
+
.Example
|
| 22 |
+
Activate.ps1
|
| 23 |
+
Activates the Python virtual environment that contains the Activate.ps1 script.
|
| 24 |
+
|
| 25 |
+
.Example
|
| 26 |
+
Activate.ps1 -Verbose
|
| 27 |
+
Activates the Python virtual environment that contains the Activate.ps1 script,
|
| 28 |
+
and shows extra information about the activation as it executes.
|
| 29 |
+
|
| 30 |
+
.Example
|
| 31 |
+
Activate.ps1 -VenvDir C:\Users\MyUser\Common\.venv
|
| 32 |
+
Activates the Python virtual environment located in the specified location.
|
| 33 |
+
|
| 34 |
+
.Example
|
| 35 |
+
Activate.ps1 -Prompt "MyPython"
|
| 36 |
+
Activates the Python virtual environment that contains the Activate.ps1 script,
|
| 37 |
+
and prefixes the current prompt with the specified string (surrounded in
|
| 38 |
+
parentheses) while the virtual environment is active.
|
| 39 |
+
|
| 40 |
+
.Notes
|
| 41 |
+
On Windows, it may be required to enable this Activate.ps1 script by setting the
|
| 42 |
+
execution policy for the user. You can do this by issuing the following PowerShell
|
| 43 |
+
command:
|
| 44 |
+
|
| 45 |
+
PS C:\> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
|
| 46 |
+
|
| 47 |
+
For more information on Execution Policies:
|
| 48 |
+
https://go.microsoft.com/fwlink/?LinkID=135170
|
| 49 |
+
|
| 50 |
+
#>
|
| 51 |
+
Param(
|
| 52 |
+
[Parameter(Mandatory = $false)]
|
| 53 |
+
[String]
|
| 54 |
+
$VenvDir,
|
| 55 |
+
[Parameter(Mandatory = $false)]
|
| 56 |
+
[String]
|
| 57 |
+
$Prompt
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
<# Function declarations --------------------------------------------------- #>
|
| 61 |
+
|
| 62 |
+
<#
|
| 63 |
+
.Synopsis
|
| 64 |
+
Remove all shell session elements added by the Activate script, including the
|
| 65 |
+
addition of the virtual environment's Python executable from the beginning of
|
| 66 |
+
the PATH variable.
|
| 67 |
+
|
| 68 |
+
.Parameter NonDestructive
|
| 69 |
+
If present, do not remove this function from the global namespace for the
|
| 70 |
+
session.
|
| 71 |
+
|
| 72 |
+
#>
|
| 73 |
+
function global:deactivate ([switch]$NonDestructive) {
|
| 74 |
+
# Revert to original values
|
| 75 |
+
|
| 76 |
+
# The prior prompt:
|
| 77 |
+
if (Test-Path -Path Function:_OLD_VIRTUAL_PROMPT) {
|
| 78 |
+
Copy-Item -Path Function:_OLD_VIRTUAL_PROMPT -Destination Function:prompt
|
| 79 |
+
Remove-Item -Path Function:_OLD_VIRTUAL_PROMPT
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
# The prior PYTHONHOME:
|
| 83 |
+
if (Test-Path -Path Env:_OLD_VIRTUAL_PYTHONHOME) {
|
| 84 |
+
Copy-Item -Path Env:_OLD_VIRTUAL_PYTHONHOME -Destination Env:PYTHONHOME
|
| 85 |
+
Remove-Item -Path Env:_OLD_VIRTUAL_PYTHONHOME
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
# The prior PATH:
|
| 89 |
+
if (Test-Path -Path Env:_OLD_VIRTUAL_PATH) {
|
| 90 |
+
Copy-Item -Path Env:_OLD_VIRTUAL_PATH -Destination Env:PATH
|
| 91 |
+
Remove-Item -Path Env:_OLD_VIRTUAL_PATH
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
# Just remove the VIRTUAL_ENV altogether:
|
| 95 |
+
if (Test-Path -Path Env:VIRTUAL_ENV) {
|
| 96 |
+
Remove-Item -Path env:VIRTUAL_ENV
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
# Just remove VIRTUAL_ENV_PROMPT altogether.
|
| 100 |
+
if (Test-Path -Path Env:VIRTUAL_ENV_PROMPT) {
|
| 101 |
+
Remove-Item -Path env:VIRTUAL_ENV_PROMPT
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
# Just remove the _PYTHON_VENV_PROMPT_PREFIX altogether:
|
| 105 |
+
if (Get-Variable -Name "_PYTHON_VENV_PROMPT_PREFIX" -ErrorAction SilentlyContinue) {
|
| 106 |
+
Remove-Variable -Name _PYTHON_VENV_PROMPT_PREFIX -Scope Global -Force
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
# Leave deactivate function in the global namespace if requested:
|
| 110 |
+
if (-not $NonDestructive) {
|
| 111 |
+
Remove-Item -Path function:deactivate
|
| 112 |
+
}
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
<#
|
| 116 |
+
.Description
|
| 117 |
+
Get-PyVenvConfig parses the values from the pyvenv.cfg file located in the
|
| 118 |
+
given folder, and returns them in a map.
|
| 119 |
+
|
| 120 |
+
For each line in the pyvenv.cfg file, if that line can be parsed into exactly
|
| 121 |
+
two strings separated by `=` (with any amount of whitespace surrounding the =)
|
| 122 |
+
then it is considered a `key = value` line. The left hand string is the key,
|
| 123 |
+
the right hand is the value.
|
| 124 |
+
|
| 125 |
+
If the value starts with a `'` or a `"` then the first and last character is
|
| 126 |
+
stripped from the value before being captured.
|
| 127 |
+
|
| 128 |
+
.Parameter ConfigDir
|
| 129 |
+
Path to the directory that contains the `pyvenv.cfg` file.
|
| 130 |
+
#>
|
| 131 |
+
function Get-PyVenvConfig(
|
| 132 |
+
[String]
|
| 133 |
+
$ConfigDir
|
| 134 |
+
) {
|
| 135 |
+
Write-Verbose "Given ConfigDir=$ConfigDir, obtain values in pyvenv.cfg"
|
| 136 |
+
|
| 137 |
+
# Ensure the file exists, and issue a warning if it doesn't (but still allow the function to continue).
|
| 138 |
+
$pyvenvConfigPath = Join-Path -Resolve -Path $ConfigDir -ChildPath 'pyvenv.cfg' -ErrorAction Continue
|
| 139 |
+
|
| 140 |
+
# An empty map will be returned if no config file is found.
|
| 141 |
+
$pyvenvConfig = @{ }
|
| 142 |
+
|
| 143 |
+
if ($pyvenvConfigPath) {
|
| 144 |
+
|
| 145 |
+
Write-Verbose "File exists, parse `key = value` lines"
|
| 146 |
+
$pyvenvConfigContent = Get-Content -Path $pyvenvConfigPath
|
| 147 |
+
|
| 148 |
+
$pyvenvConfigContent | ForEach-Object {
|
| 149 |
+
$keyval = $PSItem -split "\s*=\s*", 2
|
| 150 |
+
if ($keyval[0] -and $keyval[1]) {
|
| 151 |
+
$val = $keyval[1]
|
| 152 |
+
|
| 153 |
+
# Remove extraneous quotations around a string value.
|
| 154 |
+
if ("'""".Contains($val.Substring(0, 1))) {
|
| 155 |
+
$val = $val.Substring(1, $val.Length - 2)
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
$pyvenvConfig[$keyval[0]] = $val
|
| 159 |
+
Write-Verbose "Adding Key: '$($keyval[0])'='$val'"
|
| 160 |
+
}
|
| 161 |
+
}
|
| 162 |
+
}
|
| 163 |
+
return $pyvenvConfig
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
<# Begin Activate script --------------------------------------------------- #>
|
| 168 |
+
|
| 169 |
+
# Determine the containing directory of this script
|
| 170 |
+
$VenvExecPath = Split-Path -Parent $MyInvocation.MyCommand.Definition
|
| 171 |
+
$VenvExecDir = Get-Item -Path $VenvExecPath
|
| 172 |
+
|
| 173 |
+
Write-Verbose "Activation script is located in path: '$VenvExecPath'"
|
| 174 |
+
Write-Verbose "VenvExecDir Fullname: '$($VenvExecDir.FullName)"
|
| 175 |
+
Write-Verbose "VenvExecDir Name: '$($VenvExecDir.Name)"
|
| 176 |
+
|
| 177 |
+
# Set values required in priority: CmdLine, ConfigFile, Default
|
| 178 |
+
# First, get the location of the virtual environment, it might not be
|
| 179 |
+
# VenvExecDir if specified on the command line.
|
| 180 |
+
if ($VenvDir) {
|
| 181 |
+
Write-Verbose "VenvDir given as parameter, using '$VenvDir' to determine values"
|
| 182 |
+
}
|
| 183 |
+
else {
|
| 184 |
+
Write-Verbose "VenvDir not given as a parameter, using parent directory name as VenvDir."
|
| 185 |
+
$VenvDir = $VenvExecDir.Parent.FullName.TrimEnd("\\/")
|
| 186 |
+
Write-Verbose "VenvDir=$VenvDir"
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
# Next, read the `pyvenv.cfg` file to determine any required value such
|
| 190 |
+
# as `prompt`.
|
| 191 |
+
$pyvenvCfg = Get-PyVenvConfig -ConfigDir $VenvDir
|
| 192 |
+
|
| 193 |
+
# Next, set the prompt from the command line, or the config file, or
|
| 194 |
+
# just use the name of the virtual environment folder.
|
| 195 |
+
if ($Prompt) {
|
| 196 |
+
Write-Verbose "Prompt specified as argument, using '$Prompt'"
|
| 197 |
+
}
|
| 198 |
+
else {
|
| 199 |
+
Write-Verbose "Prompt not specified as argument to script, checking pyvenv.cfg value"
|
| 200 |
+
if ($pyvenvCfg -and $pyvenvCfg['prompt']) {
|
| 201 |
+
Write-Verbose " Setting based on value in pyvenv.cfg='$($pyvenvCfg['prompt'])'"
|
| 202 |
+
$Prompt = $pyvenvCfg['prompt'];
|
| 203 |
+
}
|
| 204 |
+
else {
|
| 205 |
+
Write-Verbose " Setting prompt based on parent's directory's name. (Is the directory name passed to venv module when creating the virtual environment)"
|
| 206 |
+
Write-Verbose " Got leaf-name of $VenvDir='$(Split-Path -Path $venvDir -Leaf)'"
|
| 207 |
+
$Prompt = Split-Path -Path $venvDir -Leaf
|
| 208 |
+
}
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
Write-Verbose "Prompt = '$Prompt'"
|
| 212 |
+
Write-Verbose "VenvDir='$VenvDir'"
|
| 213 |
+
|
| 214 |
+
# Deactivate any currently active virtual environment, but leave the
|
| 215 |
+
# deactivate function in place.
|
| 216 |
+
deactivate -nondestructive
|
| 217 |
+
|
| 218 |
+
# Now set the environment variable VIRTUAL_ENV, used by many tools to determine
|
| 219 |
+
# that there is an activated venv.
|
| 220 |
+
$env:VIRTUAL_ENV = $VenvDir
|
| 221 |
+
|
| 222 |
+
if (-not $Env:VIRTUAL_ENV_DISABLE_PROMPT) {
|
| 223 |
+
|
| 224 |
+
Write-Verbose "Setting prompt to '$Prompt'"
|
| 225 |
+
|
| 226 |
+
# Set the prompt to include the env name
|
| 227 |
+
# Make sure _OLD_VIRTUAL_PROMPT is global
|
| 228 |
+
function global:_OLD_VIRTUAL_PROMPT { "" }
|
| 229 |
+
Copy-Item -Path function:prompt -Destination function:_OLD_VIRTUAL_PROMPT
|
| 230 |
+
New-Variable -Name _PYTHON_VENV_PROMPT_PREFIX -Description "Python virtual environment prompt prefix" -Scope Global -Option ReadOnly -Visibility Public -Value $Prompt
|
| 231 |
+
|
| 232 |
+
function global:prompt {
|
| 233 |
+
Write-Host -NoNewline -ForegroundColor Green "($_PYTHON_VENV_PROMPT_PREFIX) "
|
| 234 |
+
_OLD_VIRTUAL_PROMPT
|
| 235 |
+
}
|
| 236 |
+
$env:VIRTUAL_ENV_PROMPT = $Prompt
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
# Clear PYTHONHOME
|
| 240 |
+
if (Test-Path -Path Env:PYTHONHOME) {
|
| 241 |
+
Copy-Item -Path Env:PYTHONHOME -Destination Env:_OLD_VIRTUAL_PYTHONHOME
|
| 242 |
+
Remove-Item -Path Env:PYTHONHOME
|
| 243 |
+
}
|
| 244 |
+
|
| 245 |
+
# Add the venv to the PATH
|
| 246 |
+
Copy-Item -Path Env:PATH -Destination Env:_OLD_VIRTUAL_PATH
|
| 247 |
+
$Env:PATH = "$VenvExecDir$([System.IO.Path]::PathSeparator)$Env:PATH"
|
.venv/bin/activate
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This file must be used with "source bin/activate" *from bash*
|
| 2 |
+
# You cannot run it directly
|
| 3 |
+
|
| 4 |
+
deactivate () {
|
| 5 |
+
# reset old environment variables
|
| 6 |
+
if [ -n "${_OLD_VIRTUAL_PATH:-}" ] ; then
|
| 7 |
+
PATH="${_OLD_VIRTUAL_PATH:-}"
|
| 8 |
+
export PATH
|
| 9 |
+
unset _OLD_VIRTUAL_PATH
|
| 10 |
+
fi
|
| 11 |
+
if [ -n "${_OLD_VIRTUAL_PYTHONHOME:-}" ] ; then
|
| 12 |
+
PYTHONHOME="${_OLD_VIRTUAL_PYTHONHOME:-}"
|
| 13 |
+
export PYTHONHOME
|
| 14 |
+
unset _OLD_VIRTUAL_PYTHONHOME
|
| 15 |
+
fi
|
| 16 |
+
|
| 17 |
+
# Call hash to forget past commands. Without forgetting
|
| 18 |
+
# past commands the $PATH changes we made may not be respected
|
| 19 |
+
hash -r 2> /dev/null
|
| 20 |
+
|
| 21 |
+
if [ -n "${_OLD_VIRTUAL_PS1:-}" ] ; then
|
| 22 |
+
PS1="${_OLD_VIRTUAL_PS1:-}"
|
| 23 |
+
export PS1
|
| 24 |
+
unset _OLD_VIRTUAL_PS1
|
| 25 |
+
fi
|
| 26 |
+
|
| 27 |
+
unset VIRTUAL_ENV
|
| 28 |
+
unset VIRTUAL_ENV_PROMPT
|
| 29 |
+
if [ ! "${1:-}" = "nondestructive" ] ; then
|
| 30 |
+
# Self destruct!
|
| 31 |
+
unset -f deactivate
|
| 32 |
+
fi
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
# unset irrelevant variables
|
| 36 |
+
deactivate nondestructive
|
| 37 |
+
|
| 38 |
+
# on Windows, a path can contain colons and backslashes and has to be converted:
|
| 39 |
+
if [ "${OSTYPE:-}" = "cygwin" ] || [ "${OSTYPE:-}" = "msys" ] ; then
|
| 40 |
+
# transform D:\path\to\venv to /d/path/to/venv on MSYS
|
| 41 |
+
# and to /cygdrive/d/path/to/venv on Cygwin
|
| 42 |
+
export VIRTUAL_ENV=$(cygpath /home/taruns/Downloads/scraper/.venv)
|
| 43 |
+
else
|
| 44 |
+
# use the path as-is
|
| 45 |
+
export VIRTUAL_ENV=/home/taruns/Downloads/scraper/.venv
|
| 46 |
+
fi
|
| 47 |
+
|
| 48 |
+
_OLD_VIRTUAL_PATH="$PATH"
|
| 49 |
+
PATH="$VIRTUAL_ENV/"bin":$PATH"
|
| 50 |
+
export PATH
|
| 51 |
+
|
| 52 |
+
# unset PYTHONHOME if set
|
| 53 |
+
# this will fail if PYTHONHOME is set to the empty string (which is bad anyway)
|
| 54 |
+
# could use `if (set -u; : $PYTHONHOME) ;` in bash
|
| 55 |
+
if [ -n "${PYTHONHOME:-}" ] ; then
|
| 56 |
+
_OLD_VIRTUAL_PYTHONHOME="${PYTHONHOME:-}"
|
| 57 |
+
unset PYTHONHOME
|
| 58 |
+
fi
|
| 59 |
+
|
| 60 |
+
if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT:-}" ] ; then
|
| 61 |
+
_OLD_VIRTUAL_PS1="${PS1:-}"
|
| 62 |
+
PS1='(.venv) '"${PS1:-}"
|
| 63 |
+
export PS1
|
| 64 |
+
VIRTUAL_ENV_PROMPT='(.venv) '
|
| 65 |
+
export VIRTUAL_ENV_PROMPT
|
| 66 |
+
fi
|
| 67 |
+
|
| 68 |
+
# Call hash to forget past commands. Without forgetting
|
| 69 |
+
# past commands the $PATH changes we made may not be respected
|
| 70 |
+
hash -r 2> /dev/null
|
.venv/bin/activate.csh
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This file must be used with "source bin/activate.csh" *from csh*.
|
| 2 |
+
# You cannot run it directly.
|
| 3 |
+
|
| 4 |
+
# Created by Davide Di Blasi <davidedb@gmail.com>.
|
| 5 |
+
# Ported to Python 3.3 venv by Andrew Svetlov <andrew.svetlov@gmail.com>
|
| 6 |
+
|
| 7 |
+
alias deactivate 'test $?_OLD_VIRTUAL_PATH != 0 && setenv PATH "$_OLD_VIRTUAL_PATH" && unset _OLD_VIRTUAL_PATH; rehash; test $?_OLD_VIRTUAL_PROMPT != 0 && set prompt="$_OLD_VIRTUAL_PROMPT" && unset _OLD_VIRTUAL_PROMPT; unsetenv VIRTUAL_ENV; unsetenv VIRTUAL_ENV_PROMPT; test "\!:*" != "nondestructive" && unalias deactivate'
|
| 8 |
+
|
| 9 |
+
# Unset irrelevant variables.
|
| 10 |
+
deactivate nondestructive
|
| 11 |
+
|
| 12 |
+
setenv VIRTUAL_ENV /home/taruns/Downloads/scraper/.venv
|
| 13 |
+
|
| 14 |
+
set _OLD_VIRTUAL_PATH="$PATH"
|
| 15 |
+
setenv PATH "$VIRTUAL_ENV/"bin":$PATH"
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
set _OLD_VIRTUAL_PROMPT="$prompt"
|
| 19 |
+
|
| 20 |
+
if (! "$?VIRTUAL_ENV_DISABLE_PROMPT") then
|
| 21 |
+
set prompt = '(.venv) '"$prompt"
|
| 22 |
+
setenv VIRTUAL_ENV_PROMPT '(.venv) '
|
| 23 |
+
endif
|
| 24 |
+
|
| 25 |
+
alias pydoc python -m pydoc
|
| 26 |
+
|
| 27 |
+
rehash
|
.venv/bin/activate.fish
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This file must be used with "source <venv>/bin/activate.fish" *from fish*
|
| 2 |
+
# (https://fishshell.com/). You cannot run it directly.
|
| 3 |
+
|
| 4 |
+
function deactivate -d "Exit virtual environment and return to normal shell environment"
|
| 5 |
+
# reset old environment variables
|
| 6 |
+
if test -n "$_OLD_VIRTUAL_PATH"
|
| 7 |
+
set -gx PATH $_OLD_VIRTUAL_PATH
|
| 8 |
+
set -e _OLD_VIRTUAL_PATH
|
| 9 |
+
end
|
| 10 |
+
if test -n "$_OLD_VIRTUAL_PYTHONHOME"
|
| 11 |
+
set -gx PYTHONHOME $_OLD_VIRTUAL_PYTHONHOME
|
| 12 |
+
set -e _OLD_VIRTUAL_PYTHONHOME
|
| 13 |
+
end
|
| 14 |
+
|
| 15 |
+
if test -n "$_OLD_FISH_PROMPT_OVERRIDE"
|
| 16 |
+
set -e _OLD_FISH_PROMPT_OVERRIDE
|
| 17 |
+
# prevents error when using nested fish instances (Issue #93858)
|
| 18 |
+
if functions -q _old_fish_prompt
|
| 19 |
+
functions -e fish_prompt
|
| 20 |
+
functions -c _old_fish_prompt fish_prompt
|
| 21 |
+
functions -e _old_fish_prompt
|
| 22 |
+
end
|
| 23 |
+
end
|
| 24 |
+
|
| 25 |
+
set -e VIRTUAL_ENV
|
| 26 |
+
set -e VIRTUAL_ENV_PROMPT
|
| 27 |
+
if test "$argv[1]" != "nondestructive"
|
| 28 |
+
# Self-destruct!
|
| 29 |
+
functions -e deactivate
|
| 30 |
+
end
|
| 31 |
+
end
|
| 32 |
+
|
| 33 |
+
# Unset irrelevant variables.
|
| 34 |
+
deactivate nondestructive
|
| 35 |
+
|
| 36 |
+
set -gx VIRTUAL_ENV /home/taruns/Downloads/scraper/.venv
|
| 37 |
+
|
| 38 |
+
set -gx _OLD_VIRTUAL_PATH $PATH
|
| 39 |
+
set -gx PATH "$VIRTUAL_ENV/"bin $PATH
|
| 40 |
+
|
| 41 |
+
# Unset PYTHONHOME if set.
|
| 42 |
+
if set -q PYTHONHOME
|
| 43 |
+
set -gx _OLD_VIRTUAL_PYTHONHOME $PYTHONHOME
|
| 44 |
+
set -e PYTHONHOME
|
| 45 |
+
end
|
| 46 |
+
|
| 47 |
+
if test -z "$VIRTUAL_ENV_DISABLE_PROMPT"
|
| 48 |
+
# fish uses a function instead of an env var to generate the prompt.
|
| 49 |
+
|
| 50 |
+
# Save the current fish_prompt function as the function _old_fish_prompt.
|
| 51 |
+
functions -c fish_prompt _old_fish_prompt
|
| 52 |
+
|
| 53 |
+
# With the original prompt function renamed, we can override with our own.
|
| 54 |
+
function fish_prompt
|
| 55 |
+
# Save the return status of the last command.
|
| 56 |
+
set -l old_status $status
|
| 57 |
+
|
| 58 |
+
# Output the venv prompt; color taken from the blue of the Python logo.
|
| 59 |
+
printf "%s%s%s" (set_color 4B8BBE) '(.venv) ' (set_color normal)
|
| 60 |
+
|
| 61 |
+
# Restore the return status of the previous command.
|
| 62 |
+
echo "exit $old_status" | .
|
| 63 |
+
# Output the original/"old" prompt.
|
| 64 |
+
_old_fish_prompt
|
| 65 |
+
end
|
| 66 |
+
|
| 67 |
+
set -gx _OLD_FISH_PROMPT_OVERRIDE "$VIRTUAL_ENV"
|
| 68 |
+
set -gx VIRTUAL_ENV_PROMPT '(.venv) '
|
| 69 |
+
end
|
.venv/bin/f2py
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/home/taruns/Downloads/scraper/.venv/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from numpy.f2py.f2py2e import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
.venv/bin/find_similar_images.py
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/home/taruns/Downloads/scraper/.venv/bin/python3
|
| 2 |
+
from __future__ import absolute_import, division, print_function
|
| 3 |
+
|
| 4 |
+
from PIL import Image
|
| 5 |
+
|
| 6 |
+
import imagehash
|
| 7 |
+
|
| 8 |
+
"""
|
| 9 |
+
Demo of hashing
|
| 10 |
+
"""
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def find_similar_images(userpaths, hashfunc=imagehash.average_hash):
|
| 14 |
+
def is_image(filename):
|
| 15 |
+
f = filename.lower()
|
| 16 |
+
return f.endswith('.png') or f.endswith('.jpg') or \
|
| 17 |
+
f.endswith('.jpeg') or f.endswith('.bmp') or \
|
| 18 |
+
f.endswith('.gif') or '.jpg' in f or f.endswith('.svg')
|
| 19 |
+
|
| 20 |
+
image_filenames = []
|
| 21 |
+
for userpath in userpaths:
|
| 22 |
+
image_filenames += [os.path.join(userpath, path) for path in os.listdir(userpath) if is_image(path)]
|
| 23 |
+
images = {}
|
| 24 |
+
for img in sorted(image_filenames):
|
| 25 |
+
try:
|
| 26 |
+
hash = hashfunc(Image.open(img))
|
| 27 |
+
except Exception as e:
|
| 28 |
+
print('Problem:', e, 'with', img)
|
| 29 |
+
continue
|
| 30 |
+
if hash in images:
|
| 31 |
+
print(img, ' already exists as', ' '.join(images[hash]))
|
| 32 |
+
if 'dupPictures' in img:
|
| 33 |
+
print('rm -v', img)
|
| 34 |
+
images[hash] = images.get(hash, []) + [img]
|
| 35 |
+
|
| 36 |
+
# for k, img_list in six.iteritems(images):
|
| 37 |
+
# if len(img_list) > 1:
|
| 38 |
+
# print(" ".join(img_list))
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
if __name__ == '__main__': # noqa: C901
|
| 42 |
+
import os
|
| 43 |
+
import sys
|
| 44 |
+
|
| 45 |
+
def usage():
|
| 46 |
+
sys.stderr.write("""SYNOPSIS: %s [ahash|phash|dhash|...] [<directory>]
|
| 47 |
+
|
| 48 |
+
Identifies similar images in the directory.
|
| 49 |
+
|
| 50 |
+
Method:
|
| 51 |
+
ahash: Average hash
|
| 52 |
+
phash: Perceptual hash
|
| 53 |
+
dhash: Difference hash
|
| 54 |
+
whash-haar: Haar wavelet hash
|
| 55 |
+
whash-db4: Daubechies wavelet hash
|
| 56 |
+
colorhash: HSV color hash
|
| 57 |
+
crop-resistant: Crop-resistant hash
|
| 58 |
+
|
| 59 |
+
(C) Johannes Buchner, 2013-2017
|
| 60 |
+
""" % sys.argv[0])
|
| 61 |
+
sys.exit(1)
|
| 62 |
+
|
| 63 |
+
hashmethod = sys.argv[1] if len(sys.argv) > 1 else usage()
|
| 64 |
+
if hashmethod == 'ahash':
|
| 65 |
+
hashfunc = imagehash.average_hash
|
| 66 |
+
elif hashmethod == 'phash':
|
| 67 |
+
hashfunc = imagehash.phash
|
| 68 |
+
elif hashmethod == 'dhash':
|
| 69 |
+
hashfunc = imagehash.dhash
|
| 70 |
+
elif hashmethod == 'whash-haar':
|
| 71 |
+
hashfunc = imagehash.whash
|
| 72 |
+
elif hashmethod == 'whash-db4':
|
| 73 |
+
def hashfunc(img):
|
| 74 |
+
return imagehash.whash(img, mode='db4')
|
| 75 |
+
elif hashmethod == 'colorhash':
|
| 76 |
+
hashfunc = imagehash.colorhash
|
| 77 |
+
elif hashmethod == 'crop-resistant':
|
| 78 |
+
hashfunc = imagehash.crop_resistant_hash
|
| 79 |
+
else:
|
| 80 |
+
usage()
|
| 81 |
+
userpaths = sys.argv[2:] if len(sys.argv) > 2 else '.'
|
| 82 |
+
find_similar_images(userpaths=userpaths, hashfunc=hashfunc)
|
.venv/bin/fonttools
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/home/taruns/Downloads/scraper/.venv/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from fontTools.__main__ import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
.venv/bin/ftfy
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/home/taruns/Downloads/scraper/.venv/bin/python
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from ftfy.cli import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
.venv/bin/httpx
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/home/taruns/Downloads/scraper/.venv/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from httpx import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
.venv/bin/idna
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/home/taruns/Downloads/scraper/.venv/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from idna.cli import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
.venv/bin/isympy
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/home/taruns/Downloads/scraper/.venv/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from isympy import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
.venv/bin/normalizer
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/home/taruns/Downloads/scraper/.venv/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from charset_normalizer.cli import cli_detect
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(cli_detect())
|
.venv/bin/numpy-config
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/home/taruns/Downloads/scraper/.venv/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from numpy._configtool import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
.venv/bin/pip
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/home/taruns/Downloads/scraper/.venv/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from pip._internal.cli.main import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
.venv/bin/pip3
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/home/taruns/Downloads/scraper/.venv/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from pip._internal.cli.main import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
.venv/bin/pip3.12
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/home/taruns/Downloads/scraper/.venv/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from pip._internal.cli.main import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
.venv/bin/py.test
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/home/taruns/Downloads/scraper/.venv/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from _pytest.config import _console_main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(_console_main())
|
.venv/bin/pyav
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/home/taruns/Downloads/scraper/.venv/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from av.__main__ import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
.venv/bin/pydeprecate
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/home/taruns/Downloads/scraper/.venv/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from deprecate._cli import cli
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(cli())
|
.venv/bin/pyftmerge
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/home/taruns/Downloads/scraper/.venv/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from fontTools.merge import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
.venv/bin/pyftsubset
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/home/taruns/Downloads/scraper/.venv/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from fontTools.subset import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
.venv/bin/pygmentize
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/home/taruns/Downloads/scraper/.venv/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from pygments.cmdline import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
.venv/bin/pytest
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/home/taruns/Downloads/scraper/.venv/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from _pytest.config import _console_main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(_console_main())
|
.venv/bin/python
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e50d468e8b0adfb05733f5b87b3cff34829c4a8c1aea50c865aa8bdfe4bb150f
|
| 3 |
+
size 8020928
|
.venv/bin/python3
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e50d468e8b0adfb05733f5b87b3cff34829c4a8c1aea50c865aa8bdfe4bb150f
|
| 3 |
+
size 8020928
|
.venv/bin/python3.12
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e50d468e8b0adfb05733f5b87b3cff34829c4a8c1aea50c865aa8bdfe4bb150f
|
| 3 |
+
size 8020928
|
.venv/bin/torchfrtrace
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/home/taruns/Downloads/scraper/.venv/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from torch.distributed.flight_recorder.fr_trace import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
.venv/bin/torchrun
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/home/taruns/Downloads/scraper/.venv/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from torch.distributed.run import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
.venv/bin/tqdm
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/home/taruns/Downloads/scraper/.venv/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from tqdm.cli import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
.venv/bin/ttx
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/home/taruns/Downloads/scraper/.venv/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from fontTools.ttx import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
.venv/bin/ul
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/home/taruns/Downloads/scraper/.venv/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from ultralytics_platform.cli import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
.venv/bin/ultralytics
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/home/taruns/Downloads/scraper/.venv/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from ultralytics.cfg import entrypoint
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(entrypoint())
|
.venv/bin/yolo
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/home/taruns/Downloads/scraper/.venv/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from ultralytics.cfg import entrypoint
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(entrypoint())
|
.venv/images/imagehash.png
ADDED
|
Git LFS Details
|
.venv/lib/python3.12/site-packages/ImageHash-4.3.2.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
pip
|
.venv/lib/python3.12/site-packages/ImageHash-4.3.2.dist-info/LICENSE
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Copyright (c) 2013-2022, Johannes Buchner
|
| 2 |
+
All rights reserved.
|
| 3 |
+
|
| 4 |
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
| 5 |
+
|
| 6 |
+
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
| 7 |
+
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
| 8 |
+
|
| 9 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 10 |
+
|
.venv/lib/python3.12/site-packages/ImageHash-4.3.2.dist-info/METADATA
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.1
|
| 2 |
+
Name: ImageHash
|
| 3 |
+
Version: 4.3.2
|
| 4 |
+
Summary: Image Hashing library
|
| 5 |
+
Home-page: https://github.com/JohannesBuchner/imagehash
|
| 6 |
+
Author: Johannes Buchner
|
| 7 |
+
Author-email: buchner.johannes@gmx.at
|
| 8 |
+
License: 2-clause BSD License
|
| 9 |
+
Description-Content-Type: text/x-rst
|
| 10 |
+
License-File: LICENSE
|
| 11 |
+
Requires-Dist: PyWavelets
|
| 12 |
+
Requires-Dist: numpy
|
| 13 |
+
Requires-Dist: pillow
|
| 14 |
+
Requires-Dist: scipy
|
| 15 |
+
|
| 16 |
+
===========
|
| 17 |
+
ImageHash
|
| 18 |
+
===========
|
| 19 |
+
|
| 20 |
+
An image hashing library written in Python. ImageHash supports:
|
| 21 |
+
|
| 22 |
+
* Average hashing
|
| 23 |
+
* Perceptual hashing
|
| 24 |
+
* Difference hashing
|
| 25 |
+
* Wavelet hashing
|
| 26 |
+
* HSV color hashing (colorhash)
|
| 27 |
+
* Crop-resistant hashing
|
| 28 |
+
|
| 29 |
+
|CI|_ |Coveralls|_
|
| 30 |
+
|
| 31 |
+
Rationale
|
| 32 |
+
=========
|
| 33 |
+
|
| 34 |
+
Image hashes tell whether two images look nearly identical.
|
| 35 |
+
This is different from cryptographic hashing algorithms (like MD5, SHA-1)
|
| 36 |
+
where tiny changes in the image give completely different hashes.
|
| 37 |
+
In image fingerprinting, we actually want our similar inputs to have
|
| 38 |
+
similar output hashes as well.
|
| 39 |
+
|
| 40 |
+
The image hash algorithms (average, perceptual, difference, wavelet)
|
| 41 |
+
analyse the image structure on luminance (without color information).
|
| 42 |
+
The color hash algorithm analyses the color distribution and
|
| 43 |
+
black & gray fractions (without position information).
|
| 44 |
+
|
| 45 |
+
Installation
|
| 46 |
+
============
|
| 47 |
+
|
| 48 |
+
Based on PIL/Pillow Image, numpy and scipy.fftpack (for pHash)
|
| 49 |
+
Easy installation through `pypi`_::
|
| 50 |
+
|
| 51 |
+
pip install imagehash
|
| 52 |
+
|
| 53 |
+
Basic usage
|
| 54 |
+
===========
|
| 55 |
+
::
|
| 56 |
+
|
| 57 |
+
>>> from PIL import Image
|
| 58 |
+
>>> import imagehash
|
| 59 |
+
>>> hash = imagehash.average_hash(Image.open('tests/data/imagehash.png'))
|
| 60 |
+
>>> print(hash)
|
| 61 |
+
ffd7918181c9ffff
|
| 62 |
+
>>> otherhash = imagehash.average_hash(Image.open('tests/data/peppers.png'))
|
| 63 |
+
>>> print(otherhash)
|
| 64 |
+
9f172786e71f1e00
|
| 65 |
+
>>> print(hash == otherhash)
|
| 66 |
+
False
|
| 67 |
+
>>> print(hash - otherhash) # hamming distance
|
| 68 |
+
33
|
| 69 |
+
|
| 70 |
+
Each algorithm can also have its hash size adjusted (or in the case of
|
| 71 |
+
colorhash, its :code:`binbits`). Increasing the hash size allows an
|
| 72 |
+
algorithm to store more detail in its hash, increasing its sensitivity
|
| 73 |
+
to changes in detail.
|
| 74 |
+
|
| 75 |
+
The demo script **find_similar_images** illustrates how to find similar
|
| 76 |
+
images in a directory.
|
| 77 |
+
|
| 78 |
+
Source hosted at GitHub: https://github.com/JohannesBuchner/imagehash
|
| 79 |
+
|
| 80 |
+
References
|
| 81 |
+
-----------
|
| 82 |
+
|
| 83 |
+
* Average hashing (`aHashref`_)
|
| 84 |
+
* Perceptual hashing (`pHashref`_)
|
| 85 |
+
* Difference hashing (`dHashref`_)
|
| 86 |
+
* Wavelet hashing (`wHashref`_)
|
| 87 |
+
* Crop-resistant hashing (`crop_resistant_hashref`_)
|
| 88 |
+
|
| 89 |
+
.. _aHashref: https://www.hackerfactor.com/blog/index.php?/archives/432-Looks-Like-It.html
|
| 90 |
+
.. _pHashref: https://www.hackerfactor.com/blog/index.php?/archives/432-Looks-Like-It.html
|
| 91 |
+
.. _dHashref: https://www.hackerfactor.com/blog/index.php?/archives/529-Kind-of-Like-That.html
|
| 92 |
+
.. _wHashref: https://fullstackml.com/2016/07/02/wavelet-image-hash-in-python/
|
| 93 |
+
.. _pypi: https://pypi.python.org/pypi/ImageHash
|
| 94 |
+
.. _crop_resistant_hashref: https://ieeexplore.ieee.org/document/6980335
|
| 95 |
+
|
| 96 |
+
Examples
|
| 97 |
+
=========
|
| 98 |
+
|
| 99 |
+
To help evaluate how different hashing algorithms behave, below are a few hashes applied
|
| 100 |
+
to two datasets. This will let you know what images an algorithm thinks are basically identical.
|
| 101 |
+
|
| 102 |
+
Example 1: Icon dataset
|
| 103 |
+
-----------------------
|
| 104 |
+
|
| 105 |
+
Source: 7441 free icons on GitHub (see examples/github-urls.txt).
|
| 106 |
+
|
| 107 |
+
The following pages show groups of images with the same hash (the hashing method sees them as the same).
|
| 108 |
+
|
| 109 |
+
* `phash <https://johannesbuchner.github.io/imagehash/index3.html>`__ (or `with z-transform <https://johannesbuchner.github.io/imagehash/index9.html>`__)
|
| 110 |
+
* `dhash <https://johannesbuchner.github.io/imagehash/index4.html>`__ (or `with z-transform <https://johannesbuchner.github.io/imagehash/index10.html>`__)
|
| 111 |
+
* `colorhash <https://johannesbuchner.github.io/imagehash/index7.html>`__
|
| 112 |
+
* `average_hash <https://johannesbuchner.github.io/imagehash/index2.html>`__ (`with z-transform <https://johannesbuchner.github.io/imagehash/index8.html>`__)
|
| 113 |
+
|
| 114 |
+
The hashes use hashsize=8; colorhash uses binbits=3.
|
| 115 |
+
You may want to adjust the hashsize or require some manhattan distance (hash1 - hash2 < threshold).
|
| 116 |
+
|
| 117 |
+
Example 2: Art dataset
|
| 118 |
+
----------------------
|
| 119 |
+
|
| 120 |
+
Source: 109259 art pieces from https://www.parismuseescollections.paris.fr/en/recherche/image-libre/.
|
| 121 |
+
|
| 122 |
+
The following pages show groups of images with the same hash (the hashing method sees them as the same).
|
| 123 |
+
|
| 124 |
+
* `phash <https://johannesbuchner.github.io/imagehash/art3.html>`__ (or `with z-transform <https://johannesbuchner.github.io/imagehash/art9.html>`__)
|
| 125 |
+
* `dhash <https://johannesbuchner.github.io/imagehash/art4.html>`__ (or `with z-transform <https://johannesbuchner.github.io/imagehash/art10.html>`__)
|
| 126 |
+
* `colorhash <https://johannesbuchner.github.io/imagehash/art7.html>`__
|
| 127 |
+
* `average_hash <https://johannesbuchner.github.io/imagehash/art2.html>`__ (`with z-transform <https://johannesbuchner.github.io/imagehash/art8.html>`__)
|
| 128 |
+
|
| 129 |
+
For understanding hash distances, check out these excellent blog posts:
|
| 130 |
+
* https://tech.okcupid.com/evaluating-perceptual-image-hashes-at-okcupid-e98a3e74aa3a
|
| 131 |
+
* https://content-blockchain.org/research/testing-different-image-hash-functions/
|
| 132 |
+
|
| 133 |
+
Storing hashes
|
| 134 |
+
==============
|
| 135 |
+
|
| 136 |
+
As illustrated above, hashes can be turned into strings.
|
| 137 |
+
The strings can be turned back into a ImageHash object as follows.
|
| 138 |
+
|
| 139 |
+
For single perceptual hashes::
|
| 140 |
+
|
| 141 |
+
>>> original_hash = imagehash.phash(Image.open('tests/data/imagehash.png'))
|
| 142 |
+
>>> hash_as_str = str(original_hash)
|
| 143 |
+
>>> print(hash_as_str)
|
| 144 |
+
ffd7918181c9ffff
|
| 145 |
+
>>> restored_hash = imagehash.hex_to_hash(hash_as_str)
|
| 146 |
+
>>> print(restored_hash)
|
| 147 |
+
ffd7918181c9ffff
|
| 148 |
+
>>> assert restored_hash == original_hash
|
| 149 |
+
>>> assert str(restored_hash) == hash_as_str
|
| 150 |
+
|
| 151 |
+
For crop_resistant_hash::
|
| 152 |
+
|
| 153 |
+
>>> original_hash = imagehash.crop_resistant_hash(Image.open('tests/data/imagehash.png'), min_segment_size=500, segmentation_image_size=1000)
|
| 154 |
+
>>> hash_as_str = str(original_hash)
|
| 155 |
+
>>> restored_hash = imagehash.hex_to_multihash(hash_as_str)
|
| 156 |
+
>>> assert restored_hash == original_hash
|
| 157 |
+
>>> assert str(restored_hash) == hash_as_str
|
| 158 |
+
|
| 159 |
+
For colorhash::
|
| 160 |
+
|
| 161 |
+
>>> original_hash = imagehash.colorhash(Image.open('tests/data/imagehash.png'), binbits=3)
|
| 162 |
+
>>> hash_as_str = str(original_hash)
|
| 163 |
+
>>> restored_hash = imagehash.hex_to_flathash(hash_as_str, hashsize=3)
|
| 164 |
+
|
| 165 |
+
Efficient database search
|
| 166 |
+
-------------------------
|
| 167 |
+
|
| 168 |
+
For storing the hashes in a database and using fast hamming distance
|
| 169 |
+
searches, see pointers at https://github.com/JohannesBuchner/imagehash/issues/127
|
| 170 |
+
(a blog post on how to do this would be a great contribution!)
|
| 171 |
+
|
| 172 |
+
@KDJDEV points to https://github.com/KDJDEV/imagehash-reverse-image-search-tutorial and writes:
|
| 173 |
+
In this tutorial I use PostgreSQL and `this extension <https://github.com/fake-name/pg-spgist_hamming>`_,
|
| 174 |
+
and show how you can create a reverse image search using hashes generated by this library.
|
| 175 |
+
|
| 176 |
+
|
| 177 |
+
Changelog
|
| 178 |
+
----------
|
| 179 |
+
|
| 180 |
+
* 4.3: typing annotations by @Avasam @SpangleLabs and @nh2
|
| 181 |
+
|
| 182 |
+
* 4.2: Cropping-Resistant image hashing added by @SpangleLabs
|
| 183 |
+
|
| 184 |
+
* 4.1: Add examples and colorhash
|
| 185 |
+
|
| 186 |
+
* 4.0: Changed binary to hex implementation, because the previous one was broken for various hash sizes. This change breaks compatibility to previously stored hashes; to convert them from the old encoding, use the "old_hex_to_hash" function.
|
| 187 |
+
|
| 188 |
+
* 3.5: Image data handling speed-up
|
| 189 |
+
|
| 190 |
+
* 3.2: whash now also handles smaller-than-hash images
|
| 191 |
+
|
| 192 |
+
* 3.0: dhash had a bug: It computed pixel differences vertically, not horizontally.
|
| 193 |
+
I modified it to follow `dHashref`_. The old function is available as dhash_vertical.
|
| 194 |
+
|
| 195 |
+
* 2.0: Added whash
|
| 196 |
+
|
| 197 |
+
* 1.0: Initial ahash, dhash, phash implementations.
|
| 198 |
+
|
| 199 |
+
Contributing
|
| 200 |
+
=============
|
| 201 |
+
|
| 202 |
+
Pull requests and new features are warmly welcome.
|
| 203 |
+
|
| 204 |
+
If you encounter a bug or have a question, please open a GitHub issue. You can also try Stack Overflow.
|
| 205 |
+
|
| 206 |
+
Other projects
|
| 207 |
+
==============
|
| 208 |
+
|
| 209 |
+
* https://github.com/commonsmachinery/blockhash-python
|
| 210 |
+
* https://github.com/acoomans/instagram-filters
|
| 211 |
+
* https://pippy360.github.io/transformationInvariantImageSearch/
|
| 212 |
+
* https://www.phash.org/
|
| 213 |
+
* https://pypi.org/project/dhash/
|
| 214 |
+
* https://github.com/thorn-oss/perception (based on imagehash code, depends on opencv)
|
| 215 |
+
* https://docs.opencv.org/3.4/d4/d93/group__img__hash.html
|
| 216 |
+
|
| 217 |
+
.. |CI| image:: https://github.com/JohannesBuchner/imagehash/actions/workflows/testing.yml/badge.svg
|
| 218 |
+
.. _CI: https://github.com/JohannesBuchner/imagehash/actions/workflows/testing.yml
|
| 219 |
+
|
| 220 |
+
.. |Coveralls| image:: https://coveralls.io/repos/github/JohannesBuchner/imagehash/badge.svg
|
| 221 |
+
.. _Coveralls: https://coveralls.io/github/JohannesBuchner/imagehash
|
.venv/lib/python3.12/site-packages/ImageHash-4.3.2.dist-info/RECORD
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
../../../bin/__pycache__/find_similar_images.cpython-312.pyc,,
|
| 2 |
+
../../../bin/find_similar_images.py,sha256=AQWzqhStcXQYO2du-SdOBRPTSdLBs1KabTG7N9OLatY,2272
|
| 3 |
+
../../../images/imagehash.png,sha256=NRNPYFhZRvuj5wXbVtSUEkG7F0IHqS4s1GSY76BVqTY,292247
|
| 4 |
+
ImageHash-4.3.2.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
| 5 |
+
ImageHash-4.3.2.dist-info/LICENSE,sha256=nQsDeFPa57z2sZtyhVmoM5k82HEPwYomHmAm5Wv3BL4,1302
|
| 6 |
+
ImageHash-4.3.2.dist-info/METADATA,sha256=DxeVzwTsq2TRFItYj5O3t_i4l-rJJuC1N988dL5N1dk,8391
|
| 7 |
+
ImageHash-4.3.2.dist-info/RECORD,,
|
| 8 |
+
ImageHash-4.3.2.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 9 |
+
ImageHash-4.3.2.dist-info/WHEEL,sha256=-G_t0oGuE7UD0DrSpVZnq1hHMBV9DD2XkS5v7XpmTnk,110
|
| 10 |
+
ImageHash-4.3.2.dist-info/top_level.txt,sha256=50BXQ_hiKLUM8Nh9bREcTIsLBl9-TggxRdi7bv2LYZg,10
|
| 11 |
+
imagehash/__init__.py,sha256=ZY8Jlx0wSVor2mol5_VqCHWmK00LjudWaZimPJxXz_g,25332
|
| 12 |
+
imagehash/__pycache__/__init__.cpython-312.pyc,,
|
| 13 |
+
imagehash/py.typed,sha256=sNJcSCznk4EDK7g4Y8Bdo8eFC1UeFKrL9sFIBvoFsOk,69
|
.venv/lib/python3.12/site-packages/ImageHash-4.3.2.dist-info/REQUESTED
ADDED
|
File without changes
|
.venv/lib/python3.12/site-packages/ImageHash-4.3.2.dist-info/WHEEL
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Wheel-Version: 1.0
|
| 2 |
+
Generator: bdist_wheel (0.42.0)
|
| 3 |
+
Root-Is-Purelib: true
|
| 4 |
+
Tag: py2-none-any
|
| 5 |
+
Tag: py3-none-any
|
| 6 |
+
|
.venv/lib/python3.12/site-packages/ImageHash-4.3.2.dist-info/top_level.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
imagehash
|
.venv/lib/python3.12/site-packages/PIL/AvifImagePlugin.py
ADDED
|
@@ -0,0 +1,295 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
from io import BytesIO
|
| 5 |
+
from typing import IO
|
| 6 |
+
|
| 7 |
+
from . import ExifTags, Image, ImageFile, ImageSequence
|
| 8 |
+
|
| 9 |
+
try:
|
| 10 |
+
from . import _avif
|
| 11 |
+
|
| 12 |
+
SUPPORTED = True
|
| 13 |
+
except ImportError:
|
| 14 |
+
SUPPORTED = False
|
| 15 |
+
|
| 16 |
+
# Decoder options as module globals, until there is a way to pass parameters
|
| 17 |
+
# to Image.open (see https://github.com/python-pillow/Pillow/issues/569)
|
| 18 |
+
DECODE_CODEC_CHOICE = "auto"
|
| 19 |
+
DEFAULT_MAX_THREADS = 0
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def get_codec_version(codec_name: str) -> str | None:
|
| 23 |
+
versions = _avif.codec_versions()
|
| 24 |
+
for version in versions.split(", "):
|
| 25 |
+
if version.split(" [")[0] == codec_name:
|
| 26 |
+
return version.split(":")[-1].split(" ")[0]
|
| 27 |
+
return None
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def _accept(prefix: bytes) -> bool | str:
|
| 31 |
+
if prefix[4:8] != b"ftyp":
|
| 32 |
+
return False
|
| 33 |
+
major_brand = prefix[8:12]
|
| 34 |
+
if major_brand in (
|
| 35 |
+
# coding brands
|
| 36 |
+
b"avif",
|
| 37 |
+
b"avis",
|
| 38 |
+
# We accept files with AVIF container brands; we can't yet know if
|
| 39 |
+
# the ftyp box has the correct compatible brands, but if it doesn't
|
| 40 |
+
# then the plugin will raise a SyntaxError which Pillow will catch
|
| 41 |
+
# before moving on to the next plugin that accepts the file.
|
| 42 |
+
#
|
| 43 |
+
# Also, because this file might not actually be an AVIF file, we
|
| 44 |
+
# don't raise an error if AVIF support isn't properly compiled.
|
| 45 |
+
b"mif1",
|
| 46 |
+
b"msf1",
|
| 47 |
+
):
|
| 48 |
+
if not SUPPORTED:
|
| 49 |
+
return (
|
| 50 |
+
"image file could not be identified because AVIF support not installed"
|
| 51 |
+
)
|
| 52 |
+
return True
|
| 53 |
+
return False
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def _get_default_max_threads() -> int:
|
| 57 |
+
if DEFAULT_MAX_THREADS:
|
| 58 |
+
return DEFAULT_MAX_THREADS
|
| 59 |
+
if hasattr(os, "sched_getaffinity"):
|
| 60 |
+
return len(os.sched_getaffinity(0))
|
| 61 |
+
else:
|
| 62 |
+
return os.cpu_count() or 1
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
class AvifImageFile(ImageFile.ImageFile):
|
| 66 |
+
format = "AVIF"
|
| 67 |
+
format_description = "AVIF image"
|
| 68 |
+
__frame = -1
|
| 69 |
+
|
| 70 |
+
def _open(self) -> None:
|
| 71 |
+
if not SUPPORTED:
|
| 72 |
+
msg = "image file could not be opened because AVIF support not installed"
|
| 73 |
+
raise SyntaxError(msg)
|
| 74 |
+
|
| 75 |
+
if DECODE_CODEC_CHOICE != "auto" and not _avif.decoder_codec_available(
|
| 76 |
+
DECODE_CODEC_CHOICE
|
| 77 |
+
):
|
| 78 |
+
msg = "Invalid opening codec"
|
| 79 |
+
raise ValueError(msg)
|
| 80 |
+
|
| 81 |
+
assert self.fp is not None
|
| 82 |
+
self._decoder = _avif.AvifDecoder(
|
| 83 |
+
self.fp.read(),
|
| 84 |
+
DECODE_CODEC_CHOICE,
|
| 85 |
+
_get_default_max_threads(),
|
| 86 |
+
)
|
| 87 |
+
|
| 88 |
+
# Get info from decoder
|
| 89 |
+
self._size, self.n_frames, self._mode, icc, exif, exif_orientation, xmp = (
|
| 90 |
+
self._decoder.get_info()
|
| 91 |
+
)
|
| 92 |
+
self.is_animated = self.n_frames > 1
|
| 93 |
+
|
| 94 |
+
if icc:
|
| 95 |
+
self.info["icc_profile"] = icc
|
| 96 |
+
if xmp:
|
| 97 |
+
self.info["xmp"] = xmp
|
| 98 |
+
|
| 99 |
+
if exif_orientation != 1 or exif:
|
| 100 |
+
exif_data = Image.Exif()
|
| 101 |
+
if exif:
|
| 102 |
+
exif_data.load(exif)
|
| 103 |
+
original_orientation = exif_data.get(ExifTags.Base.Orientation, 1)
|
| 104 |
+
else:
|
| 105 |
+
original_orientation = 1
|
| 106 |
+
if exif_orientation != original_orientation:
|
| 107 |
+
exif_data[ExifTags.Base.Orientation] = exif_orientation
|
| 108 |
+
exif = exif_data.tobytes()
|
| 109 |
+
if exif:
|
| 110 |
+
self.info["exif"] = exif
|
| 111 |
+
self.seek(0)
|
| 112 |
+
|
| 113 |
+
def seek(self, frame: int) -> None:
|
| 114 |
+
if not self._seek_check(frame):
|
| 115 |
+
return
|
| 116 |
+
|
| 117 |
+
# Set tile
|
| 118 |
+
self.__frame = frame
|
| 119 |
+
self.tile = [ImageFile._Tile("raw", (0, 0) + self.size, 0, self.mode)]
|
| 120 |
+
|
| 121 |
+
def load(self) -> Image.core.PixelAccess | None:
|
| 122 |
+
if self.tile:
|
| 123 |
+
# We need to load the image data for this frame
|
| 124 |
+
data, timescale, pts_in_timescales, duration_in_timescales = (
|
| 125 |
+
self._decoder.get_frame(self.__frame)
|
| 126 |
+
)
|
| 127 |
+
self.info["timestamp"] = round(1000 * (pts_in_timescales / timescale))
|
| 128 |
+
self.info["duration"] = round(1000 * (duration_in_timescales / timescale))
|
| 129 |
+
|
| 130 |
+
if self.fp and self._exclusive_fp:
|
| 131 |
+
self.fp.close()
|
| 132 |
+
self.fp = BytesIO(data)
|
| 133 |
+
|
| 134 |
+
return super().load()
|
| 135 |
+
|
| 136 |
+
def load_seek(self, pos: int) -> None:
|
| 137 |
+
pass
|
| 138 |
+
|
| 139 |
+
def tell(self) -> int:
|
| 140 |
+
return self.__frame
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
def _save_all(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None:
|
| 144 |
+
_save(im, fp, filename, save_all=True)
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
def _save(
|
| 148 |
+
im: Image.Image, fp: IO[bytes], filename: str | bytes, save_all: bool = False
|
| 149 |
+
) -> None:
|
| 150 |
+
info = im.encoderinfo.copy()
|
| 151 |
+
if save_all:
|
| 152 |
+
append_images = list(info.get("append_images", []))
|
| 153 |
+
else:
|
| 154 |
+
append_images = []
|
| 155 |
+
|
| 156 |
+
grayscale_modes = {"1", "L", "I", "I;16", "I;16L", "I;16B", "I;16N", "F"}
|
| 157 |
+
grayscale = all(
|
| 158 |
+
frame.mode in grayscale_modes
|
| 159 |
+
for ims in [im] + append_images
|
| 160 |
+
for frame in ImageSequence.Iterator(ims)
|
| 161 |
+
)
|
| 162 |
+
|
| 163 |
+
quality = info.get("quality", 75)
|
| 164 |
+
if not isinstance(quality, int) or quality < 0 or quality > 100:
|
| 165 |
+
msg = "Invalid quality setting"
|
| 166 |
+
raise ValueError(msg)
|
| 167 |
+
|
| 168 |
+
duration = info.get("duration", 0)
|
| 169 |
+
subsampling = info.get("subsampling", "4:0:0" if grayscale else "4:2:0")
|
| 170 |
+
speed = info.get("speed", 6)
|
| 171 |
+
max_threads = info.get("max_threads", _get_default_max_threads())
|
| 172 |
+
codec = info.get("codec", "auto")
|
| 173 |
+
if codec != "auto" and not _avif.encoder_codec_available(codec):
|
| 174 |
+
msg = "Invalid saving codec"
|
| 175 |
+
raise ValueError(msg)
|
| 176 |
+
range_ = info.get("range", "full")
|
| 177 |
+
tile_rows_log2 = info.get("tile_rows", 0)
|
| 178 |
+
tile_cols_log2 = info.get("tile_cols", 0)
|
| 179 |
+
alpha_premultiplied = bool(info.get("alpha_premultiplied", False))
|
| 180 |
+
autotiling = bool(info.get("autotiling", tile_rows_log2 == tile_cols_log2 == 0))
|
| 181 |
+
|
| 182 |
+
icc_profile = info.get("icc_profile", im.info.get("icc_profile"))
|
| 183 |
+
exif_orientation = 1
|
| 184 |
+
if exif := info.get("exif"):
|
| 185 |
+
if isinstance(exif, Image.Exif):
|
| 186 |
+
exif_data = exif
|
| 187 |
+
else:
|
| 188 |
+
exif_data = Image.Exif()
|
| 189 |
+
exif_data.load(exif)
|
| 190 |
+
if ExifTags.Base.Orientation in exif_data:
|
| 191 |
+
exif_orientation = exif_data.pop(ExifTags.Base.Orientation)
|
| 192 |
+
exif = exif_data.tobytes() if exif_data else b""
|
| 193 |
+
elif isinstance(exif, Image.Exif):
|
| 194 |
+
exif = exif_data.tobytes()
|
| 195 |
+
|
| 196 |
+
xmp = info.get("xmp")
|
| 197 |
+
|
| 198 |
+
if isinstance(xmp, str):
|
| 199 |
+
xmp = xmp.encode("utf-8")
|
| 200 |
+
|
| 201 |
+
advanced = info.get("advanced")
|
| 202 |
+
if advanced is not None:
|
| 203 |
+
if isinstance(advanced, dict):
|
| 204 |
+
advanced = advanced.items()
|
| 205 |
+
try:
|
| 206 |
+
advanced = tuple(advanced)
|
| 207 |
+
except TypeError:
|
| 208 |
+
invalid = True
|
| 209 |
+
else:
|
| 210 |
+
invalid = any(not isinstance(v, tuple) or len(v) != 2 for v in advanced)
|
| 211 |
+
if invalid:
|
| 212 |
+
msg = (
|
| 213 |
+
"advanced codec options must be a dict of key-value string "
|
| 214 |
+
"pairs or a series of key-value two-tuples"
|
| 215 |
+
)
|
| 216 |
+
raise ValueError(msg)
|
| 217 |
+
|
| 218 |
+
# Setup the AVIF encoder
|
| 219 |
+
enc = _avif.AvifEncoder(
|
| 220 |
+
im.size,
|
| 221 |
+
subsampling,
|
| 222 |
+
quality,
|
| 223 |
+
speed,
|
| 224 |
+
max_threads,
|
| 225 |
+
codec,
|
| 226 |
+
range_,
|
| 227 |
+
tile_rows_log2,
|
| 228 |
+
tile_cols_log2,
|
| 229 |
+
alpha_premultiplied,
|
| 230 |
+
autotiling,
|
| 231 |
+
icc_profile or b"",
|
| 232 |
+
exif or b"",
|
| 233 |
+
exif_orientation,
|
| 234 |
+
xmp or b"",
|
| 235 |
+
advanced,
|
| 236 |
+
)
|
| 237 |
+
|
| 238 |
+
# Add each frame
|
| 239 |
+
frame_idx = 0
|
| 240 |
+
frame_duration = 0
|
| 241 |
+
cur_idx = im.tell()
|
| 242 |
+
is_single_frame = not append_images and not getattr(im, "is_animated", False)
|
| 243 |
+
try:
|
| 244 |
+
for ims in [im] + append_images:
|
| 245 |
+
for frame in ImageSequence.Iterator(ims):
|
| 246 |
+
# Make sure image mode is supported
|
| 247 |
+
rawmode = frame.mode
|
| 248 |
+
if ims.mode not in {"L", "RGB", "RGBA"}:
|
| 249 |
+
if ims.has_transparency_data:
|
| 250 |
+
rawmode = "RGBA"
|
| 251 |
+
elif ims.mode in grayscale_modes:
|
| 252 |
+
rawmode = "L"
|
| 253 |
+
else:
|
| 254 |
+
rawmode = "RGB"
|
| 255 |
+
frame = frame.convert(rawmode)
|
| 256 |
+
|
| 257 |
+
# Update frame duration
|
| 258 |
+
if isinstance(duration, (list, tuple)):
|
| 259 |
+
frame_duration = duration[frame_idx]
|
| 260 |
+
else:
|
| 261 |
+
frame_duration = duration
|
| 262 |
+
|
| 263 |
+
# Append the frame to the animation encoder
|
| 264 |
+
enc.add(
|
| 265 |
+
frame.tobytes("raw", rawmode),
|
| 266 |
+
frame_duration,
|
| 267 |
+
frame.size,
|
| 268 |
+
rawmode,
|
| 269 |
+
is_single_frame,
|
| 270 |
+
)
|
| 271 |
+
|
| 272 |
+
# Update frame index
|
| 273 |
+
frame_idx += 1
|
| 274 |
+
|
| 275 |
+
if not save_all:
|
| 276 |
+
break
|
| 277 |
+
|
| 278 |
+
finally:
|
| 279 |
+
im.seek(cur_idx)
|
| 280 |
+
|
| 281 |
+
# Get the final output from the encoder
|
| 282 |
+
data = enc.finish()
|
| 283 |
+
if data is None:
|
| 284 |
+
msg = "cannot write file as AVIF (encoder returned None)"
|
| 285 |
+
raise OSError(msg)
|
| 286 |
+
|
| 287 |
+
fp.write(data)
|
| 288 |
+
|
| 289 |
+
|
| 290 |
+
Image.register_open(AvifImageFile.format, AvifImageFile, _accept)
|
| 291 |
+
if SUPPORTED:
|
| 292 |
+
Image.register_save(AvifImageFile.format, _save)
|
| 293 |
+
Image.register_save_all(AvifImageFile.format, _save_all)
|
| 294 |
+
Image.register_extensions(AvifImageFile.format, [".avif", ".avifs"])
|
| 295 |
+
Image.register_mime(AvifImageFile.format, "image/avif")
|
.venv/lib/python3.12/site-packages/PIL/BdfFontFile.py
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
from __future__ import annotations
|
| 25 |
+
|
| 26 |
+
from typing import BinaryIO
|
| 27 |
+
|
| 28 |
+
from . import FontFile, Image
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def bdf_char(
|
| 32 |
+
f: BinaryIO,
|
| 33 |
+
) -> (
|
| 34 |
+
tuple[
|
| 35 |
+
str,
|
| 36 |
+
int,
|
| 37 |
+
tuple[tuple[int, int], tuple[int, int, int, int], tuple[int, int, int, int]],
|
| 38 |
+
Image.Image,
|
| 39 |
+
]
|
| 40 |
+
| None
|
| 41 |
+
):
|
| 42 |
+
# skip to STARTCHAR
|
| 43 |
+
while True:
|
| 44 |
+
s = f.readline()
|
| 45 |
+
if not s:
|
| 46 |
+
return None
|
| 47 |
+
if s.startswith(b"STARTCHAR"):
|
| 48 |
+
break
|
| 49 |
+
id = s[9:].strip().decode("ascii")
|
| 50 |
+
|
| 51 |
+
# load symbol properties
|
| 52 |
+
props = {}
|
| 53 |
+
while True:
|
| 54 |
+
s = f.readline()
|
| 55 |
+
if not s or s.startswith(b"BITMAP"):
|
| 56 |
+
break
|
| 57 |
+
i = s.find(b" ")
|
| 58 |
+
props[s[:i].decode("ascii")] = s[i + 1 : -1].decode("ascii")
|
| 59 |
+
|
| 60 |
+
# load bitmap
|
| 61 |
+
bitmap = bytearray()
|
| 62 |
+
while True:
|
| 63 |
+
s = f.readline()
|
| 64 |
+
if not s or s.startswith(b"ENDCHAR"):
|
| 65 |
+
break
|
| 66 |
+
bitmap += s[:-1]
|
| 67 |
+
|
| 68 |
+
# The word BBX
|
| 69 |
+
# followed by the width in x (BBw), height in y (BBh),
|
| 70 |
+
# and x and y displacement (BBxoff0, BByoff0)
|
| 71 |
+
# of the lower left corner from the origin of the character.
|
| 72 |
+
width, height, x_disp, y_disp = (int(p) for p in props["BBX"].split())
|
| 73 |
+
Image._decompression_bomb_check((width, height))
|
| 74 |
+
|
| 75 |
+
# The word DWIDTH
|
| 76 |
+
# followed by the width in x and y of the character in device pixels.
|
| 77 |
+
dwx, dwy = (int(p) for p in props["DWIDTH"].split())
|
| 78 |
+
|
| 79 |
+
bbox = (
|
| 80 |
+
(dwx, dwy),
|
| 81 |
+
(x_disp, -y_disp - height, width + x_disp, -y_disp),
|
| 82 |
+
(0, 0, width, height),
|
| 83 |
+
)
|
| 84 |
+
|
| 85 |
+
try:
|
| 86 |
+
im = Image.frombytes("1", (width, height), bitmap, "hex", "1")
|
| 87 |
+
except ValueError:
|
| 88 |
+
# deal with zero-width characters
|
| 89 |
+
im = Image.new("1", (width, height))
|
| 90 |
+
|
| 91 |
+
return id, int(props["ENCODING"]), bbox, im
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
class BdfFontFile(FontFile.FontFile):
|
| 95 |
+
"""Font file plugin for the X11 BDF format."""
|
| 96 |
+
|
| 97 |
+
def __init__(self, fp: BinaryIO) -> None:
|
| 98 |
+
super().__init__()
|
| 99 |
+
|
| 100 |
+
s = fp.readline()
|
| 101 |
+
if not s.startswith(b"STARTFONT 2.1"):
|
| 102 |
+
msg = "not a valid BDF file"
|
| 103 |
+
raise SyntaxError(msg)
|
| 104 |
+
|
| 105 |
+
props = {}
|
| 106 |
+
comments = []
|
| 107 |
+
|
| 108 |
+
while True:
|
| 109 |
+
s = fp.readline()
|
| 110 |
+
if not s or s.startswith(b"ENDPROPERTIES"):
|
| 111 |
+
break
|
| 112 |
+
i = s.find(b" ")
|
| 113 |
+
props[s[:i].decode("ascii")] = s[i + 1 : -1].decode("ascii")
|
| 114 |
+
if s[:i] in [b"COMMENT", b"COPYRIGHT"]:
|
| 115 |
+
if s.find(b"LogicalFontDescription") < 0:
|
| 116 |
+
comments.append(s[i + 1 : -1].decode("ascii"))
|
| 117 |
+
|
| 118 |
+
while True:
|
| 119 |
+
c = bdf_char(fp)
|
| 120 |
+
if not c:
|
| 121 |
+
break
|
| 122 |
+
id, ch, (xy, dst, src), im = c
|
| 123 |
+
if 0 <= ch < len(self.glyph):
|
| 124 |
+
self.glyph[ch] = xy, dst, src, im
|
.venv/lib/python3.12/site-packages/PIL/BlpImagePlugin.py
ADDED
|
@@ -0,0 +1,498 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Blizzard Mipmap Format (.blp)
|
| 3 |
+
Jerome Leclanche <jerome@leclan.ch>
|
| 4 |
+
|
| 5 |
+
The contents of this file are hereby released in the public domain (CC0)
|
| 6 |
+
Full text of the CC0 license:
|
| 7 |
+
https://creativecommons.org/publicdomain/zero/1.0/
|
| 8 |
+
|
| 9 |
+
BLP1 files, used mostly in Warcraft III, are not fully supported.
|
| 10 |
+
All types of BLP2 files used in World of Warcraft are supported.
|
| 11 |
+
|
| 12 |
+
The BLP file structure consists of a header, up to 16 mipmaps of the
|
| 13 |
+
texture
|
| 14 |
+
|
| 15 |
+
Texture sizes must be powers of two, though the two dimensions do
|
| 16 |
+
not have to be equal; 512x256 is valid, but 512x200 is not.
|
| 17 |
+
The first mipmap (mipmap #0) is the full size image; each subsequent
|
| 18 |
+
mipmap halves both dimensions. The final mipmap should be 1x1.
|
| 19 |
+
|
| 20 |
+
BLP files come in many different flavours:
|
| 21 |
+
* JPEG-compressed (type == 0) - only supported for BLP1.
|
| 22 |
+
* RAW images (type == 1, encoding == 1). Each mipmap is stored as an
|
| 23 |
+
array of 8-bit values, one per pixel, left to right, top to bottom.
|
| 24 |
+
Each value is an index to the palette.
|
| 25 |
+
* DXT-compressed (type == 1, encoding == 2):
|
| 26 |
+
- DXT1 compression is used if alpha_encoding == 0.
|
| 27 |
+
- An additional alpha bit is used if alpha_depth == 1.
|
| 28 |
+
- DXT3 compression is used if alpha_encoding == 1.
|
| 29 |
+
- DXT5 compression is used if alpha_encoding == 7.
|
| 30 |
+
"""
|
| 31 |
+
|
| 32 |
+
from __future__ import annotations
|
| 33 |
+
|
| 34 |
+
import abc
|
| 35 |
+
import os
|
| 36 |
+
import struct
|
| 37 |
+
from enum import IntEnum
|
| 38 |
+
from io import BytesIO
|
| 39 |
+
from typing import IO
|
| 40 |
+
|
| 41 |
+
from . import Image, ImageFile
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
class Format(IntEnum):
|
| 45 |
+
JPEG = 0
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
class Encoding(IntEnum):
|
| 49 |
+
UNCOMPRESSED = 1
|
| 50 |
+
DXT = 2
|
| 51 |
+
UNCOMPRESSED_RAW_BGRA = 3
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
class AlphaEncoding(IntEnum):
|
| 55 |
+
DXT1 = 0
|
| 56 |
+
DXT3 = 1
|
| 57 |
+
DXT5 = 7
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def unpack_565(i: int) -> tuple[int, int, int]:
|
| 61 |
+
return ((i >> 11) & 0x1F) << 3, ((i >> 5) & 0x3F) << 2, (i & 0x1F) << 3
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def decode_dxt1(
|
| 65 |
+
data: bytes, alpha: bool = False
|
| 66 |
+
) -> tuple[bytearray, bytearray, bytearray, bytearray]:
|
| 67 |
+
"""
|
| 68 |
+
input: one "row" of data (i.e. will produce 4*width pixels)
|
| 69 |
+
"""
|
| 70 |
+
|
| 71 |
+
blocks = len(data) // 8 # number of blocks in row
|
| 72 |
+
ret = (bytearray(), bytearray(), bytearray(), bytearray())
|
| 73 |
+
|
| 74 |
+
for block_index in range(blocks):
|
| 75 |
+
# Decode next 8-byte block.
|
| 76 |
+
idx = block_index * 8
|
| 77 |
+
color0, color1, bits = struct.unpack_from("<HHI", data, idx)
|
| 78 |
+
|
| 79 |
+
r0, g0, b0 = unpack_565(color0)
|
| 80 |
+
r1, g1, b1 = unpack_565(color1)
|
| 81 |
+
|
| 82 |
+
# Decode this block into 4x4 pixels
|
| 83 |
+
# Accumulate the results onto our 4 row accumulators
|
| 84 |
+
for j in range(4):
|
| 85 |
+
for i in range(4):
|
| 86 |
+
# get next control op and generate a pixel
|
| 87 |
+
|
| 88 |
+
control = bits & 3
|
| 89 |
+
bits = bits >> 2
|
| 90 |
+
|
| 91 |
+
a = 0xFF
|
| 92 |
+
if control == 0:
|
| 93 |
+
r, g, b = r0, g0, b0
|
| 94 |
+
elif control == 1:
|
| 95 |
+
r, g, b = r1, g1, b1
|
| 96 |
+
elif control == 2:
|
| 97 |
+
if color0 > color1:
|
| 98 |
+
r = (2 * r0 + r1) // 3
|
| 99 |
+
g = (2 * g0 + g1) // 3
|
| 100 |
+
b = (2 * b0 + b1) // 3
|
| 101 |
+
else:
|
| 102 |
+
r = (r0 + r1) // 2
|
| 103 |
+
g = (g0 + g1) // 2
|
| 104 |
+
b = (b0 + b1) // 2
|
| 105 |
+
elif control == 3:
|
| 106 |
+
if color0 > color1:
|
| 107 |
+
r = (2 * r1 + r0) // 3
|
| 108 |
+
g = (2 * g1 + g0) // 3
|
| 109 |
+
b = (2 * b1 + b0) // 3
|
| 110 |
+
else:
|
| 111 |
+
r, g, b, a = 0, 0, 0, 0
|
| 112 |
+
|
| 113 |
+
if alpha:
|
| 114 |
+
ret[j].extend([r, g, b, a])
|
| 115 |
+
else:
|
| 116 |
+
ret[j].extend([r, g, b])
|
| 117 |
+
|
| 118 |
+
return ret
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
def decode_dxt3(data: bytes) -> tuple[bytearray, bytearray, bytearray, bytearray]:
|
| 122 |
+
"""
|
| 123 |
+
input: one "row" of data (i.e. will produce 4*width pixels)
|
| 124 |
+
"""
|
| 125 |
+
|
| 126 |
+
blocks = len(data) // 16 # number of blocks in row
|
| 127 |
+
ret = (bytearray(), bytearray(), bytearray(), bytearray())
|
| 128 |
+
|
| 129 |
+
for block_index in range(blocks):
|
| 130 |
+
idx = block_index * 16
|
| 131 |
+
block = data[idx : idx + 16]
|
| 132 |
+
# Decode next 16-byte block.
|
| 133 |
+
bits = struct.unpack_from("<8B", block)
|
| 134 |
+
color0, color1 = struct.unpack_from("<HH", block, 8)
|
| 135 |
+
|
| 136 |
+
(code,) = struct.unpack_from("<I", block, 12)
|
| 137 |
+
|
| 138 |
+
r0, g0, b0 = unpack_565(color0)
|
| 139 |
+
r1, g1, b1 = unpack_565(color1)
|
| 140 |
+
|
| 141 |
+
for j in range(4):
|
| 142 |
+
high = False # Do we want the higher bits?
|
| 143 |
+
for i in range(4):
|
| 144 |
+
alphacode_index = (4 * j + i) // 2
|
| 145 |
+
a = bits[alphacode_index]
|
| 146 |
+
if high:
|
| 147 |
+
high = False
|
| 148 |
+
a >>= 4
|
| 149 |
+
else:
|
| 150 |
+
high = True
|
| 151 |
+
a &= 0xF
|
| 152 |
+
a *= 17 # We get a value between 0 and 15
|
| 153 |
+
|
| 154 |
+
color_code = (code >> 2 * (4 * j + i)) & 0x03
|
| 155 |
+
|
| 156 |
+
if color_code == 0:
|
| 157 |
+
r, g, b = r0, g0, b0
|
| 158 |
+
elif color_code == 1:
|
| 159 |
+
r, g, b = r1, g1, b1
|
| 160 |
+
elif color_code == 2:
|
| 161 |
+
r = (2 * r0 + r1) // 3
|
| 162 |
+
g = (2 * g0 + g1) // 3
|
| 163 |
+
b = (2 * b0 + b1) // 3
|
| 164 |
+
elif color_code == 3:
|
| 165 |
+
r = (2 * r1 + r0) // 3
|
| 166 |
+
g = (2 * g1 + g0) // 3
|
| 167 |
+
b = (2 * b1 + b0) // 3
|
| 168 |
+
|
| 169 |
+
ret[j].extend([r, g, b, a])
|
| 170 |
+
|
| 171 |
+
return ret
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
def decode_dxt5(data: bytes) -> tuple[bytearray, bytearray, bytearray, bytearray]:
|
| 175 |
+
"""
|
| 176 |
+
input: one "row" of data (i.e. will produce 4 * width pixels)
|
| 177 |
+
"""
|
| 178 |
+
|
| 179 |
+
blocks = len(data) // 16 # number of blocks in row
|
| 180 |
+
ret = (bytearray(), bytearray(), bytearray(), bytearray())
|
| 181 |
+
|
| 182 |
+
for block_index in range(blocks):
|
| 183 |
+
idx = block_index * 16
|
| 184 |
+
block = data[idx : idx + 16]
|
| 185 |
+
# Decode next 16-byte block.
|
| 186 |
+
a0, a1 = struct.unpack_from("<BB", block)
|
| 187 |
+
|
| 188 |
+
bits = struct.unpack_from("<6B", block, 2)
|
| 189 |
+
alphacode1 = bits[2] | (bits[3] << 8) | (bits[4] << 16) | (bits[5] << 24)
|
| 190 |
+
alphacode2 = bits[0] | (bits[1] << 8)
|
| 191 |
+
|
| 192 |
+
color0, color1 = struct.unpack_from("<HH", block, 8)
|
| 193 |
+
|
| 194 |
+
(code,) = struct.unpack_from("<I", block, 12)
|
| 195 |
+
|
| 196 |
+
r0, g0, b0 = unpack_565(color0)
|
| 197 |
+
r1, g1, b1 = unpack_565(color1)
|
| 198 |
+
|
| 199 |
+
for j in range(4):
|
| 200 |
+
for i in range(4):
|
| 201 |
+
# get next control op and generate a pixel
|
| 202 |
+
alphacode_index = 3 * (4 * j + i)
|
| 203 |
+
|
| 204 |
+
if alphacode_index <= 12:
|
| 205 |
+
alphacode = (alphacode2 >> alphacode_index) & 0x07
|
| 206 |
+
elif alphacode_index == 15:
|
| 207 |
+
alphacode = (alphacode2 >> 15) | ((alphacode1 << 1) & 0x06)
|
| 208 |
+
else: # alphacode_index >= 18 and alphacode_index <= 45
|
| 209 |
+
alphacode = (alphacode1 >> (alphacode_index - 16)) & 0x07
|
| 210 |
+
|
| 211 |
+
if alphacode == 0:
|
| 212 |
+
a = a0
|
| 213 |
+
elif alphacode == 1:
|
| 214 |
+
a = a1
|
| 215 |
+
elif a0 > a1:
|
| 216 |
+
a = ((8 - alphacode) * a0 + (alphacode - 1) * a1) // 7
|
| 217 |
+
elif alphacode == 6:
|
| 218 |
+
a = 0
|
| 219 |
+
elif alphacode == 7:
|
| 220 |
+
a = 255
|
| 221 |
+
else:
|
| 222 |
+
a = ((6 - alphacode) * a0 + (alphacode - 1) * a1) // 5
|
| 223 |
+
|
| 224 |
+
color_code = (code >> 2 * (4 * j + i)) & 0x03
|
| 225 |
+
|
| 226 |
+
if color_code == 0:
|
| 227 |
+
r, g, b = r0, g0, b0
|
| 228 |
+
elif color_code == 1:
|
| 229 |
+
r, g, b = r1, g1, b1
|
| 230 |
+
elif color_code == 2:
|
| 231 |
+
r = (2 * r0 + r1) // 3
|
| 232 |
+
g = (2 * g0 + g1) // 3
|
| 233 |
+
b = (2 * b0 + b1) // 3
|
| 234 |
+
elif color_code == 3:
|
| 235 |
+
r = (2 * r1 + r0) // 3
|
| 236 |
+
g = (2 * g1 + g0) // 3
|
| 237 |
+
b = (2 * b1 + b0) // 3
|
| 238 |
+
|
| 239 |
+
ret[j].extend([r, g, b, a])
|
| 240 |
+
|
| 241 |
+
return ret
|
| 242 |
+
|
| 243 |
+
|
| 244 |
+
class BLPFormatError(NotImplementedError):
|
| 245 |
+
pass
|
| 246 |
+
|
| 247 |
+
|
| 248 |
+
def _accept(prefix: bytes) -> bool:
|
| 249 |
+
return prefix.startswith((b"BLP1", b"BLP2"))
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
class BlpImageFile(ImageFile.ImageFile):
|
| 253 |
+
"""
|
| 254 |
+
Blizzard Mipmap Format
|
| 255 |
+
"""
|
| 256 |
+
|
| 257 |
+
format = "BLP"
|
| 258 |
+
format_description = "Blizzard Mipmap Format"
|
| 259 |
+
|
| 260 |
+
def _open(self) -> None:
|
| 261 |
+
assert self.fp is not None
|
| 262 |
+
self.magic = self.fp.read(4)
|
| 263 |
+
if not _accept(self.magic):
|
| 264 |
+
msg = f"Bad BLP magic {repr(self.magic)}"
|
| 265 |
+
raise BLPFormatError(msg)
|
| 266 |
+
|
| 267 |
+
compression = struct.unpack("<i", self.fp.read(4))[0]
|
| 268 |
+
if self.magic == b"BLP1":
|
| 269 |
+
alpha = struct.unpack("<I", self.fp.read(4))[0] != 0
|
| 270 |
+
else:
|
| 271 |
+
encoding = struct.unpack("<b", self.fp.read(1))[0]
|
| 272 |
+
alpha = struct.unpack("<b", self.fp.read(1))[0] != 0
|
| 273 |
+
alpha_encoding = struct.unpack("<b", self.fp.read(1))[0]
|
| 274 |
+
self.fp.seek(1, os.SEEK_CUR) # mips
|
| 275 |
+
|
| 276 |
+
self._size = struct.unpack("<II", self.fp.read(8))
|
| 277 |
+
|
| 278 |
+
args: tuple[int, int, bool] | tuple[int, int, bool, int]
|
| 279 |
+
if self.magic == b"BLP1":
|
| 280 |
+
encoding = struct.unpack("<i", self.fp.read(4))[0]
|
| 281 |
+
self.fp.seek(4, os.SEEK_CUR) # subtype
|
| 282 |
+
|
| 283 |
+
args = (compression, encoding, alpha)
|
| 284 |
+
offset = 28
|
| 285 |
+
else:
|
| 286 |
+
args = (compression, encoding, alpha, alpha_encoding)
|
| 287 |
+
offset = 20
|
| 288 |
+
|
| 289 |
+
decoder = self.magic.decode()
|
| 290 |
+
|
| 291 |
+
self._mode = "RGBA" if alpha else "RGB"
|
| 292 |
+
self.tile = [ImageFile._Tile(decoder, (0, 0) + self.size, offset, args)]
|
| 293 |
+
|
| 294 |
+
|
| 295 |
+
class _BLPBaseDecoder(abc.ABC, ImageFile.PyDecoder):
|
| 296 |
+
_pulls_fd = True
|
| 297 |
+
|
| 298 |
+
def decode(self, buffer: Image.DecoderInput) -> tuple[int, int]:
|
| 299 |
+
try:
|
| 300 |
+
self._read_header()
|
| 301 |
+
self._load()
|
| 302 |
+
except struct.error as e:
|
| 303 |
+
msg = "Truncated BLP file"
|
| 304 |
+
raise OSError(msg) from e
|
| 305 |
+
return -1, 0
|
| 306 |
+
|
| 307 |
+
@abc.abstractmethod
|
| 308 |
+
def _load(self) -> None:
|
| 309 |
+
pass
|
| 310 |
+
|
| 311 |
+
def _read_header(self) -> None:
|
| 312 |
+
self._offsets = struct.unpack("<16I", self._safe_read(16 * 4))
|
| 313 |
+
self._lengths = struct.unpack("<16I", self._safe_read(16 * 4))
|
| 314 |
+
|
| 315 |
+
def _safe_read(self, length: int) -> bytes:
|
| 316 |
+
assert self.fd is not None
|
| 317 |
+
return ImageFile._safe_read(self.fd, length)
|
| 318 |
+
|
| 319 |
+
def _read_palette(self) -> list[tuple[int, int, int, int]]:
|
| 320 |
+
ret = []
|
| 321 |
+
for i in range(256):
|
| 322 |
+
try:
|
| 323 |
+
b, g, r, a = struct.unpack("<4B", self._safe_read(4))
|
| 324 |
+
except struct.error:
|
| 325 |
+
break
|
| 326 |
+
ret.append((b, g, r, a))
|
| 327 |
+
return ret
|
| 328 |
+
|
| 329 |
+
def _read_bgra(
|
| 330 |
+
self, palette: list[tuple[int, int, int, int]], alpha: bool
|
| 331 |
+
) -> bytearray:
|
| 332 |
+
data = bytearray()
|
| 333 |
+
_data = BytesIO(self._safe_read(self._lengths[0]))
|
| 334 |
+
while True:
|
| 335 |
+
try:
|
| 336 |
+
(offset,) = struct.unpack("<B", _data.read(1))
|
| 337 |
+
except struct.error:
|
| 338 |
+
break
|
| 339 |
+
b, g, r, a = palette[offset]
|
| 340 |
+
d: tuple[int, ...] = (r, g, b)
|
| 341 |
+
if alpha:
|
| 342 |
+
d += (a,)
|
| 343 |
+
data.extend(d)
|
| 344 |
+
return data
|
| 345 |
+
|
| 346 |
+
|
| 347 |
+
class BLP1Decoder(_BLPBaseDecoder):
|
| 348 |
+
def _load(self) -> None:
|
| 349 |
+
self._compression, self._encoding, alpha = self.args
|
| 350 |
+
|
| 351 |
+
if self._compression == Format.JPEG:
|
| 352 |
+
self._decode_jpeg_stream()
|
| 353 |
+
|
| 354 |
+
elif self._compression == 1:
|
| 355 |
+
if self._encoding in (4, 5):
|
| 356 |
+
palette = self._read_palette()
|
| 357 |
+
data = self._read_bgra(palette, alpha)
|
| 358 |
+
self.set_as_raw(data)
|
| 359 |
+
else:
|
| 360 |
+
msg = f"Unsupported BLP encoding {repr(self._encoding)}"
|
| 361 |
+
raise BLPFormatError(msg)
|
| 362 |
+
else:
|
| 363 |
+
msg = f"Unsupported BLP compression {repr(self._encoding)}"
|
| 364 |
+
raise BLPFormatError(msg)
|
| 365 |
+
|
| 366 |
+
def _decode_jpeg_stream(self) -> None:
|
| 367 |
+
from .JpegImagePlugin import JpegImageFile
|
| 368 |
+
|
| 369 |
+
(jpeg_header_size,) = struct.unpack("<I", self._safe_read(4))
|
| 370 |
+
jpeg_header = self._safe_read(jpeg_header_size)
|
| 371 |
+
assert self.fd is not None
|
| 372 |
+
self._safe_read(self._offsets[0] - self.fd.tell()) # What IS this?
|
| 373 |
+
data = self._safe_read(self._lengths[0])
|
| 374 |
+
data = jpeg_header + data
|
| 375 |
+
image = JpegImageFile(BytesIO(data))
|
| 376 |
+
Image._decompression_bomb_check(image.size)
|
| 377 |
+
if image.mode == "CMYK":
|
| 378 |
+
args = image.tile[0].args
|
| 379 |
+
assert isinstance(args, tuple)
|
| 380 |
+
image.tile = [image.tile[0]._replace(args=(args[0], "CMYK"))]
|
| 381 |
+
self.set_as_raw(image.convert("RGB").tobytes(), "BGR")
|
| 382 |
+
|
| 383 |
+
|
| 384 |
+
class BLP2Decoder(_BLPBaseDecoder):
|
| 385 |
+
def _load(self) -> None:
|
| 386 |
+
self._compression, self._encoding, alpha, self._alpha_encoding = self.args
|
| 387 |
+
|
| 388 |
+
palette = self._read_palette()
|
| 389 |
+
|
| 390 |
+
assert self.fd is not None
|
| 391 |
+
self.fd.seek(self._offsets[0])
|
| 392 |
+
|
| 393 |
+
if self._compression == 1:
|
| 394 |
+
# Uncompressed or DirectX compression
|
| 395 |
+
|
| 396 |
+
if self._encoding == Encoding.UNCOMPRESSED:
|
| 397 |
+
data = self._read_bgra(palette, alpha)
|
| 398 |
+
|
| 399 |
+
elif self._encoding == Encoding.DXT:
|
| 400 |
+
data = bytearray()
|
| 401 |
+
if self._alpha_encoding == AlphaEncoding.DXT1:
|
| 402 |
+
linesize = (self.state.xsize + 3) // 4 * 8
|
| 403 |
+
for yb in range((self.state.ysize + 3) // 4):
|
| 404 |
+
for d in decode_dxt1(self._safe_read(linesize), alpha):
|
| 405 |
+
data += d
|
| 406 |
+
|
| 407 |
+
elif self._alpha_encoding == AlphaEncoding.DXT3:
|
| 408 |
+
linesize = (self.state.xsize + 3) // 4 * 16
|
| 409 |
+
for yb in range((self.state.ysize + 3) // 4):
|
| 410 |
+
for d in decode_dxt3(self._safe_read(linesize)):
|
| 411 |
+
data += d
|
| 412 |
+
|
| 413 |
+
elif self._alpha_encoding == AlphaEncoding.DXT5:
|
| 414 |
+
linesize = (self.state.xsize + 3) // 4 * 16
|
| 415 |
+
for yb in range((self.state.ysize + 3) // 4):
|
| 416 |
+
for d in decode_dxt5(self._safe_read(linesize)):
|
| 417 |
+
data += d
|
| 418 |
+
else:
|
| 419 |
+
msg = f"Unsupported alpha encoding {repr(self._alpha_encoding)}"
|
| 420 |
+
raise BLPFormatError(msg)
|
| 421 |
+
else:
|
| 422 |
+
msg = f"Unknown BLP encoding {repr(self._encoding)}"
|
| 423 |
+
raise BLPFormatError(msg)
|
| 424 |
+
|
| 425 |
+
else:
|
| 426 |
+
msg = f"Unknown BLP compression {repr(self._compression)}"
|
| 427 |
+
raise BLPFormatError(msg)
|
| 428 |
+
|
| 429 |
+
self.set_as_raw(data)
|
| 430 |
+
|
| 431 |
+
|
| 432 |
+
class BLPEncoder(ImageFile.PyEncoder):
|
| 433 |
+
_pushes_fd = True
|
| 434 |
+
|
| 435 |
+
def _write_palette(self) -> bytes:
|
| 436 |
+
data = b""
|
| 437 |
+
assert self.im is not None
|
| 438 |
+
palette = self.im.getpalette("RGBA", "RGBA")
|
| 439 |
+
for i in range(len(palette) // 4):
|
| 440 |
+
r, g, b, a = palette[i * 4 : (i + 1) * 4]
|
| 441 |
+
data += struct.pack("<4B", b, g, r, a)
|
| 442 |
+
while len(data) < 256 * 4:
|
| 443 |
+
data += b"\x00" * 4
|
| 444 |
+
return data
|
| 445 |
+
|
| 446 |
+
def encode(self, bufsize: int) -> tuple[int, int, bytes]:
|
| 447 |
+
palette_data = self._write_palette()
|
| 448 |
+
|
| 449 |
+
offset = 20 + 16 * 4 * 2 + len(palette_data)
|
| 450 |
+
data = struct.pack("<16I", offset, *((0,) * 15))
|
| 451 |
+
|
| 452 |
+
assert self.im is not None
|
| 453 |
+
w, h = self.im.size
|
| 454 |
+
data += struct.pack("<16I", w * h, *((0,) * 15))
|
| 455 |
+
|
| 456 |
+
data += palette_data
|
| 457 |
+
|
| 458 |
+
for y in range(h):
|
| 459 |
+
for x in range(w):
|
| 460 |
+
data += struct.pack("<B", self.im.getpixel((x, y)))
|
| 461 |
+
|
| 462 |
+
return len(data), 0, data
|
| 463 |
+
|
| 464 |
+
|
| 465 |
+
def _save(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None:
|
| 466 |
+
if im.mode != "P":
|
| 467 |
+
msg = "Unsupported BLP image mode"
|
| 468 |
+
raise ValueError(msg)
|
| 469 |
+
|
| 470 |
+
magic = b"BLP1" if im.encoderinfo.get("blp_version") == "BLP1" else b"BLP2"
|
| 471 |
+
fp.write(magic)
|
| 472 |
+
|
| 473 |
+
assert im.palette is not None
|
| 474 |
+
fp.write(struct.pack("<i", 1)) # Uncompressed or DirectX compression
|
| 475 |
+
|
| 476 |
+
alpha_depth = 1 if im.palette.mode == "RGBA" else 0
|
| 477 |
+
if magic == b"BLP1":
|
| 478 |
+
fp.write(struct.pack("<L", alpha_depth))
|
| 479 |
+
else:
|
| 480 |
+
fp.write(struct.pack("<b", Encoding.UNCOMPRESSED))
|
| 481 |
+
fp.write(struct.pack("<b", alpha_depth))
|
| 482 |
+
fp.write(struct.pack("<b", 0)) # alpha encoding
|
| 483 |
+
fp.write(struct.pack("<b", 0)) # mips
|
| 484 |
+
fp.write(struct.pack("<II", *im.size))
|
| 485 |
+
if magic == b"BLP1":
|
| 486 |
+
fp.write(struct.pack("<i", 5))
|
| 487 |
+
fp.write(struct.pack("<i", 0))
|
| 488 |
+
|
| 489 |
+
ImageFile._save(im, fp, [ImageFile._Tile("BLP", (0, 0) + im.size, 0, im.mode)])
|
| 490 |
+
|
| 491 |
+
|
| 492 |
+
Image.register_open(BlpImageFile.format, BlpImageFile, _accept)
|
| 493 |
+
Image.register_extension(BlpImageFile.format, ".blp")
|
| 494 |
+
Image.register_decoder("BLP1", BLP1Decoder)
|
| 495 |
+
Image.register_decoder("BLP2", BLP2Decoder)
|
| 496 |
+
|
| 497 |
+
Image.register_save(BlpImageFile.format, _save)
|
| 498 |
+
Image.register_encoder("BLP", BLPEncoder)
|