Added gamma correction, writing to image file.