Announcement

Collapse
No announcement yet.

RGB Compliment

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • RGB Compliment


    How do I pull the R, G, B values back out of BkClr?

    Code:
    LOCAL BkClr as LONG
    
     BkClr = RGB( 255, 10, 20 )
    
     R = ???( BkClr )
     G = ???( BkClr )
     B = ???( BkClr )
    ------------------
    Kind Regards
    Mike

  • #2
    Code:
    #COMPILE EXE
    #DIM ALL
    
    DECLARE FUNCTION GetRed(inVal AS LONG) AS LONG
    DECLARE FUNCTION GetGreen(inVal AS LONG) AS LONG
    DECLARE FUNCTION GetBlue(inVal AS LONG) AS LONG
    
    FUNCTION PBMAIN () AS LONG
    
        LOCAL l AS LONG
    
        l=RGB(201,202,203)
    
        MSGBOX "Red: "+FORMAT$(GetRed(l))
        MSGBOX "Green: "+FORMAT$(GetGreen(l))
        MSGBOX "Blue: "+FORMAT$(GetBlue(l))
    
    END FUNCTION
    
    FUNCTION GetRed(inVal AS LONG) AS LONG
    
        #REGISTER NONE
    
        !push   eax
        !push   ebx
        !mov    eax,inVal
        !mov    eax,[eax]
        !xor    ebx,ebx
        !mov    bl,al
        !mov    FUNCTION, ebx
        !pop    ebx
        !pop    eax
    
    END FUNCTION
    
    FUNCTION GetGreen(inVal AS LONG) AS LONG
    
        #REGISTER NONE
    
        !push   eax
        !push   ebx
        !mov    eax,inVal
        !mov    eax,[eax]
        !shr    eax,&H8
        !xor    ebx,ebx
        !mov    bl,al
        !mov    FUNCTION, ebx
        !pop    ebx
        !pop    eax
    
    END FUNCTION
    
    FUNCTION GetBlue(inVal AS LONG) AS LONG
    
        #REGISTER NONE
    
        !push   eax
        !push   ebx
        !mov    eax,inVal
        !mov    eax,[eax]
        !shr    eax,&H10
        !xor    ebx,ebx
        !mov    bl,al
        !mov    FUNCTION, ebx
        !pop    ebx
        !pop    eax
    
    END FUNCTION
    ------------------
    Adam Drake
    Drake Software

    Comment


    • #3
      Mike --
      Code:
      TYPE COLORBYTES
          B AS BYTE
          G AS BYTE
          R AS BYTE
          A AS BYTE
      END TYPE
      
      SUB SplitARGBcolor ALIAS "SplitARGBcolor" (BYVAL ARGB AS LONG, Alpha AS BYTE, Red AS BYTE, Green AS BYTE, Blue AS BYTE) EXPORT
          DIM bytestruct AS COLORBYTES
          LSET bytestruct = MKL$(ARGB)
          Alpha = bytestruct.A
          Red   = bytestruct.R
          Green = bytestruct.G
          Blue  = bytestruct.B
      END SUB
      ------------------
      Patrice Terrier
      mailto[email protected][email protected]</A>
      www.zapsolution.com
      Addons: WinLIFT (Skin Engine), GDImage (Graphic control), Artwork (logo creation), GDI+ Helper (GDIPLUS)
      Patrice Terrier
      www.zapsolution.com
      www.objreader.com
      Addons: GDImage.DLL 32/64-bit (Graphic library), WinLIFT.DLL 32/64-bit (Skin Engine).

      Comment


      • #4
        Here's another one! ...

        Code:
        TYPE Components
          Red AS BYTE
          Green AS BYTE
          Blue AS BYTE
        END TYPE
        
        UNION Colors
          Complete AS DWORD
          Component AS Components
        END UNION
          
        FUNCTION PBMAIN () AS LONG
        
          LOCAL BkClr AS LONG
          LOCAL Color AS Colors
          LOCAL R AS LONG
          LOCAL G AS LONG
          LOCAL B AS LONG
          
          BkClr = RGB( 255, 10, 20 )
        
          Color.Complete = BkClr
          R = Color.Component.Red
          G = Color.Component.Green
          B = Color.Component.Blue
          
          MSGBOX FORMAT$(R) & ", " & FORMAT$(G) & ", " & FORMAT$(B)
        
        END FUNCTION


        ------------------
        - LJ

        Comment


        • #5
          Thought again. This is actually the simplest way to do it...

          Code:
          FUNCTION PBMAIN () AS LONG
          
            LOCAL BkClr AS LONG
            LOCAL R AS LONG
            LOCAL G AS LONG
            LOCAL B AS LONG
            
            BkClr = RGB( 255, 10, 20 )
            R = PEEK(varptr(BkClr))
            G = PEEK(varptr(BkClr)+1)
            B = PEEK(varptr(BkClr)+2)
            MSGBOX FORMAT$(R) & ", " & FORMAT$(G) & ", " & FORMAT$(B)
          
          END FUNCTION
          ------------------
          - LJ

          Comment

          Working...
          X