Question on Pixel Format operations

I had a question on Pixel Format, specifically the glPixelStorei function.

First some background, I’m creating my own Mipmap building routine because the app I’m working on creates many, many large textures at startup, and using the gluBuild2DMipmap functions is quite slow. So I’m working on my own scaling and Mipmap functions. This will also be nice as I will also be able to add filtering steps to the images used as textures at later stages in development.

Okay the question, I’ve run into an issue when building the last couple of textures in a a Mipmap and found that I need to make sure glPixelStore(GL_UNPACK_ALIGNMENT , ??) needs is set to 1. This is because my scale function doen’t pad images to word boundaries so the 2x2 image causes problems. If I set this to 1 everything works correctly. My question is this, is setting it to 1 a bad thing from a performance standpoint? Would I be better off padding the images so I can use a different alignment?

Also as a side question, does anyone know of resouces that I could track down to help in optimzing my scaling code, algorithms for scaling (RGB images only)?

Thanks

elroy

Yes, unaligned textures may slow down, depending on cards and drivers.

2D linear interpolation is often quite good enough for images. If you want better quality, you can try a gaussian filter function, but it will be quite slow. Foley, van Dam et al: Computer Graphics, Practice and Principle (or something close) contains code and discussions.

Thanks for the info.

Regarding image scaling, I’m more interested in speed than quality, but need some filtering. Currently I have two routines, one is the simplified case scaling down to next power of 2 (used in mipmap building) for that I use a box filter, 4 pixels to one. The general case of arbitrary scaling needs some work though. Does Foley have the algorithm for linear interpolation as well?

Thanks

James

Linear is simple. Assuming you have r00, r01, r10 and r11, with an xd from 0 to 1 and an yd from 0 to 1, then our outr is:

outr0 = (r00*(1-xd)+r01xd); // intermediate
outr1 = (r10
(1-xd)+r11xd); // intermediate
outr = outr0
(1-yd)+outr1*yd; // output

Repeat for outg, outb and possibly outa :slight_smile:

Note that this is equivalent to a box filter of size 1 ONLY when xd = 0.5 and yd = 0.5, which is probably the case you’re using for your MIP map creation.

That book (Foley et al)is very good and has a fast algorithm for scaling images (Weiman’s method on page 821) based on copying (or ignoring) columns.

This is theoretically not very good in terms of quality for scaling images upwards but might be better for scaling them down. You could combine this with a smoothing filter although I have never tried it.

The more I think about it the more it seems worth playing about with

[This message has been edited by foobar (edited 08-10-2000).]

That mechanism is what’s known as a zeroth-order algorithm, which is of lower quality than first-order algorithms such as linear interpolation (which, in turn is lower quality than seccond-order, third-order (cubic) etc). That’s how, say, DOOM scaled its textures – the quality isn’t all it should be; when you scale up, you get blockiness; when you scale down, you get crawling pixels during movement. And for passes you only do once (like building a MIP map) it really makes more sense to spend the little extra time it takes to interpolate, because you only do it once and the quality is worth it.

Thanks for all the input!

I will play around with some of the algorithms, I’ll probably start simple and put provisions for adding better filtering as time permits. For the app I’m working on it is a trade off. At start up we may load > 25 images used for textures/mipmaps at a resolution of 512x512, the higher the image quality the better but at the same time I don’t want to take 5 minutes for start up either.

It isn’t as big of deal if the image jiggles a bit when zooming in, it is of greater concern for image quality when the larger images are used (that contain text), They need to be legible. I’m wondering if perhaps using some filtering to enhance text in those cases might be useful.

Thanks again for the input, I’ll let you know how it turns out.

elroy