ColorHasAlpha()
-
- Addict
- Posts: 1264
- Joined: Wed Feb 28, 2007 9:13 am
- Location: London
ColorHasAlpha()
I've noticed that RGB(255,0,0) and RGBA(255,0,0,255) give different integers, although they look identical visually.
Could we get a function that would tell us whether a colour integer has an alpha channel or not? It would be very helpful.
Could we get a function that would tell us whether a colour integer has an alpha channel or not? It would be very helpful.
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."
Re: ColorHasAlpha()
Code: Select all
Alpha(Color)
but you can not distinguish between RGB(255,0,0) and RGBA(255,0,0,0)
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
-
- Addict
- Posts: 1264
- Joined: Wed Feb 28, 2007 9:13 am
- Location: London
Re: ColorHasAlpha()
That's the problem. Because it has no alpha channel, it will look like RGBA(255,0,0,255).STARGÅTE wrote:RGB(255,0,0) has no alpha-channel, so it returns 0
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."
Re: ColorHasAlpha()
From the color alone, you can't read the alpha value, because it is always 32 bits (long).
The only way is DrawingBufferPixelFormat, it returns:
The only way is DrawingBufferPixelFormat, it returns:
Code: Select all
#PB_PixelFormat_24Bits_RGB ; 3 Byte pro Pixel (RRGGBB)
#PB_PixelFormat_24Bits_BGR ; 3 Byte pro Pixel (BBGGRR)
#PB_PixelFormat_32Bits_RGB ; 4 Byte pro Pixel (RRGGBB)
#PB_PixelFormat_32Bits_BGR ; 4 Byte pro Pixel (BBGGRR)
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
-
- Addict
- Posts: 1264
- Joined: Wed Feb 28, 2007 9:13 am
- Location: London
Re: ColorHasAlpha()
What about this?
Code: Select all
Procedure.b ColorHasAlpha(c.i)
r = Red(c)
g = Green(c)
b = Blue(c)
c2 = RGB(r,g,b)
If c2=c
ProcedureReturn #False
Else
ProcedureReturn #True
EndIf
EndProcedure
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."
Re: ColorHasAlpha()
Sorry but your code doesn't make any sense. You can't detect if there is alpha. Either it is supported by the drawing output you are currently using and therefore present or not - It's as easy as that.
Maybe you should post what you need this function for. It maybe easier to help you then...
Maybe you should post what you need this function for. It maybe easier to help you then...
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
Re: ColorHasAlpha()
I don't agree that the code doesn't make sense... however, RGB(255,0,0) would still return the same value as RGBA(255,0,0,0)
DrawingBufferPixelFormat is the easiest (perhaps the only) way
DrawingBufferPixelFormat is the easiest (perhaps the only) way
there is no sig, only zuul (and the following disclaimer)
WARNING: may be talking out of his hat
WARNING: may be talking out of his hat
Re: ColorHasAlpha()
Untested but wouldn't it be more like this?
Code: Select all
Procedure ColorHasAlpha(x, y)
c = Point(x, y)
a = Alpha(c)
If a < 255
ProcedureReturn #True
Else
ProcedureReturn #False
EndIf
EndProcedure
www.posemotion.com
PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef
Even the vine knows it surroundings but the man with eyes does not.
PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef
Even the vine knows it surroundings but the man with eyes does not.
-
- Addict
- Posts: 1264
- Joined: Wed Feb 28, 2007 9:13 am
- Location: London
Re: ColorHasAlpha()
The point is that RGB(255,0,0) looks exactly the same as RGBA(255,0,0,255), but they have different numbers. RGBA(255,0,0,0) has the same number has RGB(255,0,0), but is completely invisible.
After further testing I can see that it's impossible to tell from the integer whether it has an alpha channel. A number produced with RGBA() is exactly the same as with RGB() if the alpha channel is 0. Only if you raise the alpha (to 1, for example) does RGBA() record it as a 32-bit colour. So I'm sorry for making this feature request as I can see it's impossible.
Why do I need to know the difference?
I'm building a system that takes values which could have been made using either RGB() or RGBA(). It stores them as numbers, and uses them later on. If the colour has alpha 0, does that mean the colour was made with RGB(), or with RGBA() using zero as the alpha value? Both have alpha 0, but one should be fully transparent and the other should be fully opaque.
That's the problem.
After further testing I can see that it's impossible to tell from the integer whether it has an alpha channel. A number produced with RGBA() is exactly the same as with RGB() if the alpha channel is 0. Only if you raise the alpha (to 1, for example) does RGBA() record it as a 32-bit colour. So I'm sorry for making this feature request as I can see it's impossible.
Why do I need to know the difference?
I'm building a system that takes values which could have been made using either RGB() or RGBA(). It stores them as numbers, and uses them later on. If the colour has alpha 0, does that mean the colour was made with RGB(), or with RGBA() using zero as the alpha value? Both have alpha 0, but one should be fully transparent and the other should be fully opaque.
That's the problem.
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."
Re: ColorHasAlpha()
Forgive me if I'm missing something but you can't draw an alpha image with RGB alone as it always draws 255 for the alpha, so to speak. You could draw with RGB on a alpha layer but it still only draws the R, G, and B color information. So I would say if the color has an alpha value other then 255, save the info as RGBA, otherwise RGB.
www.posemotion.com
PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef
Even the vine knows it surroundings but the man with eyes does not.
PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef
Even the vine knows it surroundings but the man with eyes does not.