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
208 void set_irrev_quant(float delta, size_t num_weights,
209 const float weights[]);
210
229 void set_qfactor(float qfactor);
230
248 void set_irrev_quant(ui32 comp_idx, float delta, size_t num_weights,
249 const float weights[]);
250
262 void set_irrev_quant(ui32 comp_idx, float delta);
263
276 void set_qfactor(ui32 comp_idx, comp_type ctype, float qfactor);
277
278 private:
280 };
281
282 /*************************************************************************/
333 {
334 public:
335 enum special_comp_num : ui16 { ALL_COMPS = 65535 };
337 OJPH_NLT_NO_NLT = 0, // supported
338 OJPH_NLT_GAMMA_STYLE_NLT = 1, // not supported
339 OJPH_NLT_LUT_STYLE_NLT = 2, // supported
342 OJPH_NLT_UNDEFINED = 255 // This is used internally and
343 // is not part of the standard
344 };
345 public:
347
348 /*************************************************************************
349 * @brief Sets nonlinearity to OJPH_NLT_NO_NLT = 0 or
350 * OJPH_NLT_BINARY_COMPLEMENT_NLT = 3, which is sometimes called SMAG or
351 * UMAG.
352 * When creating a codestream for writing, call this function before
353 * you call codestream::write_headers.
354 *
355 * The standard requires "If the binary complement to sign-magnitude
356 * conversion transformation is used, the bit-depth of the input samples
357 * to this transformation shall be equal to the bit-depth of the samples
358 * generated by the transformation, and the signed-ness of the input
359 * samples shall be equal to the signed-ness of the output samples."
360 *
361 * @param comp_num: component number, or ALL_COMPS for all components
362 * @param nlt_type: desired non-linearity from enum nonlinearity, only
363 * OJPH_NLT_NO_NLT and OJPH_NLT_BINARY_COMPLEMENT_NLT are allowed
364 */
365 void set_nonlinear_transform(ui32 comp_num, ui8 nl_type);
366
367 /*************************************************************************
368 * @brief Sets nonlinearity to OJPH_NLT_LUT_STYLE_NLT = 2 or
369 * OJPH_NLT_BINARY_COMPLEMENT_PLUS_LUT = 4 nonlinearity. Note that as of
370 * this writing OJPH_NLT_BINARY_COMPLEMENT_PLUS_LUT is not part of the
371 * standard.
372 * When creating a codestream for writing, call this function before
373 * you call codestream::write_headers.
374 * Note that a component, as defined by the codestream headers, has
375 * bitdepth/signedness specified in SIZ marker segment; this is also
376 * the internal format used in encoding/decoding the samples.
377 * The nonlinearity stage allows you to define a different format for
378 * data exchange (for feeding-in and extracting samples) with the library;
379 * this different format is communicated using decoded_bit_depth and
380 * decoded_signedness. Said differently, the nonlinearity can take-in
381 * samples in one format (NLT format) and store them in a different format
382 * (SIZ format).
383 *
384 * The information needed for this call is defined in A.3.10 Non-linearity
385 * point transformation (NLT) of the JPEG2000 Standard Part 2
386 *
387 * @param comp_num: component number, or ALL_COMPS for all components
388 * @param decoded_bit_depth: the number of bits for the fed-in or
389 * extracted samples
390 * @param decoded_signedness: the signedness of the fed-in or extracted
391 * samples
392 * @param d_min: Dmin parameters as defined in the standard
393 * @param d_max: Dmax parameters as defined in the standard
394 * @param pt_val: PTval parameters as defined in the standard
395 * @param num_points: the number of points in the next `points` array
396 * @param points: An array that has `num_points` entries; the size of
397 * each entry depends on pt_val; 1 byte for pt_val \in [1,8],
398 * 2 bytes for pt_val \in [9,16], and 4 bytes for pt_val \in
399 * [17,32].
400 * @param nlt_type: desired non-linearity from enum nonlinearity, only
401 * OJPH_NLT_LUT_STYLE_NLT and OJPH_NLT_BINARY_COMPLEMENT_PLUS_LUT
402 * are allowed
403 * @param approx_encoding_nlt: Selects how the non-linearity is represented
404 * during encoding; the encoding process can either use
405 * a fast approximate representation of the LUT during encoding, or
406 * use the decoder's LUT directly (which we name `precise`).
407 * Set this option to true to use the fast approximate
408 * representation of the non‑linearity or set it to false for the
409 * encoder to directly use the decoder's LUT. The precise approach
410 * is accurate up to floating‑point rounding errors but is slower
411 * than the approximate method. For LUTs that have near‑flat
412 * sections, the precise encoding can be considerably slower; a
413 * warning is issued if this occurs.
414 * @param num_enc_points: sets the number of points to use in the encoding
415 * LUT. For the approximate method, the more points you have the
416 * more accurate representation of the LUT is.
417 * The precise encoding process is basically a search to find the
418 * closest no-larger entry in the decoder's LUT. We improve
419 * performance of this slow search operation by using an encoder LUT
420 * with num_enc_points entries. If the num_enc_points is large
421 * enough such that each edge in the decoder's LUT is accessed by
422 * at least one entry in the encoder's LUT, a quick one step search
423 * is sufficient; otherwise, we need multiple steps.
424 * The one-step search is accelerated using SIMD instructions where
425 * applicable, while it is not clear how useful it would be
426 * to accelerate multi-step searches, so it was not implemented it.
427 * If unsure set it to 0, and let the function call decide.
428 */
429 void set_nonlinear_transform(ui32 comp_num, ui8 decoded_bit_depth,
430 bool decoded_signedness, ui32 d_min,
431 ui32 d_max, ui8 pt_val, ui16 num_points,
432 void* points, ui8 nl_type,
433 bool approx_encoding_nlt = false,
434 ui32 num_enc_points = 0);
435
436 /*************************************************************************
437 * @brief get the nonlinearity type associated with comp_num, which
438 * should be one from enum nonlinearity
439 *
440 * @param comp_num: component number, or ALL_COMPS for all components
441 * @param decoded_bit_depth: returns the bit depth of the decoded samples
442 * for component samples
443 * @param decoded_signedness: returns signedness of decoded samples for
444 * the component samples
445 * @param type: nonlinearity type
446 * @return true if the nonlinearity for comp_num is set
447 */
448 bool get_nonlinear_transform(ui32 comp_num, ui8& decoded_bit_depth,
449 bool& decoded_signedness, ui8& nl_type) const;
450
451 private:
453 };
454
455 /***************************************************************************/
457 {
458 friend class local::codestream;
459 public:
460 comment_exchange() : data(NULL), len(0), Rcom(0) {}
461 void set_string(const char* str);
462 void set_data(const char* data, ui16 len);
463
464 private:
465 const char* data;
468 };
469
470}
471
472#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