From c79ba3ab8acf95aca14410ad736d51d982428911 Mon Sep 17 00:00:00 2001 From: Josh Holmer Date: Sun, 26 Feb 2017 22:53:23 -0500 Subject: [PATCH] Version 0.14.4 --- CHANGELOG.md | 3 +++ Cargo.lock | 54 +++++++++++++++++++-------------------- Cargo.toml | 2 +- src/reduction.rs | 13 ++++++++-- tests/files/issue-59.png | Bin 0 -> 3128 bytes tests/regression.rs | 15 +++++++++++ 6 files changed, 57 insertions(+), 30 deletions(-) create mode 100644 tests/files/issue-59.png diff --git a/CHANGELOG.md b/CHANGELOG.md index 8967a752..c27cd77f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +**Version 0.14.4** + - Fix bug when reducing RGBA to Indexed if image has 256 colors plus a background color + **Version 0.14.3** - Fix multiple bugs when reducing transparency palettes diff --git a/Cargo.lock b/Cargo.lock index 5e0a4b22..0f7f4682 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ [root] name = "oxipng" -version = "0.14.3" +version = "0.14.4" dependencies = [ "bit-vec 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -65,8 +65,8 @@ name = "cargo_metadata" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "serde 0.9.8 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 0.9.8 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 0.9.9 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 0.9.9 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 0.9.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -147,7 +147,7 @@ name = "enum_primitive" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "num-traits 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -168,9 +168,9 @@ dependencies = [ "byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "enum_primitive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "num-iter 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", - "num-rational 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)", + "num-iter 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)", + "num-rational 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", "png 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -240,33 +240,33 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "num-integer" -version = "0.1.32" +version = "0.1.33" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "num-traits 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "num-iter" -version = "0.1.32" +version = "0.1.33" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "num-integer 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)", + "num-integer 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "num-rational" -version = "0.1.35" +version = "0.1.36" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "num-integer 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)", + "num-integer 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "num-traits" -version = "0.1.36" +version = "0.1.37" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -285,7 +285,7 @@ dependencies = [ "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "deflate 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", "inflate 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "num-iter 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", + "num-iter 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -350,7 +350,7 @@ dependencies = [ [[package]] name = "serde" -version = "0.9.8" +version = "0.9.9" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -363,7 +363,7 @@ dependencies = [ [[package]] name = "serde_derive" -version = "0.9.8" +version = "0.9.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "quote 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)", @@ -378,8 +378,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "dtoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "itoa 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 0.9.8 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 0.9.9 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -541,10 +541,10 @@ dependencies = [ "checksum memchr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1dbccc0e46f1ea47b9f17e6d67c5a96bd27030519c519c9c91327e31275a47b4" "checksum miniz-sys 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "28eaee17666671fa872e567547e8428e83308ebe5808cdf6a0e28397dbe2c726" "checksum nom 1.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a5b8c256fd9471521bcb84c3cdba98921497f1a331cbc15b8030fc63b82050ce" -"checksum num-integer 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "fb24d9bfb3f222010df27995441ded1e954f8f69cd35021f6bef02ca9552fb92" -"checksum num-iter 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "287a1c9969a847055e1122ec0ea7a5c5d6f72aad97934e131c83d5c08ab4e45c" -"checksum num-rational 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)" = "54ff603b8334a72fbb27fe66948aac0abaaa40231b3cecd189e76162f6f38aaf" -"checksum num-traits 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)" = "a16a42856a256b39c6d3484f097f6713e14feacd9bfb02290917904fae46c81c" +"checksum num-integer 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)" = "21e4df1098d1d797d27ef0c69c178c3fab64941559b290fcae198e0825c9c8b5" +"checksum num-iter 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)" = "f7d1891bd7b936f12349b7d1403761c8a0b85a18b148e9da4429d5d102c1a41e" +"checksum num-rational 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)" = "c2dc5ea04020a8f18318ae485c751f8cfa1c0e69dcf465c29ddaaa64a313cc44" +"checksum num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "e1cbfa3781f3fe73dc05321bed52a06d2d491eaa764c52335cf4399f046ece99" "checksum num_cpus 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a225d1e2717567599c24f88e49f00856c6e825a12125181ee42c4257e3688d39" "checksum png 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3cb773e9a557edb568ce9935cf783e3cdcabe06a9449d41b3e5506d88e582c82" "checksum quine-mc_cluskey 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "07589615d719a60c8dd8a4622e7946465dfef20d1a428f969e3443e7386d5f45" @@ -555,9 +555,9 @@ dependencies = [ "checksum regex-syntax 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9191b1f57603095f105d317e375d19b1c9c5c3185ea9633a99a6dcbed04457" "checksum rustc-serialize 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)" = "237546c689f20bb44980270c73c3b9edd0891c1be49cc1274406134a66d3957b" "checksum semver 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2d5b7638a1f03815d94e88cb3b3c08e87f0db4d683ef499d1836aaf70a45623f" -"checksum serde 0.9.8 (registry+https://github.com/rust-lang/crates.io-index)" = "204db0f2a5335be7313fd4453132fd56d2085aed081c673140a256772903e116" +"checksum serde 0.9.9 (registry+https://github.com/rust-lang/crates.io-index)" = "05a67b8a53f885f4b6e3ed183806035819f9862474e747fe4488a6d63bcbfcb7" "checksum serde_codegen_internals 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a5113d5bd16471b183803b374f0fe4877ad9658b95e33b11f4a004d73aacc74a" -"checksum serde_derive 0.9.8 (registry+https://github.com/rust-lang/crates.io-index)" = "e88ec062a02cbebfd6276044a305d665a9919b497aa6acb2e12c070d1a50d32d" +"checksum serde_derive 0.9.9 (registry+https://github.com/rust-lang/crates.io-index)" = "a85017d774504173e5f908f69790ad7616f535f4ea91d0cdc65676ea3c933709" "checksum serde_json 0.9.8 (registry+https://github.com/rust-lang/crates.io-index)" = "6501ac6f8b74f9b1033f7ddf79a08edfa0f58d6f8e3190cb8dc97736afa257a8" "checksum simd 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "63b5847c2d766ca7ce7227672850955802fabd779ba616aeabead4c2c3877023" "checksum strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b4d15c810519a91cf877e7e36e63fe068815c678181439f2f29e2562147c3694" diff --git a/Cargo.toml b/Cargo.toml index 7b533cec..d6e79dbd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ homepage = "https://github.com/shssoichiro/oxipng" license = "MIT" name = "oxipng" repository = "https://github.com/shssoichiro/oxipng" -version = "0.14.3" +version = "0.14.4" [lib] name = "oxipng" diff --git a/src/reduction.rs b/src/reduction.rs index 9df4bbc7..61964126 100644 --- a/src/reduction.rs +++ b/src/reduction.rs @@ -134,7 +134,13 @@ pub fn reduce_rgba_to_palette(png: &mut PngData) -> bool { } } - let mut color_palette = Vec::with_capacity(palette.len() * 3); + let mut color_palette = Vec::with_capacity(palette.len() * 3 + + if png.aux_headers + .contains_key(&"bKGD".to_string()) { + 6 + } else { + 0 + }); let mut trans_palette = Vec::with_capacity(palette.len()); for color in &palette { for (i, byte) in color.iter().enumerate() { @@ -151,7 +157,7 @@ pub fn reduce_rgba_to_palette(png: &mut PngData) -> bool { let header_pixels = bkgd_header.iter().skip(1).step(2).cloned().collect::>(); if let Some(entry) = color_palette.chunks(3).position(|x| x == header_pixels.as_slice()) { *bkgd_header = vec![entry as u8]; - } else if color_palette.len() == 255 { + } else if color_palette.len() / 3 == 256 { return false; } else { let entry = color_palette.len() / 3; @@ -167,6 +173,9 @@ pub fn reduce_rgba_to_palette(png: &mut PngData) -> bool { png.raw_data = reduced; png.palette = Some(color_palette); if trans_palette.iter().any(|x| *x != 255) { + while let Some(255) = trans_palette.last().cloned() { + trans_palette.pop(); + } png.transparency_palette = Some(trans_palette); } else { png.transparency_palette = None; diff --git a/tests/files/issue-59.png b/tests/files/issue-59.png new file mode 100644 index 0000000000000000000000000000000000000000..f2101164335d5c18ac9be4fc0c64fd60241c6bd4 GIT binary patch literal 3128 zcmd^Cdo)|=7C$F~G-zl$6^bg;302BaEuk1fQPS45DIJf-C~axn)FVZS8Kd=z=}po0 z7S#?q(_&6NQZ$c2Wpq>xQ|}0qLD7hKhJ@auz3Z-Z@0ywW-(7dDyUsr6tZ(oAo&DS2 zx4*sj$vEokp@G�|21mdD!hZ0DvR#9f4ATIk^W+4B?jw+1tYnc)M}kWtTGnKuzrF z=JF|RKr9G;)EleMml91>F=1%cn{<~mWz#QD90;sISl{$<)A;MFfN6K;+|7Fz>T0iF zWaMoM&uAkAKDo^(_45}vj}vS~p0!+Lx*{p;&**5%NP5 zqu$K+&db{;IwVOc!eB2`^Xv*MYwPMVbBbgZQ#9XZX>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