48#include "../transform/ojph_colour.h"
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)
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");
293 for (
int i = 0; i < 3; ++i)
297 for (
int i = 0; i < 3; ++i)
312 constexpr ui8 type3 =
313 param_nlt::nonlinearity::OJPH_NLT_BINARY_COMPLEMENT_NLT;
332 tc, 0, shift + 1, comp_width);
334 shift =
is_signed[comp_num] ? 0 : -shift;
358 lines + comp_num, 0, shift + 1, comp_width);
360 shift =
is_signed[comp_num] ? 0 : -shift;
370 comps[2].get_line(), comp_width);
389 comps[0].get_line()->f32,
390 comps[1].get_line()->f32,
391 comps[2].get_line()->f32, comp_width);
405 constexpr ui8 type3 =
406 param_nlt::nonlinearity::OJPH_NLT_BINARY_COMPLEMENT_NLT;
451 lines + 2, comp_width);
455 lines[2].f32, comp_width);
462 src_line =
lines + comp_num;
478 lbp =
lines + comp_num;
516 max_decs =
ojph_max(max_decs,
comps[c].get_num_decompositions());
517 for (
ui32 r = 0; r <= max_decs; ++r)
521 bytes +=
comps[c].get_num_bytes(r);
531 max_decs =
ojph_max(max_decs,
comps[c].get_num_decompositions());
532 for (
ui32 r = 0; r <= max_decs; ++r)
534 if (r <=
comps[c].get_num_decompositions())
549 max_decs =
ojph_max(max_decs,
comps[c].get_num_decompositions());
550 for (
ui32 r = 0; r <= max_decs; ++r)
552 if (r <=
comps[c].get_num_decompositions())
562 ui32 max_decompositions = 0;
564 max_decompositions =
ojph_max(max_decompositions,
565 comps[c].get_num_decompositions());
570 if (!
sot.
write(file, this->num_bytes))
571 OJPH_ERROR(0x00030081,
"Error writing to file");
575 if (!file->
write(&t, 2))
576 OJPH_ERROR(0x00030082,
"Error writing to file");
585 for (
ui32 r = 0; r <= max_decompositions; ++r)
587 comps[c].write_precincts(r, file);
591 for (
ui32 r = 0; r <= max_decompositions; ++r)
595 bytes +=
comps[c].get_num_bytes(r);
598 if (!
sot.
write(file, bytes, (
ui8)r, (
ui8)(max_decompositions + 1)))
599 OJPH_ERROR(0x00030083,
"Error writing to file");
603 if (!file->
write(&t, 2))
604 OJPH_ERROR(0x00030084,
"Error writing to file");
608 comps[c].write_precincts(r, file);
614 for (
ui32 r = 0; r <= max_decompositions; ++r)
616 if (r <=
comps[c].get_num_decompositions()) {
620 OJPH_ERROR(0x00030085,
"Error writing to file");
623 if (!file->
write(&t, 2))
624 OJPH_ERROR(0x00030086,
"Error writing to file");
631 for (
ui32 r = 0; r <= max_decompositions; ++r)
637 bytes +=
comps[c].get_num_bytes(r);
639 if (!
sot.
write(file, bytes, (
ui8)r, (
ui8)(max_decompositions + 1)))
640 OJPH_ERROR(0x00030087,
"Error writing to file");
644 if (!file->
write(&t, 2))
645 OJPH_ERROR(0x00030088,
"Error writing to file");
651 point smallest(INT_MAX, INT_MAX), cur;
654 if (!
comps[c].get_top_left_precinct(r, cur))
659 if (cur.
y < smallest.y)
660 { smallest = cur; comp_num = c; }
661 else if (cur.
y == smallest.y && cur.
x < smallest.x)
662 { smallest = cur; comp_num = c; }
678 point smallest(INT_MAX, INT_MAX), cur;
683 if (!
comps[c].get_top_left_precinct(r, cur))
688 if (cur.
y < smallest.y)
689 { smallest = cur; comp_num = c; res_num = r; }
690 else if (cur.
y == smallest.y && cur.
x < smallest.x)
691 { smallest = cur; comp_num = c; res_num = r; }
692 else if (cur.
y == smallest.y && cur.
x == smallest.x &&
694 { smallest = cur; comp_num = c; res_num = r; }
695 else if (cur.
y == smallest.y && cur.
x == smallest.x &&
696 c == comp_num && r < res_num)
697 { smallest = cur; comp_num = c; res_num = r; }
715 OJPH_ERROR(0x0003008A,
"Error writing to file");
719 if (!file->
write(&t, 2))
720 OJPH_ERROR(0x0003008B,
"Error writing to file");
727 point smallest(INT_MAX, INT_MAX), cur;
728 for (
ui32 r = 0; r <= max_decompositions; ++r)
730 if (!
comps[c].get_top_left_precinct(r, cur))
735 if (cur.
y < smallest.y)
736 { smallest = cur; res_num = r; }
737 else if (cur.
y == smallest.y && cur.
x < smallest.x)
738 { smallest = cur; res_num = r; }
754 const ui64& tile_start_location)
759 OJPH_INFO(0x00030091,
"wrong tile part index")
761 OJPH_ERROR(0x00030091,
"wrong tile part index")
769 data_left -= (
ui32)((
ui64)file->
tell() - tile_start_location);
774 ui32 max_decompositions = 0;
776 max_decompositions =
ojph_max(max_decompositions,
777 comps[c].get_num_decompositions());
785 for (
ui32 r = 0; r <= max_decompositions; ++r)
793 for (
ui32 r = 0; r <= max_decompositions; ++r)
799 point smallest(INT_MAX, INT_MAX), cur;
802 if (!
comps[c].get_top_left_precinct(r, cur))
807 if (cur.
y < smallest.y)
808 { smallest = cur; comp_num = c; }
809 else if (cur.
y == smallest.y && cur.
x < smallest.x)
810 { smallest = cur; comp_num = c; }
812 if (found ==
true && data_left > 0)
826 point smallest(INT_MAX, INT_MAX), cur;
831 if (!
comps[c].get_top_left_precinct(r, cur))
836 if (cur.
y < smallest.y)
837 { smallest = cur; comp_num = c; res_num = r; }
838 else if (cur.
y == smallest.y && cur.
x < smallest.x)
839 { smallest = cur; comp_num = c; res_num = r; }
840 else if (cur.
y == smallest.y && cur.
x == smallest.x &&
842 { smallest = cur; comp_num = c; res_num = r; }
843 else if (cur.
y == smallest.y && cur.
x == smallest.x &&
844 c == comp_num && r < res_num)
845 { smallest = cur; comp_num = c; res_num = r; }
848 if (found ==
true && data_left > 0)
862 point smallest(INT_MAX, INT_MAX), cur;
863 for (
ui32 r = 0; r <= max_decompositions; ++r)
865 if (!
comps[c].get_top_left_precinct(r, cur))
870 if (cur.
y < smallest.y)
871 { smallest = cur; res_num = r; }
872 else if (cur.
y == smallest.y && cur.
x < smallest.x)
873 { smallest = cur; res_num = r; }
875 if (found ==
true && data_left > 0)
886 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
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
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 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)