Blender V2.61 - r43446

ImageMix.h

Go to the documentation of this file.
00001 /*
00002 -----------------------------------------------------------------------------
00003 This source file is part of VideoTexture 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 IMAGEMIX_H
00028 #define IMAGEMIX_H
00029 
00030 
00031 #include "Common.h"
00032 
00033 #include "ImageBase.h"
00034 #include "FilterBase.h"
00035 
00036 
00038 class ImageSourceMix : public ImageSource
00039 {
00040 public:
00042     ImageSourceMix (const char * id) : ImageSource(id), m_weight(0x100) {}
00044     virtual ~ImageSourceMix (void) {}
00045 
00047     long long getOffset (void) { return m_offset; }
00049     void setOffset (unsigned int * firstImg) { m_offset = m_image - firstImg; }
00050 
00052     short getWeight (void) { return m_weight; }
00054     void setWeight (short weight) { m_weight = weight; }
00055 
00056 protected:
00058     long long m_offset;
00060     short m_weight;
00061 };
00062 
00063 
00065 class ImageMix : public ImageBase
00066 {
00067 public:
00069     ImageMix (void) : ImageBase(false) {}
00070 
00072     virtual ~ImageMix (void) {}
00073 
00075     short getWeight (const char * id);
00077     bool setWeight (const char * id, short weight);
00078 
00079 protected:
00080 
00082     virtual ImageSource * newSource (const char * id) { return new ImageSourceMix(id); }
00083 
00085     virtual void calcImage (unsigned int texId, double ts);
00086 };
00087 
00088 
00090 class FilterImageMix : public FilterBase
00091 {
00092 public:
00094     FilterImageMix (ImageSourceList & sources) : m_sources(sources) {}
00096     virtual ~FilterImageMix (void) {}
00097 
00098 protected:
00100     ImageSourceList & m_sources;
00101 
00103     virtual unsigned int filter (unsigned int * src, short x, short y,
00104         short * size, unsigned int pixSize, unsigned int val = 0)
00105     {
00106         // resulting pixel color
00107         int color[] = {0, 0, 0, 0};
00108         // iterate sources
00109         for (ImageSourceList::iterator it = m_sources.begin(); it != m_sources.end(); ++it)
00110         {
00111             // get pointer to mixer source
00112             ImageSourceMix * mixSrc = static_cast<ImageSourceMix*>(*it);
00113             // add weighted source pixel to result
00114             color[0] += mixSrc->getWeight() * (src[mixSrc->getOffset()] & 0xFF);
00115             color[1] += mixSrc->getWeight() * ((src[mixSrc->getOffset()] >> 8) & 0xFF);
00116             color[2] += mixSrc->getWeight() * ((src[mixSrc->getOffset()] >> 16) & 0xFF);
00117             color[3] += mixSrc->getWeight() * ((src[mixSrc->getOffset()] >> 24) & 0xFF);
00118         }
00119         // return resulting color
00120         return ((color[0] >> 8) & 0xFF) | (color[1] & 0xFF00)
00121             | ((color[2] << 8) & 0xFF0000) | ((color[3] << 16) & 0xFF000000);
00122     }
00123 };
00124 
00125 
00126 #endif
00127