* optimize swap code
* move private variable declarations to cpp
* correctly handle RGBA, BGRA, RGB, BGR formats