Graphic optimizations 1

The main optimizations here are in the CalGrayCS conversion and JPG decoder