Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Color Mix Modes

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

  • PBWin Color Mix Modes

    Test dialog to explore the different Color Mix Modes available for Graphic Targets in PB.

    See discussion at http://www.powerbasic.com/support/pb...ad.php?t=40680
    '
    Code:
    '#DEBUG DISPLAY ON
    #DIM ALL
    #REGISTER NONE
    #COMPILE EXE
     
    #INCLUDE "WIN32API.INC"
    #INCLUDE "COMDLG32.INC"
     
    %GFX_GRAPHIC1    = 1001
    %GFX_Color1      = 1002
    %GFX_Color2      = 1003
    %GFX_MixRes      = 1004
    %LBL_Color1      = 1012
    %LBL_Color2      = 1013
    %LBL_MixRes      = 1014
    %CMB_MixModeSel  = 1016
    %LBL_Intro       = 1018
    %BTN_ColorPick1  = 1019
    %BTN_ColorPick2  = 1020
    %LBL_Description = 1021
    '------------------/
     
    FUNCTION PBMAIN()
      Dialog1 0
    END FUNCTION
     
    CALLBACK FUNCTION Dialog1Proc()
     Static hBmp As Dword 
     Local n As Long
     Local sTemp As String
     Static Color1, Color2 As Dword 
     Static Mix_Mode As Long
     
      SELECT CASE AS LONG CBMSG
        CASE %WM_INITDIALOG
          Color1 = %WHITE : Color2 = %BLACK
          Mix_Mode = 13
          Paint_Samples CbHndl, Color1, Color2, Mix_Mode
          Load_Combobox CbHndl, %CMB_MixModeSel
          ComboBox Select CbHndl, %CMB_MixModeSel, 13
          Load_Label CbHndl, %LBL_Description, 13
     
          Graphic Bitmap New 248, 248 To hBmp     ' Create bitmap for background
          Graphic Attach hBmp, 0 
          Graphic Clear %Black
          Graphic Width 10
          For n = 46 To 246 Step 50
            Graphic Line (n,1) - (1,n), %White
            Graphic Line (250,n)- (n,250), %White
          Next
     
          Paint_Main CbHndl, hBmp, Color1, Color2, Mix_Mode
     
        CASE %WM_NCACTIVATE
          STATIC hWndSaveFocus AS DWORD
          IF ISFALSE CbWparam  THEN
            hWndSaveFocus = GetFocus()
          ELSEIF hWndSaveFocus THEN
            SetFocus(hWndSaveFocus)
            hWndSaveFocus = 0
          END IF
     
        CASE %WM_COMMAND
          SELECT CASE AS LONG CBCTL
            CASE %GFX_GRAPHIC1
     
            CASE %GFX_Color1
     
            CASE %BTN_ColorPick1
              IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                Pick_Color CbHndl, Color1
                Control Set Text CbHndl, %LBL_Color1, Hex$(Color1,6)
                Paint_Samples CbHndl, Color1, Color2, Mix_Mode
                Paint_Main CbHndl, hBmp, Color1, Color2, Mix_Mode
              END IF
     
            CASE %GFX_Color2
     
            CASE %BTN_ColorPick2
              IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                Pick_Color CbHndl, Color2
                Control Set Text CbHndl, %LBL_Color2, Hex$(Color2,6)
                Paint_Samples CbHndl, Color1, Color2, Mix_Mode
                Paint_Main CbHndl, hBmp, Color1, Color2, Mix_Mode
              END IF
     
            CASE %GFX_MixRes
     
            CASE %CMB_MixModeSel
              If CbCtlMsg = %CBN_SELCHANGE Then
                ComboBox Get Text CbHndl, %CMB_MixModeSel To sTemp
                ComboBox Get Select CbHndl, %CMB_MixModeSel To n
                Load_Label CbHndl, %LBL_Description, n
                Mix_Mode = n
                Paint_Samples CbHndl, Color1, Color2, Mix_Mode
                Paint_Main CbHndl, hBmp, Color1, Color2, Mix_Mode
              End If
     
          END SELECT
      END SELECT
    END FUNCTION
    '------------------/DlgProc
     
    FUNCTION Dialog1(BYVAL hParent AS DWORD) AS LONG
     LOCAL hDlg, hFont1, hFont2 AS DWORD
     LOCAL sTemp AS STRING
     FONT NEW "ARIAL", 12 To hFont1
     FONT NEW "COURIER NEW", 10 To hFont2
     
     DIALOG NEW PIXELS, hParent, "Mix test", 200, 200, 600, 500,  %WS_CAPTION OR %WS_SYSMENU TO hDlg
      CONTROL ADD GRAPHIC,  hDlg, %GFX_GRAPHIC1, "", 38, 24, 250, 251, %WS_CHILD OR %WS_VISIBLE OR %WS_BORDER
      CONTROL ADD BUTTON,   hDlg, %BTN_ColorPick1, "...", 48, 299, 30, 24
      CONTROL ADD GRAPHIC,  hDlg, %GFX_Color1, "", 93, 299, 79, 29, %WS_CHILD OR %WS_VISIBLE OR %WS_BORDER OR _
        %SS_SUNKEN OR %SS_NOTIFY
      CONTROL ADD LABEL,    hDlg, %LBL_Color1, "Pixel", 183, 307, 97, 20
      CONTROL ADD BUTTON,   hDlg, %BTN_ColorPick2, "...", 48, 340, 30, 24
      CONTROL ADD GRAPHIC,  hDlg, %GFX_Color2, "", 93, 340, 79, 29, %WS_CHILD OR %WS_VISIBLE OR %WS_BORDER OR _
        %SS_SUNKEN OR %SS_NOTIFY
      CONTROL ADD LABEL,    hDlg, %LBL_Color2, "Source", 183, 348, 97, 19
      CONTROL ADD GRAPHIC,  hDlg, %GFX_MixRes, "", 93, 379, 79, 31, %WS_CHILD OR %WS_VISIBLE OR %WS_BORDER OR _
        %SS_SUNKEN OR %SS_NOTIFY
      CONTROL ADD LABEL,    hDlg, %LBL_MixRes, "Result of Mix", 183, 388, 97, 20
      sTemp = "There are 16 built-in mix modes available to use for mixing the drawing color with the color that already " + _
              "exists at the drawing location."
      CONTROL ADD LABEL,    hDlg, %LBL_Intro, sTemp , 330, 24, 233, 75
      CONTROL ADD COMBOBOX, hDlg, %CMB_MixModeSel, , 330, 114, 214, 300, %WS_CHILD OR %WS_VISIBLE OR _
        %WS_TABSTOP OR %CBS_SIMPLE
      CONTROL ADD LABEL,    hDlg, %LBL_Description, "MixMode Description", 90, 431, 382, 57
     
      CONTROL SET FONT      hDlg, %LBL_Color1, hFont1
      CONTROL SET FONT      hDlg, %LBL_Color2, hFont1
      CONTROL SET FONT      hDlg, %LBL_MixRes, hFont1
      CONTROL SET FONT      hDlg, %LBL_Intro, hFont1
      CONTROL SET FONT      hDlg, %LBL_Description, hFont1
      CONTROL SET FONT      hDlg, %CMB_MixModeSel, hFont2
     
      DIALOG SHOW MODAL hDlg, CALL Dialog1Proc
    END FUNCTION
    '------------------/Dialog1
     
    Sub Load_ComboBox (hWnd As Dword, CtlID As long)
     Local n As Long
      For n = 1 To Datacount
        Combobox Add hWnd, CtlID, Read$(n)
      Next
     
      DATA "  1  %mix_Blackness "
      DATA "  2  %mix_NotMergeSrc "
      DATA "  3  %mix_MaskNotSrc "
      DATA "  4  %mix_NotCopySrc "
      DATA "  5  %mix_MaskSrcNot "
      DATA "  6  %mix_Not "
      DATA "  7  %mix_XorSrc "
      DATA "  8  %mix_NotMaskSrc "
      DATA "  9  %mix_MaskSrc  "
      DATA " 10  %mix_NotXorSrc "
      DATA " 11  %mix_Nop "
      DATA " 12  %mix_MergeNotSrc "
      DATA " 13  %mix_CopySrc (def) "
      DATA " 14  %mix_MergeSrcNot "
      DATA " 15  %mix_MergeSrc "
      DATA " 16  %mix_Whiteness "
      DATA " 17  Average Colours"
    End Sub
    '------------------/Load_ComboBox
     
    Sub Load_Label (hWnd As Dword, CtlID As Long, Index As Long)
     
      Control Set Text hWnd, CtlID, ""
      Control Set Text hWnd, CtlID, Read$(Index)
     
      Data "Pixel is always 0 (black)."
      Data "Pixel is the inverse of the MergeSrc color."
      Data "Pixel is a combination of the colors common to both the pixel and the inverse of the source."
      Data "Pixel is the inverse of the pen color."
      Data "Pixel is a combination of the colors common to both the source and the inverse of the pixel."
      Data "Pixel is the inverse of the pixel color."
      Data "Pixel is a combination of the colors in the source and in the pixel, but not in both."
      Data "Pixel is the inverse of the MaskSrc color."
      Data "Pixel is a combination of the colors common to both the source and the pixel."
      Data "Pixel is the inverse of the XorSrc color."
      Data "Pixel remains unchanged."
      Data "Pixel is a combination of the source color and the inverse of the pixel color."
      Data "Pixel is the source color (default)."
      Data "Pixel is a combination of the source color and the inverse of the pixel color."
      Data "Pixel is a combination of the source color and the pixel color."
      Data "Pixel is always 1 (white)."
      Data "Result of Mix is average of combined colors. ('Custom' mix, not built-in TT Chis Boss)"
    End Sub
    '------------------/Load_Label
     
    SUB Pick_Color (ByVal hWnd As Dword, ColorRes AS DWORD)
      Dim cc As CHOOSECOLORAPI
      Dim cr (1 To 16) As RGBQUAD
     
      cc.lStructSize = SizeOf (CHOOSECOLORAPI)
      cc.flags = %CC_SOLIDCOLOR Or %CC_FULLOPEN Or %CC_RGBINIT
      cc.hwndowner = hWnd
      cc.lpcustcolors = VarPtr(cr())
      cc.rgbResult = ColorRes
      ChooseColor (cc)
     
     ColorRes = cc.rgbResult
    End Sub
    '------------------/ColorPick
     
    Sub Paint_Samples (hWnd As Dword, Color1 As Dword, Color2 As Dword, Mix_Mode As Long)
     LOCAL B1 AS BYTE PTR, B2 AS BYTE PTR, B3 As BYTE PTR, Color3 As Long
     
      Graphic Attach hWnd, %GFX_Color1 : Graphic Clear Color1
      Graphic Attach hWnd, %GFX_Color2 : Graphic Clear Color2
        Select Case Mix_Mode
          Case 1 to 16
            Graphic Attach hWnd, %GFX_MixRes : Graphic Clear Color1
            Graphic Set Mix Mix_Mode
            Graphic Paint (0,0), Color2
          Case 17          ' Average colours as per CB
            B1=VARPTR(Color1)
            B2=VARPTR(Color2)
            B3=Varptr(Color3)
            @B3=(@[email protected])/2
            INCR B1
            INCR B2
            INCR B3
            @B3=(@[email protected])/2
            INCR B1
            INCR B2
            INCR B3
            @B3=(@[email protected])/2
            Graphic Attach hWnd, %GFX_MixRes : Graphic Set Mix 13
            Graphic Paint (0,0), Color3
        End Select
     
      Graphic Get Pixel (10,10) To Color3
      Control Set Text hWnd, %LBL_MixRes, Hex$(Color3, 6)
     
    End Sub
    '------------------/Paint_Samples
     
    Sub Paint_Main (hWnd As dword, hBmp As Dword, Color1 As Dword, Color2 As Dword, Mix_Mode As Long)
     
      Graphic Attach hWnd, %GFX_GRAPHIC1
      Graphic Set Mix Mix_Mode
      Graphic Copy hBmp, 0 
      Graphic Box (49,49)-(149,149), 10, %LTGRAY, Color1
      Graphic Box (99,99)-(199,199), 10, %LTGRAY, Color2
     
    End Sub
    '------------------/Paint_Main
    Rgds, Dave

  • #2
    Color mix test dialog MkII

    Some embelishments to the test dialog..
    Click on Pixel or Source samples to bring up color pick dialog.
    Option buttons for setting render mode of sample boxes in main graphic - Copy (solid) or Mix (Mixed with background)

    Also now render two non built-in Mix Modes. Alphablend (50%) and Addative (?) routines sugested by Chris Boss and Paul Dixon in the original thread. These last two mix_Modes are pretty slow to render in the graphic control
    Code:
    ' Test dialog to explore the different Color Mix Modes available for Graphic targets in PB
    ' See discussion at [URL]http://www.powerbasic.com/support/pbforums/showthread.php?t=40680[/URL]
    '
    '#DEBUG DISPLAY ON
    #DIM ALL
    #REGISTER NONE
    #COMPILE EXE
     
    #INCLUDE "WIN32API.INC"
    #INCLUDE "COMDLG32.INC"
     
    %GFX_GRAPHIC1    = 1001
    %GFX_Color1      = 1002
    %GFX_Color2      = 1003
    %GFX_MixRes      = 1004
    %LBL_Color1      = 1012
    %LBL_Color2      = 1013
    %LBL_MixRes      = 1014
    %CMB_MixModeSel  = 1016
    %LBL_Intro       = 1018
    %LBL_Description = 1021
    %OPT_1_Copy      = 1022
    %OPT_1_Mix       = 1023
    %OPT_2_Copy      = 1024
    %OPT_2_Mix       = 1025
    %LBL_Col_Inv     = 1026
    %LBL_Result      = 1027
    '------------------/
     
    FUNCTION PBMAIN()
      Dialog1 0
    END FUNCTION
    '------------------/PbMain
     
    CALLBACK FUNCTION Dialog1Proc()
     STATIC hBmp AS DWORD
     LOCAL n AS LONG
     STATIC Color1, Color2 AS DWORD
     STATIC Mix_Mode AS LONG
     
      SELECT CASE AS LONG CBMSG
        CASE %WM_INITDIALOG
          Color1 = %WHITE : Color2 = %BLACK
          CONTROL SET OPTION CBHNDL, %OPT_1_Copy, %OPT_1_Copy, %OPT_1_Mix
          CONTROL SET OPTION CBHNDL, %OPT_2_Mix, %OPT_2_Copy, %OPT_2_Mix
          Mix_Mode = %MIX_COPYSRC                               ' initial mix_mode
          Paint_Samples CBHNDL, Color1, Color2, Mix_Mode
     
          Load_Combobox CBHNDL, %CMB_MixModeSel
          COMBOBOX SELECT CBHNDL, %CMB_MixModeSel, 13           '
          Load_Label CBHNDL, %LBL_Description, 13               '
     
          GRAPHIC BITMAP NEW 248, 248 TO hBmp     ' Create bitmap for background
          GRAPHIC ATTACH hBmp, 0
          GRAPHIC CLEAR %BLACK
          GRAPHIC WIDTH 10
          FOR n = 46 TO 246 STEP 50
            GRAPHIC LINE (n,1) - (1,n), %WHITE
            GRAPHIC LINE (250,n)- (n,250), %WHITE
          NEXT
     
          Paint_GFX CBHNDL, hBmp, Color1, Color2, Mix_Mode
          CONTROL SET FOCUS CBHNDL, %CMB_MixModeSel
     
        CASE %WM_NCACTIVATE
          STATIC hWndSaveFocus AS DWORD
          IF ISFALSE CBWPARAM  THEN
            hWndSaveFocus = GetFocus()
          ELSEIF hWndSaveFocus THEN
            SetFocus(hWndSaveFocus)
            hWndSaveFocus = 0
          END IF
     
        CASE %WM_COMMAND
          SELECT CASE AS LONG CBCTL
            CASE %GFX_GRAPHIC1
     
            CASE %GFX_Color1
              IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                Pick_Color CBHNDL, Color1
                CONTROL SET TEXT CBHNDL, %LBL_Color1, HEX$(Color1,6) + "  /  " + HEX$(Inverse(Color1), 6)
                Paint_Samples CBHNDL, Color1, Color2, Mix_Mode
                Paint_GFX CBHNDL, hBmp, Color1, Color2, Mix_Mode
                CLIPBOARD RESET
                CLIPBOARD SET TEXT HEX$(Color1,6)
                CONTROL SET FOCUS CBHNDL, %CMB_MixModeSel
              END IF
     
            CASE %OPT_1_Copy, %OPT_1_Mix, %OPT_2_Copy, %OPT_2_Mix
              IF CBCTLMSG = %BN_CLICKED THEN
                COMBOBOX GET SELECT CBHNDL, %CMB_MixModeSel TO n
                Mix_Mode = n
                Paint_GFX CBHNDL, hBmp, Color1, Color2, Mix_Mode
                CONTROL SET FOCUS CBHNDL, %CMB_MixModeSel
              END IF
     
            CASE %GFX_Color2
              IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                Pick_Color CBHNDL, Color2
                CONTROL SET TEXT CBHNDL, %LBL_Color2, HEX$(Color2,6) + "  /  " + HEX$(Inverse(Color2), 6)
                Paint_Samples CBHNDL, Color1, Color2, Mix_Mode
                Paint_GFX CBHNDL, hBmp, Color1, Color2, Mix_Mode
                CLIPBOARD RESET
                CLIPBOARD SET TEXT HEX$(Color2,6)
                CONTROL SET FOCUS CBHNDL, %CMB_MixModeSel
              END IF
     
            CASE %OPT_1_Copy, %OPT_1_Mix
     
            CASE %GFX_MixRes
                CLIPBOARD RESET
                CLIPBOARD SET TEXT HEX$(Color2,6)
     
            CASE %CMB_MixModeSel
              IF CBCTLMSG = %CBN_SELCHANGE THEN
                COMBOBOX GET SELECT CBHNDL, %CMB_MixModeSel TO n
                Load_Label CBHNDL, %LBL_Description, n
                Mix_Mode = n
                Paint_Samples CBHNDL, Color1, Color2, Mix_Mode
                Paint_GFX CBHNDL, hBmp, Color1, Color2, Mix_Mode
              END IF
     
          END SELECT
        CASE %WM_DESTROY
     
      END SELECT
    END FUNCTION
    '------------------/DlgProc
     
    FUNCTION Dialog1(BYVAL hParent AS DWORD) AS LONG
     LOCAL hDlg, hFont1, hFont2 AS DWORD
     LOCAL sTemp AS STRING
     FONT NEW "ARIAL", 12 TO hFont1
     FONT NEW "COURIER NEW", 10 TO hFont2
     
     DIALOG NEW PIXELS, hParent, "Mix test. MkII", 200, 200, 600, 500,  %WS_CAPTION OR %WS_SYSMENU TO hDlg
      CONTROL ADD GRAPHIC,  hDlg, %GFX_GRAPHIC1, "", 30, 16, 250, 250, %WS_CHILD OR %WS_VISIBLE OR %WS_BORDER
      CONTROL ADD LABEL,    hDlg, %LBL_Col_Inv, "     Color              Inverse", 165, 270, 150, 18
      CONTROL ADD OPTION,   hDlg, %OPT_2_Copy, "Copy", 22, 333, 46, 16, %WS_CHILD OR %WS_VISIBLE OR _
        %WS_TABSTOP OR %BS_TEXT OR %BS_AUTORADIOBUTTON OR %BS_LEFTTEXT OR %BS_RIGHT OR %BS_VCENTER OR %WS_GROUP
      CONTROL ADD OPTION,   hDlg, %OPT_2_Mix, "Mix", 22, 349, 46, 17, %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP _
        OR %BS_TEXT OR %BS_AUTORADIOBUTTON OR %BS_LEFTTEXT OR %BS_RIGHT OR %BS_VCENTER, %WS_EX_LEFT OR _
        %WS_EX_LTRREADING
      CONTROL ADD GRAPHIC,  hDlg, %GFX_Color2, "", 75, 333, 79, 29, %WS_CHILD OR %WS_VISIBLE OR %WS_BORDER OR _
        %SS_SUNKEN OR %SS_NOTIFY OR %WS_GROUP
      CONTROL ADD LABEL,    hDlg, %LBL_Color2, "Source", 165, 341, 150, 20
      CONTROL ADD GRAPHIC,  hDlg, %GFX_MixRes, "", 75, 382, 79, 31, %WS_CHILD OR %WS_VISIBLE OR %WS_BORDER OR _
        %SS_SUNKEN OR %SS_NOTIFY
      CONTROL ADD LABEL,    hDlg, %LBL_MixRes, "Result of Mix", 168, 388, 147, 20
      sTemp = "There are 16 built-in mix modes available to use for mixing the drawing color with the color that already " + _
              "exists at the drawing location."
      CONTROL ADD LABEL,    hDlg, %LBL_Intro, sTemp, 330, 10, 230, 75
      CONTROL ADD COMBOBOX, hDlg, %CMB_MixModeSel, , 330, 90, 215, 335, %WS_CHILD OR %WS_VISIBLE OR _
        %WS_TABSTOP OR %CBS_SIMPLE, %WS_EX_LEFT OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR
      CONTROL ADD LABEL,    hDlg, %LBL_Description, "MixMode Description", 90, 431, 382, 48
      CONTROL ADD OPTION,   hDlg, %OPT_1_Copy, "Copy", 22, 284, 46, 17, %WS_CHILD OR %WS_VISIBLE OR _
        %WS_TABSTOP OR %BS_TEXT OR %BS_AUTORADIOBUTTON OR %BS_LEFTTEXT OR %BS_RIGHT OR %BS_VCENTER OR %WS_GROUP
      CONTROL ADD OPTION,   hDlg, %OPT_1_Mix, "Mix", 22, 301, 46, 16, %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP _
        OR %BS_TEXT OR %BS_AUTORADIOBUTTON OR %BS_LEFTTEXT OR %BS_RIGHT OR %BS_VCENTER, %WS_EX_LEFT OR _
        %WS_EX_LTRREADING
      CONTROL ADD GRAPHIC,  hDlg, %GFX_Color1, "", 75, 284, 79, 30, %WS_CHILD OR %WS_VISIBLE OR %WS_BORDER OR _
        %SS_SUNKEN OR %SS_NOTIFY OR %WS_GROUP
      CONTROL ADD LABEL,    hDlg, %LBL_Color1, "Pixel", 165, 292, 150, 20
      CONTROL ADD LABEL,    hDlg, %LBL_Result, "Mix Result", 34, 384, 30, 24
     
      CONTROL SET FONT      hDlg, %LBL_Color1, hFont1
      CONTROL SET FONT      hDlg, %LBL_Color2, hFont1
      CONTROL SET FONT      hDlg, %LBL_MixRes, hFont1
      CONTROL SET FONT      hDlg, %LBL_Intro, hFont1
      CONTROL SET FONT      hDlg, %LBL_Description, hFont1
      CONTROL SET FONT      hDlg, %CMB_MixModeSel, hFont2
     
      DIALOG SHOW MODAL hDlg, CALL Dialog1Proc
    END FUNCTION
    '------------------/Dialog1
     
    SUB Load_ComboBox (hWnd AS DWORD, CtlID AS LONG)
     LOCAL n AS LONG
      FOR n = 1 TO DATACOUNT
        COMBOBOX ADD hWnd, CtlID, READ$(n)
      NEXT
     
      DATA "  1  %mix_Blackness "
      DATA "  2  %mix_NotMergeSrc "
      DATA "  3  %mix_MaskNotSrc "
      DATA "  4  %mix_NotCopySrc "
      DATA "  5  %mix_MaskSrcNot "
      DATA "  6  %mix_Not "
      DATA "  7  %mix_XorSrc "
      DATA "  8  %mix_NotMaskSrc "
      DATA "  9  %mix_MaskSrc  "
      DATA " 10  %mix_NotXorSrc "
      DATA " 11  %mix_Nop "
      DATA " 12  %mix_MergeNotSrc "
      DATA " 13  %mix_CopySrc (def) "
      DATA " 14  %mix_MergeSrcNot "
      DATA " 15  %mix_MergeSrc "
      DATA " 16  %mix_Whiteness "
      DATA " 17  Alpha Blend (50)"
      DATA " 18  Add"
    END SUB
    '------------------/Load_ComboBox
     
    SUB Load_Label (hWnd AS DWORD, CtlID AS LONG, Index AS LONG)
     
      CONTROL SET TEXT hWnd, CtlID, ""
      CONTROL SET TEXT hWnd, CtlID, READ$(Index)
     
      DATA "Blackness. - Pixel is always 0 (black)."
      DATA "NotMergeSrc. - Pixel is the inverse of the MergeSrc color."
      DATA "MaskNotSrc. - Pixel is a combination of the colors common to both the pixel and the inverse of the source."
      DATA "NotCopySrc. - Pixel is the inverse of the pen color."
      DATA "MaskSrcNot. - Pixel is a combination of the colors common to both the source and the inverse of the pixel."
      DATA "Not. - Pixel is the inverse of the pixel color."
      DATA "XorSrc. - Pixel is a combination of the colors in the source and in the pixel, but not in both."
      DATA "NotMaskSrc. - Pixel is the inverse of the MaskSrc color."
      DATA "MaskSrc. - Pixel is a combination of the colors common to both the source and the pixel."
      DATA "NotXorSrc. - Pixel is the inverse of the XorSrc color."
      DATA "Nop. - Pixel remains unchanged."
      DATA "MergeNotSrc. - Pixel is a combination of the source color and the inverse of the pixel color."
      DATA "CopySrc. - Pixel is the source color (default)."
      DATA "MergeSrcNot. - Pixel is a combination of the source color and the inverse of the pixel color."
      DATA "MergeSrc. - Pixel is a combination of the source color and the pixel color."
      DATA "Whiteness. - Pixel is always 1 (white)."
        ' TT Chis Boss
      DATA "Alphablend (50). - Pixel is a combination of the source color * 50% and the pixel color * 50%  (Not built-in)."
       ' TT Paul Dixon
      DATA "Add. - Pixel is the addition of the source color and the pixel color (Not built-in)."
    END SUB
    '------------------/Load_Label
     
    SUB Pick_Color (BYVAL hWnd AS DWORD, ColorRes AS DWORD)
      DIM cc AS CHOOSECOLORAPI
      DIM cr (1 TO 16) AS RGBQUAD
     
      cc.lStructSize = SIZEOF (CHOOSECOLORAPI)
      cc.flags = %CC_SOLIDCOLOR OR %CC_FULLOPEN OR %CC_RGBINIT
      cc.hwndowner = hWnd
      cc.lpcustcolors = VARPTR(cr())
      cc.rgbResult = ColorRes
      ChooseColor (cc)
     
     ColorRes = cc.rgbResult
    END SUB
    '------------------/ColorPick
     
    FUNCTION Inverse(hColor AS LONG) AS LONG
     LOCAL r,g,b AS BYTE
     
      r=255-GetRValue(hColor)
      g=255-GetGValue(hColor)
      b=255-GetBValue(hColor)
     
     FUNCTION = RGB(r,g,b)
    END FUNCTION
    '------------------/Inverse
     
    FUNCTION MixRGB (Color1 AS DWORD, Color2 AS DWORD) AS DWORD
     LOCAL r1, r2, g1, g2, b1, b2 AS BYTE
      ' extract the red, green and blue components of each colour
      r1 = GetRValue(Color1)/2 : r2 = GetRValue(Color2)/2
      g1 = GetGValue(Color1)/2 : g2 = GetGValue(Color2)/2
      b1 = GetBValue(Color1)/2 : b2 = GetBValue(Color2)/2
     
     FUNCTION = RGB(r1+r2, g1+g2, b1+b2)
    END FUNCTION
    '------------------/MixRGB
     
    FUNCTION MixColors (Color1 AS DWORD, Color2 AS DWORD) AS DWORD
     LOCAL r1, r2, g1, g2, b1, b2 AS BYTE
      ' extract the red, green and blue components of each colour
      r1 = GetRValue(Color1) : r2 = GetRValue(Color2)
      g1 = GetGValue(Color1) : g2 = GetGValue(Color2)
      b1 = GetBValue(Color1) : b2 = GetBValue(Color2)
      ' add the individual components together but don't allow it to exceed 1 byte.
      ' if the sum is greater than the mask then return the mask instead as it represents the fullest value of that colour
     
     FUNCTION = RGB(MIN (r1 + r2, 255), MIN (g1 + g2, 255), MIN (b1  + b2, 255))
    END FUNCTION
    '------------------/MixColors
     
    SUB Paint_Samples (hWnd AS DWORD, Color1 AS DWORD, Color2 AS DWORD, Mix_Mode AS LONG)
     LOCAL Color3 AS DWORD
     
      GRAPHIC ATTACH hWnd, %GFX_Color1 : GRAPHIC CLEAR Color1
      GRAPHIC ATTACH hWnd, %GFX_Color2 : GRAPHIC CLEAR Color2
        SELECT CASE Mix_Mode
          CASE 1 TO 16
            GRAPHIC ATTACH hWnd, %GFX_MixRes : GRAPHIC CLEAR Color1
            GRAPHIC SET MIX Mix_Mode
            GRAPHIC PAINT (0,0), Color2
     
          CASE 17          ' Average colours as per CB (AKA Alphablend 50)
            Color3 = MixRGB (Color1, Color2)
            GRAPHIC ATTACH hWnd, %GFX_MixRes : GRAPHIC SET MIX %MIX_COPYSRC
            GRAPHIC PAINT (0,0), Color3
     
          CASE 18          ' Add colors as per PD (similar to %mix_MergeSrc until saturation..
            ' extract the red, green and blue components of each colour
            Color3 = MixColors (Color1, Color2)
            GRAPHIC ATTACH hWnd, %GFX_MixRes : GRAPHIC SET MIX %MIX_COPYSRC
            GRAPHIC PAINT (0,0), Color3
        END SELECT
     
      GRAPHIC GET PIXEL (10,10) TO Color3
      CONTROL SET TEXT hWnd, %LBL_MixRes, HEX$(Color3, 6)
     
    END SUB
    '------------------/Paint_Samples
     
    SUB Paint_GFX (hWnd AS DWORD, hBmp AS DWORD, Color1 AS DWORD, Color2 AS DWORD, Mix_Mode AS LONG)
     REGISTER x AS LONG
     REGISTER y AS LONG
     LOCAL Opt_Mode1, Opt_Mode2 AS LONG
     LOCAL Pixl AS DWORD
     
      GRAPHIC ATTACH hWnd, %GFX_GRAPHIC1
      GRAPHIC COPY hBmp, 0
     
      CONTROL GET CHECK hWnd, %OPT_1_Copy TO Opt_Mode1
      CONTROL GET CHECK hWnd, %OPT_2_Copy TO Opt_Mode2
     
      IF Mix_Mode = 17 THEN
        GRAPHIC SET MIX %MIX_COPYSRC
        FOR x = 49 TO 149
          FOR y = 49 TO 149
            GRAPHIC GET PIXEL (x, y) TO Pixl
            IF Opt_Mode1 THEN
              GRAPHIC SET PIXEL (x, y), MixRGB(Color1, Color1)
            ELSE
              GRAPHIC SET PIXEL (x, y), MixRGB(Pixl, Color1)
            END IF
          NEXT
        NEXT
        FOR x = 99 TO 199
          FOR y = 99 TO 199
            GRAPHIC GET PIXEL (x, y) TO Pixl
            IF Opt_Mode2 THEN
              GRAPHIC SET PIXEL (x, y), MixRGB(Color2, Color2)
            ELSE
              GRAPHIC SET PIXEL (x, y), MixRGB(Pixl, Color2)
            END IF
          NEXT
        NEXT
       EXIT SUB
      END IF
     
      IF Mix_Mode = 18 THEN
        GRAPHIC SET MIX %MIX_COPYSRC
        FOR x = 49 TO 149
          FOR y = 49 TO 149
            GRAPHIC GET PIXEL (x, y) TO Pixl
            IF Opt_Mode1 THEN
              GRAPHIC SET PIXEL (x, y), MixColors(%Black, Color1)
            ELSE
              GRAPHIC SET PIXEL (x, y), MixColors(Pixl, Color1)
            END IF
          NEXT
        NEXT
        FOR x = 99 TO 199
          FOR y = 99 TO 199
            GRAPHIC GET PIXEL (x, y) TO Pixl
            IF Opt_Mode2 THEN
              GRAPHIC SET PIXEL (x, y), MixColors(%Black, Color2)
            ELSE
              GRAPHIC SET PIXEL (x, y), MixColors(Pixl, Color2)
            END IF
          NEXT
        NEXT
       EXIT SUB
      END IF
     
      GRAPHIC SET MIX IIF(Opt_Mode1, %MIX_COPYSRC, Mix_Mode)
      GRAPHIC BOX (49,49)-(149,149), 0, %LTGRAY, Color1
     
      GRAPHIC SET MIX IIF(Opt_Mode2, %MIX_COPYSRC, Mix_Mode)
      GRAPHIC BOX (99,99)-(199,199), 0, %LTGRAY, Color2
     
    END SUB
    '------------------/Paint_GFX
    Last edited by Dave Biggs; 12 Jun 2009, 11:28 AM. Reason: Correction
    Rgds, Dave

    Comment

    Working...
    X