Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong encoding of text keys #56

Open
moxian opened this issue May 18, 2022 · 2 comments
Open

Wrong encoding of text keys #56

moxian opened this issue May 18, 2022 · 2 comments

Comments

@moxian
Copy link

moxian commented May 18, 2022

Problem: png's encoded by lodepng seem to lack text_keys, as seen by the png crate and a certain non-rust closed-source application that i care about.
Given png's very strongly worded claims of standard compliance (and that png-produced images are recognized by the aforementioned non-rust application, whereas the lodepng ones are not), i assume the fault lies with lodepng.
Sadly i have not delved deep enough into the standard to provide any more specifics.

Code demonstrating the issue:
extern crate lodepng;
extern crate png;

fn main() {
    let image = vec![255u8, 0, 0, 255]; // single red pixel
    let mut encoder = lodepng::Encoder::new();
    encoder.info_png_mut().add_text("hello", "world").unwrap();
    let encoded_image = encoder.encode(&image, 1, 1).unwrap();

    // parse it back
    {
        println!("\n -- lodepng view of the metadata:");
        let mut decoder = lodepng::Decoder::new();
        let decoded = decoder.decode(&encoded_image).unwrap();
        // displays keys properly
        println!("the following text keys are present:");
        for (k, v) in decoder.info_png().text_keys() {
            println!(
                "{:?} - {:?}",
                std::str::from_utf8(k),
                std::str::from_utf8(v),
            )
        }
    }

    {
        println!("\n -- png view of the metadata:");
        let decoder = png::Decoder::new(encoded_image.as_slice());
        let mut r = decoder.read_info().unwrap();
        println!("{:?}", r.info());
        // displays nothing
        println!(
            " compressed text: {:?}\n uncompressed text: {:?}",
            r.info().compressed_latin1_text,
            r.info().uncompressed_latin1_text
        );
    }
}

Output:

 -- lodepng view of the metadata:
the following text keys are present:
Ok("hello") - Ok("world")

 -- png view of the metadata:
Info { width: 1, height: 1, bit_depth: Eight, color_type: Rgb, interlaced: false, trns: None, pixel_dims: None, palette: None, gama_chunk: None, chrm_chunk: None, frame_control: None, animation_control: None, compression: Fast, source_gamma: None, source_chromaticities: None, srgb: None, icc_profile: None, uncompressed_latin1_text: [], compressed_latin1_text: [], utf8_text: [] }
 compressed text: []
 uncompressed text: []
@kornelski
Copy link
Owner

Have you checked the utf8_text field?

@moxian
Copy link
Author

moxian commented May 19, 2022

Yes, i have. It's empty as well (again, as per png crate; i have not inspected the encoded bytes).
Playing with encoder.set_text_compression() does not change things either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants