Blender V2.61 - r43446
|
00001 /* 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 FILTERCOLOR_H 00028 #define FILTERCOLOR_H 00029 00030 #include "Common.h" 00031 00032 #include "FilterBase.h" 00033 00034 00036 class FilterGray : public FilterBase 00037 { 00038 public: 00040 FilterGray (void) {} 00042 virtual ~FilterGray (void) {} 00043 00044 protected: 00046 template <class SRC> unsigned int tFilter (SRC src, short x, short y, 00047 short * size, unsigned int pixSize, unsigned int val) 00048 { 00049 // calculate gray value 00050 unsigned int gray = (28 * (VT_B(val)) + 151 * (VT_G(val)) 00051 + 77 * (VT_R(val))) >> 8; 00052 // return gray scale value 00053 VT_R(val) = gray; 00054 VT_G(val) = gray; 00055 VT_B(val) = gray; 00056 return val; 00057 } 00058 00060 virtual unsigned int filter (unsigned char * src, short x, short y, 00061 short * size, unsigned int pixSize, unsigned int val = 0) 00062 { return tFilter(src, x, y, size, pixSize, val); } 00064 virtual unsigned int filter (unsigned int * src, short x, short y, 00065 short * size, unsigned int pixSize, unsigned int val = 0) 00066 { return tFilter(src, x, y, size, pixSize, val); } 00067 }; 00068 00069 00071 typedef short ColorMatrix[4][5]; 00072 00074 class FilterColor : public FilterBase 00075 { 00076 public: 00078 FilterColor (void); 00080 virtual ~FilterColor (void) {} 00081 00083 ColorMatrix & getMatrix (void) { return m_matrix; } 00085 void setMatrix (ColorMatrix & mat); 00086 00087 protected: 00089 ColorMatrix m_matrix; 00090 00092 unsigned char calcColor (unsigned int val, short idx) 00093 { 00094 return (((m_matrix[idx][0] * (VT_R(val)) + m_matrix[idx][1] * (VT_G(val)) 00095 + m_matrix[idx][2] * (VT_B(val)) + m_matrix[idx][3] * (VT_A(val)) 00096 + m_matrix[idx][4]) >> 8) & 0xFF); 00097 } 00098 00100 template <class SRC> unsigned int tFilter (SRC src, short x, short y, 00101 short * size, unsigned int pixSize, unsigned int val) 00102 { 00103 // return calculated color 00104 int color; 00105 VT_RGBA(color, calcColor(val, 0), calcColor(val, 1), calcColor(val, 2), calcColor(val, 3)); 00106 return color; 00107 } 00108 00110 virtual unsigned int filter (unsigned char * src, short x, short y, 00111 short * size, unsigned int pixSize, unsigned int val = 0) 00112 { return tFilter(src, x, y, size, pixSize, val); } 00114 virtual unsigned int filter (unsigned int * src, short x, short y, 00115 short * size, unsigned int pixSize, unsigned int val = 0) 00116 { return tFilter(src, x, y, size, pixSize, val); } 00117 }; 00118 00119 00121 typedef unsigned short ColorLevel[4][3]; 00122 00124 class FilterLevel : public FilterBase 00125 { 00126 public: 00128 FilterLevel (void); 00130 virtual ~FilterLevel (void) {} 00131 00133 ColorLevel & getLevels (void) { return levels; } 00135 void setLevels (ColorLevel & lev); 00136 00137 protected: 00139 ColorLevel levels; 00140 00142 unsigned int calcColor (unsigned int val, short idx) 00143 { 00144 unsigned int col = VT_C(val,idx); 00145 if (col <= levels[idx][0]) col = 0; 00146 else if (col >= levels[idx][1]) col = 0xFF; 00147 else col = (((col - levels[idx][0]) << 8) / levels[idx][2]) & 0xFF; 00148 return col; 00149 } 00150 00152 template <class SRC> unsigned int tFilter (SRC src, short x, short y, 00153 short * size, unsigned int pixSize, unsigned int val) 00154 { 00155 // return calculated color 00156 int color; 00157 VT_RGBA(color, calcColor(val, 0), calcColor(val, 1), calcColor(val, 2), calcColor(val, 3)); 00158 return color; 00159 } 00160 00162 virtual unsigned int filter (unsigned char * src, short x, short y, 00163 short * size, unsigned int pixSize, unsigned int val = 0) 00164 { return tFilter(src, x, y, size, pixSize, val); } 00166 virtual unsigned int filter (unsigned int * src, short x, short y, 00167 short * size, unsigned int pixSize, unsigned int val = 0) 00168 { return tFilter(src, x, y, size, pixSize, val); } 00169 }; 00170 00171 00172 #endif