raster icon indicating copy to clipboard operation
raster copied to clipboard

Freezing when loading png (manjaro linux)

Open NikolafTheGreat opened this issue 3 years ago • 3 comments

I am having a lot of fun with raster. It is super nice to use. However there is this small annoying thing that happens when i try to load a .png file with the raster::open function. The program stops and my fan spins up like crazy. If you have any idea what is going on then i would love to know.

NikolafTheGreat avatar Aug 09 '22 14:08 NikolafTheGreat

I have the same problem when loading 24-bit RGB PNGs, it works fine with 32-bit RGB+alpha PNGs. On my laptop it takes ~100 seconds to load (1280x1280, 24-bit RGB, non-interlaced, 84.7%) and ~ 75ms to load (1280x1280, 32-bit RGB+alpha, non-interlaced, 70.3%)

Vloeck avatar Oct 19 '22 09:10 Vloeck

    if info.color_type == png::ColorType::RGB {
        // Applies only to RGB

        let mut insert_count = 0;
        let len = (info.width * info.height) as usize;
        for i in 0..len {
            // TODO: This is slow!
            let insert_pos = 3 * (i + 1) + insert_count;
            bytes.insert(insert_pos, 255);
            insert_count += 1;
        }
    } //  TODO other ::ColorType

this is probably the cause, already annotated with a todo

Vloeck avatar Oct 19 '22 09:10 Vloeck

The original algorithm for extending from RGB to RGBA is probably O(n^2), mine should be O(n)

Vloeck avatar Oct 19 '22 12:10 Vloeck