improve lossless webp compression

This commit is contained in:
Andrei Alexeyev 2019-05-06 11:19:03 +03:00
parent b4081c6550
commit 8047ca18ce
No known key found for this signature in database
GPG key ID: 363707CD4C7FE8A4
63 changed files with 119 additions and 81 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 MiB

After

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 519 KiB

After

Width:  |  Height:  |  Size: 394 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 MiB

After

Width:  |  Height:  |  Size: 1.3 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 460 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 360 KiB

View file

@ -1,7 +1,7 @@
# Autogenerated by the atlas packer, do not modify
texture = atlas_common_0
region_x = 4000
region_y = 508
region_x = 3996
region_y = 1122
region_w = 92
region_h = 127

View file

@ -1,7 +1,7 @@
# Autogenerated by the atlas packer, do not modify
texture = atlas_common_0
region_x = 4000
region_y = 639
region_x = 1386
region_y = 1508
region_w = 92
region_h = 127

View file

@ -1,7 +1,7 @@
# Autogenerated by the atlas packer, do not modify
texture = atlas_common_0
region_x = 4000
region_y = 770
region_x = 1916
region_y = 1530
region_w = 92
region_h = 127

View file

@ -1,7 +1,7 @@
# Autogenerated by the atlas packer, do not modify
texture = atlas_common_0
region_x = 3996
region_y = 1122
region_x = 2012
region_y = 1530
region_w = 92
region_h = 127

View file

@ -1,7 +1,7 @@
# Autogenerated by the atlas packer, do not modify
texture = atlas_common_0
region_x = 1386
region_y = 1508
region_x = 508
region_y = 1532
region_w = 92
region_h = 127

View file

@ -1,7 +1,7 @@
# Autogenerated by the atlas packer, do not modify
texture = atlas_common_0
region_x = 1916
region_y = 1530
region_x = 604
region_y = 1532
region_w = 92
region_h = 127

View file

@ -1,7 +1,7 @@
# Autogenerated by the atlas packer, do not modify
texture = atlas_common_0
region_x = 2012
region_y = 1530
region_x = 700
region_y = 1536
region_w = 92
region_h = 127

View file

@ -1,7 +1,7 @@
# Autogenerated by the atlas packer, do not modify
texture = atlas_common_0
region_x = 508
region_y = 1532
region_x = 796
region_y = 1536
region_w = 92
region_h = 127

View file

@ -1,7 +1,7 @@
# Autogenerated by the atlas packer, do not modify
texture = atlas_common_0
region_x = 604
region_y = 1532
region_x = 892
region_y = 1536
region_w = 92
region_h = 127

View file

@ -1,7 +1,7 @@
# Autogenerated by the atlas packer, do not modify
texture = atlas_common_0
region_x = 700
region_y = 1536
region_x = 210
region_y = 1544
region_w = 92
region_h = 127

View file

@ -1,7 +1,7 @@
# Autogenerated by the atlas packer, do not modify
texture = atlas_common_0
region_x = 796
region_y = 1536
region_x = 306
region_y = 1544
region_w = 92
region_h = 127

View file

@ -1,7 +1,7 @@
# Autogenerated by the atlas packer, do not modify
texture = atlas_common_0
region_x = 892
region_y = 1536
region_x = 1694
region_y = 1549
region_w = 92
region_h = 127

View file

@ -1,7 +1,7 @@
# Autogenerated by the atlas packer, do not modify
texture = atlas_common_0
region_x = 210
region_y = 1544
region_x = 1790
region_y = 1549
region_w = 92
region_h = 127

View file

@ -1,7 +1,7 @@
# Autogenerated by the atlas packer, do not modify
texture = atlas_common_0
region_x = 306
region_y = 1544
region_x = 3796
region_y = 1612
region_w = 92
region_h = 127

View file

@ -1,7 +1,7 @@
# Autogenerated by the atlas packer, do not modify
texture = atlas_common_0
region_x = 1694
region_y = 1549
region_x = 3892
region_y = 1612
region_w = 92
region_h = 127

View file

@ -1,7 +1,7 @@
# Autogenerated by the atlas packer, do not modify
texture = atlas_common_0
region_x = 1790
region_y = 1549
region_x = 3988
region_y = 1612
region_w = 92
region_h = 127

View file

@ -1,7 +1,7 @@
# Autogenerated by the atlas packer, do not modify
texture = atlas_common_0
region_x = 3796
region_x = 1282
region_y = 1612
region_w = 92
region_h = 127

View file

@ -1,7 +1,7 @@
# Autogenerated by the atlas packer, do not modify
texture = atlas_common_0
region_x = 3892
region_y = 1612
region_x = 402
region_y = 1616
region_w = 92
region_h = 127

View file

@ -1,7 +1,7 @@
# Autogenerated by the atlas packer, do not modify
texture = atlas_common_0
region_x = 3988
region_y = 1612
region_x = 1126
region_y = 1616
region_w = 92
region_h = 127

View file

@ -1,7 +1,7 @@
# Autogenerated by the atlas packer, do not modify
texture = atlas_common_0
region_x = 1282
region_y = 1612
region_x = 2
region_y = 1628
region_w = 92
region_h = 127

View file

@ -1,7 +1,7 @@
# Autogenerated by the atlas packer, do not modify
texture = atlas_common_0
region_x = 402
region_y = 1616
region_x = 98
region_y = 1628
region_w = 92
region_h = 127

View file

@ -1,7 +1,7 @@
# Autogenerated by the atlas packer, do not modify
texture = atlas_common_0
region_x = 1126
region_y = 1616
region_x = 1482
region_y = 1636
region_w = 92
region_h = 127

View file

@ -1,7 +1,7 @@
# Autogenerated by the atlas packer, do not modify
texture = atlas_common_0
region_x = 2
region_y = 1628
region_x = 4000
region_y = 508
region_w = 92
region_h = 127

View file

@ -1,7 +1,7 @@
# Autogenerated by the atlas packer, do not modify
texture = atlas_common_0
region_x = 98
region_y = 1628
region_x = 4000
region_y = 639
region_w = 92
region_h = 127

View file

@ -1,7 +1,7 @@
# Autogenerated by the atlas packer, do not modify
texture = atlas_common_0
region_x = 1482
region_y = 1636
region_x = 4000
region_y = 770
region_w = 92
region_h = 127

Binary file not shown.

Before

Width:  |  Height:  |  Size: 870 KiB

After

Width:  |  Height:  |  Size: 865 KiB

View file

@ -1,7 +1,7 @@
# Autogenerated by the atlas packer, do not modify
texture = atlas_common_0
region_x = 942
region_x = 962
region_y = 384
region_w = 16
region_h = 16

View file

@ -1,7 +1,7 @@
# Autogenerated by the atlas packer, do not modify
texture = atlas_common_0
region_x = 962
region_x = 942
region_y = 384
region_w = 16
region_h = 16

View file

@ -1,7 +1,7 @@
# Autogenerated by the atlas packer, do not modify
texture = atlas_common_0
region_x = 2548
region_x = 2660
region_y = 1354
region_w = 108
region_h = 120

View file

@ -1,7 +1,7 @@
# Autogenerated by the atlas packer, do not modify
texture = atlas_common_0
region_x = 2660
region_x = 2772
region_y = 1354
region_w = 108
region_h = 120

View file

@ -1,7 +1,7 @@
# Autogenerated by the atlas packer, do not modify
texture = atlas_common_0
region_x = 2772
region_x = 2884
region_y = 1354
region_w = 108
region_h = 120

View file

@ -1,7 +1,7 @@
# Autogenerated by the atlas packer, do not modify
texture = atlas_common_0
region_x = 2884
region_x = 2996
region_y = 1354
region_w = 108
region_h = 120

View file

@ -1,7 +1,7 @@
# Autogenerated by the atlas packer, do not modify
texture = atlas_common_0
region_x = 2996
region_x = 2548
region_y = 1354
region_w = 108
region_h = 120

Binary file not shown.

Before

Width:  |  Height:  |  Size: 389 KiB

After

Width:  |  Height:  |  Size: 389 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.2 KiB

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 379 KiB

After

Width:  |  Height:  |  Size: 372 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 302 KiB

After

Width:  |  Height:  |  Size: 302 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 816 KiB

After

Width:  |  Height:  |  Size: 814 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 159 KiB

After

Width:  |  Height:  |  Size: 158 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 630 KiB

After

Width:  |  Height:  |  Size: 609 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 270 KiB

After

Width:  |  Height:  |  Size: 270 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 625 KiB

After

Width:  |  Height:  |  Size: 502 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 570 KiB

After

Width:  |  Height:  |  Size: 565 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 674 KiB

After

Width:  |  Height:  |  Size: 649 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 129 KiB

After

Width:  |  Height:  |  Size: 128 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 385 KiB

After

Width:  |  Height:  |  Size: 366 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 120 KiB

After

Width:  |  Height:  |  Size: 119 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 105 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 148 KiB

After

Width:  |  Height:  |  Size: 145 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 122 KiB

After

Width:  |  Height:  |  Size: 122 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 186 KiB

After

Width:  |  Height:  |  Size: 186 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 114 KiB

After

Width:  |  Height:  |  Size: 114 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 753 KiB

After

Width:  |  Height:  |  Size: 741 KiB

View file

@ -302,10 +302,11 @@ def gen_atlas(overrides, src, dst, binsize, atlasname, tex_format=texture_format
subprocess.check_call([
'cwebp',
'-progress',
'-preset', 'drawing',
'-preset', 'icon',
'-z', '9',
'-lossless',
'-q', '100',
'-m', '6',
str(dstfile),
'-o', str(new_dstfile),
])

View file

@ -1,4 +1,4 @@
#!/usr/bin/env bash
cd "$(dirname "${BASH_SOURCE[0]}")"/.. || exit $?
find resources -type f -name "*.png" | parallel -j$(nproc) scripts/optimize-img.sh
find resources -type f -name "*.png" -or -name '*.webp' | parallel -j$(nproc) scripts/optimize-img.sh

View file

@ -2,15 +2,15 @@
set -e
png="$1"
src="$1"
if ! [[ -f "$png" ]]; then
echo "Usage: $0 [file.png]" 1>&2
if ! [[ -f "$src" ]]; then
echo "Usage: $0 file.{png,webp}" 1>&2
exit 1
fi
msg() {
echo " *** $@"
echo "$src: $@"
}
getsize() {
@ -18,28 +18,65 @@ getsize() {
echo -n "${out%% *}"
}
msg "leanifying..."
leanify -vvv "$png"
png_size="$(getsize "$png")"
id="$(identify "$png")"
makewebp() {
local input="$1"
local output="$2"
cwebp \
-preset icon \
-z 9 \
-lossless \
-q 100 \
-m 6 \
"$input" -o "$output" 2>&1 | while read line; do msg "[cwebp] $line"; done
}
if [[ "$id" == *" 16-bit "* ]]; then
msg "16bpp image, WebP conversion skipped"
exit 0
fi
fileid="$(file "$src")"
orig_size="$(getsize "$src")"
msg "converting to WebP..."
webp="${png%%png}webp"
cwebp -progress -preset drawing -z 9 -lossless -q 100 "$png" -o "$webp"
webp_size="$(getsize "$webp")"
if [[ "$fileid" == *" Web/P image"* ]]; then
if [[ "$fileid" == *" YUV color"* ]]; then
msg "lossy WebP detected, will not process"
exit
fi
msg "PNG: $png_size bytes"
msg "WebP: $webp_size bytes"
msg "recompressing..."
makewebp "$src" "$src~"
new_size="$(getsize "$src~")"
msg "old: $orig_size bytes"
msg "new: $new_size bytes"
if [ "$png_size" -lt "$webp_size" ]; then
msg "Keeping PNG ('$png'; $png_size bytes)"
rm -fv "$webp"
if [[ "$new_size" -lt "$orig_size" ]]; then
msg "keeping new version"
mv "$src~" "$src"
else
msg "keeping original version"
rm -f "$src~"
fi
elif [[ "$fileid" == *" PNG image data"* ]]; then
msg "leanifying..."
leanify -vvv "$src" 2>&1 | while read line; do msg "[leanify] $line"; done
png_size="$(getsize "$src")"
id="$(identify "$src")"
if [[ "$id" == *" 16-bit "* ]]; then
msg "16bpp image, WebP conversion skipped"
else
msg "converting to WebP..."
webp="${src%%png}webp"
makewebp "$src" "$webp"
webp_size="$(getsize "$webp")"
msg "PNG: $png_size bytes"
msg "WebP: $webp_size bytes"
if [[ "$png_size" -lt "$webp_size" ]]; then
msg "keeping PNG ('$src'; $png_size bytes)"
rm -f "$webp"
else
msg "keeping WebP ('$webp'; $webp_size bytes)"
rm -f "$src"
fi
fi
else
msg "Keeping WebP ('$webp'; $webp_size bytes)"
rm -fv "$png"
msg "unhandled file type" 1>&2
exit 1
fi