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& comp_rect,
56 const rect& recon_comp_rect)
57 {
59
60 //allocate a resolution
62 allocator->pre_alloc_obj<resolution>(1);
63
66 }
67
70 ui32 comp_num, const rect& comp_rect,
71 const rect& recon_comp_rect)
72 {
74
75 //allocate a resolution
77
79 this->comp_rect = comp_rect;
80 this->parent_tile = parent;
81
82 this->comp_num = comp_num;
83 this->num_bytes = 0;
84 res = allocator->post_alloc_obj<resolution>(1);
87 NULL);
88 }
89
92 {
93 return res->get_line();
94 }
95
98 {
99 res->push_line();
100 }
101
104 {
105 return res->pull_line();
106 }
107
110 {
111 this->num_bytes = res->prepare_precinct();
112 return this->num_bytes;
113 }
114
117 {
118 assert(res_num <= num_decomps);
119 res_num = num_decomps - res_num; //how many levels to go down
120 resolution *r = res;
121 while (res_num > 0 && r != NULL)
122 {
123 r = r->next_resolution();
124 --res_num;
125 }
126 if (r) //resolution does not exist if r is NULL
127 r->write_precincts(file);
128 }
129
132 {
133 assert(res_num <= num_decomps);
134 res_num = num_decomps - res_num;
135 resolution *r = res;
136 while (res_num > 0 && r != NULL)
137 {
138 r = r->next_resolution();
139 --res_num;
140 }
141 if (r) //resolution does not exist if r is NULL
142 return r->get_top_left_precinct(top_left);
143 else
144 return false;
145 }
146
149 {
150 assert(res_num <= num_decomps);
151 res_num = num_decomps - res_num;
152 resolution *r = res;
153 while (res_num > 0 && r != NULL)
154 {
155 r = r->next_resolution();
156 --res_num;
157 }
158 if (r) //resolution does not exist if r is NULL
159 r->write_one_precinct(file);
160 }
161
163 void tile_comp::parse_precincts(ui32 res_num, ui32& data_left,
164 infile_base *file)
165 {
166 assert(res_num <= num_decomps);
167 res_num = num_decomps - res_num; //how many levels to go down
168 resolution *r = res;
169 while (res_num > 0 && r != NULL)
170 {
171 r = r->next_resolution();
172 --res_num;
173 }
174 if (r) //resolution does not exist if r is NULL
175 r->parse_all_precincts(data_left, file);
176 }
177
178
180 void tile_comp::parse_one_precinct(ui32 res_num, ui32& data_left,
181 infile_base *file)
182 {
183 assert(res_num <= num_decomps);
184 res_num = num_decomps - res_num;
185 resolution *r = res;
186 while (res_num > 0 && r != NULL)
187 {
188 r = r->next_resolution();
189 --res_num;
190 }
191 if (r) //resolution does not exist if r is NULL
192 r->parse_one_precinct(data_left, file);
193 }
194
196 ui32 tile_comp::get_num_bytes(ui32 resolution_num) const
197 {
198 return res->get_num_bytes(resolution_num);
199 }
200 }
201}
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)
static void pre_alloc(codestream *codestream, const rect &res_rect, const rect &recon_res_rect, ui32 comp_num, ui32 res_num)
void finalize_alloc(codestream *codestream, const rect &res_rect, const rect &recon_res_rect, ui32 comp_num, ui32 res_num, point comp_downsamp, point res_downsamp, tile_comp *parent_tile_comp, resolution *parent_res)
resolution * next_resolution()
void parse_all_precincts(ui32 &data_left, infile_base *file)
void write_one_precinct(outfile_base *file)
bool get_top_left_precinct(ui32 res_num, point &top_left)
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)
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
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