57 const rect& recon_tile_rect,
ui32& num_tileparts)
88 num_tileparts = 1 + max_decs;
95 num_tileparts += s + 1;
98 if (num_tileparts > 255)
99 OJPH_ERROR(0x000300D1,
"Trying to create %d tileparts; a tile "
100 "cannot have more than 255 tile parts.", num_tileparts);
107 ui32 recon_tx0 = recon_tile_rect.
org.
x;
108 ui32 recon_ty0 = recon_tile_rect.
org.
y;
109 ui32 recon_tx1 = recon_tile_rect.
org.
x + recon_tile_rect.
siz.
w;
110 ui32 recon_ty1 = recon_tile_rect.
org.
y + recon_tile_rect.
siz.
h;
113 rect colour_comp_rect[3];
128 comp_rect.
org.
x = tcx0;
129 comp_rect.
org.
y = tcy0;
130 comp_rect.
siz.
w = tcx1 - tcx0;
131 comp_rect.
siz.
h = tcy1 - tcy0;
134 colour_comp_rect[i] = comp_rect;
136 rect recon_comp_rect;
137 recon_comp_rect.
org.
x = recon_tcx0;
138 recon_comp_rect.
org.
y = recon_tcy0;
139 recon_comp_rect.
siz.
w = recon_tcx1 - recon_tcx0;
140 recon_comp_rect.
siz.
h = recon_tcy1 - recon_tcy0;
151 for (
ui32 i = 0; i < 3; ++i)
154 OJPH_ERROR(0x000300A2,
"When the colour transform is employed, "
155 "all colour components must undergo either reversible or "
156 "irreversible wavelet transform; if not, then it is not clear "
157 "what colour transform should be used (reversible or "
158 "irreversible). Here we found that the first three colour "
159 "components uses %s, %s, and %s transforms, respectively.",
160 reversible[0] ?
"reversible" :
"irreversible",
161 reversible[1] ?
"reversible" :
"irreversible",
162 reversible[2] ?
"reversible" :
"irreversible");
164 if (colour_comp_rect[0] != colour_comp_rect[1] ||
165 colour_comp_rect[1] != colour_comp_rect[2])
166 OJPH_ERROR(0x000300A3,
"When the colour transform is employed, "
167 "the first three colour components must have the same rectangle; "
168 "i.e., the same origin on the canvas and the same width and "
169 "height. The first three components have the following "
170 "origin-size (x,y)-(w,h) values. Component 0 (%d,%d)-(%d,%d), "
171 "Component 1 (%d,%d)-(%d,%d), Component 2 (%d,%d)-(%d,%d)",
172 colour_comp_rect[0].org.x, colour_comp_rect[0].
org.
y,
173 colour_comp_rect[0].
siz.
w, colour_comp_rect[0].
siz.
h,
174 colour_comp_rect[1].
org.
x, colour_comp_rect[1].
org.
y,
175 colour_comp_rect[1].
siz.
w, colour_comp_rect[1].
siz.
h,
176 colour_comp_rect[2].
org.
x, colour_comp_rect[2].
org.
y,
177 colour_comp_rect[2].
siz.
w, colour_comp_rect[2].
siz.
h);
181 for (
int i = 0; i < 3; ++i)
184 for (
int i = 0; i < 3; ++i)
197 sot.init(0, (
ui16)tile_idx, 0, 1);
234 num_tileparts = 1 + max_decs;
241 num_tileparts += s + 1;
244 if (num_tileparts > 255)
245 OJPH_ERROR(0x000300D1,
"Trying to create %d tileparts; a tile "
246 "cannot have more than 255 tile parts.", num_tileparts);
293 OJPH_ERROR(0x000300A1,
"Mismatch between Ssiz (bit_depth = %d, "
294 "is_signed = %s) from SIZ marker segment, and BDnlt "
295 "(bit_depth = %d, is_signed = %s) from NLT marker segment, "
297 is_signed[i] ?
"True" :
"False", bd, is ?
"True" :
"False", i);
314 for (
int i = 0; i < 3; ++i)
318 for (
int i = 0; i < 3; ++i)
333 constexpr ui8 type3 =
353 tc, 0, shift + 1, comp_width);
355 shift =
is_signed[comp_num] ? 0 : -shift;
369 comps[comp_num].push_line();
379 lines + comp_num, 0, shift + 1, comp_width);
381 shift =
is_signed[comp_num] ? 0 : -shift;
391 comps[2].get_line(), comp_width);
392 comps[0].push_line();
393 comps[1].push_line();
394 comps[2].push_line();
410 comps[0].get_line()->f32,
411 comps[1].get_line()->f32,
412 comps[2].get_line()->f32, comp_width);
413 comps[0].push_line();
414 comps[1].push_line();
415 comps[2].push_line();
426 constexpr ui8 type3 =
474 lines + 2, comp_width);
478 lines[2].f32, comp_width);
485 src_line =
lines + comp_num;
487 src_line =
comps[comp_num].pull_line();
501 lbp =
lines + comp_num;
503 lbp =
comps[comp_num].pull_line();
539 max_decs =
ojph_max(max_decs,
comps[c].get_num_decompositions());
540 for (
ui32 r = 0; r <= max_decs; ++r)
544 bytes +=
comps[c].get_num_bytes(r);
554 max_decs =
ojph_max(max_decs,
comps[c].get_num_decompositions());
555 for (
ui32 r = 0; r <= max_decs; ++r)
557 if (r <=
comps[c].get_num_decompositions())
559 comps[c].get_num_bytes(r));
572 max_decs =
ojph_max(max_decs,
comps[c].get_num_decompositions());
573 for (
ui32 r = 0; r <= max_decs; ++r)
575 if (r <=
comps[c].get_num_decompositions())
577 comps[c].get_num_bytes(r));
585 ui32 max_decompositions = 0;
587 max_decompositions =
ojph_max(max_decompositions,
588 comps[c].get_num_decompositions());
593 if (!
sot.write(file, this->num_bytes))
594 OJPH_ERROR(0x00030081,
"Error writing to file");
598 if (!file->
write(&t, 2))
599 OJPH_ERROR(0x00030082,
"Error writing to file");
608 for (
ui32 r = 0; r <= max_decompositions; ++r)
610 comps[c].write_precincts(r, file);
614 for (
ui32 r = 0; r <= max_decompositions; ++r)
618 bytes +=
comps[c].get_num_bytes(r);
621 if (!
sot.write(file, bytes, (
ui8)r, (
ui8)(max_decompositions + 1)))
622 OJPH_ERROR(0x00030083,
"Error writing to file");
626 if (!file->
write(&t, 2))
627 OJPH_ERROR(0x00030084,
"Error writing to file");
631 comps[c].write_precincts(r, file);
637 for (
ui32 r = 0; r <= max_decompositions; ++r)
639 if (r <=
comps[c].get_num_decompositions()) {
641 if (!
sot.write(file,
comps[c].get_num_bytes(r),
643 OJPH_ERROR(0x00030085,
"Error writing to file");
646 if (!file->
write(&t, 2))
647 OJPH_ERROR(0x00030086,
"Error writing to file");
648 comps[c].write_precincts(r, file);
654 for (
ui32 r = 0; r <= max_decompositions; ++r)
660 bytes +=
comps[c].get_num_bytes(r);
662 if (!
sot.write(file, bytes, (
ui8)r, (
ui8)(max_decompositions + 1)))
663 OJPH_ERROR(0x00030087,
"Error writing to file");
667 if (!file->
write(&t, 2))
668 OJPH_ERROR(0x00030088,
"Error writing to file");
674 point smallest(INT_MAX, INT_MAX), cur;
677 if (!
comps[c].get_top_left_precinct(r, cur))
682 if (cur.
y < smallest.y)
683 { smallest = cur; comp_num = c; }
684 else if (cur.
y == smallest.y && cur.
x < smallest.x)
685 { smallest = cur; comp_num = c; }
688 comps[comp_num].write_one_precinct(r, file);
701 point smallest(INT_MAX, INT_MAX), cur;
704 for (
ui32 r = 0; r <=
comps[c].get_num_decompositions(); ++r)
706 if (!
comps[c].get_top_left_precinct(r, cur))
711 if (cur.
y < smallest.y)
712 { smallest = cur; comp_num = c; res_num = r; }
713 else if (cur.
y == smallest.y && cur.
x < smallest.x)
714 { smallest = cur; comp_num = c; res_num = r; }
715 else if (cur.
y == smallest.y && cur.
x == smallest.x &&
717 { smallest = cur; comp_num = c; res_num = r; }
718 else if (cur.
y == smallest.y && cur.
x == smallest.x &&
719 c == comp_num && r < res_num)
720 { smallest = cur; comp_num = c; res_num = r; }
724 comps[comp_num].write_one_precinct(res_num, file);
738 OJPH_ERROR(0x0003008A,
"Error writing to file");
742 if (!file->
write(&t, 2))
743 OJPH_ERROR(0x0003008B,
"Error writing to file");
750 point smallest(INT_MAX, INT_MAX), cur;
751 for (
ui32 r = 0; r <= max_decompositions; ++r)
753 if (!
comps[c].get_top_left_precinct(r, cur))
758 if (cur.
y < smallest.y)
759 { smallest = cur; res_num = r; }
760 else if (cur.
y == smallest.y && cur.
x < smallest.x)
761 { smallest = cur; res_num = r; }
764 comps[c].write_one_precinct(res_num, file);
777 const ui64& tile_start_location)
782 OJPH_INFO(0x00030091,
"wrong tile part index")
784 OJPH_ERROR(0x00030091,
"wrong tile part index")
789 ui64 tile_end_location = tile_start_location +
sot.get_payload_length();
791 ui32 data_left =
sot.get_payload_length();
792 data_left -= (
ui32)((
ui64)file->
tell() - tile_start_location);
797 ui32 max_decompositions = 0;
799 max_decompositions =
ojph_max(max_decompositions,
800 comps[c].get_num_decompositions());
808 for (
ui32 r = 0; r <= max_decompositions; ++r)
811 comps[c].parse_precincts(r, data_left, file);
816 for (
ui32 r = 0; r <= max_decompositions; ++r)
822 point smallest(INT_MAX, INT_MAX), cur;
825 if (!
comps[c].get_top_left_precinct(r, cur))
830 if (cur.
y < smallest.y)
831 { smallest = cur; comp_num = c; }
832 else if (cur.
y == smallest.y && cur.
x < smallest.x)
833 { smallest = cur; comp_num = c; }
835 if (found ==
true && data_left > 0)
836 comps[comp_num].parse_one_precinct(r, data_left, file);
849 point smallest(INT_MAX, INT_MAX), cur;
852 for (
ui32 r = 0; r <=
comps[c].get_num_decompositions(); ++r)
854 if (!
comps[c].get_top_left_precinct(r, cur))
859 if (cur.
y < smallest.y)
860 { smallest = cur; comp_num = c; res_num = r; }
861 else if (cur.
y == smallest.y && cur.
x < smallest.x)
862 { smallest = cur; comp_num = c; res_num = r; }
863 else if (cur.
y == smallest.y && cur.
x == smallest.x &&
865 { smallest = cur; comp_num = c; res_num = r; }
866 else if (cur.
y == smallest.y && cur.
x == smallest.x &&
867 c == comp_num && r < res_num)
868 { smallest = cur; comp_num = c; res_num = r; }
871 if (found ==
true && data_left > 0)
872 comps[comp_num].parse_one_precinct(res_num, data_left, file);
885 point smallest(INT_MAX, INT_MAX), cur;
886 for (
ui32 r = 0; r <= max_decompositions; ++r)
888 if (!
comps[c].get_top_left_precinct(r, cur))
893 if (cur.
y < smallest.y)
894 { smallest = cur; res_num = r; }
895 else if (cur.
y == smallest.y && cur.
x < smallest.x)
896 { smallest = cur; res_num = r; }
898 if (found ==
true && data_left > 0)
899 comps[c].parse_one_precinct(res_num, data_left, file);
909 catch (
const char *
error)
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
static void pre_alloc(codestream *codestream, ui32 comp_num, const rect &comp_rect, const rect &recon_comp_rect)
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
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(* ict_forward)(const float *r, const float *g, const float *b, float *y, float *cb, float *cr, ui32 repeat)
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(* 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)
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(* 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(* 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(* 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)
static ui16 swap_bytes_if_le(ui16 t)
@ 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
bool get_nonlinear_transform(ui32 comp_num, ui8 &bit_depth, bool &is_signed, ui8 &nl_type) 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 set_next_pair(ui16 Ttlm, ui32 Ptlm)