Linear interpolation using "packed" image format

I use the GPU mainly to do image filtering and signal processing (GPGPU programming). Because I’m only intrested in images in grayscale, I store 4 grayscale pixels in one 4-component pixel (R, G, B and A). That works perfect for most of the time, some filters even get a 4 times speedup compered to the naïve approach, and some filters need some swizzling to get working. I use Cg for the shaders.

But now I’ve come to a point where i need to warp the image using linear interpolation. Haven’t I used the packed format, it would’ve been trivial, just enable GL_LINEAR and change some coordinates, but if I do that with the packed format, the result is horrific.

I could solve it by interpolating manually by writing a fairly complex pixel shader, but that whould involve som heavy swizzling and lots of branching.

Another solution would be to “unpack” the image, transform it with GL_LINEAR, and then pack it again.

I’m not really happy with any of these solutions, none of them would be very efficent. Is there any other way of doing it? Is there some expansion to OpenGL that lets me use GL_LINEAR on my kind of “packed” image format?

I can’t see how you can do it the way you want. Linear interpolation will mess a lot with any sort of spatial packing.

Depends on the application but what about packing 4 frames in one (sort of temporal packing instead of spatial).
Or maybe use GL_LUMINANCE8 textures, without packing (no idea about performance).

GL_LUMINANCE8 would probably be slightly faster than repeating the pixel value over a GL_RGBA8, but I’m still stuck with the packed GL_RGBA8 on the other filters, and therefore the costly packing/unpacking still would be there.

I’m not sure if a 4 frame delay would be acceptable, it is supposed to be a real time application. But if it would, storing 4 images in one (one in R, one in G and so on) would be great.

Another thing I’ve thought about is to store the left fourth of the image in R, the next fourth in G and so on. But to avoid artefacts due to the borders, I’d have to introduce some frame with repeated pixels.