LoadImage() fails with very large images

Just starting out? Need help? Post your questions and find answers here.
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

LoadImage() fails with very large images

Post 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)
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: LoadImage() fails with very large images

Post 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 :wink:
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: LoadImage() fails with very large images

Post 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 :wink:
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...
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: LoadImage() fails with very large images

Post 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 :wink:
I don't know the limits on Linux and MacOS
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: LoadImage() fails with very large images

Post 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....
Last edited by luis on Sat Mar 08, 2014 6:48 pm, edited 1 time in total.
"Have you tried turning it off and on again ?"
A little PureBasic review
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: LoadImage() fails with very large images

Post 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
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: LoadImage() fails with very large images

Post 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
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: LoadImage() fails with very large images

Post 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.
Last edited by luis on Sat Mar 08, 2014 6:51 pm, edited 1 time in total.
"Have you tried turning it off and on again ?"
A little PureBasic review
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: LoadImage() fails with very large images

Post by Thunder93 »

ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: LoadImage() fails with very large images

Post by luis »

Yep, there seem to be a 2GB limit for a single DIB section.
"Have you tried turning it off and on again ?"
A little PureBasic review
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: LoadImage() fails with very large images

Post by Fred »

It's a Windows limit, we don't have hard limit in the PB code.
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: LoadImage() fails with very large images

Post 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... :(
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: LoadImage() fails with very large images

Post 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.
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: LoadImage() fails with very large images

Post 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?
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: LoadImage() fails with very large images

Post 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.
Post Reply