121 OJPH_ERROR(0x00030011,
"the number of tiles cannot exceed 65535");
123 OJPH_ERROR(0x00030012,
"the number of tiles cannot be 0");
128 ui32 num_tileparts = 0;
130 rect tile_rect, recon_tile_rect;
146 - recon_tile_rect.
org.
y;
162 - recon_tile_rect.
org.
x;
166 num_tileparts += tps;
198 for (
ui32 r = 0; r <= num_decomps; ++r)
206 max_ratio = 1 << max_ratio;
215 4 * ((max_ratio * max_ratio * 4 + 2) / 3);
232 ui32 num_tileparts = 0;
259 tiles[idx].finalize_alloc(
this, tile_rect, idx, offset, tps);
260 num_tileparts += tps;
300 bool imf2k = !reversible, imf4k = !reversible, imf8k = !reversible;
301 bool imf2kls = reversible, imf4kls = reversible, imf8kls = reversible;
306 if (ext.
x <= 2048 && ext.
y <= 1556)
308 if (ext.
x <= 4096 && ext.
y <= 3112)
310 if (ext.
x <= 8192 && ext.
y <= 6224)
313 if (!imf2kls && !imf4kls && !imf8kls)
315 "Image dimensions do not meet any of the lossless IMF profiles");
320 if (ext.
x <= 2048 && ext.
y <= 1556)
322 if (ext.
x <= 4096 && ext.
y <= 3112)
324 if (ext.
x <= 8192 && ext.
y <= 6224)
327 if (!imf2k && !imf4k && !imf8k)
329 "Image dimensions do not meet any of the lossy IMF profiles");
335 "For IMF profile, image offset (XOsiz, YOsiz) has to be 0.");
338 "For IMF profile, tile offset (XTOsiz, YTOsiz) has to be 0.");
341 "For IMF profile, the number of components has to be less "
343 bool test_ds1 =
true, test_ds2 =
true;
347 test_ds1 &= downsamping.
y == 1;
348 test_ds2 &= downsamping.
y == 1;
350 test_ds1 &= downsamping.
x == 1;
351 if (i == 1 || i == 2)
352 test_ds2 &= downsamping.
x == 2;
354 test_ds2 &= downsamping.
x == 1;
356 if (!test_ds1 && !test_ds2)
358 "For IMF profile, either no component downsampling is used,"
359 " or the x-dimension of the 2nd and 3rd components is downsampled"
367 test_bd &= bit_depth >= 8 && bit_depth <= 16 && is_signed ==
false;
371 "For IMF profile, compnent bit_depth has to be between"
372 " 8 and 16 bits inclusively, and the samples must be unsigned");
376 "For IMF profile, codeblock dimensions are restricted."
377 " Use \"-block_size {32,32}\" at the commandline");
382 for (
ui32 i = 1; i <= num_decomps; ++i)
387 "For IMF profile, precinct sizes are restricted."
388 " Use \"-precincts {128,128},{256,256}\" at the commandline");
392 "For IMF profile, the CPRL progression order must be used."
393 " Use \"-prog_order CPRL\".");
395 imf2k &= num_decomps <= 5;
396 imf2kls &= num_decomps <= 5;
397 imf4k &= num_decomps <= 6;
398 imf4kls &= num_decomps <= 6;
399 imf8k &= num_decomps <= 7;
400 imf8kls &= num_decomps <= 7;
402 if (num_decomps == 0 ||
403 (!imf2k && !imf4k && !imf8k && !imf2kls && !imf4kls && !imf8kls))
405 "Number of decompositions does not match the IMF profile"
406 " dictated by wavelet reversibility and image dimensions.");
412 ui32 total_tiles = tiles_w * tiles_h;
418 "Lossy IMF profile must have one tile.");
421 imf2kls &= (tt.
w == 1024 && tt.
h == 1024);
422 imf2kls &= (tt.
w >= 1024 && num_decomps <= 4)
423 || (tt.
w >= 2048 && num_decomps <= 5);
424 imf4kls &= (tt.
w == 1024 && tt.
h == 1024)
425 || (tt.
w == 2048 && tt.
h == 2048);
426 imf4kls &= (tt.
w >= 1024 && num_decomps <= 4)
427 || (tt.
w >= 2048 && num_decomps <= 5)
428 || (tt.
w >= 4096 && num_decomps <= 6);
429 imf8kls &= (tt.
w == 1024 && tt.
h == 1024)
430 || (tt.
w == 2048 && tt.
h == 2048)
431 || (tt.
w == 4096 && tt.
h == 4096);
432 imf8kls &= (tt.
w >= 1024 && num_decomps <= 4)
433 || (tt.
w >= 2048 && num_decomps <= 5)
434 || (tt.
w >= 4096 && num_decomps <= 6)
435 || (tt.
w >= 8192 && num_decomps <= 7);
436 if (!imf2kls && !imf4kls && !imf8kls)
438 "Number of decompositions does not match the IMF profile"
439 " dictated by wavelet reversibility and image dimensions and"
449 "In IMF profile, tile part divisions at the component level must be "
450 "employed, while at the resolution level is not allowed. "
451 "This has been corrected.");
463 "For broadcast profile, image offset (XOsiz, YOsiz) has to be 0.");
466 "For broadcast profile, tile offset (XTOsiz, YTOsiz) has to be 0.");
469 "For broadcast profile, the number of components has to be less "
471 bool test_ds1 =
true, test_ds2 =
true;
475 test_ds1 &= downsamping.
y == 1;
476 test_ds2 &= downsamping.
y == 1;
478 test_ds1 &= downsamping.
x == 1;
479 if (i == 1 || i == 2)
480 test_ds2 &= downsamping.
x == 2;
482 test_ds2 &= downsamping.
x == 1;
484 if (!test_ds1 && !test_ds2)
486 "For broadcast profile, either no component downsampling is used,"
487 " or the x-dimension of the 2nd and 3rd components is downsampled"
495 test_bd &= bit_depth >= 8 && bit_depth <= 12 && is_signed ==
false;
499 "For broadcast profile, compnent bit_depth has to be between"
500 " 8 and 12 bits inclusively, and the samples must be unsigned");
503 if (num_decomps == 0 || num_decomps > 5)
505 "For broadcast profile, number of decompositions has to be between"
506 "1 and 5 inclusively.");
510 "For broadcast profile, codeblock dimensions are restricted such"
511 " that codeblock width has to be either 32, 64, or 128.");
515 "For broadcast profile, codeblock dimensions are restricted such"
516 " that codeblock height has to be either 32, 64, or 128.");
520 for (
ui32 i = 1; i <= num_decomps; ++i)
525 "For broadcast profile, precinct sizes are restricted."
526 " Use \"-precincts {128,128},{256,256}\" at the commandline");
530 "For broadcast profile, the CPRL progression order must be used."
531 " Use \"-prog_order CPRL\".");
537 ui32 total_tiles = tiles_w * tiles_h;
539 if (total_tiles != 1 && total_tiles != 4)
541 "The broadcast profile can only have 1 or 4 tiles");
549 "In BROADCAST profile, tile part divisions at the component level "
550 "must be employed, while at the resolution level is not allowed. "
551 "This has been corrected.");
564 if (tile_size.
h == 0 && tile_size.
w == 0)
568 size t(img_extent.
x + img_offset.
x, img_extent.
y + img_offset.
y);
588 "For LRCP and RLCP progression orders, tilepart divisions at the "
589 "component level, means that we have a tilepart for every "
590 "resolution and component.\n");
596 "For RPCL progression, having tilepart divisions at the component "
597 "level means a tilepart for every precinct, which does not "
598 "make sense, since we can have no more than 255 tile parts. This "
599 "has been corrected by removing tilepart divisions at the component "
606 "For PCRL progression, having tilepart divisions at the component "
607 "level or the resolution level means a tile part for every "
608 "precinct, which does not make sense, since we can have no more "
609 "than 255 tile parts. This has been corrected by removing tilepart "
610 "divisions; use another progression if you want tileparts.");
616 "For CPRL progression, having tilepart divisions at the resolution "
617 "level means a tile part for every precinct, which does not "
618 "make sense, since we can have no more than 255 tile parts. This "
619 "has been corrected by removing tilepart divisions at the "
620 "resolution level.");
632 "the planar interface option cannot be used when colour "
633 "transform is employed");
644 if (file->
write(&t, 2) != 2)
645 OJPH_ERROR(0x00030022,
"Error writing to file");
648 OJPH_ERROR(0x00030023,
"Error writing to file");
651 OJPH_ERROR(0x00030024,
"Error writing to file");
654 OJPH_ERROR(0x00030025,
"Error writing to file");
657 OJPH_ERROR(0x0003002E,
"Error writing to file");
660 OJPH_ERROR(0x00030026,
"Error writing to file");
663 OJPH_ERROR(0x0003002D,
"Error writing to file");
666 OJPH_ERROR(0x00030027,
"Error writing to file");
668 const char* version_str =
"OpenJPH Ver "
672 size_t data_len = strlen(version_str);
676 OJPH_ERROR(0x00030028,
"Error writing to file");
677 t = swap_bytes_if_le((
ui16)(data_len + 4));
679 OJPH_ERROR(0x0003002D,
"Error writing to file");
681 t = swap_bytes_if_le((
ui16)(1));
683 OJPH_ERROR(0x0003002E,
"Error writing to file");
684 if (file->
write(version_str, data_len) != data_len)
685 OJPH_ERROR(0x0003002F,
"Error writing to file");
687 if (comments != NULL) {
688 for (
ui32 i = 0; i < num_comments; ++i)
691 if (file->
write(&t, 2) != 2)
692 OJPH_ERROR(0x00030029,
"Error writing to file");
693 t = swap_bytes_if_le((
ui16)(comments[i].len + 4));
694 if (file->
write(&t, 2) != 2)
695 OJPH_ERROR(0x0003002A,
"Error writing to file");
697 t = swap_bytes_if_le(comments[i].Rcom);
698 if (file->
write(&t, 2) != 2)
699 OJPH_ERROR(0x0003002B,
"Error writing to file");
701 OJPH_ERROR(0x0003002C,
"Error writing to file");
714 size_t num_bytes = f->
read(&new_char, 1);
717 if (new_char == 0xFF)
719 size_t num_bytes = f->
read(&new_char, 1);
724 for (
int i = 0; i < list_len; ++i)
725 if (new_char == (char_list[i] & 0xFF))
735 const char *msg,
int msg_level,
bool resilient)
739 if (file->
read(&com_len, 2) != 2)
744 OJPH_ERROR(0x00030041,
"error reading marker");
746 com_len = swap_bytes_if_le(com_len);
772 RGN,
POC,
PPM,
TLM,
PLM,
CRG,
COM,
DFS,
ATK,
NLT,
SOT };
777 int received_markers = 0;
780 marker_idx =
find_marker(file, marker_list + 2, 18);
783 else if (marker_idx == 1)
786 else if (marker_idx == 2)
789 else if (marker_idx == 3)
792 received_markers |= 1;
795 if (num_qlayers != 1)
796 OJPH_ERROR(0x00030053,
"The current implementation supports "
797 "1 quality layer only. This codestream has %d quality layers",
800 else if (marker_idx == 4)
805 OJPH_INFO(0x00030056,
"The codestream carries a COC marker "
806 "segment for a component indexed by %d, which is more than the "
807 "allowed index number, since the codestream has %d components",
811 OJPH_ERROR(0x00030057,
"The codestream has two COC marker "
812 "segments for one component of index %d", p->
get_comp_idx());
814 else if (marker_idx == 5)
817 received_markers |= 2;
819 else if (marker_idx == 6)
824 OJPH_ERROR(0x00030054,
"The codestream carries a QCC marker "
825 "segment for a component indexed by %d, which is more than the "
826 "allowed index number, since the codestream has %d components",
830 OJPH_ERROR(0x00030055,
"The codestream has two QCC marker "
831 "segments for one component of index %d", p->
get_comp_idx());
833 else if (marker_idx == 7)
834 skip_marker(file,
"RGN",
"RGN is not supported yet",
836 else if (marker_idx == 8)
837 skip_marker(file,
"POC",
"POC is not supported yet",
839 else if (marker_idx == 9)
840 skip_marker(file,
"PPM",
"PPM is not supported yet",
842 else if (marker_idx == 10)
845 else if (marker_idx == 11)
848 else if (marker_idx == 12)
850 skip_marker(file,
"CRG",
"CRG has been ignored; CRG is related to"
851 " where the Cb and Cr colour components are co-sited or located"
852 " with respect to the Y' luma component. Perhaps, it is better"
853 " to get the individual components and assemble the samples"
854 " according to your needs",
856 else if (marker_idx == 13)
858 else if (marker_idx == 14)
860 else if (marker_idx == 15)
862 else if (marker_idx == 16)
864 else if (marker_idx == 17)
867 OJPH_ERROR(0x00030051,
"File ended before finding a tile segment");
875 if (received_markers != 3)
876 OJPH_ERROR(0x00030052,
"markers error, COD and QCD are required");
882 if (unsupported_nlt >= 0)
883 OJPH_ERROR(0x00030059,
"The codestream uses a LUT style nonlinearity "
884 "(type 2 or type 4) together with the reversible (5/3) wavelet for "
885 "component %d. This does not make sense since LUT itself is not "
886 "reversible. This library does not implement the processing path "
887 "needed for this conbination.", unsupported_nlt);
899 "skipped_resolution for data %d must be equal or smaller than "
900 " skipped_resolution for reconstruction %d\n",
904 "skipped_resolution for data %d must be smaller than "
905 " the number of decomposition levels %d\n",
917 OJPH_ERROR(0x000300A3,
"Codestream resilience must be enabled before"
918 " reading file headers.\n");
934 bool skip_tile =
false;
939 OJPH_INFO(0x00030061,
"wrong tile index")
955 "error in tile part number, should be smaller than total"
956 " number of tile parts")
959 "error in tile part number, should be smaller than total"
960 " number of tile parts")
963 bool sod_found =
false;
973 "POC marker segment in a tile is not supported yet",
975 else if (marker_idx == 1)
977 "PPT marker segment in a tile is not supported yet",
979 else if (marker_idx == 2)
983 else if (marker_idx == 3)
986 else if (marker_idx == 4)
988 "NLT marker in tile is not supported yet",
990 else if (marker_idx == 5)
996 if (marker_idx == -1)
1000 "File terminated early before start of data is found"
1001 " for tile indexed %d and tile part %d",
1005 "File terminated early before start of data is found"
1006 " for tile indexed %d and tile part %d",
1014 "File terminated during marker segment skipping")
1017 "File terminated during marker segment skipping")
1023 tile_start_location);
1027 bool sod_found =
false;
1035 if (marker_idx == 0)
1037 "COD marker segment in a tile is not supported yet",
1039 else if (marker_idx == 1)
1041 "COC marker segment in a tile is not supported yet",
1043 else if (marker_idx == 2)
1045 "QCD marker segment in a tile is not supported yet",
1047 else if (marker_idx == 3)
1049 "QCC marker segment in a tile is not supported yet",
1051 else if (marker_idx == 4)
1053 "RGN marker segment in a tile is not supported yet",
1055 else if (marker_idx == 5)
1057 "POC marker segment in a tile is not supported yet",
1059 else if (marker_idx == 6)
1061 "PPT marker segment in a tile is not supported yet",
1063 else if (marker_idx == 7)
1067 else if (marker_idx == 8)
1070 else if (marker_idx == 9)
1072 "PPT marker segment in a tile is not supported yet",
1074 else if (marker_idx == 10)
1080 if (marker_idx == -1)
1084 "File terminated early before start of data is found"
1085 " for tile indexed %d and tile part %d",
1089 "File terminated early before start of data is found"
1090 " for tile indexed %d and tile part %d",
1098 "File terminated during marker segment skipping")
1101 "File terminated during marker segment skipping")
1107 tile_start_location);
1116 if (marker_idx == -1)
1118 OJPH_INFO(0x00030067,
"File terminated early");
1121 else if (marker_idx == 0)
1123 else if (marker_idx == 1)
1137 size_t len = strlen(s);
1143 OJPH_ERROR(0x000300A1,
"unkownn or unsupported profile");
1162 for (
si32 i = 0; i < repeat; ++i)
1163 tiles[i].prepare_for_flush();
1166 for (
si32 i = 0; i < repeat; ++i)
1170 for (
si32 i = 0; i < repeat; ++i)
1174 OJPH_ERROR(0x00030071,
"Error writing to file");
1191 bool success =
false;
1240 bool success =
false;
1282 return lines + comp_num;
virtual size_t read(void *ptr, size_t size)=0
void wrap(T *buffer, size_t num_ele, ui32 pre_size)
ui32 skipped_res_for_recon
ojph::param_siz access_siz()
void request_tlm_marker(bool needed)
line_buf * exchange(line_buf *line, ui32 &next_component)
void set_planar(int planar)
void check_imf_validity()
void restrict_input_resolution(ui32 skipped_res_for_data, ui32 skipped_res_for_recon)
mem_elastic_allocator * elastic_alloc
mem_fixed_allocator * allocator
void write_headers(outfile_base *file, const comment_exchange *comments, ui32 num_comments)
ui32 precinct_scratch_needed_bytes
void check_broadcast_validity()
void read_headers(infile_base *file)
void set_profile(const char *s)
bool employ_color_transform
void set_tilepart_divisions(ui32 value)
line_buf * pull(ui32 &comp_num)
ui32 skipped_res_for_read
static void pre_alloc(codestream *codestream, const rect &tile_rect, const rect &recon_tile_rect, ui32 &num_tileparts)
void parse_tile_header(const param_sot &sot, infile_base *file, const ui64 &tile_start_location)
mem_elastic_allocator(ui32 chunk_size)
void pre_alloc_data(size_t num_ele, ui32 pre_size)
void pre_alloc_obj(size_t num_ele)
T * post_alloc_data(size_t num_ele, ui32 pre_size)
T * post_alloc_obj(size_t num_ele)
virtual size_t write(const void *ptr, size_t size)=0
int get_progression_order() const
ui32 get_num_decompositions() const
size get_log_block_dims() const
bool is_reversible() const
size get_log_precinct_size(ui32 level_num) const
int get_num_layers() const
point get_image_extent() const
ui32 get_bit_depth(ui32 comp_num) const
point get_image_offset() const
size get_tile_size() const
point get_downsampling(ui32 comp_num) const
point get_tile_offset() const
bool is_signed(ui32 comp_num) const
ui32 get_num_components() const
static int find_marker(infile_base *f, const ui16 *char_list, int list_len)
static int skip_marker(infile_base *file, const char *marker, const char *msg, int msg_level, bool resilient)
void init_wavelet_transform_functions()
void init_colour_transform_functions()
const char OJPH_PN_STRING_BROADCAST[]
const char OJPH_PN_STRING_IMF[]
@ OJPH_TILEPART_RESOLUTIONS
@ OJPH_TILEPART_NO_DIVISIONS
@ OJPH_TILEPART_COMPONENTS
#define OJPH_INT_TO_STRING(I)
#define ojph_div_ceil(a, b)
#define OJPH_INFO(t,...)
MACROs to insert file and line number for info, warning, and error.
#define OJPH_ERROR(t,...)
#define OPENJPH_VERSION_PATCH
#define OPENJPH_VERSION_MAJOR
#define OPENJPH_VERSION_MINOR
bool read(infile_base *file)
void check_validity(const param_cod &cod, const param_qcd &qcd)
void read(infile_base *file)
bool write(outfile_base *file)
void check_validity(const param_siz &siz)
bool write(outfile_base *file)
const param_cod * get_coc(ui32 comp_idx) const
size get_log_block_dims() const
bool write_coc(outfile_base *file, ui32 num_comps)
bool is_employing_color_transform() const
ui32 get_comp_idx() const
void read(infile_base *file)
size get_log_precinct_size(ui32 res_num) const
void read_coc(infile_base *file, ui32 num_comps, param_cod *top_cod)
void update_atk(param_atk *atk)
ui8 get_num_decompositions() const
param_cod * add_coc_object(ui32 comp_idx)
bool read(infile_base *file)
bool write(outfile_base *file) const
void check_validity(param_siz &siz, const param_cod &cod)
bool read(infile_base *file)
int find_unsupported_nlt(const param_siz &siz, const param_cod &cod) const
bool write_qcc(outfile_base *file, ui32 num_comps)
ui16 get_comp_idx() const
void read_qcc(infile_base *file, ui32 num_comps)
void check_validity(const param_siz &siz, const param_cod &cod)
bool write(outfile_base *file)
void read(infile_base *file)
param_qcd * add_qcc_object(ui32 comp_idx)
param_qcd * get_qcc(ui32 comp_idx)
void set_skipped_resolutions(ui32 skipped_resolutions)
ui32 get_recon_height(ui32 comp_num) const
bool write(outfile_base *file)
ui16 get_num_components() const
void set_tile_size(size s)
void set_cod(const param_cod &cod)
ui32 get_height(ui32 comp_num) const
point get_image_offset() const
void link(const param_cod *cod)
size get_tile_size() const
void read(infile_base *file)
ui32 get_width(ui32 comp_num) const
point get_image_extent() const
ui32 get_recon_width(ui32 comp_num) const
ui8 get_num_tile_parts() const
ui16 get_tile_index() const
bool read(infile_base *file, bool resilient)
ui8 get_tile_part_index() const
bool write(outfile_base *file)
void init(ui32 num_pairs, Ttlm_Ptlm_pair *store)