fast integer interpolation

G

Gernot Frisch

Hi,

I have some code that scales from an image buffer to the screen buffer
(line by line).

Assume:
int Width; // Width of image (e.g. 32)
int zWidth; // Width of screen output (e.g. 192)

// Now, I perform interpolation of:
// --------------------------------

Offset2 = x * ((float)Width / (float)zWidth);

// like this:
// --------------

int fracx = (1<<16)/zWidth;
do
{
Offset2 = y_val + ( (XWidth * fracx) >>16);
[...]
}while(++pScreen, XWidth+=Width, ++x<linelen);

// Where { XWidth = x*(float)Width } so to say.

Is there any faster way (on ARM processors) like this? I mean: I still
have an multiplication and a shifting for every pixel.


--
-Gernot
int main(int argc, char** argv) {printf
("%silto%c%cf%cgl%ssic%ccom%c", "ma", 58, 'g', 64, "ba", 46, 10);}

________________________________________
Looking for a good game? Do it yourself!
GLBasic - you can do
www.GLBasic.com
 
V

Victor Bazarov

Gernot said:
I have some code that scales from an image buffer to the screen buffer
(line by line).

Assume:
int Width; // Width of image (e.g. 32)
int zWidth; // Width of screen output (e.g. 192)

// Now, I perform interpolation of:
// --------------------------------

Offset2 = x * ((float)Width / (float)zWidth);

// like this:
// --------------

int fracx = (1<<16)/zWidth;
do
{
Offset2 = y_val + ( (XWidth * fracx) >>16);
[...]
}while(++pScreen, XWidth+=Width, ++x<linelen);

// Where { XWidth = x*(float)Width } so to say.

Is there any faster way (on ARM processors) like this? I mean: I still
have an multiplication and a shifting for every pixel.

First of all, we can't discuss ARM processors here, they are off-topic.
If you need CPU-specific information, consider the newsgroup dedicated
to that CPU.

Second, the speed of any code should be considered within the context.
For that it needs to be measured first. Why is it you're not satisfied
with a mulitplication and a shift per iteration? How expensive (related
to the rest of the process) is it?

Try posting to 'comp.graphics.algorithms'. I am not saying that your
image stretching is necessarily specific to graphics. I think they just
might have a good solution for you, like a modified Bresenham's algorithm
for stepping through the resulting pixels instead of calculating each of
them individually.

V
 
J

Jon Harrop

Gernot said:
Is there any faster way (on ARM processors) like this? I mean: I still
have an multiplication and a shifting for every pixel.

You can use Bresenham's line algorithm to do integer interpolation. Have a
look for optimised line render and rasterising routines for Acorn computers
(e.g. by Jan Vlietinck and myself). They were all written in ARM assembler
rather than C++, of course.

IIRC, the approach you are already using (i.e. not Bresenham) was the
fastest.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top