Improved code. Great speedup for graphics and video functions.

Improved code. Great speedup for graphics and video functions.