473,474 Members | 1,614 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

fast integer interpolation


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
Feb 5 '07 #1
2 4503
Gernot Frisch wrote:
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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Feb 5 '07 #2
Gernot Frisch wrote:
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.

--
Dr Jon D Harrop, Flying Frog Consultancy
OCaml for Scientists
http://www.ffconsultancy.com/product...ex.html?usenet
Feb 5 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: dave.harper | last post by:
I'm relativly new to C++, and have been looking for a way to interpolate data (i.e. a table indexed by 2 arrays, or just an array indexed by another array). I haven't been able to find an easy way...
14
by: Charles Banas | last post by:
I'm not sure if this is the right place to ask about this, but I've seen several posts in the past regarding Akima's Bivariate Interpolations routines, and i'm wondering if someone can give me some...
45
by: OcelotIguana | last post by:
Hello, Does anyone have any suggestions for where to find a good sincos routine (i.e. a routine that calculates both the sin and cos of a given argument) written in c? Thanks, ...
3
by: Jonas Ernst | last post by:
Hi, Can somebody give me some hints how to do a line interpolation without using floating point arithemtics? The function shall do a linear interpolation between 2 points (line interp?) and...
20
by: GS | last post by:
The stdint.h header definition mentions five integer categories, 1) exact width, eg., int32_t 2) at least as wide as, eg., int_least32_t 3) as fast as possible but at least as wide as, eg.,...
5
by: Manuel Daponte | last post by:
I found this code in this newsgroup and used it, but the lines drawn are composed of point too separated when the mouse moves at medium or fast speed. How can I fix it? Thanks in advance !!! ...
5
by: xandra | last post by:
i understood the concept of interpolation search. but i couldn't understand what would be the steps for that search. for example, if i'm searching for J in this file A A B E F H J M N N N N O P P...
0
by: MonkeeSage | last post by:
There are several string interpolation functions, as well as string.Template. But here's yet another. This one emulates ruby's inline interpolation syntax (using #{}), which interpolates strings as...
5
by: Marian Steinbach | last post by:
Howdy! I am just switching from PHP4 to PHP5. Since there are many different ways to create XML in PHP5, I'd like to know from the community which one would be suited best for a REST web service...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.