Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Raster graphics

Name: Anonymous 2010-09-29 20:25

How are raster graphics renderers usually organized?

I'm making a simple bitmap (as in, the file format) renderer in C++ as a learning project. I've got a BitmapReader class which takes in a FILE handle to a .bmp and provides basic services such as retrieving the pixel at row X and column Y, retrieving all of the pixels of row X, and so on.

Right now the renderer just runs a loop that calls getPixel(row, column) over and over until the image is complete, but of course this is very slow.

Row by row would be faster, and it would work in most cases, but what about cases where it wouldn't? Off the top of my head I can only think of one, which is when you're zoomed out. I assume the basic principle is to grab a block of pixels from the bitmap, average them according to some algorithm, and then display the result. In which case you'd have to go pixel by pixel rather than row by row. How is zoom-out usually implemented?

Name: Anonymous 2010-09-29 21:00

Oh boy. Listen buddy, just go and use some prebuilt library.

To answer your question more specifically, look up bilinear interpolation, mip-mapping, bicubic interpolation, and lanczos resampling, for starters.

Also, a friendly hint: competitive implementations use real-time code generation to build optimized filter kernels for whatever magnification/minification factor is desired at the time. Many implementation use separate horizontal and vertical resizing passes, often interleaved — it must be done with care if you want reasonable speeds.

You can check out avisynth, ffmpeg/libswscale and chromium/skia for some reasonable source code.

PS: Nowadays you're much better off rendering quads in a 3D context, if all you want is draw stuff to the screen.

PPS: Classic sprite games don't usually zoom out. When they did, it was nearest neighborhood sampling (you can't do much better with palette graphics). In most cases they used prebuilt sprites of all the needed sizes.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List