libopenraw
nefdiffiterator.cpp
1 /* -*- tab-width:4; c-basic-offset:4 -*- */
2 /*
3  * libopenraw - nefdiffiterator.cpp
4  *
5  * Copyright (C) 2008 Rafael Avila de Espindola.
6  * Copyright (C) 2013-2016 Hubert Figuiere
7  *
8  * This library is free software: you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation, either version 3 of
11  * the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library. If not, see
20  * <http://www.gnu.org/licenses/>.
21  */
22 
23 #include "nefdiffiterator.hpp"
24 
25 namespace OpenRaw {
26 namespace Internals {
27 
28 int NefDiffIterator::get()
29 {
30  unsigned int t = m_decoder.decode(m_iter);
31  unsigned int len = t & 15;
32  unsigned int shl = t >> 4;
33 
34 
35  unsigned int bits = m_iter.get(len - shl);
36 
37  int diff = ((bits << 1) + 1) << shl >> 1;
38  if ((diff & (1 << (len-1))) == 0)
39  diff -= (1 << len) - !shl;
40 
41  return diff;
42 }
43 
44 // 00 5
45 // 010 4
46 // 011 3
47 // 100 6
48 // 101 2
49 // 110 7
50 // 1110 1
51 // 11110 0
52 // 111110 8
53 // 1111110 9
54 // 11111110 11
55 // 111111110 10
56 // 1111111110 12
57 // 1111111111 0
58 const HuffmanNode NefDiffIterator::Lossy12Bit[] = {
59  /* 0 */ {0, 6}, /* root */
60  /* 1 */ {0, 3}, /* 0 */
61  /* 2 */ {1, 5}, /* 00 */
62  /* 3 */ {0, 5}, /* 01 */
63  /* 4 */ {1, 4}, /* 010 */
64  /* 5 */ {1, 3}, /* 011 */
65  /* 6 */ {0, 10}, /* 1 */
66  /* 7 */ {0, 9}, /* 10 */
67  /* 8 */ {1, 6}, /* 100 */
68  /* 9 */ {1, 2}, /* 101 */
69  /* 10 */ {0, 12}, /* 11 */
70  /* 11 */ {1, 7}, /* 110 */
71  /* 12 */ {0, 14}, /* 111 */
72  /* 13 */ {1, 1}, /* 1110 */
73  /* 14 */ {0, 16}, /* 1111 */
74  /* 15 */ {1, 0}, /* 11110 */
75  /* 16 */ {0, 18}, /* 11111 */
76  /* 17 */ {1, 8}, /* 111110 */
77  /* 18 */ {0, 20}, /* 111111 */
78  /* 19 */ {1, 9}, /* 1111110 */
79  /* 20 */ {0, 22}, /* 1111111 */
80  /* 21 */ {1, 11}, /* 11111110 */
81  /* 22 */ {0, 24}, /* 11111111 */
82  /* 23 */ {1, 10}, /* 111111110 */
83  /* 24 */ {0, 26}, /* 111111111 */
84  /* 25 */ {1, 12}, /* 1111111110 */
85  /* 26 */ {1, 0}, /* 1111111111 */
86 };
87 
88 // 00 5
89 // 010 6
90 // 011 4
91 // 100 7
92 // 101 8
93 // 1100 3
94 // 1101 9
95 // 11100 2
96 // 11101 1
97 // 111100 0
98 // 111101 10
99 // 111110 11
100 // 1111110 12
101 // 11111110 13
102 // 11111111 14
103 const HuffmanNode NefDiffIterator::Lossy14Bit[] = {
104  /* 0 */ {0, 6}, /* root */
105  /* 1 */ {0, 3}, /* 0 */
106  /* 2 */ {1, 5}, /* 00 */
107  /* 3 */ {0, 5}, /* 01 */
108  /* 4 */ {1, 6}, /* 010 */
109  /* 5 */ {1, 4}, /* 011 */
110  /* 6 */ {0, 10}, /* 1 */
111  /* 7 */ {0, 9}, /* 10 */
112  /* 8 */ {1, 7}, /* 100 */
113  /* 9 */ {1, 8}, /* 101 */
114  /* 10 */ {0, 14}, /* 11 */
115  /* 11 */ {0, 13}, /* 110 */
116  /* 12 */ {1, 3}, /* 1100 */
117  /* 13 */ {1, 9}, /* 1101 */
118  /* 14 */ {0, 18}, /* 111 */
119  /* 15 */ {0, 17}, /* 1110 */
120  /* 16 */ {1, 2}, /* 11100 */
121  /* 17 */ {1, 1}, /* 11101 */
122  /* 18 */ {0, 22}, /* 1111 */
123  /* 19 */ {0, 21}, /* 11110 */
124  /* 20 */ {1, 0}, /* 111100 */
125  /* 21 */ {1, 10}, /* 111101 */
126  /* 22 */ {0, 24}, /* 11111 */
127  /* 23 */ {1, 11}, /* 111110 */
128  /* 24 */ {0, 26}, /* 111111 */
129  /* 25 */ {1, 12}, /* 1111110 */
130  /* 26 */ {0, 28}, /* 1111111 */
131  /* 27 */ {1, 13}, /* 11111110 */
132  /* 28 */ {1, 14}, /* 11111111 */
133 };
134 
135 // 00 7
136 // 010 6
137 // 011 8
138 // 100 5
139 // 101 9
140 // 1100 4
141 // 1101 10
142 // 11100 3
143 // 11101 11
144 // 111100 12
145 // 111101 2
146 // 111110 0
147 // 1111110 1
148 // 11111110 13
149 // 11111111 14
150 const HuffmanNode NefDiffIterator::LossLess14Bit[] = {
151  /* 0 */ {0, 6}, /* root */
152  /* 1 */ {0, 3}, /* 0 */
153  /* 2 */ {1, 7}, /* 00 */
154  /* 3 */ {0, 5}, /* 01 */
155  /* 4 */ {1, 6}, /* 010 */
156  /* 5 */ {1, 8}, /* 011 */
157  /* 6 */ {0, 10}, /* 1 */
158  /* 7 */ {0, 9}, /* 10 */
159  /* 8 */ {1, 5}, /* 100 */
160  /* 9 */ {1, 9}, /* 101 */
161  /* 10 */ {0, 14}, /* 11 */
162  /* 11 */ {0, 13}, /* 110 */
163  /* 12 */ {1, 4}, /* 1100 */
164  /* 13 */ {1, 10}, /* 1101 */
165  /* 14 */ {0, 18}, /* 111 */
166  /* 15 */ {0, 17}, /* 1110 */
167  /* 16 */ {1, 3}, /* 11100 */
168  /* 17 */ {1, 11}, /* 11101 */
169  /* 18 */ {0, 22}, /* 1111 */
170  /* 19 */ {0, 21}, /* 11110 */
171  /* 20 */ {1, 12}, /* 111100 */
172  /* 21 */ {1, 2}, /* 111101 */
173  /* 22 */ {0, 24}, /* 11111 */
174  /* 23 */ {1, 0}, /* 111110 */
175  /* 24 */ {0, 26}, /* 111111 */
176  /* 25 */ {1, 1}, /* 1111110 */
177  /* 26 */ {0, 28}, /* 1111111 */
178  /* 27 */ {1, 13}, /* 11111110 */
179  /* 28 */ {1, 14}, /* 11111111 */
180 };
181 
182 NefDiffIterator::NefDiffIterator(const HuffmanNode* const t,
183  const uint8_t *p, size_t size) :
184  m_iter(p, size), m_decoder(t)
185 {
186 }
187 
188 }
189 }
CIFF is the container for CRW files. It is an attempt from Canon to make this a standard. I guess it failed.
Definition: arwfile.cpp:30