Contrast: When increasing contrast the dark colors get darker
and the light colors get darker. When decreasing contrast the dark colors
get lighter and the light colors get darker (start to become more alike).
The critical code:
public Image makeShade(int change){
Image temp=null;
int test=0;
try{
int pixel[] = new int[w*h];
PixelGrabber pg = new PixelGrabber(c, 0, 0, w, h, pixel, 0, w);
if(pg.grabPixels() &&((pg.status() & ImageObserver.ALLBITS) != 0)){
for(int x = 0; x< w * h; x++){
int r = (pixel[x] & 0x00ff0000)>>16;
int g = (pixel[x] & 0x0000ff00)>>8;
int b = (pixel[x] & 0x000000ff);
test=0;
if(r>128) test++; if(g>128) test++; if(b>128) test++;
if(test>1){
r+=change; g+=change; b+=change;
}
else{
r-=change; g-=change; b-=change;
}
if(r<0) r=0; if(g<0) g=0; if(b<0) b=0;
if(r>255) r=255; if(g>255) g=255; if(b>255) b=255;
pixel[x]= (255<<24) | (r<<16) | (g<<8) | b;
}
temp=createImage(new MemoryImageSource(w, h, pixel, 0, w));
}
}catch(InterruptedException e) { }
return temp;
}