Skip to content

Commit 4946caf

Browse files
committed
detect when to RGBA interface for EXR writing
1 parent 5149f18 commit 4946caf

File tree

5 files changed

+207
-69
lines changed

5 files changed

+207
-69
lines changed

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#in noble, apt-get installs OpenEXR v3
1+
#in ubuntu:noble, apt-get installs OpenEXR v3
22
FROM ubuntu:noble
3-
#in jammy, apt-get installs OpenEXR v2
3+
#in ubuntu:jammy, apt-get installs OpenEXR v2
44
#FROM ubuntu:jammy
55

66
RUN apt-get update

src/apps/CMakeLists.txt

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ if( OJPH_ENABLE_TIFF_SUPPORT )
99
set(USE_TIFF TRUE CACHE BOOL "Add TIFF support")
1010
include_directories( ${TIFF_INCLUDE_DIR} )
1111
add_definitions(-DOJPH_ENABLE_TIFF_SUPPORT)
12-
elseif(TIFF_FOUND)
12+
elseif( TIFF_FOUND )
1313
message(STATUS "TIFF support has been enabled but no path to the TIFF library "
1414
"has been specified; please configure with -DCMAKE_PREFIX_PATH=<TIFF library directory>, "
1515
"or disable TIFF support using -DOJPH_ENABLE_TIFF_SUPPORT=OFF.")
@@ -58,17 +58,29 @@ if( OJPH_ENABLE_OPENEXR_SUPPORT )
5858
set(USE_OPENEXR TRUE CACHE BOOL "Add OpenEXR support")
5959
add_definitions(-DOJPH_ENABLE_OPENEXR_SUPPORT)
6060
else(OpenEXR_FOUND)
61+
message(STATUS "OpenEXR v3 not found, looking for OpenEXR v2")
6162
find_package(IlmBase)
6263
if(IlmBase_FOUND)
6364
message(STATUS "Found IlmBase ${IlmBase_VERSION}")
64-
6565
find_package(OpenEXR 2)
6666
if(OpenEXR_FOUND)
6767
message(STATUS "Found OpenEXR ${OpenEXR_VERSION}")
6868
set(USE_OPENEXR TRUE CACHE BOOL "Add OpenEXR support")
6969
add_definitions(-DOJPH_ENABLE_OPENEXR_SUPPORT)
70+
# if (MSVC)
71+
# # Suffix for debug configuration libraries
72+
# # (if you should choose to install those)
73+
# set(CMAKE_DEBUG_POSTFIX "_d" CACHE STRING "Suffix for debug builds")
74+
# endif (MSVC)
75+
else(OpenEXR_FOUND)
76+
message(STATUS "OpenEXR support has been enabled but no path to the OpenEXR library "
77+
"has been specified; please configure with -DCMAKE_PREFIX_PATH=<OpenEXR library directory>, "
78+
"or disable OpenEXR support using -DOJPH_ENABLE_OpenEXR_SUPPORT=OFF.")
7079
endif(OpenEXR_FOUND)
71-
80+
else(IlmBase_FOUND)
81+
message(STATUS "OpenEXR support has been enabled but no path to the OpenEXR or IlmBase library "
82+
"has been specified; please configure with -DCMAKE_PREFIX_PATH=<OpenEXR library directory>, "
83+
"or disable OpenEXR support using -DOJPH_ENABLE_OpenEXR_SUPPORT=OFF.")
7284
endif(IlmBase_FOUND)
7385

7486
endif(OpenEXR_FOUND)

src/apps/common/ojph_img_io.h

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -901,28 +901,42 @@ namespace ojph {
901901
width = 0;
902902
height = 0;
903903
num_components = 0;
904-
for( int i = 0; i < MAXIMUM_NUMBER_OF_COMPONENTS_EXR_OUT; i++)
904+
for (int i = 0; i < MAXIMUM_NUMBER_OF_COMPONENTS_EXR_OUT; i++)
905+
{
906+
has_nlt[i] = false;
905907
bit_depth[i] = 0;
908+
is_signed[i] = false;
909+
}
910+
is_use_Rgba_interface = false;
911+
906912
is_open = false;
907913
}
908914
virtual ~exr_out()
909915
{
910916
close();
911-
pixels.resizeErase(0, 0);
917+
if(true == is_use_Rgba_interface )
918+
pixels.resizeErase(0, 0);
912919
}
913920

914921
void open(const char* filename);
915-
void configure(ui32 width, ui32 height, ui32 num_components, ui32 bit_depth);
922+
void configure(ui32 width, ui32 height, ui32 num_components, bool* has_nlt, ui8* bitdepths, bool* is_signed);
916923
virtual ui32 write(const line_buf* line, ui32 comp_num);
917924
virtual void close();
918925

919926
private:
920927

921928
const char* fname;
922929
bool is_open;
930+
923931
ui32 width, height, num_components;
932+
933+
bool has_nlt[MAXIMUM_NUMBER_OF_COMPONENTS_EXR_OUT];
924934
ui32 bit_depth[MAXIMUM_NUMBER_OF_COMPONENTS_EXR_OUT];
935+
bool is_signed[MAXIMUM_NUMBER_OF_COMPONENTS_EXR_OUT];
936+
925937
Imf::Array2D<Imf::Rgba> pixels;
938+
bool is_use_Rgba_interface;
939+
926940
ui32 cur_line;
927941
};
928942
#endif /* OJPH_ENABLE_OPENEXR_SUPPORT */

src/apps/ojph_expand/ojph_expand.cpp

Lines changed: 75 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -399,30 +399,99 @@ int main(int argc, char *argv[]) {
399399
else if (is_matching(".exr", v))
400400
{
401401
ojph::param_siz siz = codestream.access_siz();
402+
ojph::param_nlt nlt = codestream.access_nlt();
403+
ojph::ui32 num_components = siz.get_num_components();
404+
405+
ojph::ui8 *bitdepths = (ojph::ui8*)calloc(num_components, sizeof(ojph::ui8));
406+
if (NULL == bitdepths) {
407+
fprintf(stderr, "Unable to allocate %zd bytes for bitdepths", num_components * sizeof(ojph::ui8));
408+
exit(-1);
409+
}
410+
411+
bool *is_signed = (bool*)calloc(num_components, sizeof(bool));
412+
if (NULL == is_signed) {
413+
fprintf(stderr, "Unable to allocate %zd bytes for is_signed", num_components * sizeof(bool));
414+
exit(-1);
415+
}
416+
bool *has_nlt = (bool*)calloc(num_components, sizeof(bool));
417+
if (NULL == has_nlt) {
418+
fprintf(stderr, "Unable to allocate %zd bytes for has_nlt", num_components * sizeof(bool));
419+
exit(-1);
420+
}
402421

403-
if (siz.get_num_components() != 3 && siz.get_num_components() != 4)
422+
// check properties for all components
423+
for (ojph::ui32 c = 0; c < num_components; c++)
424+
{
425+
bool nlt_is_signed;
426+
ojph::ui8 nlt_bit_depth;
427+
has_nlt[c] = nlt.get_type3_transformation(c, nlt_bit_depth, nlt_is_signed);
428+
429+
fprintf(stderr, "comp = %d has_nlt = %s ",
430+
c, has_nlt[c] ? "true" : "false");
431+
if (true == has_nlt[c])
432+
{
433+
fprintf(stderr, "nlt_bit_depth = %d nlt_is_signed = % s\n",
434+
nlt_bit_depth,
435+
nlt_is_signed ? "true" : "false");
436+
}
437+
else
438+
{
439+
fprintf(stderr, "\n");
440+
}
441+
442+
if (true == has_nlt[c] && (nlt_bit_depth != siz.get_bit_depth(c) || nlt_is_signed != siz.is_signed(c)))
443+
{
444+
OJPH_ERROR(0x0200000F,
445+
"There is discrepancy in component %d configuration between "
446+
"SIZ marker segment, which specifies bit_depth = %d and "
447+
"signedness = %s, and NLT marker segment, which specifies "
448+
"bit_depth = %d and signedness = %s.\n", c,
449+
siz.get_bit_depth(c), siz.is_signed(c) ? "True" : "False",
450+
nlt_bit_depth, nlt_is_signed ? "True" : "False");
451+
}
452+
453+
bitdepths[c] = siz.get_bit_depth(c);
454+
is_signed[c] = siz.is_signed(c);
455+
}
456+
457+
if (num_components != 3 && num_components != 4)
404458
OJPH_ERROR(0x0200000C,
405459
"The file has %d color components; this cannot be saved to"
406460
" .exr file (currently only 3 and 4 components are supported).\n",
407-
siz.get_num_components());
461+
num_components);
408462
ojph::ui32 width = siz.get_recon_width(0);
409463
ojph::ui32 height = siz.get_recon_height(0);
410-
ojph::ui32 bit_depth = siz.get_bit_depth(0);
411-
ojph::ui32 num_components = siz.get_num_components();
412-
exr.configure(width, height, num_components, bit_depth);
464+
465+
exr.configure(width, height, num_components, has_nlt, bitdepths, is_signed);
413466
exr.open(output_filename);
414467
base = &exr;
468+
469+
free(bitdepths);
470+
free(is_signed);
471+
free(has_nlt);
415472
}
416473
#endif /* OJPH_ENABLE_EXR_SUPPORT */
417474
else
418475
#ifdef OJPH_ENABLE_TIFF_SUPPORT
476+
#ifdef OJPH_ENABLE_OPENEXR_SUPPORT
419477
OJPH_ERROR(0x02000009,
420-
"unknown output file extension; only pgm, ppm, tif(f) and raw(yuv))"
478+
"unknown output file extension; only pgm, ppm, tif(f), exr and raw(yuv))"
421479
" are supported\n");
480+
#else
481+
OJPH_ERROR(0x02000009,
482+
"unknown output file extension; only pgm, ppm, tif(f) and raw(yuv))"
483+
" are supported\n");
484+
#endif
422485
#else
486+
#ifdef OJPH_ENABLE_OPENEXR_SUPPORT
487+
OJPH_ERROR(0x02000009,
488+
"unknown output file extension; only pgm, ppm, exr and raw(yuv))"
489+
" are supported\n");
490+
#else
423491
OJPH_ERROR(0x0200000A,
424492
"unknown output file extension; only pgm, ppm, and raw(yuv) are"
425493
" supported\n");
494+
#endif
426495
#endif // !OJPH_ENABLE_TIFF_SUPPORT
427496
}
428497
else

0 commit comments

Comments
 (0)