~ubuntu-branches/ubuntu/trusty/digikam/trusty

« back to all changes in this revision

Viewing changes to extra/libkdcraw/libraw/RawSpeed/ColorFilterArray.cpp

  • Committer: Package Import Robot
  • Author(s): Rohan Garg
  • Date: 2012-11-26 18:24:20 UTC
  • mfrom: (1.9.1) (3.1.23 experimental)
  • Revision ID: package-import@ubuntu.com-20121126182420-qoy6z0nx4ai0wzcl
Tags: 4:3.0.0~beta3-0ubuntu1
* New upstream release
  - Add build-deps :  libhupnp-dev, libqtgstreamer-dev, libmagickcore-dev
* Merge from debian, remaining changes:
  - Make sure libqt4-opengl-dev, libgl1-mesa-dev and libglu1-mesa-dev only
    install on i386,amd64 and powerpc
  - Depend on libtiff-dev instead of libtiff4-dev
  - Drop digikam breaks/replaces kipi-plugins-common since we're past the
    LTS release now
  - digikam to recommend mplayerthumbs | ffmpegthumbs. We currently only
    have latter in the archives, even though former is also supposed to
    be part of kdemultimedia. (LP: #890059)
  - kipi-plugins to recommend www-browser rather than konqueror directly
    since 2.8 no direct usage of konqueror is present in the flickr
    plugin anymore (LP: #1011211)
  - Keep kubuntu_mysqld_executable_name.diff
  - Don't install libkipi translations
  - Keep deps on libcv-dev, libcvaux-dev
  - Keep split packaging of libraries
  - Replace icons from KDE 3 time in debian/xpm.d/*.xpm with the new
    versions (LP: #658047)
* Update debian/not-installed

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "StdAfx.h"
 
2
#include "ColorFilterArray.h"
 
3
/*
 
4
    RawSpeed - RAW file decoder.
 
5
 
 
6
    Copyright (C) 2009 Klaus Post
 
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
 
10
    License as published by the Free Software Foundation; either
 
11
    version 2 of 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, write to the Free Software
 
20
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
21
 
 
22
    http://www.klauspost.com
 
23
*/
 
24
 
 
25
namespace RawSpeed {
 
26
 
 
27
ColorFilterArray::ColorFilterArray(void) {
 
28
  setCFA(CFA_UNKNOWN, CFA_UNKNOWN, CFA_UNKNOWN, CFA_UNKNOWN);
 
29
}
 
30
 
 
31
ColorFilterArray::ColorFilterArray(CFAColor up_left, CFAColor up_right, CFAColor down_left, CFAColor down_right) {
 
32
  cfa[0] = up_left;
 
33
  cfa[1] = up_right;
 
34
  cfa[2] = down_left;
 
35
  cfa[3] = down_right;
 
36
}
 
37
 
 
38
ColorFilterArray::~ColorFilterArray(void) {
 
39
}
 
40
 
 
41
void ColorFilterArray::setCFA(CFAColor up_left, CFAColor up_right, CFAColor down_left, CFAColor down_right) {
 
42
  cfa[0] = up_left;
 
43
  cfa[1] = up_right;
 
44
  cfa[2] = down_left;
 
45
  cfa[3] = down_right;
 
46
}
 
47
 
 
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);
 
53
}
 
54
 
 
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);
 
60
}
 
61
 
 
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]);
 
71
  s.append("\n");
 
72
 
 
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");
 
75
  return s;
 
76
}
 
77
 
 
78
std::string ColorFilterArray::colorToString(CFAColor c) {
 
79
  switch (c) {
 
80
    case CFA_RED:
 
81
      return string("RED");
 
82
    case CFA_GREEN:
 
83
      return string("GREEN");
 
84
    case CFA_BLUE:
 
85
      return string("BLUE");
 
86
    case CFA_GREEN2:
 
87
      return string("GREEN2");
 
88
    case CFA_CYAN:
 
89
      return string("CYAN");
 
90
    case CFA_MAGENTA:
 
91
      return string("MAGENTA");
 
92
    case CFA_YELLOW:
 
93
      return string("YELLOW");
 
94
    case CFA_WHITE:
 
95
      return string("WHITE");
 
96
    default:
 
97
      return string("UNKNOWN");
 
98
  }
 
99
}
 
100
 
 
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);
 
108
}
 
109
 
 
110
void ColorFilterArray::shiftLeft() {
 
111
  CFAColor tmp1 = cfa[0];
 
112
  CFAColor tmp2 = cfa[2];
 
113
  cfa[0] = cfa[1];
 
114
  cfa[2] = cfa[3];
 
115
  cfa[1] = tmp1;
 
116
  cfa[3] = tmp2;
 
117
}
 
118
 
 
119
void ColorFilterArray::shiftDown() {
 
120
  CFAColor tmp1 = cfa[0];
 
121
  CFAColor tmp2 = cfa[1];
 
122
  cfa[0] = cfa[2];
 
123
  cfa[1] = cfa[3];
 
124
  cfa[2] = tmp1;
 
125
  cfa[3] = tmp2;
 
126
}
 
127
 
 
128
} // namespace RawSpeed