OpenJPH: /build/openjph/src/OpenJPH/src/core/codestream/ojph_params.cpp Source File

OpenJPH Open-source implementation of JPEG2000 Part-15

Loading...
Searching...
No Matches
ojph_params.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_params.cpp
34// Author: Aous Naman
35// Date: 28 August 2019
36//***************************************************************************/
37
38#define _USE_MATH_DEFINES
39#include <cmath>
40
41#include "ojph_base.h"
42#include "ojph_file.h"
43#include "ojph_params.h"
44
45#include "ojph_params_local.h"
46#include "ojph_message.h"
47
48namespace ojph {
49
51 //
52 //
53 //
54 //
55 //
57
59 void param_siz::set_image_extent(point dims)
60 {
61 state->set_image_extent(dims);
62 }
63
65 void param_siz::set_tile_size(size s)
66 {
67 state->set_tile_size(s);
68 }
69
71 void param_siz::set_image_offset(point offset)
72 {
73 state->set_image_offset(offset);
74 }
75
77 void param_siz::set_tile_offset(point offset)
78 {
79 state->set_tile_offset(offset);
80 }
81
83 void param_siz::set_num_components(ui32 num_comps)
84 {
85 state->set_num_components(num_comps);
86 }
87
89 void param_siz::set_component(ui32 comp_num, const point& downsampling,
90 ui32 bit_depth, bool is_signed)
91 {
92 state->set_comp_info(comp_num, downsampling, bit_depth, is_signed);
93 }
94
96 point param_siz::get_image_extent() const
97 {
98 return point(state->Xsiz, state->Ysiz);
99 }
100
102 point param_siz::get_image_offset() const
103 {
104 return point(state->XOsiz, state->YOsiz);
105 }
106
108 size param_siz::get_tile_size() const
109 {
110 return size(state->XTsiz, state->YTsiz);
111 }
112
114 point param_siz::get_tile_offset() const
115 {
116 return point(state->XTOsiz, state->YTOsiz);
117 }
118
120 ui32 param_siz::get_num_components() const
121 {
122 return state->Csiz;
123 }
124
126 ui32 param_siz::get_bit_depth(ui32 comp_num) const
127 {
128 return state->get_bit_depth(comp_num);
129 }
130
132 bool param_siz::is_signed(ui32 comp_num) const
133 {
134 return state->is_signed(comp_num);
135 }
136
138 point param_siz::get_downsampling(ui32 comp_num) const
139 {
140 return state->get_downsampling(comp_num);
141 }
142
144 ui32 param_siz::get_recon_width(ui32 comp_num) const
145 {
146 return state->get_recon_width(comp_num);
147 }
148
150 ui32 param_siz::get_recon_height(ui32 comp_num) const
151 {
152 return state->get_recon_height(comp_num);
153 }
154
156 //
157 //
158 //
159 //
160 //
162
164 void param_cod::set_num_decomposition(ui32 num_decompositions)
165 {
166 if (num_decompositions > 32)
167 OJPH_ERROR(0x00050001,
168 "maximum number of decompositions cannot exceed 32");
169 state->SPcod.num_decomp = (ui8)num_decompositions;
170 }
171
173 void param_cod::set_block_dims(ui32 width, ui32 height)
174 {
175 ui32 log_width = 31 - count_leading_zeros(width);
176 ui32 log_height = 31 - count_leading_zeros(height);
177 if (width == 0 || width != (1u << log_width)
178 || height == 0 || height != (1u << log_height)
179 || log_width < 2 || log_height < 2
180 || log_width + log_height > 12)
181 OJPH_ERROR(0x00050011, "incorrect code block dimensions");
182 state->SPcod.block_width = (ui8)(log_width - 2);
183 state->SPcod.block_height = (ui8)(log_height - 2);
184 }
185
187 void param_cod::set_precinct_size(int num_levels, size* precinct_size)
188 {
189 if (num_levels == 0 || precinct_size == NULL)
190 state->Scod &= 0xFE;
191 else
192 {
193 state->Scod |= 1;
194 for (int i = 0; i <= state->SPcod.num_decomp; ++i)
195 {
196 size t = precinct_size[i < num_levels ? i : num_levels - 1];
197
198 ui32 PPx = 31 - count_leading_zeros(t.w);
199 ui32 PPy = 31 - count_leading_zeros(t.h);
200 if (t.w == 0 || t.h == 0)
201 OJPH_ERROR(0x00050021, "precinct width or height cannot be 0");
202 if (t.w != (1u<<PPx) || t.h != (1u<<PPy))
203 OJPH_ERROR(0x00050022,
204 "precinct width and height should be a power of 2");
205 if (PPx > 15 || PPy > 15)
206 OJPH_ERROR(0x00050023, "precinct size is too large");
207 if (i > 0 && (PPx == 0 || PPy == 0))
208 OJPH_ERROR(0x00050024, "precinct size is too small");
209 state->SPcod.precinct_size[i] = (ui8)(PPx | (PPy << 4));
210 }
211 }
212 }
213
215 void param_cod::set_progression_order(const char *name)
216 {
217 int prog_order = 0;
218 size_t len = strlen(name);
219 if (len == 4)
220 {
221 if (strncmp(name, OJPH_PO_STRING_LRCP, 4) == 0)
222 prog_order = OJPH_PO_LRCP;
223 else if (strncmp(name, OJPH_PO_STRING_RLCP, 4) == 0)
224 prog_order = OJPH_PO_RLCP;
225 else if (strncmp(name, OJPH_PO_STRING_RPCL, 4) == 0)
226 prog_order = OJPH_PO_RPCL;
227 else if (strncmp(name, OJPH_PO_STRING_PCRL, 4) == 0)
228 prog_order = OJPH_PO_PCRL;
229 else if (strncmp(name, OJPH_PO_STRING_CPRL, 4) == 0)
230 prog_order = OJPH_PO_CPRL;
231 else
232 OJPH_ERROR(0x00050031, "unknown progression order");
233 }
234 else
235 OJPH_ERROR(0x00050032, "improper progression order");
236
237
238 state->SGCod.prog_order = (ui8)prog_order;
239 }
240
242 void param_cod::set_color_transform(bool color_transform)
243 {
244 state->employ_color_transform(color_transform ? 1 : 0);
245 }
246
248 void param_cod::set_reversible(bool reversible)
249 {
250 state->set_reversible(reversible);
251 }
252
254 param_coc param_cod::get_coc(ui32 component_idx)
255 {
256 local::param_cod *p = state->get_coc(component_idx);
257 if (p == state) // no COC segment marker for this component
258 p = state->add_coc_object(component_idx);
259 return param_coc(p);
260 }
261
263 ui32 param_cod::get_num_decompositions() const
264 {
265 return state->get_num_decompositions();
266 }
267
269 size param_cod::get_block_dims() const
270 {
271 return state->get_block_dims();
272 }
273
275 size param_cod::get_log_block_dims() const
276 {
277 return state->get_log_block_dims();
278 }
279
281 bool param_cod::is_reversible() const
282 {
283 return state->is_reversible();
284 }
285
287 size param_cod::get_precinct_size(ui32 level_num) const
288 {
289 return state->get_precinct_size(level_num);
290 }
291
293 size param_cod::get_log_precinct_size(ui32 level_num) const
294 {
295 return state->get_log_precinct_size(level_num);
296 }
297
299 int param_cod::get_progression_order() const
300 {
301 return state->SGCod.prog_order;
302 }
303
305 const char* param_cod::get_progression_order_as_string() const
306 {
307 if (state->SGCod.prog_order == OJPH_PO_LRCP)
308 return OJPH_PO_STRING_LRCP;
309 else if (state->SGCod.prog_order == OJPH_PO_RLCP)
310 return OJPH_PO_STRING_RLCP;
311 else if (state->SGCod.prog_order == OJPH_PO_RPCL)
312 return OJPH_PO_STRING_RPCL;
313 else if (state->SGCod.prog_order == OJPH_PO_PCRL)
314 return OJPH_PO_STRING_PCRL;
315 else if (state->SGCod.prog_order == OJPH_PO_CPRL)
316 return OJPH_PO_STRING_CPRL;
317 else
318 assert(0);
319 return "";
320 }
321
323 int param_cod::get_num_layers() const
324 {
325 return state->SGCod.num_layers;
326 }
327
329 bool param_cod::is_using_color_transform() const
330 {
331 return state->is_employing_color_transform();
332 }
333
335 bool param_cod::packets_may_use_sop() const
336 {
337 return state->packets_may_use_sop();
338 }
339
341 bool param_cod::packets_use_eph() const
342 {
343 return state->packets_use_eph();
344 }
345
347 bool param_cod::get_block_vertical_causality() const
348 {
349 return state->get_block_vertical_causality();
350 }
351
353 //
354 //
355 //
356 //
357 //
359
361 void param_coc::set_num_decomposition(ui32 num_decompositions)
362 { ojph::param_cod(state).set_num_decomposition(num_decompositions); }
363
365 void param_coc::set_block_dims(ui32 width, ui32 height)
366 { ojph::param_cod(state).set_block_dims(width, height); }
367
369 void param_coc::set_precinct_size(int num_levels, size* precinct_size)
370 { ojph::param_cod(state).set_precinct_size(num_levels, precinct_size); }
371
373 void param_coc::set_reversible(bool reversible)
374 { ojph::param_cod(state).set_reversible(reversible); }
375
377 ui32 param_coc::get_num_decompositions() const
378 { return ojph::param_cod(state).get_num_decompositions(); }
379
381 size param_coc::get_block_dims() const
382 { return ojph::param_cod(state).get_block_dims(); }
383
385 size param_coc::get_log_block_dims() const
386 { return ojph::param_cod(state).get_log_block_dims(); }
387
389 bool param_coc::is_reversible() const
390 { return ojph::param_cod(state).is_reversible(); }
391
393 size param_coc::get_precinct_size(ui32 level_num) const
394 { return ojph::param_cod(state).get_precinct_size(level_num); }
395
397 size param_coc::get_log_precinct_size(ui32 level_num) const
398 { return ojph::param_cod(state).get_log_precinct_size(level_num); }
399
401 bool param_coc::get_block_vertical_causality() const
402 { return ojph::param_cod(state).get_block_vertical_causality(); }
403
404
406 //
407 //
408 //
409 //
410 //
412
414 void param_qcd::set_irrev_quant(float delta)
415 {
416 state->set_delta(delta);
417 }
418
420 void param_qcd::set_irrev_quant(ui32 comp_idx, float delta)
421 {
422 state->set_delta(comp_idx, delta);
423 }
424
426 //
427 //
428 //
429 //
430 //
432
434 void param_nlt::set_nonlinear_transform(ui32 comp_num, ui8 nl_type)
435 {
436 state->set_nonlinear_transform(comp_num, nl_type);
437 }
438
440 bool param_nlt::get_nonlinear_transform(ui32 comp_num, ui8& bit_depth,
441 bool& is_signed, ui8& nl_type) const
442 {
443 return state->get_nonlinear_transform(comp_num, bit_depth, is_signed,
444 nl_type);
445 }
446
448 //
449 //
450 //
451 //
452 //
454
456 void comment_exchange::set_string(const char* str)
457 {
458 size_t t = strlen(str);
459 if (len > 65531)
460 OJPH_ERROR(0x000500C1,
461 "COM marker string length cannot be larger than 65531");
462 this->data = str;
463 this->len = (ui16)t;
464 this->Rcom = 1;
465 }
466
468 void comment_exchange::set_data(const char* data, ui16 len)
469 {
470 if (len > 65531)
471 OJPH_ERROR(0x000500C2,
472 "COM marker string length cannot be larger than 65531");
473 this->data = data;
474 this->len = len;
475 this->Rcom = 0;
476 }
477
479 //
480 //
481 // LOCAL
482 //
483 //
485
486 namespace local {
487
489 static inline
490 ui16 swap_byte(ui16 t)
491 {
492 return (ui16)((t << 8) | (t >> 8));
493 }
494
496 static inline
497 ui32 swap_byte(ui32 t)
498 {
499 ui32 u = swap_byte((ui16)(t & 0xFFFFu));
500 u <<= 16;
501 u |= swap_byte((ui16)(t >> 16));
502 return u;
503 }
504
506 static inline
507 ui64 swap_byte(ui64 t)
508 {
509 ui64 u = swap_byte((ui32)(t & 0xFFFFFFFFu));
510 u <<= 32;
511 u |= swap_byte((ui32)(t >> 32));
512 return u;
513 }
514
516 //
517 //
518 //
519 //
520 //
522
524 //static
525 class sqrt_energy_gains
526 {
527 public:
528 static float get_gain_l(ui32 num_decomp, bool reversible)
529 { return reversible ? gain_5x3_l[num_decomp] : gain_9x7_l[num_decomp]; }
530 static float get_gain_h(ui32 num_decomp, bool reversible)
531 { return reversible ? gain_5x3_h[num_decomp] : gain_9x7_h[num_decomp]; }
532
533 private:
534 static const float gain_9x7_l[34];
535 static const float gain_9x7_h[34];
536 static const float gain_5x3_l[34];
537 static const float gain_5x3_h[34];
538 };
539
541 const float sqrt_energy_gains::gain_9x7_l[34] = { 1.0000e+00f,
542 1.4021e+00f, 2.0304e+00f, 2.9012e+00f, 4.1153e+00f, 5.8245e+00f,
543 8.2388e+00f, 1.1652e+01f, 1.6479e+01f, 2.3304e+01f, 3.2957e+01f,
544 4.6609e+01f, 6.5915e+01f, 9.3217e+01f, 1.3183e+02f, 1.8643e+02f,
545 2.6366e+02f, 3.7287e+02f, 5.2732e+02f, 7.4574e+02f, 1.0546e+03f,
546 1.4915e+03f, 2.1093e+03f, 2.9830e+03f, 4.2185e+03f, 5.9659e+03f,
547 8.4371e+03f, 1.1932e+04f, 1.6874e+04f, 2.3864e+04f, 3.3748e+04f,
548 4.7727e+04f, 6.7496e+04f, 9.5454e+04f };
549 const float sqrt_energy_gains::gain_9x7_h[34] = { 1.4425e+00f,
550 1.9669e+00f, 2.8839e+00f, 4.1475e+00f, 5.8946e+00f, 8.3472e+00f,
551 1.1809e+01f, 1.6701e+01f, 2.3620e+01f, 3.3403e+01f, 4.7240e+01f,
552 6.6807e+01f, 9.4479e+01f, 1.3361e+02f, 1.8896e+02f, 2.6723e+02f,
553 3.7792e+02f, 5.3446e+02f, 7.5583e+02f, 1.0689e+03f, 1.5117e+03f,
554 2.1378e+03f, 3.0233e+03f, 4.2756e+03f, 6.0467e+03f, 8.5513e+03f,
555 1.2093e+04f, 1.7103e+04f, 2.4187e+04f, 3.4205e+04f, 4.8373e+04f,
556 6.8410e+04f, 9.6747e+04f, 1.3682e+05f };
557 const float sqrt_energy_gains::gain_5x3_l[34] = { 1.0000e+00f,
558 1.2247e+00f, 1.3229e+00f, 1.5411e+00f, 1.7139e+00f, 1.9605e+00f,
559 2.2044e+00f, 2.5047e+00f, 2.8277e+00f, 3.2049e+00f, 3.6238e+00f,
560 4.1033e+00f, 4.6423e+00f, 5.2548e+00f, 5.9462e+00f, 6.7299e+00f,
561 7.6159e+00f, 8.6193e+00f, 9.7544e+00f, 1.1039e+01f, 1.2493e+01f,
562 1.4139e+01f, 1.6001e+01f, 1.8108e+01f, 2.0493e+01f, 2.3192e+01f,
563 2.6246e+01f, 2.9702e+01f, 3.3614e+01f, 3.8041e+01f, 4.3051e+01f,
564 4.8721e+01f, 5.5138e+01f, 6.2399e+01f };
565 const float sqrt_energy_gains::gain_5x3_h[34] = { 1.0458e+00f,
566 1.3975e+00f, 1.4389e+00f, 1.7287e+00f, 1.8880e+00f, 2.1841e+00f,
567 2.4392e+00f, 2.7830e+00f, 3.1341e+00f, 3.5576e+00f, 4.0188e+00f,
568 4.5532e+00f, 5.1494e+00f, 5.8301e+00f, 6.5963e+00f, 7.4663e+00f,
569 8.4489e+00f, 9.5623e+00f, 1.0821e+01f, 1.2247e+01f, 1.3860e+01f,
570 1.5685e+01f, 1.7751e+01f, 2.0089e+01f, 2.2735e+01f, 2.5729e+01f,
571 2.9117e+01f, 3.2952e+01f, 3.7292e+01f, 4.2203e+01f, 4.7761e+01f,
572 5.4051e+01f, 6.1170e+01f, 6.9226e+01f };
573
575 //static
576 class bibo_gains
577 {
578 public:
579 static float get_bibo_gain_l(ui32 num_decomp, bool reversible)
580 { return reversible ? gain_5x3_l[num_decomp] : gain_9x7_l[num_decomp]; }
581 static float get_bibo_gain_h(ui32 num_decomp, bool reversible)
582 { return reversible ? gain_5x3_h[num_decomp] : gain_9x7_h[num_decomp]; }
583
584 private:
585 static const float gain_9x7_l[34];
586 static const float gain_9x7_h[34];
587 static const float gain_5x3_l[34];
588 static const float gain_5x3_h[34];
589 };
590
592 const float bibo_gains::gain_9x7_l[34] = { 1.0000e+00f, 1.3803e+00f,
593 1.3328e+00f, 1.3067e+00f, 1.3028e+00f, 1.3001e+00f, 1.2993e+00f,
594 1.2992e+00f, 1.2992e+00f, 1.2992e+00f, 1.2992e+00f, 1.2992e+00f,
595 1.2992e+00f, 1.2992e+00f, 1.2992e+00f, 1.2992e+00f, 1.2992e+00f,
596 1.2992e+00f, 1.2992e+00f, 1.2992e+00f, 1.2992e+00f, 1.2992e+00f,
597 1.2992e+00f, 1.2992e+00f, 1.2992e+00f, 1.2992e+00f, 1.2992e+00f,
598 1.2992e+00f, 1.2992e+00f, 1.2992e+00f, 1.2992e+00f, 1.2992e+00f,
599 1.2992e+00f, 1.2992e+00f };
600 const float bibo_gains::gain_9x7_h[34] = { 1.2976e+00f, 1.3126e+00f,
601 1.2757e+00f, 1.2352e+00f, 1.2312e+00f, 1.2285e+00f, 1.2280e+00f,
602 1.2278e+00f, 1.2278e+00f, 1.2278e+00f, 1.2278e+00f, 1.2278e+00f,
603 1.2278e+00f, 1.2278e+00f, 1.2278e+00f, 1.2278e+00f, 1.2278e+00f,
604 1.2278e+00f, 1.2278e+00f, 1.2278e+00f, 1.2278e+00f, 1.2278e+00f,
605 1.2278e+00f, 1.2278e+00f, 1.2278e+00f, 1.2278e+00f, 1.2278e+00f,
606 1.2278e+00f, 1.2278e+00f, 1.2278e+00f, 1.2278e+00f, 1.2278e+00f,
607 1.2278e+00f, 1.2278e+00f };
608 const float bibo_gains::gain_5x3_l[34] = { 1.0000e+00f, 1.5000e+00f,
609 1.6250e+00f, 1.6875e+00f, 1.6963e+00f, 1.7067e+00f, 1.7116e+00f,
610 1.7129e+00f, 1.7141e+00f, 1.7145e+00f, 1.7151e+00f, 1.7152e+00f,
611 1.7155e+00f, 1.7155e+00f, 1.7156e+00f, 1.7156e+00f, 1.7156e+00f,
612 1.7156e+00f, 1.7156e+00f, 1.7156e+00f, 1.7156e+00f, 1.7156e+00f,
613 1.7156e+00f, 1.7156e+00f, 1.7156e+00f, 1.7156e+00f, 1.7156e+00f,
614 1.7156e+00f, 1.7156e+00f, 1.7156e+00f, 1.7156e+00f, 1.7156e+00f,
615 1.7156e+00f, 1.7156e+00f };
616 const float bibo_gains::gain_5x3_h[34] = { 2.0000e+00f, 2.5000e+00f,
617 2.7500e+00f, 2.8047e+00f, 2.8198e+00f, 2.8410e+00f, 2.8558e+00f,
618 2.8601e+00f, 2.8628e+00f, 2.8656e+00f, 2.8662e+00f, 2.8667e+00f,
619 2.8669e+00f, 2.8670e+00f, 2.8671e+00f, 2.8671e+00f, 2.8671e+00f,
620 2.8671e+00f, 2.8671e+00f, 2.8671e+00f, 2.8671e+00f, 2.8671e+00f,
621 2.8671e+00f, 2.8671e+00f, 2.8671e+00f, 2.8671e+00f, 2.8671e+00f,
622 2.8671e+00f, 2.8671e+00f, 2.8671e+00f, 2.8671e+00f, 2.8671e+00f,
623 2.8671e+00f, 2.8671e+00f };
624
625
627 //
628 //
629 //
630 //
631 //
633
635 bool param_siz::write(outfile_base *file)
636 {
637 //marker size excluding header
638 Lsiz = (ui16)(38 + 3 * Csiz);
639
640 ui8 buf[4];
641 bool result = true;
642
643 *(ui16*)buf = JP2K_MARKER::SIZ;
644 *(ui16*)buf = swap_byte(*(ui16*)buf);
645 result &= file->write(&buf, 2) == 2;
646 *(ui16*)buf = swap_byte(Lsiz);
647 result &= file->write(&buf, 2) == 2;
648 *(ui16*)buf = swap_byte(Rsiz);
649 result &= file->write(&buf, 2) == 2;
650 *(ui32*)buf = swap_byte(Xsiz);
651 result &= file->write(&buf, 4) == 4;
652 *(ui32*)buf = swap_byte(Ysiz);
653 result &= file->write(&buf, 4) == 4;
654 *(ui32*)buf = swap_byte(XOsiz);
655 result &= file->write(&buf, 4) == 4;
656 *(ui32*)buf = swap_byte(YOsiz);
657 result &= file->write(&buf, 4) == 4;
658 *(ui32*)buf = swap_byte(XTsiz);
659 result &= file->write(&buf, 4) == 4;
660 *(ui32*)buf = swap_byte(YTsiz);
661 result &= file->write(&buf, 4) == 4;
662 *(ui32*)buf = swap_byte(XTOsiz);
663 result &= file->write(&buf, 4) == 4;
664 *(ui32*)buf = swap_byte(YTOsiz);
665 result &= file->write(&buf, 4) == 4;
666 *(ui16*)buf = swap_byte(Csiz);
667 result &= file->write(&buf, 2) == 2;
668 for (int c = 0; c < Csiz; ++c)
669 {
670 buf[0] = cptr[c].SSiz;
671 buf[1] = cptr[c].XRsiz;
672 buf[2] = cptr[c].YRsiz;
673 result &= file->write(&buf, 3) == 3;
674 }
675
676 return result;
677 }
678
680 void param_siz::read(infile_base *file)
681 {
682 if (file->read(&Lsiz, 2) != 2)
683 OJPH_ERROR(0x00050041, "error reading SIZ marker");
684 Lsiz = swap_byte(Lsiz);
685 int num_comps = (Lsiz - 38) / 3;
686 if (Lsiz != 38 + 3 * num_comps)
687 OJPH_ERROR(0x00050042, "error in SIZ marker length");
688 if (file->read(&Rsiz, 2) != 2)
689 OJPH_ERROR(0x00050043, "error reading SIZ marker");
690 Rsiz = swap_byte(Rsiz);
691 if ((Rsiz & 0x4000) == 0)
692 OJPH_ERROR(0x00050044,
693 "Rsiz bit 14 is not set (this is not a JPH file)");
694 if ((Rsiz & 0x8000) != 0 && (Rsiz & 0xD5F) != 0)
695 OJPH_WARN(0x00050001, "Rsiz in SIZ has unimplemented fields");
696 if (file->read(&Xsiz, 4) != 4)
697 OJPH_ERROR(0x00050045, "error reading SIZ marker");
698 Xsiz = swap_byte(Xsiz);
699 if (file->read(&Ysiz, 4) != 4)
700 OJPH_ERROR(0x00050046, "error reading SIZ marker");
701 Ysiz = swap_byte(Ysiz);
702 ui32 t_XOsiz, t_YOsiz;
703 if (file->read(&t_XOsiz, 4) != 4)
704 OJPH_ERROR(0x00050047, "error reading SIZ marker");
705 if (file->read(&t_YOsiz, 4) != 4)
706 OJPH_ERROR(0x00050048, "error reading SIZ marker");
707 set_image_offset(point(swap_byte(t_XOsiz), swap_byte(t_YOsiz)));
708 ui32 t_XTsiz, t_YTsiz;
709 if (file->read(&t_XTsiz, 4) != 4)
710 OJPH_ERROR(0x00050049, "error reading SIZ marker");
711 if (file->read(&t_YTsiz, 4) != 4)
712 OJPH_ERROR(0x0005004A, "error reading SIZ marker");
713 set_tile_size(size(swap_byte(t_XTsiz), swap_byte(t_YTsiz)));
714 ui32 t_XTOsiz, t_YTOsiz;
715 if (file->read(&t_XTOsiz, 4) != 4)
716 OJPH_ERROR(0x0005004B, "error reading SIZ marker");
717 if (file->read(&t_YTOsiz, 4) != 4)
718 OJPH_ERROR(0x0005004C, "error reading SIZ marker");
719 set_tile_offset(point(swap_byte(t_XTOsiz), swap_byte(t_YTOsiz)));
720 if (file->read(&Csiz, 2) != 2)
721 OJPH_ERROR(0x0005004D, "error reading SIZ marker");
722 Csiz = swap_byte(Csiz);
723 if (Csiz != num_comps)
724 OJPH_ERROR(0x0005004E, "Csiz does not match the SIZ marker size");
725 set_num_components(Csiz);
726 for (int c = 0; c < Csiz; ++c)
727 {
728 if (file->read(&cptr[c].SSiz, 1) != 1)
729 OJPH_ERROR(0x00050051, "error reading SIZ marker");
730 if (file->read(&cptr[c].XRsiz, 1) != 1)
731 OJPH_ERROR(0x00050052, "error reading SIZ marker");
732 if (file->read(&cptr[c].YRsiz, 1) != 1)
733 OJPH_ERROR(0x00050053, "error reading SIZ marker");
734 if ((cptr[c].SSiz & 0x7F) > 37)
735 OJPH_ERROR(0x00050054, "Wrong SIZ-SSiz value of %d", cptr[c].SSiz);
736 if (cptr[c].XRsiz == 0)
737 OJPH_ERROR(0x00050055, "Wrong SIZ-XRsiz value of %d", cptr[c].XRsiz);
738 if (cptr[c].YRsiz == 0)
739 OJPH_ERROR(0x00050056, "Wrong SIZ-YRsiz value of %d", cptr[c].YRsiz);
740 }
741
742 ws_kern_support_needed = (Rsiz & 0x20) != 0;
743 dfs_support_needed = (Rsiz & 0x80) != 0;
744
745 check_validity();
746 }
747
749 point param_siz::get_recon_downsampling(ui32 comp_num) const
750 {
751 assert(comp_num < get_num_components());
752
753 point factor(1u << skipped_resolutions, 1u << skipped_resolutions);
754 const param_cod* cdp = cod->get_coc(comp_num);
755 if (dfs && cdp && cdp->is_dfs_defined()) {
756 const param_dfs* d = dfs->get_dfs(cdp->get_dfs_index());
757 factor = d->get_res_downsamp(skipped_resolutions);
758 }
759 factor.x *= (ui32)cptr[comp_num].XRsiz;
760 factor.y *= (ui32)cptr[comp_num].YRsiz;
761 return factor;
762 }
763
765 point param_siz::get_recon_size(ui32 comp_num) const
766 {
767 assert(comp_num < get_num_components());
768
769 point factor = get_recon_downsampling(comp_num);
770 point r;
771 r.x = ojph_div_ceil(Xsiz, factor.x) - ojph_div_ceil(XOsiz, factor.x);
772 r.y = ojph_div_ceil(Ysiz, factor.y) - ojph_div_ceil(YOsiz, factor.y);
773 return r;
774 }
775
776
778 //
779 //
780 //
781 //
782 //
784
786 bool param_cap::write(outfile_base *file)
787 {
788 //marker size excluding header
789 Lcap = 8;
790
791 char buf[4];
792 bool result = true;
793
794 *(ui16*)buf = JP2K_MARKER::CAP;
795 *(ui16*)buf = swap_byte(*(ui16*)buf);
796 result &= file->write(&buf, 2) == 2;
797 *(ui16*)buf = swap_byte(Lcap);
798 result &= file->write(&buf, 2) == 2;
799 *(ui32*)buf = swap_byte(Pcap);
800 result &= file->write(&buf, 4) == 4;
801
802 *(ui16*)buf = swap_byte(Ccap[0]);
803 result &= file->write(&buf, 2) == 2;
804
805 return result;
806 }
807
809 void param_cap::read(infile_base *file)
810 {
811 if (file->read(&Lcap, 2) != 2)
812 OJPH_ERROR(0x00050061, "error reading CAP marker");
813 Lcap = swap_byte(Lcap);
814 if (file->read(&Pcap, 4) != 4)
815 OJPH_ERROR(0x00050062, "error reading CAP marker");
816 Pcap = swap_byte(Pcap);
817 ui32 count = population_count(Pcap);
818 if (Pcap & 0xFFFDFFFF)
819 OJPH_ERROR(0x00050063,
820 "error Pcap in CAP has options that are not supported");
821 if ((Pcap & 0x00020000) == 0)
822 OJPH_ERROR(0x00050064,
823 "error Pcap should have its 15th MSB set, Pcap^15. "
824 " This is not a JPH file");
825 for (ui32 i = 0; i < count; ++i)
826 if (file->read(Ccap+i, 2) != 2)
827 OJPH_ERROR(0x00050065, "error reading CAP marker");
828 if (Lcap != 6 + 2 * count)
829 OJPH_ERROR(0x00050066, "error in CAP marker length");
830 }
831
833 //
834 //
835 //
836 //
837 //
839
841 bool param_cod::is_reversible() const
842 {
843 if (SPcod.wavelet_trans <= 1)
844 return get_wavelet_kern() == local::param_cod::DWT_REV53;
845 else {
846 assert(atk != NULL);
847 return atk->is_reversible();
848 }
849 }
850
852 bool param_cod::write(outfile_base *file)
853 {
854 assert(type == COD_MAIN);
855
856 //marker size excluding header
857 Lcod = 12;
858 Lcod = (ui16)(Lcod + (Scod & 1 ? 1 + SPcod.num_decomp : 0));
859
860 ui8 buf[4];
861 bool result = true;
862
863 *(ui16*)buf = JP2K_MARKER::COD;
864 *(ui16*)buf = swap_byte(*(ui16*)buf);
865 result &= file->write(&buf, 2) == 2;
866 *(ui16*)buf = swap_byte(Lcod);
867 result &= file->write(&buf, 2) == 2;
868 *(ui8*)buf = Scod;
869 result &= file->write(&buf, 1) == 1;
870 *(ui8*)buf = SGCod.prog_order;
871 result &= file->write(&buf, 1) == 1;
872 *(ui16*)buf = swap_byte(SGCod.num_layers);
873 result &= file->write(&buf, 2) == 2;
874 *(ui8*)buf = SGCod.mc_trans;
875 result &= file->write(&buf, 1) == 1;
876 buf[0] = SPcod.num_decomp;
877 buf[1] = SPcod.block_width;
878 buf[2] = SPcod.block_height;
879 buf[3] = SPcod.block_style;
880 result &= file->write(&buf, 4) == 4;
881 *(ui8*)buf = SPcod.wavelet_trans;
882 result &= file->write(&buf, 1) == 1;
883 if (Scod & 1)
884 for (int i = 0; i <= SPcod.num_decomp; ++i)
885 {
886 *(ui8*)buf = SPcod.precinct_size[i];
887 result &= file->write(&buf, 1) == 1;
888 }
889
890 return result;
891 }
892
894 bool param_cod::write_coc(outfile_base *file, ui32 num_comps)
895 {
896 assert(type == COD_MAIN);
897 bool result = true;
898 param_cod *p = this->next;
899 while (p)
900 {
901 if (p->comp_idx < num_comps)
902 result &= p->internal_write_coc(file, num_comps);
903 p = p->next;
904 }
905 return result;
906 }
907
909 bool param_cod::internal_write_coc(outfile_base *file, ui32 num_comps)
910 {
911 assert(type == COC_MAIN);
912
913 //marker size excluding header
914 Lcod = num_comps < 257 ? 9 : 10;
915 Lcod = (ui16)(Lcod + (Scod & 1 ? 1 + SPcod.num_decomp : 0));
916
917 ui8 buf[4];
918 bool result = true;
919
920 *(ui16*)buf = JP2K_MARKER::COC;
921 *(ui16*)buf = swap_byte(*(ui16*)buf);
922 result &= file->write(&buf, 2) == 2;
923 *(ui16*)buf = swap_byte(Lcod);
924 result &= file->write(&buf, 2) == 2;
925 if (num_comps < 257)
926 {
927 *(ui8*)buf = (ui8)comp_idx;
928 result &= file->write(&buf, 1) == 1;
929 }
930 else
931 {
932 *(ui16*)buf = swap_byte(comp_idx);
933 result &= file->write(&buf, 2) == 2;
934 }
935 *(ui8*)buf = Scod;
936 result &= file->write(&buf, 1) == 1;
937 buf[0] = SPcod.num_decomp;
938 buf[1] = SPcod.block_width;
939 buf[2] = SPcod.block_height;
940 buf[3] = SPcod.block_style;
941 result &= file->write(&buf, 4) == 4;
942 *(ui8*)buf = SPcod.wavelet_trans;
943 result &= file->write(&buf, 1) == 1;
944 if (Scod & 1)
945 for (int i = 0; i <= SPcod.num_decomp; ++i)
946 {
947 *(ui8*)buf = SPcod.precinct_size[i];
948 result &= file->write(&buf, 1) == 1;
949 }
950
951 return result;
952 }
953
955 void param_cod::read(infile_base *file)
956 {
957 assert(type == COD_MAIN);
958
959 if (file->read(&Lcod, 2) != 2)
960 OJPH_ERROR(0x00050071, "error reading COD segment");
961 Lcod = swap_byte(Lcod);
962 if (file->read(&Scod, 1) != 1)
963 OJPH_ERROR(0x00050072, "error reading COD segment");
964 if (file->read(&SGCod.prog_order, 1) != 1)
965 OJPH_ERROR(0x00050073, "error reading COD segment");
966 if (file->read(&SGCod.num_layers, 2) != 2)
967 { OJPH_ERROR(0x00050074, "error reading COD segment"); }
968 else
969 SGCod.num_layers = swap_byte(SGCod.num_layers);
970 if (file->read(&SGCod.mc_trans, 1) != 1)
971 OJPH_ERROR(0x00050075, "error reading COD segment");
972 if (file->read(&SPcod.num_decomp, 1) != 1)
973 OJPH_ERROR(0x00050076, "error reading COD segment");
974 if (file->read(&SPcod.block_width, 1) != 1)
975 OJPH_ERROR(0x00050077, "error reading COD segment");
976 if (file->read(&SPcod.block_height, 1) != 1)
977 OJPH_ERROR(0x00050078, "error reading COD segment");
978 if (file->read(&SPcod.block_style, 1) != 1)
979 OJPH_ERROR(0x00050079, "error reading COD segment");
980 if (file->read(&SPcod.wavelet_trans, 1) != 1)
981 OJPH_ERROR(0x0005007A, "error reading COD segment");
982
983 if (get_num_decompositions() > 32
984 || SPcod.block_width > 8
985 || SPcod.block_height > 8
986 || SPcod.block_width + SPcod.block_height > 8
987 || (SPcod.block_style & 0x40) != 0x40
988 || (SPcod.block_style & 0xB7) != 0x00)
989 OJPH_ERROR(0x0005007D, "wrong settings in a COD-SPcod parameter");
990 if ((SPcod.block_style & 0x40) != 0x40
991 || (SPcod.block_style & 0xB7) != 0x00)
992 OJPH_ERROR(0x0005007E, "unsupported settings in a COD-SPcod parameter");
993
994 ui8 num_decompositions = get_num_decompositions();
995 if (Scod & 1)
996 for (int i = 0; i <= num_decompositions; ++i)
997 if (file->read(&SPcod.precinct_size[i], 1) != 1)
998 OJPH_ERROR(0x0005007B, "error reading COD segment");
999 if (Lcod != 12 + ((Scod & 1) ? 1 + SPcod.num_decomp : 0))
1000 OJPH_ERROR(0x0005007C, "error in COD segment length");
1001 }
1002
1004 void param_cod::read_coc(infile_base* file, ui32 num_comps,
1005 param_cod *top_cod)
1006 {
1007 assert(type == COC_MAIN);
1008 assert(top_cod != NULL);
1009
1010 this->SGCod = top_cod->SGCod;
1011 this->top_cod = top_cod;
1012 if (file->read(&Lcod, 2) != 2)
1013 OJPH_ERROR(0x00050121, "error reading COC segment");
1014 Lcod = swap_byte(Lcod);
1015 if (num_comps < 257) {
1016 ui8 t;
1017 if (file->read(&t, 1) != 1)
1018 OJPH_ERROR(0x00050122, "error reading COC segment");
1019 comp_idx = t;
1020 }
1021 else {
1022 if (file->read(&comp_idx, 2) != 2)
1023 OJPH_ERROR(0x00050123, "error reading COC segment");
1024 comp_idx = swap_byte(comp_idx);
1025 }
1026 if (file->read(&Scod, 1) != 1)
1027 OJPH_ERROR(0x00050124, "error reading COC segment");
1028 if (Scod & 0xF8)
1029 OJPH_WARN(0x00050011,
1030 "Unsupported options in Scoc field of the COC segment");
1031 if (file->read(&SPcod.num_decomp, 1) != 1)
1032 OJPH_ERROR(0x00050125, "error reading COC segment");
1033 if (file->read(&SPcod.block_width, 1) != 1)
1034 OJPH_ERROR(0x00050126, "error reading COC segment");
1035 if (file->read(&SPcod.block_height, 1) != 1)
1036 OJPH_ERROR(0x00050127, "error reading COC segment");
1037 if (file->read(&SPcod.block_style, 1) != 1)
1038 OJPH_ERROR(0x00050128, "error reading COC segment");
1039 if (file->read(&SPcod.wavelet_trans, 1) != 1)
1040 OJPH_ERROR(0x00050129, "error reading COC segment");
1041
1042 if (get_num_decompositions() > 32
1043 || SPcod.block_width > 8
1044 || SPcod.block_height > 8
1045 || SPcod.block_width + SPcod.block_height > 8
1046 || (SPcod.block_style & 0x40) != 0x40
1047 || (SPcod.block_style & 0xB7) != 0x00)
1048 OJPH_ERROR(0x0005012C, "wrong settings in a COC-SPcoc parameter");
1049 if ((SPcod.block_style & 0x40) != 0x40
1050 || (SPcod.block_style & 0xB7) != 0x00)
1051 OJPH_ERROR(0x0005012D, "unsupported settings in a COC-SPcoc parameter");
1052
1053 ui8 num_decompositions = get_num_decompositions();
1054 if (Scod & 1)
1055 for (int i = 0; i <= num_decompositions; ++i)
1056 if (file->read(&SPcod.precinct_size[i], 1) != 1)
1057 OJPH_ERROR(0x0005012A, "error reading COC segment");
1058 ui32 t = 9;
1059 t += num_comps < 257 ? 0 : 1;
1060 t += (Scod & 1) ? 1 + num_decompositions : 0;
1061 if (Lcod != t)
1062 OJPH_ERROR(0x0005012B, "error in COC segment length");
1063 }
1064
1066 void param_cod::update_atk(param_atk* atk)
1067 {
1068 assert(type == COD_MAIN);
1069 this->atk = atk->get_atk(SPcod.wavelet_trans);
1070 if (this->atk == NULL)
1071 OJPH_ERROR(0x00050131, "A COD segment employs the DWT kernel "
1072 "atk = %d, but a corresponding ATK segment cannot be found.",
1073 SPcod.wavelet_trans);
1074 param_cod *p = next;
1075 while (p)
1076 {
1077 p->atk = atk->get_atk(p->SPcod.wavelet_trans);
1078 if (p->atk == NULL)
1079 OJPH_ERROR(0x00050132, "A COC segment employs the DWT kernel "
1080 "atk = %d, but a corresponding ATK segment cannot be found",
1081 SPcod.wavelet_trans);
1082 p = p->next;
1083 }
1084 }
1085
1087 const param_cod* param_cod::get_coc(ui32 comp_idx) const
1088 {
1089 assert(this->type == COD_MAIN || this->top_cod->type == COD_MAIN);
1090 const param_cod *p, *q;
1091 if (this->type == COD_MAIN)
1092 q = p = this;
1093 else
1094 q = p = this->top_cod;
1095 while (p && p->comp_idx != comp_idx)
1096 p = p->next;
1097 return p ? p : q;
1098 }
1099
1101 param_cod* param_cod::get_coc(ui32 comp_idx)
1102 {
1103 // cast object to constant
1104 const param_cod* const_p = const_cast<const param_cod*>(this);
1105 // call using the constant object, then cast to non-const
1106 return const_cast<param_cod*>(const_p->get_coc(comp_idx));
1107 }
1108
1110 param_cod* param_cod::add_coc_object(ui32 comp_idx)
1111 {
1112 assert(type == COD_MAIN);
1113 param_cod *p = this;
1114 while (p->next != NULL)
1115 p = p->next;
1116 if (avail)
1117 {
1118 p->next = avail;
1119 avail = avail->next;
1120 p->next->init(this, (ui16)comp_idx);
1121 }
1122 else
1123 p->next = new param_cod(this, (ui16)comp_idx);
1124 return p->next;
1125 }
1126
1128 //
1129 //
1130 //
1131 //
1132 //
1134
1136 void param_qcd::check_validity(const param_siz& siz, const param_cod& cod)
1137 {
1138 ui32 num_comps = siz.get_num_components();
1139 trim_non_existing_components(num_comps);
1140
1141 // first check that all the component captured by QCD have the same
1142 // bit_depth and signedness
1143 bool all_same = true;
1144 bool other_comps_exist = false;
1145 ui32 first_comp = 0xFFFF; // an impossible component
1146 {
1147 ui32 num_decompositions = 0;
1148 ui32 bit_depth = 0;
1149 bool is_signed = false;
1150 ui32 wavelet_kern = param_cod::DWT_IRV97;
1151
1152 for (ui32 c = 0; c < num_comps; ++c)
1153 {
1154 if (get_qcc(c) == this) // no qcc defined for component c
1155 {
1156 const param_cod *p = cod.get_coc(c);
1157 if (bit_depth == 0) // first component captured by QCD
1158 {
1159 num_decompositions = p->get_num_decompositions();
1160 bit_depth = siz.get_bit_depth(c);
1161 is_signed = siz.is_signed(c);
1162 wavelet_kern = p->get_wavelet_kern();
1163 first_comp = c;
1164 }
1165 else
1166 {
1167 all_same = all_same
1168 && (num_decompositions == p->get_num_decompositions())
1169 && (bit_depth == siz.get_bit_depth(c))
1170 && (is_signed == siz.is_signed(c))
1171 && (wavelet_kern == p->get_wavelet_kern());
1172 }
1173 }
1174 else
1175 other_comps_exist = true;
1176 }
1177 }
1178
1179 // configure QCD according COD
1180 ui32 qcd_num_decompositions;
1181 ui32 qcd_bit_depth;
1182 bool qcd_is_signed;
1183 ui32 qcd_wavelet_kern;
1184 {
1185 ui32 qcd_component = first_comp != 0xFFFF ? first_comp : 0;
1186 bool employing_color_transform = cod.is_employing_color_transform();
1187 qcd_num_decompositions = cod.get_num_decompositions();
1188 qcd_bit_depth = siz.get_bit_depth(qcd_component);
1189 qcd_is_signed = siz.is_signed(qcd_component);
1190 qcd_wavelet_kern = cod.get_wavelet_kern();
1191 this->num_subbands = 1 + 3 * qcd_num_decompositions;
1192 if (qcd_wavelet_kern == param_cod::DWT_REV53)
1193 set_rev_quant(qcd_num_decompositions, qcd_bit_depth,
1194 qcd_component < 3 ? employing_color_transform : false);
1195 else if (qcd_wavelet_kern == param_cod::DWT_IRV97)
1196 {
1197 if (this->base_delta == -1.0f)
1198 this->base_delta = 1.0f / (float)(1 << qcd_bit_depth);
1199 set_irrev_quant(qcd_num_decompositions);
1200 }
1201 else
1202 assert(0);
1203 }
1204
1205 // if not all the same and captured by QCD, then create QCC for them
1206 if (!all_same)
1207 {
1208 bool employing_color_transform = cod.is_employing_color_transform();
1209 for (ui32 c = 0; c < num_comps; ++c)
1210 {
1211 const param_cod *cp = cod.get_coc(c);
1212 if (qcd_num_decompositions == cp->get_num_decompositions()
1213 && qcd_bit_depth == siz.get_bit_depth(c)
1214 && qcd_is_signed == siz.is_signed(c)
1215 && qcd_wavelet_kern == cp->get_wavelet_kern())
1216 continue; // captured by QCD
1217
1218 // Does not match QCD, must have QCC
1219 param_qcd *qp = get_qcc(c);
1220 if (qp == this) // no QCC was defined, create QCC
1221 qp = this->add_qcc_object(c);
1222
1223 ui32 num_decompositions = cp->get_num_decompositions();
1224 qp->num_subbands = 1 + 3 * num_decompositions;
1225 ui32 bit_depth = siz.get_bit_depth(c);
1226 if (cp->get_wavelet_kern() == param_cod::DWT_REV53)
1227 qp->set_rev_quant(num_decompositions, bit_depth,
1228 c < 3 ? employing_color_transform : false);
1229 else if (cp->get_wavelet_kern() == param_cod::DWT_IRV97)
1230 {
1231 if (qp->base_delta == -1.0f)
1232 qp->base_delta = 1.0f / (float)(1 << bit_depth);
1233 qp->set_irrev_quant(num_decompositions);
1234 }
1235 else
1236 assert(0);
1237 }
1238 }
1239 else if (other_comps_exist) // Some are captured by QCD
1240 {
1241 bool employing_color_transform = cod.is_employing_color_transform();
1242 for (ui32 c = 0; c < num_comps; ++c)
1243 {
1244 param_qcd *qp = get_qcc(c);
1245 if (qp == this) // if captured by QCD continue
1246 continue;
1247 const param_cod *cp = cod.get_coc(c);
1248 ui32 num_decompositions = cp->get_num_decompositions();
1249 qp->num_subbands = 1 + 3 * num_decompositions;
1250 ui32 bit_depth = siz.get_bit_depth(c);
1251 if (cp->get_wavelet_kern() == param_cod::DWT_REV53)
1252 qp->set_rev_quant(num_decompositions, bit_depth,
1253 c < 3 ? employing_color_transform : false);
1254 else if (cp->get_wavelet_kern() == param_cod::DWT_IRV97)
1255 {
1256 if (qp->base_delta == -1.0f)
1257 qp->base_delta = 1.0f / (float)(1 << bit_depth);
1258 qp->set_irrev_quant(num_decompositions);
1259 }
1260 else
1261 assert(0);
1262 }
1263 }
1264 }
1265
1267 void param_qcd::set_delta(ui32 comp_idx, float delta)
1268 {
1269 assert(type == QCD_MAIN);
1270 param_qcd *p = get_qcc(comp_idx);
1271 if (p == NULL)
1272 p = add_qcc_object(comp_idx);
1273 p->set_delta(delta);
1274 }
1275
1277 void param_qcd::set_rev_quant(ui32 num_decomps, ui32 bit_depth,
1278 bool is_employing_color_transform)
1279 {
1280 ui32 B = bit_depth;
1281 B += is_employing_color_transform ? 1 : 0; //1 bit for RCT
1282 int s = 0;
1283 double bibo_l = bibo_gains::get_bibo_gain_l(num_decomps, true);
1284 ui32 X = (ui32) ceil(log(bibo_l * bibo_l) / M_LN2);
1285 SPqcd.u8[s++] = (ui8)(B + X);
1286 ui32 max_B_plus_X = (ui32)(B + X);
1287 for (ui32 d = num_decomps; d > 0; --d)
1288 {
1289 double bibo_l = bibo_gains::get_bibo_gain_l(d, true);
1290 double bibo_h = bibo_gains::get_bibo_gain_h(d - 1, true);
1291 X = (ui32) ceil(log(bibo_h * bibo_l) / M_LN2);
1292 SPqcd.u8[s++] = (ui8)(B + X);
1293 max_B_plus_X = ojph_max(max_B_plus_X, B + X);
1294 SPqcd.u8[s++] = (ui8)(B + X);
1295 max_B_plus_X = ojph_max(max_B_plus_X, B + X);
1296 X = (ui32) ceil(log(bibo_h * bibo_h) / M_LN2);
1297 SPqcd.u8[s++] = (ui8)(B + X);
1298 max_B_plus_X = ojph_max(max_B_plus_X, B + X);
1299 }
1300
1301 if (max_B_plus_X > 38)
1302 OJPH_ERROR(0x00050151, "The specified combination of bit_depth, "
1303 "colour transform, and type of wavelet transform requires more than "
1304 "38 bits; it requires %d bits. This is beyond what is allowed in "
1305 "the JPEG2000 image coding format.", max_B_plus_X);
1306
1307 int guard_bits = ojph_max(1, (si32)max_B_plus_X - 31);
1308 Sqcd = (ui8)(guard_bits << 5);
1309 s = 0;
1310 SPqcd.u8[s] = encode_SPqcd((ui8)(SPqcd.u8[s] - guard_bits));
1311 s++;
1312 for (ui32 d = num_decomps; d > 0; --d)
1313 {
1314 SPqcd.u8[s] = encode_SPqcd((ui8)(SPqcd.u8[s] - guard_bits));
1315 s++;
1316 SPqcd.u8[s] = encode_SPqcd((ui8)(SPqcd.u8[s] - guard_bits));
1317 s++;
1318 SPqcd.u8[s] = encode_SPqcd((ui8)(SPqcd.u8[s] - guard_bits));
1319 s++;
1320 }
1321 }
1322
1324 void param_qcd::set_irrev_quant(ui32 num_decomps)
1325 {
1326 int guard_bits = 1;
1327 Sqcd = (ui8)((guard_bits<<5)|0x2);//one guard bit, scalar quantization
1328 int s = 0;
1329 float gain_l = sqrt_energy_gains::get_gain_l(num_decomps, false);
1330 float delta_b = base_delta / (gain_l * gain_l);
1331 int exp = 0, mantissa;
1332 while (delta_b < 1.0f)
1333 { exp++; delta_b *= 2.0f; }
1334 //with rounding, there is a risk of becoming equal to 1<<12
1335 // but that should not happen in reality
1336 mantissa = (int)round(delta_b * (float)(1<<11)) - (1<<11);
1337 mantissa = mantissa < (1<<11) ? mantissa : 0x7FF;
1338 SPqcd.u16[s++] = (ui16)((exp << 11) | mantissa);
1339 for (ui32 d = num_decomps; d > 0; --d)
1340 {
1341 float gain_l = sqrt_energy_gains::get_gain_l(d, false);
1342 float gain_h = sqrt_energy_gains::get_gain_h(d - 1, false);
1343
1344 delta_b = base_delta / (gain_l * gain_h);
1345
1346 int exp = 0, mantissa;
1347 while (delta_b < 1.0f)
1348 { exp++; delta_b *= 2.0f; }
1349 mantissa = (int)round(delta_b * (float)(1<<11)) - (1<<11);
1350 mantissa = mantissa < (1<<11) ? mantissa : 0x7FF;
1351 SPqcd.u16[s++] = (ui16)((exp << 11) | mantissa);
1352 SPqcd.u16[s++] = (ui16)((exp << 11) | mantissa);
1353
1354 delta_b = base_delta / (gain_h * gain_h);
1355
1356 exp = 0;
1357 while (delta_b < 1)
1358 { exp++; delta_b *= 2.0f; }
1359 mantissa = (int)round(delta_b * (float)(1<<11)) - (1<<11);
1360 mantissa = mantissa < (1<<11) ? mantissa : 0x7FF;
1361 SPqcd.u16[s++] = (ui16)((exp << 11) | mantissa);
1362 }
1363 }
1364
1366 ui32 param_qcd::get_MAGB() const
1367 {
1368 ui32 B = 0;
1369
1370 const param_qcd *p = this;
1371 while (p)
1372 {
1373 //this can be written better, but it is only executed once
1374 // this assumes a bi-directional wavelet (conventional DWT)
1375 ui32 num_decomps = (p->num_subbands - 1) / 3;
1376
1377 int irrev = p->Sqcd & 0x1F;
1378 if (irrev == 0) //reversible
1379 for (ui32 i = 0; i < p->num_subbands; ++i) {
1380 ui32 t = p->decode_SPqcd(p->SPqcd.u8[i]);
1381 t += p->get_num_guard_bits() - 1u;
1382 B = ojph_max(B, t);
1383 }
1384 else if (irrev == 2) //scalar expounded
1385 for (ui32 i = 0; i < p->num_subbands; ++i)
1386 {
1387 ui32 nb = num_decomps - (i ? (i - 1) / 3 : 0); //decompsition level
1388 ui32 t = (p->SPqcd.u16[i] >> 11) + p->get_num_guard_bits() - nb;
1389 B = ojph_max(B, t);
1390 }
1391 else
1392 assert(0);
1393
1394 p = p->next;
1395 }
1396
1397 return B;
1398 }
1399
1401 float param_qcd::get_irrev_delta(const param_dfs* dfs,
1402 ui32 num_decompositions,
1403 ui32 resolution, ui32 subband) const
1404 {
1405 float arr[] = { 1.0f, 2.0f, 2.0f, 4.0f };
1406 assert((Sqcd & 0x1F) == 2);
1407
1408 ui32 idx;
1409 if (dfs != NULL && dfs->exists())
1410 idx = dfs->get_subband_idx(num_decompositions, resolution, subband);
1411 else
1412 idx = resolution ? (resolution - 1) * 3 + subband : 0;
1413 if (idx >= num_subbands) {
1414 OJPH_INFO(0x00050101, "Trying to access quantization step size for "
1415 "subband %d when the QCD/QCC marker segment specifies "
1416 "quantization step sizes for %d subbands only. To continue "
1417 "decoding, we are using the step size for subband %d, which can "
1418 "produce incorrect results",
1419 idx + 1, num_subbands, num_subbands - 1);
1420 idx = num_subbands - 1;
1421 }
1422 int eps = SPqcd.u16[idx] >> 11;
1423 float mantissa;
1424 mantissa = (float)((SPqcd.u16[idx] & 0x7FF) | 0x800) * arr[subband];
1425 mantissa /= (float)(1 << 11);
1426 mantissa /= (float)(1u << eps);
1427 return mantissa;
1428 }
1429
1431 ui32 param_qcd::propose_precision(const param_cod* cod) const
1432 {
1433 ui32 comp_idx = cod->get_comp_idx();
1434 ui32 precision = 0;
1435 const param_cod *main =
1436 cod->get_coc(param_cod::OJPH_COD_DEFAULT);
1437 if (main->is_employing_color_transform() && comp_idx < 3)
1438 {
1439 for (ui32 i = 0; i < 3; ++i) {
1440 const param_qcd* p = this->get_qcc(i);
1441 precision = ojph_max(precision, p->get_largest_Kmax());
1442 }
1443 }
1444 else {
1445 precision = get_largest_Kmax();
1446 }
1447 // ``precision'' now holds the largest K_max, which excludes the sign
1448 // bit.
1449 // + 1 for the sign bit
1450 // + 1 because my block decoder/encoder does not supports up to 30
1451 // bits (not 31), so we bump it by one more bit.
1452 return precision + 1 + 1;
1453 }
1454
1456 ui32 param_qcd::get_num_guard_bits() const
1457 {
1458 return (Sqcd >> 5);
1459 }
1460
1462 ui32 param_qcd::get_Kmax(const param_dfs* dfs, ui32 num_decompositions,
1463 ui32 resolution, ui32 subband) const
1464 {
1465 ui32 idx;
1466 if (dfs != NULL && dfs->exists())
1467 idx = dfs->get_subband_idx(num_decompositions, resolution, subband);
1468 else
1469 idx = resolution ? (resolution - 1) * 3 + subband : 0;
1470 if (idx >= num_subbands) {
1471 OJPH_INFO(0x00050111, "Trying to access quantization step size for "
1472 "subband %d when the QCD/QCC marker segment specifies "
1473 "quantization step sizes for %d subbands only. To continue "
1474 "decoding, we are using the step size for subband %d, which can "
1475 "produce incorrect results",
1476 idx + 1, num_subbands, num_subbands - 1);
1477 idx = num_subbands - 1;
1478 }
1479
1480 int irrev = Sqcd & 0x1F;
1481 ui32 num_bits = 0;
1482 if (irrev == 0) // reversible; this is (10.22) from the J2K book
1483 {
1484 num_bits = decode_SPqcd(SPqcd.u8[idx]);
1485 num_bits = num_bits == 0 ? 0 : num_bits - 1;
1486 }
1487 else if (irrev == 1)
1488 assert(0);
1489 else if (irrev == 2) //scalar expounded
1490 num_bits = (SPqcd.u16[idx] >> 11) - 1;
1491 else
1492 assert(0);
1493
1494 return num_bits + get_num_guard_bits();
1495 }
1496
1498 ui32 param_qcd::get_largest_Kmax() const
1499 {
1500 int irrev = Sqcd & 0x1F;
1501 ui32 num_bits = 0;
1502 if (irrev == 0) // reversible; this is (10.22) from the J2K book
1503 {
1504 for (ui32 i = 0; i < num_subbands; ++i) {
1505 ui32 t = decode_SPqcd(SPqcd.u8[i]);
1506 num_bits = ojph_max(num_bits, t == 0 ? 0 : t - 1);
1507 }
1508 }
1509 else if (irrev == 1)
1510 assert(0);
1511 else if (irrev == 2) //scalar expounded
1512 {
1513 for (ui32 i = 0; i < num_subbands; ++i) {
1514 ui32 t = (SPqcd.u16[i] >> 11) - 1;
1515 num_bits = ojph_max(num_bits, t);
1516 }
1517 }
1518 else
1519 assert(0);
1520
1521 return num_bits + get_num_guard_bits();
1522 }
1523
1525 bool param_qcd::write(outfile_base *file)
1526 {
1527 int irrev = Sqcd & 0x1F;
1528
1529 //marker size excluding header
1530 Lqcd = 3;
1531 if (irrev == 0)
1532 Lqcd = (ui16)(Lqcd + num_subbands);
1533 else if (irrev == 2)
1534 Lqcd = (ui16)(Lqcd + 2 * num_subbands);
1535 else
1536 assert(0);
1537
1538 char buf[4];
1539 bool result = true;
1540
1541 *(ui16*)buf = JP2K_MARKER::QCD;
1542 *(ui16*)buf = swap_byte(*(ui16*)buf);
1543 result &= file->write(&buf, 2) == 2;
1544 *(ui16*)buf = swap_byte(Lqcd);
1545 result &= file->write(&buf, 2) == 2;
1546 *(ui8*)buf = Sqcd;
1547 result &= file->write(&buf, 1) == 1;
1548
1549 if (irrev == 0)
1550 for (ui32 i = 0; i < num_subbands; ++i)
1551 {
1552 *(ui8*)buf = SPqcd.u8[i];
1553 result &= file->write(&buf, 1) == 1;
1554 }
1555 else if (irrev == 2)
1556 for (ui32 i = 0; i < num_subbands; ++i)
1557 {
1558 *(ui16*)buf = swap_byte(SPqcd.u16[i]);
1559 result &= file->write(&buf, 2) == 2;
1560 }
1561 else
1562 assert(0);
1563
1564 return result;
1565 }
1566
1568 bool param_qcd::write_qcc(outfile_base *file, ui32 num_comps)
1569 {
1570 assert(type == QCD_MAIN);
1571 bool result = true;
1572 param_qcd *p = this->next;
1573 while (p)
1574 {
1575 if (p->enabled)
1576 result &= p->internal_write_qcc(file, num_comps);
1577 p = p->next;
1578 }
1579 return result;
1580 }
1581
1583 bool param_qcd::internal_write_qcc(outfile_base *file, ui32 num_comps)
1584 {
1585 int irrev = Sqcd & 0x1F;
1586
1587 //marker size excluding header
1588 Lqcd = (ui16)(4 + (num_comps < 257 ? 0 : 1));
1589 if (irrev == 0)
1590 Lqcd = (ui16)(Lqcd + num_subbands);
1591 else if (irrev == 2)
1592 Lqcd = (ui16)(Lqcd + 2 * num_subbands);
1593 else
1594 assert(0);
1595
1596 char buf[4];
1597 bool result = true;
1598
1599 *(ui16*)buf = JP2K_MARKER::QCC;
1600 *(ui16*)buf = swap_byte(*(ui16*)buf);
1601 result &= file->write(&buf, 2) == 2;
1602 *(ui16*)buf = swap_byte(Lqcd);
1603 result &= file->write(&buf, 2) == 2;
1604 if (num_comps < 257)
1605 {
1606 *(ui8*)buf = (ui8)comp_idx;
1607 result &= file->write(&buf, 1) == 1;
1608 }
1609 else
1610 {
1611 *(ui16*)buf = swap_byte(comp_idx);
1612 result &= file->write(&buf, 2) == 2;
1613 }
1614 *(ui8*)buf = Sqcd;
1615 result &= file->write(&buf, 1) == 1;
1616 if (irrev == 0)
1617 for (ui32 i = 0; i < num_subbands; ++i)
1618 {
1619 *(ui8*)buf = SPqcd.u8[i];
1620 result &= file->write(&buf, 1) == 1;
1621 }
1622 else if (irrev == 2)
1623 for (ui32 i = 0; i < num_subbands; ++i)
1624 {
1625 *(ui16*)buf = swap_byte(SPqcd.u16[i]);
1626 result &= file->write(&buf, 2) == 2;
1627 }
1628 else
1629 assert(0);
1630
1631 return result;
1632 }
1633
1635 void param_qcd::trim_non_existing_components(ui32 num_comps)
1636 {
1637 assert(type == QCD_MAIN && comp_idx == OJPH_QCD_DEFAULT);
1638 param_qcd *p = this->next;
1639 while (p)
1640 {
1641 assert(p->type == QCC_MAIN);
1642 p->enabled = p->comp_idx < num_comps;
1643 p = p->next;
1644 }
1645 }
1646
1648 void param_qcd::read(infile_base *file)
1649 {
1650 if (file->read(&Lqcd, 2) != 2)
1651 OJPH_ERROR(0x00050081, "error reading QCD marker");
1652 Lqcd = swap_byte(Lqcd);
1653 if (file->read(&Sqcd, 1) != 1)
1654 OJPH_ERROR(0x00050082, "error reading QCD marker");
1655 if ((Sqcd & 0x1F) == 0)
1656 {
1657 num_subbands = (Lqcd - 3);
1658 if (num_subbands == 0)
1659 OJPH_ERROR(0x0005008A, "QCD marker segment that specifies no "
1660 "quantization informtion");
1661 if (num_subbands > 97 || Lqcd != 3 + num_subbands)
1662 OJPH_ERROR(0x00050083, "wrong Lqcd value of %d in QCD marker", Lqcd);
1663 for (ui32 i = 0; i < num_subbands; ++i)
1664 if (file->read(&SPqcd.u8[i], 1) != 1)
1665 OJPH_ERROR(0x00050084, "error reading QCD marker");
1666 }
1667 else if ((Sqcd & 0x1F) == 1)
1668 {
1669 num_subbands = 0;
1670 OJPH_ERROR(0x00050089,
1671 "Scalar derived quantization is not supported yet in QCD marker");
1672 if (Lqcd != 5)
1673 OJPH_ERROR(0x00050085, "wrong Lqcd value in QCD marker");
1674 }
1675 else if ((Sqcd & 0x1F) == 2)
1676 {
1677 num_subbands = (Lqcd - 3) / 2;
1678 if (num_subbands == 0)
1679 OJPH_ERROR(0x0005008B, "QCD marker segment that specifies no "
1680 "quantization informtion");
1681 if (num_subbands > 97 || Lqcd != 3 + 2 * num_subbands)
1682 OJPH_ERROR(0x00050086, "wrong Lqcd value of %d in QCD marker", Lqcd);
1683 for (ui32 i = 0; i < num_subbands; ++i)
1684 {
1685 if (file->read(&SPqcd.u16[i], 2) != 2)
1686 OJPH_ERROR(0x00050087, "error reading QCD marker");
1687 SPqcd.u16[i] = swap_byte(SPqcd.u16[i]);
1688 }
1689 }
1690 else
1691 OJPH_ERROR(0x00050088, "wrong Sqcd value in QCD marker");
1692 }
1693
1695 void param_qcd::read_qcc(infile_base *file, ui32 num_comps)
1696 {
1697 if (file->read(&Lqcd, 2) != 2)
1698 OJPH_ERROR(0x000500A1, "error reading QCC marker");
1699 Lqcd = swap_byte(Lqcd);
1700 if (num_comps < 257)
1701 {
1702 ui8 v;
1703 if (file->read(&v, 1) != 1)
1704 OJPH_ERROR(0x000500A2, "error reading QCC marker");
1705 comp_idx = v;
1706 }
1707 else
1708 {
1709 if (file->read(&comp_idx, 2) != 2)
1710 OJPH_ERROR(0x000500A3, "error reading QCC marker");
1711 comp_idx = swap_byte(comp_idx);
1712 }
1713 if (file->read(&Sqcd, 1) != 1)
1714 OJPH_ERROR(0x000500A4, "error reading QCC marker");
1715 ui32 offset = num_comps < 257 ? 4 : 5;
1716 if ((Sqcd & 0x1F) == 0)
1717 {
1718 num_subbands = (Lqcd - offset);
1719 if (num_subbands == 0)
1720 OJPH_ERROR(0x000500AC, "QCC marker segment that specifies no "
1721 "quantization informtion");
1722 if (num_subbands > 97 || Lqcd != offset + num_subbands)
1723 OJPH_ERROR(0x000500A5, "wrong Lqcd value of %d in QCC marker", Lqcd);
1724 for (ui32 i = 0; i < num_subbands; ++i)
1725 if (file->read(&SPqcd.u8[i], 1) != 1)
1726 OJPH_ERROR(0x000500A6, "error reading QCC marker");
1727 }
1728 else if ((Sqcd & 0x1F) == 1)
1729 {
1730 num_subbands = 0;
1731 OJPH_ERROR(0x000500AB,
1732 "Scalar derived quantization is not supported yet in QCC marker");
1733 if (Lqcd != offset)
1734 OJPH_ERROR(0x000500A7, "wrong Lqcc value in QCC marker");
1735 }
1736 else if ((Sqcd & 0x1F) == 2)
1737 {
1738 num_subbands = (Lqcd - offset) / 2;
1739 if (num_subbands == 0)
1740 OJPH_ERROR(0x000500AD, "QCC marker segment that specifies no "
1741 "quantization informtion");
1742 if (num_subbands > 97 || Lqcd != offset + 2 * num_subbands)
1743 OJPH_ERROR(0x000500A8, "wrong Lqcc value of %d in QCC marker", Lqcd);
1744 for (ui32 i = 0; i < num_subbands; ++i)
1745 {
1746 if (file->read(&SPqcd.u16[i], 2) != 2)
1747 OJPH_ERROR(0x000500A9, "error reading QCC marker");
1748 SPqcd.u16[i] = swap_byte(SPqcd.u16[i]);
1749 }
1750 }
1751 else
1752 OJPH_ERROR(0x000500AA, "wrong Sqcc value in QCC marker");
1753 }
1754
1756 param_qcd* param_qcd::get_qcc(ui32 comp_idx)
1757 {
1758 // cast object to constant
1759 const param_qcd* const_p = const_cast<const param_qcd*>(this);
1760 // call using the constant object, then cast to non-const
1761 return const_cast<param_qcd*>(const_p->get_qcc(comp_idx));
1762 }
1763
1765 const param_qcd* param_qcd::get_qcc(ui32 comp_idx) const
1766 {
1767 assert(this->type == QCD_MAIN || this->top_qcd->type == QCD_MAIN);
1768 const param_qcd *p, *q;
1769 if (this->type == QCD_MAIN)
1770 q = p = this;
1771 else
1772 q = p = this->top_qcd;
1773 while (p && p->comp_idx != comp_idx)
1774 p = p->next;
1775 return p ? p : q;
1776 }
1777
1779 param_qcd* param_qcd::add_qcc_object(ui32 comp_idx)
1780 {
1781 assert(type == QCD_MAIN);
1782 param_qcd *p = this;
1783 while (p->next != NULL)
1784 p = p->next;
1785 if (avail)
1786 {
1787 p->next = avail;
1788 avail = avail->next;
1789 p->next->init(this, (ui16)comp_idx);
1790 }
1791 else
1792 p->next = new param_qcd(this, (ui16)comp_idx);
1793 return p->next;
1794 }
1795
1797 //
1798 //
1799 //
1800 //
1801 //
1803
1805 void param_nlt::check_validity(param_siz& siz)
1806 {
1807 if (is_any_enabled() == false)
1808 return;
1809
1810 if (this->enabled && this->Tnlt == nonlinearity::OJPH_NLT_NO_NLT)
1811 this->enabled = false;
1812
1813 if (this->enabled &&
1814 this->Tnlt == nonlinearity::OJPH_NLT_BINARY_COMPLEMENT_NLT)
1815 {
1816 bool all_same = true;
1817 ui32 num_comps = siz.get_num_components();
1818
1819 // first stage; find out if all components captured by the default
1820 // entry (ALL_COMPS) has the same bit_depth/signedness,
1821 // while doing this, set the BDnlt for components not captured by the
1822 // default entry (ALL_COMPS)
1823 ui32 bit_depth = 0; // unknown yet
1824 bool is_signed = false; // unknown yet
1825 for (ui32 c = 0; c < num_comps; ++c)
1826 { // captured by ALL_COMPS
1827 param_nlt* p = get_nlt_object(c);
1828 if (p == NULL || !p->enabled)
1829 {
1830 if (bit_depth != 0)
1831 {
1832 // we have seen an undefined component previously
1833 all_same = all_same && (bit_depth == siz.get_bit_depth(c));
1834 all_same = all_same && (is_signed == siz.is_signed(c));
1835 }
1836 else
1837 {
1838 // this is the first component which has not type 3 nlt definition
1839 bit_depth = siz.get_bit_depth(c);
1840 is_signed = siz.is_signed(c);
1841 }
1842 }
1843 else
1844 { // can be type 0 or type 3
1845 p->BDnlt = (ui8)(siz.get_bit_depth(c) - 1);
1846 p->BDnlt = (ui8)(p->BDnlt | (siz.is_signed(c) ? 0x80 : 0));
1847 }
1848 }
1849
1850 if (all_same && bit_depth != 0)
1851 { // all the same, and some components are captured by ALL_COMPS
1852 this->BDnlt = (ui8)(bit_depth - 1);
1853 this->BDnlt = (ui8)(this->BDnlt | (is_signed ? 0x80 : 0));
1854 }
1855 else if (!all_same)
1856 { // have different settings or no component is captured by ALL_COMPS
1857 this->enabled = false;
1858 for (ui32 c = 0; c < num_comps; ++c)
1859 {
1860 param_nlt* p = get_nlt_object(c);
1861 if (p == NULL || !p->enabled)
1862 { // captured by ALL_COMPS
1863 if (p == NULL)
1864 p = add_object(c);
1865 p->enabled = true;
1866 p->Tnlt = nonlinearity::OJPH_NLT_BINARY_COMPLEMENT_NLT;
1867 p->BDnlt = (ui8)(siz.get_bit_depth(c) - 1);
1868 p->BDnlt = (ui8)(p->BDnlt | (siz.is_signed(c) ? 0x80 : 0));
1869 }
1870 }
1871 }
1872 }
1873 else {
1874 // fill NLT segment markers with correct information
1875 ui32 num_comps = siz.get_num_components();
1876 for (ui32 c = 0; c < num_comps; ++c)
1877 { // captured by ALL_COMPS
1878 param_nlt* p = get_nlt_object(c);
1879 if (p != NULL && p->enabled)
1880 { // can be type 0 or type 3
1881 p->BDnlt = (ui8)(siz.get_bit_depth(c) - 1);
1882 p->BDnlt = (ui8)(p->BDnlt | (siz.is_signed(c) ? 0x80 : 0));
1883 }
1884 }
1885 }
1886
1887 trim_non_existing_components(siz.get_num_components());
1888
1889 if (is_any_enabled() == true)
1890 siz.set_Rsiz_flag(param_siz::RSIZ_EXT_FLAG | param_siz::RSIZ_NLT_FLAG);
1891 }
1892
1894 void param_nlt::set_nonlinear_transform(ui32 comp_num, ui8 nl_type)
1895 {
1896 if (nl_type != ojph::param_nlt::OJPH_NLT_NO_NLT &&
1897 nl_type != ojph::param_nlt::OJPH_NLT_BINARY_COMPLEMENT_NLT)
1898 OJPH_ERROR(0x00050171, "Nonliearities other than type 0 "
1899 "(No Nonlinearity) or type 3 (Binary Binary Complement to Sign "
1900 "Magnitude Conversion) are not supported yet");
1901 param_nlt* p = get_nlt_object(comp_num);
1902 if (p == NULL)
1903 p = add_object(comp_num);
1904 p->Tnlt = nl_type;
1905 p->enabled = true;
1906 }
1907
1909 bool
1910 param_nlt::get_nonlinear_transform(ui32 comp_num, ui8& bit_depth,
1911 bool& is_signed, ui8& nl_type) const
1912 {
1913 assert(Cnlt == special_comp_num::ALL_COMPS);
1914 const param_nlt* p = get_nlt_object(comp_num);
1915 p = (p && p->enabled) ? p : this;
1916 if (p->enabled)
1917 {
1918 bit_depth = (ui8)((p->BDnlt & 0x7F) + 1);
1919 bit_depth = bit_depth <= 38 ? bit_depth : 38;
1920 is_signed = (p->BDnlt & 0x80) == 0x80;
1921 nl_type = (nonlinearity)p->Tnlt;
1922 return true;
1923 }
1924 return false;
1925 }
1926
1928 bool param_nlt::write(outfile_base* file) const
1929 {
1930 if (is_any_enabled() == false)
1931 return true;
1932
1933 char buf[2];
1934 bool result = true;
1935 const param_nlt* p = this;
1936 while (p)
1937 {
1938 if (p->enabled)
1939 {
1940 *(ui16*)buf = JP2K_MARKER::NLT;
1941 *(ui16*)buf = swap_byte(*(ui16*)buf);
1942 result &= file->write(&buf, 2) == 2;
1943 *(ui16*)buf = swap_byte(p->Lnlt);
1944 result &= file->write(&buf, 2) == 2;
1945 *(ui16*)buf = swap_byte(p->Cnlt);
1946 result &= file->write(&buf, 2) == 2;
1947 result &= file->write(&p->BDnlt, 1) == 1;
1948 result &= file->write(&p->Tnlt, 1) == 1;
1949 }
1950 p = p->next;
1951 }
1952 return result;
1953 }
1954
1956 void param_nlt::read(infile_base* file)
1957 {
1958 ui8 buf[6];
1959
1960 if (file->read(buf, 6) != 6)
1961 OJPH_ERROR(0x00050141, "error reading NLT marker segment");
1962
1963 ui16 length = swap_byte(*(ui16*)buf);
1964 if (length != 6 || (buf[5] != 3 && buf[5] != 0)) // wrong length or type
1965 OJPH_ERROR(0x00050142, "Unsupported NLT type %d\n", buf[5]);
1966
1967 ui16 comp = swap_byte(*(ui16*)(buf + 2));
1968 param_nlt* p = get_nlt_object(comp);
1969 if (p == NULL)
1970 p = add_object(comp);
1971 p->enabled = true;
1972 p->Cnlt = comp;
1973 p->BDnlt = buf[4];
1974 p->Tnlt = buf[5];
1975 }
1976
1978 param_nlt* param_nlt::get_nlt_object(ui32 comp_num)
1979 {
1980 // cast object to constant
1981 const param_nlt* const_p = const_cast<const param_nlt*>(this);
1982 // call using the constant object, then cast to non-const
1983 return const_cast<param_nlt*>(const_p->get_nlt_object(comp_num));
1984 }
1985
1987 const param_nlt* param_nlt::get_nlt_object(ui32 comp_num) const
1988 {
1989 const param_nlt* p = this;
1990 while (p && p->Cnlt != comp_num)
1991 p = p->next;
1992 return p;
1993 }
1994
1996 param_nlt* param_nlt::add_object(ui32 comp_num)
1997 {
1998 assert(comp_num != special_comp_num::ALL_COMPS);
1999 assert(Cnlt == special_comp_num::ALL_COMPS);
2000 param_nlt* p = this;
2001 while (p->next != NULL) {
2002 assert(p->Cnlt != comp_num);
2003 p = p->next;
2004 }
2005 if (avail)
2006 {
2007 p->next = avail;
2008 avail = avail->next;
2009 p->next->init();
2010 }
2011 else
2012 p->next = new param_nlt;
2013 p = p->next;
2014 p->Cnlt = (ui16)comp_num;
2015 return p;
2016 }
2017
2019 bool param_nlt::is_any_enabled() const
2020 {
2021 // check if any field is enabled
2022 const param_nlt* p = this;
2023 while (p && p->enabled == false)
2024 p = p->next;
2025 return (p != NULL);
2026 }
2027
2029 void param_nlt::trim_non_existing_components(ui32 num_comps)
2030 {
2031 param_nlt* p = this->next;
2032 while (p) {
2033 if (p->enabled == true && p->Cnlt >= num_comps) {
2034 p->enabled = false;
2035 OJPH_INFO(0x00050161, "The NLT marker segment for the "
2036 "non-existing component %d has been removed.", p->Cnlt);
2037 }
2038 p = p->next;
2039 }
2040 }
2041
2042
2044 //
2045 //
2046 //
2047 //
2048 //
2050
2052 bool param_sot::write(outfile_base *file, ui32 payload_len)
2053 {
2054 char buf[4];
2055 bool result = true;
2056
2057 this->Psot = payload_len + 14; //inc. SOT marker, field & SOD
2058
2059 *(ui16*)buf = JP2K_MARKER::SOT;
2060 *(ui16*)buf = swap_byte(*(ui16*)buf);
2061 result &= file->write(&buf, 2) == 2;
2062 *(ui16*)buf = swap_byte(Lsot);
2063 result &= file->write(&buf, 2) == 2;
2064 *(ui16*)buf = swap_byte(Isot);
2065 result &= file->write(&buf, 2) == 2;
2066 *(ui32*)buf = swap_byte(Psot);
2067 result &= file->write(&buf, 4) == 4;
2068 result &= file->write(&TPsot, 1) == 1;
2069 result &= file->write(&TNsot, 1) == 1;
2070
2071 return result;
2072 }
2073
2075 bool param_sot::write(outfile_base *file, ui32 payload_len,
2076 ui8 TPsot, ui8 TNsot)
2077 {
2078 char buf[4];
2079 bool result = true;
2080
2081 *(ui16*)buf = JP2K_MARKER::SOT;
2082 *(ui16*)buf = swap_byte(*(ui16*)buf);
2083 result &= file->write(&buf, 2) == 2;
2084 *(ui16*)buf = swap_byte(Lsot);
2085 result &= file->write(&buf, 2) == 2;
2086 *(ui16*)buf = swap_byte(Isot);
2087 result &= file->write(&buf, 2) == 2;
2088 *(ui32*)buf = swap_byte(payload_len + 14);
2089 result &= file->write(&buf, 4) == 4;
2090 result &= file->write(&TPsot, 1) == 1;
2091 result &= file->write(&TNsot, 1) == 1;
2092
2093 return result;
2094 }
2095
2097 bool param_sot::read(infile_base *file, bool resilient)
2098 {
2099 if (resilient)
2100 {
2101 if (file->read(&Lsot, 2) != 2)
2102 {
2103 OJPH_INFO(0x00050091, "error reading SOT marker");
2104 Lsot = 0; Isot = 0; Psot = 0; TPsot = 0; TNsot = 0;
2105 return false;
2106 }
2107 Lsot = swap_byte(Lsot);
2108 if (Lsot != 10)
2109 {
2110 OJPH_INFO(0x00050092, "error in SOT length");
2111 Lsot = 0; Isot = 0; Psot = 0; TPsot = 0; TNsot = 0;
2112 return false;
2113 }
2114 if (file->read(&Isot, 2) != 2)
2115 {
2116 OJPH_INFO(0x00050093, "error reading tile index");
2117 Lsot = 0; Isot = 0; Psot = 0; TPsot = 0; TNsot = 0;
2118 return false;
2119 }
2120 Isot = swap_byte(Isot);
2121 if (Isot == 0xFFFF)
2122 {
2123 OJPH_INFO(0x00050094, "tile index in SOT marker cannot be 0xFFFF");
2124 Lsot = 0; Isot = 0; Psot = 0; TPsot = 0; TNsot = 0;
2125 return false;
2126 }
2127 if (file->read(&Psot, 4) != 4)
2128 {
2129 OJPH_INFO(0x00050095, "error reading SOT marker");
2130 Lsot = 0; Isot = 0; Psot = 0; TPsot = 0; TNsot = 0;
2131 return false;
2132 }
2133 Psot = swap_byte(Psot);
2134 if (file->read(&TPsot, 1) != 1)
2135 {
2136 OJPH_INFO(0x00050096, "error reading SOT marker");
2137 Lsot = 0; Isot = 0; Psot = 0; TPsot = 0; TNsot = 0;
2138 return false;
2139 }
2140 if (file->read(&TNsot, 1) != 1)
2141 {
2142 OJPH_INFO(0x00050097, "error reading SOT marker");
2143 Lsot = 0; Isot = 0; Psot = 0; TPsot = 0; TNsot = 0;
2144 return false;
2145 }
2146 }
2147 else
2148 {
2149 if (file->read(&Lsot, 2) != 2)
2150 OJPH_ERROR(0x00050091, "error reading SOT marker");
2151 Lsot = swap_byte(Lsot);
2152 if (Lsot != 10)
2153 OJPH_ERROR(0x00050092, "error in SOT length");
2154 if (file->read(&Isot, 2) != 2)
2155 OJPH_ERROR(0x00050093, "error reading SOT tile index");
2156 Isot = swap_byte(Isot);
2157 if (Isot == 0xFFFF)
2158 OJPH_ERROR(0x00050094, "tile index in SOT marker cannot be 0xFFFF");
2159 if (file->read(&Psot, 4) != 4)
2160 OJPH_ERROR(0x00050095, "error reading SOT marker");
2161 Psot = swap_byte(Psot);
2162 if (file->read(&TPsot, 1) != 1)
2163 OJPH_ERROR(0x00050096, "error reading SOT marker");
2164 if (file->read(&TNsot, 1) != 1)
2165 OJPH_ERROR(0x00050097, "error reading SOT marker");
2166 }
2167 return true;
2168 }
2169
2171 //
2172 //
2173 //
2174 //
2175 //
2177
2179 void param_tlm::init(ui32 num_pairs, Ttlm_Ptlm_pair *store)
2180 {
2181 if (4 + 6 * num_pairs > 65535)
2182 OJPH_ERROR(0x000500B1, "Trying to allocate more than 65535 bytes for "
2183 "a TLM marker; this can be resolved by having more than "
2184 "one TLM marker, but the code does not support this. "
2185 "In any case, this limit means that we have 10922 "
2186 "tileparts or more, which is a huge number.");
2187 this->num_pairs = num_pairs;
2188 pairs = store;
2189 Ltlm = (ui16)(4 + 6 * num_pairs);
2190 Ztlm = 0;
2191 Stlm = 0x60;
2192 }
2193
2195 void param_tlm::set_next_pair(ui16 Ttlm, ui32 Ptlm)
2196 {
2197 assert(next_pair_index < num_pairs);
2198 pairs[next_pair_index].Ttlm = Ttlm;
2199 pairs[next_pair_index].Ptlm = Ptlm + 14;
2200 ++next_pair_index;
2201 }
2202
2204 bool param_tlm::write(outfile_base *file)
2205 {
2206 assert(next_pair_index == num_pairs);
2207 char buf[4];
2208 bool result = true;
2209
2210 *(ui16*)buf = JP2K_MARKER::TLM;
2211 *(ui16*)buf = swap_byte(*(ui16*)buf);
2212 result &= file->write(&buf, 2) == 2;
2213 *(ui16*)buf = swap_byte(Ltlm);
2214 result &= file->write(&buf, 2) == 2;
2215 result &= file->write(&Ztlm, 1) == 1;
2216 result &= file->write(&Stlm, 1) == 1;
2217 for (ui32 i = 0; i < num_pairs; ++i)
2218 {
2219 *(ui16*)buf = swap_byte(pairs[i].Ttlm);
2220 result &= file->write(&buf, 2) == 2;
2221 *(ui32*)buf = swap_byte(pairs[i].Ptlm);
2222 result &= file->write(&buf, 4) == 4;
2223 }
2224 return result;
2225 }
2226
2228 //
2229 //
2230 //
2231 //
2232 //
2234
2236 const param_dfs* param_dfs::get_dfs(int index) const
2237 {
2238 const param_dfs* p = this;
2239 while (p && p->Sdfs != index)
2240 p = p->next;
2241 return p;
2242 }
2243
2245 param_dfs::dfs_dwt_type param_dfs::get_dwt_type(ui32 decomp_level) const
2246 {
2247 decomp_level = ojph_min(decomp_level, Ids);
2248 ui32 d = decomp_level - 1; // decomp_level starts from 1
2249 ui32 idx = d >> 2; // complete bytes
2250 ui32 bits = d & 0x3; // bit within the bytes
2251 ui32 val = (Ddfs[idx] >> (6 - 2 * bits)) & 0x3;
2252 return (dfs_dwt_type)val;
2253 }
2254
2256 ui32 param_dfs::get_subband_idx(ui32 num_decompositions, ui32 resolution,
2257 ui32 subband) const
2258 {
2259 assert((resolution == 0 && subband == 0) ||
2260 (resolution > 0 && subband > 0 && subband < 4));
2261
2262 ui32 ns[4] = { 0, 3, 1, 1 };
2263
2264 ui32 idx = 0;
2265 if (resolution > 0)
2266 {
2267 idx = 0;
2268 ui32 i = 1;
2269 for (; i < resolution; ++i)
2270 idx += ns[get_dwt_type(num_decompositions - i + 1)];
2271 dfs_dwt_type t = get_dwt_type(num_decompositions - i + 1);
2272 idx += subband;
2273 if (t == VERT_DWT && subband == 2)
2274 --idx;
2275 }
2276
2277 return idx;
2278 }
2279
2281 point param_dfs::get_res_downsamp(ui32 skipped_resolutions) const
2282 {
2283 point factor(1, 1);
2284 ui32 decomp_level = 1;
2285 while (skipped_resolutions > 0)
2286 {
2287 param_dfs::dfs_dwt_type type = get_dwt_type(decomp_level);
2288 if (type == BIDIR_DWT)
2289 { factor.x *= 2; factor.y *= 2; }
2290 else if (type == HORZ_DWT)
2291 factor.x *= 2;
2292 else if (type == VERT_DWT)
2293 factor.y *= 2;
2294
2295 ++decomp_level;
2296 --skipped_resolutions;
2297 }
2298 return factor;
2299 }
2300
2302 bool param_dfs::read(infile_base *file)
2303 {
2304 if (Ldfs != 0) { // this param_dfs is used
2305 param_dfs* p = this;
2306 while (p->next != NULL)
2307 p = p->next;
2308 if (avail)
2309 {
2310 p->next = avail;
2311 avail = avail->next;
2312 p->next->init();
2313 }
2314 else
2315 p->next = new param_dfs;
2316 p = p->next;
2317 return p->read(file);
2318 }
2319
2320 if (file->read(&Ldfs, 2) != 2)
2321 OJPH_ERROR(0x000500D1, "error reading DFS-Ldfs parameter");
2322 Ldfs = swap_byte(Ldfs);
2323 if (file->read(&Sdfs, 2) != 2)
2324 OJPH_ERROR(0x000500D2, "error reading DFS-Sdfs parameter");
2325 Sdfs = swap_byte(Sdfs);
2326 if (Sdfs > 15)
2327 OJPH_ERROR(0x000500D3, "The DFS-Sdfs parameter is %d, which is "
2328 "larger than the permissible 15", Sdfs);
2329 ui8 t, l_Ids = 0;
2330 if (file->read(&l_Ids, 1) != 1)
2331 OJPH_ERROR(0x000500D4, "error reading DFS-Ids parameter");
2332 constexpr int max_Ddfs = sizeof(Ddfs) * 4;
2333 if (l_Ids > max_Ddfs)
2334 OJPH_INFO(0x000500D5, "The DFS-Ids parameter is %d; while this is "
2335 "valid, the number is unnessarily large -- you do not need more "
2336 "than %d. Please contact me regarding this issue.",
2337 l_Ids, max_Ddfs);
2338 Ids = l_Ids < max_Ddfs ? l_Ids : max_Ddfs;
2339 for (int i = 0; i < Ids; i += 4)
2340 if (file->read(&Ddfs[i / 4], 1) != 1)
2341 OJPH_ERROR(0x000500D6, "error reading DFS-Ddfs parameters");
2342 for (int i = Ids; i < l_Ids; i += 4)
2343 if (file->read(&t, 1) != 1)
2344 OJPH_ERROR(0x000500D7, "error reading DFS-Ddfs parameters");
2345 return true;
2346 }
2347
2349 //
2350 //
2351 //
2352 //
2353 //
2355
2357 param_atk* param_atk::get_atk(int index)
2358 {
2359 assert(top_atk == NULL);
2360
2361 if (Latk == 0)
2362 {
2363 // This atk object is not used, initialize it to either 0 (irv97)
2364 // or 1 (rev53), and use it. If index is not 0 nor 1, then index
2365 // must have been read from file previously, otherwise it is an
2366 // error.
2367 if (index == 0) { this->init_irv97(); return this; }
2368 else if (index == 1) { this->init_rev53(); return this; }
2369 }
2370
2371 param_atk* p = this;
2372 while (p && p->get_index() != index)
2373 p = p->next;
2374
2375 if (p == NULL && (index == 0 || index == 1))
2376 {
2377 // The index was not found, add an atk object only if the index is
2378 // either 0 or 1
2379 p = add_object();
2380 if (index == 0)
2381 p->init_irv97();
2382 else if (index == 1)
2383 p->init_rev53();
2384 }
2385
2386 return p;
2387 }
2388
2390 bool param_atk::read_coefficient(infile_base *file, float &K, si32& bytes)
2391 {
2392 int coeff_type = get_coeff_type();
2393 if (coeff_type == 0) { // 8bit
2394 ui8 v;
2395 if (file->read(&v, 1) != 1) return false;
2396 bytes -= 1;
2397 K = v;
2398 }
2399 else if (coeff_type == 1) { // 16bit
2400 ui16 v;
2401 if (file->read(&v, 2) != 2) return false;
2402 bytes -= 2;
2403 K = swap_byte(v);
2404 }
2405 else if (coeff_type == 2) { // float
2406 union {
2407 float f;
2408 ui32 i;
2409 } v;
2410 if (file->read(&v.i, 4) != 4) return false;
2411 bytes -= 4;
2412 v.i = swap_byte(v.i);
2413 K = v.f;
2414 }
2415 else if (coeff_type == 3) { // double
2416 union {
2417 double d;
2418 ui64 i;
2419 } v;
2420 if (file->read(&v.i, 8) != 8) return false;
2421 bytes -= 8;
2422 v.i = swap_byte(v.i);
2423 K = (float)v.d;
2424 }
2425 else if (coeff_type == 4) { // 128 bit float
2426 ui64 v, v1;
2427 if (file->read(&v, 8) != 8) return false;
2428 bytes -= 8;
2429 if (file->read(&v1, 8) != 8) return false; // v1 not needed
2430 bytes -= 8;
2431 v = swap_byte(v);
2432
2433 union {
2434 float f;
2435 ui32 i;
2436 } s;
2437 // convert the MSB of 128b float to 32b float
2438 // 32b float has 1 sign bit, 8 exponent (offset 127), 23 mantissa
2439 // 128b float has 1 sign bit, 15 exponent (offset 16383), 112 mantissa
2440 si32 e = (si32)((v >> 48) & 0x7FFF); // exponent
2441 e -= 16383;
2442 e += 127;
2443 e = e & 0xFF; // removes MSBs if negative
2444 e <<= 23; // move bits to their location
2445 s.i = 0;
2446 s.i |= ((ui32)(v >> 32) & 0x80000000); // copy sign bit
2447 s.i |= (ui32)e; // copy exponent
2448 s.i |= (ui32)((v >> 25) & 0x007FFFFF); // copy 23 mantissa
2449 K = s.f;
2450 }
2451 return true;
2452 }
2453
2454
2456 bool param_atk::read_coefficient(infile_base *file, si16 &K, si32& bytes)
2457 {
2458 int coeff_type = get_coeff_type();
2459 if (coeff_type == 0) {
2460 si8 v;
2461 if (file->read(&v, 1) != 1) return false;
2462 bytes -= 1;
2463 K = v;
2464 }
2465 else if (coeff_type == 1) {
2466 si16 v;
2467 if (file->read(&v, 2) != 2) return false;
2468 bytes -= 2;
2469 K = (si16)swap_byte((ui16)v);
2470 }
2471 else
2472 return false;
2473 return true;
2474 }
2475
2477 bool param_atk::read(infile_base *file)
2478 {
2479 if (Latk != 0) // this param_atk is used
2480 return add_object()->read(file);
2481
2482 if (file->read(&Latk, 2) != 2)
2483 OJPH_ERROR(0x000500E1, "error reading ATK-Latk parameter");
2484 Latk = swap_byte(Latk);
2485 si32 bytes = Latk - 2;
2486 ojph::ui16 temp_Satk;
2487 if (file->read(&temp_Satk, 2) != 2)
2488 OJPH_ERROR(0x000500E2, "error reading ATK-Satk parameter");
2489 bytes -= 2;
2490 temp_Satk = swap_byte(temp_Satk);
2491 int tmp_idx = temp_Satk & 0xFF;
2492 if ((top_atk && top_atk->get_atk(tmp_idx) != NULL)
2493 || tmp_idx == 0 || tmp_idx == 1)
2494 OJPH_ERROR(0x000500F3, "ATK-Satk parameter sets ATK marker index to "
2495 "the illegal value of %d. ATK-Satk should be in (2-255) and, I "
2496 "believe, must not be repeated; otherwise, it would be unclear "
2497 "what marker segment must be employed when an index is repeated.",
2498 tmp_idx);
2499 Satk = temp_Satk;
2500 if (is_m_init0() == false) // only even-indexed is supported
2501 OJPH_ERROR(0x000500E3, "ATK-Satk parameter sets m_init to 1, "
2502 "requiring odd-indexed subsequence in first reconstruction step, "
2503 "which is not supported yet.");
2504 if (is_whole_sample() == false) // ARB filter not supported
2505 OJPH_ERROR(0x000500E4, "ATK-Satk parameter specified ARB filter, "
2506 "which is not supported yet.");
2507 if (is_reversible() && get_coeff_type() >= 2) // reversible & float
2508 OJPH_ERROR(0x000500E5, "ATK-Satk parameter does not make sense. "
2509 "It employs floats with reversible filtering.");
2510 if (is_using_ws_extension() == false) // only sym. ext is supported
2511 OJPH_ERROR(0x000500E6, "ATK-Satk parameter requires constant "
2512 "boundary extension, which is not supported yet.");
2513 if (is_reversible() == false)
2514 if (read_coefficient(file, Katk, bytes) == false)
2515 OJPH_ERROR(0x000500E7, "error reading ATK-Katk parameter");
2516 if (file->read(&Natk, 1) != 1)
2517 OJPH_ERROR(0x000500E8, "error reading ATK-Natk parameter");
2518 bytes -= 1;
2519 if (Natk > max_steps) {
2520 if (d != d_store) // was this allocated -- very unlikely
2521 delete[] d;
2522 d = new lifting_step[Natk];
2523 max_steps = Natk;
2524 }
2525
2526 if (is_reversible())
2527 {
2528 for (int s = 0; s < Natk; ++s)
2529 {
2530 if (file->read(&d[s].rev.Eatk, 1) != 1)
2531 OJPH_ERROR(0x000500E9, "error reading ATK-Eatk parameter");
2532 bytes -= 1;
2533 if (file->read(&d[s].rev.Batk, 2) != 2)
2534 OJPH_ERROR(0x000500EA, "error reading ATK-Batk parameter");
2535 bytes -= 2;
2536 d[s].rev.Batk = (si16)swap_byte((ui16)d[s].rev.Batk);
2537 ui8 LCatk;
2538 if (file->read(&LCatk, 1) != 1)
2539 OJPH_ERROR(0x000500EB, "error reading ATK-LCatk parameter");
2540 bytes -= 1;
2541 if (LCatk == 0)
2542 OJPH_ERROR(0x000500EC, "Encountered a ATK-LCatk value of zero; "
2543 "something is wrong.");
2544 if (LCatk > 1)
2545 OJPH_ERROR(0x000500ED, "ATK-LCatk value greater than 1; "
2546 "that is, a multitap filter is not supported");
2547 if (read_coefficient(file, d[s].rev.Aatk, bytes) == false)
2548 OJPH_ERROR(0x000500EE, "Error reding ATK-Aatk parameter");
2549 }
2550 }
2551 else
2552 {
2553 for (int s = 0; s < Natk; ++s)
2554 {
2555 ui8 LCatk;
2556 if (file->read(&LCatk, 1) != 1)
2557 OJPH_ERROR(0x000500EF, "error reading ATK-LCatk parameter");
2558 bytes -= 1;
2559 if (LCatk == 0)
2560 OJPH_ERROR(0x000500F0, "Encountered a ATK-LCatk value of zero; "
2561 "something is wrong.");
2562 if (LCatk > 1)
2563 OJPH_ERROR(0x000500F1, "ATK-LCatk value greater than 1; "
2564 "that is, a multitap filter is not supported.");
2565 if (read_coefficient(file, d[s].irv.Aatk, bytes) == false)
2566 OJPH_ERROR(0x000500F2, "Error reding ATK-Aatk parameter");
2567 }
2568 }
2569 if (bytes != 0)
2570 OJPH_ERROR(0x000500F3, "The length of an ATK marker segment "
2571 "(ATK-Latk) is not correct");
2572
2573 return true;
2574 }
2575
2577 void param_atk::init_irv97()
2578 {
2579 Satk = 0x4a00; // illegal because ATK = 0
2580 Katk = (float)1.230174104914001;
2581 Natk = 4;
2582 // next is (A-4) in T.801 second line
2583 Latk = (ui16)(5 + Natk + sizeof(float) * (1 + Natk));
2584 d[0].irv.Aatk = (float)0.443506852043971;
2585 d[1].irv.Aatk = (float)0.882911075530934;
2586 d[2].irv.Aatk = (float)-0.052980118572961;
2587 d[3].irv.Aatk = (float)-1.586134342059924;
2588 }
2589
2591 void param_atk::init_rev53()
2592 {
2593 Satk = 0x5801; // illegal because ATK = 1
2594 Natk = 2;
2595 // next is (A-4) in T.801 fourth line
2596 Latk = (ui16)(5 + 2 * Natk + sizeof(ui8) * (Natk + Natk));
2597 d[0].rev.Aatk = 1;
2598 d[0].rev.Batk = 2;
2599 d[0].rev.Eatk = 2;
2600 d[1].rev.Aatk = -1;
2601 d[1].rev.Batk = 1;
2602 d[1].rev.Eatk = 1;
2603 }
2604
2606 param_atk* param_atk::add_object()
2607 {
2608 assert(top_atk = NULL);
2609 param_atk *p = this;
2610 while (p->next != NULL)
2611 p = p->next;
2612 if (avail)
2613 {
2614 p->next = avail;
2615 avail = avail->next;
2616 }
2617 else
2618 p->next = new param_atk;
2619 p = p->next;
2620 p->init(this);
2621 return p;
2622 }
2623
2624 } // !local namespace
2625} // !ojph namespace
ojph::comment_exchange::len
ui16 len
Definition ojph_params.h:300
ojph::comment_exchange::Rcom
ui16 Rcom
Definition ojph_params.h:301
ojph::comment_exchange::set_string
void set_string(const char *str)
Definition ojph_params.cpp:456
ojph::comment_exchange::set_data
void set_data(const char *data, ui16 len)
Definition ojph_params.cpp:468
ojph::comment_exchange::data
const char * data
Definition ojph_params.h:299
ojph::infile_base
Definition ojph_file.h:267
ojph::infile_base::read
virtual size_t read(void *ptr, size_t size)=0
ojph::local::bibo_gains
Definition ojph_params.cpp:577
ojph::local::bibo_gains::gain_5x3_l
static const float gain_5x3_l[34]
Definition ojph_params.cpp:587
ojph::local::bibo_gains::get_bibo_gain_l
static float get_bibo_gain_l(ui32 num_decomp, bool reversible)
Definition ojph_params.cpp:579
ojph::local::bibo_gains::gain_5x3_h
static const float gain_5x3_h[34]
Definition ojph_params.cpp:588
ojph::local::bibo_gains::get_bibo_gain_h
static float get_bibo_gain_h(ui32 num_decomp, bool reversible)
Definition ojph_params.cpp:581
ojph::local::bibo_gains::gain_9x7_h
static const float gain_9x7_h[34]
Definition ojph_params.cpp:586
ojph::local::bibo_gains::gain_9x7_l
static const float gain_9x7_l[34]
Definition ojph_params.cpp:585
ojph::local::resolution
Definition ojph_resolution.h:62
ojph::local::sqrt_energy_gains
Definition ojph_params.cpp:526
ojph::local::sqrt_energy_gains::gain_5x3_l
static const float gain_5x3_l[34]
Definition ojph_params.cpp:536
ojph::local::sqrt_energy_gains::gain_5x3_h
static const float gain_5x3_h[34]
Definition ojph_params.cpp:537
ojph::local::sqrt_energy_gains::get_gain_l
static float get_gain_l(ui32 num_decomp, bool reversible)
Definition ojph_params.cpp:528
ojph::local::sqrt_energy_gains::gain_9x7_l
static const float gain_9x7_l[34]
Definition ojph_params.cpp:534
ojph::local::sqrt_energy_gains::get_gain_h
static float get_gain_h(ui32 num_decomp, bool reversible)
Definition ojph_params.cpp:530
ojph::local::sqrt_energy_gains::gain_9x7_h
static const float gain_9x7_h[34]
Definition ojph_params.cpp:535
ojph::local::subband
Definition ojph_subband.h:63
ojph::outfile_base
Definition ojph_file.h:75
ojph::outfile_base::write
virtual size_t write(const void *ptr, size_t size)=0
ojph::param_coc
Definition ojph_params.h:136
ojph::param_coc::is_reversible
bool is_reversible() const
Definition ojph_params.cpp:389
ojph::param_coc::set_precinct_size
void set_precinct_size(int num_levels, size *precinct_size)
Definition ojph_params.cpp:369
ojph::param_coc::get_block_dims
size get_block_dims() const
Definition ojph_params.cpp:381
ojph::param_coc::set_reversible
void set_reversible(bool reversible)
Definition ojph_params.cpp:373
ojph::param_coc::get_precinct_size
size get_precinct_size(ui32 level_num) const
Definition ojph_params.cpp:393
ojph::param_coc::get_num_decompositions
ui32 get_num_decompositions() const
Definition ojph_params.cpp:377
ojph::param_coc::state
local::param_cod * state
Definition ojph_params.h:154
ojph::param_coc::get_log_block_dims
size get_log_block_dims() const
Definition ojph_params.cpp:385
ojph::param_coc::get_log_precinct_size
size get_log_precinct_size(ui32 level_num) const
Definition ojph_params.cpp:397
ojph::param_coc::set_num_decomposition
void set_num_decomposition(ui32 num_decompositions)
Definition ojph_params.cpp:361
ojph::param_coc::get_block_vertical_causality
bool get_block_vertical_causality() const
Definition ojph_params.cpp:401
ojph::param_coc::set_block_dims
void set_block_dims(ui32 width, ui32 height)
Definition ojph_params.cpp:365
ojph::param_cod
Definition ojph_params.h:104
ojph::param_cod::get_block_dims
size get_block_dims() const
Definition ojph_params.cpp:269
ojph::param_cod::get_progression_order
int get_progression_order() const
Definition ojph_params.cpp:299
ojph::param_cod::is_using_color_transform
bool is_using_color_transform() const
Definition ojph_params.cpp:329
ojph::param_cod::get_coc
param_coc get_coc(ui32 component_idx)
Definition ojph_params.cpp:254
ojph::param_cod::set_num_decomposition
void set_num_decomposition(ui32 num_decompositions)
Definition ojph_params.cpp:164
ojph::param_cod::get_num_decompositions
ui32 get_num_decompositions() const
Definition ojph_params.cpp:263
ojph::param_cod::get_log_block_dims
size get_log_block_dims() const
Definition ojph_params.cpp:275
ojph::param_cod::packets_may_use_sop
bool packets_may_use_sop() const
Definition ojph_params.cpp:335
ojph::param_cod::get_precinct_size
size get_precinct_size(ui32 level_num) const
Definition ojph_params.cpp:287
ojph::param_cod::get_progression_order_as_string
const char * get_progression_order_as_string() const
Definition ojph_params.cpp:305
ojph::param_cod::set_precinct_size
void set_precinct_size(int num_levels, size *precinct_size)
Definition ojph_params.cpp:187
ojph::param_cod::packets_use_eph
bool packets_use_eph() const
Definition ojph_params.cpp:341
ojph::param_cod::state
local::param_cod * state
Definition ojph_params.h:131
ojph::param_cod::is_reversible
bool is_reversible() const
Definition ojph_params.cpp:281
ojph::param_cod::set_progression_order
void set_progression_order(const char *name)
Definition ojph_params.cpp:215
ojph::param_cod::get_block_vertical_causality
bool get_block_vertical_causality() const
Definition ojph_params.cpp:347
ojph::param_cod::set_block_dims
void set_block_dims(ui32 width, ui32 height)
Definition ojph_params.cpp:173
ojph::param_cod::get_log_precinct_size
size get_log_precinct_size(ui32 level_num) const
Definition ojph_params.cpp:293
ojph::param_cod::get_num_layers
int get_num_layers() const
Definition ojph_params.cpp:323
ojph::param_cod::set_color_transform
void set_color_transform(bool color_transform)
Definition ojph_params.cpp:242
ojph::param_cod::set_reversible
void set_reversible(bool reversible)
Definition ojph_params.cpp:248
ojph::param_nlt::OJPH_NLT_NO_NLT
@ OJPH_NLT_NO_NLT
Definition ojph_params.h:249
ojph::param_nlt::OJPH_NLT_BINARY_COMPLEMENT_NLT
@ OJPH_NLT_BINARY_COMPLEMENT_NLT
Definition ojph_params.h:252
ojph::param_nlt::get_nonlinear_transform
bool get_nonlinear_transform(ui32 comp_num, ui8 &bit_depth, bool &is_signed, ui8 &nl_type) const
get the nonlinearity type associated with comp_num, which should be one from enum nonlinearity
Definition ojph_params.cpp:440
ojph::param_nlt::state
local::param_nlt * state
Definition ojph_params.h:286
ojph::param_nlt::set_nonlinear_transform
void set_nonlinear_transform(ui32 comp_num, ui8 nl_type)
enables or disables type 3 nonlinearity for a component or the default setting
Definition ojph_params.cpp:434
ojph::param_qcd::set_irrev_quant
void set_irrev_quant(float delta)
Set the irreversible quantization base delta.
Definition ojph_params.cpp:414
ojph::param_qcd::state
local::param_qcd * state
Definition ojph_params.h:191
ojph::param_siz::set_tile_size
void set_tile_size(size s)
Definition ojph_params.cpp:65
ojph::param_siz::get_image_extent
point get_image_extent() const
Definition ojph_params.cpp:96
ojph::param_siz::set_component
void set_component(ui32 comp_num, const point &downsampling, ui32 bit_depth, bool is_signed)
Definition ojph_params.cpp:89
ojph::param_siz::set_num_components
void set_num_components(ui32 num_comps)
Definition ojph_params.cpp:83
ojph::param_siz::get_bit_depth
ui32 get_bit_depth(ui32 comp_num) const
Definition ojph_params.cpp:126
ojph::param_siz::set_tile_offset
void set_tile_offset(point offset)
Definition ojph_params.cpp:77
ojph::param_siz::get_image_offset
point get_image_offset() const
Definition ojph_params.cpp:102
ojph::param_siz::state
local::param_siz * state
Definition ojph_params.h:99
ojph::param_siz::set_image_offset
void set_image_offset(point offset)
Definition ojph_params.cpp:71
ojph::param_siz::get_tile_size
size get_tile_size() const
Definition ojph_params.cpp:108
ojph::param_siz::get_recon_height
ui32 get_recon_height(ui32 comp_num) const
Definition ojph_params.cpp:150
ojph::param_siz::get_downsampling
point get_downsampling(ui32 comp_num) const
Definition ojph_params.cpp:138
ojph::param_siz::set_image_extent
void set_image_extent(point extent)
Definition ojph_params.cpp:59
ojph::param_siz::get_tile_offset
point get_tile_offset() const
Definition ojph_params.cpp:114
ojph::param_siz::get_recon_width
ui32 get_recon_width(ui32 comp_num) const
Definition ojph_params.cpp:144
ojph::param_siz::is_signed
bool is_signed(ui32 comp_num) const
Definition ojph_params.cpp:132
ojph::param_siz::get_num_components
ui32 get_num_components() const
Definition ojph_params.cpp:120
ojph::local
Definition ojph_bitbuffer_read.h:52
ojph::local::SIZ
@ SIZ
Definition ojph_params_local.h:123
ojph::local::NLT
@ NLT
Definition ojph_params_local.h:141
ojph::local::TLM
@ TLM
Definition ojph_params_local.h:126
ojph::local::QCC
@ QCC
Definition ojph_params_local.h:132
ojph::local::QCD
@ QCD
Definition ojph_params_local.h:131
ojph::local::COC
@ COC
Definition ojph_params_local.h:125
ojph::local::COD
@ COD
Definition ojph_params_local.h:124
ojph::local::CAP
@ CAP
Definition ojph_params_local.h:122
ojph::local::SOT
@ SOT
Definition ojph_params_local.h:143
ojph::local::swap_byte
static ui16 swap_byte(ui16 t)
Definition ojph_codestream_local.h:58
ojph
Definition ojph_img_io.h:52
ojph::OJPH_PO_STRING_PCRL
const char OJPH_PO_STRING_PCRL[]
Definition ojph_params_local.h:70
ojph::OJPH_PO_LRCP
@ OJPH_PO_LRCP
Definition ojph_params_local.h:59
ojph::OJPH_PO_RLCP
@ OJPH_PO_RLCP
Definition ojph_params_local.h:60
ojph::OJPH_PO_CPRL
@ OJPH_PO_CPRL
Definition ojph_params_local.h:63
ojph::OJPH_PO_PCRL
@ OJPH_PO_PCRL
Definition ojph_params_local.h:62
ojph::OJPH_PO_RPCL
@ OJPH_PO_RPCL
Definition ojph_params_local.h:61
ojph::si8
int8_t si8
Definition ojph_defs.h:51
ojph::ui64
uint64_t ui64
Definition ojph_defs.h:56
ojph::ui16
uint16_t ui16
Definition ojph_defs.h:52
ojph::population_count
static ui32 population_count(ui32 val)
Definition ojph_arch.h:156
ojph::OJPH_PO_STRING_RLCP
const char OJPH_PO_STRING_RLCP[]
Definition ojph_params_local.h:68
ojph::OJPH_PO_STRING_RPCL
const char OJPH_PO_STRING_RPCL[]
Definition ojph_params_local.h:69
ojph::OJPH_PO_STRING_CPRL
const char OJPH_PO_STRING_CPRL[]
Definition ojph_params_local.h:71
ojph::count_leading_zeros
static ui32 count_leading_zeros(ui32 val)
Definition ojph_arch.h:177
ojph::si32
int32_t si32
Definition ojph_defs.h:55
ojph::si16
int16_t si16
Definition ojph_defs.h:53
ojph::ui32
uint32_t ui32
Definition ojph_defs.h:54
ojph::ui8
uint8_t ui8
Definition ojph_defs.h:50
ojph::OJPH_PO_STRING_LRCP
const char OJPH_PO_STRING_LRCP[]
Definition ojph_params_local.h:67
ojph_base.h
main
int main(int argc, char *argv[])
Definition ojph_compress.cpp:487
ojph_max
#define ojph_max(a, b)
Definition ojph_defs.h:73
ojph_div_ceil
#define ojph_div_ceil(a, b)
Definition ojph_defs.h:70
ojph_min
#define ojph_min(a, b)
Definition ojph_defs.h:76
ojph_file.h
ojph_message.h
OJPH_INFO
#define OJPH_INFO(t,...)
MACROs to insert file and line number for info, warning, and error.
Definition ojph_message.h:284
OJPH_ERROR
#define OJPH_ERROR(t,...)
Definition ojph_message.h:288
OJPH_WARN
#define OJPH_WARN(t,...)
Definition ojph_message.h:286
ojph_params.h
ojph_params_local.h
ojph::local::cod_SPcod::wavelet_trans
ui8 wavelet_trans
Definition ojph_params_local.h:359
ojph::local::param_atk
Definition ojph_params_local.h:1085
ojph::local::param_atk::Natk
ui8 Natk
Definition ojph_params_local.h:1179
ojph::local::param_atk::read_coefficient
bool read_coefficient(infile_base *file, float &K, si32 &bytes)
Definition ojph_params.cpp:2390
ojph::local::param_atk::Katk
float Katk
Definition ojph_params_local.h:1178
ojph::local::param_atk::d
lifting_step * d
Definition ojph_params_local.h:1180
ojph::local::param_atk::is_m_init0
bool is_m_init0() const
Definition ojph_params_local.h:1143
ojph::local::param_atk::Satk
ui16 Satk
Definition ojph_params_local.h:1177
ojph::local::param_atk::d_store
lifting_step d_store[6]
Definition ojph_params_local.h:1182
ojph::local::param_atk::top_atk
param_atk * top_atk
Definition ojph_params_local.h:1185
ojph::local::param_atk::init
void init(param_atk *top_atk)
Definition ojph_params_local.h:1153
ojph::local::param_atk::param_atk
param_atk()
Definition ojph_params_local.h:1092
ojph::local::param_atk::is_reversible
bool is_reversible() const
Definition ojph_params_local.h:1142
ojph::local::param_atk::read
bool read(infile_base *file)
Definition ojph_params.cpp:2477
ojph::local::param_atk::add_object
param_atk * add_object()
Definition ojph_params.cpp:2606
ojph::local::param_atk::get_coeff_type
int get_coeff_type() const
Definition ojph_params_local.h:1140
ojph::local::param_atk::get_index
ui8 get_index() const
Definition ojph_params_local.h:1139
ojph::local::param_atk::Latk
ui16 Latk
Definition ojph_params_local.h:1176
ojph::local::param_atk::avail
param_atk * avail
Definition ojph_params_local.h:1189
ojph::local::param_atk::next
param_atk * next
Definition ojph_params_local.h:1183
ojph::local::param_atk::get_atk
param_atk * get_atk(int index)
Definition ojph_params.cpp:2357
ojph::local::param_atk::is_whole_sample
bool is_whole_sample() const
Definition ojph_params_local.h:1141
ojph::local::param_atk::max_steps
ui32 max_steps
Definition ojph_params_local.h:1181
ojph::local::param_atk::init_rev53
void init_rev53()
Definition ojph_params.cpp:2591
ojph::local::param_atk::init_irv97
void init_irv97()
Definition ojph_params.cpp:2577
ojph::local::param_atk::is_using_ws_extension
bool is_using_ws_extension() const
Definition ojph_params_local.h:1144
ojph::local::param_cap::read
void read(infile_base *file)
Definition ojph_params.cpp:809
ojph::local::param_cap::Pcap
ui32 Pcap
Definition ojph_params_local.h:912
ojph::local::param_cap::write
bool write(outfile_base *file)
Definition ojph_params.cpp:786
ojph::local::param_cap::Ccap
ui16 Ccap[32]
Definition ojph_params_local.h:913
ojph::local::param_cap::Lcap
ui16 Lcap
Definition ojph_params_local.h:911
ojph::local::param_cod
Definition ojph_params_local.h:385
ojph::local::param_cod::comp_idx
ui16 comp_idx
Definition ojph_params_local.h:663
ojph::local::param_cod::COD_MAIN
@ COD_MAIN
Definition ojph_params_local.h:401
ojph::local::param_cod::COC_MAIN
@ COC_MAIN
Definition ojph_params_local.h:402
ojph::local::param_cod::write
bool write(outfile_base *file)
Definition ojph_params.cpp:852
ojph::local::param_cod::get_coc
const param_cod * get_coc(ui32 comp_idx) const
Definition ojph_params.cpp:1087
ojph::local::param_cod::internal_write_coc
bool internal_write_coc(outfile_base *file, ui32 num_comps)
Definition ojph_params.cpp:909
ojph::local::param_cod::get_dfs_index
ui16 get_dfs_index() const
Definition ojph_params_local.h:614
ojph::local::param_cod::write_coc
bool write_coc(outfile_base *file, ui32 num_comps)
Definition ojph_params.cpp:894
ojph::local::param_cod::SGCod
cod_SGcod SGCod
Definition ojph_params_local.h:656
ojph::local::param_cod::atk
const param_atk * atk
Definition ojph_params_local.h:659
ojph::local::param_cod::is_employing_color_transform
bool is_employing_color_transform() const
Definition ojph_params_local.h:537
ojph::local::param_cod::get_comp_idx
ui32 get_comp_idx() const
Definition ojph_params_local.h:618
ojph::local::param_cod::avail
param_cod * avail
Definition ojph_params_local.h:666
ojph::local::param_cod::SPcod
cod_SPcod SPcod
Definition ojph_params_local.h:657
ojph::local::param_cod::OJPH_COD_DEFAULT
@ OJPH_COD_DEFAULT
Definition ojph_params_local.h:390
ojph::local::param_cod::top_cod
param_cod * top_cod
Definition ojph_params_local.h:662
ojph::local::param_cod::DWT_REV53
@ DWT_REV53
Definition ojph_params_local.h:409
ojph::local::param_cod::DWT_IRV97
@ DWT_IRV97
Definition ojph_params_local.h:408
ojph::local::param_cod::read
void read(infile_base *file)
Definition ojph_params.cpp:955
ojph::local::param_cod::init
void init(param_cod *top_cod, ui16 comp_idx)
Definition ojph_params_local.h:627
ojph::local::param_cod::read_coc
void read_coc(infile_base *file, ui32 num_comps, param_cod *top_cod)
Definition ojph_params.cpp:1004
ojph::local::param_cod::Lcod
ui16 Lcod
Definition ojph_params_local.h:654
ojph::local::param_cod::type
cod_type type
Definition ojph_params_local.h:653
ojph::local::param_cod::update_atk
void update_atk(param_atk *atk)
Definition ojph_params.cpp:1066
ojph::local::param_cod::Scod
ui8 Scod
Definition ojph_params_local.h:655
ojph::local::param_cod::is_dfs_defined
bool is_dfs_defined() const
Definition ojph_params_local.h:610
ojph::local::param_cod::get_num_decompositions
ui8 get_num_decompositions() const
Definition ojph_params_local.h:504
ojph::local::param_cod::is_reversible
bool is_reversible() const
Definition ojph_params.cpp:841
ojph::local::param_cod::param_cod
param_cod(param_cod *top_cod=NULL, ui16 comp_idx=OJPH_COD_DEFAULT)
Definition ojph_params_local.h:413
ojph::local::param_cod::get_wavelet_kern
ui8 get_wavelet_kern() const
Definition ojph_params_local.h:530
ojph::local::param_cod::add_coc_object
param_cod * add_coc_object(ui32 comp_idx)
Definition ojph_params.cpp:1110
ojph::local::param_cod::next
param_cod * next
Definition ojph_params_local.h:658
ojph::local::param_dfs
Definition ojph_params_local.h:993
ojph::local::param_dfs::read
bool read(infile_base *file)
Definition ojph_params.cpp:2302
ojph::local::param_dfs::get_dwt_type
dfs_dwt_type get_dwt_type(ui32 decomp_level) const
Definition ojph_params.cpp:2245
ojph::local::param_dfs::get_res_downsamp
point get_res_downsamp(ui32 skipped_resolutions) const
Definition ojph_params.cpp:2281
ojph::local::param_dfs::dfs_dwt_type
dfs_dwt_type
Definition ojph_params_local.h:995
ojph::local::param_dfs::HORZ_DWT
@ HORZ_DWT
Definition ojph_params_local.h:998
ojph::local::param_dfs::BIDIR_DWT
@ BIDIR_DWT
Definition ojph_params_local.h:997
ojph::local::param_dfs::VERT_DWT
@ VERT_DWT
Definition ojph_params_local.h:999
ojph::local::param_dfs::param_dfs
param_dfs()
Definition ojph_params_local.h:1003
ojph::local::param_dfs::next
param_dfs * next
Definition ojph_params_local.h:1050
ojph::local::param_dfs::Ddfs
ui8 Ddfs[8]
Definition ojph_params_local.h:1048
ojph::local::param_dfs::Sdfs
ui16 Sdfs
Definition ojph_params_local.h:1046
ojph::local::param_dfs::Ldfs
ui16 Ldfs
Definition ojph_params_local.h:1045
ojph::local::param_dfs::avail
param_dfs * avail
Definition ojph_params_local.h:1053
ojph::local::param_dfs::get_subband_idx
ui32 get_subband_idx(ui32 num_decompositions, ui32 resolution, ui32 subband) const
Definition ojph_params.cpp:2256
ojph::local::param_dfs::init
void init()
Definition ojph_params_local.h:1030
ojph::local::param_dfs::Ids
ui8 Ids
Definition ojph_params_local.h:1047
ojph::local::param_dfs::get_dfs
const param_dfs * get_dfs(int index) const
Definition ojph_params.cpp:2236
ojph::local::param_dfs::exists
bool exists() const
Definition ojph_params_local.h:1017
ojph::local::param_nlt::param_nlt
param_nlt()
Definition ojph_params_local.h:806
ojph::local::param_nlt::BDnlt
ui8 BDnlt
Definition ojph_params_local.h:858
ojph::local::param_nlt::write
bool write(outfile_base *file) const
Definition ojph_params.cpp:1928
ojph::local::param_nlt::add_object
param_nlt * add_object(ui32 comp_num)
Definition ojph_params.cpp:1996
ojph::local::param_nlt::avail
param_nlt * avail
Definition ojph_params_local.h:869
ojph::local::param_nlt::Tnlt
ui8 Tnlt
Definition ojph_params_local.h:859
ojph::local::param_nlt::trim_non_existing_components
void trim_non_existing_components(ui32 num_comps)
Definition ojph_params.cpp:2029
ojph::local::param_nlt::Lnlt
ui16 Lnlt
Definition ojph_params_local.h:856
ojph::local::param_nlt::read
void read(infile_base *file)
Definition ojph_params.cpp:1956
ojph::local::param_nlt::nonlinearity
ojph::param_nlt::nonlinearity nonlinearity
Definition ojph_params_local.h:804
ojph::local::param_nlt::next
param_nlt * next
Definition ojph_params_local.h:861
ojph::local::param_nlt::init
void init()
Definition ojph_params_local.h:828
ojph::local::param_nlt::get_nonlinear_transform
bool get_nonlinear_transform(ui32 comp_num, ui8 &bit_depth, bool &is_signed, ui8 &nl_type) const
Definition ojph_params.cpp:1910
ojph::local::param_nlt::Cnlt
ui16 Cnlt
Definition ojph_params_local.h:857
ojph::local::param_nlt::get_nlt_object
const param_nlt * get_nlt_object(ui32 comp_num) const
Definition ojph_params.cpp:1987
ojph::local::param_nlt::check_validity
void check_validity(param_siz &siz)
Definition ojph_params.cpp:1805
ojph::local::param_nlt::enabled
bool enabled
Definition ojph_params_local.h:860
ojph::local::param_nlt::is_any_enabled
bool is_any_enabled() const
Definition ojph_params.cpp:2019
ojph::local::param_nlt::set_nonlinear_transform
void set_nonlinear_transform(ui32 comp_num, ui8 nl_type)
Definition ojph_params.cpp:1894
ojph::local::param_qcd::encode_SPqcd
ui8 encode_SPqcd(ui8 v) const
Definition ojph_params_local.h:767
ojph::local::param_qcd::u16
ui16 u16[97]
Definition ojph_params_local.h:777
ojph::local::param_qcd::write_qcc
bool write_qcc(outfile_base *file, ui32 num_comps)
Definition ojph_params.cpp:1568
ojph::local::param_qcd::u8
ui8 u8[97]
Definition ojph_params_local.h:776
ojph::local::param_qcd::set_rev_quant
void set_rev_quant(ui32 num_decomps, ui32 bit_depth, bool is_employing_color_transform)
Definition ojph_params.cpp:1277
ojph::local::param_qcd::set_irrev_quant
void set_irrev_quant(ui32 num_decomps)
Definition ojph_params.cpp:1324
ojph::local::param_qcd::get_largest_Kmax
ui32 get_largest_Kmax() const
Definition ojph_params.cpp:1498
ojph::local::param_qcd::get_num_guard_bits
ui32 get_num_guard_bits() const
Definition ojph_params.cpp:1456
ojph::local::param_qcd::get_irrev_delta
float get_irrev_delta(const param_dfs *dfs, ui32 num_decompositions, ui32 resolution, ui32 subband) const
Definition ojph_params.cpp:1401
ojph::local::param_qcd::enabled
bool enabled
Definition ojph_params_local.h:782
ojph::local::param_qcd::set_delta
void set_delta(float delta)
Definition ojph_params_local.h:710
ojph::local::param_qcd::read_qcc
void read_qcc(infile_base *file, ui32 num_comps)
Definition ojph_params.cpp:1695
ojph::local::param_qcd::check_validity
void check_validity(const param_siz &siz, const param_cod &cod)
Definition ojph_params.cpp:1136
ojph::local::param_qcd::write
bool write(outfile_base *file)
Definition ojph_params.cpp:1525
ojph::local::param_qcd::propose_precision
ui32 propose_precision(const param_cod *cod) const
Definition ojph_params.cpp:1431
ojph::local::param_qcd::read
void read(infile_base *file)
Definition ojph_params.cpp:1648
ojph::local::param_qcd::init
void init(param_qcd *top_qcd, ui16 comp_idx)
Definition ojph_params_local.h:732
ojph::local::param_qcd::base_delta
float base_delta
Definition ojph_params_local.h:780
ojph::local::param_qcd::add_qcc_object
param_qcd * add_qcc_object(ui32 comp_idx)
Definition ojph_params.cpp:1779
ojph::local::param_qcd::type
qcd_type type
Definition ojph_params_local.h:771
ojph::local::param_qcd::top_qcd
param_qcd * top_qcd
Definition ojph_params_local.h:784
ojph::local::param_qcd::num_subbands
ui32 num_subbands
Definition ojph_params_local.h:779
ojph::local::param_qcd::QCD_MAIN
@ QCD_MAIN
Definition ojph_params_local.h:688
ojph::local::param_qcd::QCC_MAIN
@ QCC_MAIN
Definition ojph_params_local.h:689
ojph::local::param_qcd::get_MAGB
ui32 get_MAGB() const
Definition ojph_params.cpp:1366
ojph::local::param_qcd::avail
param_qcd * avail
Definition ojph_params_local.h:790
ojph::local::param_qcd::get_Kmax
ui32 get_Kmax(const param_dfs *dfs, ui32 num_decompositions, ui32 resolution, ui32 subband) const
Definition ojph_params.cpp:1462
ojph::local::param_qcd::Lqcd
ui16 Lqcd
Definition ojph_params_local.h:772
ojph::local::param_qcd::comp_idx
ui16 comp_idx
Definition ojph_params_local.h:787
ojph::local::param_qcd::decode_SPqcd
ui8 decode_SPqcd(ui8 v) const
Definition ojph_params_local.h:765
ojph::local::param_qcd::get_qcc
param_qcd * get_qcc(ui32 comp_idx)
Definition ojph_params.cpp:1756
ojph::local::param_qcd::param_qcd
param_qcd(param_qcd *top_qcd=NULL, ui16 comp_idx=OJPH_QCD_DEFAULT)
Definition ojph_params_local.h:695
ojph::local::param_qcd::next
param_qcd * next
Definition ojph_params_local.h:783
ojph::local::param_qcd::OJPH_QCD_DEFAULT
@ OJPH_QCD_DEFAULT
Definition ojph_params_local.h:682
ojph::local::param_qcd::trim_non_existing_components
void trim_non_existing_components(ui32 num_comps)
Definition ojph_params.cpp:1635
ojph::local::param_qcd::internal_write_qcc
bool internal_write_qcc(outfile_base *file, ui32 num_comps)
Definition ojph_params.cpp:1583
ojph::local::param_qcd::SPqcd
union ojph::local::param_qcd::@140013103227173134364232343330020031205064137337 SPqcd
ojph::local::param_qcd::Sqcd
ui8 Sqcd
Definition ojph_params_local.h:773
ojph::local::param_siz
Definition ojph_params_local.h:166
ojph::local::param_siz::skipped_resolutions
ui32 skipped_resolutions
Definition ojph_params_local.h:326
ojph::local::param_siz::cptr
siz_comp_info * cptr
Definition ojph_params_local.h:323
ojph::local::param_siz::YOsiz
ui32 YOsiz
Definition ojph_params_local.h:317
ojph::local::param_siz::YTsiz
ui32 YTsiz
Definition ojph_params_local.h:319
ojph::local::param_siz::get_bit_depth
ui32 get_bit_depth(ui32 comp_num) const
Definition ojph_params_local.h:252
ojph::local::param_siz::ws_kern_support_needed
bool ws_kern_support_needed
Definition ojph_params_local.h:329
ojph::local::param_siz::is_signed
bool is_signed(ui32 comp_num) const
Definition ojph_params_local.h:257
ojph::local::param_siz::set_image_offset
void set_image_offset(point offset)
Definition ojph_params_local.h:224
ojph::local::param_siz::XTOsiz
ui32 XTOsiz
Definition ojph_params_local.h:320
ojph::local::param_siz::write
bool write(outfile_base *file)
Definition ojph_params.cpp:635
ojph::local::param_siz::get_num_components
ui16 get_num_components() const
Definition ojph_params_local.h:251
ojph::local::param_siz::set_tile_size
void set_tile_size(size s)
Definition ojph_params_local.h:222
ojph::local::param_siz::cod
const param_cod * cod
Definition ojph_params_local.h:331
ojph::local::param_siz::get_recon_downsampling
point get_recon_downsampling(ui32 comp_num) const
Definition ojph_params.cpp:749
ojph::local::param_siz::set_Rsiz_flag
void set_Rsiz_flag(ui16 flag)
Definition ojph_params_local.h:306
ojph::local::param_siz::check_validity
void check_validity()
Definition ojph_params_local.h:235
ojph::local::param_siz::XOsiz
ui32 XOsiz
Definition ojph_params_local.h:316
ojph::local::param_siz::Csiz
ui16 Csiz
Definition ojph_params_local.h:322
ojph::local::param_siz::get_recon_size
point get_recon_size(ui32 comp_num) const
Definition ojph_params.cpp:765
ojph::local::param_siz::Xsiz
ui32 Xsiz
Definition ojph_params_local.h:314
ojph::local::param_siz::RSIZ_NLT_FLAG
@ RSIZ_NLT_FLAG
Definition ojph_params_local.h:171
ojph::local::param_siz::RSIZ_EXT_FLAG
@ RSIZ_EXT_FLAG
Definition ojph_params_local.h:173
ojph::local::param_siz::dfs
const param_dfs * dfs
Definition ojph_params_local.h:332
ojph::local::param_siz::dfs_support_needed
bool dfs_support_needed
Definition ojph_params_local.h:330
ojph::local::param_siz::YTOsiz
ui32 YTOsiz
Definition ojph_params_local.h:321
ojph::local::param_siz::Rsiz
ui16 Rsiz
Definition ojph_params_local.h:313
ojph::local::param_siz::Lsiz
ui16 Lsiz
Definition ojph_params_local.h:312
ojph::local::param_siz::XTsiz
ui32 XTsiz
Definition ojph_params_local.h:318
ojph::local::param_siz::set_tile_offset
void set_tile_offset(point offset)
Definition ojph_params_local.h:228
ojph::local::param_siz::read
void read(infile_base *file)
Definition ojph_params.cpp:680
ojph::local::param_siz::Ysiz
ui32 Ysiz
Definition ojph_params_local.h:315
ojph::local::param_siz::set_num_components
void set_num_components(ui32 num_comps)
Definition ojph_params_local.h:197
ojph::local::param_sot::TPsot
ui8 TPsot
Definition ojph_params_local.h:950
ojph::local::param_sot::read
bool read(infile_base *file, bool resilient)
Definition ojph_params.cpp:2097
ojph::local::param_sot::TNsot
ui8 TNsot
Definition ojph_params_local.h:951
ojph::local::param_sot::Lsot
ui16 Lsot
Definition ojph_params_local.h:947
ojph::local::param_sot::write
bool write(outfile_base *file, ui32 payload_len)
Definition ojph_params.cpp:2052
ojph::local::param_sot::Isot
ui16 Isot
Definition ojph_params_local.h:948
ojph::local::param_sot::Psot
ui32 Psot
Definition ojph_params_local.h:949
ojph::local::param_tlm::Ttlm_Ptlm_pair
Definition ojph_params_local.h:964
ojph::local::param_tlm::next_pair_index
ui32 next_pair_index
Definition ojph_params_local.h:982
ojph::local::param_tlm::Ltlm
ui16 Ltlm
Definition ojph_params_local.h:977
ojph::local::param_tlm::set_next_pair
void set_next_pair(ui16 Ttlm, ui32 Ptlm)
Definition ojph_params.cpp:2195
ojph::local::param_tlm::write
bool write(outfile_base *file)
Definition ojph_params.cpp:2204
ojph::local::param_tlm::Ztlm
ui8 Ztlm
Definition ojph_params_local.h:978
ojph::local::param_tlm::pairs
Ttlm_Ptlm_pair * pairs
Definition ojph_params_local.h:980
ojph::local::param_tlm::Stlm
ui8 Stlm
Definition ojph_params_local.h:979
ojph::local::param_tlm::num_pairs
ui32 num_pairs
Definition ojph_params_local.h:981
ojph::local::param_tlm::init
void init(ui32 num_pairs, Ttlm_Ptlm_pair *store)
Definition ojph_params.cpp:2179
ojph::point
Definition ojph_base.h:58
ojph::point::y
ui32 y
Definition ojph_base.h:60
ojph::point::x
ui32 x
Definition ojph_base.h:60
ojph::size
Definition ojph_base.h:48
ojph::size::w
ui32 w
Definition ojph_base.h:50
ojph::size::h
ui32 h
Definition ojph_base.h:51
ojph::local::lifting_step
Definition ojph_params_local.h:1065