58 const rect& recon_tile_rect,
ui32& num_tileparts)
89 num_tileparts = 1 + max_decs;
96 num_tileparts += s + 1;
99 if (num_tileparts > 255)
100 OJPH_ERROR(0x000300D1,
"Trying to create %d tileparts; a tile "
101 "cannot have more than 255 tile parts.", num_tileparts);
108 ui32 recon_tx0 = recon_tile_rect.
org.
x;
109 ui32 recon_ty0 = recon_tile_rect.
org.
y;
110 ui32 recon_tx1 = recon_tile_rect.
org.
x + recon_tile_rect.
siz.
w;
111 ui32 recon_ty1 = recon_tile_rect.
org.
y + recon_tile_rect.
siz.
h;
114 rect colour_comp_rect[3];
129 comp_rect.
org.
x = tcx0;
130 comp_rect.
org.
y = tcy0;
131 comp_rect.
siz.
w = tcx1 - tcx0;
132 comp_rect.
siz.
h = tcy1 - tcy0;
135 colour_comp_rect[i] = comp_rect;
137 rect recon_comp_rect;
138 recon_comp_rect.
org.
x = recon_tcx0;
139 recon_comp_rect.
org.
y = recon_tcy0;
140 recon_comp_rect.
siz.
w = recon_tcx1 - recon_tcx0;
141 recon_comp_rect.
siz.
h = recon_tcy1 - recon_tcy0;
152 for (
ui32 i = 0; i < 3; ++i)
155 OJPH_ERROR(0x000300A2,
"When the colour transform is employed, "
156 "all colour components must undergo either reversible or "
157 "irreversible wavelet transform; if not, then it is not clear "
158 "what colour transform should be used (reversible or "
159 "irreversible). Here we found that the first three colour "
160 "components uses %s, %s, and %s transforms, respectively.",
161 reversible[0] ?
"reversible" :
"irreversible",
162 reversible[1] ?
"reversible" :
"irreversible",
163 reversible[2] ?
"reversible" :
"irreversible");
165 if (colour_comp_rect[0] != colour_comp_rect[1] ||
166 colour_comp_rect[1] != colour_comp_rect[2])
167 OJPH_ERROR(0x000300A3,
"When the colour transform is employed, "
168 "the first three colour components must have the same rectangle; "
169 "i.e., the same origin on the canvas and the same width and "
170 "height. The first three components have the following "
171 "origin-size (x,y)-(w,h) values. Component 0 (%d,%d)-(%d,%d), "
172 "Component 1 (%d,%d)-(%d,%d), Component 2 (%d,%d)-(%d,%d)",
173 colour_comp_rect[0].org.x, colour_comp_rect[0].
org.
y,
174 colour_comp_rect[0].
siz.
w, colour_comp_rect[0].
siz.
h,
175 colour_comp_rect[1].
org.
x, colour_comp_rect[1].
org.
y,
176 colour_comp_rect[1].
siz.
w, colour_comp_rect[1].
siz.
h,
177 colour_comp_rect[2].
org.
x, colour_comp_rect[2].
org.
y,
178 colour_comp_rect[2].
siz.
w, colour_comp_rect[2].
siz.
h);
182 for (
int i = 0; i < 3; ++i)
185 for (
int i = 0; i < 3; ++i)
195 constexpr ui8 type3 =
238 num_tileparts = 1 + max_decs;
245 num_tileparts += s + 1;
248 if (num_tileparts > 255)
249 OJPH_ERROR(0x000300D1,
"Trying to create %d tileparts; a tile "
250 "cannot have more than 255 tile parts.", num_tileparts);
299 bool is =
nlt_ptr[i]->is_signed();
301 OJPH_ERROR(0x000300A1,
"Mismatch between Ssiz (bit_depth = %d, "
302 "is_signed = %s) from SIZ marker segment, and BDnlt "
303 "(bit_depth = %d, is_signed = %s) from NLT marker segment, "
305 is_signed[i] ?
"True" :
"False", bd, is ?
"True" :
"False", i);
321 for (
int i = 0; i < 3; ++i)
325 for (
int i = 0; i < 3; ++i)
340 constexpr ui8 type2 =
342 constexpr ui8 type3 =
344 constexpr ui8 type4 =
362 if (
nlt_ptr[comp_num] == NULL) {
363 shift =
is_signed[comp_num] ? 0 : -shift;
368 nlt_ptr[comp_num]->get_type() == type3)
370 tc, 0, shift + 1, comp_width);
371 else if (
nlt_ptr[comp_num]->get_type() == type2 ||
372 nlt_ptr[comp_num]->get_type() == type4)
382 else if (
nlt_ptr[comp_num]->get_type() == type3)
385 else if (
nlt_ptr[comp_num]->get_type() == type2 ||
386 nlt_ptr[comp_num]->get_type() == type4)
399 if (
nlt_ptr[comp_num] == NULL) {
400 shift =
is_signed[comp_num] ? 0 : -shift;
405 nlt_ptr[comp_num]->get_type() == type3)
407 lines + comp_num, 0, shift + 1, comp_width);
408 else if (
nlt_ptr[comp_num]->get_type() == type2 ||
409 nlt_ptr[comp_num]->get_type() == type4)
419 comps[2].get_line(), comp_width);
431 else if (
nlt_ptr[comp_num]->get_type() == type3)
435 else if (
nlt_ptr[comp_num]->get_type() == type2 ||
436 nlt_ptr[comp_num]->get_type() == type4)
439 comp_width,
nlt_ptr[comp_num]);
443 comps[0].get_line()->f32,
444 comps[1].get_line()->f32,
445 comps[2].get_line()->f32, comp_width);
459 constexpr ui8 type2 =
461 constexpr ui8 type3 =
463 constexpr ui8 type4 =
482 if (
nlt_ptr[comp_num] == NULL) {
488 nlt_ptr[comp_num]->get_type() == type3)
491 else if (
nlt_ptr[comp_num]->get_type() == type2 ||
492 nlt_ptr[comp_num]->get_type() == type4)
503 else if (
nlt_ptr[comp_num]->get_type() == type3)
507 else if (
nlt_ptr[comp_num]->get_type() == type2 ||
508 nlt_ptr[comp_num]->get_type() == type4)
522 lines + 2, comp_width);
526 lines[2].f32, comp_width);
533 src_line =
lines + comp_num;
536 if (
nlt_ptr[comp_num] == NULL) {
542 nlt_ptr[comp_num]->get_type() == type3)
545 else if (
nlt_ptr[comp_num]->get_type() == type2 ||
546 nlt_ptr[comp_num]->get_type() == type4)
555 lbp =
lines + comp_num;
562 else if (
nlt_ptr[comp_num]->get_type() == type3)
566 else if (
nlt_ptr[comp_num]->get_type() == type2 ||
567 nlt_ptr[comp_num]->get_type() == type4)
570 comp_width,
nlt_ptr[comp_num]);
598 max_decs =
ojph_max(max_decs,
comps[c].get_num_decompositions());
599 for (
ui32 r = 0; r <= max_decs; ++r)
603 bytes +=
comps[c].get_num_bytes(r);
613 max_decs =
ojph_max(max_decs,
comps[c].get_num_decompositions());
614 for (
ui32 r = 0; r <= max_decs; ++r)
616 if (r <=
comps[c].get_num_decompositions())
631 max_decs =
ojph_max(max_decs,
comps[c].get_num_decompositions());
632 for (
ui32 r = 0; r <= max_decs; ++r)
634 if (r <=
comps[c].get_num_decompositions())
644 ui32 max_decompositions = 0;
646 max_decompositions =
ojph_max(max_decompositions,
647 comps[c].get_num_decompositions());
652 if (!
sot.
write(file, this->num_bytes))
653 OJPH_ERROR(0x00030081,
"Error writing to file");
657 if (!file->
write(&t, 2))
658 OJPH_ERROR(0x00030082,
"Error writing to file");
667 for (
ui32 r = 0; r <= max_decompositions; ++r)
669 comps[c].write_precincts(r, file);
673 for (
ui32 r = 0; r <= max_decompositions; ++r)
677 bytes +=
comps[c].get_num_bytes(r);
680 if (!
sot.
write(file, bytes, (
ui8)r, (
ui8)(max_decompositions + 1)))
681 OJPH_ERROR(0x00030083,
"Error writing to file");
685 if (!file->
write(&t, 2))
686 OJPH_ERROR(0x00030084,
"Error writing to file");
690 comps[c].write_precincts(r, file);
696 for (
ui32 r = 0; r <= max_decompositions; ++r)
698 if (r <=
comps[c].get_num_decompositions()) {
702 OJPH_ERROR(0x00030085,
"Error writing to file");
705 if (!file->
write(&t, 2))
706 OJPH_ERROR(0x00030086,
"Error writing to file");
713 for (
ui32 r = 0; r <= max_decompositions; ++r)
719 bytes +=
comps[c].get_num_bytes(r);
721 if (!
sot.
write(file, bytes, (
ui8)r, (
ui8)(max_decompositions + 1)))
722 OJPH_ERROR(0x00030087,
"Error writing to file");
726 if (!file->
write(&t, 2))
727 OJPH_ERROR(0x00030088,
"Error writing to file");
733 point smallest(INT_MAX, INT_MAX), cur;
736 if (!
comps[c].get_top_left_precinct(r, cur))
741 if (cur.
y < smallest.y)
742 { smallest = cur; comp_num = c; }
743 else if (cur.
y == smallest.y && cur.
x < smallest.x)
744 { smallest = cur; comp_num = c; }
760 point smallest(INT_MAX, INT_MAX), cur;
765 if (!
comps[c].get_top_left_precinct(r, cur))
770 if (cur.
y < smallest.y)
771 { smallest = cur; comp_num = c; res_num = r; }
772 else if (cur.
y == smallest.y && cur.
x < smallest.x)
773 { smallest = cur; comp_num = c; res_num = r; }
774 else if (cur.
y == smallest.y && cur.
x == smallest.x &&
776 { smallest = cur; comp_num = c; res_num = r; }
777 else if (cur.
y == smallest.y && cur.
x == smallest.x &&
778 c == comp_num && r < res_num)
779 { smallest = cur; comp_num = c; res_num = r; }
797 OJPH_ERROR(0x0003008A,
"Error writing to file");
801 if (!file->
write(&t, 2))
802 OJPH_ERROR(0x0003008B,
"Error writing to file");
809 point smallest(INT_MAX, INT_MAX), cur;
810 for (
ui32 r = 0; r <= max_decompositions; ++r)
812 if (!
comps[c].get_top_left_precinct(r, cur))
817 if (cur.
y < smallest.y)
818 { smallest = cur; res_num = r; }
819 else if (cur.
y == smallest.y && cur.
x < smallest.x)
820 { smallest = cur; res_num = r; }
836 const ui64& tile_start_location)
841 OJPH_INFO(0x00030091,
"wrong tile part index")
843 OJPH_ERROR(0x00030091,
"wrong tile part index")
851 data_left -= (
ui32)((
ui64)file->
tell() - tile_start_location);
856 ui32 max_decompositions = 0;
858 max_decompositions =
ojph_max(max_decompositions,
859 comps[c].get_num_decompositions());
867 for (
ui32 r = 0; r <= max_decompositions; ++r)
875 for (
ui32 r = 0; r <= max_decompositions; ++r)
881 point smallest(INT_MAX, INT_MAX), cur;
884 if (!
comps[c].get_top_left_precinct(r, cur))
889 if (cur.
y < smallest.y)
890 { smallest = cur; comp_num = c; }
891 else if (cur.
y == smallest.y && cur.
x < smallest.x)
892 { smallest = cur; comp_num = c; }
894 if (found ==
true && data_left > 0)
908 point smallest(INT_MAX, INT_MAX), cur;
913 if (!
comps[c].get_top_left_precinct(r, cur))
918 if (cur.
y < smallest.y)
919 { smallest = cur; comp_num = c; res_num = r; }
920 else if (cur.
y == smallest.y && cur.
x < smallest.x)
921 { smallest = cur; comp_num = c; res_num = r; }
922 else if (cur.
y == smallest.y && cur.
x == smallest.x &&
924 { smallest = cur; comp_num = c; res_num = r; }
925 else if (cur.
y == smallest.y && cur.
x == smallest.x &&
926 c == comp_num && r < res_num)
927 { smallest = cur; comp_num = c; res_num = r; }
930 if (found ==
true && data_left > 0)
944 point smallest(INT_MAX, INT_MAX), cur;
945 for (
ui32 r = 0; r <= max_decompositions; ++r)
947 if (!
comps[c].get_top_left_precinct(r, cur))
952 if (cur.
y < smallest.y)
953 { smallest = cur; res_num = r; }
954 else if (cur.
y == smallest.y && cur.
x < smallest.x)
955 { smallest = cur; res_num = r; }
957 if (found ==
true && data_left > 0)
968 catch (
const char *
error)
981 catch (
const std::exception&
error)
991 OJPH_INFO(0x00030094,
"unknown error while parsing a tile header")
ui32 get_tilepart_div() const
const param_cod * get_coc(ui32 comp_num)
ui32 get_skipped_res_for_read()
const param_siz * get_siz()
mem_fixed_allocator * get_allocator()
const param_nlt * get_nlt()
ojph::param_cod access_cod()
const param_cod * get_cod()
bool is_tlm_needed() const
ui32 get_num_decompositions()
void write_one_precinct(ui32 res_num, outfile_base *file)
static void pre_alloc(codestream *codestream, ui32 comp_num, const rect &comp_rect, const rect &recon_comp_rect)
void finalize_alloc(codestream *codestream, tile *parent, ui32 comp_num, const rect &comp_rect, const rect &recon_comp_rect)
void parse_one_precinct(ui32 res_num, ui32 &data_left, infile_base *file)
void write_precincts(ui32 res_num, outfile_base *file)
ui32 get_num_bytes() const
void parse_precincts(ui32 res_num, ui32 &data_left, infile_base *file)
bool pull(line_buf *, ui32 comp_num)
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 fill_tlm(param_tlm *tlm)
void flush(outfile_base *file)
ui32 skipped_res_for_read
bool push(line_buf *line, ui32 comp_num)
bool employ_color_transform
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
@ OJPH_NLT_BINARY_COMPLEMENT_NLT
@ OJPH_NLT_BINARY_COMPLEMENT_PLUS_LUT
void(*) ict_forward(const float *r, const float *g, const float *b, float *y, float *cb, float *cr, ui32 repeat)
void(*) rev_decode_nlt(const line_buf *src_line, const ui32 src_line_offset, line_buf *dst_line, const ui32 dst_line_offset, ui32 bit_depth, bool is_signed, ui32 width, const nlt_rec *rec)
void(*) irv_convert_to_float_nlt_type3(const line_buf *src_line, ui32 src_line_offset, line_buf *dst_line, ui32 bit_depth, bool is_signed, ui32 width)
void(*) irv_convert_to_integer_nlt_type3(const line_buf *src_line, line_buf *dst_line, ui32 dst_line_offset, ui32 bit_depth, bool is_signed, ui32 width)
void(*) rev_convert_nlt_type3(const line_buf *src_line, const ui32 src_line_offset, line_buf *dst_line, const ui32 dst_line_offset, si64 shift, ui32 width)
void(*) irv_convert_to_float_nlt(const line_buf *src_line, ui32 src_line_offset, line_buf *dst_line, ui32 bit_depth, bool is_signed, ui32 width, const nlt_rec *rec)
void(*) rct_forward(const line_buf *r, const line_buf *g, const line_buf *b, line_buf *y, line_buf *cb, line_buf *cr, ui32 repeat)
void(*) irv_convert_to_integer_nlt(const line_buf *src_line, line_buf *dst_line, ui32 dst_line_offset, ui32 bit_depth, bool is_signed, ui32 width, const nlt_rec *rec)
void(*) irv_convert_to_integer(const line_buf *src_line, line_buf *dst_line, ui32 dst_line_offset, ui32 bit_depth, bool is_signed, ui32 width)
void(*) rev_convert(const line_buf *src_line, const ui32 src_line_offset, line_buf *dst_line, const ui32 dst_line_offset, si64 shift, ui32 width)
void(*) rev_encode_nlt(const line_buf *src_line, const ui32 src_line_offset, line_buf *dst_line, ui32 bit_depth, bool is_signed, ui32 width, const nlt_rec *rec)
void(*) irv_convert_to_float(const line_buf *src_line, ui32 src_line_offset, line_buf *dst_line, ui32 bit_depth, bool is_signed, ui32 width)
void(*) ict_backward(const float *y, const float *cb, const float *cr, float *r, float *g, float *b, ui32 repeat)
void(*) rct_backward(const line_buf *r, const line_buf *g, const line_buf *b, line_buf *y, line_buf *cb, line_buf *cr, ui32 repeat)
@ OJPH_TILEPART_RESOLUTIONS
@ OJPH_TILEPART_NO_DIVISIONS
@ OJPH_TILEPART_COMPONENTS
#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,...)
bool is_employing_color_transform() const
ui8 get_num_decompositions() const
bool is_reversible() const
const nlt_rec * get_nlt_rec(ui32 comp_num) const
ui32 get_bit_depth(ui32 comp_num) const
bool is_signed(ui32 comp_num) const
ui16 get_num_components() const
point get_recon_downsampling(ui32 comp_num) const
point get_downsampling(ui32 comp_num) const
void init(ui32 payload_length=0, ui16 tile_idx=0, ui8 tile_part_index=0, ui8 num_tile_parts=0)
ui16 get_tile_index() const
ui8 get_tile_part_index() const
ui32 get_payload_length() const
bool write(outfile_base *file, ui32 payload_len)
void set_next_pair(ui16 Ttlm, ui32 Ptlm)