Check if pixel is transparent

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

Moderators: Shine, Insert_witty_name

Post Reply
Mr Billy
Posts: 10
Joined: Wed Oct 26, 2005 10:13 am

Check if pixel is transparent

Post by Mr Billy »

Is there a way to check if a pixel in an image is transparent? When I use the img:pixel, the transparent pixels register as white for me. thanks.
"There is no spoone"
-The Matricks
haust
Posts: 25
Joined: Sat Oct 01, 2005 12:37 am
Location: France

Post by haust »

Take a look here, this may help.
Mr Billy
Posts: 10
Joined: Wed Oct 26, 2005 10:13 am

Post by Mr Billy »

I know how to make pngs transparent, and how to set pixels to transparent, but I want to be able to identify whether or not a pixel is transparent in a loaded png.
"There is no spoone"
-The Matricks
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

You can use "pixel" to get the color and "colors" to get the color components of a color object:

Code: Select all

image = Image.createEmpty(1, 1)
color = image:pixel(0, 0)
colors = color:colors()
assert(colors.r == 0)
assert(colors.g == 0)
assert(colors.b == 0)
assert(colors.a == 0)
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Post by LuMo »

@shine
would it be faster than lua if supported by a C-funtion?
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

LuMo wrote: would it be faster than lua if supported by a C-funtion?
What should this C function do?

Anyway, with the new true color mode and perhaps your collision test, there is no reason to read pixel components.
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Post by LuMo »

true;
so new model will be 8888 for sure?
cause then i can rewrite my stuff ;)
if you grand me svn access i could put it up too
note: 8888 would make my life much easier ;)

greets
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

Yes, I think 8888 should be the new pixelmode mode for Lua Player, because this makes things a lot easier and you have alpha blending and true color. The drawback is less speed, but you can use the Timer class for smooth animations, so you don't need 60 fps.

Not relying on a fixed fps rate, but using the Timer class, has another advantage: a port to the PC version would be much easier and it would run on PC smooth, too and on other consoles. And if someone wants to implement a caching algorithm for images in VRAM, it would be faster than the current Lua Player, even in true color :-)
Post Reply