Hauptseite   Klassenhierarchie   Auflistung der Dateien  

filterstamp.cpp

00001 /**********************************************************************************
00002 * Copyright (c) 2003, Matthias Bader and Christoph Rueegg <opendev@cdrnet.ch>     *
00003 * All rights reserved.                                                            *
00004 *                                                                                 *
00005 * Project Website: http://www.cdrnet.net/projects/painter/                        *
00006 *                                                                                 *
00007 * Redistribution and use in source and binary forms, with or without modification,*
00008 * are permitted provided that the following conditions are met:                   *
00009 *                                                                                 *
00010 * 1. Redistributions of source code must retain the above copyright notice,       *
00011 * this list of conditions and the following disclaimer.                           *
00012 *                                                                                 *
00013 * 2. Redistributions in binary form must reproduce the above copyright notice,    *
00014 * this list of conditions and the following disclaimer in the documentation       *
00015 * and/or other materials provided with the distribution.                          *
00016 *                                                                                 *
00017 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"     *
00018 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE       *
00019 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE      *
00020 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE        *
00021 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR             *
00022 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF            *
00023 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS        *
00024 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN         *
00025 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)         *
00026 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF          *
00027 * THE POSSIBILITY OF SUCH DAMAGE.                                                 *
00028 **********************************************************************************/
00029 
00030 #include "filterstamp.h"
00031 #include <cmath>
00032 
00033 StampFilter::StampFilter() : ChannelFilter<unsigned char>()
00034 {
00035   stamp = GrayImage::CreateFromTiff("stamp.tif");
00036   stamp->LoadAlphaMap("stampa.tif");
00037 }
00038 
00039 StampFilter::~StampFilter()
00040 {
00041   delete stamp;
00042 }
00043 
00044 ChannelFilter<unsigned char>* StampFilter::EmptyClone()
00045 {
00046   StampFilter *copy = new StampFilter();
00047   copy->SetSubChannel(ChannelFilter<unsigned char>::GetSubChannel());
00048   return(copy);
00049 }
00050 
00051 void StampFilter::OnMouseEvent(const int button, const int state, int x, int y)
00052 {
00053   if(state == 0 && button == 0)
00054   {
00055     
00056   int i, j;
00057   int i_left, i_right, j_top, j_bottom;
00058   float alpha;
00059 
00060   //assert(StampImage->width==StampImageAlpha->width);         //do the two stamp images have the same dimensions?
00061   //assert(StampImage->height==StampImageAlpha->height);
00062 
00063   i_left=0;
00064   j_top=0;
00065   i_right=stamp->GetWidth();
00066   j_bottom=stamp->GetHeight();
00067   x -= i_right/2;
00068   y -= j_bottom/2;
00069 
00070   if (x+i_right>GetWidth())   i_right=GetWidth()-x; //we don't want to stamp off-image areas
00071   if (y+j_bottom>GetHeight())  j_bottom=GetHeight()-y;
00072   if (x<0)                              i_left=-x;
00073   if (y<0)                               j_top=-y;
00074 
00075   for (j=j_top; j<j_bottom; j++)
00076   {
00077     for (i=i_left; i<i_right; i++)
00078     {
00079       alpha=(stamp->GetAlpha(i,j))/255.0f;    //this is the alpha value. It goes from [0 to 1]. 0 means transparent, 1 means solid.
00080       Set(i+x,j+y,(unsigned char)(alpha*stamp->GetLuminance(i,j)+(1-alpha)*Get(i+x,j+y)));
00081       //img->data[(i + destleft) + (j + desttop)*img->width] = (unsigned char) (alpha*StampImage->data[i + j*StampImage->width] + (1-alpha)*img->data[(i + destleft) + (j + desttop)*img->width]);
00082     }                                        //the line above renders the stampImage into img by using the alpha values from stampImageAlpha
00083   }
00084   }
00085 }
00086 
00087 
00088 

Erzeugt am Fri Jan 31 15:27:35 2003 für OOP Miniprojekt von doxygen1.3-rc2