Alpha Mask

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
swordman
Posts: 27
Joined: Tue Dec 27, 2005 9:04 pm

Alpha Mask

Post by swordman »

Hi! Is there a way to use an image as alpha mask to others?
Also a B/W one could be fine;)
Thanks!
CT_Bolt
Posts: 14
Joined: Sat Mar 04, 2006 3:21 am
Location: Computer Chair

Oops...

Post by CT_Bolt »

My I.E. glitched and sent my post twice.
Last edited by CT_Bolt on Fri Mar 31, 2006 6:30 am, edited 1 time in total.
CT_Bolt
Posts: 14
Joined: Sat Mar 04, 2006 3:21 am
Location: Computer Chair

Check it out.

Post by CT_Bolt »

I have made a function for the Image Class that does just that... It makes an alpha mask of the image that calls the function 'AlphaImage' and sets it to anouther image.

Use it like this:

Code: Select all

X = 0 ; Y = 0 ; Color.new(200,0,0,200)
MyImagesAlphaMask = MyImage.AlphaImage(X, Y, Colour)
My Alpha Function: Click Here
swordman
Posts: 27
Joined: Tue Dec 27, 2005 9:04 pm

Post by swordman »

Thanks CT_Bolt! Your code is perfect!
CT_Bolt
Posts: 14
Joined: Sat Mar 04, 2006 3:21 am
Location: Computer Chair

No problem

Post by CT_Bolt »

Well I am happy you can use it... if you have any other problems just post them and I'll be happy to help.
swordman
Posts: 27
Joined: Tue Dec 27, 2005 9:04 pm

Post by swordman »

Hi CT_Bolt
I do some more test but at some point i get errors al line

Code: Select all

color = self:pixel(XPos,YPos)
Something aboute XPos or YPos meke them unvalid.
So I rewrite the function myself.
If it could be usefull, here it is

Code: Select all

function Mask(ToDraw,Mask,Alpha)
  if not Alpha then Alpha = Color.new(0,0,0,0) end
  Masked = Image.createEmpty(Mask:width(),Mask:height())
  Masked:clear(Color.new(0,0,0,0))
  for xp = 0, Mask:width()-1 do
    for yp = 0, Mask:height()-1 do
      pix = Mask:pixel(xp,yp)
      c = pix:colors()
      if  not (c.a == 0) then
        Masked:fillRect(xp,yp,1,1,ToDraw:pixel(xp,yp))
      end
    end
  end
  return Masked
end
The main idea is the same, but i cuold use it without error.
Thanks Again!
JorDy
Posts: 121
Joined: Sun Dec 11, 2005 8:45 am

Post by JorDy »

i had that problem with the :pixel(x,y) function i solved it by setting the ammount of pixeld to cover as

Code: Select all

Image:width()-1
but the code seems fine to me
CT_Bolt
Posts: 14
Joined: Sat Mar 04, 2006 3:21 am
Location: Computer Chair

Ahh... oh yeah.

Post by CT_Bolt »

Hmm... I see... yes I did overlook that... well thanks for fixing it.
Post Reply