slint-ui / slint

Slint is a declarative GUI toolkit to build native user interfaces for Rust, C++, or JavaScript apps.
https://slint.dev
Other
16.93k stars 566 forks source link

PNG and BMP Image Format not supported #1108

Closed AlexanderHeim closed 1 year ago

AlexanderHeim commented 2 years ago

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?

tronical commented 2 years ago

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" }

AlexanderHeim commented 2 years ago

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 commented 2 years ago

No, adding image version 0.24.0 didnt change anything sadly

tronical commented 2 years ago

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?

AlexanderHeim commented 2 years ago

Setting slint backend to GL does not fix it either.

feature tree is attached featuretree.txt

ogoffart commented 2 years ago

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.

tronical commented 2 years ago

ping @AlexanderHeim :-)

AlexanderHeim commented 2 years ago

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

tronical commented 2 years ago

No problem :). Good luck with school!

AlexanderHeim commented 2 years ago

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

ogoffart commented 2 years ago

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.

AlexanderHeim commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

Update: Updating the dependencies doesnt do anything either.

ogoffart commented 1 year ago

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.