Debian Codegraph @

src/filter/timeout/timeout.cpp

raw symbols SCIP
1 /*
2 * Copyright (C) 2010-2011 Simon Andreas Eugster ([email protected])
3 * This file is not a Frei0r plugin but a collection of ideas.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program 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. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #include "frei0r.hpp"
21 #include <iostream>
22
23 //#define DEBUG
24
25 typedef unsigned char uchar;
26 struct ABGR {
27 uchar r;
28 uchar g;
29 uchar b;
30 uchar a;
31
32 ABGR blend(const ABGR &other, const float opacity)
33 {
34 #ifdef DEBUG
35 if (opacity < 0 || opacity > 1) {
36 std::cerr << "Timeout indicator: Opacity must be within 0 and 1!" << std::endl;
37 }
38 #endif
39 const float o1 = opacity;
40 const float o2= 1-opacity;
41 ABGR ret;
42 ret.r = o1*r + o2*other.r;
43 ret.g = o1*g + o2*other.g;
44 ret.b = o1*b + o2*other.b;
45 ret.a = other.a;
46 return ret;
47 }
48 };
49
50 class Timeout : public frei0r::filter
51 {
52
53 public:
54
55 Timeout(unsigned int width, unsigned int height)
56
57 {
58 register_param(m_time, "time", "Current time");
59 register_param(m_color, "color", "Indicator colour");
60 register_param(m_transparency, "transparency", "Indicator transparency");
61
62 W = std::min(width, height) / 20;
63 H = W;
64
65 x0 = width-2*W;
66 y0 = height-H;
67 }
68
69 ~Timeout()
70 {
71 // Delete member variables if necessary.
72 }
73
74 virtual void update(double time,
75 uint32_t* out,
76 const uint32_t* in)
77 {
78 std::copy(in, in + width*height, out);
79
80
81 ABGR col;
82 col.r = 255*m_color.r;
83 col.g = 255*m_color.g;
84 col.b = 255*m_color.b;
85 col.a = 255;
86
87 float yt = y0 - (1-m_time)*H;
88 ABGR *outAsABGR = (ABGR*) out;
89
90 #ifdef DEBUG
91 #define printcol(x) std::cout << #x ": [ " << (int) x.r << " | " << (int) x.g << " | " << (int) x.b << " ]" << std::endl;
92
93 std::cout << "r = " << m_color.r << ", g = " << m_color.g << std::endl;
94 ABGR blended = col.blend(outAsABGR[0], .5);
95 printcol(col);
96 printcol(outAsABGR[0]);
97 printcol(blended);
98 #undef printcol
99 #endif
100
101
102 for (int y = y0; y > int(yt); y--) {
103
104 float factor = 1-m_transparency;
105 if (y == int(yt)) {
106 factor *= 1 - (yt-int(yt));
107 }
108
109 for (int x = x0; x < x0+W; x++) {
110
111 outAsABGR[width*y + x] = col.blend(outAsABGR[width*y + x], factor);
112 }
113 }
114
115 }
116
117 private:
118 // The various f0r_params are adjustable parameters.
119 double m_time = 0.0;
120 f0r_param_color m_color = {0.0, 0.0, 0.0};
121 double m_transparency = 0.0;
122
123 unsigned int x0, y0;
124 unsigned int W , H ;
125
126 };
127
128
129
130 frei0r::construct<Timeout> plugin("Timeout indicator",
131 "Timeout indicators e.g. for slides.",
132 "Simon A. Eugster",
133 0,2,
134 F0R_COLOR_MODEL_RGBA8888);