Read directly from GD structure instead of calling imagecolorat. 100x
speedup.