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;
185 ui32 num_decomps =
cod.get_num_decompositions();
186 size log_cb =
cod.get_log_block_dims();
189 for (
ui32 r = 0; r <= num_decomps; ++r)
191 size log_PP =
cod.get_log_precinct_size(r);
196 max_ratio = 1 << max_ratio;
205 4 * ((max_ratio * max_ratio * 4 + 2) / 3);
222 ui32 num_tileparts = 0;
249 tiles[idx].finalize_alloc(
this, tile_rect, idx, offset, tps);
250 num_tileparts += tps;
266 ui32 cw =
siz.get_recon_width(i);
277 tlm.init(num_tileparts,
290 bool imf2k = !reversible, imf4k = !reversible, imf8k = !reversible;
291 bool imf2kls = reversible, imf4kls = reversible, imf8kls = reversible;
296 if (ext.
x <= 2048 && ext.
y <= 1556)
298 if (ext.
x <= 4096 && ext.
y <= 3112)
300 if (ext.
x <= 8192 && ext.
y <= 6224)
303 if (!imf2kls && !imf4kls && !imf8kls)
305 "Image dimensions do not meet any of the lossless IMF profiles");
310 if (ext.
x <= 2048 && ext.
y <= 1556)
312 if (ext.
x <= 4096 && ext.
y <= 3112)
314 if (ext.
x <= 8192 && ext.
y <= 6224)
317 if (!imf2k && !imf4k && !imf8k)
319 "Image dimensions do not meet any of the lossy IMF profiles");
325 "For IMF profile, image offset (XOsiz, YOsiz) has to be 0.");
328 "For IMF profile, tile offset (XTOsiz, YTOsiz) has to be 0.");
331 "For IMF profile, the number of components has to be less "
333 bool test_ds1 =
true, test_ds2 =
true;
337 test_ds1 &= downsamping.
y == 1;
338 test_ds2 &= downsamping.
y == 1;
340 test_ds1 &= downsamping.
x == 1;
341 if (i == 1 || i == 2)
342 test_ds2 &= downsamping.
x == 2;
344 test_ds2 &= downsamping.
x == 1;
346 if (!test_ds1 && !test_ds2)
348 "For IMF profile, either no component downsampling is used,"
349 " or the x-dimension of the 2nd and 3rd components is downsampled"
357 test_bd &= bit_depth >= 8 && bit_depth <= 16 && is_signed ==
false;
361 "For IMF profile, compnent bit_depth has to be between"
362 " 8 and 16 bits inclusively, and the samples must be unsigned");
366 "For IMF profile, codeblock dimensions are restricted."
367 " Use \"-block_size {32,32}\" at the commandline");
372 for (
ui32 i = 1; i <= num_decomps; ++i)
377 "For IMF profile, precinct sizes are restricted."
378 " Use \"-precincts {128,128},{256,256}\" at the commandline");
382 "For IMF profile, the CPRL progression order must be used."
383 " Use \"-prog_order CPRL\".");
385 imf2k &= num_decomps <= 5;
386 imf2kls &= num_decomps <= 5;
387 imf4k &= num_decomps <= 6;
388 imf4kls &= num_decomps <= 6;
389 imf8k &= num_decomps <= 7;
390 imf8kls &= num_decomps <= 7;
392 if (num_decomps == 0 ||
393 (!imf2k && !imf4k && !imf8k && !imf2kls && !imf4kls && !imf8kls))
395 "Number of decompositions does not match the IMF profile"
396 " dictated by wavelet reversibility and image dimensions.");
402 ui32 total_tiles = tiles_w * tiles_h;
408 "Lossy IMF profile must have one tile.");
411 imf2kls &= (tt.
w == 1024 && tt.
h == 1024);
412 imf2kls &= (tt.
w >= 1024 && num_decomps <= 4)
413 || (tt.
w >= 2048 && num_decomps <= 5);
414 imf4kls &= (tt.
w == 1024 && tt.
h == 1024)
415 || (tt.
w == 2048 && tt.
h == 2048);
416 imf4kls &= (tt.
w >= 1024 && num_decomps <= 4)
417 || (tt.
w >= 2048 && num_decomps <= 5)
418 || (tt.
w >= 4096 && num_decomps <= 6);
419 imf8kls &= (tt.
w == 1024 && tt.
h == 1024)
420 || (tt.
w == 2048 && tt.
h == 2048)
421 || (tt.
w == 4096 && tt.
h == 4096);
422 imf8kls &= (tt.
w >= 1024 && num_decomps <= 4)
423 || (tt.
w >= 2048 && num_decomps <= 5)
424 || (tt.
w >= 4096 && num_decomps <= 6)
425 || (tt.
w >= 8192 && num_decomps <= 7);
426 if (!imf2kls && !imf4kls && !imf8kls)
428 "Number of decompositions does not match the IMF profile"
429 " dictated by wavelet reversibility and image dimensions and"
439 "In IMF profile, tile part divisions at the component level must be "
440 "employed, while at the resolution level is not allowed. "
441 "This has been corrected.");
453 "For broadcast profile, image offset (XOsiz, YOsiz) has to be 0.");
456 "For broadcast profile, tile offset (XTOsiz, YTOsiz) has to be 0.");
459 "For broadcast profile, the number of components has to be less "
461 bool test_ds1 =
true, test_ds2 =
true;
465 test_ds1 &= downsamping.
y == 1;
466 test_ds2 &= downsamping.
y == 1;
468 test_ds1 &= downsamping.
x == 1;
469 if (i == 1 || i == 2)
470 test_ds2 &= downsamping.
x == 2;
472 test_ds2 &= downsamping.
x == 1;
474 if (!test_ds1 && !test_ds2)
476 "For broadcast profile, either no component downsampling is used,"
477 " or the x-dimension of the 2nd and 3rd components is downsampled"
485 test_bd &= bit_depth >= 8 && bit_depth <= 12 && is_signed ==
false;
489 "For broadcast profile, compnent bit_depth has to be between"
490 " 8 and 12 bits inclusively, and the samples must be unsigned");
493 if (num_decomps == 0 || num_decomps > 5)
495 "For broadcast profile, number of decompositions has to be between"
496 "1 and 5 inclusively.");
500 "For broadcast profile, codeblock dimensions are restricted such"
501 " that codeblock width has to be either 32, 64, or 128.");
505 "For broadcast profile, codeblock dimensions are restricted such"
506 " that codeblock height has to be either 32, 64, or 128.");
510 for (
ui32 i = 1; i <= num_decomps; ++i)
515 "For broadcast profile, precinct sizes are restricted."
516 " Use \"-precincts {128,128},{256,256}\" at the commandline");
520 "For broadcast profile, the CPRL progression order must be used."
521 " Use \"-prog_order CPRL\".");
527 ui32 total_tiles = tiles_w * tiles_h;
529 if (total_tiles != 1 && total_tiles != 4)
531 "The broadcast profile can only have 1 or 4 tiles");
539 "In BROADCAST profile, tile part divisions at the component level "
540 "must be employed, while at the resolution level is not allowed. "
541 "This has been corrected.");
553 size tile_size =
siz.get_tile_size();
554 if (tile_size.
h == 0 && tile_size.
w == 0)
556 point img_offset =
siz.get_image_offset();
557 point img_extent =
siz.get_image_extent();
558 size t(img_extent.
x + img_offset.
x, img_extent.
y + img_offset.
y);
559 siz.set_tile_size(t);
561 siz.check_validity();
578 "For LRCP and RLCP progression orders, tilepart divisions at the "
579 "component level, means that we have a tilepart for every "
580 "resolution and component.\n");
586 "For RPCL progression, having tilepart divisions at the component "
587 "level means a tilepart 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 component "
596 "For PCRL progression, having tilepart divisions at the component "
597 "level or the resolution level means a tile part for every "
598 "precinct, which does not make sense, since we can have no more "
599 "than 255 tile parts. This has been corrected by removing tilepart "
600 "divisions; use another progression if you want tileparts.");
606 "For CPRL progression, having tilepart divisions at the resolution "
607 "level means a tile part for every precinct, which does not "
608 "make sense, since we can have no more than 255 tile parts. This "
609 "has been corrected by removing tilepart divisions at the "
610 "resolution level.");
614 planar =
cod.is_employing_color_transform() ? 1 : 0;
620 if (
cod.is_employing_color_transform() ==
true)
622 "the planar interface option cannot be used when colour "
623 "transform is employed");
634 if (file->
write(&t, 2) != 2)
635 OJPH_ERROR(0x00030022,
"Error writing to file");
637 if (!
siz.write(file))
638 OJPH_ERROR(0x00030023,
"Error writing to file");
640 if (!
cap.write(file))
641 OJPH_ERROR(0x00030024,
"Error writing to file");
643 if (!
cod.write(file))
644 OJPH_ERROR(0x00030025,
"Error writing to file");
647 OJPH_ERROR(0x0003002E,
"Error writing to file");
649 if (!
qcd.write(file))
650 OJPH_ERROR(0x00030026,
"Error writing to file");
653 OJPH_ERROR(0x0003002D,
"Error writing to file");
655 if (!
nlt.write(file))
656 OJPH_ERROR(0x00030027,
"Error writing to file");
658 char buf[] =
" OpenJPH Ver "
662 size_t len = strlen(buf);
667 if (file->
write(buf, len) != len)
668 OJPH_ERROR(0x00030028,
"Error writing to file");
670 if (comments != NULL) {
671 for (
ui32 i = 0; i < num_comments; ++i)
674 if (file->
write(&t, 2) != 2)
675 OJPH_ERROR(0x00030029,
"Error writing to file");
677 if (file->
write(&t, 2) != 2)
678 OJPH_ERROR(0x0003002A,
"Error writing to file");
681 if (file->
write(&t, 2) != 2)
682 OJPH_ERROR(0x0003002B,
"Error writing to file");
684 OJPH_ERROR(0x0003002C,
"Error writing to file");
697 size_t num_bytes = f->
read(&new_char, 1);
700 if (new_char == 0xFF)
702 size_t num_bytes = f->
read(&new_char, 1);
707 for (
int i = 0; i < list_len; ++i)
708 if (new_char == (char_list[i] & 0xFF))
718 const char *msg,
int msg_level,
bool resilient)
722 if (file->
read(&com_len, 2) != 2)
727 OJPH_ERROR(0x00030041,
"error reading marker");
755 RGN,
POC,
PPM,
TLM,
PLM,
CRG,
COM,
DFS,
ATK,
NLT,
SOT };
760 int received_markers = 0;
763 marker_idx =
find_marker(file, marker_list + 2, 18);
766 else if (marker_idx == 1)
769 else if (marker_idx == 2)
772 else if (marker_idx == 3)
775 received_markers |= 1;
778 if (num_qlayers != 1)
779 OJPH_ERROR(0x00030053,
"The current implementation supports "
780 "1 quality layer only. This codestream has %d quality layers",
783 else if (marker_idx == 4)
788 OJPH_INFO(0x00030056,
"The codestream carries a COC marker "
789 "segment for a component indexed by %d, which is more than the "
790 "allowed index number, since the codestream has %d components",
794 OJPH_ERROR(0x00030057,
"The codestream has two COC marker "
795 "segments for one component of index %d", p->
get_comp_idx());
797 else if (marker_idx == 5)
800 received_markers |= 2;
802 else if (marker_idx == 6)
807 OJPH_ERROR(0x00030054,
"The codestream carries a QCC marker "
808 "segment for a component indexed by %d, which is more than the "
809 "allowed index number, since the codestream has %d components",
813 OJPH_ERROR(0x00030055,
"The codestream has two QCC marker "
814 "segments for one component of index %d", p->
get_comp_idx());
816 else if (marker_idx == 7)
817 skip_marker(file,
"RGN",
"RGN is not supported yet",
819 else if (marker_idx == 8)
820 skip_marker(file,
"POC",
"POC is not supported yet",
822 else if (marker_idx == 9)
823 skip_marker(file,
"PPM",
"PPM is not supported yet",
825 else if (marker_idx == 10)
828 else if (marker_idx == 11)
831 else if (marker_idx == 12)
833 skip_marker(file,
"CRG",
"CRG has been ignored; CRG is related to"
834 " where the Cb and Cr colour components are co-sited or located"
835 " with respect to the Y' luma component. Perhaps, it is better"
836 " to get the individual components and assemble the samples"
837 " according to your needs",
839 else if (marker_idx == 13)
841 else if (marker_idx == 14)
843 else if (marker_idx == 15)
845 else if (marker_idx == 16)
847 else if (marker_idx == 17)
850 OJPH_ERROR(0x00030051,
"File ended before finding a tile segment");
858 if (received_markers != 3)
859 OJPH_ERROR(0x00030052,
"markers error, COD and QCD are required");
862 planar =
cod.is_employing_color_transform() ? 0 : 1;
871 "skipped_resolution for data %d must be equal or smaller than "
872 " skipped_resolution for reconstruction %d\n",
876 "skipped_resolution for data %d must be smaller than "
877 " the number of decomposition levels %d\n",
889 OJPH_ERROR(0x000300A3,
"Codestream resilience must be enabled before"
890 " reading file headers.\n");
906 bool skip_tile =
false;
911 OJPH_INFO(0x00030061,
"wrong tile index")
927 "error in tile part number, should be smaller than total"
928 " number of tile parts")
931 "error in tile part number, should be smaller than total"
932 " number of tile parts")
935 bool sod_found =
false;
945 "POC marker segment in a tile is not supported yet",
947 else if (marker_idx == 1)
949 "PPT marker segment in a tile is not supported yet",
951 else if (marker_idx == 2)
955 else if (marker_idx == 3)
958 else if (marker_idx == 4)
960 "NLT marker in tile is not supported yet",
962 else if (marker_idx == 5)
968 if (marker_idx == -1)
972 "File terminated early before start of data is found"
973 " for tile indexed %d and tile part %d",
977 "File terminated early before start of data is found"
978 " for tile indexed %d and tile part %d",
986 "File terminated during marker segment skipping")
989 "File terminated during marker segment skipping")
995 tile_start_location);
999 bool sod_found =
false;
1007 if (marker_idx == 0)
1009 "COD marker segment in a tile is not supported yet",
1011 else if (marker_idx == 1)
1013 "COC marker segment in a tile is not supported yet",
1015 else if (marker_idx == 2)
1017 "QCD marker segment in a tile is not supported yet",
1019 else if (marker_idx == 3)
1021 "QCC marker segment in a tile is not supported yet",
1023 else if (marker_idx == 4)
1025 "RGN marker segment in a tile is not supported yet",
1027 else if (marker_idx == 5)
1029 "POC marker segment in a tile is not supported yet",
1031 else if (marker_idx == 6)
1033 "PPT marker segment in a tile is not supported yet",
1035 else if (marker_idx == 7)
1039 else if (marker_idx == 8)
1042 else if (marker_idx == 9)
1044 "PPT marker segment in a tile is not supported yet",
1046 else if (marker_idx == 10)
1052 if (marker_idx == -1)
1056 "File terminated early before start of data is found"
1057 " for tile indexed %d and tile part %d",
1061 "File terminated early before start of data is found"
1062 " for tile indexed %d and tile part %d",
1070 "File terminated during marker segment skipping")
1073 "File terminated during marker segment skipping")
1079 tile_start_location);
1088 if (marker_idx == -1)
1090 OJPH_INFO(0x00030067,
"File terminated early");
1093 else if (marker_idx == 0)
1095 else if (marker_idx == 1)
1109 size_t len = strlen(s);
1115 OJPH_ERROR(0x000300A1,
"unkownn or unsupported profile");
1134 for (
si32 i = 0; i < repeat; ++i)
1135 tiles[i].prepare_for_flush();
1138 for (
si32 i = 0; i < repeat; ++i)
1142 for (
si32 i = 0; i < repeat; ++i)
1146 OJPH_ERROR(0x00030071,
"Error writing to file");
1163 bool success =
false;
1212 bool success =
false;
1254 return lines + comp_num;
virtual size_t read(void *ptr, size_t size)=0
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)
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
ui32 get_comp_idx() const
void read_coc(infile_base *file, ui32 num_comps, param_cod *top_cod)
ui16 get_comp_idx() const
void read_qcc(infile_base *file, ui32 num_comps)
ui8 get_num_tile_parts() const
ui16 get_tile_index() const
bool read(infile_base *file, bool resilient)
ui8 get_tile_part_index() const