Fast Contrast & Brightness
Hi there
I'm been trying to create an image contrast and brightness class
The thing is I would like to change the contrast Brightness with two seperated scrollbars
But I can not make it work fast enough
It hacks and you have to wait for a long time
whats wrong
should I use several threads or what
Here is my code that the scrollbar is calling
Contrast
publicvoid contrast2()
{
pixel =newint[imw*imh];
try
{
PixelGrabber pg =new PixelGrabber(im,0,0,imw,imh,pixel,0,imw);
pg.grabPixels();
}
catch(InterruptedException e)
{
e.printStackTrace();
}
int r;
int g;
int b;
int offset;
int i =0;
for(int x = 0; x < imw;x++)
{
for(int y = 0; y < imh; y++)
{
i = x+y*imw;
r= (pixel[i]>>16)&0xff;
g= (pixel[i]>>8)&0xff;
b= (pixel[i])&0xff;
r=(int)(r*contrast);
g=(int)(g*contrast);
b=(int)(b*contrast);
if(r > 255) r = 255;
if(g > 255) g = 255;
if(b > 255) b = 255;
pixel[i] = (pixel[i] & 0xff000000)|(r<<16) | (g<<8) | b;
}
}
ImageProducer ip =new MemoryImageSource(imw,imh,pixel,0,imw);
temp = toolkit.createImage(ip);
repaint();
}
Brightness
publicvoid brightness2()
{
pixel =newint[imw*imh];
try
{
PixelGrabber pg =new PixelGrabber(im,0,0,imw,imh,pixel,0,imw);
pg.grabPixels();
}
catch(InterruptedException e)
{
e.printStackTrace();
}
int r;
int g;
int b;
int offset;
int i =0;
for(int x = 0; x < imw;x++)
{
for(int y = 0; y < imh; y++)
{
i = x+y*imw;
r= (pixel[i]>>16)&0xff;
g= (pixel[i]>>8)&0xff;
b= (pixel[i])&0xff;
r=r+brightness;
g=g+brightness;
b=b+brightness;
if(r > 255) r = 255;
if(r < 0) r = 0;
if(g > 255) g = 255;
if(g < 0) g = 0;
if(b > 255) b = 255;
if(b < 0) b = 0;
pixel[i] = (pixel[i] & 0xff000000)|(r<<16) | (g<<8) | b;
}
}
ImageProducer ip =new MemoryImageSource(imw,imh,pixel,0,imw);
temp = toolkit.createImage(ip);
repaint();
}
Hm sun has to change the format renderer I see that the arrays look a litle suspicous but I think you understand any whay
Markus

