Skip to content

Commit db878e0

Browse files
authored
jpegxl: Handle various bits per sample values in JPEG XL files (#4738)
Handle bps other than 8, 16, 32, with appropriate conversion. --------- Signed-off-by: Peter Kovář <peter.kovar@reflexion.tv>
1 parent 255a84f commit db878e0

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

src/jpegxl.imageio/jxlinput.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ JxlInput::open(const std::string& name, ImageSpec& newspec)
221221
JxlPixelFormat format;
222222
JxlDataType jxl_data_type;
223223
TypeDesc m_data_type;
224+
uint32_t bits = 0;
224225

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

252-
switch (info.bits_per_sample) {
253-
case 8:
253+
if (info.bits_per_sample <= 8) {
254254
jxl_data_type = JXL_TYPE_UINT8;
255255
m_data_type = TypeDesc::UINT8;
256-
break;
257-
case 16:
256+
bits = 8;
257+
} else if (info.bits_per_sample <= 16) {
258258
jxl_data_type = is_float ? JXL_TYPE_FLOAT16 : JXL_TYPE_UINT16;
259259
m_data_type = is_float ? TypeDesc::HALF : TypeDesc::UINT16;
260-
break;
261-
case 32:
260+
bits = 16;
261+
} else if (info.bits_per_sample <= 32) {
262262
jxl_data_type = JXL_TYPE_FLOAT;
263263
m_data_type = TypeDesc::FLOAT;
264-
break;
265-
default: errorfmt("Unsupported bits per sample\n"); return false;
264+
bits = 32;
265+
} else {
266+
errorfmt("Unsupported bits per sample\n");
267+
return false;
266268
}
267269

268270
format = { m_channels, jxl_data_type, JXL_NATIVE_ENDIAN, 0 };
@@ -307,11 +309,9 @@ JxlInput::open(const std::string& name, ImageSpec& newspec)
307309
return false;
308310
}
309311
if (buffer_size
310-
!= info.xsize * info.ysize * m_channels * info.bits_per_sample
311-
/ 8) {
312+
!= info.xsize * info.ysize * m_channels * bits / 8) {
312313
errorfmt("Invalid out buffer size {} {}\n", buffer_size,
313-
info.xsize * info.ysize * m_channels
314-
* info.bits_per_sample / 8);
314+
info.xsize * info.ysize * m_channels * bits / 8);
315315
return false;
316316
}
317317

0 commit comments

Comments
 (0)