RGB Farbcode über HSL Farbcode verändern (Sättigung & Helligkeit)

  • Hi com,

    leider stellte sich heraus, dass ich mit Farben nicht rechnen kann. Daher wollte ich mir von einer Funktion helfen lassen, um Sättigung und Helligkeit etwas zu bearbeiten.
    Paint.Net hat es vorgemacht, aber AutoIt...
    Aus irgendeinem Grund kann man den RGB-Farbcode nicht einfach in einen HSL-Farbcode konvertieren, ein paar Werte verändern und dann wieder zurückkonvertieren.
    Frage also: Wie geht das (richtig)?

    Ich hab hier einen kleinen Testcode, da kann man jeweils ein Attribut ändern und das meistens perfekt!
    Wenn man allerdings zwei Werte gleichzeitig ändern will, scheitert es. Dasselbe beim Ändern nacheinander. (Ohne Z. 45ff ist das ganze Farbenroulette)

    Spoiler anzeigen
    [autoit]

    #include <Color.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Global $iMode = 0, $aHSL[3] = ["H","S","L"]

    [/autoit] [autoit][/autoit] [autoit]

    $hWnd = GUICreate("Farbtest", 200, 200)
    $hLabel = GUICtrlCreateLabel("", 100, 0, 100, 200)
    $hInput1 = GUICtrlCreateInput("", 0, 0, 100, 50)
    $hInput2 = GUICtrlCreateInput("", 0, 50, 100, 50)
    $hInput3 = GUICtrlCreateInput("0", 0, 125, 100, 25)
    $hButton = GUICtrlCreateButton("H um 0 verändern", 0, 150, 100, 50)
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    Sleep(20)
    Switch GUIGetMsg()
    Case -3
    Exit
    Case $hButton
    $iMode += 1
    If $iMode = 3 Then $iMode = 0
    EndSwitch
    GUICtrlSetData($hButton, $aHSL[$iMode] & " um " & GUICtrlRead($hInput3) & " verändern.")
    $sFarbcode = GUICtrlRead($hInput1)
    $sFarbcode = _ColorRGBChangeHSL($sFarbcode, $aHSL[$iMode], Int(GUICtrlRead($hInput3)))
    GUICtrlSetData($hInput2, $sFarbcode)
    GUICtrlSetBkColor($hLabel, $sFarbcode)
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _ColorRGBChangeHSL($i_Color, $s_Opt, $i_Int)
    Local $a_Colors = _ColorGetRGB($i_Color)
    ;~ ConsoleWrite($a_Colors[0] & "|" & $a_Colors[1] & "|" & $a_Colors[2] & @CRLF)
    $a_Colors = _ColorConvertRGBtoHSL($a_Colors) ; $H 240, $S 240, $L 120
    ;~ ConsoleWrite(($a_Colors[0] * 1.5) & "|" & ($a_Colors[1] / 2.4) & "|" & ($a_Colors[2] / 1.2) & @CRLF)
    Switch $s_Opt
    Case "H"
    $a_Colors[0] = (($a_Colors[0] * 1.5) + $i_Int) / 1.5
    Case "S"
    $a_Colors[1] = (($a_Colors[1] / 2.4) + $i_Int) * 2.4
    Case "L"
    $a_Colors[2] = (($a_Colors[2] / 1.2) + $i_Int) * 1.2
    EndSwitch
    ;~ ConsoleWrite(($a_Colors[0] * 1.5) & "|" & ($a_Colors[1] / 2.4) & "|" & ($a_Colors[2] / 1.2) & @CRLF)
    $a_Colors = _ColorConvertHSLtoRGB($a_Colors)
    ;~ ConsoleWrite($a_Colors[0] & "|" & $a_Colors[1] & "|" & $a_Colors[2] & @CRLF)
    If True Then ; Nimmt man das hier Weg, dann kommt nie die vorherige Farbe raus, sollte man nichts verändern, vermutlich wird nicht gerundet (Änderungen von 0.000...001)
    $a_Colors[0] = Round($a_Colors[0])
    $a_Colors[1] = Round($a_Colors[1])
    $a_Colors[2] = Round($a_Colors[2])
    EndIf
    Return "0x" & Hex($a_Colors[0], 2) & Hex($a_Colors[1], 2) & Hex($a_Colors[2], 2)
    EndFunc

    [/autoit]


    Weiß jemand, warum das ganze nicht funktionieren will oder hat sogar eine Lösung dafür?