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 =
453 lines + 2, comp_width);
457 lines[2].f32, comp_width);
464 src_line =
lines + comp_num;
466 src_line =
comps[comp_num].pull_line();
480 lbp =
lines + comp_num;
482 lbp =
comps[comp_num].pull_line();
518 max_decs =
ojph_max(max_decs,
comps[c].get_num_decompositions());
519 for (
ui32 r = 0; r <= max_decs; ++r)
523 bytes +=
comps[c].get_num_bytes(r);
533 max_decs =
ojph_max(max_decs,
comps[c].get_num_decompositions());
534 for (
ui32 r = 0; r <= max_decs; ++r)
536 if (r <=
comps[c].get_num_decompositions())
538 comps[c].get_num_bytes(r));
551 max_decs =
ojph_max(max_decs,
comps[c].get_num_decompositions());
552 for (
ui32 r = 0; r <= max_decs; ++r)
554 if (r <=
comps[c].get_num_decompositions())
556 comps[c].get_num_bytes(r));
564 ui32 max_decompositions = 0;
566 max_decompositions =
ojph_max(max_decompositions,
567 comps[c].get_num_decompositions());
572 if (!
sot.write(file, this->num_bytes))
573 OJPH_ERROR(0x00030081,
"Error writing to file");
577 if (!file->
write(&t, 2))
578 OJPH_ERROR(0x00030082,
"Error writing to file");
587 for (
ui32 r = 0; r <= max_decompositions; ++r)
589 comps[c].write_precincts(r, file);
593 for (
ui32 r = 0; r <= max_decompositions; ++r)
597 bytes +=
comps[c].get_num_bytes(r);
600 if (!
sot.write(file, bytes, (
ui8)r, (
ui8)(max_decompositions + 1)))
601 OJPH_ERROR(0x00030083,
"Error writing to file");
605 if (!file->
write(&t, 2))
606 OJPH_ERROR(0x00030084,
"Error writing to file");
610 comps[c].write_precincts(r, file);
616 for (
ui32 r = 0; r <= max_decompositions; ++r)
618 if (r <=
comps[c].get_num_decompositions()) {
620 if (!
sot.write(file,
comps[c].get_num_bytes(r),
622 OJPH_ERROR(0x00030085,
"Error writing to file");
625 if (!file->
write(&t, 2))
626 OJPH_ERROR(0x00030086,
"Error writing to file");
627 comps[c].write_precincts(r, file);
633 for (
ui32 r = 0; r <= max_decompositions; ++r)
639 bytes +=
comps[c].get_num_bytes(r);
641 if (!
sot.write(file, bytes, (
ui8)r, (
ui8)(max_decompositions + 1)))
642 OJPH_ERROR(0x00030087,
"Error writing to file");
646 if (!file->
write(&t, 2))
647 OJPH_ERROR(0x00030088,
"Error writing to file");
653 point smallest(INT_MAX, INT_MAX), cur;
656 if (!
comps[c].get_top_left_precinct(r, cur))
661 if (cur.
y < smallest.y)
662 { smallest = cur; comp_num = c; }
663 else if (cur.
y == smallest.y && cur.
x < smallest.x)
664 { smallest = cur; comp_num = c; }
667 comps[comp_num].write_one_precinct(r, file);
680 point smallest(INT_MAX, INT_MAX), cur;
683 for (
ui32 r = 0; r <=
comps[c].get_num_decompositions(); ++r)
685 if (!
comps[c].get_top_left_precinct(r, cur))
690 if (cur.
y < smallest.y)
691 { smallest = cur; comp_num = c; res_num = r; }
692 else if (cur.
y == smallest.y && cur.
x < smallest.x)
693 { smallest = cur; comp_num = c; res_num = r; }
694 else if (cur.
y == smallest.y && cur.
x == smallest.x &&
696 { smallest = cur; comp_num = c; res_num = r; }
697 else if (cur.
y == smallest.y && cur.
x == smallest.x &&
698 c == comp_num && r < res_num)
699 { smallest = cur; comp_num = c; res_num = r; }
703 comps[comp_num].write_one_precinct(res_num, file);
717 OJPH_ERROR(0x0003008A,
"Error writing to file");
721 if (!file->
write(&t, 2))
722 OJPH_ERROR(0x0003008B,
"Error writing to file");
729 point smallest(INT_MAX, INT_MAX), cur;
730 for (
ui32 r = 0; r <= max_decompositions; ++r)
732 if (!
comps[c].get_top_left_precinct(r, cur))
737 if (cur.
y < smallest.y)
738 { smallest = cur; res_num = r; }
739 else if (cur.
y == smallest.y && cur.
x < smallest.x)
740 { smallest = cur; res_num = r; }
743 comps[c].write_one_precinct(res_num, file);
756 const ui64& tile_start_location)
761 OJPH_INFO(0x00030091,
"wrong tile part index")
763 OJPH_ERROR(0x00030091,
"wrong tile part index")
768 ui64 tile_end_location = tile_start_location +
sot.get_payload_length();
770 ui32 data_left =
sot.get_payload_length();
771 data_left -= (
ui32)((
ui64)file->
tell() - tile_start_location);
776 ui32 max_decompositions = 0;
778 max_decompositions =
ojph_max(max_decompositions,
779 comps[c].get_num_decompositions());
787 for (
ui32 r = 0; r <= max_decompositions; ++r)
790 comps[c].parse_precincts(r, data_left, file);
795 for (
ui32 r = 0; r <= max_decompositions; ++r)
801 point smallest(INT_MAX, INT_MAX), cur;
804 if (!
comps[c].get_top_left_precinct(r, cur))
809 if (cur.
y < smallest.y)
810 { smallest = cur; comp_num = c; }
811 else if (cur.
y == smallest.y && cur.
x < smallest.x)
812 { smallest = cur; comp_num = c; }
814 if (found ==
true && data_left > 0)
815 comps[comp_num].parse_one_precinct(r, data_left, file);
828 point smallest(INT_MAX, INT_MAX), cur;
831 for (
ui32 r = 0; r <=
comps[c].get_num_decompositions(); ++r)
833 if (!
comps[c].get_top_left_precinct(r, cur))
838 if (cur.
y < smallest.y)
839 { smallest = cur; comp_num = c; res_num = r; }
840 else if (cur.
y == smallest.y && cur.
x < smallest.x)
841 { smallest = cur; comp_num = c; res_num = r; }
842 else if (cur.
y == smallest.y && cur.
x == smallest.x &&
844 { smallest = cur; comp_num = c; res_num = r; }
845 else if (cur.
y == smallest.y && cur.
x == smallest.x &&
846 c == comp_num && r < res_num)
847 { smallest = cur; comp_num = c; res_num = r; }
850 if (found ==
true && data_left > 0)
851 comps[comp_num].parse_one_precinct(res_num, data_left, file);
864 point smallest(INT_MAX, INT_MAX), cur;
865 for (
ui32 r = 0; r <= max_decompositions; ++r)
867 if (!
comps[c].get_top_left_precinct(r, cur))
872 if (cur.
y < smallest.y)
873 { smallest = cur; res_num = r; }
874 else if (cur.
y == smallest.y && cur.
x < smallest.x)
875 { smallest = cur; res_num = r; }
877 if (found ==
true && data_left > 0)
878 comps[c].parse_one_precinct(res_num, data_left, file);
888 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)