OpenJPH
Open-source implementation of JPEG2000 Part-15
ojph_tile_comp.cpp
Go to the documentation of this file.
1//***************************************************************************/
2// This software is released under the 2-Clause BSD license, included
3// below.
4//
5// Copyright (c) 2019, Aous Naman
6// Copyright (c) 2019, Kakadu Software Pty Ltd, Australia
7// Copyright (c) 2019, The University of New South Wales, Australia
8//
9// Redistribution and use in source and binary forms, with or without
10// modification, are permitted provided that the following conditions are
11// met:
12//
13// 1. Redistributions of source code must retain the above copyright
14// notice, this list of conditions and the following disclaimer.
15//
16// 2. Redistributions in binary form must reproduce the above copyright
17// notice, this list of conditions and the following disclaimer in the
18// documentation and/or other materials provided with the distribution.
19//
20// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
26// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31//***************************************************************************/
32// This file is part of the OpenJPH software implementation.
33// File: ojph_tile_comp.cpp
34// Author: Aous Naman
35// Date: 28 August 2019
36//***************************************************************************/
37
38
39#include <climits>
40#include <cmath>
41
42#include "ojph_mem.h"
43#include "ojph_params.h"
45#include "ojph_tile_comp.h"
46#include "ojph_resolution.h"
47
48namespace ojph {
49
50 namespace local
51 {
52
55 const rect& recon_comp_rect)
56 {
58
59 //allocate a resolution
61 allocator->pre_alloc_obj<resolution>(1);
62
65 }
66
69 ui32 comp_num, const rect& comp_rect,
70 const rect& recon_comp_rect)
71 {
73
74 //allocate a resolution
76
78 this->comp_rect = comp_rect;
79 this->parent_tile = parent;
80
81 this->comp_num = comp_num;
82 this->num_bytes = 0;
83 res = allocator->post_alloc_obj<resolution>(1);
85 num_decomps, comp_downsamp, this, NULL);
86 }
87
90 {
91 return res->get_line();
92 }
93
96 {
97 res->push_line();
98 }
99
102 {
103 return res->pull_line();
104 }
105
108 {
109 this->num_bytes = res->prepare_precinct();
110 return this->num_bytes;
111 }
112
115 {
116 assert(res_num <= num_decomps);
117 res_num = num_decomps - res_num; //how many levels to go down
118 resolution *r = res;
119 while (res_num > 0 && r != NULL)
120 {
121 r = r->next_resolution();
122 --res_num;
123 }
124 if (r) //resolution does not exist if r is NULL
125 r->write_precincts(file);
126 }
127
130 {
131 assert(res_num <= num_decomps);
132 res_num = num_decomps - res_num;
133 resolution *r = res;
134 while (res_num > 0 && r != NULL)
135 {
136 r = r->next_resolution();
137 --res_num;
138 }
139 if (r) //resolution does not exist if r is NULL
140 return r->get_top_left_precinct(top_left);
141 else
142 return false;
143 }
144
147 {
148 assert(res_num <= num_decomps);
149 res_num = num_decomps - res_num;
150 resolution *r = res;
151 while (res_num > 0 && r != NULL)
152 {
153 r = r->next_resolution();
154 --res_num;
155 }
156 if (r) //resolution does not exist if r is NULL
157 r->write_one_precinct(file);
158 }
159
161 void tile_comp::parse_precincts(ui32 res_num, ui32& data_left,
162 infile_base *file)
163 {
164 assert(res_num <= num_decomps);
165 res_num = num_decomps - res_num; //how many levels to go down
166 resolution *r = res;
167 while (res_num > 0 && r != NULL)
168 {
169 r = r->next_resolution();
170 --res_num;
171 }
172 if (r) //resolution does not exist if r is NULL
173 r->parse_all_precincts(data_left, file);
174 }
175
176
178 void tile_comp::parse_one_precinct(ui32 res_num, ui32& data_left,
179 infile_base *file)
180 {
181 assert(res_num <= num_decomps);
182 res_num = num_decomps - res_num;
183 resolution *r = res;
184 while (res_num > 0 && r != NULL)
185 {
186 r = r->next_resolution();
187 --res_num;
188 }
189 if (r) //resolution does not exist if r is NULL
190 r->parse_one_precinct(data_left, file);
191 }
192
194 ui32 tile_comp::get_num_bytes(ui32 resolution_num) const
195 {
196 return res->get_num_bytes(resolution_num);
197 }
198 }
199}
const param_siz * get_siz()
mem_fixed_allocator * get_allocator()
const param_cod * get_cod()
bool get_top_left_precinct(point &top_left)
void parse_one_precinct(ui32 &data_left, infile_base *file)
void write_precincts(outfile_base *file)
resolution * next_resolution()
void finalize_alloc(codestream *codestream, const rect &res_rect, const rect &recon_res_rect, ui32 comp_num, ui32 res_num, point comp_downsamp, tile_comp *parent_tile_comp, resolution *parent_res)
void parse_all_precincts(ui32 &data_left, infile_base *file)
static void pre_alloc(codestream *codestream, const rect &res_rect, const rect &recon_res_rect, ui32 res_num)
void write_one_precinct(outfile_base *file)
static void pre_alloc(codestream *codestream, const rect &comp_rect, const rect &recon_comp_rect)
bool get_top_left_precinct(ui32 res_num, point &top_left)
void write_one_precinct(ui32 res_num, outfile_base *file)
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)
void pre_alloc_obj(size_t num_ele)
Definition: ojph_mem.h:72
T * post_alloc_obj(size_t num_ele)
Definition: ojph_mem.h:96
OJPH_EXPORT ui32 get_num_decompositions() const
uint32_t ui32
Definition: ojph_defs.h:54
ui8 get_num_decompositions() const
point get_downsampling(ui32 comp_num) const