OpenJPH
Open-source implementation of JPEG2000 Part-15
Loading...
Searching...
No Matches
ojph_params_local.h
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_params_local.h
34// Author: Aous Naman
35// Date: 28 August 2019
36//***************************************************************************/
37
38
39#ifndef OJPH_PARAMS_LOCAL_H
40#define OJPH_PARAMS_LOCAL_H
41
42#include <cstring>
43#include <cassert>
44
45#include "ojph_defs.h"
46#include "ojph_base.h"
47#include "ojph_arch.h"
48#include "ojph_message.h"
49
50namespace ojph {
51
53 class outfile_base;
54 class infile_base;
55
65
67 const char OJPH_PO_STRING_LRCP[] = "LRCP";
68 const char OJPH_PO_STRING_RLCP[] = "RLCP";
69 const char OJPH_PO_STRING_RPCL[] = "RPCL";
70 const char OJPH_PO_STRING_PCRL[] = "PCRL";
71 const char OJPH_PO_STRING_CPRL[] = "CPRL";
72
86
88 const char OJPH_PN_STRING_PROFILE0[] = "PROFILE0";
89 const char OJPH_PN_STRING_PROFILE1[] = "PROFILE1";
90 const char OJPH_PN_STRING_CINEMA2K[] = "CINEMA2K";
91 const char OJPH_PN_STRING_CINEMA4K[] = "CINEMA4K";
92 const char OJPH_PN_STRING_CINEMAS2K[] = "CINEMAS2K";
93 const char OJPH_PN_STRING_CINEMAS4K[] = "CINEMAS4K";
94 const char OJPH_PN_STRING_BROADCAST[] = "BROADCAST";
95 const char OJPH_PN_STRING_IMF[] = "IMF";
96
99 OJPH_TILEPART_NO_DIVISIONS = 0x0, // no divisions to tile parts
102 OJPH_TILEPART_LAYERS = 0x4, // these are meaningless with HTJ2K
103 OJPH_TILEPART_MASK = 0x3, // mask used for testing
104 };
105
106 namespace local {
107
108 //defined here
109 struct param_siz;
110 struct param_cod;
111 struct param_qcd;
112 struct param_cap;
113 struct param_sot;
114 struct param_tlm;
115 struct param_dfs;
116 struct param_atk;
117
120 {
121 SOC = 0xFF4F, //start of codestream (required)
122 CAP = 0xFF50, //extended capability
123 SIZ = 0xFF51, //image and tile size (required)
124 COD = 0xFF52, //coding style default (required)
125 COC = 0xFF53, //coding style component
126 TLM = 0xFF55, //tile-part lengths
127 PRF = 0xFF56, //profile
128 PLM = 0xFF57, //packet length, main header
129 PLT = 0xFF58, //packet length, tile-part header
130 CPF = 0xFF59, //corresponding profile values
131 QCD = 0xFF5C, //qunatization default (required)
132 QCC = 0xFF5D, //quantization component
133 RGN = 0xFF5E, //region of interest
134 POC = 0xFF5F, //progression order change
135 PPM = 0xFF60, //packed packet headers, main header
136 PPT = 0xFF61, //packed packet headers, tile-part header
137 CRG = 0xFF63, //component registration
138 COM = 0xFF64, //comment
139 DFS = 0xFF72, //downsampling factor styles
140 ADS = 0xFF73, //arbitrary decomposition styles
141 NLT = 0xFF76, //non-linearity point transformation
142 ATK = 0xFF79, //arbitrary transformation kernels
143 SOT = 0xFF90, //start of tile-part
144 SOP = 0xFF91, //start of packet
145 EPH = 0xFF92, //end of packet
146 SOD = 0xFF93, //start of data
147 EOC = 0xFFD9, //end of codestream (required)
148 };
149
151 //
152 //
153 //
154 //
155 //
163
166 {
167 friend ::ojph::param_siz;
168
169 public:
170 enum : ui16 {
172 RSIZ_HT_FLAG = 0x4000,
174 };
175
176 public:
178 {
179 Lsiz = Csiz = 0;
180 Xsiz = Ysiz = XOsiz = YOsiz = XTsiz = YTsiz = XTOsiz = YTOsiz = 0;
182 memset(store, 0, sizeof(store));
184 cod = NULL;
185 dfs = NULL;
187 cptr = store;
188 old_Csiz = 4;
189 }
190
192 {
193 if (cptr != store) delete[] cptr;
194 }
195
196 void set_num_components(ui32 num_comps)
197 {
198 Csiz = (ui16)num_comps;
199 if (Csiz > old_Csiz)
200 {
201 if (cptr != store)
202 delete[] cptr;
203 cptr = new siz_comp_info[num_comps];
204 old_Csiz = Csiz;
205 }
206 memset(cptr, 0, sizeof(local::siz_comp_info) * num_comps);
207 }
208
209 void set_comp_info(ui32 comp_num, const point& downsampling,
210 ui32 bit_depth, bool is_signed)
211 {
212 assert(comp_num < Csiz);
213 assert(downsampling.x != 0 && downsampling.y != 0);
214 cptr[comp_num].SSiz = (ui8)(bit_depth - 1 + (is_signed ? 0x80 : 0));
215 cptr[comp_num].XRsiz = (ui8)downsampling.x;
216 cptr[comp_num].YRsiz = (ui8)downsampling.y;
217 }
218
220 {
221 this->cod = &cod;
222
223 if (XTsiz == 0 && YTsiz == 0)
224 { XTsiz = Xsiz + XOsiz; YTsiz = Ysiz + YOsiz; }
225 if (Xsiz == 0 || Ysiz == 0 || XTsiz == 0 || YTsiz == 0)
226 OJPH_ERROR(0x00040001,
227 "You cannot set image extent nor tile size to zero");
228 if (XTOsiz > XOsiz || YTOsiz > YOsiz)
229 OJPH_ERROR(0x00040002,
230 "tile offset has to be smaller than image offset");
231 if (XTsiz + XTOsiz <= XOsiz || YTsiz + YTOsiz <= YOsiz)
232 OJPH_ERROR(0x00040003,
233 "the top left tile must intersect with the image");
234 }
235
236 ui16 get_num_components() const { return Csiz; }
237 ui32 get_bit_depth(ui32 comp_num) const
238 {
239 assert(comp_num < Csiz);
240 return (cptr[comp_num].SSiz & 0x7F) + 1u;
241 }
242 bool is_signed(ui32 comp_num) const
243 {
244 assert(comp_num < Csiz);
245 return (cptr[comp_num].SSiz & 0x80) != 0;
246 }
248 {
249 assert(comp_num < Csiz);
250 return point(cptr[comp_num].XRsiz, cptr[comp_num].YRsiz);
251 }
252
253 bool write(outfile_base *file);
254 void read(infile_base *file);
255
256 void link(const param_cod* cod)
257 { this->cod = cod; }
258
259 void link(const param_dfs* dfs)
260 { this->dfs = dfs; }
261
263 { this->skipped_resolutions = skipped_resolutions; }
264
265 ui32 get_width(ui32 comp_num) const
266 {
267 assert(comp_num < get_num_components());
268 ui32 ds = (ui32)cptr[comp_num].XRsiz;
269 ui32 t = ojph_div_ceil(Xsiz, ds) - ojph_div_ceil(XOsiz, ds);
270 return t;
271 }
272
273 ui32 get_height(ui32 comp_num) const
274 {
275 assert(comp_num < get_num_components());
276 ui32 ds = (ui32)cptr[comp_num].YRsiz;
277 ui32 t = ojph_div_ceil(Ysiz, ds) - ojph_div_ceil(YOsiz, ds);
278 return t;
279 }
280
281 point get_recon_downsampling(ui32 comp_num) const;
282 point get_recon_size(ui32 comp_num) const;
283 ui32 get_recon_width(ui32 comp_num) const
284 { return get_recon_size(comp_num).x; }
285 ui32 get_recon_height(ui32 comp_num) const
286 { return get_recon_size(comp_num).y; }
287
290
292 { Rsiz |= flag; }
294 { Rsiz = (ui16)(Rsiz & ~flag); }
295
296 private:
309
310 private:
318 param_siz(const param_siz&) = delete; //prevent copy constructor
319 param_siz& operator=(const param_siz&) = delete; //prevent copy
320 };
321
323 //
324 //
325 //
326 //
327 //
330 {
332 num_decomp = 5;
333 block_width = 4; // 64
334 block_height = 4; // 64
335 block_style = 0x40; // HT mode
336 wavelet_trans = 0; // reversible 5 / 3
337 memset(precinct_size, 0, sizeof(precinct_size));
338 }
339
345 ui8 precinct_size[33]; //num_decomp is in [0,32]
346
348 { return size(block_width + 2, block_height + 2); }
350 { size t = get_log_block_dims(); return size(1 << t.w, 1 << t.h); }
352 {
353 assert(res_num <= num_decomp);
354 size ps(precinct_size[res_num] & 0xF, precinct_size[res_num] >> 4);
355 return ps;
356 }
357 };
358
367
370 {
371 // serves for both COD and COC markers
372 friend ::ojph::param_cod;
377
384 enum cod_type : ui8 {
388 COD_TILE = 3, // not implemented
389 COC_TILE = 4 // not implemented
390 };
392 enum dwt_type : ui8 {
395 };
396
397 public: // COD_MAIN and COC_MAIN common functions
400 {
402 Lcod = 0;
403 Scod = 0;
404 next = NULL;
405 atk = NULL;
406 this->top_cod = top_cod;
407 this->comp_idx = comp_idx;
408 }
409
412 if (next) {
413 delete next;
414 next = NULL;
415 }
416 }
417
419 void set_reversible(bool reversible)
420 {
421 assert(type == UNDEFINED || type == COD_MAIN || type == COC_MAIN);
422 SPcod.