CreateImage() 32bit white bug

Post bugreports for the Windows version here
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

CreateImage() 32bit white bug

Post by infratec »

Hi,

$FFFFFFFF (-1) as color results in a transparent image instead of a white one.

Code: Select all

If OpenWindow(0, 0, 0, 900, 100, "DrawAddBorder", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  
  CreateImage(0, 450, 100, 32, RGBA(255,255,255,255)) ; -> transparent
  ImageGadget(0, 0, 0, 0, 0, ImageID(0))
  
  CreateImage(1, 450, 100, 32, RGBA(255,255,255,254)) ; -> white
  ImageGadget(1, 450, 0, 0, 0, ImageID(1))
  
  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
EndIf
Win10 x64 with PB 5.61 x86

Bernd
marc_256
Enthusiast
Enthusiast
Posts: 743
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

Re: CreateImage() 32bit white bug

Post by marc_256 »

Bernd,

you need this
you need to use RGB() color instead of RGBA()

Code: Select all

CreateImage(1, 450, 100, 32, RGB(255,255,254) | #PB_Image_Transparent) ; -> white

Code: Select all

If OpenWindow(0, 0, 0, 800, 200, "DrawAddBorder", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
	StartDrawing(WindowOutput(0))
		DrawingMode(#PB_2DDrawing_Default)
		Box(0, 0, 1200, 200, $00000000)
	StopDrawing()

;---------------------------------------------------------------------------------------------------
	CreateImage(0, 400, 100, 32, RGB(255, 255, 255) | #PB_Image_Transparent) ; -> transparent
	ImageGadget(0, 0, 0, 0, 0, ImageID(0))

	CreateImage(1, 400, 100, 32, RGB(255, 255, 254) | #PB_Image_Transparent) ; -> white
	ImageGadget(1, 400, 0, 0, 0, ImageID(1))

	CreateImage(2, 400, 100, 32, RGBA(255, 255, 255, 255)) ; -> transparent
	ImageGadget(2, 0, 200, 0, 0, ImageID(1))

	CreateImage(2, 400, 100, 32, RGBA(255, 255, 255, 254)) ; -> white
	ImageGadget(2, 400, 100, 0, 0, ImageID(1))

;---------------------------------------------------------------------------------------------------
	StartDrawing(WindowOutput(0))
		DrawingMode(#PB_2DDrawing_Default)
		DrawText(10, 10, "RGB(255, 255, 255) | #PB_Image_Transparent)", $00FFFFFF, $00000000)
	StopDrawing()

	StartDrawing(WindowOutput(0))
		DrawingMode(#PB_2DDrawing_Default)
		DrawText(410, 10, "RGB(255, 255, 254) | #PB_Image_Transparent)", $00FFFFFF, $00000000)
	StopDrawing()

	StartDrawing(WindowOutput(0))
		DrawingMode(#PB_2DDrawing_Default)
		DrawText(10, 110, "RGBA(255, 255, 255, 255)", $00FFFFFF, $00000000)
	StopDrawing()

	StartDrawing(WindowOutput(0))
		DrawingMode(#PB_2DDrawing_Default)
		DrawText(410, 110, "RGBA(255, 255, 255, 254)", $00FFFFFF, $00000000)
	StopDrawing()

;---------------------------------------------------------------------------------------------------
	Repeat
		Event = WaitWindowEvent()
	Until Event = #PB_Event_CloseWindow

	EndIf
marc,
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
Little John
Addict
Addict
Posts: 4519
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: CreateImage() 32bit white bug

Post by Little John »

infratec wrote:$FFFFFFFF (-1) as color results in a transparent image instead of a white one.
This is in accordance to the documentation.
[u]Documentation of CreateImage()[/u] wrote:[The background] color can be set to #PB_Image_Transparent to create an image with the alpha channel set to full transparent.
Now guess what the value of #PB_Image_Transparent is ...? :-)
-1
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: CreateImage() 32bit white bug

Post by infratec »

Hm...

you are right.

But when I create a 32 bit image it should be natural to use RGBA().
And the last parameter of CreateImage() should be a quad, then -1 is out of the normal range.

Bernd
Little John
Addict
Addict
Posts: 4519
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: CreateImage() 32bit white bug

Post by Little John »

infratec wrote:But when I create a 32 bit image it should be natural to use RGBA().
And the last parameter of CreateImage() should be a quad, then -1 is out of the normal range.
I agree.

Interesting enough, when in your above code example I replace

Code: Select all

RGBA(255,255,255,255)
with

Code: Select all

#White   ; (some color constants for all OS added in PB 5.60)
then the result is as expected (tested with PB 5.61 x86 and x64 on Windows).

So the source of the problem seems to be an inconsistency of the RGBA() function.
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Re: CreateImage() 32bit white bug

Post by nco2k »

@Little John
thats because white is $FFFFFF (16777215).
Little John wrote:So the source of the problem seems to be an inconsistency of the RGBA() function.
no, the source of the problem is that #PB_Image_Transparent clashes with a valid RGBA value:

Code: Select all

Debug Bin(#PB_Image_Transparent, #PB_Long)
Debug Bin(RGBA(255, 255, 255, 255), #PB_Long)
@infratec
infratec wrote:And the last parameter of CreateImage() should be a quad, then -1 is out of the normal range.
changing the BackColor parameter to quad wont be enough. RGBA() returns a signed long, and therefor will still return -1. the #PB_Image_Transparent constant has to be changed to a value larger than +4294967295 or smaller than -2147483648.

c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
Little John
Addict
Addict
Posts: 4519
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: CreateImage() 32bit white bug

Post by Little John »

nco2k wrote:@Little John
thats because white is $FFFFFF (16777215).
Yes, I know.
And if RGBA(255, 255, 255, 255) would return the same value, then this problem wouldn't exist.
nco2k wrote:#PB_Image_Transparent clashes with a valid RGBA value
I know, I already wrote that in my first post in this thread.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8425
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: CreateImage() 32bit white bug

Post by netmaestro »

There is no value for #PB_Image_Transparent that won't clash with a colorref as long as the flag shares a common parameter with the backcolor. The correct solution is to add a new parameter for transparency that is either true or false. Until that happens confusion will abound in the creation of images and the bug reports will keep on coming.
BERESHEIT
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

Re: CreateImage() 32bit white bug

Post by kenmo »

I proposed a simple solution in 2015:
http://www.purebasic.fr/english/viewtop ... =3&t=63339

If the depth parameter is 32, then the color parameter should be interpreted as an RGBA value. (24-bit can just interpret it as RGB.)

Then change the value of #PB_Image_Transparent from $FFFFFFFF (conflicts with opaque white) to $00000000 (same as RGBA(0, 0, 0, 0)).

This eliminates all the confusion... all RGBA values work as expected (no conflicts), and code that passes #PB_Image_Transparent still works as expected (black* image with alpha = 0, as is produced by PB now!)

No quad needed, just a clever value for #PB_Image_Transparent!





* or does #PB_Image_Transparent produce white with alpha = 0 ? It's a quick check... If white, then set #PB_Image_Transparent to RGBA(255, 255, 255, 0)
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8425
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: CreateImage() 32bit white bug

Post by netmaestro »

Using clever approaches to merge two parameters into one will always lead to confusion of one kind or another. One more optional parameter isn't going to cause an epidemic of arthritis.
BERESHEIT
Little John
Addict
Addict
Posts: 4519
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: CreateImage() 32bit white bug

Post by Little John »

Strictly speaking, I think this is not a bug. According to the documentation of CreateImage(), the function expects a 24 bit RGB value for the 'BackColor' parameter, not a 32 bit RGBA value. And when we only pass RGB values as 'BackColor' parameter, then we won't encounter this issue!

Passing RGBA values as 'BackColor' parameter is currently no advantage anyway, since according to my tests the Alpha value is simply ignored ... with the one exception of RGBA(255,255,255,255) that we are discussing here. So what we are talking about is a feature request, and that's what kenmo did in 2015. As for this request, I agree with netmaestro: Keep it straight and simple.
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Re: CreateImage() 32bit white bug

Post by nco2k »

Little John wrote:As for this request, I agree with netmaestro: Keep it straight and simple.
why shouldnt you be able to pre-define the alpha channel? if you want to keep things straight and simple, then you should be able to set all 32bit in one go. currently you can pre-define the first 24bit, but have to manually define the last 8bit. does that make sense to you?

c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

Re: CreateImage() 32bit white bug

Post by kenmo »

I agree with nco2k, the simplest solution is to use the Alpha channel in the existing BackColor parameter, not to add another parameter.

You've already specified an RGBA image by the depth parameter, so why mask out the A part of the passed value?

(Plus this gives you an alpha choice of 0-255, instead of just 100% transparent like #PB_Image_Transparent does.)
Little John
Addict
Addict
Posts: 4519
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: CreateImage() 32bit white bug

Post by Little John »

kenmo wrote:the simplest solution is to use the Alpha channel in the existing BackColor parameter, not to add another parameter.

You've already specified an RGBA image by the depth parameter, so why mask out the A part of the passed value?
Yes, I see your point now.
User avatar
Demivec
Addict
Addict
Posts: 4086
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: CreateImage() 32bit white bug

Post by Demivec »

This isn't a bug, according to Fred it is a feature request.

http://www.purebasic.fr/english/viewtopic.php?f=3&t=63302&p=471887
Post Reply