Skip to content

support variable number of channels, png#1

Open
dllu wants to merge 1 commit intotempus-ex:mainfrom
dllu:dllu/png-rgb24
Open

support variable number of channels, png#1
dllu wants to merge 1 commit intotempus-ex:mainfrom
dllu:dllu/png-rgb24

Conversation

@dllu
Copy link
Copy Markdown

@dllu dllu commented Jul 15, 2021

Uses two bits to encode number of planes (1, 2, 3, or 4); implement reading png file. tested on monochrome and rgb png files.

For example to run on the Lossless Photo Compression Benchmark, we can download LPCB.7z from google drive and then run the following program:

extern crate hello_video_codec as hvc;
fn main() {
    let mut size = 0;
    let mut encode_time = std::time::Duration::new(0, 0);
    let mut decode_time = std::time::Duration::new(0, 0);
    for img in std::env::args().skip(1) {
        let frame = hvc::frame::RGB48Frame::from_png(&img).unwrap();

        let mut encoded = Vec::new();
        let now = std::time::Instant::now();
        frame.encode::<hvc::codec::Codec, _>(&mut encoded).unwrap();
        encode_time += now.elapsed();

        size += encoded.len();

        let now = std::time::Instant::now();
        let decoded = hvc::frame::RGB48Frame::decode::<hvc::codec::Codec, _>(
            &*encoded,
            frame.width,
            frame.height,
        )
        .unwrap();
        decode_time += now.elapsed();
        assert_eq!(frame == decoded, true);
        println!("{} : {} --> {}", &img, frame.data.len(), encoded.len());
    }
    println!("encode time: {} ms", encode_time.as_millis());
    println!("decode time: {} ms", decode_time.as_millis());
    println!("size: {} bytes", size);
}

We note that LPCB.7z contains a monochrome PNG file

identify /Users/dllu/Downloads/LPCB/PIA13943.png
/Users/dllu/Downloads/LPCB/PIA13943.png PNG 3000x2400 3000x2400+0+0 8-bit Gray 256c 560526B 0.000u 0:00.000

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

Successfully merging this pull request may close these issues.

1 participant