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"
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 bluescreen0r : public frei0r::filter
33 {
34 private:
35 double dist;
36 f0r_param_color color;
37 bool invert;
38 uint32_t r256,g256,b256;
39
40 // returns the distance to 'color', but does not normalize
41 inline uint32_t distance(uint32_t pixel) {
42 uint32_t d = 0;
43 int t;
44 t = ((pixel&0x00FF0000) >> 16) - b256;
45 d += t*t;
46 t = ((pixel&0x0000FF00) >> 8) - g256;
47 d += t*t;
48 t = ((pixel&0x000000FF) >> 0) - r256;
49 d += t*t;
50
51 return (uint32_t) d; // no sqrtf
52 }
53 public:
54 bluescreen0r(unsigned int width, unsigned int height)
55 {
56 dist = 0.288;
57
58 color.r = 0;
59 color.g = 0.94;
60 color.b = 0;
61
62 invert = false;
63
64 register_param(color, "Color", "The color to make transparent (B G R)");
65 register_param(dist, "Distance", "Distance to Color (127 is good)");
66 register_param(invert, "Invert", "Whether to produce the inverse of the effect on the alpha channel");
67 }
68
69 virtual void update(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) (dist*dist*195075);
76 uint32_t distInt2 = distInt/2;
77
78 r256=255*color.r;
79 g256=255*color.g;
80 b256=255*color.b;
81
82 while(pixel != in+size) {
83 *outpixel= (*pixel & 0x00FFFFFF); // copy all except alpha
84
85 uint32_t d = distance(*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 (invert) a = 255 - a;
94 *outpixel |= (a<<24);
95
96 ++outpixel;
97 ++pixel;
98 }
99 }
100 };
101
102
103 frei0r::construct<bluescreen0r> plugin("bluescreen0r",
104 "Color to alpha (blit SRCALPHA)",
105 "Hedde Bosman",
106 0, 5,
107 F0R_COLOR_MODEL_RGBA8888);