slint icon indicating copy to clipboard operation
slint copied to clipboard

PNG and BMP Image Format not supported

Open AlexanderHeim opened this issue 2 years ago • 14 comments

Hello, I am trying to load a PNG-Image file into a slint program on my Raspberry Pi.

Somehow the PNG and BMP Image formats are not supported. I am running Raspberry Pi OS light with a minimal x setup.

Am I missing any packages? I was unable to find out if i do.

Does someone know what I'm missing?

AlexanderHeim avatar Mar 26 '22 16:03 AlexanderHeim

That sounds strange, we do explicitly enable png support in the image crate at least. Are you using Rust or C++? How are you compiling Slint?

Can you try adding this to Cargo.toml of your app in case you're using Rust? image = { version = "0.24.0" }

tronical avatar Mar 26 '22 16:03 tronical

I am running it in Rust and compiling it directly on the raspberry pi using cargo in the most standard way possible.

The thing is, on my pc it works. Its only the raspberry that it doesn't.

I will test it in half an hour brb

AlexanderHeim avatar Mar 26 '22 16:03 AlexanderHeim

No, adding image version 0.24.0 didnt change anything sadly

AlexanderHeim avatar Mar 26 '22 17:03 AlexanderHeim

Ok, the mystery remains :-). Next thing on the list of things to try: Does cargo tree -e features show the png feature in the image crate? (Feel free to paste the output here or parts of it)

Alternatively: Does loading of pngs at least work if you set SLINT_BACKEND=GL?

tronical avatar Mar 26 '22 17:03 tronical

Setting slint backend to GL does not fix it either.

feature tree is attached featuretree.txt

AlexanderHeim avatar Mar 26 '22 20:03 AlexanderHeim

How are you loading the image? can you paste the relevant section of your code? Are you running the program in place (not that it matters since the image should normally be embedded in the binary by default) Do you see any warning in the console? I see in the tree that you are using the png crate version v0.17.3, which is not the latest one. I know that the version 0.17.4 version has a bug preventing to decode some images that was fixed in 0.17.5. But perhaps it would be a good idea to try cargo update anyway.

ogoffart avatar Mar 27 '22 06:03 ogoffart

ping @AlexanderHeim :-)

tronical avatar Apr 19 '22 07:04 tronical

Sorry I am having a lot of school stress right now, I will come back to this issue in a few days.

AlexanderHeim avatar Apr 19 '22 14:04 AlexanderHeim

No problem :). Good luck with school!

tronical avatar Apr 19 '22 14:04 tronical

Ok, I finally have time lol:

Context: As a diploma project i am creating a "smart" doorlock. Basically it's just a raspberry pi 4 hooked up to an electronic lock and a display. The display is the official raspberry pi 4 display. I know that this configuration is a bit overkill but yeah, this project is not about economics.

On the raspberry I am running the official raspberry pi os lite and x with startx (somewhat following https://sylvaindurand.org/launch-chromium-in-kiosk-mode/ (without chromium of course))

I have compiled the whole binary locally on the raspberry pi.

PROBLEM: Everything works wonderfully expect for showing a qr code when run on the raspberry pi. The special thing about the qr code is, that it is created at runtime, saved to a file and THEN loaded/rendered into the ui. Small hint: On my friends ubuntu machine it didn't work either (PNG Format not supported), after retrying it a week later it suddenly worked again.

Answering @ogoffart questions: I have never worked with images in slint and the deadline was pretty close so I had no choice but to quickly come up with a solution :

in mainwindow.slint:

export global qr_code_ui := {
    property <image> qr_code: @image-url("qr_code.png");
}

in main.rs:

    // Above the qr code is created and saved as a file.
    let ui_handle = ui.as_weak();
    ui_handle.upgrade_in_event_loop(move |ui| {
        while !Path::new("qr_code.png").exists() {
            std::thread::sleep(Duration::from_millis(100));
        }
        let qr = ui.global::<qr_code_ui>();
        qr.set_qr_code(match Image::load_from_path(Path::new("qr_code.png")) {
            Ok(qr) => qr,
            Err(_e) => panic!("Unable to set QrCode Image"),
        });
    });

    ui.run();

NOTE: The qr code does NOT exist when compiling.

Are you running the program in place (not that it matters since the image should normally be embedded in the binary by default)?

I have absolutely zero clue, I'm sorry.

Do you see any warning in the console?

No

Try cargo update

I am currently updating the dependencies and will reply to this issue once the updated crate is being run on the raspberry pi.

Thanks for wishing me good luck in school! I will need it as I soon have my finals haha. For more context, the diploma project resides at: https://github.com/htl-anichstrasse/shulker

AlexanderHeim avatar Apr 22 '22 14:04 AlexanderHeim

NOTE: The qr code does NOT exist when compiling

@image-url("qr_code.png");

That will then not work because this will try to read the file at compile time

Image::load_from_path(Path::new("qr_code.png"))

But this should work. If it doesn't, it might be because the path is wrong... Have you tried using an absolute path instead?

I would expect that if it cannot load the image, it should print a warning in the standard output or standard error of the program.

ogoffart avatar Apr 22 '22 18:04 ogoffart

That will then not work because this will try to read the file at compile time

Maybe I am missing something, but it clearly works on my machine. It doesn't make much sense though I know that.

AlexanderHeim avatar Apr 23 '22 05:04 AlexanderHeim

OK, so I have finally found a way to reliable get an error message:

(1280) Error on render prepare - Invalid enum

The error shows up the instant i switch to the "view" where the image is shown.

NOTE: I have yet to update the dependencies (will do it now).

AlexanderHeim avatar Apr 23 '22 05:04 AlexanderHeim

Update: Updating the dependencies doesnt do anything either.

AlexanderHeim avatar Apr 23 '22 12:04 AlexanderHeim

Is this still an issue? It seems like this s caused by a problem in the image crate. There was some error with invalid enum. Closing for now. Please re-open or comment if this is still a problem.

ogoffart avatar Nov 29 '22 11:11 ogoffart