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 "filterdotselect.h"
00031
00032 ChannelSelectDotFilter::ChannelSelectDotFilter(bool withbar) : ChannelFilter<unsigned char>()
00033 {
00034 displayBar = false;
00035 this->withbar = withbar;
00036 selectedcolor = 100;
00037 selectedx = selectedy = 0;
00038 bartlx = bartly = 2;
00039 barbrx = barbry = 4;
00040 bar = new Channel<unsigned char>(barbry-bartly,barbrx-bartly);
00041 }
00042
00043 ChannelSelectDotFilter::~ChannelSelectDotFilter()
00044 {
00045 delete bar;
00046 }
00047
00048 void ChannelSelectDotFilter::SetSubChannel(Channel<unsigned char>* channel)
00049 {
00050 ChannelFilter<unsigned char>::SetSubChannel(channel);
00051 bartlx = 2;
00052 barbrx = channel->GetWidth()-2;
00053 barbry = (int)(float(channel->GetHeight())/12.0)+4;
00054 bartly = 2;
00055 delete bar;
00056 bar = new Channel<unsigned char>(barbry-bartly,barbrx-bartly);
00057 }
00058
00059 ChannelFilter<unsigned char>* ChannelSelectDotFilter::EmptyClone()
00060 {
00061 ChannelSelectDotFilter *copy = new ChannelSelectDotFilter(this->withbar);
00062 copy->SetSubChannel(ChannelFilter<unsigned char>::GetSubChannel());
00063 return(copy);
00064 }
00065
00066 void ChannelSelectDotFilter::OnMouseEvent(const int button, const int state, int x, int y)
00067 {
00068 if(button == 2 && state == 0 && withbar)
00069 {
00070 displayBar = true;
00071 for(int xi=bartlx;xi<barbrx;xi++)
00072 for(int yi=bartly;yi<barbry;yi++)
00073 {
00074 bar->Set(xi-bartlx,yi-bartly,ChannelFilter<unsigned char>::Get(xi,yi));
00075 ChannelFilter<unsigned char>::Set(xi,yi,(int)((255.0*xi)/(barbrx-bartlx)));
00076 }
00077 }
00078 if(button == 2 && state != 0)
00079 {;
00080 ChannelFilter<unsigned char>::Normalize(&x,&y);
00081 selectedx = x;
00082 selectedy = y;
00083 selectedcolor = ChannelFilter<unsigned char>::Get(x,y);
00084 if(withbar)
00085 {
00086 for(int xi=bartlx;xi<barbrx;xi++)
00087 for(int yi=bartly;yi<barbry;yi++)
00088 {
00089 ChannelFilter<unsigned char>::Set(xi,yi,bar->Get(xi-bartlx,yi-bartly));
00090 }
00091 displayBar = false;
00092 }
00093 }
00094 }
00095
00096 unsigned char ChannelSelectDotFilter::Get(const int x, const int y)
00097 {;
00098 if(displayBar && x>=bartlx && x<barbrx && y>=bartly && y<barbry)
00099 return(bar->Get(x,y));
00100 else
00101 return(ChannelFilter<unsigned char>::Get(x,y));
00102 }
00103
00104 void ChannelSelectDotFilter::Set(const int x, const int y, const unsigned char val)
00105 {
00106 if(displayBar && x>=bartlx && x<barbrx && y>=bartly && y<barbry)
00107 bar->Set(x,y,val);
00108 else
00109 ChannelFilter<unsigned char>::Set(x,y,val);
00110 }
00111
00112 void ChannelSelectDotFilter::ResetChannel()
00113 {
00114 if(displayBar && bar != 0)
00115 {
00116 for(int xi=bartlx;xi<barbrx;xi++)
00117 for(int yi=bartly;yi<barbry;yi++)
00118 {
00119 ChannelFilter<unsigned char>::Set(xi,yi,bar->Get(xi-bartlx,yi-bartly));
00120 }
00121 }
00122 ChannelFilter<unsigned char>::ResetChannel();
00123 }
00124
00125 unsigned char ChannelSelectDotFilter::GetSelectedColor()
00126 {
00127 return(selectedcolor);
00128 }
00129
00130 int ChannelSelectDotFilter::GetSelectedX()
00131 {
00132 return(selectedx);
00133 }
00134
00135 int ChannelSelectDotFilter::GetSelectedY()
00136 {
00137 return(selectedy);
00138 }