Skip to content

Commit 66a2d41

Browse files
committed
Handle various bits per sample values
Signed-off-by: Peter Kovář <peter.kovar@reflexion.tv>
1 parent ff8d777 commit 66a2d41

1 file changed

Lines changed: 11 additions & 12 deletions

File tree

src/jpegxl.imageio/jxlinput.cpp

Lines changed: 11 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;
224225

225226
for (;;) {
226227
JxlDecoderStatus status = JxlDecoderProcessInput(m_decoder.get());
@@ -249,20 +250,20 @@ 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+
}
258+
else if (info.bits_per_sample <= 16) {
258259
jxl_data_type = is_float ? JXL_TYPE_FLOAT16 : JXL_TYPE_UINT16;
259260
m_data_type = is_float ? TypeDesc::HALF : TypeDesc::UINT16;
260-
break;
261-
case 32:
261+
bits = 16;
262+
}
263+
else if (info.bits_per_sample <= 32) {
262264
jxl_data_type = JXL_TYPE_FLOAT;
263265
m_data_type = TypeDesc::FLOAT;
264-
break;
265-
default: errorfmt("Unsupported bits per sample\n"); return false;
266+
bits = 32;
266267
}
267268

268269
format = { m_channels, jxl_data_type, JXL_NATIVE_ENDIAN, 0 };
@@ -307,11 +308,9 @@ JxlInput::open(const std::string& name, ImageSpec& newspec)
307308
return false;
308309
}
309310
if (buffer_size
310-
!= info.xsize * info.ysize * m_channels * info.bits_per_sample
311-
/ 8) {
311+
!= info.xsize * info.ysize * m_channels * bits / 8) {
312312
errorfmt("Invalid out buffer size {} {}\n", buffer_size,
313-
info.xsize * info.ysize * m_channels
314-
* info.bits_per_sample / 8);
313+
info.xsize * info.ysize * m_channels * bits / 8);
315314
return false;
316315
}
317316

0 commit comments

Comments
 (0)