Skip to content

JPEG XL: Saving image in float band format fails #2830

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dloebl opened this issue Jun 1, 2022 · 5 comments
Closed

JPEG XL: Saving image in float band format fails #2830

dloebl opened this issue Jun 1, 2022 · 5 comments
Labels
Milestone

Comments

@dloebl
Copy link
Contributor

dloebl commented Jun 1, 2022

jxlsave seems to fail with the following error in case the input image is in the float band format:
jxlsave: error JxlEncoderSetBasicInfo

We noticed this behaviour while resizing images with an alpha channel.

Example image:
test.png

C code:

#include <vips/vips.h>
#include <stdio.h>

int main() {
        VipsImage* in, *thm, *pre, *out;

        VIPS_INIT("test app");

        // load input png
        vips_pngload("test.png",
                &in,
                NULL);

        // resize image
        vips_premultiply(in, &pre, NULL);
        vips_resize(pre, &thm, 0.5, NULL);
        vips_unpremultiply(thm, &out, NULL);

        // save as JPEG XL
        vips_jxlsave(out, "out.jxl", NULL);
        puts(vips_error_buffer());

        vips_shutdown();
        return 0;
}

Environment

  • OS: MacOS 12.4
  • Vips: v8.13 master
  • libjxl: v0.6.1
@dloebl dloebl added the bug label Jun 1, 2022
@jcupitt
Copy link
Member

jcupitt commented Jun 1, 2022

Hi @dloebl, you're right, looks like we need to add a new SAVEABLE enum for scRGB. Let's fix this for 8.13.

@jcupitt jcupitt added this to the 8.13 milestone Jun 1, 2022
@jcupitt
Copy link
Member

jcupitt commented Jun 12, 2022

After asking on libjxl discord, it seems this is the position:

save strategy

  • FLOAT srgb ... convert to 8 bit for write
  • scrgb ... write as float, call JxlColorEncodingSetToLinearSRGB(), libjxl wants 0 - 1 so there's no scaling

load strategy

  • char/short data ... as now
  • float data ... convert to scRGB, attach the profile, no scaling needed, no need to worry about lionear/nonlinear, since libjxl with synthesise a profile with the correct gamma if necessary

jcupitt added a commit that referenced this issue Jun 12, 2022
after some discussion on discord with the libjxl maintainers

see #2830

to do: save scrgb to eg. JPEG fails right now :( we need to do
scRGB->sRGB in jpegsave
@jcupitt
Copy link
Member

jcupitt commented Jun 12, 2022

Fixed with 9f3860e

@jcupitt jcupitt closed this as completed Jun 12, 2022
@lovell
Copy link
Member

lovell commented Jun 13, 2022

@jcupitt It looks like a couple of stray #define DEBUG snuck into commit 9f3860e

@jcupitt
Copy link
Member

jcupitt commented Jun 13, 2022

Ooop, sorry!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants