Debian Codegraph @

src/mixer2/addition_alpha/addition_alpha.cpp

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