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