Page 1 of 1
How to include series of images, icons etc.
Posted: Wed Aug 31, 2011 9:24 am
by Michael Vogel
I am doing something like this right now to include many icons (with different sizes):
Code: Select all
IconHandle(#Icon_Waypoint+1)=CatchImage(#Icon_Waypoint+1,?IconVA)
IconHandle(#Icon_Waypoint+2)=CatchImage(#Icon_Waypoint+2,?IconVB)
IconHandle(#Icon_Waypoint+3)=CatchImage(#Icon_Waypoint+3,?IconVC)
IconHandle(#Icon_Waypoint+4)=CatchImage(#Icon_Waypoint+4,?IconVD)
IconHandle(#Icon_Waypoint+5)=CatchImage(#Icon_Waypoint+5,?IconVE)
IconHandle(#Icon_Waypoint+6)=CatchImage(#Icon_Waypoint+6,?IconVF)
:
IconVA: IncludeBinary "Icons\POI_A.ico"
IconVB: IncludeBinary "Icons\POI_B.ico"
IconVC: IncludeBinary "Icons\POI_C.ico"
IconVD: IncludeBinary "Icons\POI_D.ico"
IconVE: IncludeBinary "Icons\POI_E.ico"
IconVF: IncludeBinary "Icons\POI_F.ico"
:
Can this be done easier (in a loop)? I mean, how to calculate the memory position of the icons VB, VC etc.
Re: How to include series of images, icons etc.
Posted: Wed Aug 31, 2011 1:43 pm
by spikey
Its the "different sizes" bit that causes the problem. If the images are all the same size then you can calculate an offset. However if they aren't then you will need to
record each image's size so that you can update an offset pointer to use with CatchImage. This would mean you would need to update a list of sizes every time you added and/or changed an image and this list of sizes needs to be accessible at runtime. I can't make up my mind if this is more or less fiddly than maintaining the images solely using labels.
Something like:-
Code: Select all
*ImageBase = ?ImageBase
Restore ImageLengths
For iLoop = 0 To 5
Read.I iSize
CatchImage(iLoop, *ImageBase, iSize)
*ImageBase + iSize
Next iLoop
ImageLengths:
DataSection
Data.I 1150, 1150, 1150, 1150, 1150, 1150
EndDataSection
DataSection
ImageBase:
IncludeBinary "POI_A.ico"
IncludeBinary "POI_B.ico"
IncludeBinary "POI_C.ico"
IncludeBinary "POI_D.ico"
IncludeBinary "POI_E.ico"
IncludeBinary "POI_F.ico"
EndDataSection
Each value in the ImageLengths: DataSection is the length in bytes of the corresponding image file, mine were all the same size as it turns out.
Re: How to include series of images, icons etc.
Posted: Wed Aug 31, 2011 2:20 pm
by breeze4me
It's easy if you use the anonymous label of FASM.
viewtopic.php?p=265591#p265591
Code: Select all
*Addr = ?image_data
i = 1
Repeat
IconHandle(#Icon_Waypoint + i) = CatchImage(#Icon_Waypoint + i, *Addr + 4)
*Addr = PeekL(*Addr)
i + 1
Until *Addr = 0
DataSection
image_data:
!dd @f
IncludeBinary "POI_A.ico"
!@@:
!dd @f
IncludeBinary "POI_B.ico"
!@@:
!dd @f
IncludeBinary "POI_C.ico"
!@@:
!dd @f
IncludeBinary "POI_D.ico"
!@@:
!dd @f
IncludeBinary "POI_E.ico"
!@@:
!dd 0 ; <-- the last icon.
IncludeBinary "POI_F.ico"
EndDataSection
Re: How to include series of images, icons etc.
Posted: Wed Aug 31, 2011 3:34 pm
by Demivec
Michael Vogel wrote:Can this be done easier (in a loop)? I mean, how to calculate the memory position of the icons VB, VC etc.
Maybe like this:
Code: Select all
For iLoop = 1 To (?AfterLengths - ?ImageLengths) / SizeOf(Long)
IconHandle(#Icon_Waypoint + iLoop) = CatchImage(#Icon_Waypoint + iLoop, PeekL(?ImageLengths + (iLoop - 1) * SizeOf(Long)))
;IconHandle(#Icon_Waypoint + iLoop) = CatchImage(#Icon_Waypoint + iLoop, PeekL(?ImageLengths + (iLoop - 1) * SizeOf(Long)), PeekL(?ImageLengths + iLoop * SizeOf(Long)) - PeekL(?ImageLengths + (iLoop - 1) * SizeOf(Long))) ;includes size limit
Next iLoop
DataSection
ImageLengths:
Data.I ?IconVA, ?IconVB, ?IconVC, ?IconVD, ?IconVE, ?IconVF
Data.l ?AfterIcons
AfterLengths:
EndDataSection
DataSection
IconVA: IncludeBinary "Icons\POI_A.ico"
IconVB: IncludeBinary "Icons\POI_B.ico"
IconVC: IncludeBinary "Icons\POI_C.ico"
IconVD: IncludeBinary "Icons\POI_D.ico"
IconVE: IncludeBinary "Icons\POI_E.ico"
IconVF: IncludeBinary "Icons\POI_F.ico"
AfterIcons:
EndDataSection
Re: How to include series of images, icons etc.
Posted: Wed Aug 31, 2011 4:24 pm
by Michael Vogel
Nice,
I will change my code to something like this...
Code: Select all
Macro DataAddress(x)
!@@:
!dd @x
EndMacro
*Addr = ?image_data
For i=1 To 4
;IconHandle(#Icon_Waypoint + i) = CatchImage(#Icon_Waypoint + i, *Addr + 4)
Debug PeekS(*Addr+SizeOf(Long)); for testing only
*Addr = PeekL(*Addr)
Next i
DataSection
image_data:
DataAddress(f)
Data.s "Here's an icon",Chr(0)
DataAddress(f)
Data.s "Here's another icon",Chr(0)
DataAddress(f)
Data.s "Here's again an icon",Chr(0)
DataAddress(b)
Data.s "Here's the last icon",Chr(0)
EndDataSection
Re: How to include series of images, icons etc.
Posted: Wed Aug 31, 2011 4:24 pm
by netmaestro
If it was me I'd probably write a couple of loops to generate an include file:
Code: Select all
If CreateFile(0, "c:\icondata.pb")
For i=1 To 50
WriteStringN(0, "CatchImage(i, ?icon_"+Str(i)+")")
Next
WriteStringN(0, "")
WriteStringN(0, "DataSection")
For i=1 To 50
WriteStringN(0, " icon_"+Str(i)+": IncludeBinary " +Chr(34)+ "icon_"+Str(i)+".ico"+Chr(34))
Next
WriteStringN(0, "EndDataSection")
CloseFile(0)
EndIf
Then in the program put
and adding ten more icons later is a matter of changing "50" to "60".
Re: How to include series of images, icons etc.
Posted: Fri Aug 03, 2012 3:35 am
by IdeasVacuum
Separate PB app that creates the Data Section from your folder of images:
Data Section maker source