Skip to content
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

Add jxl cmyk support #3883

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

Add jxl cmyk support #3883

wants to merge 1 commit into from

Conversation

jcupitt
Copy link
Member

@jcupitt jcupitt commented Mar 8, 2024

I had a quick go, but it fails with:

$ vips copy cmyk.jpg x.jxl
attaching 961644 bytes of ICC
attaching exif-data ..
JxlBasicInfo:
    have_container = 0
    xsize = 1450
    ysize = 2048
    bits_per_sample = 8
    exponent_bits_per_sample = 0
    intensity_target = 0
    min_nits = 0
    relative_to_max_display = 0
    linear_below = 0
    uses_original_profile = 0
    have_preview = 0
    have_animation = 0
    orientation = 1
    num_color_channels = 3
    num_extra_channels = 1
    alpha_bits = 8
    alpha_exponent_bits = 0
    alpha_premultiplied = 0
    preview.xsize = 0
    preview.ysize = 0
    animation.tps_numerator = 10
    animation.tps_denominator = 1
    animation.num_loops = 0
    animation.have_timecodes = 0
JxlPixelFormat:
    num_channels = 4
    data_type = JXL_TYPE_UINT8
    endianness = 0
    align = 0
JxlEncoderFrameSettings:
    tier = 0
    distance = 2.35
    effort = 7
    lossless = 0
./lib/jxl/encode.cc:820: Extra channel 0 is not initialized
JXL_ENC_ERROR

ie. we are passing a 3 channel (CMY) buffer with 1 extra channel (K).

We use JxlEncoderSetExtraChannelInfo() to tag the extra channel as black. I'd think this ought to work, how do we encode an interleaved CMYK image?

But it fails with:

```
./lib/jxl/encode.cc:820: Extra channel 0 is not initialized
JXL_ENC_ERROR
```

How do we pass an interleaved CMYK buffer?
@jcupitt
Copy link
Member Author

jcupitt commented Mar 8, 2024

This pr is for #3880

@jcupitt
Copy link
Member Author

jcupitt commented Mar 8, 2024

I asked on the libjxl discord and they say CMYK needs to be encoded as CMY plus a separate K channel, so we'll need quite a bit of code to break off the K and compress the extra channel. Let's park this PR for now.

@jcupitt jcupitt marked this pull request as draft March 8, 2024 12:27
@jcupitt
Copy link
Member Author

jcupitt commented Mar 8, 2024

Thinking a little more, we'll need to:

  • render the whole CMYK (and possibly alpha?) image to a huge memory array
  • break it into separate CMY and KA arrays
  • encode the CMY, then encode the KA

So that's at least 2x the memory use. We should probably do progressive write before returning to this PR, we might be able to avoid the extra huge memory allocations.

@kleisauke
Copy link
Member

I remembered a similar issue when loading a CMYK + Alpha image, see: #3623 (comment).

Furthermore, it looks like cjxl also fails to encode CMYK images: libjxl/libjxl#2126.

@jcupitt
Copy link
Member Author

jcupitt commented Mar 12, 2024

I've tagged this as blocked upstream since chunked jxl write needs doing first.

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

Successfully merging this pull request may close these issues.

None yet

2 participants