[vtkusers] Loading images in a memory efficient way

Francois Bertel francois.bertel at kitware.com
Wed Sep 23 10:09:37 EDT 2009


Hello,

First of all, is 3.2MB the size of the image uncompressed in memory or
the size of the png (ie compressed) file?

If the 3.2MB is the size of the image uncompressed in memory, when the
image is sent as a texture to OpenGL, the graphics driver make a local
copy first in central memory (RAM) in its own space and then transfer
it from the RAM to the video RAM (VRAM). The memory footprint of the
image in memory in then 6.4MB. In this case, I cannot explain the
extra 2.6MB.


If 3.2MB is the size of the png file, then the image in memory is much
more than that. Imaging it is actually 4.5MB, double this quantity
because of the graphics driver mirroring, and you reach 9MB.

Regards.

On Tue, Sep 22, 2009 at 11:41 PM, John Eke <tonee47 at yahoo.com> wrote:
> Hi Guys/Girls,
>
> Please take a look at the simple code snippet below:
>
> int main ()
> {
>     vtkRenderer *ren = vtkRenderer::New();
>     vtkRenderWindow *renWin = vtkRenderWindow::New();
>
>     vtkRenderWindowInteractor* iren = vtkRenderWindowInteractor::New();
>     renWin->SetInteractor(iren);
>
>     renWin->AddRenderer (ren);
>
>         vtkPNGReader *imageReader = vtkPNGReader::New();
>         imageReader->SetFileName("image.png");
>         imageReader->Update();
>
>         vtkImageActor *actor = vtkImageActor::New();
>         actor->SetInput(imageReader->GetOutput());
>         ren->AddActor(actor);
>
>     iren->Initialize();
>     iren->Start();
>
>     imageReader->Delete();
>     actor->Delete();
> }
>
> It simply loads an image (image.png) and displays it.  In memory, it takes
> up about 16MB of memory. When I strip away the image loading part and just
> leave in the render window, interactor, and renderer.. the program uses
> about 6.5MB of memory.
>
> The image I had used is about 3.2MB in size. So from my calculations, just
> loading and displaying the image used just over 9MB, which is about three
> times he original image size!!
>
> Is this accurate? Am I doing something wrong? Is there a more efficient way
> to do this?
>
> Any help is much appreciated.
>
> Thanks,
>
> John E
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>



-- 
François Bertel, PhD  | Kitware Inc. Suite 204
1 (518) 371 3971 x113 | 28 Corporate Drive
                      | Clifton Park NY 12065, USA



More information about the vtkusers mailing list