[SDL] Scaling Images
nbs at sonic.net
Mon Nov 14 11:20:28 PST 2005
On Mon, Nov 14, 2005 at 01:13:57PM +0000, Guilherme De Sousa wrote:
> Basically what I'm looking for is a routine that will
> take a rectangular image, can scale it to a smaller or
> larger rectangle but can also scale it to appear as
> though it's in perspective. The screenshots here might
> make it clearer:
Right-on! Out of curiosity, have you spoken with the original AR creators?
(A while back they were hoping to make a modern version of AR for PCs,
but that sadly fell through.)
Firstly, it looks like you're coming from a C=64 perspective, since
there are so few colors in your demo screenshots. Pump it up! Go for
all 256 Atari 8-bit colors, man! ;^) (That game was _gorgeous_ on the
Atari... lots of DLI tricks used!)
(or, like, maybe AR:The Dungeon was less colorful than AR:The City ;^) )
> I'm currently using the SDL GFX library which works
> fine for the rectangular scaling but can't do the
> perspective scaling as far as I know. I've also heard
> SDL_SoftStretch mentioned but haven't found much
> written about it.
So in other words you want to take something like this:
and turn it into:
In a sense, it's simply slicing the rectangle into long, vertical slices,
and scaling each one differently. In the example above, the leftmost 'slice'
(be it one pixel wide, or more... up to you) is kept at 100% height.
The middle slice is at 50%. The rightmost slice diminishes to nothing. :)
Alter the percentages accordingly for other shapes pieces, e.g.:
Scaling can be pretty simple to code. And, as someone else pointed out,
you might want to consider using OpenGL. But, I guess it depends on if
you're targetting high-end PCs, or, say, PDAs, phones or Dreamcasts. :)
> Can anybody point me to some code or examples that
> might be helpful?
I don't do perspective, but there is a scaling routine ("thumbnail", I
call it) in Tux Paint, which is GPL. See the URL in my sig.
bill at newbreedsoftware.com
More information about the SDL