OpenJPH
Open-source implementation of JPEG2000 Part-15
Loading...
Searching...
No Matches
ojph_params.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.h
34// Author: Aous Naman
35// Date: 28 August 2019
36//***************************************************************************/
37
38
39#ifndef OJPH_PARAMS_H
40#define OJPH_PARAMS_H
41
42#include "ojph_arch.h"
43#include "ojph_base.h"
44
45namespace ojph {
46
47 /***************************************************************************/
48 // defined here
49 class param_siz;
50 class param_cod;
51 class param_qcd;
52 class param_cap;
53 class param_nlt;
54 class codestream;
55
56 /***************************************************************************/
57 // prototyping from local
58 namespace local {
59 struct param_siz;
60 struct param_cod;
61 struct param_qcd;
62 struct param_cap;
63 struct param_nlt;
64 class codestream;
65 }
66
67 /***************************************************************************/
69 {
70 public:
72
73 //setters
74 void set_image_extent(point extent);
75 void set_tile_size(size s);
76 void set_image_offset(point offset);
77 void set_tile_offset(point offset);
78 void set_num_components(ui32 num_comps);
79 void set_component(ui32 comp_num, const point& downsampling,
80 ui32 bit_depth, bool is_signed);
81
82 //getters
83 point get_image_extent() const;
84 point get_image_offset() const;
85 size get_tile_size() const;
86 point get_tile_offset() const;
87 ui32 get_num_components() const;
88 ui32 get_bit_depth(ui32 comp_num) const;
89 bool is_signed(ui32 comp_num) const;
90 point get_downsampling(ui32 comp_num) const;
91
92 //deeper getters
93 ui32 get_recon_width(ui32 comp_num) const;
94 ui32 get_recon_height(ui32 comp_num) const;
95
96 private:
98 };
99
100 /*****************************************************************************
101 * @brief An interface to COD and COC marker segments.
102 *
103 * The param_cod object uses Pimpl design.
104 * The top set of functions give access to the COD marker segment, while
105 * the lower set, the ones that have comp_idx as the first parameter,
106 * gives access to COC marker segment.
107 * The functions:
108 * - set_num_decomposition(ui32 comp_idx, ...)
109 * - set_block_dims(ui32 comp_idx, ...)
110 * - set_precinct_size(ui32 comp_idx, ...)
111 * - set_reversible(ui32 comp_idx, ...)
112 * create a COC segment on first call; subsequent calls to these
113 * functions on the same component index will use the COC segment
114 * created by the first call. On first creation, the COC segment is
115 * initialized to the default COD settings; in particular, 5 levels of
116 * decomposition, 64x64 codeblocks, reversible 5/3 transform and no
117 * precinct size is defined, which gives 32768x32768 precincts.
118 */
120 {
121 public:
123
124 // COD marker segment interface
125 void set_num_decomposition(ui32 num_decompositions);
126 void set_block_dims(ui32 width, ui32 height);
127 void set_precinct_size(int num_levels, size* precinct_size);
128 void set_progression_order(const char *name);
129 void set_color_transform(bool color_transform);
130 void set_reversible(bool reversible);
131
132 ui32 get_num_decompositions() const;
133 size get_block_dims() const;
134 size get_log_block_dims() const;
135 bool is_reversible() const;
136 size get_precinct_size(ui32 level_num) const;
137 size get_log_precinct_size(ui32 level_num) const;
138 int get_progression_order() const;
139 const char* get_progression_order_as_string() const;
140 int get_num_layers() const;
141 bool is_using_color_transform() const;
142 bool packets_may_use_sop() const;
143 bool packets_use_eph() const;
144 bool get_block_vertical_causality() const;
145
146 // COC marker segment interface
147 void set_num_decomposition(ui32 comp_idx, ui32 num_decompositions);
148 void set_block_dims(ui32 comp_idx, ui32 width, ui32 height);
149 void set_precinct_size(ui32 comp_idx, int num_levels, size* precinct_size);
150 void set_reversible(ui32 comp_idx, bool reversible);
151
152 ui32 get_num_decompositions(ui32 comp_idx) const;
153 size get_block_dims(ui32 comp_idx) const;
154 size get_log_block_dims(ui32 comp_idx) const;
155 bool is_reversible(ui32 comp_idx) const;
156 size get_precinct_size(ui32 comp_idx, ui32 level_num) const;
157 size get_log_precinct_size(ui32 comp_idx, ui32 level_num) const;
158 bool get_block_vertical_causality(ui32 comp_idx) const;
159
160 private:
162 };
163
164 /***************************************************************************/
170 {
171 public:
172 enum comp_type : ui8 { // Note the numbers are used by the code
177 };
179 {
180 if (c >= OJPH_COMP_Y && c <= OJPH_COMP_CR)
181 return static_cast<comp_type>(c);
182 else
183 return OJPH_COMP_UNDEFINED;
184 }
185
187
196 void set_irrev_quant(float delta);
197
216 void set_qfactor(float qfactor);
217
229 void set_irrev_quant(ui32 comp_idx, float delta);
230
243 void set_qfactor(ui32 comp_idx, comp_type ctype, float qfactor);
244
245 private:
247 };
248
249 /*************************************************************************/
300 {
301 public:
302 enum special_comp_num : ui16 { ALL_COMPS = 65535 };
304 OJPH_NLT_NO_NLT = 0, // supported
305 OJPH_NLT_GAMMA_STYLE_NLT = 1, // not supported
306 OJPH_NLT_LUT_STYLE_NLT = 2, // supported
309 OJPH_NLT_UNDEFINED = 255 // This is used internally and
310 // is not part of the standard
311 };
312 public:
314
315 /*************************************************************************
316 * @brief Sets nonlinearity to OJPH_NLT_NO_NLT = 0 or
317 * OJPH_NLT_BINARY_COMPLEMENT_NLT = 3, which is sometimes called SMAG or
318 * UMAG.
319 * When creating a codestream for writing, call this function before
320 * you call codestream::write_headers.
321 *
322 * The standard requires "If the binary complement to sign-magnitude
323 * conversion transformation is used, the bit-depth of the input samples
324 * to this transformation shall be equal to the bit-depth of the samples
325 * generated by the transformation, and the signed-ness of the input
326 * samples shall be equal to the signed-ness of the output samples."
327 *
328 * @param comp_num: component number, or ALL_COMPS for all components
329 * @param nlt_type: desired non-linearity from enum nonlinearity, only
330 * OJPH_NLT_NO_NLT and OJPH_NLT_BINARY_COMPLEMENT_NLT are allowed
331 */
332 void set_nonlinear_transform(ui32 comp_num, ui8 nl_type);
333
334 /*************************************************************************
335 * @brief Sets nonlinearity to OJPH_NLT_LUT_STYLE_NLT = 2 or
336 * OJPH_NLT_BINARY_COMPLEMENT_PLUS_LUT = 4 nonlinearity. Note that as of
337 * this writing OJPH_NLT_BINARY_COMPLEMENT_PLUS_LUT is not part of the
338 * standard.
339 * When creating a codestream for writing, call this function before
340 * you call codestream::write_headers.
341 * Note that a component, as defined by the codestream headers, has
342 * bitdepth/signedness specified in SIZ marker segment; this is also
343 * the internal format used in encoding/decoding the samples.
344 * The nonlinearity stage allows you to define a different format for
345 * data exchange (for feeding-in and extracting samples) with the library;
346 * this different format is communicated using decoded_bit_depth and
347 * decoded_signedness. Said differently, the nonlinearity can take-in
348 * samples in one format (NLT format) and store them in a different format
349 * (SIZ format).
350 *
351 * The information needed for this call is defined in A.3.10 Non-linearity
352 * point transformation (NLT) of the JPEG2000 Standard Part 2
353 *
354 * @param comp_num: component number, or ALL_COMPS for all components
355 * @param decoded_bit_depth: the number of bits for the fed-in or
356 * extracted samples
357 * @param decoded_signedness: the signedness of the fed-in or extracted
358 * samples
359 * @param d_min: Dmin parameters as defined in the standard
360 * @param d_max: Dmax parameters as defined in the standard
361 * @param pt_val: PTval parameters as defined in the standard
362 * @param num_points: the number of points in the next `points` array
363 * @param points: An array that has `num_points` entries; the size of
364 * each entry depends on pt_val; 1 byte for pt_val \in [1,8],
365 * 2 bytes for pt_val \in [9,16], and 4 bytes for pt_val \in
366 * [17,32].
367 * @param nlt_type: desired non-linearity from enum nonlinearity, only
368 * OJPH_NLT_LUT_STYLE_NLT and OJPH_NLT_BINARY_COMPLEMENT_PLUS_LUT
369 * are allowed
370 */
371 void set_nonlinear_transform(ui32 comp_num,
372 ui8 decoded_bit_depth, bool decoded_signedness,
373 ui32 d_min, ui32 d_max, ui8 pt_val,
374 ui16 num_points, void* points, ui8 nl_type);
375
376 /*************************************************************************
377 * @brief get the nonlinearity type associated with comp_num, which
378 * should be one from enum nonlinearity
379 *
380 * @param comp_num: component number, or ALL_COMPS for all components
381 * @param decoded_bit_depth: returns the bit depth of the decoded samples
382 * for component samples
383 * @param decoded_signedness: returns signedness of decoded samples for
384 * the component samples
385 * @param type: nonlinearity type
386 * @return true if the nonlinearity for comp_num is set
387 */
388 bool get_nonlinear_transform(ui32 comp_num, ui8& decoded_bit_depth,
389 bool& decoded_signedness, ui8& nl_type) const;
390
391 private:
393 };
394
395 /***************************************************************************/
397 {
398 friend class local::codestream;
399 public:
400 comment_exchange() : data(NULL), len(0), Rcom(0) {}
401 void set_string(const char* str);
402 void set_data(const char* data, ui16 len);
403
404 private:
405 const char* data;
408 };
409
410}
411
412#endif // !OJPH_PARAMS_H
The object represent a codestream.
local::param_cod * state
param_cod(local::param_cod *p)
non-linearity point transformation object (implements NLT marker segment)
@ OJPH_NLT_BINARY_COMPLEMENT_NLT
@ OJPH_NLT_BINARY_COMPLEMENT_PLUS_LUT
param_nlt(local::param_nlt *p)
local::param_nlt * state
Quantization parameters object.
local::param_qcd * state
param_qcd(local::param_qcd *p)
static comp_type ui8_2_comp_type(ui8 c)
local::param_siz * state
Definition ojph_params.h:97
param_siz(local::param_siz *p)
Definition ojph_params.h:71
uint16_t ui16
Definition ojph_defs.h:52
uint32_t ui32
Definition ojph_defs.h:54
uint8_t ui8
Definition ojph_defs.h:50
#define OJPH_EXPORT
Definition ojph_arch.h:144