Need a good(cubic interp) image stretching/reducing library

Hi, I’ve been trying to find some basic library that will give me high quality image size reduction(bicubic/cubic interpolation)… I’ve looked at rotozoom, and it only interpolates when it enlarges, and I think it only uses linear interpolation. (Even when you are just reducing an image, there is a very noticable difference between linear and cubic interpolation)

I tried the bci library at http://nyxo.ru/ and while I could get the sample program to work, I couldn’t get it to work with how I thought it should work with SDL_surfaces…

I tried SDL_stretch, but couldn’t get it to work for anything… Do you have to rebuild SDL with that inserted into the source, or what? I’m using VC++ 2005 Express, is that what’s wrong? Would this library even do what I am wanting?

I looked at the gimp source, and couldn’t locate the proper code to see how they did it in there, since it is so massive…

The reason I want to find a library to interpolates well in reduction is that I am writing a game targeted at 1024x768, but I want to be able to let the user choose 800x600 or 640x480, and I’d like to be able to simply scale all of the images down in the program before using them, as opposed to storing a lot of prerendered reduced images of the same thing in my data/images folder. It would also allow for scaling upwards for higher res displays… Anyway, someone please help!

Thanks!
-David Olsen

The reason I want to find a library to interpolates well in reduction is
that I am writing a game targeted at 1024x768, but I want to be able to
let the user choose 800x600 or 640x480, and I’d like to be able to
simply scale all of the images down in the program before using them, as
opposed to storing a lot of prerendered reduced images of the same thing
in my data/images folder. It would also allow for scaling upwards for
higher res displays… Anyway, someone please help!

Thanks!
-David Olsen

Hi

There’s always OpenGL :slight_smile: which has IMHO good interpolation routines,
and what’s better - they’re hardware accelerated, which means you’ll get
them pretty much for free - during runtime, without any precaching…
neat, ehh? :slight_smile: Just load your image, convert it to OGL texture and
render it with GL_LINEAR enabled both for GL_TEXTURE_MAG_FILTER and
GL_TEXTURE_MIN_FILTER:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );

Though the name suggests that it’s linear interpolation, I think that
it’s sth better… some time ago I made tests where I enlarged textures
1000’s times and shrinked them 100’s times and rendered them on screen,
and I have to say, that VERY little pixelization occured. IMHO, for your
needs, when you’re going to scale by a lot less factors, it should be
good enough.

Of course, problems arise when you’re targetting platform which doesn’t
have hw accelerated OGL, or you don’t know OGL and don’t have time to
learn it… :-/

Koshmaar

Koshmaar wrote:

The reason I want to find a library to interpolates well in reduction
is that I am writing a game targeted at 1024x768, but I want to be
able to let the user choose 800x600 or 640x480, and I’d like to be
able to simply scale all of the images down in the program before
using them, as opposed to storing a lot of prerendered reduced images
of the same thing in my data/images folder. It would also allow for
scaling upwards for higher res displays… Anyway, someone please help!

Thanks!
-David Olsen

Hi

There’s always OpenGL :slight_smile: which has IMHO good interpolation routines,
and what’s better - they’re hardware accelerated, which means you’ll
get them pretty much for free - during runtime, without any
precaching… neat, ehh? :slight_smile: Just load your image, convert it to OGL
texture and render it with GL_LINEAR enabled both for
GL_TEXTURE_MAG_FILTER and GL_TEXTURE_MIN_FILTER:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );

Though the name suggests that it’s linear interpolation, I think that
it’s sth better…

No, that’s really bilinear. However a few cards provide better filtering
implementations, like anisotropic, or you can implement your own with
multitexturing as described there :
http://www.vrvis.at/via/research/hq-hw-reco/algorithm.html

Stephane

David Olsen wrote:

Hi, I’ve been trying to find some basic library that will give me high
quality image size reduction(bicubic/cubic interpolation)… I’ve
looked at rotozoom, and it only interpolates when it enlarges, and I
think it only uses linear interpolation. (Even when you are just
reducing an image, there is a very noticable difference between linear
and cubic interpolation)

I tried the bci library at http://nyxo.ru/ and while I could get the
sample program to work, I couldn’t get it to work with how I thought
it should work with SDL_surfaces…

I tried SDL_stretch, but couldn’t get it to work for anything… Do
you have to rebuild SDL with that inserted into the source, or what?
I’m using VC++ 2005 Express, is that what’s wrong? Would this library
even do what I am wanting?

I looked at the gimp source, and couldn’t locate the proper code to
see how they did it in there, since it is so massive…

The reason I want to find a library to interpolates well in reduction
is that I am writing a game targeted at 1024x768, but I want to be
able to let the user choose 800x600 or 640x480, and I’d like to be
able to simply scale all of the images down in the program before
using them, as opposed to storing a lot of prerendered reduced images
of the same thing in my data/images folder. It would also allow for
scaling upwards for higher res displays… Anyway, someone please help!

So, what’s your problem with implementing bicubic interpolation ? It’s
described here very clearly :
http://astronomy.swin.edu.au/~pbourke/colour/bicubic/

Stephane

So, what’s your problem with implementing bicubic interpolation ? It’s
described here very clearly :
http://astronomy.swin.edu.au/~pbourke/colour/bicubic/

Stephane

I guess it’s translating those equations into the kind of c/c++ equations
that will do the same thing. (I understand the concept of everything that it
says in the preceding text, but am lost in trying to apply it to the picture
info(it was easy to split the image into discreet red, green and blue
images - I also need to do alpha, but I figure it’ll be just the same as the
other channels. I also have no problem re-composing the image from those
seperate channels. )
Is it really so simple that no one has incorporated it into any of the
libraries available at libsdl.org? Sort of like, why post a library that can
add two numbers and give you the result? If so, please consider me a person
that can’t add two numbers without a calculator… and please post a c/c++
translation of those equations!

Thanks!
-David Olsen

----- Original Message -----
From: stephane.marchesin@wanadoo.fr (Stephane Marchesin)

David Olsen wrote:

<@Stephane_Marchesin>

So, what’s your problem with implementing bicubic interpolation ?
It’s described here very clearly :
http://astronomy.swin.edu.au/~pbourke/colour/bicubic/

Stephane

I guess it’s translating those equations into the kind of c/c++
equations that will do the same thing. (I understand the concept of
everything that it says in the preceding text, but am lost in trying
to apply it to the picture info(it was easy to split the image into
discreet red, green and blue images - I also need to do alpha, but I
figure it’ll be just the same as the other channels. I also have no
problem re-composing the image from those seperate channels. )
Is it really so simple that no one has incorporated it into any of the
libraries available at libsdl.org? Sort of like, why post a library
that can add two numbers and give you the result? If so, please
consider me a person that can’t add two numbers without a
calculator… and please post a c/c++ translation of those equations!

To implement it, just consider that your picture is the array F, and i
and j are the x and y coordinates. So to compute a given pixel at (i,j),
you need the 4*4 neighbouring values fetched by the double summation
m=-1…2 and n=-1…2

Btw, I think one of the equations is inaccurate, it says :
F(i’,j’)=…
while I think it should read :
F’(i,j)=…

Smssdl has a bicubic filter which is a direct implementation of these
equations :
http://membres.lycos.fr/cyxdown/smssdl/

Also, I think not many people implement the bicubic filter because it’s
not suitable for any kind of real time processing when done on the CPU
and big pictures.

Stephane> ----- Original Message ----- From: “Stephane Marchesin”

library

David Olsen wrote:

<stephane.marchesin at wanadoo.fr>

So, what’s your problem with implementing bicubic interpolation ? It’s
described here very clearly :
http://astronomy.swin.edu.au/~pbourke/colour/bicubic/

Stephane

I guess it’s translating those equations into the kind of c/c++ equations
that will do the same thing. (I understand the concept of everything that
it says in the preceding text, but am lost in trying to apply it to the
picture info(it was easy to split the image into discreet red, green and
blue images - I also need to do alpha, but I figure it’ll be just the
same as the other channels. I also have no problem re-composing the image
from those seperate channels. )
Is it really so simple that no one has incorporated it into any of the
libraries available at libsdl.org? Sort of like, why post a library that
can add two numbers and give you the result? If so, please consider me a
person that can’t add two numbers without a calculator… and please post
a c/c++ translation of those equations!

To implement it, just consider that your picture is the array F, and i and
j are the x and y coordinates. So to compute a given pixel at (i,j), you
need the 4*4 neighbouring values fetched by the double summation m=-1…2
and n=-1…2

Btw, I think one of the equations is inaccurate, it says :
F(i’,j’)=…
while I think it should read :
F’(i,j)=…

Smssdl has a bicubic filter which is a direct implementation of these
equations :
http://membres.lycos.fr/cyxdown/smssdl/

Also, I think not many people implement the bicubic filter because it’s
not suitable for any kind of real time processing when done on the CPU and
big pictures.

Stephane

Thanks for pointing out that program. I will attempt to reconstruct this
code in a manner that will work with 32-bit surfaces, as it seems he has
geared everything to 16-bit. If nothing else, it helps me understand the way
to realize those equations!
Thanks again,
-David Olsen

----- Original Message -----
From: stephane.marchesin@wanadoo.fr (Stephane Marchesin)
To: "A list for developers using the SDL library. (includes SDL-announce)"
Sent: Thursday, December 29, 2005 7:16 PM
Subject: Re: [SDL] Need a good(cubic interp) image stretching/reducing

----- Original Message ----- From: “Stephane Marchesin”

There’s always OpenGL :slight_smile: which has IMHO good interpolation routines,
and what’s better - they’re hardware accelerated, which means you’ll
get them pretty much for free - during runtime, without any
precaching… neat, ehh? :slight_smile: Just load your image, convert it to OGL
texture and render it with GL_LINEAR enabled both for
GL_TEXTURE_MAG_FILTER and GL_TEXTURE_MIN_FILTER:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );

Though the name suggests that it’s linear interpolation, I think that
it’s sth better…

No, that’s really bilinear. However a few cards provide better filtering
implementations, like anisotropic, or you can implement your own with
multitexturing as described there :
http://www.vrvis.at/via/research/hq-hw-reco/algorithm.html

For enlarging it is bilinear. For shrinking, most hardware is capable
of using trilinear filtering between mipmaps.

Regardless, from what I understand of your problem, using OpenGL would
be messy and a pain.

David Olsen wrote:

discreet red, green and blue images - I also need to do alpha, but I
figure it’ll be just the same as the other channels.

Though alpha will sort of be the same as other channels, adding alpha to
the mix throws the equations somewhat out of whack. If you simply compute
the alpha the same way, your images will only render correctly on black
backgrounds, assuming the transparent pixels (alpha=0) in the source images
have RGB=(0,0,0), or if the transparent source pixels are set to the value
of the background of your choice.
To compute the destination pixels correctly for any background, you need to
use alpha values as weights in the equation instead (then it also does not
matter what the RGB values of source transparent pixels are because alpha=0
cancels these out). The final equation would look something like this (I am
doing this from memory so treat this as “ad hoc” please) –

F’(i’,j’) = Sum( F(i+m,j+n) R(m-dx) R(dy-n) A(i+m,j+n) ) / Sum( A(i+m,j+n) )

and then you can compute the final A’(i’,j’) as the normal per-channel
equation goes.

Stephane Marchesin wrote:

Btw, I think one of the equations is inaccurate, it says :
F(i’,j’)=…
while I think it should read :
F’(i,j)=…

Yeah, it should read F’(i’,j’)
The explanation around the diagrams is sloppy – it mixes up (i,j) and
(i’,j’), and is generally confusing. The Bad Part is –
! The nearest pixel coordinate (i,j) is the integer part of x and y,
! dx and dy in the diagram is the difference between these,
! dx = x - i, dy = y - j.

It should simply read
i’ = floor(x)
j’ = floor(y)
dx = i’ - x
dy = j’ - y

-Alex

Hi,

If you’re doing C++ (although you could re-code it easily enough), do
a Google search on Bresenham resizing.? It does very close to bicubic
quality, in real-time.? I use it for my video work (real-time 30 FPS
re-sizing), and the quality is excellent.

Gerald> ----- Original Message -----

SUBJECT:?[SDL] Need a good(cubic interp) image stretching/reducing
library
FROM: ?David Olsen
TO:?"A list for developers using the SDL library.
(includesSDL-announce)"
DATE:?29-12-2005 12:01 pm
Hi, I’ve been trying to find some basic library that will give me
high quality image size reduction(bicubic/cubic interpolation)…
I’ve looked at rotozoom, and it only interpolates when it enlarges,
and I think it only uses linear interpolation. (Even when you are
just reducing an image, there is a very noticable difference between
linear and cubic interpolation) ? I tried the bci library at
http://nyxo.ru/[1]?and while I could get the sample program to
work, I couldn’t get it to work with how I thought it should work
with SDL_surfaces… ? I tried SDL_stretch, but couldn’t get it to
work for anything… Do you have to rebuild SDL with that inserted
into the source, or what? I’m using VC++ 2005 Express, is that
what’s wrong? Would this library even do what I am wanting? ? I
looked at the gimp source, and couldn’t locate the proper code to
see how they did it in there, since it is so massive… ? The
reason I want to find a library to interpolates well in reduction is
that I am writing a game targeted at 1024x768, but I want to be able
to let the user choose 800x600 or 640x480, and I’d like to be able to
simply scale all of the images down in the program before using them,
as opposed to storing a lot of prerendered?reduced images of the
same thing in my data/images folder. It would also allow for scaling
upwards for higher res displays… Anyway, someone please help! ?
Thanks! -David Olsen _______________________________________________
SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Links:

[1] http://nyxo.ru/