OpenJPH
Open-source implementation of JPEG2000 Part-15
Loading...
Searching...
No Matches
ojph_params_local.h
Go to the documentation of this file.
1//***************************************************************************/
2// This software is released under the 2-Clause BSD license, included
3// below.
4//
5// Copyright (c) 2019, Aous Naman
6// Copyright (c) 2019, Kakadu Software Pty Ltd, Australia
7// Copyright (c) 2019, The University of New South Wales, Australia
8//
9// Redistribution and use in source and binary forms, with or without
10// modification, are permitted provided that the following conditions are
11// met:
12//
13// 1. Redistributions of source code must retain the above copyright
14// notice, this list of conditions and the following disclaimer.
15//
16// 2. Redistributions in binary form must reproduce the above copyright
17// notice, this list of conditions and the following disclaimer in the
18// documentation and/or other materials provided with the distribution.
19//
20// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
26// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31//***************************************************************************/
32// This file is part of the OpenJPH software implementation.
33// File: ojph_params_local.h
34// Author: Aous Naman
35// Date: 28 August 2019
36//***************************************************************************/
37
38
39#ifndef OJPH_PARAMS_LOCAL_H
40#define OJPH_PARAMS_LOCAL_H
41
42#include <cstring>
43#include <cassert>
44
45#include "ojph_defs.h"
46#include "ojph_base.h"
47#include "ojph_arch.h"
48#include "ojph_message.h"
49
50namespace ojph {
51
53 class outfile_base;
54 class infile_base;
55
65
67 const char OJPH_PO_STRING_LRCP[] = "LRCP";
68 const char OJPH_PO_STRING_RLCP[] = "RLCP";
69 const char OJPH_PO_STRING_RPCL[] = "RPCL";
70 const char OJPH_PO_STRING_PCRL[] = "PCRL";
71 const char OJPH_PO_STRING_CPRL[] = "CPRL";
72
86
88 const char OJPH_PN_STRING_PROFILE0[] = "PROFILE0";
89 const char OJPH_PN_STRING_PROFILE1[] = "PROFILE1";
90 const char OJPH_PN_STRING_CINEMA2K[] = "CINEMA2K";
91 const char OJPH_PN_STRING_CINEMA4K[] = "CINEMA4K";
92 const char OJPH_PN_STRING_CINEMAS2K[] = "CINEMAS2K";
93 const char OJPH_PN_STRING_CINEMAS4K[] = "CINEMAS4K";
94 const char OJPH_PN_STRING_BROADCAST[] = "BROADCAST";
95 const char OJPH_PN_STRING_IMF[] = "IMF";
96
99 OJPH_TILEPART_NO_DIVISIONS = 0x0, // no divisions to tile parts
102 OJPH_TILEPART_LAYERS = 0x4, // these are meaningless with HTJ2K
103 OJPH_TILEPART_MASK = 0x3, // mask used for testing
104 };
105
106 namespace local {
107
108 //defined here
109 struct param_siz;
110 struct param_cod;
111 struct param_qcd;
112 struct param_cap;
113 struct param_sot;
114 struct param_tlm;
115 struct param_dfs;
116 struct param_atk;
117
120 {
121 SOC = 0xFF4F, //start of codestream (required)
122 CAP = 0xFF50, //extended capability
123 SIZ = 0xFF51, //image and tile size (required)
124 COD = 0xFF52, //coding style default (required)
125 COC = 0xFF53, //coding style component
126 TLM = 0xFF55, //tile-part lengths
127 PRF = 0xFF56, //profile
128 PLM = 0xFF57, //packet length, main header
129 PLT = 0xFF58, //packet length, tile-part header
130 CPF = 0xFF59, //corresponding profile values
131 QCD = 0xFF5C, //qunatization default (required)
132 QCC = 0xFF5D, //quantization component
133 RGN = 0xFF5E, //region of interest
134 POC = 0xFF5F, //progression order change
135 PPM = 0xFF60, //packed packet headers, main header
136 PPT = 0xFF61, //packed packet headers, tile-part header
137 CRG = 0xFF63, //component registration
138 COM = 0xFF64, //comment
139 DFS = 0xFF72, //downsampling factor styles
140 ADS = 0xFF73, //arbitrary decomposition styles
141 NLT = 0xFF76, //non-linearity point transformation
142 ATK = 0xFF79, //arbitrary transformation kernels
143 SOT = 0xFF90, //start of tile-part
144 SOP = 0xFF91, //start of packet
145 EPH = 0xFF92, //end of packet
146 SOD = 0xFF93, //start of data
147 EOC = 0xFFD9, //end of codestream (required)
148 };
149
151 //
152 //
153 //
154 //
155 //
163
166 {
167 friend ::ojph::param_siz;
168
169 public:
170 enum : ui16 {
172 RSIZ_HT_FLAG = 0x4000,
174 };
175
176 public:
179
180 void init()
181 {
182 Lsiz = Csiz = 0;
183 Xsiz = Ysiz = XOsiz = YOsiz = XTsiz = YTsiz = XTOsiz = YTOsiz = 0;
185 memset(store, 0, sizeof(store));
187 cod = NULL;
188 dfs = NULL;
190 cptr = store;
191 old_Csiz = sizeof(store) / sizeof(siz_comp_info);
192 }
193
194 void destroy()
195 { if (cptr != store) { delete[] cptr; cptr = NULL; } }
196
197 void set_num_components(ui32 num_comps)
198 {
199 Csiz = (ui16)num_comps;
200 if (Csiz > old_Csiz)
201 {
202 if (cptr != store)
203 delete[] cptr;
204 cptr = new siz_comp_info[num_comps];
205 old_Csiz = Csiz;
206 }
207 memset(cptr, 0, sizeof(local::siz_comp_info) * num_comps);
208 }
209
210 void set_comp_info(ui32 comp_num, const point& downsampling,
211 ui32 bit_depth, bool is_signed)
212 {
213 assert(comp_num < Csiz);
214 assert(downsampling.x != 0 && downsampling.y != 0);
215 cptr[comp_num].SSiz = (ui8)(bit_depth - 1 + (is_signed ? 0x80 : 0));
216 cptr[comp_num].XRsiz = (ui8)downsampling.x;
217 cptr[comp_num].YRsiz = (ui8)downsampling.y;
218 }
219
221 {
222 this->cod = &cod;
223
224 if (XTsiz == 0 && YTsiz == 0)
225 { XTsiz = Xsiz + XOsiz; YTsiz = Ysiz + YOsiz; }
226 if (Xsiz == 0 || Ysiz == 0 || XTsiz == 0 || YTsiz == 0)
227 OJPH_ERROR(0x00040001,
228 "You cannot set image extent nor tile size to zero");
229 if (XTOsiz > XOsiz || YTOsiz > YOsiz)
230 OJPH_ERROR(0x00040002,
231 "tile offset has to be smaller than image offset");
232 if (XTsiz + XTOsiz <= XOsiz || YTsiz + YTOsiz <= YOsiz)
233 OJPH_ERROR(0x00040003,
234 "the top left tile must intersect with the image");
235 }
236
237 ui16 get_num_components() const { return Csiz; }
238 ui32 get_bit_depth(ui32 comp_num) const
239 {
240 assert(comp_num < Csiz);
241 return (cptr[comp_num].SSiz & 0x7F) + 1u;
242 }
243 bool is_signed(ui32 comp_num) const
244 {
245 assert(comp_num < Csiz);
246 return (cptr[comp_num].SSiz & 0x80) != 0;
247 }
249 {
250 assert(comp_num < Csiz);
251 return point(cptr[comp_num].XRsiz, cptr[comp_num].YRsiz);
252 }
253
254 bool write(outfile_base *file);
255 void read(infile_base *file);
256
257 void link(const param_cod* cod)
258 { this->cod = cod; }
259
260 void link(const param_dfs* dfs)
261 { this->dfs = dfs; }
262
264 { this->skipped_resolutions = skipped_resolutions; }
265
266 ui32 get_width(ui32 comp_num) const
267 {
268 assert(comp_num < get_num_components());
269 ui32 ds = (ui32)cptr[comp_num].XRsiz;
270 ui32 t = ojph_div_ceil(Xsiz, ds) - ojph_div_ceil(XOsiz, ds);
271 return t;
272 }
273
274 ui32 get_height(ui32 comp_num) const
275 {
276 assert(comp_num < get_num_components());
277 ui32 ds = (ui32)cptr[comp_num].YRsiz;
278 ui32 t = ojph_div_ceil(Ysiz, ds) - ojph_div_ceil(YOsiz, ds);
279 return t;
280 }
281
282 point get_recon_downsampling(ui32 comp_num) const;
283 point get_recon_size(ui32 comp_num) const;
284 ui32 get_recon_width(ui32 comp_num) const
285 { return get_recon_size(comp_num).x; }
286 ui32 get_recon_height(ui32 comp_num) const
287 { return get_recon_size(comp_num).y; }
288
291
293 { Rsiz |= flag; }
295 { Rsiz = (ui16)(Rsiz & ~flag); }
296
297 private:
310
311 private:
319 param_siz(const param_siz&) = delete; //prevent copy constructor
320 param_siz& operator=(const param_siz&) = delete; //prevent copy
321 };
322
324 //
325 //
326 //
327 //
328 //
331 {
333 num_decomp = 5;
334 block_width = 4; // 64
335 block_height = 4; // 64
336 block_style = 0x40; // HT mode
337 wavelet_trans = 0; // reversible 5 / 3
338 memset(precinct_size, 0, sizeof(precinct_size));
339 }
340
346 ui8 precinct_size[33]; //num_decomp is in [0,32]
347
349 { return size(block_width + 2, block_height + 2); }
351 { size t = get_log_block_dims(); return size(1 << t.w, 1 << t.h); }
353 {
354 assert(res_num <= num_decomp);
355 size ps(precinct_size[res_num] & 0xF, precinct_size[res_num] >> 4);
356 return ps;
357 }
358 };
359
368
371 {
372 // serves for both COD and COC markers
373 friend ::ojph::param_cod;
378
384
385 enum cod_type : ui8 {
389 COD_TILE = 3, // not implemented
390 COC_TILE = 4 // not implemented
391 };
392
393 enum dwt_type : ui8 {
396 };
397
398 public: // COD_MAIN and COC_MAIN common functions
402
404 void restart()
405 {
406 param_cod** p = &avail; // move next to the end of avail
407 while (*p != NULL)
408 p = &((*p)->next);
409 *p = next;
411 }
412
414 void set_reversible(bool reversible)
415 {
416 assert(type == UNDEFINED || type == COD_MAIN || type == COC_MAIN);
417 SPcod.wavelet_trans = reversible ? DWT_REV53 : DWT_IRV97;
418 }
419
422 {
423 assert(val == 0 || val == 1);
424 assert(type == UNDEFINED || type == COD_MAIN);
425 SGCod.mc_trans = val;
426 }
427
429 void check_validity(const param_siz& siz)
430 {
431 assert(type == COD_MAIN);
432
433 //check that colour transform and match number of components and
434 // downsampling
435 int num_comps = siz.get_num_components();
436 if (SGCod.mc_trans == 1 && num_comps < 3)
437 OJPH_ERROR(0x00040011,
438 "color transform can only be employed when the image has 3 or "
439 "more color components");
440
441 if (SGCod.mc_trans == 1)
442 {
443 bool test_signedness = false;
444 bool test_bit_depth = false;
445 bool test_downsampling = false;
446 point p = siz.get_downsampling(0);
447 ui32 bit_depth = siz.get_bit_depth(0);
448 bool is_signed = siz.is_signed(0);
449 for (ui32 i = 1; i < 3; ++i)
450 {
451 point p1 = siz.get_downsampling(i);
452 test_downsampling = test_downsampling
453 || (p.x != p1.x || p.y != p1.y);
454 test_bit_depth = test_bit_depth
455 || (bit_depth != siz.get_bit_depth(i));
456 test_signedness = test_signedness
457 || (is_signed != siz.is_signed(i));
458 }
459 if (test_downsampling)
460 OJPH_ERROR(0x00040012,
461 "when color transform is used, the first 3 colour components "
462 "must have the same downsampling factor.");
463 if (test_bit_depth)
464 OJPH_ERROR(0x00040014,
465 "when color transform is used, the first 3 colour components "
466 "must have the same bit depth.");
467 if (test_signedness)
468 OJPH_ERROR(0x00040015,
469 "when color transform is used, the first 3 colour components "
470 "must have the same signedness (signed or unsigned).");
471
472 }
473
474 //check the progression order matches downsampling
475 if (SGCod.prog_order == OJPH_PO_RPCL ||
476 SGCod.prog_order == OJPH_PO_PCRL)
477 {
478 ui32 num_comps = siz.get_num_components();
479 for (ui32 i = 0; i < num_comps; ++i)
480 {
481 point r = siz.get_downsampling(i);
482 if (r.x & (r.x - 1) || r.y & (r.y - 1))
483 OJPH_ERROR(0x00040013, "For RPCL and PCRL progression orders,"
484 "component downsampling factors have to be powers of 2");
485 }
486 }
487 }
488
491 {
492 if (type == COD_MAIN)
493 return SPcod.num_decomp;
494 else if (type == COC_MAIN)
495 {
496 if (is_dfs_defined())
497 return top_cod->get_num_decompositions();
498 else
499 return SPcod.num_decomp;
500 }
501 else {
502 assert(0);
503 return 0; // just in case
504 }
505 }
506
509 { return SPcod.get_block_dims(); }
510
513 { return SPcod.get_log_block_dims(); }
514
517 { return SPcod.wavelet_trans; }
518
520 bool is_reversible() const;
521
524 {
525 if (type == COD_MAIN || type == COD_TILE)
526 return (SGCod.mc_trans == 1);
527 else
528 return top_cod->is_employing_color_transform();
529 }
530
533 {
534 size t = get_log_precinct_size(res_num);
535 return size(1 << t.w, 1 << t.h);
536 }
537
540 {
541 if (Scod & 1)
542 return SPcod.get_log_precinct_size(res_num);
543 else
544 return size(15, 15);
545 }
546
549 {
550 if (type == COD_MAIN || type == COD_TILE)
551 return (Scod & 2) == 2;
552 return false;
553 }
554
556 bool packets_use_eph() const
557 {
558 if (type == COD_MAIN || type == COD_TILE)
559 return (Scod & 4) == 4;
560 return false;
561 }
562
565 { return (SPcod.block_style & local::param_cod::VERT_CAUSAL_MODE) != 0; }
566
568 bool write(outfile_base *file);
569
571 bool write_coc(outfile_base *file, ui32 num_comps);
572
574 void read(infile_base *file);
575
577 void read_coc(infile_base* file, ui32 num_comps, param_cod* top_cod);
578
580 void update_atk(param_atk* atk);
581
583 const param_cod* get_coc(ui32 comp_idx) const;
584
587
590
592 const param_atk* access_atk() const { return atk; }
593
594 public: // COC_MAIN only functions
596 bool is_dfs_defined() const
597 { return (SPcod.num_decomp & 0x80) != 0; }
598
600 ui16 get_dfs_index() const // cannot be more than 15
601 { return SPcod.num_decomp & 0xF; }
602
605 {
606 assert((type == COC_MAIN && comp_idx != OJPH_COD_DEFAULT) ||
608 return comp_idx;
609 }
610
611 private:
614 {
616 Lcod = 0;
617 Scod = 0;
618 next = NULL;
619 atk = NULL;
620 this->top_cod = top_cod;
621 this->comp_idx = comp_idx;
622 }
623
625 void destroy() {
626 if (avail)
627 delete avail;
628 if (next) {
629 delete next;
630 next = NULL;
631 }
632 }
633
634 private:
635 bool internal_write_coc(outfile_base *file, ui32 num_comps);
636
638 private: // Common variables
639 cod_type type; // The type of this cod structure
640 ui16 Lcod; // serves as Lcod and Scod
641 ui8 Scod; // serves as Scod and Scoc
642 cod_SGcod SGCod; // Used in COD and copied to COC
643 cod_SPcod SPcod; // serves as SPcod and SPcoc
644 param_cod* next; // to chain coc parameters to cod
645 const param_atk* atk; // used to read transform information
646
647 private: // COC only variables
648 param_cod* top_cod; // parent COD structure
649 ui16 comp_idx; // component index of this COC structure
650
651 private: // on restart, already allocated param_cod objs are stored here
653 };
654
656 //
657 //
658 //
659 //
660 //
663 {
664 // serves for both QCD and QCC markers
665 friend ::ojph::param_qcd;
670
672 enum qcd_type : ui8 {
676 QCD_TILE = 3, // not implemented
677 QCC_TILE = 4 // not implemented
678 };
679
680 public:
684
686 void restart()
687 {
688 param_qcd** p = &avail; // move next to the end of avail
689 while (*p != NULL)
690 p = &((*p)->next);
691 *p = next;
693 }
694
695 void check_validity(const param_siz& siz, const param_cod& cod);
696 void set_delta(float delta) { base_delta = delta; }
697 void set_delta(ui32 comp_idx, float delta);
698 ui32 get_num_guard_bits() const;
699 ui32 get_MAGB() const;
700 ui32 get_Kmax(const param_dfs* dfs, ui32 num_decompositions,
701 ui32 resolution, ui32 subband) const;
702 ui32 propose_precision(const param_cod* cod) const;
703 float get_irrev_delta(const param_dfs* dfs,
704 ui32 num_decompositions,
705 ui32 resolution, ui32 subband) const;
706 bool write(outfile_base *file);
707 bool write_qcc(outfile_base *file, ui32 num_comps);
708 void read(infile_base *file);
709 void read_qcc(infile_base *file, ui32 num_comps);
710
712 const param_qcd* get_qcc(ui32 comp_idx) const;
714 ui16 get_comp_idx() const { return comp_idx; }
715
716 private:
719 {
721 Lqcd = 0;
722 Sqcd = 0;
723 memset(&SPqcd, 0, sizeof(SPqcd));
724 num_subbands = 0;
725 base_delta = -1.0f;
726 enabled = true;
727 next = NULL;
728 this->top_qcd = top_qcd;
729 this->comp_idx = comp_idx;
730 }
731
733 void destroy() {
734 if (avail)
735 delete avail;
736 if (next)
737 {
738 delete next;
739 next = NULL;
740 }
741 }
742
743 private:
744 void set_rev_quant(ui32 num_decomps, ui32 bit_depth,
745 bool is_employing_color_transform);
746 void set_irrev_quant(ui32 num_decomps);
747 ui32 get_largest_Kmax() const;
748 bool internal_write_qcc(outfile_base *file, ui32 num_comps);
749 void trim_non_existing_components(ui32 num_comps);
750
752 { return (ui8)(v >> 3); }
754 { return (ui8)(v << 3); }
755
756 private: // QCD variables
760 union
761 {
762 ui8 u8[97];
765 ui32 num_subbands; // number of subbands
766 float base_delta; // base quantization step size -- all other
767 // step sizes are derived from it.
768 bool enabled; // enabled if two, and ignored if false
769 param_qcd *next; // pointer to create chains of qcc marker segments
770 param_qcd *top_qcd; // pointer to the top QCD (this is the default)
771
772 private: // QCC only variables
774
775 private: // on restart, already allocated param_qcd objs are stored here
777 };
778
780 //
781 //
782 //
783 //
784 //
786 // data structures used by param_nlt
788 {
791 public:
792 param_nlt() { avail = NULL; init(); }
794
796 void restart()
797 {
798 param_nlt** p = &avail; // move next to the end of avail
799 while (*p != NULL)
800 p = &((*p)->next);
801 *p = next;
802 this->init();
803 }
804
805 void check_validity(param_siz& siz);
806 void set_nonlinear_transform(ui32 comp_num, ui8 nl_type);
807 bool get_nonlinear_transform(ui32 comp_num, ui8& bit_depth,
808 bool& is_signed, ui8& nl_type) const;
809 bool write(outfile_base* file) const;
810 void read(infile_base* file);
811
812 private:
814 void init()
815 {
816 Lnlt = 6;
817 Cnlt = special_comp_num::ALL_COMPS; // default
818 BDnlt = 0;
819 Tnlt = nonlinearity::OJPH_NLT_UNDEFINED;
820 enabled = false; next = NULL;
821 }
822
824 void destroy()
825 {
826 if (avail)
827 delete avail;
828 if (next) {
829 delete next;
830 next = NULL;
831 }
832 }
833
834 private:
835 const param_nlt* get_nlt_object(ui32 comp_num) const;
836 param_nlt* get_nlt_object(ui32 comp_num);
837 param_nlt* add_object(ui32 comp_num);
838 bool is_any_enabled() const;
839 void trim_non_existing_components(ui32 num_comps);
840
841 private:
842 ui16 Lnlt; // length of the marker segment excluding marker
843 ui16 Cnlt; // Component involved in the transformation
844 ui8 BDnlt; // Decoded image component bit depth parameter
845 ui8 Tnlt; // Type of non-linearity
846 bool enabled; // true if this object is used
847 param_nlt* next; // for chaining NLT markers
848
849 // The top level param_nlt object is not allocated, but as part of
850 // codestream, and is used to manage allocated next objects.
851 // next holds a list of param_nlt objects, which are managed by the top
852 // param_nlt object.
853
854 private: // on restart, already allocated param_nlt objs are stored here
856 };
857
859 //
860 //
861 //
862 //
863 //
866 {
867 public:
869 {
870 memset(this, 0, sizeof(param_cap));
871 Lcap = 8;
872 Pcap = 0x00020000; //for jph, Pcap^15 must be set, the 15th MSB
873 }
874
875 void check_validity(const param_cod& cod, const param_qcd& qcd)
876 {
878 Ccap[0] &= 0xFFDF;
879 else
880 Ccap[0] |= 0x0020;
881 Ccap[0] &= 0xFFE0;
882 ui32 Bp = 0;
883 ui32 B = qcd.get_MAGB();
884 if (B <= 8)
885 Bp = 0;
886 else if (B < 28)
887 Bp = B - 8;
888 else
889 Bp = 13 + (B >> 2);
890 Ccap[0] = (ui16)(Ccap[0] | (ui16)Bp);
891 }
892
893 bool write(outfile_base *file);
894 void read(infile_base *file);
895
896 private:
899 ui16 Ccap[32]; //a maximum of 32
900 };
901
902
904 //
905 //
906 //
907 //
908 //
911 {
912 public:
913 void init(ui32 payload_length = 0, ui16 tile_idx = 0,
914 ui8 tile_part_index = 0, ui8 num_tile_parts = 0)
915 {
916 Lsot = 10;
917 Psot = payload_length + 12; //total = payload + SOT marker
918 Isot = tile_idx;
919 TPsot = tile_part_index;
920 TNsot = num_tile_parts;
921 }
922
923 bool write(outfile_base *file, ui32 payload_len);
924 bool write(outfile_base *file, ui32 payload_len, ui8 TPsot, ui8 TNsot);
925 bool read(infile_base *file, bool resilient);
926
927 ui16 get_tile_index() const { return Isot; }
928 ui32 get_payload_length() const { return Psot > 0 ? Psot - 12 : 0; }
929 ui8 get_tile_part_index() const { return TPsot; }
930 ui8 get_num_tile_parts() const { return TNsot; }
931
932 private:
938 };
939
941 //
942 //
943 //
944 //
945 //
948 {
950 {
953 };
954
955 public:
956 param_tlm() { pairs = NULL; num_pairs = 0; next_pair_index = 0; };
957 void init(ui32 num_pairs, Ttlm_Ptlm_pair* store);
958
959 void set_next_pair(ui16 Ttlm, ui32 Ptlm);
960 bool write(outfile_base *file);
961
962 private:
969 };
970
972 //
973 //
974 //
975 //
976 //
979 {
980 public:
982 NO_DWT = 0, // no wavelet transform
983 BIDIR_DWT = 1, // bidirectional DWT (this the conventional DWT)
984 HORZ_DWT = 2, // horizontal only DWT transform
985 VERT_DWT = 3, // vertical only DWT transform
986 };
987
988 public: // member functions
989 param_dfs() { avail = NULL; init(); }
991
993 void restart()
994 {
995 param_dfs** p = &avail; // move next to the end of avail
996 while (*p != NULL)
997 p = &((*p)->next);
998 *p = next;
999 this->init();
1000 }
1001
1002 bool read(infile_base *file);
1003 bool exists() const { return Ldfs != 0; }
1004
1005 // get_dfs return a dfs structure Sdfs == index, or NULL if not found
1006 const param_dfs* get_dfs(int index) const;
1007 // decomp_level is the decomposition level, starting from 1 for highest
1008 // resolution to num_decomps for the coarsest resolution
1009 dfs_dwt_type get_dwt_type(ui32 decomp_level) const;
1010 ui32 get_subband_idx(ui32 num_decompositions, ui32 resolution,
1011 ui32 subband) const;
1012 point get_res_downsamp(ui32 skipped_resolutions) const;
1013
1014 private:
1016 void init()
1017 { Ldfs = Sdfs = Ids = 0; memset(Ddfs, 0, sizeof(Ddfs)); next = NULL; }
1018
1020 void destroy()
1021 {
1022 if (avail)
1023 delete avail;
1024 if (next) {
1025 delete next;
1026 next = NULL;
1027 }
1028 }
1029
1030 private: // member variables
1031 ui16 Ldfs; // length of the segment marker
1032 ui16 Sdfs; // index of this DFS marker segment
1033 ui8 Ids; // number of elements in Ddfs, 2 bits per sub-level
1034 ui8 Ddfs[8]; // a string defining number of decomposition sub-levels
1035 // 8 bytes should be enough for 32 levels
1036 param_dfs* next; // used for linking other dfs segments
1037
1038 private: // on restart, already allocated param_dfs objs are stored here
1040 };
1041
1043 //
1044 //
1045 //
1046 //
1047 //
1049 // data structures used by param_atk
1050
1052 struct irv_data {
1053 // si8 Oatk; // only for arbitrary filter
1054 // ui8 LCatk; // number of lifting coefficients in a step
1055 float Aatk; // lifting coefficient
1056 };
1057
1058 struct rev_data {
1059 // si8 Oatk; // only for arbitrary filter, offset of filter
1060 ui8 Eatk; // only for reversible, epsilon, the power of 2
1061 si16 Batk; // only for reversible, beta, the additive residue
1062 // ui8 LCatk; // number of lifting coefficients in a step
1063 si16 Aatk; // lifting coefficient
1064 };
1065
1068 };
1069
1071 {
1072 // Limitations:
1073 // Arbitrary filters (ARB) are not supported
1074 // Only one coefficient per step -- first order filter
1075 // Only even-indexed subsequence in first reconstruction step,
1076 // m_init = 0 is supported
1077 private:
1078 enum : ui8 { // this is not a real parameter; it used for debugging
1081 };
1082
1083 public: // member functions
1085 avail = NULL;
1086 d = d_store;
1087 max_steps = sizeof(d_store) / sizeof(lifting_step);
1088 this->top_atk = top_atk;
1089 this->type = type;
1090 init(this);
1091 }
1093
1095 void restart()
1096 {
1097 assert(type == OJPH_ATK_TOP);
1098 param_atk** p = &avail; // move next to the end of avail
1099 while (*p != NULL)
1100 p = &((*p)->next);
1101 *p = next;
1102 this->init(this);
1103 }
1104
1105 bool read(infile_base *file);
1106
1107 ui8 get_index() const { return (ui8)(Satk & 0xFF); }
1108 int get_coeff_type() const { return (Satk >> 8) & 0x7; }
1109 bool is_whole_sample() const { return (Satk & 0x800) != 0; }
1110 bool is_reversible() const { return (Satk & 0x1000) != 0; }
1111 bool is_m_init0() const { return (Satk & 0x2000) == 0; }
1112 bool is_using_ws_extension() const { return (Satk & 0x4000) != 0; }
1113 param_atk* get_atk(int index);
1115 { assert(s < Natk); return d + s; }
1116 ui32 get_num_steps() const { return Natk; }
1117 float get_K() const { return Katk; }
1118
1119 private:
1122 {
1123 Latk = Satk = 0;
1124 Katk = 0.0f;
1125 Natk = 0;
1126 next = NULL;
1127 this->top_atk = top_atk;
1128 if (d == NULL) {
1129 d = d_store;
1130 max_steps = sizeof(d_store) / sizeof(lifting_step);
1131 }
1132 memset(d, 0, max_steps * sizeof(lifting_step));
1133 }
1134
1136 void destroy()
1137 {
1138 assert(type == OJPH_ATK_TOP);
1139 if (avail)
1140 delete avail;
1141 if (next) {
1142 delete next;
1143 next = NULL;
1144 }
1145 if (d != NULL && d != d_store) {
1146 delete[] d;
1147 d = d_store;
1148 max_steps = sizeof(d_store) / sizeof(lifting_step);
1149 }
1150 }
1151
1152 private:
1153 bool read_coefficient(infile_base *file, float &K);
1154 bool read_coefficient(infile_base *file, si16 &K);
1155
1156 void init_irv97();
1157 void init_rev53();
1159
1160 private: // member variables
1161 ui16 Latk; // structure length
1162 ui16 Satk; // carries a variety of information
1163 float Katk; // only for irreversible scaling factor K
1164 ui8 Natk; // number of lifting steps
1165 lifting_step* d; // pointer to data, initialized to d_store
1166 ui32 max_steps; // maximum number of steps without memory allocation
1167 lifting_step d_store[6]; // lifting step coefficient
1168 param_atk* next; // used for chaining if more than one atk segment
1169 // exist in the codestream
1170 ui8 type; // marker type -- this not a standard type; it is used
1171 // for debugging
1172 param_atk* top_atk;// This is the top level atk, from which all atk
1173 // objects are derived
1174
1175 private: // on restart, already allocated param_atk objs are stored here
1177 };
1178 } // !local namespace
1179} // !ojph namespace
1180
1181#endif // !OJPH_PARAMS_LOCAL_H
const char OJPH_PN_STRING_BROADCAST[]
const char OJPH_PN_STRING_CINEMAS4K[]
const char OJPH_PO_STRING_PCRL[]
const char OJPH_PN_STRING_IMF[]
const char OJPH_PN_STRING_CINEMA4K[]
uint16_t ui16
Definition ojph_defs.h:52
const char OJPH_PO_STRING_RLCP[]
const char OJPH_PN_STRING_CINEMA2K[]
const char OJPH_PO_STRING_RPCL[]
OJPH_TILEPART_DIVISIONS
@ OJPH_TILEPART_RESOLUTIONS
@ OJPH_TILEPART_NO_DIVISIONS
@ OJPH_TILEPART_LAYERS
@ OJPH_TILEPART_COMPONENTS
const char OJPH_PO_STRING_CPRL[]
@ OJPH_PN_BROADCAST
@ OJPH_PN_CINEMAS4K
@ OJPH_PN_UNDEFINED
@ OJPH_PN_CINEMAS2K
int32_t si32
Definition ojph_defs.h:55
const char OJPH_PN_STRING_PROFILE0[]
int16_t si16
Definition ojph_defs.h:53
const char OJPH_PN_STRING_CINEMAS2K[]
uint32_t ui32
Definition ojph_defs.h:54
uint8_t ui8
Definition ojph_defs.h:50
const char OJPH_PO_STRING_LRCP[]
const char OJPH_PN_STRING_PROFILE1[]
#define ojph_div_ceil(a, b)
Definition ojph_defs.h:70
#define OJPH_ERROR(t,...)
size get_log_precinct_size(ui32 res_num) const
void init(param_atk *top_atk)
bool read(infile_base *file)
bool read_coefficient(infile_base *file, float &K)
param_atk * get_atk(int index)
const lifting_step * get_step(ui32 s) const
param_atk(param_atk *top_atk=NULL, ui8 type=OJPH_ATK_TOP)
void check_validity(const param_cod &cod, const param_qcd &qcd)
void read(infile_base *file)
bool write(outfile_base *file)
void check_validity(const param_siz &siz)
bool write(outfile_base *file)
const param_cod * get_coc(ui32 comp_idx) const
bool internal_write_coc(outfile_base *file, ui32 num_comps)
bool write_coc(outfile_base *file, ui32 num_comps)
void set_reversible(bool reversible)
bool is_employing_color_transform() const
void employ_color_transform(ui8 val)
bool get_block_vertical_causality() const
const param_atk * access_atk() const
void read(infile_base *file)
size get_log_precinct_size(ui32 res_num) const
void init(param_cod *top_cod, ui16 comp_idx)
void read_coc(infile_base *file, ui32 num_comps, param_cod *top_cod)
void update_atk(param_atk *atk)
size get_precinct_size(ui32 res_num) const
param_cod(param_cod *top_cod=NULL, ui16 comp_idx=OJPH_COD_DEFAULT)
param_cod * add_coc_object(ui32 comp_idx)
bool read(infile_base *file)
dfs_dwt_type get_dwt_type(ui32 decomp_level) const
point get_res_downsamp(ui32 skipped_resolutions) const
ui32 get_subband_idx(ui32 num_decompositions, ui32 resolution, ui32 subband) const
const param_dfs * get_dfs(int index) const
ojph::param_nlt::special_comp_num special_comp_num
bool write(outfile_base *file) const
param_nlt * add_object(ui32 comp_num)
void trim_non_existing_components(ui32 num_comps)
void read(infile_base *file)
ojph::param_nlt::nonlinearity nonlinearity
bool get_nonlinear_transform(ui32 comp_num, ui8 &bit_depth, bool &is_signed, ui8 &nl_type) const
const param_nlt * get_nlt_object(ui32 comp_num) const
void check_validity(param_siz &siz)
void set_nonlinear_transform(ui32 comp_num, ui8 nl_type)
ui8 encode_SPqcd(ui8 v) const
bool write_qcc(outfile_base *file, ui32 num_comps)
void set_rev_quant(ui32 num_decomps, ui32 bit_depth, bool is_employing_color_transform)
void set_irrev_quant(ui32 num_decomps)
ui32 get_largest_Kmax() const
ui32 get_num_guard_bits() const
float get_irrev_delta(const param_dfs *dfs, ui32 num_decompositions, ui32 resolution, ui32 subband) const
void set_delta(float delta)
void read_qcc(infile_base *file, ui32 num_comps)
void check_validity(const param_siz &siz, const param_cod &cod)
bool write(outfile_base *file)
ui32 propose_precision(const param_cod *cod) const
void read(infile_base *file)
void init(param_qcd *top_qcd, ui16 comp_idx)
param_qcd * add_qcc_object(ui32 comp_idx)
ui32 get_Kmax(const param_dfs *dfs, ui32 num_decompositions, ui32 resolution, ui32 subband) const
ui8 decode_SPqcd(ui8 v) const
param_qcd * get_qcc(ui32 comp_idx)
param_qcd(param_qcd *top_qcd=NULL, ui16 comp_idx=OJPH_QCD_DEFAULT)
union ojph::local::param_qcd::@041147364276274120356145073202012174327214131340 SPqcd
void trim_non_existing_components(ui32 num_comps)
bool internal_write_qcc(outfile_base *file, ui32 num_comps)
void set_skipped_resolutions(ui32 skipped_resolutions)
ui32 get_bit_depth(ui32 comp_num) const
ui32 get_recon_height(ui32 comp_num) const
bool is_signed(ui32 comp_num) const
void check_validity(const param_cod &cod)
bool write(outfile_base *file)
param_siz(const param_siz &)=delete
point get_recon_downsampling(ui32 comp_num) const
void set_Rsiz_flag(ui16 flag)
point get_recon_size(ui32 comp_num) const
ui32 get_height(ui32 comp_num) const
void set_comp_info(ui32 comp_num, const point &downsampling, ui32 bit_depth, bool is_signed)
void link(const param_cod *cod)
point get_downsampling(ui32 comp_num) const
void reset_Rsiz_flag(ui16 flag)
void read(infile_base *file)
param_siz & operator=(const param_siz &)=delete
void link(const param_dfs *dfs)
void set_num_components(ui32 num_comps)
ui32 get_width(ui32 comp_num) const
ui32 get_recon_width(ui32 comp_num) const
void init(ui32 payload_length=0, ui16 tile_idx=0, ui8 tile_part_index=0, ui8 num_tile_parts=0)
bool read(infile_base *file, bool resilient)
bool write(outfile_base *file, ui32 payload_len)
void set_next_pair(ui16 Ttlm, ui32 Ptlm)
bool write(outfile_base *file)
void init(ui32 num_pairs, Ttlm_Ptlm_pair *store)