[SDL] Somethng wrong with my scaling function?
mir_ctx at imap.cc
mir_ctx at imap.cc
Fri Dec 14 08:29:12 PST 2007
Hi.
I'm not sure if this problem is due to misunderstanding of
the way SDL works or just a stupid error on my part. For
some reason, this vanilla "nearest neighbour" scaling function
I've written correctly scales in the X direction but not in
the Y direction (the image appears interlaced or totally
corrupted with fractional scaling values):
void
scale(SDL_Surface *dst, const SDL_Surface *src, double scale_x, double
scale_y)
{
unsigned int dst_w = dst->w;
unsigned int dst_h = dst->h;
unsigned int src_w = src->w;
unsigned int x;
unsigned int y;
unsigned int src_y;
unsigned int src_x;
unsigned int dst_y;
uint32 *dst_pix = dst->pixels;
uint32 *src_pix = src->pixels;
scale_x = 1 / scale_x;
scale_y = 1 / scale_y;
for (y = 0; y < dst_h; ++y) {
src_y = (y * src_w) * scale_y;
dst_y = y * dst_w;
for (x = 0; x < dst_w; ++x) {
src_x = x * scale_x;
dst_pix[dst_y + x] = src_pix[src_y + src_x];
}
}
}
I have made sure that dst is large enough to hold the scaled
pixels and that both surfaces are in 32 bit RGBA format.
Is there some glaring error here?
Any help appreciated.
--
mir_ctx at imap.cc
--
http://www.fastmail.fm - One of many happy users:
http://www.fastmail.fm/docs/quotes.html
More information about the SDL
mailing list