Blender  V2.59
FilterBlueScreen.h
Go to the documentation of this file.
00001 /* $Id: FilterBlueScreen.h 35082 2011-02-22 19:30:37Z jesterking $
00002 -----------------------------------------------------------------------------
00003 This source file is part of blendTex library
00004 
00005 Copyright (c) 2007 The Zdeno Ash Miklas
00006 
00007 This program is free software; you can redistribute it and/or modify it under
00008 the terms of the GNU Lesser General Public License as published by the Free Software
00009 Foundation; either version 2 of the License, or (at your option) any later
00010 version.
00011 
00012 This program is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00014 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
00015 
00016 You should have received a copy of the GNU Lesser General Public License along with
00017 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00018 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
00019 http://www.gnu.org/copyleft/lesser.txt.
00020 -----------------------------------------------------------------------------
00021 */
00022 
00027 #if !defined FILTERBLUESCREEN_H
00028 #define FILTERBLUESCREEN_H
00029 
00030 #include "Common.h"
00031 
00032 #include "FilterBase.h"
00033 
00034 
00036 class FilterBlueScreen : public FilterBase
00037 {
00038 public:
00040         FilterBlueScreen (void);
00042         virtual ~FilterBlueScreen (void) {}
00043 
00045         unsigned char * getColor (void) { return m_color; }
00047         void setColor (unsigned char red, unsigned char green, unsigned char blue);
00048 
00050         unsigned short * getLimits (void) { return m_limits; }
00052         void setLimits (unsigned short minLimit, unsigned short maxLimit);
00053 
00054 protected:
00056         unsigned char m_color[3];
00059         unsigned short m_limits[2];
00061         unsigned int m_squareLimits[2];
00063         unsigned int m_limitDist;
00064 
00066         template <class SRC> unsigned int tFilter (SRC src, short x, short y,
00067                 short * size, unsigned int pixSize, unsigned int val)
00068         {
00069                 // calculate differences
00070                 int difRed = int(VT_R(val)) - int(m_color[0]);
00071                 int difGreen = int(VT_G(val)) - int(m_color[1]);
00072                 int difBlue = int(VT_B(val)) - int(m_color[2]);
00073                 // calc distance from "blue screen" color
00074                 unsigned int dist = (unsigned int)(difRed * difRed + difGreen * difGreen
00075                         + difBlue * difBlue);
00076                 // condition for fully transparent color
00077                 if (m_squareLimits[0] >= dist) 
00078                         // return color with zero alpha
00079                         VT_A(val) = 0;
00080                 // condition for fully opaque color
00081                 else if (m_squareLimits[1] <= dist)
00082                         // return normal color
00083                         VT_A(val) = 0xFF;
00084                 // otherwise calc alpha
00085                 else
00086                         VT_A(val) = (((dist - m_squareLimits[0]) << 8) / m_limitDist);
00087                 return val;
00088         }
00089 
00091         virtual unsigned int filter (unsigned char * src, short x, short y,
00092                 short * size, unsigned int pixSize, unsigned int val = 0)
00093         { return tFilter(src, x, y, size, pixSize, val); }
00095         virtual unsigned int filter (unsigned int * src, short x, short y,
00096                 short * size, unsigned int pixSize, unsigned int val = 0)
00097         { return tFilter(src, x, y, size, pixSize, val); }
00098 };
00099 
00100 
00101 #endif