1 /* alphaxor.cpp 2 * Copyright (C) 2005 Jean-Sebastien Senecal (js@drone.ws) 3 * This file is a Frei0r plugin. 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 "frei0r_math.h" 22 23 #include <algorithm> 24 25 class alphaxor : public frei0r::mixer2 26 { 27 public: alphaxor(unsigned int width,unsigned int height)28 alphaxor(unsigned int width, unsigned int height) 29 { 30 } 31 update(double time,uint32_t * out,const uint32_t * in1,const uint32_t * in2)32 void update(double time, 33 uint32_t* out, 34 const uint32_t* in1, 35 const uint32_t* in2) 36 { 37 uint8_t *dst = reinterpret_cast<uint8_t*>(out); 38 const uint8_t *src1 = reinterpret_cast<const uint8_t*>(in1); 39 const uint8_t *src2 = reinterpret_cast<const uint8_t*>(in2); 40 41 for (unsigned int i=0; i<size; ++i) 42 { 43 uint32_t tmp1, tmp2; 44 uint8_t alpha_src1 = src1[3]; 45 uint8_t alpha_src2 = src2[3]; 46 uint8_t alpha_dst; 47 uint8_t w1 = 0xff ^ alpha_src2; // w1 = 255 - alpha_2 48 uint8_t w2 = 0xff ^ alpha_src1; // w2 = 255 - alpha_1 49 50 // compute destination alpha 51 alpha_dst = dst[3] = INT_MULT(alpha_src1, w1, tmp1) + INT_MULT(alpha_src2, w2, tmp2); 52 53 // compute destination values 54 if (alpha_dst == 0) 55 for (int b=0; b<3; ++b) 56 dst[b] = 0; 57 else 58 for (int b=0; b<3; ++b) 59 dst[b] = CLAMP0255( (uint32_t)( (uint32_t) (INT_MULT(src1[b], alpha_src1, tmp1) * w1 + INT_MULT(src2[b], alpha_src2, tmp2) * w2) / alpha_dst) ); 60 61 src1 += 4; 62 src2 += 4; 63 dst += 4; 64 } 65 } 66 67 }; 68 69 70 frei0r::construct<alphaxor> plugin("alphaxor", 71 "the alpha XOR operation", 72 "Jean-Sebastien Senecal", 73 0,2, 74 F0R_COLOR_MODEL_RGBA8888); 75 76