Also... to adjust the contrast take the average of the RGB like 64,64,64 you'ld subtract 10 or divide by 4 or 5, and like 192,192,192 you're add 10 etc. 128,128,128 would stay the same.
You may want to do this progressively like:
if r > 128 then
r = r + ((r - 128) / 2)
else
r = r - ((128 - r) / 2)
end if