January 23, 2021, 05:11:45 AM

Author Topic: [bmx] Pixmap paste with mask by tonyg [ 1+ years ago ]  (Read 484 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bmx] Pixmap paste with mask by tonyg [ 1+ years ago ]
« on: June 29, 2017, 12:28:38 AM »
Title : Pixmap paste with mask
Author : tonyg
Posted : 1+ years ago

Description : The supplied Pixmap.paste method will use memcopy to copy
all the pixels from source to target. This means that pixels normally omitted using the mask colour are also copied. This function (which could do with a tidy up) will copy pixels from source to target omitting pixels whose colour matches the mask.


Code :
Code: BlitzMax
  1. Graphics 640,480
  2. image1:TImage=LoadImage("max.png")
  3. image2:TImage=LoadImage("light.png")
  4. While Not KeyHit(key_escape)
  5.         Cls
  6.         If MouseHit(1)
  7.                 argb:Int=intcolor(image2.mask_r,image2.mask_g,image2.mask_b)
  8.                 image1:TImage=drawbuffer(image1,image2,0,0,argb)
  9.         EndIf
  10.         DrawImage image1,0,0
  11.         Flip
  12. Wend
  13. WaitKey()
  14. Function drawbuffer:TImage(imagea:TImage,imageb:TImage,x:Int,y:Int,argb:Int)
  15.   If x + ImageWidth(imageb) > ImageWidth(imagea) Or y + ImageHeight(imageb) > ImageHeight(imagea) RuntimeError("Imagea to big to fit in imageb")
  16. '  start_func=MilliSecs()
  17.   mypixmap2:TPixmap=LockImage(imageb)
  18.   UnlockImage(imageb)
  19.   mypixmap1:TPixmap=LockImage(imagea)
  20.   Local mypixelptr2:Int Ptr = Int Ptr(mypixmap2.pixelptr(0,0))
  21.   Local mypixelptr2backup:Int Ptr = mypixelptr2
  22.   Local mypixelptr1:Int Ptr = Int Ptr(mypixmap1.pixelptr(x,y))
  23.   Local mypixelptr1backup:Int Ptr = mypixelptr1
  24.   For my_x=0 To ((mypixmap2.width)*(mypixmap2.height))
  25.      If mypixelptr2[0] <> argb
  26.          If mypixelptr2[0] <> 0 mypixelptr1[0]=mypixelptr2[0]
  27.  '             If mypixelptr2[0] <> 16777215 mypixelptr1[0]=mypixelptr2[0]
  28.     EndIf
  29.      mypixelptr1:+1
  30.      mypixelptr2:+1
  31.      If mypixelptr2 = mypixelptr2backup+(mypixmap2.pitch Shr 2)
  32.          mypixelptr1 = mypixelptr1backup+(mypixmap1.pitch Shr 2)
  33.          mypixelptr1backup=mypixelptr1
  34.          mypixelptr2backup=mypixelptr2
  35.      EndIf
  36.   Next
  37.   Return LoadImage(mypixmap1)
  38. '  end_func=MilliSecs()
  39. End Function
  40. Function IntColor(R,G,B,A=255)
  41. 'returns argb value from red, green, blue.
  42.      Return A Shl 24 | R Shl 16 | G Shl 8 | B Shl 0
  43. End Function


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal