Debian Codegraph @

src/filter/primaries/primaries.cpp

raw symbols SCIP
1 /*
2 * primaries
3 * 2009 Hedde Bosman
4 *
5 * This source code is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This source code is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Please refer
13 * to the GNU Public License for more details.
14 *
15 * You should have received a copy of the GNU Public License along
16 * with this source code; if not, write to: Free Software Foundation,
17 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 *
19 */
20 #include "frei0r.hpp"cxx . . $ `<file>/include/frei0r.hpp`/
21
22 #include <algorithm>
23 #include <vector>
24 #include <utility>
25 #include <cassert>
26
27 #include <iostream>
28
29 union px_tcxx . . $ px_t# {
30 uint32_t ucxx . . $ px_t#u.;
31 unsigned char ccxx . . $ px_t#c.[4]; // 0=B, 1=G,2=R,3=A ? i think :P
32 };
33
34 class primariescxx . . $ primaries# : public frei0rcxx . . $ frei0r/::filtercxx . . $ frei0r/filter# {
35 private:
36 double factorcxx . . $ primaries#factor.;
37
38 public:
39 primariescxx . . $ primaries#primaries(b4d55b1286ff73e8).(unsigned int width, unsigned int height) {
40 factorcxx . . $ primaries#factor. = 1;
41 register_paramcxx . . $ frei0r/fx#register_param(acfd1d4411be0164).(factorcxx . . $ primaries#factor., "Factor"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., "influence of mean px value. > 32 = 0"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
42 }
43 ~cxx . . $ primaries#`~primaries`(49f6e7a06ebc5aa8).primariescxx . . $ primaries#() {
44 }
45
46 virtual void updatecxx . . $ primaries#update(da7b4a17ceb4e697).(double time,
47 uint32_t* out,
48 const uint32_t* in) {
49 unsigned char mean = 0;
50
51 int f = factorcxx . . $ primaries#factor.+1; // f = [2,inf)
52 int factor127 = (f*f-3)*127;
53 int factorTot = f*f;
54 if (factor127 < 0) {
55 factor127 = 0;
56 factorTot = 3;
57 }
58
59 for (unsigned int i = 0; i < sizecxx . . $ frei0r/fx#size.; i++) {
60 px_tcxx . . $ px_t# pi;
61 pi.ucxx . . $ px_t#u. = in[i];
62
63 if (f > 32) // influence of mean color value does hardly change after this value
64 mean = 127;
65 else
66 mean = (pi.ccxx . . $ px_t#c.[0] + pi.ccxx . . $ px_t#c.[1] + pi.ccxx . . $ px_t#c.[2] + factor127)/factorTot;
67 pi.ccxx . . $ px_t#c.[0] = (pi.ccxx . . $ px_t#c.[0] > mean ? 255 : 0);
68 pi.ccxx . . $ px_t#c.[1] = (pi.ccxx . . $ px_t#c.[1] > mean ? 255 : 0);
69 pi.ccxx . . $ px_t#c.[2] = (pi.ccxx . . $ px_t#c.[2] > mean ? 255 : 0);
70
71 out[i] = pi.ucxx . . $ px_t#u.;
72 }
73 }
74 };
75
76
77 frei0rcxx . . $ frei0r/::constructcxx . . $ frei0r/construct#<primariescxx . . $ primaries#> plugincxx . . $ plugin.("primaries"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).,
78 "Reduce image to primary colors"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).,
79 "Hedde Bosman"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).,
80 0,2);
81