fix bug (dereferencing NULL pointer) + add lots of assert()s
fix bad usage of ... ? ... : ... :
it should NOT be
... ? x = ... : x = ...
but
x = ... ? ... : ...
- the affectation is clear
- if you prefer the first form, you should use if..then..else instead
bug fix: r,g,b,a could never be 0 when offset is not zero.
avoid incrementing pointers: the compiler knows very well how to optimize simple loops.
* use pre-increment instead of post increment:
- more readable ("increment i" is better than "i to be incremented")
- avoids unnecessary temporariess, see http://www.gotw.ca/gotw/002.htm and http://stackoverflow.com/questions/24901/is-there-a-performance-difference-between-i-and-i-in-c (as well as good C++ books such as "Exceptional C++")
* avoid more than 1 instruction per line: this is very hard to debug and hard to read. 1-line loops and if's should be forbidden.