Grok  9.5.0
coding_local.hpp
Go to the documentation of this file.
1 // Copyright (c) 2019 - 2021, Osamu Watanabe
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are met:
6 //
7 // 1. Redistributions of source code must retain the above copyright notice, this
8 // list of conditions and the following disclaimer.
9 //
10 // 2. Redistributions in binary form must reproduce the above copyright notice,
11 // this list of conditions and the following disclaimer in the documentation
12 // and/or other materials provided with the distribution.
13 //
14 // 3. Neither the name of the copyright holder nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 
29 #pragma once
30 
31 #define SHIFT_SIGMA 0 // J2K and HTJ2K
32 #define SHIFT_SIGMA_ 1 // J2K only
33 #define SHIFT_PI_ 2 // J2K and HTJ2K; used as refinement indicator for HTJ2K
34 #define SHIFT_REF 3 // HTJ2K only
35 #define SHIFT_SCAN 4 // HTJ2K only
36 #define SHIFT_P 3 // J2K only
37 
38 // getters
39 inline uint8_t Sigma(uint8_t &data) { return (data >> SHIFT_SIGMA) & 1; }
40 inline uint8_t Sigma_(uint8_t &data) { return (data >> SHIFT_SIGMA_) & 1; }
41 inline uint8_t Pi_(uint8_t &data) { return (data >> SHIFT_PI_) & 1; }
42 inline uint8_t Scan(uint8_t &data) { return (data >> SHIFT_SCAN) & 1; }
43 inline uint8_t Refinement_value(uint8_t &data) { return (data >> SHIFT_REF) & 1; }
44 inline uint8_t Refinement_indicator(uint8_t &data) { return (data >> SHIFT_PI_) & 1; }
45 inline uint8_t Decoded_bitplane_index(uint8_t &data) { return (data >> SHIFT_P); }
46 
47 // setters
48 inline void sigma(uint8_t &data, const uint8_t &val) { data |= val; }
49 inline void sigma_(uint8_t &data, const uint8_t &val) { data |= val << SHIFT_SIGMA_; }
50 inline void pi_(uint8_t &data, const uint8_t &val) {
51  if (val) {
52  data |= 1 << SHIFT_PI_;
53  } else {
54  data &= ~(1 << SHIFT_PI_);
55  }
56 }
57 inline void scan(uint8_t &data, const uint8_t &val) { data |= val << SHIFT_SCAN; }
58 inline void refinement_value(uint8_t &data, const uint8_t &val) { data |= val << SHIFT_REF; }
59 inline void refinement_indicator(uint8_t &data, const uint8_t &val) {
60  if (val) {
61  data |= 1 << SHIFT_PI_;
62  } else {
63  data &= ~(1 << SHIFT_PI_);
64  }
65 }
66 inline void decoded_bitplane_index(uint8_t &data, const uint8_t &val) {
67  data &= 0x07;
68  data |= val << SHIFT_P;
69 }
uint8_t Sigma(uint8_t &data)
Definition: coding_local.hpp:39
#define SHIFT_PI_
Definition: coding_local.hpp:33
#define SHIFT_REF
Definition: coding_local.hpp:34
void pi_(uint8_t &data, const uint8_t &val)
Definition: coding_local.hpp:50
uint8_t Scan(uint8_t &data)
Definition: coding_local.hpp:42
void refinement_indicator(uint8_t &data, const uint8_t &val)
Definition: coding_local.hpp:59
#define SHIFT_SIGMA
Definition: coding_local.hpp:31
#define SHIFT_SIGMA_
Definition: coding_local.hpp:32
void decoded_bitplane_index(uint8_t &data, const uint8_t &val)
Definition: coding_local.hpp:66
#define SHIFT_P
Definition: coding_local.hpp:36
uint8_t Refinement_indicator(uint8_t &data)
Definition: coding_local.hpp:44
void sigma_(uint8_t &data, const uint8_t &val)
Definition: coding_local.hpp:49
void scan(uint8_t &data, const uint8_t &val)
Definition: coding_local.hpp:57
void refinement_value(uint8_t &data, const uint8_t &val)
Definition: coding_local.hpp:58
#define SHIFT_SCAN
Definition: coding_local.hpp:35
uint8_t Decoded_bitplane_index(uint8_t &data)
Definition: coding_local.hpp:45
uint8_t Pi_(uint8_t &data)
Definition: coding_local.hpp:41
void sigma(uint8_t &data, const uint8_t &val)
Definition: coding_local.hpp:48
uint8_t Sigma_(uint8_t &data)
Definition: coding_local.hpp:40
uint8_t Refinement_value(uint8_t &data)
Definition: coding_local.hpp:43