Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/jpegxl.imageio/jxlinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ JxlInput::open(const std::string& name, ImageSpec& newspec)
JxlPixelFormat format;
JxlDataType jxl_data_type;
TypeDesc m_data_type;
uint32_t bits = 0;

for (;;) {
JxlDecoderStatus status = JxlDecoderProcessInput(m_decoder.get());
Expand Down Expand Up @@ -249,20 +250,21 @@ JxlInput::open(const std::string& name, ImageSpec& newspec)
// Need to check how we can support bfloat16 if jpegxl supports it
bool is_float = info.exponent_bits_per_sample > 0;

switch (info.bits_per_sample) {
case 8:
if (info.bits_per_sample <= 8) {
jxl_data_type = JXL_TYPE_UINT8;
m_data_type = TypeDesc::UINT8;
break;
case 16:
bits = 8;
} else if (info.bits_per_sample <= 16) {
jxl_data_type = is_float ? JXL_TYPE_FLOAT16 : JXL_TYPE_UINT16;
m_data_type = is_float ? TypeDesc::HALF : TypeDesc::UINT16;
break;
case 32:
bits = 16;
} else if (info.bits_per_sample <= 32) {
jxl_data_type = JXL_TYPE_FLOAT;
m_data_type = TypeDesc::FLOAT;
break;
default: errorfmt("Unsupported bits per sample\n"); return false;
bits = 32;
} else {
errorfmt("Unsupported bits per sample\n");
return false;
}

format = { m_channels, jxl_data_type, JXL_NATIVE_ENDIAN, 0 };
Expand Down Expand Up @@ -307,11 +309,9 @@ JxlInput::open(const std::string& name, ImageSpec& newspec)
return false;
}
if (buffer_size
!= info.xsize * info.ysize * m_channels * info.bits_per_sample
/ 8) {
!= info.xsize * info.ysize * m_channels * bits / 8) {
errorfmt("Invalid out buffer size {} {}\n", buffer_size,
info.xsize * info.ysize * m_channels
* info.bits_per_sample / 8);
info.xsize * info.ysize * m_channels * bits / 8);
return false;
}

Expand Down
Loading