LastPNGImagePlugin 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lastpngimageplugin-0.1.0/.gitignore +3 -0
- lastpngimageplugin-0.1.0/LICENSE +21 -0
- lastpngimageplugin-0.1.0/PKG-INFO +32 -0
- lastpngimageplugin-0.1.0/README.md +19 -0
- lastpngimageplugin-0.1.0/hatch_build.py +61 -0
- lastpngimageplugin-0.1.0/licenses/fdeflate-LICENSE-MIT +25 -0
- lastpngimageplugin-0.1.0/licenses/libdeflate-COPYING +22 -0
- lastpngimageplugin-0.1.0/pyproject.toml +32 -0
- lastpngimageplugin-0.1.0/rust/Cargo.lock +128 -0
- lastpngimageplugin-0.1.0/rust/Cargo.toml +37 -0
- lastpngimageplugin-0.1.0/rust/build.rs +25 -0
- lastpngimageplugin-0.1.0/rust/include/lastpng.h +75 -0
- lastpngimageplugin-0.1.0/rust/models/higher.f32le +0 -0
- lastpngimageplugin-0.1.0/rust/native/row_deflate.c +235 -0
- lastpngimageplugin-0.1.0/rust/src/deflate.rs +184 -0
- lastpngimageplugin-0.1.0/rust/src/encode.rs +218 -0
- lastpngimageplugin-0.1.0/rust/src/ffi.rs +258 -0
- lastpngimageplugin-0.1.0/rust/src/lib.rs +1551 -0
- lastpngimageplugin-0.1.0/rust/src/palette.rs +292 -0
- lastpngimageplugin-0.1.0/rust/src/row_deflate.rs +119 -0
- lastpngimageplugin-0.1.0/rust/src/row_model.rs +771 -0
- lastpngimageplugin-0.1.0/rust/src/tiny.rs +167 -0
- lastpngimageplugin-0.1.0/rust/src/ultrafast.rs +222 -0
- lastpngimageplugin-0.1.0/rust/vendor/fdeflate-LICENSE-MIT +25 -0
- lastpngimageplugin-0.1.0/rust/vendor/libdeflate/COPYING +22 -0
- lastpngimageplugin-0.1.0/rust/vendor/libdeflate/README.md +7 -0
- lastpngimageplugin-0.1.0/rust/vendor/libdeflate/common_defs.h +735 -0
- lastpngimageplugin-0.1.0/rust/vendor/libdeflate/lib/adler32.c +162 -0
- lastpngimageplugin-0.1.0/rust/vendor/libdeflate/lib/arm/adler32_impl.h +365 -0
- lastpngimageplugin-0.1.0/rust/vendor/libdeflate/lib/arm/cpu_features.c +292 -0
- lastpngimageplugin-0.1.0/rust/vendor/libdeflate/lib/arm/cpu_features.h +214 -0
- lastpngimageplugin-0.1.0/rust/vendor/libdeflate/lib/arm/matchfinder_impl.h +78 -0
- lastpngimageplugin-0.1.0/rust/vendor/libdeflate/lib/bt_matchfinder.h +229 -0
- lastpngimageplugin-0.1.0/rust/vendor/libdeflate/lib/bt_matchfinder_search.h +127 -0
- lastpngimageplugin-0.1.0/rust/vendor/libdeflate/lib/cpu_features_common.h +93 -0
- lastpngimageplugin-0.1.0/rust/vendor/libdeflate/lib/deflate_compress.c +4221 -0
- lastpngimageplugin-0.1.0/rust/vendor/libdeflate/lib/deflate_compress.h +15 -0
- lastpngimageplugin-0.1.0/rust/vendor/libdeflate/lib/deflate_constants.h +56 -0
- lastpngimageplugin-0.1.0/rust/vendor/libdeflate/lib/hc_matchfinder.h +401 -0
- lastpngimageplugin-0.1.0/rust/vendor/libdeflate/lib/ht_matchfinder.h +263 -0
- lastpngimageplugin-0.1.0/rust/vendor/libdeflate/lib/lib_common.h +106 -0
- lastpngimageplugin-0.1.0/rust/vendor/libdeflate/lib/matchfinder_common.h +224 -0
- lastpngimageplugin-0.1.0/rust/vendor/libdeflate/lib/riscv/matchfinder_impl.h +97 -0
- lastpngimageplugin-0.1.0/rust/vendor/libdeflate/lib/utils.c +141 -0
- lastpngimageplugin-0.1.0/rust/vendor/libdeflate/lib/x86/adler32_impl.h +136 -0
- lastpngimageplugin-0.1.0/rust/vendor/libdeflate/lib/x86/adler32_template.h +518 -0
- lastpngimageplugin-0.1.0/rust/vendor/libdeflate/lib/x86/cpu_features.c +213 -0
- lastpngimageplugin-0.1.0/rust/vendor/libdeflate/lib/x86/cpu_features.h +170 -0
- lastpngimageplugin-0.1.0/rust/vendor/libdeflate/lib/x86/matchfinder_impl.h +122 -0
- lastpngimageplugin-0.1.0/rust/vendor/libdeflate/lib/zlib_compress.c +82 -0
- lastpngimageplugin-0.1.0/rust/vendor/libdeflate/lib/zlib_constants.h +21 -0
- lastpngimageplugin-0.1.0/rust/vendor/libdeflate/libdeflate.h +412 -0
- lastpngimageplugin-0.1.0/src/LastPNGImagePlugin.py +161 -0
- lastpngimageplugin-0.1.0/tests/test_pillow_plugin.py +114 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Aleksandr Karpinskii
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: LastPNGImagePlugin
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A vibe-coded, blazingly fast PNG compressor for Pillow
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
License-File: licenses/fdeflate-LICENSE-MIT
|
|
8
|
+
License-File: licenses/libdeflate-COPYING
|
|
9
|
+
Requires-Python: >=3.10
|
|
10
|
+
Requires-Dist: cffi>=1.17
|
|
11
|
+
Requires-Dist: pillow<=13.0.0,>=11
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
|
|
14
|
+
# LastPNG for Pillow
|
|
15
|
+
|
|
16
|
+
Save PNG images from Pillow with LastPNG. Install with `pip install LastPNGImagePlugin`,
|
|
17
|
+
then import the plugin to register the `LASTPNG` format.
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
from PIL import Image
|
|
21
|
+
import LastPNGImagePlugin
|
|
22
|
+
|
|
23
|
+
with Image.open("input.png") as image:
|
|
24
|
+
image.save("output.png", format="LASTPNG", level=3)
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Choose a compression level from 1 (fastest) to 6 (experimental, highest effort).
|
|
28
|
+
The default is 3. The plugin supports single images in modes `1`, `L`, `I;16`,
|
|
29
|
+
`P`, `RGB`, `LA`, and `RGBA`. Platform wheels bundle the encoder. Building
|
|
30
|
+
from source requires a Rust toolchain and a C compiler.
|
|
31
|
+
|
|
32
|
+
[Supported Pillow versions and save options](https://github.com/homm/lastpng#pillow-plugin)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# LastPNG for Pillow
|
|
2
|
+
|
|
3
|
+
Save PNG images from Pillow with LastPNG. Install with `pip install LastPNGImagePlugin`,
|
|
4
|
+
then import the plugin to register the `LASTPNG` format.
|
|
5
|
+
|
|
6
|
+
```python
|
|
7
|
+
from PIL import Image
|
|
8
|
+
import LastPNGImagePlugin
|
|
9
|
+
|
|
10
|
+
with Image.open("input.png") as image:
|
|
11
|
+
image.save("output.png", format="LASTPNG", level=3)
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Choose a compression level from 1 (fastest) to 6 (experimental, highest effort).
|
|
15
|
+
The default is 3. The plugin supports single images in modes `1`, `L`, `I;16`,
|
|
16
|
+
`P`, `RGB`, `LA`, and `RGBA`. Platform wheels bundle the encoder. Building
|
|
17
|
+
from source requires a Rust toolchain and a C compiler.
|
|
18
|
+
|
|
19
|
+
[Supported Pillow versions and save options](https://github.com/homm/lastpng#pillow-plugin)
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import platform
|
|
3
|
+
import subprocess
|
|
4
|
+
import sys
|
|
5
|
+
import sysconfig
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from tempfile import TemporaryDirectory
|
|
8
|
+
|
|
9
|
+
from cffi import FFI
|
|
10
|
+
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class LastPngBuild(BuildHookInterface):
|
|
14
|
+
def initialize(self, version, build_data):
|
|
15
|
+
root = Path(self.root)
|
|
16
|
+
# The sdist carries the Rust crate inside the package.
|
|
17
|
+
rust = root / "rust" if (root / "rust/Cargo.toml").is_file() else root.parent
|
|
18
|
+
header = (rust / "include/lastpng.h").read_text()
|
|
19
|
+
ffi = FFI()
|
|
20
|
+
ffi.cdef(header[header.index("typedef struct"):header.rindex("#ifdef __cplusplus")])
|
|
21
|
+
ffi.cdef("""
|
|
22
|
+
typedef struct {
|
|
23
|
+
char mode[7];
|
|
24
|
+
int type, depth, bands, xsize, ysize;
|
|
25
|
+
void *palette, *image8, *image32;
|
|
26
|
+
const uint8_t *const *image;
|
|
27
|
+
} Imaging11;
|
|
28
|
+
|
|
29
|
+
typedef struct {
|
|
30
|
+
int mode;
|
|
31
|
+
int type, depth, bands, xsize, ysize;
|
|
32
|
+
void *palette, *image8, *image32;
|
|
33
|
+
const uint8_t *const *image;
|
|
34
|
+
} Imaging12;
|
|
35
|
+
""")
|
|
36
|
+
self.generated = TemporaryDirectory()
|
|
37
|
+
bindings = Path(self.generated.name) / "_abi.py"
|
|
38
|
+
ffi.set_source("_lastpng._abi", None)
|
|
39
|
+
ffi.emit_python_code(str(bindings))
|
|
40
|
+
|
|
41
|
+
artifacts = subprocess.check_output(
|
|
42
|
+
["cargo", "build", "--lib", "--release", "--locked", "--message-format=json-render-diagnostics"],
|
|
43
|
+
cwd=rust, text=True,
|
|
44
|
+
)
|
|
45
|
+
library = next(
|
|
46
|
+
Path(path) for item in map(json.loads, artifacts.splitlines())
|
|
47
|
+
if item["reason"] == "compiler-artifact" and item["target"]["name"] == "lastpng"
|
|
48
|
+
for path in item["filenames"] if Path(path).suffix in {".dylib", ".so", ".dll"}
|
|
49
|
+
)
|
|
50
|
+
plat = sysconfig.get_platform().replace("-", "_").replace(".", "_")
|
|
51
|
+
if sys.platform == "darwin":
|
|
52
|
+
target = subprocess.check_output(["rustc", "--print", "deployment-target"], cwd=rust, text=True)
|
|
53
|
+
major, minor, *_ = target.strip().split("=")[1].split(".") + ["0"]
|
|
54
|
+
plat = f"macosx_{major}_{minor}_{platform.machine()}"
|
|
55
|
+
build_data["pure_python"] = False
|
|
56
|
+
build_data["tag"] = f"py3-none-{plat}"
|
|
57
|
+
build_data["force_include"][str(bindings)] = "_lastpng/_abi.py"
|
|
58
|
+
build_data["force_include"][str(library)] = f"_lastpng/{library.name}"
|
|
59
|
+
|
|
60
|
+
def finalize(self, version, build_data, artifact_path):
|
|
61
|
+
self.generated.cleanup()
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any
|
|
4
|
+
person obtaining a copy of this software and associated
|
|
5
|
+
documentation files (the "Software"), to deal in the
|
|
6
|
+
Software without restriction, including without
|
|
7
|
+
limitation the rights to use, copy, modify, merge,
|
|
8
|
+
publish, distribute, sublicense, and/or sell copies of
|
|
9
|
+
the Software, and to permit persons to whom the Software
|
|
10
|
+
is furnished to do so, subject to the following
|
|
11
|
+
conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice
|
|
14
|
+
shall be included in all copies or substantial portions
|
|
15
|
+
of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
|
18
|
+
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
19
|
+
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
|
20
|
+
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
|
|
21
|
+
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
22
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
23
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
|
24
|
+
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
25
|
+
DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright 2016 Eric Biggers
|
|
2
|
+
Copyright 2024 Google LLC
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person
|
|
5
|
+
obtaining a copy of this software and associated documentation files
|
|
6
|
+
(the "Software"), to deal in the Software without restriction,
|
|
7
|
+
including without limitation the rights to use, copy, modify, merge,
|
|
8
|
+
publish, distribute, sublicense, and/or sell copies of the Software,
|
|
9
|
+
and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be
|
|
13
|
+
included in all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
19
|
+
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
20
|
+
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
21
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.26", "cffi>=1.17"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "LastPNGImagePlugin"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "A vibe-coded, blazingly fast PNG compressor for Pillow"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
license-files = ["LICENSE", "licenses/*"]
|
|
12
|
+
requires-python = ">=3.10"
|
|
13
|
+
dependencies = ["Pillow>=11,<=13.0.0", "cffi>=1.17"]
|
|
14
|
+
|
|
15
|
+
[tool.hatch.build.targets.wheel]
|
|
16
|
+
only-include = ["src/LastPNGImagePlugin.py"]
|
|
17
|
+
sources = ["src"]
|
|
18
|
+
|
|
19
|
+
[tool.hatch.build.targets.wheel.hooks.custom]
|
|
20
|
+
|
|
21
|
+
[tool.hatch.build.targets.sdist]
|
|
22
|
+
include = ["/src", "/tests", "/pyproject.toml", "/hatch_build.py"]
|
|
23
|
+
|
|
24
|
+
[tool.hatch.build.targets.sdist.force-include]
|
|
25
|
+
"../Cargo.toml" = "rust/Cargo.toml"
|
|
26
|
+
"../Cargo.lock" = "rust/Cargo.lock"
|
|
27
|
+
"../build.rs" = "rust/build.rs"
|
|
28
|
+
"../include" = "rust/include"
|
|
29
|
+
"../src" = "rust/src"
|
|
30
|
+
"../native" = "rust/native"
|
|
31
|
+
"../models" = "rust/models"
|
|
32
|
+
"../vendor" = "rust/vendor"
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# This file is automatically @generated by Cargo.
|
|
2
|
+
# It is not intended for manual editing.
|
|
3
|
+
version = 4
|
|
4
|
+
|
|
5
|
+
[[package]]
|
|
6
|
+
name = "adler2"
|
|
7
|
+
version = "2.0.1"
|
|
8
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
9
|
+
checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
|
|
10
|
+
|
|
11
|
+
[[package]]
|
|
12
|
+
name = "bitflags"
|
|
13
|
+
version = "2.13.2"
|
|
14
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
15
|
+
checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06"
|
|
16
|
+
|
|
17
|
+
[[package]]
|
|
18
|
+
name = "cc"
|
|
19
|
+
version = "1.12.0"
|
|
20
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
21
|
+
checksum = "95e45cf2980b2d467be49a9ed942c9179b701063a7ca3d037de7ee9bd67f8d66"
|
|
22
|
+
dependencies = [
|
|
23
|
+
"find-msvc-tools",
|
|
24
|
+
"shlex",
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
[[package]]
|
|
28
|
+
name = "cfg-if"
|
|
29
|
+
version = "1.0.5"
|
|
30
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
31
|
+
checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"
|
|
32
|
+
|
|
33
|
+
[[package]]
|
|
34
|
+
name = "crc32fast"
|
|
35
|
+
version = "1.5.6"
|
|
36
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
37
|
+
checksum = "fd9ae8fcb3ea71b0b26338b4ffb13006bb175de8fd07921089a906ce7e5e6945"
|
|
38
|
+
dependencies = [
|
|
39
|
+
"cfg-if",
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
[[package]]
|
|
43
|
+
name = "fdeflate"
|
|
44
|
+
version = "0.3.7"
|
|
45
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
46
|
+
checksum = "1e6853b52649d4ac5c0bd02320cddc5ba956bdb407c4b75a2c6b75bf51500f8c"
|
|
47
|
+
dependencies = [
|
|
48
|
+
"simd-adler32",
|
|
49
|
+
]
|
|
50
|
+
|
|
51
|
+
[[package]]
|
|
52
|
+
name = "find-msvc-tools"
|
|
53
|
+
version = "0.1.16"
|
|
54
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
55
|
+
checksum = "3e44f110d1777dc6559a51e7d45083945ded4f1bf3305494350f693b6d20b9c8"
|
|
56
|
+
|
|
57
|
+
[[package]]
|
|
58
|
+
name = "flate2"
|
|
59
|
+
version = "1.1.11"
|
|
60
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
61
|
+
checksum = "626d4928326b646e70f65ed36fc7cf9f206bdb68a0019ee7c6b4709da4e084c4"
|
|
62
|
+
dependencies = [
|
|
63
|
+
"crc32fast",
|
|
64
|
+
"miniz_oxide 0.9.1",
|
|
65
|
+
"zlib-rs",
|
|
66
|
+
]
|
|
67
|
+
|
|
68
|
+
[[package]]
|
|
69
|
+
name = "lastpng"
|
|
70
|
+
version = "0.1.0"
|
|
71
|
+
dependencies = [
|
|
72
|
+
"adler2",
|
|
73
|
+
"cc",
|
|
74
|
+
"crc32fast",
|
|
75
|
+
"miniz_oxide 0.9.1",
|
|
76
|
+
"png",
|
|
77
|
+
]
|
|
78
|
+
|
|
79
|
+
[[package]]
|
|
80
|
+
name = "miniz_oxide"
|
|
81
|
+
version = "0.8.9"
|
|
82
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
83
|
+
checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316"
|
|
84
|
+
dependencies = [
|
|
85
|
+
"adler2",
|
|
86
|
+
"simd-adler32",
|
|
87
|
+
]
|
|
88
|
+
|
|
89
|
+
[[package]]
|
|
90
|
+
name = "miniz_oxide"
|
|
91
|
+
version = "0.9.1"
|
|
92
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
93
|
+
checksum = "b63fbc4a50860e98e7b2aa7804ded1db5cbc3aff9193adaff57a6931bf7c4b4c"
|
|
94
|
+
dependencies = [
|
|
95
|
+
"adler2",
|
|
96
|
+
"simd-adler32",
|
|
97
|
+
]
|
|
98
|
+
|
|
99
|
+
[[package]]
|
|
100
|
+
name = "png"
|
|
101
|
+
version = "0.18.1"
|
|
102
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
103
|
+
checksum = "60769b8b31b2a9f263dae2776c37b1b28ae246943cf719eb6946a1db05128a61"
|
|
104
|
+
dependencies = [
|
|
105
|
+
"bitflags",
|
|
106
|
+
"crc32fast",
|
|
107
|
+
"fdeflate",
|
|
108
|
+
"flate2",
|
|
109
|
+
"miniz_oxide 0.8.9",
|
|
110
|
+
]
|
|
111
|
+
|
|
112
|
+
[[package]]
|
|
113
|
+
name = "shlex"
|
|
114
|
+
version = "2.0.1"
|
|
115
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
116
|
+
checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"
|
|
117
|
+
|
|
118
|
+
[[package]]
|
|
119
|
+
name = "simd-adler32"
|
|
120
|
+
version = "0.3.10"
|
|
121
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
122
|
+
checksum = "3a219298ac11a56ea9a6d2120044824d6f01aeb034955e7af7bc16858527deea"
|
|
123
|
+
|
|
124
|
+
[[package]]
|
|
125
|
+
name = "zlib-rs"
|
|
126
|
+
version = "0.6.9"
|
|
127
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
128
|
+
checksum = "aa76918995d776d9dd34d371030be228d021137449771493d56e29f77e4148ac"
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "lastpng"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
edition = "2024"
|
|
5
|
+
license = "MIT"
|
|
6
|
+
description = "A vibe-coded, blazingly fast PNG compressor"
|
|
7
|
+
repository = "https://github.com/homm/lastpng"
|
|
8
|
+
publish = ["crates-io"]
|
|
9
|
+
include = [
|
|
10
|
+
"/src/",
|
|
11
|
+
"/native/",
|
|
12
|
+
"/include/",
|
|
13
|
+
"/vendor/",
|
|
14
|
+
"/models/",
|
|
15
|
+
"/build.rs",
|
|
16
|
+
"/README.md",
|
|
17
|
+
"/LICENSE",
|
|
18
|
+
"!.DS_Store",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
[lib]
|
|
22
|
+
crate-type = ["rlib", "cdylib", "staticlib"]
|
|
23
|
+
|
|
24
|
+
# Preserve the Mach-O string table for Apple's linker and dynamic loader.
|
|
25
|
+
[profile.release.package.lastpng]
|
|
26
|
+
strip = "none"
|
|
27
|
+
|
|
28
|
+
[dependencies]
|
|
29
|
+
crc32fast = "1"
|
|
30
|
+
adler2 = "=2.0.1"
|
|
31
|
+
png = "=0.18.1"
|
|
32
|
+
|
|
33
|
+
[dev-dependencies]
|
|
34
|
+
miniz_oxide = "=0.9.1"
|
|
35
|
+
|
|
36
|
+
[build-dependencies]
|
|
37
|
+
cc = "1"
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
fn main() {
|
|
2
|
+
let root = std::path::Path::new(file!()).parent().unwrap();
|
|
3
|
+
let native = root.join("native/row_deflate.c");
|
|
4
|
+
let vendor = root.join("vendor/libdeflate");
|
|
5
|
+
println!("cargo:rerun-if-changed={}", native.display());
|
|
6
|
+
println!("cargo:rerun-if-changed={}", vendor.display());
|
|
7
|
+
cc::Build::new()
|
|
8
|
+
.file(native)
|
|
9
|
+
.file(vendor.join("lib/adler32.c"))
|
|
10
|
+
.file(vendor.join("lib/arm/cpu_features.c"))
|
|
11
|
+
.file(vendor.join("lib/x86/cpu_features.c"))
|
|
12
|
+
.define("libdeflate_adler32", "lastpng_adler32")
|
|
13
|
+
.define("libdeflate_arm_cpu_features", "lastpng_arm_cpu_features")
|
|
14
|
+
.define(
|
|
15
|
+
"libdeflate_init_arm_cpu_features",
|
|
16
|
+
"lastpng_init_arm_cpu_features",
|
|
17
|
+
)
|
|
18
|
+
.define("libdeflate_x86_cpu_features", "lastpng_x86_cpu_features")
|
|
19
|
+
.define(
|
|
20
|
+
"libdeflate_init_x86_cpu_features",
|
|
21
|
+
"lastpng_init_x86_cpu_features",
|
|
22
|
+
)
|
|
23
|
+
.warnings(false)
|
|
24
|
+
.compile("lastpng_row_deflate");
|
|
25
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
#ifndef LASTPNG_H
|
|
2
|
+
#define LASTPNG_H
|
|
3
|
+
|
|
4
|
+
#include <stddef.h>
|
|
5
|
+
#include <stdint.h>
|
|
6
|
+
|
|
7
|
+
#ifdef __cplusplus
|
|
8
|
+
extern "C" {
|
|
9
|
+
#endif
|
|
10
|
+
|
|
11
|
+
typedef struct lastpng_encoder lastpng_encoder;
|
|
12
|
+
|
|
13
|
+
enum {
|
|
14
|
+
LASTPNG_GRAY = 0, LASTPNG_RGB = 2, LASTPNG_INDEXED = 3,
|
|
15
|
+
LASTPNG_GRAY_ALPHA = 4, LASTPNG_RGBA = 6
|
|
16
|
+
};
|
|
17
|
+
enum {
|
|
18
|
+
LASTPNG_PACKED = 0, LASTPNG_RGBX = 1, LASTPNG_LXXA = 2,
|
|
19
|
+
LASTPNG_BILEVEL8 = 3, /* Gray, depth 1: one byte per pixel, nonzero is white. */
|
|
20
|
+
LASTPNG_GRAY16_LE = 4 /* Gray, depth 16: little-endian samples. */
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
typedef struct {
|
|
24
|
+
uint32_t width, height;
|
|
25
|
+
uint8_t color, depth, layout, level; /* PNG color/depth, LastPNG layout, level 1..6 */
|
|
26
|
+
uint8_t preserve_color_space; /* 1 to retain the input ICC color family, else 0 */
|
|
27
|
+
const uint8_t *palette; /* PLTE payload (RGB triples) */
|
|
28
|
+
size_t palette_len;
|
|
29
|
+
const uint8_t *transparency; /* tRNS payload in PNG byte order */
|
|
30
|
+
size_t transparency_len;
|
|
31
|
+
} lastpng_config;
|
|
32
|
+
|
|
33
|
+
typedef struct {
|
|
34
|
+
uint32_t width, height;
|
|
35
|
+
uint8_t color, depth;
|
|
36
|
+
} lastpng_output_info;
|
|
37
|
+
|
|
38
|
+
/* Optional caller-owned diagnostic, NUL-terminated on failure. */
|
|
39
|
+
typedef struct { char message[256]; } lastpng_error;
|
|
40
|
+
|
|
41
|
+
/* Constructors return NULL on failure. Keep pixel, palette and transparency
|
|
42
|
+
* bytes readable and unchanged until write or free returns. Use zero lengths
|
|
43
|
+
* for absent payloads. The config and row pointer array may be discarded
|
|
44
|
+
* immediately. Use one handle from one caller at a time. */
|
|
45
|
+
lastpng_encoder *lastpng_encoder_from_buffer(const lastpng_config *config,
|
|
46
|
+
const uint8_t *pixels, size_t pixels_len, lastpng_error *error);
|
|
47
|
+
|
|
48
|
+
/* Supply height addresses in top-to-bottom order. Each points to at least one
|
|
49
|
+
* complete row. Packed samples use PNG bit order and big-endian 16-bit values.
|
|
50
|
+
* RGBX and LXXA use four bytes per pixel, with padding ignored. */
|
|
51
|
+
lastpng_encoder *lastpng_encoder_from_rows(const lastpng_config *config,
|
|
52
|
+
const uint8_t *const *rows, lastpng_error *error);
|
|
53
|
+
|
|
54
|
+
/* Pass a live encoder. The returned IHDR fields are available before writing.
|
|
55
|
+
* Compression, filter method and interlace method are all zero. */
|
|
56
|
+
lastpng_output_info lastpng_encoder_output_info(const lastpng_encoder *encoder);
|
|
57
|
+
|
|
58
|
+
/* Return zero after accepting all bytes, nonzero on error. Data is valid only
|
|
59
|
+
* during the callback. Return normally, including on language-level exceptions. */
|
|
60
|
+
typedef int (*lastpng_write_fn)(void *context, const uint8_t *data, size_t len);
|
|
61
|
+
|
|
62
|
+
/* Both writes consume *encoder and set it to NULL, even on write failure.
|
|
63
|
+
* Return zero on success or -1 on failure. A failed destination may contain
|
|
64
|
+
* partial output. Free an unwritten encoder with lastpng_encoder_free. */
|
|
65
|
+
int lastpng_encoder_write_png(lastpng_encoder **encoder, lastpng_write_fn write,
|
|
66
|
+
void *context, lastpng_error *error);
|
|
67
|
+
/* Emits optional PLTE, optional tRNS, then consecutive framed IDAT chunks. */
|
|
68
|
+
int lastpng_encoder_write_image_chunks(lastpng_encoder **encoder, lastpng_write_fn write,
|
|
69
|
+
void *context, lastpng_error *error);
|
|
70
|
+
void lastpng_encoder_free(lastpng_encoder *encoder); /* NULL is accepted. */
|
|
71
|
+
|
|
72
|
+
#ifdef __cplusplus
|
|
73
|
+
}
|
|
74
|
+
#endif
|
|
75
|
+
#endif
|
|
Binary file
|