From d96faec4eb7c94f5bffd6cf0935bf1ac155aabd4 Mon Sep 17 00:00:00 2001 From: nworbnhoj Date: Tue, 9 Aug 2022 06:18:49 +1000 Subject: [PATCH] add png_decode comments --- Cargo.lock | 15 +++++++++++++-- services/gam/src/bitmap/decode_png.rs | 9 +++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ab67684db..c123ec293 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1209,7 +1209,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f82b0f4c27ad9f8bfd1f3208d882da2b09c301bc1c828fd3a00d0216d2fbbff6" dependencies = [ "crc32fast", - "miniz_oxide", + "miniz_oxide 0.5.1", ] [[package]] @@ -1387,6 +1387,7 @@ dependencies = [ "locales", "log", "log-server", + "miniz_oxide 0.4.4", "num-derive", "num-traits", "qrcode", @@ -2049,6 +2050,16 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" +[[package]] +name = "miniz_oxide" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a92518e98c078586bc6c934028adcca4c92a53d6a958196de835170a01d84e4b" +dependencies = [ + "adler", + "autocfg", +] + [[package]] name = "miniz_oxide" version = "0.5.1" @@ -2477,7 +2488,7 @@ dependencies = [ "bitflags", "crc32fast", "deflate", - "miniz_oxide", + "miniz_oxide 0.5.1", ] [[package]] diff --git a/services/gam/src/bitmap/decode_png.rs b/services/gam/src/bitmap/decode_png.rs index a827f3998..61f7a34fd 100644 --- a/services/gam/src/bitmap/decode_png.rs +++ b/services/gam/src/bitmap/decode_png.rs @@ -219,6 +219,7 @@ impl DecodePng { // png filter specification calls for initial prior_line = [0u8] // see: https://www.w3.org/TR/PNG/#9Filters // but [0u8] results in distortion??????? + // TODO fix this properly (probably a byte overflow or bad cast) self.prior_line = vec![125u8; self.bytes_per_line]; self.prior_px = vec![0u8; self.bytes_per_pixel]; } @@ -425,7 +426,7 @@ impl DecodePng { self.inflated_index += 1; if filter_type <= 4 { log::trace!( - "png decode prior_line {} filter type = {}", + "png decode line {} filter type = {}", self.byte_index / self.bytes_per_line, filter_type ); @@ -440,6 +441,7 @@ impl DecodePng { // Get an inflated byte from the png idat // Note: this fn() updates inflated_index, byte_index, line_index & filter_type + // a scanline of rgb begins with a filterbyte FRGBRGBRGBRGB... fn get_inflated_byte(&mut self) -> Option { match self.inflated_length() { 0 => None, @@ -462,6 +464,9 @@ impl DecodePng { } // in the notation from https://www.w3.org/TR/PNG/#9Filters + // note that a & c relate to the equivalent byte in the prior pixel + // prior_line R G B R G B c G B b G B R G B + // current_line R G B R G B a G B x fn unfilter(&mut self) -> Option { let filter = self.filter_type; let index = self.line_index; @@ -497,7 +502,7 @@ impl DecodePng { // in the notation from https://www.w3.org/TR/PNG/#9Filters fn average(a: u8, b: u8) -> u8 { - ((a as i16 + b as i16) >> 1) as u8 + ((a as u16 + b as u16) >> 1) as u8 } // in the notation from https://www.w3.org/TR/PNG/#9Filters