[No Bug]in 'Color = RGBA(Red, ...)', should use 'Color.q'

Just starting out? Need help? Post your questions and find answers here.
User avatar
gurj
Enthusiast
Enthusiast
Posts: 658
Joined: Thu Jan 22, 2009 3:48 am
Location: china
Contact:

[No Bug]in 'Color = RGBA(Red, ...)', should use 'Color.q'

Post by gurj »

updated:
in 'Color = RGBA(Red, Green, Blue, Alpha)', should use 'Color.q'
bug when using 32-bit system:
RGBA()
Syntax
Color = RGBA(Red, Green, Blue, Alpha)
----------
should use 'Color.q' , because:
Color=Color.l<$80000000<$ffffffff
x.q<=$100000000*$80000000-1

this bug on using 32-bit system, because:
-----------
Variables and Types

Variables declaration

To declare a variable in PureBasic, simply type its name. You can also specify the type you want this variable to be. By default, when a data type is not indicated, the data is an integer. Variables do not need to be explicitly declared, as they can be used as "variables on-the-fly". The Define keyword can be used to declare multiple variables in one statement. If you don't assign an initial value to the variable, their value will be 0.
-----------
Long .l 4 bytes -2147483648 to +2147483647
Integer .i 4 bytes (using 32-bit compiler) -2147483648 to +2147483647
Integer .i 8 bytes (using 64-bit compiler) -9223372036854775808 to +9223372036854775807
Last edited by gurj on Thu Mar 16, 2017 8:40 pm, edited 3 times in total.
my pb for chinese:
http://ataorj.ys168.com
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: in 'Result = Alpha(Color)', should use 'Result.q'

Post by Shield »

Alpha returns the value of the alpha channel only, so it's always between 0 and 255.
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
User avatar
gurj
Enthusiast
Enthusiast
Posts: 658
Joined: Thu Jan 22, 2009 3:48 am
Location: china
Contact:

Re: in 'Result = Alpha(Color)', should use 'Result.q'

Post by gurj »

will update,is
in 'Color = RGBA(Red, Green, Blue, Alpha)', should use 'Color.q'

thanks Shield !
my pb for chinese:
http://ataorj.ys168.com
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Re: in 'Color = RGBA(Red, Green, Blue, Alpha)', should use '

Post by nco2k »

red is 1 byte, green is 1 byte, blue is 1 byte, alpha is 1 byte, which makes a total of 4 bytes (long):

Code: Select all

Color.l = RGBA(11, 22, 33, 44)

Red.a = Red(Color)
Green.a = Green(Color)
Blue.a = Blue(Color)
Alpha.a = Alpha(Color)

Debug Red
Debug Green
Debug Blue
Debug Alpha
returning a quad would make no sense. you are simply getting confused by longs being signed and therefore returning a negative value. no bug.

c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
User avatar
gurj
Enthusiast
Enthusiast
Posts: 658
Joined: Thu Jan 22, 2009 3:48 am
Location: china
Contact:

Re: in 'Color = RGBA(Red, Green, Blue, Alpha)', should use '

Post by gurj »

@nco2k:

Code: Select all

Debug Bool(RGBA(255,255,255,255)=$ffffffff)
a.l=$ffffffff
Debug a
;x.l<$80000000
;$ffffffff=$80000000*2-1
Debug Bool($ffffffff=$80000000*2-1)
my pb for chinese:
http://ataorj.ys168.com
User avatar
gurj
Enthusiast
Enthusiast
Posts: 658
Joined: Thu Jan 22, 2009 3:48 am
Location: china
Contact:

Re: in 'Color = RGBA(Red, Green, Blue, Alpha)', should use '

Post by gurj »

Debug $ffffffff;4294967295=2147483647*2+1
;Long .l 4 bytes -2147483648 To +2147483647
my pb for chinese:
http://ataorj.ys168.com
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Re: in 'Color = RGBA(Red, Green, Blue, Alpha)', should use '

Post by nco2k »

whats your point? a signed longs -1 equals an unsigned longs 4294967295.

Code: Select all

Debug StrU(-1, #PB_Long)
as i said earlier, you are confused by the negative value of a signed variable.

a byte is a byte, wether you read it as signed or unsigned:

Code: Select all

q.q = -1
Debug PeekB(@q)
Debug PeekA(@q)
Debug PeekW(@q)
Debug PeekU(@q)
purebasic doesnt support unsigned longs and quads. why should pb return 8 bytes for a 4 byte variable, only to fix your cosmetical issue?

c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Re: in 'Color = RGBA(Red, Green, Blue, Alpha)', should use '

Post by nco2k »

gurj wrote:Debug $ffffffff;4294967295=2147483647*2+1
;Long .l 4 bytes -2147483648 To +2147483647
Debug uses a quad (8 byte) container, thats why it can display $ffffffff as 4294967295.

you can still apply a value up to 4294967295 to a long, which will correctly be displayed as -1, since a long is signed:

Code: Select all

l.l = 4294967295
Debug l
c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
User avatar
gurj
Enthusiast
Enthusiast
Posts: 658
Joined: Thu Jan 22, 2009 3:48 am
Location: china
Contact:

Re: in 'Color = RGBA(Red, Green, Blue, Alpha)', should use '

Post by gurj »

ok , thanks nco2k !
; in pb ,for Color Example:
; -16776961=4278190335
; so use 4 bytes

Code: Select all

If OpenWindow(0, 0, 0, 400, 200, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    CanvasGadget(0, 0, 0, 400, 200)

    If StartVectorDrawing(CanvasVectorOutput(0))

      AddPathBox(50, 50, 200, 50)
      VectorSourceColor(RGBA(255, 0, 0, 255))
      StrokePath(10)
      l.l=RGBA(255, 0, 0, 255)
      Debug l;=-16776961
      AddPathBox(150, 75, 200, 50)
      VectorSourceColor(l)
      StrokePath(10)
         q.q=$ff0000ff;RGBA(255, 0, 0, 255)
      Debug q;=4278190335
      AddPathBox(200, 105, 200, 50)
      VectorSourceColor(q)
      StrokePath(10)
   
      StopVectorDrawing()
    EndIf
    
    Repeat
      Event = WaitWindowEvent()
    Until Event = #PB_Event_CloseWindow
  EndIf

my pb for chinese:
http://ataorj.ys168.com
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2056
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: [no bug]in 'Color = RGBA(Red, ...)', should use 'Color.q

Post by Andre »

As it seems to be no bug nor a needed change/addition to the PB docs I close this topic now.

If there is still something wrong feel free to post here again...
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
Mesa
Enthusiast
Enthusiast
Posts: 345
Joined: Fri Feb 24, 2012 10:19 am

Re: [No Bug]in 'Color = RGBA(Red, ...)', should use 'Color.q

Post by Mesa »

Done.
(I can't change the title of this thread ! Maybe because it's a moved thread)
Post Reply