#include <GDIP.au3>
#include <GUIConstants.au3>

; Извлекает путь к AutoIt
Local $Wow64
If @AutoItX64 Then $Wow64 = "\Wow6432Node"
Local $AutoItDir = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE" & $Wow64 & "\AutoIt v3\AutoIt", "InstallDir")

_GDIPlus_Startup()

$hGUI = GUICreate("Матрица насыщенности цвета", 380, 300)

$hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI)
$hImage = _GDIPlus_ImageLoadFromFile($AutoItDir & '\Examples\GUI\msoobe.jpg')

Local $tMatrix = _GDIPlus_ColorMatrixCreate()
;Local $tMatrix = _GDIPlus_ColorMatrixCreateNegative()
Local $pColorMatrix = DllStructGetPtr($tMatrix)

; Матрица яркости цвета
Local $brightness = _GDIPlus_ColorMatrixCreateBrightness(0.8)
_GDIPlus_ColorMatrixMultiply($tMatrix, $brightness)

; Матрица контрастности цвета
Local $contrast = _GDIPlus_ColorMatrixCreateContrast(2.5)
_GDIPlus_ColorMatrixMultiply($tMatrix, $contrast)

; Матрица насыщенности цвета
Local $saturation = _GDIPlus_ColorMatrixCreateSaturation(0.5)
_GDIPlus_ColorMatrixMultiply($tMatrix, $saturation)

; Создает объект ImageAttributes
$hIA = _GDIPlus_ImageAttributesCreate()
; Устанавливает матрицу цвета
_GDIPlus_ImageAttributesSetColorMatrix($hIA, 0, True, $pColorMatrix)

GUISetState()

; Рисует изображение в указанном прямоугольнике
_GDIPlus_GraphicsDrawImageRectRectIA($hGraphics, $hImage, 0, 0, 1024, 768, 0, 0, 380, 300, $hIA)

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

_GDIPlus_ImageAttributesDispose($hIA)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_GraphicsDispose($hGraphics)

_GDIPlus_Shutdown()


; #FUNCTION# ====================================================================================================================
; Name...........: _GDIPlus_ColorMatrixCreateBrightness
; Description ...: Creates and initializes a brightness color matrix
; Syntax.........: _GDIPlus_ColorMatrixCreateBrightness($nBri)
; Parameters ....: $nCon - Color brightness factor
; Return values .: Success - $tagGDIPCOLORMATRIX structure that contains a brightness color matrix
; Failure - 0
; Related .......: $tagGDIPCOLORMATRIX
; Author ........: Daniel Jaeger - http://nerdworld.de
; Example .......; No
; ===============================================================================================================================

Func _GDIPlus_ColorMatrixCreateBrightness($nBri)

    Local $tCM = DllStructCreate($tagGDIPCOLORMATRIX)

    DllStructSetData($tCM, "m", 1, 1)
    DllStructSetData($tCM, "m", 1, 7)
    DllStructSetData($tCM, "m", 1, 13)
    DllStructSetData($tCM, "m", 1, 19)

    DllStructSetData($tCM, "m", $nBri-1, 21)
    DllStructSetData($tCM, "m", $nBri-1, 22)
    DllStructSetData($tCM, "m", $nBri-1, 23)

    DllStructSetData($tCM, "m", 1, 25)

    Return $tCM
EndFunc

; #FUNCTION# ====================================================================================================================
; Name...........: _GDIPlus_ColorMatrixCreateContrast
; Description ...: Creates and initializes a contrast color matrix
; Syntax.........: _GDIPlus_ColorMatrixCreateContrast($nCon)
; Parameters ....: $nCon - Color contrast factor
; Return values .: Success      - $tagGDIPCOLORMATRIX structure that contains a contrast color matrix
;                  Failure      - 0
; Related .......: $tagGDIPCOLORMATRIX
; Author ........: Daniel Jaeger - http://nerdworld.de
; Example .......; No
; ===============================================================================================================================
Func _GDIPlus_ColorMatrixCreateContrast($nCon)

    Local $tCM = DllStructCreate($tagGDIPCOLORMATRIX), $nT = (1 - $nCon) / 2

    DllStructSetData($tCM, "m", $nCon, 1)
    DllStructSetData($tCM, "m", $nCon, 7)
    DllStructSetData($tCM, "m", $nCon, 13)

    DllStructSetData($tCM, "m", 1, 19)

    DllStructSetData($tCM, "m", $nT, 21)
    DllStructSetData($tCM, "m", $nT, 22)
    DllStructSetData($tCM, "m", $nT, 23)

    DllStructSetData($tCM, "m", 1, 25)

    Return $tCM
EndFunc