Hi,
I need to warp rectangular images to two other shapes (see attached
file), with interpolation. How easy or difficult is it?
In theory, it’s pretty easy. Just figure out a “nice” pair of functions:
source_x = fx(destination_x);
source_y = fy(destination_y);
Then loop over the pixels of the destination surface, grabbing pixels
from the source surface:
for(y = 0; y < dst->height; ++y)
for(x = 0; x < dst->width; ++x)
setpixel(dst, x, y, getpixel(src, fx(x), fy(y)));
For good looking results, getpixel() should take fractional coordinates
(fixed or floating point) and read from the source image with bilinear or
bicubic interpolation, or maybe even some form of adaptive supersampling,
to avoid aliasing artifacts. Obviously, it should also implement
clipping, clamping or wrapping, or Bad Things will happen when the
transformation functions generate coordinates outside the source image.
Is there any library that can do this?
Dunno. Probably - but I guess it would be nice if it had a nice licence
and wasn’t too hard to port to SDL…
Or should I use OpenGL?
OpenGL only supports (or at least, most cards only implement) linear and
perspective texture transformations, so you’d have to tile the images
with some suitable grid size, and then move the vertices around to get
the desired effect. Of course, this could be very, very fast, compared to
any software implementation, at least as long as you stick to a
"reasonable" grid resolution.
Has anyone done this?
It’s been done countless times in various contexts - but as (until these
days) it hasn’t been doable in real time, it’s been a bit outside my main
field of interest…
//David Olofson — Programmer, Reologica Instruments AB
.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------------> http://www.linuxdj.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |
-------------------------------------> http://olofson.net -'On Tuesday 05 March 2002 10:51, Idigoras Inaki wrote: