Tja, also alpha ist ein double, disp.mouse_y() ist ein integer.
Code:
#include "CImg.h"
using namespace cimg_library;
int main()
{
CImg<int>img("leucht.jpg");
CImgList<double>visu(img, CImg<int>(100,450,1,3,0));
CImgDisplay disp(visu,"Test");
int pw, mw, neu, i, j, valR, valG, valB, avg = 0;
int tsize = 24;
const unsigned char white[] = {255,255,255};
const unsigned char blue[] = {0,0,255};
const unsigned char lblue[] = {0,0,192};
const unsigned char dblue[] = {0,0,128};
for (double alpha = 0.5; !disp.is_closed() && !disp.is_keyQ() && !disp.is_keyESC(); )
{
for(int x=1; x<img.width()-1; x++)
{
for(int y=1; y<img.height()-1; y++)
{
pw = img(x,y,0,0);
mw = 0;
for(i=-1; i<=1; i++)
{
for(j=-1; j<=1; j++)
{
mw += img(x+i, y+j, 0, 0);
}
}
mw /= 9;
neu = (int)((pw - (alpha*mw)) / (1.0-alpha));
if(neu > 255)
{
neu = 255;
}
else if(neu < 0)
{
neu = 0;
}
visu[0](x,y,0,0) = neu;
valR = visu[0](x,y,0,0); // Read the red component
valG = visu[0](x,y,0,1); // Read the green component
valB = visu[0](x,y,0,2); // Read the blue component (Z
avg = (int)((valR + valG + valB)/3); // Compute average pixel value.
visu[0](x,y,0,0) = visu[0](x,y,0,1) = visu[0](x,y,0,2) = avg; //Graubild
}
}
visu[1].fill(0).draw_text(25,5,"Alpha",white,0,1,tsize).
draw_text(35,450-tsize-5,"%.2f",white,0,1,tsize,alpha);
visu[0].draw_line(img.width()-1,0,img.width()-1,img.height(),white,1);
const int yb = (int)((450-tsize-25)-(alpha*(450-50-(2*tsize))));
visu[1].draw_rectangle(38, 450-tsize-23, 62, tsize+23, lblue, 1).
draw_rectangle(39, 450-tsize-24, 61, tsize+24, dblue, 1).draw_rectangle(40, 450-tsize-25, 60, yb, blue, 1);
if ((disp.button()) && (disp.mouse_x()>=img.width() + 38) && (disp.mouse_x()<=img.width() + 62) &&
(disp.mouse_y()>=tsize + 25) && (disp.mouse_y()<=450-tsize-25))
{
alpha = ((disp.mouse_y() -450 +25 +tsize) / ((50 +(2*tsize) -450)/100));
alpha/= 100;
if(alpha>0.999)
{
alpha = 0.999;
}
}
disp.resize(disp,false).display(visu).wait();
}
}