Debian Codegraph @

src/mixer2/overlay/overlay.cpp

raw symbols SCIP
1 /* overlay.cpp
2 * Copyright (C) 2006 Jean-Sebastien Senecal ([email protected])
3 * This file is a Frei0r plugin.
4 * The code is a modified version of code from the Gimp.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #include "frei0r.hpp"
22 #include "frei0r/math.h"
23
24 #define NBYTES 4
25 #define ALPHA 3
26
27 class overlay : public frei0r::mixer2
28 {
29 public:
30 overlay(unsigned int width, unsigned int height)
31 {
32 this->width = width;
33 this->height = height;
34 this->size = width * height;
35 }
36
37 /**
38 *
39 * Perform an RGB[A] overlay operation between the pixel sources
40 * in1 and in2, using the generalised algorithm:
41 *
42 * D = A * (B + (2 * B) * (255 - A))
43 *
44 **/
45 void update(double time,
46 uint32_t* out,
47 const uint32_t* in1,
48 const uint32_t* in2)
49 {
50 // Validate inputs
51 if (!out || !in1 || !in2) {
52 return;
53 }
54
55 const uint8_t *src1 = reinterpret_cast<const uint8_t*>(in1);
56 const uint8_t *src2 = reinterpret_cast<const uint8_t*>(in2);
57 uint8_t *dst = reinterpret_cast<uint8_t*>(out);
58 uint32_t sizeCounter = size;
59
60 // Validate size
61 if (sizeCounter == 0) {
62 return;
63 }
64
65 uint32_t b, tmp, tmpM;
66
67 while (sizeCounter--)
68 {
69 for (b = 0; b < ALPHA; b++)
70 {
71 dst[b] = INT_MULT(src1[b], src1[b] + INT_MULT(2 * src2[b], 255 - src1[b], tmpM), tmp);
72 }
73
74 dst[ALPHA] = MIN(src1[ALPHA], src2[ALPHA]);
75
76 src1 += NBYTES;
77 src2 += NBYTES;
78 dst += NBYTES;
79 }
80 }
81
82
83
84 };
85
86
87 frei0r::construct<overlay> plugin("overlay",
88 "Perform an RGB[A] overlay operation between the pixel sources, using the generalised algorithm: D = A * (B + (2 * B) * (255 - A))",
89 "Jean-Sebastien Senecal",
90 0,2,
91 F0R_COLOR_MODEL_RGBA8888);
92