by gp2000 · 10y ago · 0 comments
frac = 0;
while (len > 0) {
for (frac += scale; frac >= 1; frac--)
*dst++ = *src;
src++;
}
Instead of repeating the work of the inner loop every time, generate the code that has the scale baked in. For instance, doubling the image would output this code fragment repeated for the width of the source image: *dst++ = *src; *dst++ = *src; src++;
And scaling down by half would be: *dst++ = *src; src++; src++;
Though whether this is faster or the best technique really depends on the processor. It might be just as easy to pre-compute a lookup table pointing to the offset of the source pixel for each destination one. That's something an 8086 could do fairly easily and maybe a 6502, but not so much for a Z-80.No comments yet.