| 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"cxx . . $ `<file>/include/frei0r.hpp`/ |
| 23 | #include "frei0r/math.h"cxx . . $ `<file>/include/frei0r/math.h`/ |
| 24 | |
| 25 | #define NBYTEScxx . . $ `src/mixer2/addition_alpha/addition_alpha.cpp:25:9`! 4 |
| 26 | #define ALPHAcxx . . $ `src/mixer2/addition_alpha/addition_alpha.cpp:26:9`! 3 |
| 27 | |
| 28 | class addition_alphacxx . . $ addition_alpha# : public frei0rcxx . . $ frei0r/::mixer2cxx . . $ frei0r/mixer2# |
| 29 | { |
| 30 | public: |
| 31 | addition_alphacxx . . $ addition_alpha#addition_alpha(b4d55b1286ff73e8).(unsigned int width, unsigned int height) |
| 32 | { |
| 33 | // initialize look-up table |
| 34 | for (int i = 0; i < 256; i++) |
| 35 | add_lutcxx . . $ addition_alpha#add_lut.[i] = i; |
| 36 | for (int i = 256; i <= 510; i++) |
| 37 | add_lutcxx . . $ addition_alpha#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 updatecxx . . $ addition_alpha#update(aea6c563decfb03a).(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 = sizecxx . . $ frei0r/fx#size.; |
| 58 | |
| 59 | uint32_t b; |
| 60 | |
| 61 | while (sizeCounter--) |
| 62 | { |
| 63 | for (b = 0; b < ALPHAcxx . . $ `src/mixer2/addition_alpha/addition_alpha.cpp:26:9`!; b++) |
| 64 | D[b] = add_lutcxx . . $ addition_alpha#add_lut.[A[b] + ((B[b]*B[ALPHAcxx . . $ `src/mixer2/addition_alpha/addition_alpha.cpp:26:9`!])>>8)]; |
| 65 | |
| 66 | D[ALPHAcxx . . $ `src/mixer2/addition_alpha/addition_alpha.cpp:26:9`!] = 255; |
| 67 | A += NBYTEScxx . . $ `src/mixer2/addition_alpha/addition_alpha.cpp:25:9`!; |
| 68 | B += NBYTEScxx . . $ `src/mixer2/addition_alpha/addition_alpha.cpp:25:9`!; |
| 69 | D += NBYTEScxx . . $ `src/mixer2/addition_alpha/addition_alpha.cpp:25:9`!; |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | private: |
| 74 | static uint8_t add_lutcxx . . $ addition_alpha#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_alphacxx . . $ addition_alpha#::add_lutcxx . . $ addition_alpha#add_lut.[511]; |
| 78 | |
| 79 | frei0rcxx . . $ frei0r/::constructcxx . . $ frei0r/construct#<addition_alphacxx . . $ addition_alpha#> plugincxx . . $ plugin.("addition_alpha"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., |
| 80 | "Perform an RGB[A] addition_alpha operation of the pixel sources."cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., |
| 81 | "Jean-Sebastien Senecal"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., |
| 82 | 0,2, |
| 83 | F0R_COLOR_MODEL_RGBA8888cxx . . $ `include/frei0r.h:308:9`!); |
| 84 |