473,796 Members | 2,536 Online
Bytes | Software Development & Data Engineering Community
+ 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(++pScree n, 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%c gl%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 4526
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(++pScree n, 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
2461
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 to do it, other than actually coding the math, which would be a pain (especially since the indexes aren't equally spaced). Is there a common library file or something for interpolation? Thanks in advance! Dave
14
5204
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 ideas or PD code I can put to use right away. At the moment, I'm maintaining a contour calculation and plotting program for radio wave propagation studies. This program uses a number of routines written by and for the FCC in Fortran in 1976...
45
9436
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, OcelotIguana@yahoo.com
3
3912
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 it shall return the y value to any x value given. e.g. p1: (0,0) p2 (1000,50) y value to calculate at x=600
20
9180
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., int_fast32_t 4) integer capable of holding a pointer, intptr_t 5) widest integer in the implementation, intmax_t Is there a valid motivation for having both int_least and int_fast?
5
2376
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 !!! Dim bTracking As Boolean Dim blackPen As Pen Dim g As Graphics
5
3813
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 P P P R R R R T T T Z Z Z Z Z Z Z i know that i have to look in the begining of this file. but what is the steps to find j/ thank you for your help
0
1289
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 well as expressions. NB. It uses eval(), so only use it in trusted contexts! import sys, re def interp(string): locals = sys._getframe(1).f_locals globals = sys._getframe(1).f_globals
5
2820
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 API. I guess that beeing CPU friendly and using little RAM both count very high here as criteria. Here are some methods to be considered (probably not complete):
0
9680
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9528
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10456
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10230
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9052
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7548
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5442
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5575
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2926
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.