3 ms·
You would have to skip variable number of pixels in source texture according to the transformation, then calculate the reverse transformation to know where to p
by ajuc 7y ago
You would have to skip variable number of pixels in source texture according to the transformation, then calculate the reverse transformation to know where to push.
Notice how you not only change x * 4 into x/4, you also change x++ into x+=4
for (int x=0; x<width; x++)
for (int y=0; y<height; y++)
destination[x][y] = source[x*4][y*4];
vs
for (int x=0; x<width; x+=4)
for (int y=0; y<height; y+=4)
destination[x/4][y/4] = source[x][y];
If it's as simple as scaling: x+=4 isn't much harder than x++. But for complex transformations calculation of how many pixels to skip in any particular row will be slow and complicated. Meanwhile when doing pull you don't need to do it.
This is the reason every graphical API i know of does these tranformations iterating over destination pixels.