File: nefdiffiterator.cpp

package info (click to toggle)
libopenraw 0.0.8-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 2,964 kB
  • ctags: 1,936
  • sloc: sh: 10,199; cpp: 9,279; ansic: 1,466; makefile: 544; xml: 465; perl: 42
file content (141 lines) | stat: -rw-r--r-- 4,057 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/* -*- tab-width:4; c-basic-offset:4 -*- */
/*
 * libopenraw - nefdiffiterator.cpp
 *
 * Copyright (C) 2008 Rafael Avila de Espindola.
 *
 * This library is free software: you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation, either version 3 of
 * the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.  If not, see
 * <http://www.gnu.org/licenses/>.
 */

#include "nefdiffiterator.h"

namespace OpenRaw {
namespace Internals {

int NefDiffIterator::get()
{
	unsigned int t = m_decoder.decode(m_iter);
	unsigned int len = t & 15;
	unsigned int shl = t >> 4;


	unsigned int bits = m_iter.get(len - shl);

	int diff = ((bits << 1) + 1) << shl >> 1;
	if ((diff & (1 << (len-1))) == 0)
		diff -= (1 << len) - !shl;

	return diff;
}

// 00              5
// 010             4
// 011             3
// 100             6
// 101             2
// 110             7
// 1110            1
// 11110           0
// 111110          8
// 1111110         9
// 11111110        11
// 111111110       10
// 1111111110      12
// 1111111111      0
const HuffmanNode NefDiffIterator::Lossy12Bit[] = {
	/* 0  */ {0, 6},  /* root       */
	/* 1  */ {0, 3},  /* 0          */
	/* 2  */ {1, 5},  /* 00         */
	/* 3  */ {0, 5},  /* 01         */
	/* 4  */ {1, 4},  /* 010        */
	/* 5  */ {1, 3},  /* 011        */
	/* 6  */ {0, 10}, /* 1          */
	/* 7  */ {0, 9},  /* 10         */
	/* 8  */ {1, 6},  /* 100        */
	/* 9  */ {1, 2},  /* 101        */
	/* 10 */ {0, 12}, /* 11         */
	/* 11 */ {1, 7},  /* 110        */
	/* 12 */ {0, 14}, /* 111        */
	/* 13 */ {1, 1},  /* 1110       */
	/* 14 */ {0, 16}, /* 1111       */
	/* 15 */ {1, 0},  /* 11110      */
	/* 16 */ {0, 18}, /* 11111      */
	/* 17 */ {1, 8},  /* 111110     */
	/* 18 */ {0, 20}, /* 111111     */
	/* 19 */ {1, 9},  /* 1111110    */
	/* 20 */ {0, 22}, /* 1111111    */
	/* 21 */ {1, 11}, /* 11111110   */
	/* 22 */ {0, 24}, /* 11111111   */
	/* 23 */ {1, 10}, /* 111111110  */
	/* 24 */ {0, 26}, /* 111111111  */
	/* 25 */ {1, 12}, /* 1111111110 */
	/* 26 */ {1, 0},  /* 1111111111 */
};

// 00              7
// 010             6
// 011             8
// 100             5
// 101             9
// 1100            4
// 1101            10
// 11100           3
// 11101           11
// 111100          12
// 111101          2
// 111110          0
// 1111110         1
// 11111110        13
// 11111111        14
const HuffmanNode NefDiffIterator::LossLess14Bit[] = {
	/* 0  */ {0, 6},  /* root       */
	/* 1  */ {0, 3},  /* 0          */
	/* 2  */ {1, 7},  /* 00         */
	/* 3  */ {0, 5},  /* 01         */
	/* 4  */ {1, 6},  /* 010        */
	/* 5  */ {1, 8},  /* 011        */
	/* 6  */ {0, 10}, /* 1          */
	/* 7  */ {0, 9},  /* 10         */
	/* 8  */ {1, 5},  /* 100        */
	/* 9  */ {1, 9},  /* 101        */
	/* 10 */ {0, 14}, /* 11         */
	/* 11 */ {0, 13}, /* 110        */
	/* 12 */ {1, 4},  /* 1100       */
	/* 13 */ {1, 10}, /* 1101       */
	/* 14 */ {0, 18}, /* 111        */
	/* 15 */ {0, 17}, /* 1110       */
	/* 16 */ {1, 3},  /* 11100      */
	/* 17 */ {1, 11}, /* 11101      */
	/* 18 */ {0, 22}, /* 1111       */
	/* 19 */ {0, 21}, /* 11110      */
	/* 20 */ {1, 12}, /* 111100     */
	/* 21 */ {1, 2},  /* 111101     */
	/* 22 */ {0, 24}, /* 11111      */
	/* 23 */ {1, 0},  /* 111110     */
	/* 24 */ {0, 26}, /* 111111     */
	/* 25 */ {1, 1},  /* 1111110    */
	/* 26 */ {0, 28}, /* 1111111    */
	/* 27 */ {1, 13}, /* 11111110   */
	/* 28 */ {1, 14}, /* 11111111   */
};

NefDiffIterator::NefDiffIterator(const HuffmanNode* const t,
							   const void *p) :
	m_iter(p), m_decoder(t)
{
}

}
}