How to include series of images, icons etc.

Just starting out? Need help? Post your questions and find answers here.
User avatar
Michael Vogel
Addict
Addict
Posts: 2799
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

How to include series of images, icons etc.

Post 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.
User avatar
spikey
Enthusiast
Enthusiast
Posts: 762
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: How to include series of images, icons etc.

Post 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.
breeze4me
Enthusiast
Enthusiast
Posts: 633
Joined: Thu Mar 09, 2006 9:24 am
Location: S. Kor

Re: How to include series of images, icons etc.

Post 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
User avatar
Demivec
Addict
Addict
Posts: 4266
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: How to include series of images, icons etc.

Post 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
User avatar
Michael Vogel
Addict
Addict
Posts: 2799
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: How to include series of images, icons etc.

Post 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
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: How to include series of images, icons etc.

Post 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

Code: Select all

XIncludeFile "icondata.pb"
and adding ten more icons later is a matter of changing "50" to "60".
BERESHEIT
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: How to include series of images, icons etc.

Post by IdeasVacuum »

Separate PB app that creates the Data Section from your folder of images:
Data Section maker source
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Post Reply