Skip to content

Commit

Permalink
jpeg: handle Ultra HDR image formats
Browse files Browse the repository at this point in the history
Signed-off-by: loicvital <[email protected]>
  • Loading branch information
mugulmd committed Oct 18, 2024
1 parent bae85af commit abb0251
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions src/jpeg.imageio/jpeginput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,28 @@ JpgInput::read_uhdr(Filesystem::IOProxy* ioproxy)
}

uhdr_raw_image_t* uhdr_raw = uhdr_get_decoded_image(m_uhdr_dec);
ImageSpec newspec = ImageSpec(uhdr_raw->w, uhdr_raw->h, 4, TypeDesc::HALF);

int nchannels;
TypeDesc desc;
switch (uhdr_raw->fmt) {
case UHDR_IMG_FMT_32bppRGBA8888:
nchannels = 4;
desc = TypeDesc::UINT8;
break;
case UHDR_IMG_FMT_64bppRGBAHalfFloat:
nchannels = 4;
desc = TypeDesc::HALF;
break;
case UHDR_IMG_FMT_24bppRGB888:
nchannels = 3;
desc = TypeDesc::UINT8;
break;
default:
errorfmt("Unsupported Ultra HDR image format: {}", int(uhdr_raw->fmt));
return false;
}

ImageSpec newspec = ImageSpec(uhdr_raw->w, uhdr_raw->h, nchannels, desc);
newspec.extra_attribs = m_spec.extra_attribs;
m_spec = newspec;

Expand Down Expand Up @@ -502,7 +523,15 @@ JpgInput::read_native_scanline(int subimage, int miplevel, int y, int /*z*/,
if (m_use_uhdr) {
uhdr_raw_image_t* uhdr_raw = uhdr_get_decoded_image(m_uhdr_dec);

const size_t row_size = uhdr_raw->stride[UHDR_PLANE_PACKED] * 8;
unsigned int nbytes;
switch (uhdr_raw->fmt) {
case UHDR_IMG_FMT_32bppRGBA8888: nbytes = 4; break;
case UHDR_IMG_FMT_64bppRGBAHalfFloat: nbytes = 8; break;
case UHDR_IMG_FMT_24bppRGB888: nbytes = 3; break;
default: return false;
}

const size_t row_size = uhdr_raw->stride[UHDR_PLANE_PACKED] * nbytes;
unsigned char* top_left = static_cast<unsigned char *>(uhdr_raw->planes[UHDR_PLANE_PACKED]);
unsigned char* row_data_start = top_left + row_size * y;
memcpy(data, row_data_start, row_size);
Expand Down

0 comments on commit abb0251

Please sign in to comment.