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
63 allocator->pre_alloc_obj<resolution>(1);
64
67 }
68
71 ui32 comp_num, const rect& comp_rect,
72 const rect& recon_comp_rect)
73 {
75
76 //allocate a resolution
78
80 this->comp_rect = comp_rect;
81 this->parent_tile = parent;
82
83 this->comp_num = comp_num;
84 this->num_bytes = 0;
85 res = allocator->post_alloc_obj<resolution>(1);
88 NULL);
89 }
90
93 {
94 return res->get_line();
95 }
96
99 {
100 res->push_line();
101 }
102
105 {
106 return res->pull_line();
107 }
108
111 {
112 this->num_bytes = res->prepare_precinct();
113 return this->num_bytes;
114 }
115
118 {
119 assert(res_num <= num_decomps);
120 res_num = num_decomps - res_num; //how many levels to go down
121 resolution *r = res;
122 while (res_num > 0 && r != NULL)
123 {
124 r = r->next_resolution();
125 --res_num;
126 }
127 if (r) //resolution does not exist if r is NULL
128 r->write_precincts(file);
129 }
130
133 {
134 int resolution_num = (int)num_decomps - (int)res_num;
135 resolution *r = res;
136 while (resolution_num > 0 && r != NULL)
137 {
138 r = r->next_resolution();
139 --resolution_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 int resolution_num = (int)num_decomps - (int)res_num;
151 resolution *r = res;
152 while (resolution_num > 0 && r != NULL)
153 {
154 r = r->next_resolution();
155 --resolution_num;
156 }
157 if (r) //resolution does not exist if r is NULL
158 r->write_one_precinct(file);
159 }
160
162 void tile_comp::parse_precincts(ui32 res_num, ui32& data_left,
163 infile_base *file)
164 {
165 assert(res_num <= num_decomps);
166 res_num = num_decomps - res_num; //how many levels to go down
167 resolution *r = res;
168 while (res_num > 0 && r != NULL)
169 {
170 r = r->next_resolution();
171 --res_num;
172 }
173 if (r) //resolution does not exist if r is NULL
174 r->parse_all_precincts(data_left, file);
175 }
176
177
179 void tile_comp::parse_one_precinct(ui32 res_num, ui32& data_left,
180 infile_base *file)
181 {
182 assert(res_num <= num_decomps);
183 res_num = num_decomps - res_num;
184 resolution *r = res;
185 while (res_num > 0 && r != NULL)
186 {
187 r = r->next_resolution();
188 --res_num;
189 }
190 if (r) //resolution does not exist if r is NULL
191 r->parse_one_precinct(data_left, file);
192 }
193
195 ui32 tile_comp::get_num_bytes(ui32 resolution_num) const
196 {
197 return res->get_num_bytes(resolution_num);
198 }
199 }
200}
const param_cod * get_coc(ui32 comp_num)
const param_siz * get_siz()
mem_fixed_allocator * get_allocator()
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
uint32_t ui32
Definition: ojph_defs.h:54
ui8 get_num_decompositions() const
point get_downsampling(ui32 comp_num) const