Mirror Image ?

BlitzMax Forums/BlitzMax Programming/Mirror Image ?

hi :)

This program seem don't work with the last blitmax version ?
or i'm wrong ?

http://www.blitzbasic.com/codearcs/codearcs.php?code=19


Graphics 640,480

Global ImageFond1=LoadImage("image1.jpg")
Global ImageDest=mirrorImage(ImageFond1)

While Not KeyHit(KEY_ESCAPE)
	Cls
	SetColor 255,255,255
	SetAlpha 1.0
	
	DrawImage ImageFond1,10,10
	DrawImage ImageDest,10,25
	
	Flip 
Wend

Function mirrorImage:TImage(img:TImage)
   Local a:Int
   Local r:Int
   Local g:Int
   Local b:Int
   Local i:Int
   Local j:Int
   Local argb:Int

   Local pixmap:TPixmap = LockImage(img)
   pixmap = ConvertPixmap(pixmap,PF_RGBA8888)
   pixmap = YFlipPixmap(pixmap)

   For i = 0 To PixmapWidth(pixmap)-1
      For j = 0 To PixmapHeight(pixmap)-1
         argb = ReadPixel(pixmap,i,j)
         a:Int = Int(76.0*(1.0-((Float(j)/Float(ImageHeight(img))))))
         If (argb Shr 24) = 0 Then a = 0

         r:Int = (argb Shr 16) & $ff
           g:Int = (argb Shr 8)  & $ff
           b:Int = argb & $ff
         argb = a*$1000000 + r*$10000 + g*$100 + b
         WritePixel pixmap,i,j,argb
      Next
   Next

   Return LoadImage(pixmap)
EndFunction


Correct declaration of the images would make a serious performance difference
(ie use :TImage etc, otherwise its slow as it is converted to int and back)

And if you set the blendmode to alpha it would potentially not ignore the alpha channel as well :)

Ok !! Many thanks dreamora :)

Edit : New code

Graphics 640,480

Global ImageFond1=LoadImage("image1.jpg")
Global ImageDest=mirrorImage(ImageFond1)

While Not KeyHit(KEY_ESCAPE)
	Cls
	SetColor 255,255,255
	SetBlend ALPHABLEND
	SetAlpha 1.0
	
	DrawImage ImageFond1,10,10
	DrawImage ImageDest,10,250
	
	Flip 
Wend

Function mirrorImage:TImage(img:TImage)
   Local a:Int
   Local r:Int
   Local g:Int
   Local b:Int
   Local i:Int
   Local j:Int
   Local argb:Int

   Local pixmap:TPixmap = LockImage(img)
   pixmap = ConvertPixmap(pixmap,PF_RGBA8888)
   pixmap = YFlipPixmap(pixmap)

   For i = 0 To PixmapWidth(pixmap)-1
      For j = 0 To PixmapHeight(pixmap)-1
         argb = ReadPixel(pixmap,i,j)
         a:Int = Int(76.0*(1.0-((Float(j)/Float(ImageHeight(img))))))
         If (argb Shr 24) = 0 Then a = 0

         r:Int = (argb Shr 16) & $ff
           g:Int = (argb Shr 8)  & $ff
           b:Int = argb & $ff
         argb = a*$1000000 + r*$10000 + g*$100 + b
         WritePixel pixmap,i,j,argb
      Next
   Next

   Return LoadImage(pixmap)
EndFunction


Don't forget you can mirror when drawing simply by setting SetScale -1,1. You probably knew that but maybe others didn't...

Ooops. Sorry misread

Don't forget you can mirror when drawing simply by setting SetScale -1,1. You probably knew that but maybe others didn't...


also -- if you *need* an image to be stored in flipped format, I wonder if it wouldn't be faster to to a setscale -1,1, draw it, and just use a grabimage on it (instead of re-drawing it a pixel a time)

Unless you have some alpha blending going on as well, it might be faster to do it that way?

his redraw per pixel is only needed due to the alpha information. The Pixmap has a straight X Y flip command that he used ;-)

and grab image isn't the fastest way as it does a grabpixmap -> loadimage from that ... so lockimage yflip(pixmap) unlock might be faster, no grabbing involved.