Cloning an Image

BlitzMax Forums/BlitzMax Programming/Cloning an Image

Ragz(Posted 2006) [#1]
Is it possible to clone an image you have, instead of loadimage-ing it to get another copy? Also would this be faster?


Perturbatio(Posted 2006) [#2]
you could save it to ram then reload it from there.


Ragz(Posted 2006) [#3]
How?


Perturbatio(Posted 2006) [#4]
http://www.blitzbasic.com/Community/posts.php?topic=61482


Ragz(Posted 2006) [#5]
Could I convert it to a pixmap, copypixmap then convert both back?


tonyg(Posted 2006) [#6]
or...
image1:TImage=loadimage("blah.png")
mypixmap:TPixmap=lockimage(image)
image2:Timage=loadimage(mypixmap)


Ragz(Posted 2006) [#7]
Is it alright to leave an image locked, say load an image, lock it, leave it like that forever and just keep making clones of it?


tonyg(Posted 2006) [#8]
I suppose you should unlock it for future proofing.
However, at the moment all Lockimage does is call image.lock which creates and returns a pixmap.
Unlockimage does nothing.
Anyway, once you have the pixmap you can keep using it to create images until you delete it or it goes out of scope.
Graphics 640 , 480
image:Timage = LoadImage("max.png")
mypixmap:TPixmap = LockImage(image)
Local newimage:TImage[10]
For x = 0 To 9
	newimage[x] = LoadImage(mypixmap) 
	DrawImage newimage[x] , x * 10 , 0
	Flip
Next
waitKey()




ImaginaryHuman(Posted 2006) [#9]
Doesn't unlock re-transfer the pixmap data from main memory to the image on the graphics card?


tonyg(Posted 2006) [#10]
Nope. That happens next time you drawimage.

<edit> When you first load images (even with Loadimage) only pixmaps are created. When you Drawimage for the first time a surface is created from the pixmap and the texture applied. For DX (at least) Bmax uses DX automatic texture manager to decide which surfaces/texture are kept on the card and which are loaded from RAM.
Anyway, this is the Unlockimage function...
Function UnlockImage( image:TImage,frame=0 )
End Function



Ragz(Posted 2006) [#11]
Local image_temp:TImage = LoadImage("default/gfx/models/"+path)
Local mask_temp:TImage = LoadImage("default/gfx/models/masks/"+mask)


followed by either:

Local lock_image:TPixmap = LockImage(image_temp)
Local load_image:TImage = LoadAnimImage(lock_image,width,ImageHeight(image_temp),0,frames)
Local lock_mask:TPixmap = LockImage(image_temp)
Local load_mask:TImage = LoadAnimImage(lock_mask,width,ImageHeight(image_temp),0,frames)


or

Local load_image:TImage = LoadAnimImage("default/gfx/models/"+path,width,ImageHeight(image_temp),0,frames)
Local load_mask:TImage = LoadAnimImage("default/gfx/models/masks/"+mask,width,ImageHeight(image_temp),0,frames)


I thought they would work the same, but only the second example (my original code) will be colourised by a function I call right after, what is the difference between the outputs of the two methods?

EDIT: In the example the frames, height, etc code isn't included but it's worked out in the same way each time so shouldn't make a difference, (but image height is 32, width = 32, frames is 3 most times.)

EDIT: Nevermind, was just a stupid Copy+Paste where I forgot to change a variable.