mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-23 08:47:56 +01:00
Fix Rust PNG benchmark
The Rust PNG benchmark no longer compiles. This is similar to the issue that was fixed in pull request #68 for the Rust GIF benchmark. A new version of the png crate was published that broke clean builds. I've pinned the version to 0.17, which is the newest, and changed the code to use the new API. NOTE: Parts of the png crate documentation hasn't been updated to correctly list the new transformation defaults. The documentation for the `normalize_to_color8` method does say that the defaults changed from version 0.16 to 0.17.
This commit is contained in:
2 files changed
+7
-6
No files matched your search
@@ -4,5 +4,5 @@ version = "0.0.1"
|
|||||||
authors = ["Nigel Tao <nigeltao@golang.org>"]
|
authors = ["Nigel Tao <nigeltao@golang.org>"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
png = "*"
|
png = "0.17"
|
||||||
rustc_version_runtime = "*"
|
rustc_version_runtime = "*"
|
||||||
@@ -145,19 +145,20 @@ fn bench(
|
|||||||
|
|
||||||
// decode returns the number of bytes processed.
|
// decode returns the number of bytes processed.
|
||||||
fn decode(dst0: &mut [u8], dst1: &mut [u8], src: &[u8]) -> u64 {
|
fn decode(dst0: &mut [u8], dst1: &mut [u8], src: &[u8]) -> u64 {
|
||||||
let decoder = png::Decoder::new(src);
|
let mut decoder = png::Decoder::new(src);
|
||||||
let (info, mut reader) = decoder.read_info().unwrap();
|
decoder.set_transformations(png::Transformations::normalize_to_color8());
|
||||||
|
let mut reader = decoder.read_info().unwrap();
|
||||||
|
let info = reader.next_frame(dst0).unwrap();
|
||||||
let num_bytes = info.buffer_size() as u64;
|
let num_bytes = info.buffer_size() as u64;
|
||||||
reader.next_frame(dst0).unwrap();
|
|
||||||
if info.color_type == png::ColorType::Grayscale {
|
if info.color_type == png::ColorType::Grayscale {
|
||||||
// No conversion necessary.
|
// No conversion necessary.
|
||||||
return num_bytes;
|
return num_bytes;
|
||||||
} else if info.color_type == png::ColorType::RGB {
|
} else if info.color_type == png::ColorType::Rgb {
|
||||||
// Convert RGB => BGRA.
|
// Convert RGB => BGRA.
|
||||||
let new_size = ((num_bytes / 3) * 4) as usize;
|
let new_size = ((num_bytes / 3) * 4) as usize;
|
||||||
rgb_to_bgra(&dst0[..num_bytes as usize], &mut dst1[..new_size]);
|
rgb_to_bgra(&dst0[..num_bytes as usize], &mut dst1[..new_size]);
|
||||||
return new_size as u64;
|
return new_size as u64;
|
||||||
} else if info.color_type == png::ColorType::RGBA {
|
} else if info.color_type == png::ColorType::Rgba {
|
||||||
// Convert RGBA => BGRA.
|
// Convert RGBA => BGRA.
|
||||||
for i in 0..((num_bytes / 4) as usize) {
|
for i in 0..((num_bytes / 4) as usize) {
|
||||||
let d = dst0[(4 * i) + 0];
|
let d = dst0[(4 * i) + 0];
|
||||||
|
|||||||
Reference in new issue
Block a user