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
|
#include "StdAfx.h"
#include "ColorFilterArray.h"
/*
RawSpeed - RAW file decoder.
Copyright (C) 2009 Klaus Post
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 2 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, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
http://www.klauspost.com
*/
namespace RawSpeed {
ColorFilterArray::ColorFilterArray(void) {
setCFA(CFA_UNKNOWN, CFA_UNKNOWN, CFA_UNKNOWN, CFA_UNKNOWN);
}
ColorFilterArray::ColorFilterArray(CFAColor up_left, CFAColor up_right, CFAColor down_left, CFAColor down_right) {
cfa[0] = up_left;
cfa[1] = up_right;
cfa[2] = down_left;
cfa[3] = down_right;
}
ColorFilterArray::~ColorFilterArray(void) {
}
void ColorFilterArray::setCFA(CFAColor up_left, CFAColor up_right, CFAColor down_left, CFAColor down_right) {
cfa[0] = up_left;
cfa[1] = up_right;
cfa[2] = down_left;
cfa[3] = down_right;
}
void ColorFilterArray::setCFA(uchar8 dcrawCode) {
cfa[0] = (CFAColor)(dcrawCode & 0x3);
cfa[1] = (CFAColor)((dcrawCode >> 2) & 0x3);
cfa[2] = (CFAColor)((dcrawCode >> 4) & 0x3);
cfa[3] = (CFAColor)((dcrawCode >> 6) & 0x3);
}
uint32 ColorFilterArray::getDcrawFilter() {
if (cfa[0] > 3 || cfa[1] > 3 || cfa[2] > 3 || cfa[3] > 3)
ThrowRDE("getDcrawFilter: Invalid colors defined.");
uint32 v = cfa[0] | cfa[1] << 2 | cfa[2] << 4 | cfa[3] << 6;
return v | (v << 8) | (v << 16) | (v << 24);
}
std::string ColorFilterArray::asString() {
string s("Upper left:");
s += colorToString(cfa[0]);
s.append(" * Upper right:");
s += colorToString(cfa[1]);
s += ("\nLower left:");
s += colorToString(cfa[2]);
s.append(" * Lower right:");
s += colorToString(cfa[3]);
s.append("\n");
s += string("CFA_") + colorToString(cfa[0]) + string(", CFA_") + colorToString(cfa[1]);
s += string(", CFA_") + colorToString(cfa[2]) + string(", CFA_") + colorToString(cfa[3]) + string("\n");
return s;
}
std::string ColorFilterArray::colorToString(CFAColor c) {
switch (c) {
case CFA_RED:
return string("RED");
case CFA_GREEN:
return string("GREEN");
case CFA_BLUE:
return string("BLUE");
case CFA_GREEN2:
return string("GREEN2");
case CFA_CYAN:
return string("CYAN");
case CFA_MAGENTA:
return string("MAGENTA");
case CFA_YELLOW:
return string("YELLOW");
case CFA_WHITE:
return string("WHITE");
default:
return string("UNKNOWN");
}
}
void ColorFilterArray::setColorAt(iPoint2D pos, CFAColor c) {
if (pos.x > 1 || pos.x < 0)
ThrowRDE("ColorFilterArray::SetColor: position out of CFA pattern");
if (pos.y > 1 || pos.y < 0)
ThrowRDE("ColorFilterArray::SetColor: position out of CFA pattern");
cfa[pos.x+pos.y*2] = c;
// _RPT2(0, "cfa[%u] = %u\n",pos.x+pos.y*2, c);
}
void ColorFilterArray::shiftLeft() {
CFAColor tmp1 = cfa[0];
CFAColor tmp2 = cfa[2];
cfa[0] = cfa[1];
cfa[2] = cfa[3];
cfa[1] = tmp1;
cfa[3] = tmp2;
}
void ColorFilterArray::shiftDown() {
CFAColor tmp1 = cfa[0];
CFAColor tmp2 = cfa[1];
cfa[0] = cfa[2];
cfa[1] = cfa[3];
cfa[2] = tmp1;
cfa[3] = tmp2;
}
} // namespace RawSpeed
|