Lazarus

Programming => Graphics and Multimedia => Graphics => Topic started by: aradeonas on April 14, 2016, 01:51:31 am

Title: Load Very large image
Post by: aradeonas on April 14, 2016, 01:51:31 am
Hi,

I want to load a very large image (20000*20000) with Lazarus and tried many things like TImage, BGRABitmap and OpenGL.
Problem is they all will face error because of memory size or texture limit.
I know I can split image into peases like mapping or load a resized version but I want to know how far I can go without these and then what is the best approach with way like theses and in the end is there any code that I can use?
Also I prefer to use it in OpenGL after image is loaded but texture is a limit.
Title: Re: Load Very large image
Post by: Jurassic Pork on April 14, 2016, 02:52:11 am
hello,
have a look to  imagemagic (http://www.imagemagick.org/script/architecture.php#tera-pixel)k (imagemagick wrapper included in fp :  fpc\3.0.0\source\packages\imagemagick\src ). You need to install imagemagick (http://www.imagemagick.org/script/binary-releases.php) in your computer.

Quote
ImageMagick can read, process, or write mega-, giga-, or tera-pixel image sizes. An image width or height can range from 1 to 2 giga-pixels on a 32 bit OS and up to 9 exa-pixels on a 64-bit OS. Note, that some image formats have restrictions on image size. For example, Photoshop images are limited to 300,000 pixels for width or height

Friendly, J.P
Title: Re: Load Very large image
Post by: aradeonas on April 14, 2016, 09:48:38 am
Thanks Jurassic Pork, it is a powerful way but I like to have a no-dependency way.
Title: Re: Load Very large image
Post by: circular on April 14, 2016, 09:50:04 am
Hi,

Such image would take 1.6 Gb in memory, even if it is split. So if the computer has loads of memory, that would be possible to have it in RAM. But that's not guaranteed a computer has so much memory.

So I would suggest to have a mechanism to load part of the image you need by splitting the image in tiles. For example, if it is a background that scrolls, the program can load the tiles that are visible. As you progress, the program can free the tiles are not visible anymore and load the new tiles.

If you need to display everything at the same time at a reduced size, then you would need to have prepared thumbnails. You can probably use imagemagick to prepare those thumbnails.
Title: Re: Load Very large image
Post by: marcov on April 14, 2016, 10:20:18 am
The topic is loading, but I guess it is the displaying? Does loading in a TLazIntfImage or some fcl-image type work without displaying?

I myself have done similar tests for a smaller images and I found that the advertised texture sizes don't always work (http://"https://software.intel.com/en-us/forums/graphics-driver-bug-reporting/topic/599160#comment-1868185").

So tiling with say 4k x 4k images seems prudent.
Title: Re: Load Very large image
Post by: aradeonas on April 14, 2016, 03:58:04 pm
The case is both, Loading and displaying.
Something like mapping as @circular said is a good way but @marcov do you know any good way to do this with any bitmap or OpenGL?
About loading no they cant load the Image as @circular it takes to much memory.
Yes I can make a tile system but is it needed to make it from beginning or there is one already or another way?
Title: Re: Load Very large image
Post by: marcov on April 14, 2016, 05:26:06 pm
I would look at the openstreetmap demo here on the forum. That is a tiled based map.

But no, I haven't done it myself. I hit the limit when doing discovery for a project that would generate  a 8kpx wide image, but the project fell through.
Title: Re: Load Very large image
Post by: aradeonas on April 14, 2016, 05:30:42 pm
I would look at the openstreetmap demo here on the forum. That is a tiled based map.

But no, I haven't done it myself. I hit the limit when doing discovery for a project that would generate  a 8kpx wide image, but the project fell through.
If you mean this (http://forum.lazarus.freepascal.org/index.php?topic=22103.0) I saw it, Thanks.

If there is other way especially done in OpenGL I appreciate to know about.
And also loading a large image like JPEG is a problem for it self even for parts. How can I read a tile of it?