Skip to content

Commit

Permalink
fix issue with decoding to EXR with planar (when ICT or RCT is not used)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldsmith committed Jan 16, 2025
1 parent 697e626 commit b226209
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 21 deletions.
14 changes: 11 additions & 3 deletions src/apps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,17 @@ if( OJPH_ENABLE_OPENEXR_SUPPORT )
"or disable OpenEXR support using -DOJPH_ENABLE_OpenEXR_SUPPORT=OFF.")
endif(OpenEXR_FOUND)
else(IlmBase_FOUND)
message(STATUS "OpenEXR support has been enabled but no path to the OpenEXR or IlmBase library "
"has been specified; please configure with -DCMAKE_PREFIX_PATH=<OpenEXR library directory>, "
"or disable OpenEXR support using -DOJPH_ENABLE_OpenEXR_SUPPORT=OFF.")
# try again, but using the CONFIG option
find_package(OpenEXR 3 CONFIG QUIET)
if(OpenEXR_FOUND)
message(STATUS "Found OpenEXR ${OpenEXR_VERSION}")
set(USE_OPENEXR TRUE CACHE BOOL "Add OpenEXR support")
add_definitions(-DOJPH_ENABLE_OPENEXR_SUPPORT)
else(OpenEXR_FOUND)
message(STATUS "OpenEXR support has been enabled but no path to the OpenEXR or IlmBase library "
"has been specified; please configure with -DCMAKE_PREFIX_PATH=<OpenEXR library directory>, "
"or disable OpenEXR support using -DOJPH_ENABLE_OpenEXR_SUPPORT=OFF.")
endif(OpenEXR_FOUND)
endif(IlmBase_FOUND)

endif(OpenEXR_FOUND)
Expand Down
4 changes: 3 additions & 1 deletion src/apps/common/ojph_img_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,7 @@ namespace ojph {
}
rgba_output_file = NULL;
is_use_Rgba_interface = false;
codestream_is_planar = false;

this->data_window.makeEmpty();

Expand All @@ -932,7 +933,7 @@ namespace ojph {
}

void open(const char* filename);
void configure(ui32 width, ui32 height, ui32 num_components, bool* has_nlt, ui32* bitdepths, bool* is_signed);
void configure(ui32 width, ui32 height, ui32 num_components, bool* has_nlt, ui32* bitdepths, bool* is_signed, bool codestream_is_planar);
virtual ui32 write(const line_buf* line, ui32 comp_num);
virtual void close();

Expand All @@ -946,6 +947,7 @@ namespace ojph {
bool has_nlt[MAXIMUM_NUMBER_OF_COMPONENTS_EXR_OUT];
ui32 bit_depth[MAXIMUM_NUMBER_OF_COMPONENTS_EXR_OUT];
bool is_signed[MAXIMUM_NUMBER_OF_COMPONENTS_EXR_OUT];
bool codestream_is_planar;

Imf::RgbaOutputFile* rgba_output_file;
Imf::Array2D<Imf::Rgba> pixels;
Expand Down
2 changes: 1 addition & 1 deletion src/apps/ojph_expand/ojph_expand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ int main(int argc, char *argv[]) {
ojph::ui32 width = siz.get_recon_width(0);
ojph::ui32 height = siz.get_recon_height(0);

exr.configure(width, height, num_components, has_nlt, bitdepths, is_signed);
exr.configure(width, height, num_components, has_nlt, bitdepths, is_signed, codestream.is_planar());
exr.open(output_filename);
base = &exr;

Expand Down
55 changes: 39 additions & 16 deletions src/apps/others/ojph_img_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2357,14 +2357,21 @@ namespace ojph {
cur_line = 0;
if (true == is_use_Rgba_interface)
{
// allocate a scanline to hold a line of decoded data
pixels.resizeErase(1, width);
if (true == codestream_is_planar)
{
// if planar - allocate a framebuffer to hold the whole image
pixels.resizeErase(height, width);
}
else
{
// if interleaved - allocate a scanline to hold a line of decoded data
pixels.resizeErase(1, width);
}

Imath::Box2i display_window(Imath::V2i(0, 0), Imath::V2i(width - 1, height - 1));
data_window.min.x = 0;
data_window.min.y = 0;
data_window.max.x = width - 1;
data_window.max.y = height - 1;
Imath::Box2i data_window(Imath::V2i(0, 0), Imath::V2i(width - 1, height - 1));
this->data_window = data_window;

if (num_components == 4)
{
rgba_output_file = new Imf::RgbaOutputFile(fname, display_window, data_window, Imf::WRITE_RGBA);
Expand All @@ -2384,7 +2391,7 @@ namespace ojph {
return;
}

void exr_out::configure(ui32 width, ui32 height, ui32 num_components, bool *has_nlt, ui32 *bitdepths, bool* is_signed)
void exr_out::configure(ui32 width, ui32 height, ui32 num_components, bool *has_nlt, ui32 *bitdepths, bool* is_signed, bool codestream_is_planar)
{
this->num_components = num_components;
this->width = width;
Expand Down Expand Up @@ -2419,17 +2426,18 @@ namespace ojph {
fprintf(stderr, "not using RGBA interface\n");
}


this->codestream_is_planar = codestream_is_planar;

return;
}

ui32 exr_out::write(const line_buf* line, ui32 comp_num)
{
const int y = codestream_is_planar == false ? 0 : cur_line;
if (true == this->is_use_Rgba_interface)
{
// set framebuffer for first component
if (0 == comp_num)
// if interleaved - set framebuffer for first component of the line
if (codestream_is_planar == false && 0 == comp_num)
{
rgba_output_file->setFrameBuffer(&pixels[0][0] - data_window.min.x - data_window.min.y * width, 1, width);
}
Expand All @@ -2439,25 +2447,25 @@ namespace ojph {
case 0:
for (ui32 i = 0; i < width; i++)
{
pixels[0][i].r.setBits((si16)line->i32[i]);
pixels[y][i].r.setBits((si16)line->i32[i]);
}
break;
case 1:
for (ui32 i = 0; i < width; i++)
{
pixels[0][i].g.setBits((si16)line->i32[i]);
pixels[y][i].g.setBits((si16)line->i32[i]);
}
break;
case 2:
for (ui32 i = 0; i < width; i++)
{
pixels[0][i].b.setBits((si16)line->i32[i]);
pixels[y][i].b.setBits((si16)line->i32[i]);
}
break;
case 3:
for (ui32 i = 0; i < width; i++)
{
pixels[0][i].a.setBits((si16)line->i32[i]);
pixels[y][i].a.setBits((si16)line->i32[i]);
}
break;
default:
Expand All @@ -2468,7 +2476,7 @@ namespace ojph {
}

// write to file after last component has been populated in this line
if (comp_num == num_components - 1)
if (comp_num == num_components - 1 && codestream_is_planar == false)
{
rgba_output_file->writePixels(1);
data_window.min.y++;
Expand All @@ -2480,8 +2488,15 @@ namespace ojph {
fprintf(stderr, "not using RGBA interface is not currently supported\n");
}

if( comp_num == num_components - 1)
if (comp_num == num_components - 1 && codestream_is_planar == false)
cur_line++;
else if (codestream_is_planar == true)
{
cur_line++;
if (cur_line == height)
cur_line = 0; // moving to next component
}


return 0;
}
Expand All @@ -2492,6 +2507,14 @@ namespace ojph {
{
if (true == is_use_Rgba_interface)
{
// if planar - write the file now
// if interleaved - the scan lines are already written in the write() function
if (true == codestream_is_planar)
{
rgba_output_file->setFrameBuffer(&pixels[0][0], 1, width);
rgba_output_file->writePixels(height);
}

pixels.resizeErase(0, 0);

if (NULL != rgba_output_file)
Expand Down

0 comments on commit b226209

Please sign in to comment.