Debian Codegraph @

src/mixer2/hardlight/hardlight.cpp

raw symbols SCIP
1 /* hardlight.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 hardlight : public frei0r::mixer2
28 {
29 public:
30 hardlight(unsigned int width, unsigned int height)
31 {
32 }
33
34 /**
35 *
36 * Perform an RGB[A] hardlight operation between the pixel sources
37 * in1 and in2.
38 *
39 **/
40 void update(double time,
41 uint32_t* out,
42 const uint32_t* in1,
43 const uint32_t* in2)
44 {
45 const uint8_t *src1 = reinterpret_cast<const uint8_t*>(in1);
46 const uint8_t *src2 = reinterpret_cast<const uint8_t*>(in2);
47 uint8_t *dst = reinterpret_cast<uint8_t*>(out);
48 uint32_t sizeCounter = size;
49
50 uint32_t b, tmp;
51
52 while (sizeCounter--)
53 {
54 for (b = 0; b < ALPHA; b++)
55 {
56 if (src2[b] > 128)
57 {
58 tmp = ((int) 255 - src1[b]) * ((int) 255 - ((src2[b] - 128) << 1));
59 dst[b] = (uint8_t) MAX255 (255 - (tmp >> 8));
60 }
61 else
62 {
63 tmp = (int) src1[b] * ((int) src2[b] << 1);
64 dst[b] = (uint8_t) MAX255 (tmp >> 8);
65 }
66 }
67
68 dst[ALPHA] = MIN(src1[ALPHA], src2[ALPHA]);
69
70 src1 += NBYTES;
71 src2 += NBYTES;
72 dst += NBYTES;
73 }
74 }
75
76
77
78 };
79
80
81 frei0r::construct<hardlight> plugin("hardlight",
82 "Perform an RGB[A] hardlight operation between the pixel sources",
83 "Jean-Sebastien Senecal",
84 0,2,
85 F0R_COLOR_MODEL_RGBA8888);
86