@@ -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