Joshy
file: mirror.bi
Code: Select all
#ifndef __MIRROR_BI__
#define __MIRROR_BI__
' mirror an image or the screen (img=0)
' horizontal or vertical of course you can combine different calls
' e.g. step 1 vertical step 2 horizontal, step 3 vertical ...
' I'm using only GET and PUT so you can use XOR,PSET,ALPHA ...
sub Mirror(byval img as any ptr=0, byval iHorizontal as integer=1)
static as integer oWidth=0,oHeight=0,oHorizontal=0
static as any ptr imgA=0,imgB=0
dim as integer iWidth=any,iHeight=any
dim as integer xSize=any,ySize=any,xStart=any,yStart,xStep=any,yStep=any
dim as integer x1=any,x2=any,y1=any,y2=any,iStart=any,iEnd=any
if img=0 then ' screen
if ScreenPtr()=0 then exit sub
ScreenInfo(iWidth,iHeight)
else ' image
if ImageInfo(img,iWidth,iHeight) then exit sub
end if
if iHorizontal then iHorizontal=1
' realloc images only if the resolution or the mirror axis are changed !
if iWidth<>oWidth or iHeight<>oHeight or oHorizontal<>iHorizontal then
oWidth = iWidth : oHeight = iHeight : oHorizontal = iHorizontal
if iHorizontal then
xSize=iWidth : ySize=1
else
xSize=1: ySize=iHeight
end if
if ImgA then ImageDestroy ImgA:ImgA=0
if ImgB then ImageDestroy ImgB:ImgB=0
imgA=imageCreate(xSize,ySize)
imgB=imageCreate(xSize,ySize)
end if
' now the magic :lol:
xSize-=1 : ySize-=1
if iHorizontal then
x1=0:x2=0:y1=0:y2=iHeight-1 : xStep=0: yStep=1 : iStart=0:iEnd=iHeight-1
else
x1=0:x2=iWidth-1:y1=0:y2=0 : xStep=1: yStep=0 : iStart=0:iEnd=iWidth-1
end if
while iStart<=iEnd
Get img,(x1,y1)-step(xSize,ySize), imgA
Get img,(x2,y2)-step(xSize,ySize), imgB
Put img,(x1,y1),imgB,pset
Put img,(x2,y2),imgA,pset
x1+=xStep : x2-=xStep
y1+=yStep : y2-=yStep
iStart+=1 : iEnd-=1
wend
end sub
#endif ' __MIRROR_BI__