Hi,
Does anyone here know how sdl stores a bitmap in memory? the reason I ask
is because i want to impletment stretching of bitmaps for my game, and was
just wondering how I could get the sdl_surface and mess around with the
bitmap data so i can stretch it.
It depends on the format of the SDL_Surface containing your bitmap.
You’ll have to look at the SDL_PixelFormat structure associated with it.
If it’s an 8-bit indexed color image, the pixels member of SDL_Surface
can just be cast to (char *) and accessed like an array. This code
fragment accesses the pixel at x, y:
SDL_Surface *s;
Uint32 offset, x, y, pixel;
offset = y*s->pitch + x;
pixel = ((Uint8 *)s->pixels)[offset]];
Now, if the pixelformat is not 8bpp, you will have to get a number of
bytes equal to s->format->BytesPerPixel. For example, you could do the
following:
Uint32 pixel;
Uint8 r, g, b;
offset = ys->pitch + xs->format->BytesPerPixel;
memcpy(&pixel, s->pixels + offset, s->format->BytesPerPixel);
pixel &= (1<format->BitsPerPixel)-1;
SDL_GetRGB(pixel, s->format, &r, &g, &b);
to get the RGB components. This should work for any surface whose bits
per pixel is divisible by 8. (is this safe to do on big-endian
architectures? I know this works on Linux/Intel!) If it’s one of those
odd-bit surfaces, well, that’s a little more complicated!
I’ve thought of a high quality, but obviously expensive algorithm for
stretching an m x n array of pixels into an (m+p) x (n+q) array. First
use a 2D-FFT algorithm to produce an m x n array of frequency
coefficients. Expand this array to an (m+p) x (n+q) array, filling the
extra coefficients with zeroes. Inverse Fourier to get back to the space
domain and the expanded image. I think that this would produce better
results than the bilinear/spline interpolation techniques used by most
bitmap scaling programs, because the effective filter’s support is over
the entire image, not just in a 2- or 3-pixel radius. This is, of course,
overkill for what is being done…On Tue, 24 Aug 1999, Ryan Wahle wrote:
| Rafael R. Sevilla @Rafael_R_Sevilla_94 |
| Instrumentation, Robotics, and Control Laboratory |
College of Engineering, University of the Philippines, Diliman |