Debian Codegraph @

src/filter/bluescreen0r/bluescreen0r.cpp

raw symbols SCIP
1 /*
2 * Bluescreen0r
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 #include <math.h>
30
31
32 class bluescreen0rcxx . . $ bluescreen0r# : public frei0rcxx . . $ frei0r/::filtercxx . . $ frei0r/filter#
33 {
34 private:
35 double distcxx . . $ bluescreen0r#dist.;
36 f0r_param_color colorcxx . . $ bluescreen0r#color.;
37 bool invertcxx . . $ bluescreen0r#invert.;
38 uint32_t r256cxx . . $ bluescreen0r#r256.,g256cxx . . $ bluescreen0r#g256.,b256cxx . . $ bluescreen0r#b256.;
39
40 // returns the distance to 'color', but does not normalize
41 inline uint32_t distancecxx . . $ bluescreen0r#distance(2141b656ce2cc063).(uint32_t pixel) {
42 uint32_t d = 0;
43 int t;
44 t = ((pixel&0x00FF0000) >> 16) - b256cxx . . $ bluescreen0r#b256.;
45 d += t*t;
46 t = ((pixel&0x0000FF00) >> 8) - g256cxx . . $ bluescreen0r#g256.;
47 d += t*t;
48 t = ((pixel&0x000000FF) >> 0) - r256cxx . . $ bluescreen0r#r256.;
49 d += t*t;
50
51 return (uint32_t) d; // no sqrtf
52 }
53 public:
54 bluescreen0rcxx . . $ bluescreen0r#bluescreen0r(b4d55b1286ff73e8).(unsigned int width, unsigned int height)
55 {
56 distcxx . . $ bluescreen0r#dist. = 0.288;
57
58 colorcxx . . $ bluescreen0r#color..r = 0;
59 colorcxx . . $ bluescreen0r#color..g = 0.94;
60 colorcxx . . $ bluescreen0r#color..b = 0;
61
62 invertcxx . . $ bluescreen0r#invert. = false;
63
64 register_paramcxx . . $ frei0r/fx#register_param(82eda48613cf5a7a).(colorcxx . . $ bluescreen0r#color., "Color"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., "The color to make transparent (B G R)"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
65 register_paramcxx . . $ frei0r/fx#register_param(acfd1d4411be0164).(distcxx . . $ bluescreen0r#dist., "Distance"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., "Distance to Color (127 is good)"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
66 register_paramcxx . . $ frei0r/fx#register_param(f12007cc47cdd2c7).(invertcxx . . $ bluescreen0r#invert., "Invert"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., "Whether to produce the inverse of the effect on the alpha channel"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
67 }
68
69 virtual void updatecxx . . $ bluescreen0r#update(da7b4a17ceb4e697).(double time,
70 uint32_t* out,
71 const uint32_t* in) {
72 const uint32_t* pixel =in;
73 uint32_t* outpixel= out;
74
75 uint32_t distInt = (uint32_t) (distcxx . . $ bluescreen0r#dist.*distcxx . . $ bluescreen0r#dist.*195075);
76 uint32_t distInt2 = distInt/2;
77
78 r256cxx . . $ bluescreen0r#r256.=255*colorcxx . . $ bluescreen0r#color..r;
79 g256cxx . . $ bluescreen0r#g256.=255*colorcxx . . $ bluescreen0r#color..g;
80 b256cxx . . $ bluescreen0r#b256.=255*colorcxx . . $ bluescreen0r#color..b;
81
82 while(pixel != in+sizecxx . . $ frei0r/fx#size.) {
83 *outpixel= (*pixel & 0x00FFFFFF); // copy all except alpha
84
85 uint32_t d = distancecxx . . $ bluescreen0r#distance(2141b656ce2cc063).(*pixel); // get distance
86 unsigned char a = (*pixel >> 24); // default alpha
87 if (d < distInt) {
88 a = 0;
89 if (d > distInt2) {
90 a = 256*(d-distInt2)/distInt2;
91 }
92 }
93 if (invertcxx . . $ bluescreen0r#invert.) a = 255 - a;
94 *outpixel |= (a<<24);
95
96 ++outpixel;
97 ++pixel;
98 }
99 }
100 };
101
102
103 frei0rcxx . . $ frei0r/::constructcxx . . $ frei0r/construct#<bluescreen0rcxx . . $ bluescreen0r#> plugincxx . . $ plugin.("bluescreen0r"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).,
104 "Color to alpha (blit SRCALPHA)"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).,
105 "Hedde Bosman"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).,
106 0, 5,
107 F0R_COLOR_MODEL_RGBA8888cxx . . $ `include/frei0r.h:308:9`!);