2
#include "ColorFilterArray.h"
4
RawSpeed - RAW file decoder.
6
Copyright (C) 2009 Klaus Post
8
This library is free software; you can redistribute it and/or
9
modify it under the terms of the GNU Lesser General Public
10
License as published by the Free Software Foundation; either
11
version 2 of the License, or (at your option) any later version.
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.
18
You should have received a copy of the GNU Lesser General Public
19
License along with this library; if not, write to the Free Software
20
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22
http://www.klauspost.com
27
ColorFilterArray::ColorFilterArray(void) {
28
setCFA(CFA_UNKNOWN, CFA_UNKNOWN, CFA_UNKNOWN, CFA_UNKNOWN);
31
ColorFilterArray::ColorFilterArray(CFAColor up_left, CFAColor up_right, CFAColor down_left, CFAColor down_right) {
38
ColorFilterArray::~ColorFilterArray(void) {
41
void ColorFilterArray::setCFA(CFAColor up_left, CFAColor up_right, CFAColor down_left, CFAColor down_right) {
48
void ColorFilterArray::setCFA(uchar8 dcrawCode) {
49
cfa[0] = (CFAColor)(dcrawCode & 0x3);
50
cfa[1] = (CFAColor)((dcrawCode >> 2) & 0x3);
51
cfa[2] = (CFAColor)((dcrawCode >> 4) & 0x3);
52
cfa[3] = (CFAColor)((dcrawCode >> 6) & 0x3);
55
uint32 ColorFilterArray::getDcrawFilter() {
56
if (cfa[0] > 3 || cfa[1] > 3 || cfa[2] > 3 || cfa[3] > 3)
57
ThrowRDE("getDcrawFilter: Invalid colors defined.");
58
uint32 v = cfa[0] | cfa[1] << 2 | cfa[2] << 4 | cfa[3] << 6;
59
return v | (v << 8) | (v << 16) | (v << 24);
62
std::string ColorFilterArray::asString() {
63
string s("Upper left:");
64
s += colorToString(cfa[0]);
65
s.append(" * Upper right:");
66
s += colorToString(cfa[1]);
67
s += ("\nLower left:");
68
s += colorToString(cfa[2]);
69
s.append(" * Lower right:");
70
s += colorToString(cfa[3]);
73
s += string("CFA_") + colorToString(cfa[0]) + string(", CFA_") + colorToString(cfa[1]);
74
s += string(", CFA_") + colorToString(cfa[2]) + string(", CFA_") + colorToString(cfa[3]) + string("\n");
78
std::string ColorFilterArray::colorToString(CFAColor c) {
83
return string("GREEN");
85
return string("BLUE");
87
return string("GREEN2");
89
return string("CYAN");
91
return string("MAGENTA");
93
return string("YELLOW");
95
return string("WHITE");
97
return string("UNKNOWN");
101
void ColorFilterArray::setColorAt(iPoint2D pos, CFAColor c) {
102
if (pos.x > 1 || pos.x < 0)
103
ThrowRDE("ColorFilterArray::SetColor: position out of CFA pattern");
104
if (pos.y > 1 || pos.y < 0)
105
ThrowRDE("ColorFilterArray::SetColor: position out of CFA pattern");
106
cfa[pos.x+pos.y*2] = c;
107
// _RPT2(0, "cfa[%u] = %u\n",pos.x+pos.y*2, c);
110
void ColorFilterArray::shiftLeft() {
111
CFAColor tmp1 = cfa[0];
112
CFAColor tmp2 = cfa[2];
119
void ColorFilterArray::shiftDown() {
120
CFAColor tmp1 = cfa[0];
121
CFAColor tmp2 = cfa[1];
128
} // namespace RawSpeed