Page 1 of 1
LoadImage() fails with very large images
Posted: Sat Mar 08, 2014 11:22 am
by c4s
Inspired by
this post I tried to load a very large image in PureBasic using LoadImage().
LoadImage() Help wrote:The limit for the image size that can be handled depends on the operating system and the available amount of memory.
I do have enough memory so I don't understand why it failed because e.g. the Windows Picture Viewer, Photoshop and IrfanView didn't have any problems.
Here is the great test image from Wikipedia:
click (warning: 215 MB, 30000x29560 pixels)
Re: LoadImage() fails with very large images
Posted: Sat Mar 08, 2014 12:26 pm
by STARGÅTE
The limit for the image size that can be handled depends on the operating system and the available amount of memory. If enough memory is available, then images up to at least 8192x8192 are can be handled by all operating systems supported by PureBasic.
You have to read until end

Re: LoadImage() fails with very large images
Posted: Sat Mar 08, 2014 2:39 pm
by c4s
STARGÅTE wrote:The limit for the image size that can be handled depends on the operating system and the available amount of memory. If enough memory is available, then images up to at least 8192x8192 are can be handled by all operating systems supported by PureBasic.
You have to read until end

Of course I did!
"up to at least 8192x8192" means that on all OSes every resolution including 8192x8192 pixels is definitely supported. Everything above "depends on the operating system and the available amount of memory".
So if other applications on Windows can handle 30000x30000 why not PureBasic? There is no need to add artificial limits that refuse everything above e.g. 20000x20000 but I guess that something like that is stopping LoadImage() from actually loading it...
Re: LoadImage() fails with very large images
Posted: Sat Mar 08, 2014 5:06 pm
by STARGÅTE
c4s wrote:STARGÅTE wrote:So if other applications on Windows can handle 30000x30000 why not PureBasic?
Pure Basic isn't only for windows
I don't know the limits on Linux and MacOS
Re: LoadImage() fails with very large images
Posted: Sat Mar 08, 2014 5:20 pm
by luis
Again, not sure it's a real problem... the image is big and up a certain point something must fail so probably a different approach should be used... but in any case seems to be a discrepancy if I didn't do something wrong in the code below, I'm not a big user of native bitmaps
edit: I think I've made a mistake, msdn says the DC to be used in CreateCompatibleBitmap() should be the original DC, not the one returned by CreateCompatibleDC(). That one must be used just for selecting the bitmap into it.
Changing the code accordingly
Code: Select all
pbimg = CreateImage(#PB_Any, 30000, 29560, 24) ; this fails on my PC too
Debug "PB image = " + pbimg ; 0 if failed
CreateImage(0, 1, 1, 24) ; a small dummy PB image
dc = StartDrawing(ImageOutput(0)) ; get the dc of the dummy PB image
Debug "PB image DC = " + dc
newdc = CreateCompatibleDC_(dc) ; get a compatible DC from the dummy, to be sure to do something equivalent
Debug "new DC = " + newdc
bmp=CreateCompatibleBitmap_(dc, 30000, 29560) ; they both fails
Debug SelectObject_(newdc, bmp)
StopDrawing()
Debug "API bitmap = " + bmp ; <> 0 if successful
Remain the question how other programs can open an image of this size....
Re: LoadImage() fails with very large images
Posted: Sat Mar 08, 2014 5:33 pm
by Thunder93
I cannot go any higher in Height or width than...
Code: Select all
pbimg = CreateImage(#PB_Any, 24216, 29560, 24)
or different way...
Code: Select all
pbimg = CreateImage(#PB_Any, 29560, 24216, 24)
Maxed at total of 53776
Re: LoadImage() fails with very large images
Posted: Sat Mar 08, 2014 5:53 pm
by Thunder93
The PB Width and Height fields limits for CreateImage(), each supporting up-to 32000. Of course PB help mentions some reasons to possible failures.
Total PB support: 64000 (32000+32000)
Total Which works: 53776
If you have no problem with the other image viewers supporting, PB shouldn't be no different?
Edit:
Code: Select all
pbimg = CreateImage(#PB_Any, 22369, 32000, 24)
If you use instead 32 color depth, fails. Looks like PB limits
Re: LoadImage() fails with very large images
Posted: Sat Mar 08, 2014 6:11 pm
by luis
PB actually uses CreateDIBSection() for its images AFAIK, so my test above is not really an accurate comparison...
EDIT: but the result is the same nevertheless after correcting the code, the image creation fails.
Re: LoadImage() fails with very large images
Posted: Sat Mar 08, 2014 6:18 pm
by Thunder93
Re: LoadImage() fails with very large images
Posted: Sat Mar 08, 2014 6:22 pm
by luis
Yep, there seem to be a 2GB limit for a single DIB section.
Re: LoadImage() fails with very large images
Posted: Mon Mar 10, 2014 10:54 am
by Fred
It's a Windows limit, we don't have hard limit in the PB code.
Re: LoadImage() fails with very large images
Posted: Mon Mar 10, 2014 12:50 pm
by c4s
Is it possible to somehow overcome this Windows limit? As I said, other applications don't seem to have a problem with loading very large images.
I'm interested in this because I have an application that processes lots of different images. Nowadays the resolution of images is getting bigger and bigger so it's pretty bad that I cannot load them...

Re: LoadImage() fails with very large images
Posted: Mon Mar 10, 2014 1:11 pm
by Thunder93
OffTheWWWeb wrote:By trying to allocate DIBS greater than 2gb, you're really exceeding the expectations and purpose of the GDI subsystem. With such large arrays, you're probably better off writing your own libraries to manage and manipulate these images.
Re: LoadImage() fails with very large images
Posted: Mon Mar 10, 2014 1:41 pm
by c4s
Thunder93 wrote:OffTheWWWeb wrote:By trying to allocate DIBS greater than 2gb, you're really exceeding the expectations and purpose of the GDI subsystem. With such large arrays, you're probably better off writing your own libraries to manage and manipulate these images.
Is that an answer to my question on how to load large images in PureBasic?
If so,
wasn't GDI (mostly) dropped with support of alpha channel? Anyway, I'm not interested in the PB internals (as often suggested by the team). Maybe a flag for LoadImage() could be added to support larger images?
Re: LoadImage() fails with very large images
Posted: Mon Mar 10, 2014 1:58 pm
by Fred
Specialized software use different way to load a big picture, but it can be put in a button or other control. You can do the same as well, using your own decoder into raw memory and canvasgadget() to have a virtual display.