Debian Codegraph @

src/filter/ndvi/gradientlut.hpp

raw symbols SCIP
1 /*
2 * Copyright (C) 2014 Brian Matherly ([email protected])
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18
19 #include <vector>
20 //#define GRADIENTLUT_PRINT
21 #ifdef GRADIENTLUT_PRINT
22 #include <cstdio>
23 #endif
24
25 class GradientLutcxx . . $ GradientLut#
26 {
27 public:
28 struct Colorcxx . . $ GradientLut#Color# {
29 uint8_t rcxx . . $ GradientLut#Color#r.;
30 uint8_t gcxx . . $ GradientLut#Color#g.;
31 uint8_t bcxx . . $ GradientLut#Color#b.;
32 };
33
34 void setDepthcxx . . $ GradientLut#setDepth(2c44cd906ae4e829).(size_t depth);
35 void fillRangecxx . . $ GradientLut#fillRange(4e6784b12c917046).(double startPos, const Colorcxx . . $ GradientLut#Color#& startColor,
36 double endPos, const Colorcxx . . $ GradientLut#Color#& endColor);
37 const Colorcxx . . $ GradientLut#Color#& operatorcxx . . $ GradientLut#`operator[]`(d5da8d30c22ea07f).[](double pos) const;
38 void printcxx . . $ GradientLut#print(83f5f38750778ac8).() const;
39
40 private:
41 stdcxx . . $ std/::vectorcxx . . $ std/vector#<Colorcxx . . $ GradientLut#Color#> lutcxx . . $ GradientLut#lut.;
42 };
43
44 /**
45 * Set the size of the look-up table.
46 */
47 void GradientLutcxx . . $ GradientLut#::setDepthcxx . . $ GradientLut#setDepth(2c44cd906ae4e829).(size_t depth) {
48 lutcxx . . $ GradientLut#lut..resizecxx . . $ std/vector#resize(2c44cd906ae4e829).(depth);
49 }
50
51 /**
52 * Fill a part of the look-up table.
53 * The indexes in the table and their corresponding colors will be calculated
54 * proportionally to the depth of the LUT.
55 */
56 void GradientLutcxx . . $ GradientLut#::fillRangecxx . . $ GradientLut#fillRange(4e6784b12c917046).( double startPos, const GradientLutcxx . . $ GradientLut#::Colorcxx . . $ GradientLut#Color#& startColor,
57 double endPos, const GradientLutcxx . . $ GradientLut#::Colorcxx . . $ GradientLut#Color#& endColor ) {
58 unsigned int startIndex = (double)(lutcxx . . $ GradientLut#lut..sizecxx . . $ std/vector#size(fe4d2d262d4164a8).() - 1) * startPos + 0.5;
59 unsigned int endIndex = (double)(lutcxx . . $ GradientLut#lut..sizecxx . . $ std/vector#size(fe4d2d262d4164a8).() - 1) * endPos + 0.5;
60 unsigned int span = endIndex - startIndex;
61
62 if(span < 1) span = 1;
63
64 for(unsigned int i = 0; i <= span; i++) {
65 Colorcxx . . $ GradientLut#Color# color;
66 double ratio = (double)i / (double)span;
67
68 color.rcxx . . $ GradientLut#Color#r. = startColor.rcxx . . $ GradientLut#Color#r. + ratio * ((double)endColor.rcxx . . $ GradientLut#Color#r. - (double)startColor.rcxx . . $ GradientLut#Color#r.);
69 color.gcxx . . $ GradientLut#Color#g. = startColor.gcxx . . $ GradientLut#Color#g. + ratio * ((double)endColor.gcxx . . $ GradientLut#Color#g. - (double)startColor.gcxx . . $ GradientLut#Color#g.);
70 color.bcxx . . $ GradientLut#Color#b. = startColor.bcxx . . $ GradientLut#Color#b. + ratio * ((double)endColor.bcxx . . $ GradientLut#Color#b. - (double)startColor.bcxx . . $ GradientLut#Color#b.);
71 lutcxx . . $ GradientLut#lut.[cxx . . $ std/vector#`operator[]`(428bb168810b9e52).i + startIndex] =cxx . . $ GradientLut#Color#`operator=`(4434ef7084689651). color;
72 }
73 }
74
75 /**
76 * Get a color value for a given position in the table.
77 * The index in the table will be calculated proportionally to the depth of the
78 * LUT.
79 */
80 const GradientLutcxx . . $ GradientLut#::Colorcxx . . $ GradientLut#Color#& GradientLutcxx . . $ GradientLut#::operatorcxx . . $ GradientLut#`operator[]`(d5da8d30c22ea07f).[](double pos) const {
81 unsigned int size = lutcxx . . $ GradientLut#lut..sizecxx . . $ std/vector#size(fe4d2d262d4164a8).();
82 unsigned int index = (double)size * pos;
83 if(index >= size) {
84 index = size - 1;
85 }
86 return lutcxx . . $ GradientLut#lut.[cxx . . $ std/vector#`operator[]`(b61e45a10b63f40a).index];
87 };
88
89 /**
90 * Debug print function.
91 */
92 void GradientLutcxx . . $ GradientLut#::printcxx . . $ GradientLut#print(83f5f38750778ac8).() const {
93 #ifdef GRADIENTLUT_PRINT
94 printf("LUT:\tIndex\tRed\tGreen\tBlue\n");
95 for(int i = 0; i < lut.size(); i++) {
96 const Color& color = lut[i];
97 printf("\t%3d\t%02x\t%02x\t%02x\n", i, color.r, color.g, color.b);
98 }
99 #endif
100 }