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  *
7  * This library is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation, either version 3 of
10  * the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library. If not, see
19  * <http://www.gnu.org/licenses/>.
20  */
21 
22 #include "nefdiffiterator.h"
23 
24 namespace OpenRaw {
25 namespace Internals {
26 
27 int NefDiffIterator::get()
28 {
29  unsigned int t = m_decoder.decode(m_iter);
30  unsigned int len = t & 15;
31  unsigned int shl = t >> 4;
32 
33 
34  unsigned int bits = m_iter.get(len - shl);
35 
36  int diff = ((bits << 1) + 1) << shl >> 1;
37  if ((diff & (1 << (len-1))) == 0)
38  diff -= (1 << len) - !shl;
39 
40  return diff;
41 }
42 
43 // 00 5
44 // 010 4
45 // 011 3
46 // 100 6
47 // 101 2
48 // 110 7
49 // 1110 1
50 // 11110 0
51 // 111110 8
52 // 1111110 9
53 // 11111110 11
54 // 111111110 10
55 // 1111111110 12
56 // 1111111111 0
57 const HuffmanNode NefDiffIterator::Lossy12Bit[] = {
58  /* 0 */ {0, 6}, /* root */
59  /* 1 */ {0, 3}, /* 0 */
60  /* 2 */ {1, 5}, /* 00 */
61  /* 3 */ {0, 5}, /* 01 */
62  /* 4 */ {1, 4}, /* 010 */
63  /* 5 */ {1, 3}, /* 011 */
64  /* 6 */ {0, 10}, /* 1 */
65  /* 7 */ {0, 9}, /* 10 */
66  /* 8 */ {1, 6}, /* 100 */
67  /* 9 */ {1, 2}, /* 101 */
68  /* 10 */ {0, 12}, /* 11 */
69  /* 11 */ {1, 7}, /* 110 */
70  /* 12 */ {0, 14}, /* 111 */
71  /* 13 */ {1, 1}, /* 1110 */
72  /* 14 */ {0, 16}, /* 1111 */
73  /* 15 */ {1, 0}, /* 11110 */
74  /* 16 */ {0, 18}, /* 11111 */
75  /* 17 */ {1, 8}, /* 111110 */
76  /* 18 */ {0, 20}, /* 111111 */
77  /* 19 */ {1, 9}, /* 1111110 */
78  /* 20 */ {0, 22}, /* 1111111 */
79  /* 21 */ {1, 11}, /* 11111110 */
80  /* 22 */ {0, 24}, /* 11111111 */
81  /* 23 */ {1, 10}, /* 111111110 */
82  /* 24 */ {0, 26}, /* 111111111 */
83  /* 25 */ {1, 12}, /* 1111111110 */
84  /* 26 */ {1, 0}, /* 1111111111 */
85 };
86 
87 // 00 7
88 // 010 6
89 // 011 8
90 // 100 5
91 // 101 9
92 // 1100 4
93 // 1101 10
94 // 11100 3
95 // 11101 11
96 // 111100 12
97 // 111101 2
98 // 111110 0
99 // 1111110 1
100 // 11111110 13
101 // 11111111 14
102 const HuffmanNode NefDiffIterator::LossLess14Bit[] = {
103  /* 0 */ {0, 6}, /* root */
104  /* 1 */ {0, 3}, /* 0 */
105  /* 2 */ {1, 7}, /* 00 */
106  /* 3 */ {0, 5}, /* 01 */
107  /* 4 */ {1, 6}, /* 010 */
108  /* 5 */ {1, 8}, /* 011 */
109  /* 6 */ {0, 10}, /* 1 */
110  /* 7 */ {0, 9}, /* 10 */
111  /* 8 */ {1, 5}, /* 100 */
112  /* 9 */ {1, 9}, /* 101 */
113  /* 10 */ {0, 14}, /* 11 */
114  /* 11 */ {0, 13}, /* 110 */
115  /* 12 */ {1, 4}, /* 1100 */
116  /* 13 */ {1, 10}, /* 1101 */
117  /* 14 */ {0, 18}, /* 111 */
118  /* 15 */ {0, 17}, /* 1110 */
119  /* 16 */ {1, 3}, /* 11100 */
120  /* 17 */ {1, 11}, /* 11101 */
121  /* 18 */ {0, 22}, /* 1111 */
122  /* 19 */ {0, 21}, /* 11110 */
123  /* 20 */ {1, 12}, /* 111100 */
124  /* 21 */ {1, 2}, /* 111101 */
125  /* 22 */ {0, 24}, /* 11111 */
126  /* 23 */ {1, 0}, /* 111110 */
127  /* 24 */ {0, 26}, /* 111111 */
128  /* 25 */ {1, 1}, /* 1111110 */
129  /* 26 */ {0, 28}, /* 1111111 */
130  /* 27 */ {1, 13}, /* 11111110 */
131  /* 28 */ {1, 14}, /* 11111111 */
132 };
133 
134 NefDiffIterator::NefDiffIterator(const HuffmanNode* const t,
135  const void *p) :
136  m_iter(p), m_decoder(t)
137 {
138 }
139 
140 }
141 }
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:33