47#include "../transform/ojph_colour.h"
48#include "../transform/ojph_transform.h"
57 : precinct_scratch(NULL), allocator(NULL), elastic_alloc(NULL)
120 OJPH_ERROR(0x00030011,
"number of tiles cannot exceed 65535");
125 ui32 num_tileparts = 0;
127 rect tile_rect, recon_tile_rect;
143 - recon_tile_rect.
org.
y;
159 - recon_tile_rect.
org.
x;
163 num_tileparts += tps;
186 for (
ui32 r = 0; r <= num_decomps; ++r)
193 max_ratio = 1 << max_ratio;
202 4 * ((max_ratio * max_ratio * 4 + 2) / 3);
219 ui32 num_tileparts = 0;
247 num_tileparts += tps;
287 bool imf2k = !reversible, imf4k = !reversible, imf8k = !reversible;
288 bool imf2kls = reversible, imf4kls = reversible, imf8kls = reversible;
293 if (ext.
x <= 2048 && ext.
y <= 1556)
295 if (ext.
x <= 4096 && ext.
y <= 3112)
297 if (ext.
x <= 8192 && ext.
y <= 6224)
300 if (!imf2kls && !imf4kls && !imf8kls)
302 "Image dimensions do not meet any of the lossless IMF profiles");
307 if (ext.
x <= 2048 && ext.
y <= 1556)
309 if (ext.
x <= 4096 && ext.
y <= 3112)
311 if (ext.
x <= 8192 && ext.
y <= 6224)
314 if (!imf2k && !imf4k && !imf8k)
316 "Image dimensions do not meet any of the lossy IMF profiles");
322 "For IMF profile, image offset (XOsiz, YOsiz) has to be 0.");
325 "For IMF profile, tile offset (XTOsiz, YTOsiz) has to be 0.");
328 "For IMF profile, the number of components has to be less "
330 bool test_ds1 =
true, test_ds2 =
true;
334 test_ds1 &= downsamping.
y == 1;
335 test_ds2 &= downsamping.
y == 1;
337 test_ds1 &= downsamping.
x == 1;
338 if (i == 1 || i == 2)
339 test_ds2 &= downsamping.
x == 2;
341 test_ds2 &= downsamping.
x == 1;
343 if (!test_ds1 && !test_ds2)
345 "For IMF profile, either no component downsampling is used,"
346 " or the x-dimension of the 2nd and 3rd components is downsampled"
354 test_bd &= bit_depth >= 8 && bit_depth <= 16 && is_signed ==
false;
358 "For IMF profile, compnent bit_depth has to be between"
359 " 8 and 16 bits inclusively, and the samples must be unsigned");
363 "For IMF profile, codeblock dimensions are restricted."
364 " Use \"-block_size {32,32}\" at the commandline");
369 for (
ui32 i = 1; i <= num_decomps; ++i)
374 "For IMF profile, precinct sizes are restricted."
375 " Use \"-precincts {128,128},{256,256}\" at the commandline");
379 "For IMF profile, the CPRL progression order must be used."
380 " Use \"-prog_order CPRL\".");
382 imf2k &= num_decomps <= 5;
383 imf2kls &= num_decomps <= 5;
384 imf4k &= num_decomps <= 6;
385 imf4kls &= num_decomps <= 6;
386 imf8k &= num_decomps <= 7;
387 imf8kls &= num_decomps <= 7;
389 if (num_decomps == 0 ||
390 (!imf2k && !imf4k && !imf8k && !imf2kls && !imf4kls && !imf8kls))
392 "Number of decompositions does not match the IMF profile"
393 " dictated by wavelet reversibility and image dimensions.");
399 ui32 total_tiles = tiles_w * tiles_h;
405 "Lossy IMF profile must have one tile.");
408 imf2kls &= (tt.
w == 1024 && tt.
h == 1024);
409 imf2kls &= (tt.
w >= 1024 && num_decomps <= 4)
410 || (tt.
w >= 2048 && num_decomps <= 5);
411 imf4kls &= (tt.
w == 1024 && tt.
h == 1024)
412 || (tt.
w == 2048 && tt.
h == 2048);
413 imf4kls &= (tt.
w >= 1024 && num_decomps <= 4)
414 || (tt.
w >= 2048 && num_decomps <= 5)
415 || (tt.
w >= 4096 && num_decomps <= 6);
416 imf8kls &= (tt.
w == 1024 && tt.
h == 1024)
417 || (tt.
w == 2048 && tt.
h == 2048)
418 || (tt.
w == 4096 && tt.
h == 4096);
419 imf8kls &= (tt.
w >= 1024 && num_decomps <= 4)
420 || (tt.
w >= 2048 && num_decomps <= 5)
421 || (tt.
w >= 4096 && num_decomps <= 6)
422 || (tt.
w >= 8192 && num_decomps <= 7);
423 if (!imf2kls && !imf4kls && !imf8kls)
425 "Number of decompositions does not match the IMF profile"
426 " dictated by wavelet reversibility and image dimensions and"
436 "In IMF profile, tile part divisions at the component level must be "
437 "employed, while at the resolution level is not allowed. "
438 "This has been corrected.");
450 "For broadcast profile, image offset (XOsiz, YOsiz) has to be 0.");
453 "For broadcast profile, tile offset (XTOsiz, YTOsiz) has to be 0.");
456 "For broadcast profile, the number of components has to be less "
458 bool test_ds1 =
true, test_ds2 =
true;
462 test_ds1 &= downsamping.
y == 1;
463 test_ds2 &= downsamping.
y == 1;
465 test_ds1 &= downsamping.
x == 1;
466 if (i == 1 || i == 2)
467 test_ds2 &= downsamping.
x == 2;
469 test_ds2 &= downsamping.
x == 1;
471 if (!test_ds1 && !test_ds2)
473 "For broadcast profile, either no component downsampling is used,"
474 " or the x-dimension of the 2nd and 3rd components is downsampled"
482 test_bd &= bit_depth >= 8 && bit_depth <= 12 && is_signed ==
false;
486 "For broadcast profile, compnent bit_depth has to be between"
487 " 8 and 12 bits inclusively, and the samples must be unsigned");
490 if (num_decomps == 0 || num_decomps > 5)
492 "For broadcast profile, number of decompositions has to be between"
493 "1 and 5 inclusively.");
497 "For broadcast profile, codeblock dimensions are restricted such"
498 " that codeblock width has to be either 32, 64, or 128.");
502 "For broadcast profile, codeblock dimensions are restricted such"
503 " that codeblock height has to be either 32, 64, or 128.");
507 for (
ui32 i = 1; i <= num_decomps; ++i)
512 "For broadcast profile, precinct sizes are restricted."
513 " Use \"-precincts {128,128},{256,256}\" at the commandline");
517 "For broadcast profile, the CPRL progression order must be used."
518 " Use \"-prog_order CPRL\".");
524 ui32 total_tiles = tiles_w * tiles_h;
526 if (total_tiles != 1 && total_tiles != 4)
528 "The broadcast profile can only have 1 or 4 tiles");
536 "In BROADCAST profile, tile part divisions at the component level "
537 "must be employed, while at the resolution level is not allowed. "
538 "This has been corrected.");
565 "For LRCP and RLCP progression orders, tilepart divisions at the "
566 "component level, means that we have a tilepart for every "
567 "resolution and component.\n");
573 "For RPCL progression, having tilepart divisions at the component "
574 "level means a tilepart for every precinct, which does not "
575 "make sense, since we can have no more than 255 tile parts. This "
576 "has been corrected by removing tilepart divisions at the component "
583 "For PCRL progression, having tilepart divisions at the component "
584 "level or the resolution level means a tile part for every "
585 "precinct, which does not make sense, since we can have no more "
586 "than 255 tile parts. This has been corrected by removing tilepart "
587 "divisions; use another progression if you want tileparts.");
593 "For CPRL progression, having tilepart divisions at the resolution "
594 "level means a tile part for every precinct, which does not "
595 "make sense, since we can have no more than 255 tile parts. This "
596 "has been corrected by removing tilepart divisions at the "
597 "resolution level.");
609 "the planar interface option cannot be used when colour "
610 "transform is employed");
621 if (file->
write(&t, 2) != 2)
622 OJPH_ERROR(0x00030022,
"Error writing to file");
625 OJPH_ERROR(0x00030023,
"Error writing to file");
628 OJPH_ERROR(0x00030024,
"Error writing to file");
631 OJPH_ERROR(0x00030025,
"Error writing to file");
634 OJPH_ERROR(0x00030026,
"Error writing to file");
637 OJPH_ERROR(0x00030027,
"Error writing to file");
639 char buf[] =
" OpenJPH Ver "
643 size_t len = strlen(buf);
648 if (file->
write(buf, len) != len)
649 OJPH_ERROR(0x00030028,
"Error writing to file");
651 if (comments != NULL) {
652 for (
ui32 i = 0; i < num_comments; ++i)
655 if (file->
write(&t, 2) != 2)
656 OJPH_ERROR(0x00030029,
"Error writing to file");
658 if (file->
write(&t, 2) != 2)
659 OJPH_ERROR(0x0003002A,
"Error writing to file");
662 if (file->
write(&t, 2) != 2)
663 OJPH_ERROR(0x0003002B,
"Error writing to file");
665 OJPH_ERROR(0x0003002C,
"Error writing to file");
678 size_t num_bytes = f->
read(&new_char, 1);
681 if (new_char == 0xFF)
683 size_t num_bytes = f->
read(&new_char, 1);
688 for (
int i = 0; i < list_len; ++i)
689 if (new_char == (char_list[i] & 0xFF))
699 const char *msg,
int msg_level,
bool resilient)
703 if (file->
read(&com_len, 2) != 2)
708 OJPH_ERROR(0x00030041,
"error reading marker");
736 RGN,
POC,
PPM,
TLM,
PLM,
CRG,
COM,
DFS,
ATK,
NLT,
SOT };
741 int received_markers = 0;
744 marker_idx =
find_marker(file, marker_list + 2, 18);
747 else if (marker_idx == 1)
750 else if (marker_idx == 2)
753 else if (marker_idx == 3)
756 received_markers |= 1;
759 if (num_qlayers != 1)
760 OJPH_ERROR(0x00030053,
"The current implementation supports "
761 "1 quality layer only. This codestream has %d quality layers",
764 else if (marker_idx == 4)
775 else if (marker_idx == 5)
778 received_markers |= 2;
780 else if (marker_idx == 6)
790 else if (marker_idx == 7)
791 skip_marker(file,
"RGN",
"RGN is not supported yet",
793 else if (marker_idx == 8)
794 skip_marker(file,
"POC",
"POC is not supported yet",
796 else if (marker_idx == 9)
797 skip_marker(file,
"PPM",
"PPM is not supported yet",
799 else if (marker_idx == 10)
802 else if (marker_idx == 11)
805 else if (marker_idx == 12)
807 skip_marker(file,
"CRG",
"CRG has been ignored; CRG is related to"
808 " where the Cb and Cr colour components are co-sited or located"
809 " with respect to the Y' luma component. Perhaps, it is better"
810 " to get the individual components and assemble the samples"
811 " according to your needs",
813 else if (marker_idx == 13)
815 else if (marker_idx == 14)
817 else if (marker_idx == 15)
819 else if (marker_idx == 16)
821 else if (marker_idx == 17)
824 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)
void link_cod(const param_cod *coc)
size get_log_block_dims() const
bool is_employing_color_transform() const
size get_log_precinct_size(ui32 res_num) const
ui8 get_num_decompositions() const
void read(infile_base *file, cod_type type)
void update_atk(const param_atk *atk)
bool read(infile_base *file)
bool write(outfile_base *file) const
void read(infile_base *file)
void check_validity(param_siz &siz)
void read(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)
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)