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;
127 comp_rect.
org.
x = tcx0;
128 comp_rect.
org.
y = tcy0;
129 comp_rect.
siz.
w = tcx1 - tcx0;
130 comp_rect.
siz.
h = tcy1 - tcy0;
132 rect recon_comp_rect;
133 recon_comp_rect.
org.
x = recon_tcx0;
134 recon_comp_rect.
org.
y = recon_tcy0;
135 recon_comp_rect.
siz.
w = recon_tcx1 - recon_tcx0;
136 recon_comp_rect.
siz.
h = recon_tcy1 - recon_tcy0;
147 for (
ui32 i = 0; i < 3; ++i)
150 OJPH_ERROR(0x000300A2,
"When the colour transform is employed. "
151 "all colour components must undergo either reversible or "
152 "irreversible wavelet transform; if not, then it is not clear "
153 "what colour transform should be used (reversible or "
154 "irreversible). Here we found that the first three colour "
155 "components uses %s, %s, and %s transforms, respectively.",
156 reversible[0] ?
"reversible" :
"irreversible",
157 reversible[1] ?
"reversible" :
"irreversible",
158 reversible[2] ?
"reversible" :
"irreversible");
162 for (
int i = 0; i < 3; ++i)
165 for (
int i = 0; i < 3; ++i)
178 sot.init(0, (
ui16)tile_idx, 0, 1);
215 num_tileparts = 1 + max_decs;
222 num_tileparts += s + 1;
225 if (num_tileparts > 255)
226 OJPH_ERROR(0x000300D1,
"Trying to create %d tileparts; a tile "
227 "cannot have more than 255 tile parts.", num_tileparts);
274 OJPH_ERROR(0x000300A1,
"Mismatch between Ssiz (bit_depth = %d, "
275 "is_signed = %s) from SIZ marker segment, and BDnlt "
276 "(bit_depth = %d, is_signed = %s) from NLT marker segment, "
278 is_signed[i] ?
"True" :
"False", bd, is ?
"True" :
"False");
295 for (
int i = 0; i < 3; ++i)
299 for (
int i = 0; i < 3; ++i)
314 constexpr ui8 type3 =
334 tc, 0, shift + 1, comp_width);
336 shift =
is_signed[comp_num] ? 0 : -shift;
350 comps[comp_num].push_line();
360 lines + comp_num, 0, shift + 1, comp_width);
362 shift =
is_signed[comp_num] ? 0 : -shift;
372 comps[2].get_line(), comp_width);
373 comps[0].push_line();
374 comps[1].push_line();
375 comps[2].push_line();
391 comps[0].get_line()->f32,
392 comps[1].get_line()->f32,
393 comps[2].get_line()->f32, comp_width);
394 comps[0].push_line();
395 comps[1].push_line();
396 comps[2].push_line();
407 constexpr ui8 type3 =
455 lines + 2, comp_width);
459 lines[2].f32, comp_width);
466 src_line =
lines + comp_num;
468 src_line =
comps[comp_num].pull_line();
482 lbp =
lines + comp_num;
484 lbp =
comps[comp_num].pull_line();
520 max_decs =
ojph_max(max_decs,
comps[c].get_num_decompositions());
521 for (
ui32 r = 0; r <= max_decs; ++r)
525 bytes +=
comps[c].get_num_bytes(r);
535 max_decs =
ojph_max(max_decs,
comps[c].get_num_decompositions());
536 for (
ui32 r = 0; r <= max_decs; ++r)
538 if (r <=
comps[c].get_num_decompositions())
540 comps[c].get_num_bytes(r));
553 max_decs =
ojph_max(max_decs,
comps[c].get_num_decompositions());
554 for (
ui32 r = 0; r <= max_decs; ++r)
556 if (r <=
comps[c].get_num_decompositions())
558 comps[c].get_num_bytes(r));
566 ui32 max_decompositions = 0;
568 max_decompositions =
ojph_max(max_decompositions,
569 comps[c].get_num_decompositions());
574 if (!
sot.write(file, this->num_bytes))
575 OJPH_ERROR(0x00030081,
"Error writing to file");
579 if (!file->
write(&t, 2))
580 OJPH_ERROR(0x00030082,
"Error writing to file");
589 for (
ui32 r = 0; r <= max_decompositions; ++r)
591 comps[c].write_precincts(r, file);
595 for (
ui32 r = 0; r <= max_decompositions; ++r)
599 bytes +=
comps[c].get_num_bytes(r);
602 if (!
sot.write(file, bytes, (
ui8)r, (
ui8)(max_decompositions + 1)))
603 OJPH_ERROR(0x00030083,
"Error writing to file");
607 if (!file->
write(&t, 2))
608 OJPH_ERROR(0x00030084,
"Error writing to file");
612 comps[c].write_precincts(r, file);
618 for (
ui32 r = 0; r <= max_decompositions; ++r)
620 if (r <=
comps[c].get_num_decompositions()) {
622 if (!
sot.write(file,
comps[c].get_num_bytes(r),
624 OJPH_ERROR(0x00030085,
"Error writing to file");
627 if (!file->
write(&t, 2))
628 OJPH_ERROR(0x00030086,
"Error writing to file");
629 comps[c].write_precincts(r, file);
635 for (
ui32 r = 0; r <= max_decompositions; ++r)
641 bytes +=
comps[c].get_num_bytes(r);
643 if (!
sot.write(file, bytes, (
ui8)r, (
ui8)(max_decompositions + 1)))
644 OJPH_ERROR(0x00030087,
"Error writing to file");
648 if (!file->
write(&t, 2))
649 OJPH_ERROR(0x00030088,
"Error writing to file");
655 point smallest(INT_MAX, INT_MAX), cur;
658 if (!
comps[c].get_top_left_precinct(r, cur))
663 if (cur.
y < smallest.y)
664 { smallest = cur; comp_num = c; }
665 else if (cur.
y == smallest.y && cur.
x < smallest.x)
666 { smallest = cur; comp_num = c; }
669 comps[comp_num].write_one_precinct(r, file);
682 point smallest(INT_MAX, INT_MAX), cur;
685 for (
ui32 r = 0; r <=
comps[c].get_num_decompositions(); ++r)
687 if (!
comps[c].get_top_left_precinct(r, cur))
692 if (cur.
y < smallest.y)
693 { smallest = cur; comp_num = c; res_num = r; }
694 else if (cur.
y == smallest.y && cur.
x < smallest.x)
695 { smallest = cur; comp_num = c; res_num = r; }
696 else if (cur.
y == smallest.y && cur.
x == smallest.x &&
698 { smallest = cur; comp_num = c; res_num = r; }
699 else if (cur.
y == smallest.y && cur.
x == smallest.x &&
700 c == comp_num && r < res_num)
701 { smallest = cur; comp_num = c; res_num = r; }
705 comps[comp_num].write_one_precinct(res_num, file);
719 OJPH_ERROR(0x0003008A,
"Error writing to file");
723 if (!file->
write(&t, 2))
724 OJPH_ERROR(0x0003008B,
"Error writing to file");
731 point smallest(INT_MAX, INT_MAX), cur;
732 for (
ui32 r = 0; r <= max_decompositions; ++r)
734 if (!
comps[c].get_top_left_precinct(r, cur))
739 if (cur.
y < smallest.y)
740 { smallest = cur; res_num = r; }
741 else if (cur.
y == smallest.y && cur.
x < smallest.x)
742 { smallest = cur; res_num = r; }
745 comps[c].write_one_precinct(res_num, file);
758 const ui64& tile_start_location)
763 OJPH_INFO(0x00030091,
"wrong tile part index")
765 OJPH_ERROR(0x00030091,
"wrong tile part index")
770 ui64 tile_end_location = tile_start_location +
sot.get_payload_length();
772 ui32 data_left =
sot.get_payload_length();
773 data_left -= (
ui32)((
ui64)file->
tell() - tile_start_location);
778 ui32 max_decompositions = 0;
780 max_decompositions =
ojph_max(max_decompositions,
781 comps[c].get_num_decompositions());
789 for (
ui32 r = 0; r <= max_decompositions; ++r)
792 comps[c].parse_precincts(r, data_left, file);
797 for (
ui32 r = 0; r <= max_decompositions; ++r)
803 point smallest(INT_MAX, INT_MAX), cur;
806 if (!
comps[c].get_top_left_precinct(r, cur))
811 if (cur.
y < smallest.y)
812 { smallest = cur; comp_num = c; }
813 else if (cur.
y == smallest.y && cur.
x < smallest.x)
814 { smallest = cur; comp_num = c; }
816 if (found ==
true && data_left > 0)
817 comps[comp_num].parse_one_precinct(r, data_left, file);
830 point smallest(INT_MAX, INT_MAX), cur;
833 for (
ui32 r = 0; r <=
comps[c].get_num_decompositions(); ++r)
835 if (!
comps[c].get_top_left_precinct(r, cur))
840 if (cur.
y < smallest.y)
841 { smallest = cur; comp_num = c; res_num = r; }
842 else if (cur.
y == smallest.y && cur.
x < smallest.x)
843 { smallest = cur; comp_num = c; res_num = r; }
844 else if (cur.
y == smallest.y && cur.
x == smallest.x &&
846 { smallest = cur; comp_num = c; res_num = r; }
847 else if (cur.
y == smallest.y && cur.
x == smallest.x &&
848 c == comp_num && r < res_num)
849 { smallest = cur; comp_num = c; res_num = r; }
852 if (found ==
true && data_left > 0)
853 comps[comp_num].parse_one_precinct(res_num, data_left, file);
866 point smallest(INT_MAX, INT_MAX), cur;
867 for (
ui32 r = 0; r <= max_decompositions; ++r)
869 if (!
comps[c].get_top_left_precinct(r, cur))
874 if (cur.
y < smallest.y)
875 { smallest = cur; res_num = r; }
876 else if (cur.
y == smallest.y && cur.
x < smallest.x)
877 { smallest = cur; res_num = r; }
879 if (found ==
true && data_left > 0)
880 comps[c].parse_one_precinct(res_num, data_left, file);
890 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)
static ui16 swap_byte(ui16 t)
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)
@ 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)