00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "filterstatefulltrans.h"
00031 #include <cmath>
00032
00033 StatefullTransformationFilter::StatefullTransformationFilter() : ChannelFilter<unsigned char>()
00034 {
00035 src = 0;
00036 active = false;
00037 x0 = y0 = 0;
00038 }
00039
00040 StatefullTransformationFilter::~StatefullTransformationFilter()
00041 {
00042 delete src;
00043 }
00044
00045 void StatefullTransformationFilter::OnMouseEvent(const int button, const int state, int x, int y)
00046 {
00047 if(button!=0)
00048 {
00049 return;
00050 }
00051 ChannelFilter<unsigned char>::Normalize(&x,&y);
00052 if(state == 0 && button == 0)
00053 {
00054 x0 = x;
00055 y0 = y;
00056 trg = ChannelFilter<unsigned char>::GetSubChannel();
00057 src = new Channel<unsigned char>(ChannelFilter<unsigned char>::GetHeight(),ChannelFilter<unsigned char>::GetWidth());
00058 for(int x1=0;x1<trg->GetWidth();x1++)
00059 for(int y1=0;y1<trg->GetHeight();y1++)
00060 src->Set(x1,y1,trg->Get(x1,y1));
00061 OnStart(src,trg,x0,y0);
00062 active = true;
00063 }
00064 if(state == 1 && button == 0)
00065 {
00066 active = false;
00067 OnEnd(src,trg,x0,y0,x,y);
00068 for(int x1=0;x1<trg->GetWidth();x1++)
00069 for(int y1=0;y1<trg->GetHeight();y1++)
00070 trg->Set(x1,y1,src->Get(x1,y1));
00071 delete src;
00072 src = 0;
00073 }
00074 }
00075
00076 void StatefullTransformationFilter::OnMotionEvent(int x, int y)
00077 {
00078 if(active)
00079 {
00080 ChannelFilter<unsigned char>::Normalize(&x,&y);
00081 OnRender(src,trg,x0,y0,x,y);
00082 x0 = x;
00083 y0 = y;
00084 }
00085 }
00086
00087 bool StatefullTransformationFilter::OnIdleEvent()
00088 {
00089 if(active)
00090 return(OnRender(src,trg,x0,y0,x0,y0));
00091 else
00092 return(false);
00093 }
00094
00095 void StatefullTransformationFilter::ResetChannel()
00096 {
00097 if(active)
00098 {
00099 active = false;
00100 for(int x1=0;x1<trg->GetWidth();x1++)
00101 for(int y1=0;y1<trg->GetHeight();y1++)
00102 trg->Set(x1,y1,src->Get(x1,y1));
00103 delete src;
00104 src = 0;
00105 }
00106 }
00107
00108 inline unsigned char StatefullTransformationFilter::Get(const int x, const int y)
00109 {
00110 if(active && src != 0)
00111 return(src->Get(x,y));
00112 else
00113 return(ChannelFilter<unsigned char>::Get(x,y));
00114 }
00115
00116 inline void StatefullTransformationFilter::Set(const int x, const int y, const unsigned char val)
00117 {
00118 if(active && src != 0)
00119 src->Set(x,y,val);
00120 else
00121 ChannelFilter<unsigned char>::Set(x,y,val);;
00122 }
00123