57 : precinct_scratch(NULL), allocator(NULL), elastic_alloc(NULL)
113 OJPH_ERROR(0x00030011,
"number of tiles cannot exceed 65535");
118 ui32 num_tileparts = 0;
120 rect tile_rect, recon_tile_rect;
136 - recon_tile_rect.
org.
y;
152 - recon_tile_rect.
org.
x;
156 num_tileparts += tps;
179 for (
ui32 r = 0; r <= num_decomps; ++r)
186 max_ratio = 1 << max_ratio;
195 4 * ((max_ratio * max_ratio * 4 + 2) / 3);
212 ui32 num_tileparts = 0;
240 num_tileparts += tps;
280 bool imf2k = !reversible, imf4k = !reversible, imf8k = !reversible;
281 bool imf2kls = reversible, imf4kls = reversible, imf8kls = reversible;
286 if (ext.
x <= 2048 && ext.
y <= 1556)
288 if (ext.
x <= 4096 && ext.
y <= 3112)
290 if (ext.
x <= 8192 && ext.
y <= 6224)
293 if (!imf2kls && !imf4kls && !imf8kls)
295 "Image dimensions do not meet any of the lossless IMF profiles");
300 if (ext.
x <= 2048 && ext.
y <= 1556)
302 if (ext.
x <= 4096 && ext.
y <= 3112)
304 if (ext.
x <= 8192 && ext.
y <= 6224)
307 if (!imf2k && !imf4k && !imf8k)
309 "Image dimensions do not meet any of the lossy IMF profiles");
315 "For IMF profile, image offset (XOsiz, YOsiz) has to be 0.");
318 "For IMF profile, tile offset (XTOsiz, YTOsiz) has to be 0.");
321 "For IMF profile, the number of components has to be less "
323 bool test_ds1 =
true, test_ds2 =
true;
327 test_ds1 &= downsamping.
y == 1;
328 test_ds2 &= downsamping.
y == 1;
330 test_ds1 &= downsamping.
x == 1;
331 if (i == 1 || i == 2)
332 test_ds2 &= downsamping.
x == 2;
334 test_ds2 &= downsamping.
x == 1;
336 if (!test_ds1 && !test_ds2)
338 "For IMF profile, either no component downsampling is used,"
339 " or the x-dimension of the 2nd and 3rd components is downsampled"
347 test_bd &= bit_depth >= 8 && bit_depth <= 16 && is_signed ==
false;
351 "For IMF profile, compnent bit_depth has to be between"
352 " 8 and 16 bits inclusively, and the samples must be unsigned");
356 "For IMF profile, codeblock dimensions are restricted."
357 " Use \"-block_size {32,32}\" at the commandline");
362 for (
ui32 i = 1; i <= num_decomps; ++i)
367 "For IMF profile, precinct sizes are restricted."
368 " Use \"-precincts {128,128},{256,256}\" at the commandline");
372 "For IMF profile, the CPRL progression order must be used."
373 " Use \"-prog_order CPRL\".");
375 imf2k &= num_decomps <= 5;
376 imf2kls &= num_decomps <= 5;
377 imf4k &= num_decomps <= 6;
378 imf4kls &= num_decomps <= 6;
379 imf8k &= num_decomps <= 7;
380 imf8kls &= num_decomps <= 7;
382 if (num_decomps == 0 ||
383 (!imf2k && !imf4k && !imf8k && !imf2kls && !imf4kls && !imf8kls))
385 "Number of decompositions does not match the IMF profile"
386 " dictated by wavelet reversibility and image dimensions.");
392 ui32 total_tiles = tiles_w * tiles_h;
398 "Lossy IMF profile must have one tile.");
401 imf2kls &= (tt.
w == 1024 && tt.
h == 1024);
402 imf2kls &= (tt.
w >= 1024 && num_decomps <= 4)
403 || (tt.
w >= 2048 && num_decomps <= 5);
404 imf4kls &= (tt.
w == 1024 && tt.
h == 1024)
405 || (tt.
w == 2048 && tt.
h == 2048);
406 imf4kls &= (tt.
w >= 1024 && num_decomps <= 4)
407 || (tt.
w >= 2048 && num_decomps <= 5)
408 || (tt.
w >= 4096 && num_decomps <= 6);
409 imf8kls &= (tt.
w == 1024 && tt.
h == 1024)
410 || (tt.
w == 2048 && tt.
h == 2048)
411 || (tt.
w == 4096 && tt.
h == 4096);
412 imf8kls &= (tt.
w >= 1024 && num_decomps <= 4)
413 || (tt.
w >= 2048 && num_decomps <= 5)
414 || (tt.
w >= 4096 && num_decomps <= 6)
415 || (tt.
w >= 8192 && num_decomps <= 7);
416 if (!imf2kls && !imf4kls && !imf8kls)
418 "Number of decompositions does not match the IMF profile"
419 " dictated by wavelet reversibility and image dimensions and"
429 "In IMF profile, tile part divisions at the component level must be "
430 "employed, while at the resolution level is not allowed. "
431 "This has been corrected.");
443 "For broadcast profile, image offset (XOsiz, YOsiz) has to be 0.");
446 "For broadcast profile, tile offset (XTOsiz, YTOsiz) has to be 0.");
449 "For broadcast profile, the number of components has to be less "
451 bool test_ds1 =
true, test_ds2 =
true;
455 test_ds1 &= downsamping.
y == 1;
456 test_ds2 &= downsamping.
y == 1;
458 test_ds1 &= downsamping.
x == 1;
459 if (i == 1 || i == 2)
460 test_ds2 &= downsamping.
x == 2;
462 test_ds2 &= downsamping.
x == 1;
464 if (!test_ds1 && !test_ds2)
466 "For broadcast profile, either no component downsampling is used,"
467 " or the x-dimension of the 2nd and 3rd components is downsampled"
475 test_bd &= bit_depth >= 8 && bit_depth <= 12 && is_signed ==
false;
479 "For broadcast profile, compnent bit_depth has to be between"
480 " 8 and 12 bits inclusively, and the samples must be unsigned");
483 if (num_decomps == 0 || num_decomps > 5)
485 "For broadcast profile, number of decompositions has to be between"
486 "1 and 5 inclusively.");
490 "For broadcast profile, codeblock dimensions are restricted such"
491 " that codeblock width has to be either 32, 64, or 128.");
495 "For broadcast profile, codeblock dimensions are restricted such"
496 " that codeblock height has to be either 32, 64, or 128.");
500 for (
ui32 i = 1; i <= num_decomps; ++i)
505 "For broadcast profile, precinct sizes are restricted."
506 " Use \"-precincts {128,128},{256,256}\" at the commandline");
510 "For broadcast profile, the CPRL progression order must be used."
511 " Use \"-prog_order CPRL\".");
517 ui32 total_tiles = tiles_w * tiles_h;
519 if (total_tiles != 1 && total_tiles != 4)
521 "The broadcast profile can only have 1 or 4 tiles");
529 "In BROADCAST profile, tile part divisions at the component level "
530 "must be employed, while at the resolution level is not allowed. "
531 "This has been corrected.");
558 "For LRCP and RLCP progression orders, tilepart divisions at the "
559 "component level, means that we have a tilepart for every "
560 "resolution and component.\n");
566 "For RPCL progression, having tilepart divisions at the component "
567 "level means a tilepart for every precinct, which does not "
568 "make sense, since we can have no more than 255 tile parts. This "
569 "has been corrected by removing tilepart divisions at the component "
576 "For PCRL progression, having tilepart divisions at the component "
577 "level or the resolution level means a tile part for every "
578 "precinct, which does not make sense, since we can have no more "
579 "than 255 tile parts. This has been corrected by removing tilepart "
580 "divisions; use another progression if you want tileparts.");
586 "For CPRL progression, having tilepart divisions at the resolution "
587 "level means a tile part for every precinct, which does not "
588 "make sense, since we can have no more than 255 tile parts. This "
589 "has been corrected by removing tilepart divisions at the "
590 "resolution level.");
602 "the planar interface option cannot be used when colour "
603 "transform is employed");
614 if (file->
write(&t, 2) != 2)
615 OJPH_ERROR(0x00030022,
"Error writing to file");
618 OJPH_ERROR(0x00030023,
"Error writing to file");
621 OJPH_ERROR(0x00030024,
"Error writing to file");
624 OJPH_ERROR(0x00030025,
"Error writing to file");
627 OJPH_ERROR(0x0003002E,
"Error writing to file");
630 OJPH_ERROR(0x00030026,
"Error writing to file");
633 OJPH_ERROR(0x0003002D,
"Error writing to file");
636 OJPH_ERROR(0x00030027,
"Error writing to file");
638 char buf[] =
" OpenJPH Ver "
642 size_t len = strlen(buf);
647 if (file->
write(buf, len) != len)
648 OJPH_ERROR(0x00030028,
"Error writing to file");
650 if (comments != NULL) {
651 for (
ui32 i = 0; i < num_comments; ++i)
654 if (file->
write(&t, 2) != 2)
655 OJPH_ERROR(0x00030029,
"Error writing to file");
657 if (file->
write(&t, 2) != 2)
658 OJPH_ERROR(0x0003002A,
"Error writing to file");
661 if (file->
write(&t, 2) != 2)
662 OJPH_ERROR(0x0003002B,
"Error writing to file");
664 OJPH_ERROR(0x0003002C,
"Error writing to file");
677 size_t num_bytes = f->
read(&new_char, 1);
680 if (new_char == 0xFF)
682 size_t num_bytes = f->
read(&new_char, 1);
687 for (
int i = 0; i < list_len; ++i)
688 if (new_char == (char_list[i] & 0xFF))
698 const char *msg,
int msg_level,
bool resilient)
702 if (file->
read(&com_len, 2) != 2)
707 OJPH_ERROR(0x00030041,
"error reading marker");
735 RGN,
POC,
PPM,
TLM,
PLM,
CRG,
COM,
DFS,
ATK,
NLT,
SOT };
740 int received_markers = 0;
743 marker_idx =
find_marker(file, marker_list + 2, 18);
746 else if (marker_idx == 1)
749 else if (marker_idx == 2)
752 else if (marker_idx == 3)
755 received_markers |= 1;
758 if (num_qlayers != 1)
759 OJPH_ERROR(0x00030053,
"The current implementation supports "
760 "1 quality layer only. This codestream has %d quality layers",
763 else if (marker_idx == 4)
768 OJPH_INFO(0x00030056,
"The codestream carries a COC marker "
769 "segment for a component indexed by %d, which is more than the "
770 "allowed index number, since the codestream has %d components",
774 OJPH_ERROR(0x00030057,
"The codestream has two COC marker "
775 "segments for one component of index %d", p->
get_comp_idx());
777 else if (marker_idx == 5)
780 received_markers |= 2;
782 else if (marker_idx == 6)
787 OJPH_ERROR(0x00030054,
"The codestream carries a QCC marker "
788 "segment for a component indexed by %d, which is more than the "
789 "allowed index number, since the codestream has %d components",
793 OJPH_ERROR(0x00030055,
"The codestream has two QCC marker "
794 "segments for one component of index %d", p->
get_comp_idx());
796 else if (marker_idx == 7)
797 skip_marker(file,
"RGN",
"RGN is not supported yet",
799 else if (marker_idx == 8)
800 skip_marker(file,
"POC",
"POC is not supported yet",
802 else if (marker_idx == 9)
803 skip_marker(file,
"PPM",
"PPM is not supported yet",
805 else if (marker_idx == 10)
808 else if (marker_idx == 11)
811 else if (marker_idx == 12)
813 skip_marker(file,
"CRG",
"CRG has been ignored; CRG is related to"
814 " where the Cb and Cr colour components are co-sited or located"
815 " with respect to the Y' luma component. Perhaps, it is better"
816 " to get the individual components and assemble the samples"
817 " according to your needs",
819 else if (marker_idx == 13)
821 else if (marker_idx == 14)
823 else if (marker_idx == 15)
825 else if (marker_idx == 16)
827 else if (marker_idx == 17)
830 OJPH_ERROR(0x00030051,
"File ended before finding a tile segment");
838 if (received_markers != 3)
839 OJPH_ERROR(0x00030052,
"markers error, COD and QCD are required");
847 ui32 skipped_res_for_recon)
851 "skipped_resolution for data %d must be equal or smaller than "
852 " skipped_resolution for reconstruction %d\n",
856 "skipped_resolution for data %d must be smaller than "
857 " the number of decomposition levels %d\n",
869 OJPH_ERROR(0x000300A3,
"Codestream resilience must be enabled before"
870 " reading file headers.\n");
890 OJPH_INFO(0x00030061,
"wrong tile index")
902 "error in tile part number, should be smaller than total"
903 " number of tile parts")
906 "error in tile part number, should be smaller than total"
907 " number of tile parts")
910 bool sod_found =
false;
920 "POC marker segment in a tile is not supported yet",
922 else if (marker_idx == 1)
924 "PPT marker segment in a tile is not supported yet",
926 else if (marker_idx == 2)
930 else if (marker_idx == 3)
933 else if (marker_idx == 4)
935 "NLT marker in tile is not supported yet",
937 else if (marker_idx == 5)
943 if (marker_idx == -1)
947 "File terminated early before start of data is found"
948 " for tile indexed %d and tile part %d",
952 "File terminated early before start of data is found"
953 " for tile indexed %d and tile part %d",
961 "File terminated during marker segment skipping")
964 "File terminated during marker segment skipping")
970 tile_start_location);
974 bool sod_found =
false;
984 "COD marker segment in a tile is not supported yet",
986 else if (marker_idx == 1)
988 "COC marker segment in a tile is not supported yet",
990 else if (marker_idx == 2)
992 "QCD marker segment in a tile is not supported yet",
994 else if (marker_idx == 3)
996 "QCC marker segment in a tile is not supported yet",
998 else if (marker_idx == 4)
1000 "RGN marker segment in a tile is not supported yet",
1002 else if (marker_idx == 5)
1004 "POC marker segment in a tile is not supported yet",
1006 else if (marker_idx == 6)
1008 "PPT marker segment in a tile is not supported yet",
1010 else if (marker_idx == 7)
1014 else if (marker_idx == 8)
1017 else if (marker_idx == 9)
1019 "PPT marker segment in a tile is not supported yet",
1021 else if (marker_idx == 10)
1027 if (marker_idx == -1)
1031 "File terminated early before start of data is found"
1032 " for tile indexed %d and tile part %d",
1036 "File terminated early before start of data is found"
1037 " for tile indexed %d and tile part %d",
1045 "File terminated during marker segment skipping")
1048 "File terminated during marker segment skipping")
1054 tile_start_location);
1062 if (marker_idx == -1)
1064 OJPH_INFO(0x00030067,
"File terminated early");
1067 else if (marker_idx == 0)
1069 else if (marker_idx == 1)
1083 size_t len = strlen(s);
1089 OJPH_ERROR(0x000300A1,
"unkownn or unsupported profile");
1108 for (
si32 i = 0; i < repeat; ++i)
1109 tiles[i].prepare_for_flush();
1112 for (
si32 i = 0; i < repeat; ++i)
1116 for (
si32 i = 0; i < repeat; ++i)
1120 OJPH_ERROR(0x00030071,
"Error writing to file");
1137 bool success =
false;
1186 bool success =
false;
1228 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
void finalize_alloc(codestream *codestream, const rect &tile_rect, ui32 tile_idx, ui32 &offset, ui32 &num_tileparts)
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)
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()
static ui16 swap_byte(ui16 t)
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 link(param_atk *next)
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)
ui8 get_num_decompositions() const
void update_atk(const param_atk *atk)
param_cod * add_coc_object(ui32 comp_idx)
bool read(infile_base *file)
bool write(outfile_base *file) const
void read(infile_base *file)
void check_validity(param_siz &siz)
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
void check_validity(const param_cod &cod)
bool write(outfile_base *file)
ui16 get_num_components() const
ui32 get_height(ui32 comp_num) const
void link(const param_cod *cod)
void read(infile_base *file)
ui32 get_width(ui32 comp_num) 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)