PDA

View Full Version : Handling big images



swald
01-09-2006, 08:17 AM
Hi,

I'm trying to write a program that displays images.
It should be possible to rotate (90 degree steps only),
zoom in and out and move the images inside the window.

My problem is, that these images are very big and I my
program segfaults, when I try to load them as textures.

I also tried glDrawPixels but when displaying the whole
image and moving it around it gets very slowly.

Is there a way to especially move such a big image
efficiently?

Sebastian

RigidBody
01-09-2006, 09:05 AM
can you post some code? and can you tell how big is "very big"? you can use glGet(GL_MAX_TEXTURE_SIZE, ...) to determine the maximum texture size that your gl implementation allows.

songho
01-09-2006, 09:44 AM
swald,
How about partitioning the whole image into multiple grids(rectangles). And apply them as textures on adjacent multiple quads(planes).

Doing this, video driver may load/unload the textures automatically for you if they cannot fit on memory capacity.

You may notice a hiccup caused by delaying of loading textures into memory if the whole textures cannot be loaded on video memory.
==song==

swald
01-09-2006, 10:18 AM
@RigidBody
One of the images has a size of 2953x2479 pixels and a resolution
of 300 dpi. It is a tif-image which needs 22Mb disk space.
And it is possible, that there will be even bigger ones.

What code do you want to see? As I wrote above, I simply tried
something like this:

glPushMatrix();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

if (img) {
glRasterPos2f(ox, h-oy);
glPixelZoom(scale, scale);
glDrawPixels(img->GetWidth(), img->GetHeight(), GL_RGB, GL_UNSIGNED_BYTE, img->GetData());
}
glPopMatrix();Here I have the problem, that the image isn't drawn, when the
origin of the image has a negative value. I don't know how to fix
this, but because I didn't know, if I will later still use
glDrawPixels I left this bug in the test version.

@songho
But what if the whole image can be seen? Then the whole image has
to be loaded as well. And this is the case when it gets slowly.
When the zoom factor is higher and only a small part of the
image can be seen, then the performance is ok.

API
01-09-2006, 10:31 AM
When do you use this 2953x2479 image as a texture do you resize it?

Remember that a normal texture must have power of two dimensions.

API

swald
01-09-2006, 10:41 AM
No, I used this function
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

to bypass the restriction. And this worked for an image
with a 200x200 resolution.

RigidBody
01-09-2006, 11:11 AM
hm...concerning the visibility: afaik, the position which you define with glRasterPos must be inside the viewport (after being transformed with the modelview and projection matrices), otherwise the image is not drawn.

just a thought- try to scale the image- in both directions- to have a size dividable by 8.

01-09-2006, 12:25 PM
Swald, as API hinted at, you should probably be using a texture to draw your stuff, not DrawPixels (very slow by comparison). You can map in portions of the image as needed/viewed with glTexSubImage for example.

With this basic technique the texture size is virtually unlimited. You could use this in conjunction with Songho's grid idea and display massive images indeed.

Cheers

:)