Hi Josh. Great solution. The PB_Object_EnumerateStart (PB_Image_Objects) library function/constant does a great job at enumerating only the image objects, solving the #PB_Any high object number issue.
I've adapted my code to implement these functions, but it still stores the results in a map. That way there will be no need to iterate through all the image objects every time an image number is required; could be pretty slow for large image-intensive projects.
Import ""
PB_Image_Objects
PB_Object_EnumerateStart (*object)
PB_Object_EnumerateNext (*object, *Id)
EndImport
Procedure initImages()
Global NewMap images.i()
PB_Object_EnumerateStart (PB_Image_Objects)
While PB_Object_EnumerateNext (PB_Image_Objects, @i)
images(Str(ImageID(i))) = i
Wend
EndProcedure
Procedure.i GetImageNumber(imgID.i)
result = -1
If FindMapElement(images(), Str(imgID))
result = images(Str(imgID))
EndIf
ProcedureReturn result
EndProcedure
initImages()
Debug GetImageNumber(validImageID)
It now works with images initialised with #PB_Any as well.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too!Please visit my YouTube Channel
Josh wrote:9986 Images created and then startet GetImageFromHandle. Time to find the last image < 1ms.
That's pretty fast. And it would save the additional steps and overheads of using a map.
Josh wrote:(I don't know why, but with more then 9986 images I get a problem with MessageRequester)
Do you mean when iterating with the PB_Object_EnumerateStart (PB_Image_Objects) function, or when creating more than 9986 images in general?
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too!Please visit my YouTube Channel
TI-994A wrote:Do you mean when iterating with the PB_Object_EnumerateStart (PB_Image_Objects) function, or when creating more than 9986 images in general?
Thanks Josh and TI, that looks perfect what what I need to do.
The PB_Object_... stuff blows my mind, not they way it works, but that it's seemingly not well documented and seemingly almost impossible to find out about.
I Google'd it and found a German post about it dating back to 2006 but there's no reference to where it comes from, how to use it, who implemented it or where to find out more about it or if there's any other gems like this lying around.
If you two cant shed any more light on it, is there anyone else that can?
It's not 'not well documented', it's completely undocumented. You have to take it like it is and its not guaranteed, that it will work in future versions.
Josh wrote:It's not 'not well documented', it's completely undocumented.
The function names and declarations can be found in the PB-SDK "Object.h" header, and some of the
examples in the SDK show how to use those functions. The procedure was originally named ImageFromImageID(ImageID).
;
; ImageFromImageID.pb
;
; Original by Danilo: http://www.purebasic.fr/english/viewtopic.php?p=386592#p386592
; simplified version by Josh: http://www.purebasic.fr/german/viewtopic.php?f=6&t=26047&hilit=ImageFromImageID&start=4
;
Global NewMap Images.i()
Procedure LoadImage2(ImageNo, FileName.s)
Protected Result
Result = LoadImage(ImageNo, FileName)
If ImageNo = #PB_Any
If Result
Images(Str(ImageID(Result))) = Result
EndIf
Else
If Result
Images(Str(Result)) = ImageNo
EndIf
EndIf
ProcedureReturn Result
EndProcedure
Macro LoadImage(ImageNo, FileName)
LoadImage2(ImageNo, FileName)
EndMacro
UseJPEGImageDecoder()
UsePNGImageDecoder()
; Load images here
Debug " #, Id"
ForEach Images()
Debug Str(Images()) + ", " + MapKey(Images())
Next