Darkening / Ligthening

Darkening and Lightening: You can take an image and make it darker or lighter. For this assignment making an image darker will be defined as decreasing the values of the RGB values of all the pixels by a set decrement (make the values approach 0,0,0). Making an image lighter will be defined as increasing the values of the RGB values of all the pixels by a set increment (make the values approach 255, 255, 255).
The original picture:


The critical code:
public Image makeShade(int change){ Image temp=null; 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); 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; }