johannesvollmer / exrs

100% Safe Rust OpenEXR file library
Other
149 stars 22 forks source link

First example has uncommon sample types (Krita 4.4.5 and RenderDoc 1.18 cannot open) #153

Open curldivergence opened 2 years ago

curldivergence commented 2 years ago

Description

Hi, I've tried running a couple of examples, including the first one from README, but unfortunately, I'm unable to view the generated files neither with Krita nor with RenderDoc. The error messages I'm facing look like this (respectively):

image image

Is there any chance this is a known issue, or maybe I'm doing something wrong? :)

Thank you!

Reproducing

  1. Run the trivial example from README:
    fn main() {
    // write a file with 16-bit alpha and 32-bit color precision
    exr::prelude::write_rgba_file(
        "tests/images/out/minimal_rgb.exr",
        2048, 2048, // write an image with 2048x2048 pixels
        |x,y| ( // generate (or lookup in your own image) an f32 rgb color for each of the 2048x2048 pixels
                x as f32 / 2048.0, // red
                y as f32 / 2048.0, // green
                1.0 - (y as f32 / 2048.0), // blue
                f16::from_f32(0.8) // 16-bit alpha
        )
    ).unwrap();
    }
  2. Try to open the generated .exr with Krita or RenderDoc
  3. Observe the error

Environment

johannesvollmer commented 2 years ago

Hi, thanks for taking the time. It's not a known issue.

We only know that Affinity Designer and blender can open the images. Let's have a look at Krita and RenderDoc

Krita seems to use openexr 2.5.5 (February 12, 2021) Assuming that Krita 4.4.5 already uses this version (might want to check though)

johannesvollmer commented 2 years ago

There is a few things we can try in exrs when saving an image. For example, changing the compression method, or the difference between rgb and rgba, or a custom channel set. Also we should try to read an exr file which was exported from Krita and have a look at the contents of that file

johannesvollmer commented 2 years ago

Some observations:

curldivergence commented 2 years ago

Hi, thanks a lot for your efforts :) And sorry, I've missed your question about used Krita/RD versions. To be safe, I've updated both of them to the latest versions (5.0.5 and 1.19, respectively), but the results are the same. Please let me know if you need any other input from me. Thank you!

smaragden commented 2 years ago

First off, just a comment on the example in the readme. If you just want to test the example, there are 2 issues. First, the code assumes that the relative folder tests/images/out/ exists. Second, f16is not fully qualified or brought into scope. So for a test that works out of the box, I would suggest the following changes to the example:

use exr::prelude::*;

fn main() {
    // write a file with 16-bit alpha and 32-bit color precision
    write_rgba_file(
        "minimal_rgb.exr",
        2048, 2048, // write an image with 2048x2048 pixels
        |x,y| ( // generate (or lookup in your own image) an f32 rgb color for each of the 2048x2048 pixels
                x as f32 / 2048.0, // red
                y as f32 / 2048.0, // green
                1.0 - (y as f32 / 2048.0), // blue
                f16::from_f32(0.8) // 16-bit alpha
        )
    ).unwrap();
}

Or just fully qualify exrs::prelude::f16.

Now for the issue with the generated exr. It seems like Krita assumes that all channels are the same type. Krita opens the generated file fine as long as all channels are either f32or f16.

This is obviously a limitation in Krita and probably other software as well and should be reported to the Krita developers.

With that said and to make the first impression better for users trying out this crate, I suggest that the example works out of the box with the above changes. And that it generates a simpler more widely compatible exr by unifying the datatype for the channels.

Other than that, this is a great crate and I appreciate your work @johannesvollmer !

johannesvollmer commented 2 years ago

Excellent work! Agreeing in all of your points. Thank you Smaragden.

johannesvollmer commented 2 years ago

How would you go about the missing directory? Would it solve the issue to simply create the directory if it does not exist yet?

Also, I presume it would probably better to write into some folder inside the examples directory, instead of the test folder. What do you think

smaragden commented 2 years ago

Like in my above exemple. Just let it write the file to the current directory.

johannesvollmer commented 2 years ago

Yeah why not, for simplicity's sake