Jump to content

Please help with ColorMatrix and GdipDrawImage


Edano
 Share

Recommended Posts

wow, gdiplus is so difficult ! this is what i got so far in my Image Editing project (a little bit chaotic, yes i know) :

.

#include <GDIPlus.au3>
#include <SliderConstants.au3>

Opt("GUIOnEventMode",1)

Global Const $SRCCOPY=0xCC0020
Global Const $SB_ENDSCROLL=8
Global Const $SB_THUMBPOSITION=4
Global Const $GDIP_BRIGHTNESSCONTRASTEFFECT="{D3A1DBE1-8EC4-4c17-9F4C-EA97AD1C343D}"
Global Const $GDIP_BLUREFFECT="{633C80A4-1843-482b-9EF2-BE2834C5FDD4}"
Global Const $GDIP_SHARPENEFFECT="{63CBF3EE-C526-402c-8F71-62C540BF5142}"
;Global Const $tagBRIGHTNESSCONTRASTPARAMS="int brightnessLevel;int contrastLevel" ;-255-255; -100-100
;Global Const $tagBLURPARAMS="float radius;bool expandEdge" ;0-255; False/True
;Global Const $tagSHARPENPARAMS="float radius;float amount" ;0-255; 0-100
Global Const $tagGDIPCOLORMATRIX = "float m[25];" ; [5][5] matrix; [0][0] - red, [1][1] - green, [2][2] - blue; [3][3] - alpha, [4][4] - ~should~ be 1
Global $tBrightnessContrast=DllStructCreate("int brightnessLevel;int contrastLevel") ;-255-255; -100-100
Global $tSharpen=DllStructCreate("float radius;float amount") ;0-255; 0-100
Global $tBlur=DllStructCreate("float radius;bool expandEdge") ;0-255; False/True

Global $hDLL_GDI32=DllOpen("gdi32.dll")

Global $tRECTF=DllStructCreate($tagGDIPRECTF)
DllStructSetData($tRECTF,"X",0)
DllStructSetData($tRECTF,"Y",0)

Global $Sliders[5][2]

$Path=FileOpenDialog("Choose an Image  (preferably smaller than your desktop)",@ScriptDir,"Images (*.gif;*.png;*.jpg;*.bmp;*.tif)")
If $Path="" Then Exit

;MsgBox(0,"GDIPlus Version","System: "&FileGetVersion(@SystemDir&"\GDIPlus.dll")&@CRLF&"Local: "&FileGetVersion(@ScriptDir&"\GDIPlus.dll")&@CRLF&"Vista: "&FileGetVersion("C:\Install\TepcoPlotter\gdiplus1.1\Vista\x86_microsoft.windows.gdiplus_6595b64144ccf1df_1.1.6001.22170_none_76fff8857c6d0501\GDIPlus.dll")&@CRLF&"Win7: "&FileGetVersion("C:\Windows\winsxs\x86_microsoft.windows.gdiplus_6595b64144ccf1df_1.1.6001.22170_none_76fff8857c6d0501\GDIPlus.dll"))

$RFB_Child=GUICreate("",100,100,85,85,0x80800000);BitOR($WS_BORDER,$WS_POPUP))
$RFB_Pic=GUICtrlCreatePic("",0,0,100,100)
GUICtrlSetResizing(-1,102)
GUICtrlSetCursor(-1,0)
$RFB_Handle=GUICtrlGetHandle($RFB_Pic)

__GDIPlus_Startup()

$hImage=_GDIPlus_ImageLoadFromFile($Path)
;$hImage=_GDIPlus_ImageLoadFromFile("ebh1.tif")
$iw=_GDIPlus_ImageGetWidth($hImage)
$ih=_GDIPlus_ImageGetHeight($hImage)

DllStructSetData($tRECTF,"Width",$iW);das änderbar
DllStructSetData($tRECTF,"Height",$iH);das änderbar

WinMove($RFB_Child,"",(@DesktopWidth-$iw)/2,(@DesktopHeight-$ih)/2+8,$iw+2,$ih+2)
_Rotate(6)
$O_Image=_GDIPlus_ImageClone($hImage);_GDIPlus_BitmapCloneArea($hImage,0,0,$iw,$ih)

_SetImage()

GUISetOnEvent(-7,"_Drag")
GUISetState()

$RFB_Controls=GUICreate("",100,400,800,100,0x80800000,-1,$RFB_Child)

GUICtrlSetCursor(GUICtrlCreateButton("Turn L",2,2,47,20),0)
GUICtrlSetOnEvent(-1,"_TurnL")
GUICtrlSetCursor(GUICtrlCreateButton("Turn R",52,2,47,20),0)
GUICtrlSetOnEvent(-1,"_TurnR")

GUICtrlSetCursor(GUICtrlCreateButton("Flip H",2,24,47,20),0)
GUICtrlSetOnEvent(-1,"_FlipH")
GUICtrlSetCursor(GUICtrlCreateButton("Flip V",52,24,47,20),0)
GUICtrlSetOnEvent(-1,"_FlipV")

GUICtrlCreateLabel("Brightness",2,46,60,20)
$Sliders[0][0]=GUICtrlCreateSlider(2,66,96,40)
$Sliders[0][1]=GUICtrlGetHandle(-1)
GUICtrlSetLimit(-1,255,-255);-255-255
GUICtrlSetBkColor(-1,-2)
GUICtrlSetCursor(-1,0)

GUICtrlCreateLabel("Contrast",2,108,60,20)
$Sliders[1][0]=GUICtrlCreateSlider(2,128,96,40)
$Sliders[1][1]=GUICtrlGetHandle(-1)
GUICtrlSetLimit(-1,100,-100); -100-100
GUICtrlSetBkColor(-1,-2)
GUICtrlSetCursor(-1,0)

GUICtrlCreateLabel("Sharpness Amount",2,170,90,20)
$Sliders[3][0]=GUICtrlCreateSlider(2,190,96,40)
$Sliders[3][1]=GUICtrlGetHandle(-1)
GUICtrlSetLimit(-1,100); 0-100
GUICtrlSetBkColor(-1,-2)
GUICtrlSetCursor(-1,0)

GUICtrlCreateLabel("Sharpness Radius",2,232,90,20)
$Sliders[2][0]=GUICtrlCreateSlider(2,252,96,40)
$Sliders[2][1]=GUICtrlGetHandle(-1)
GUICtrlSetLimit(-1,255);0-255
GUICtrlSetBkColor(-1,-2)
GUICtrlSetCursor(-1,0)

GUICtrlCreateLabel("Blur Radius",2,294,60,20)
$Sliders[4][0]=GUICtrlCreateSlider(2,314,96,40)
$Sliders[4][1]=GUICtrlGetHandle(-1)
GUICtrlSetLimit(-1,255);0-255; False/True
GUICtrlSetBkColor(-1,-2)
GUICtrlSetCursor(-1,0)


GUICtrlSetCursor(GUICtrlCreateButton("Negativ",2,356,47,20),0)
GUICtrlSetOnEvent(-1,"_Negative")
GUICtrlSetCursor(-1,0)
GUICtrlSetCursor(GUICtrlCreateButton("S/W",52,356,47,20),0)
GUICtrlSetOnEvent(-1,"_SchwarzWeiss")
GUICtrlSetCursor(-1,0)
GUICtrlSetCursor(GUICtrlCreateButton("Restore",2,378,47,20),0)
GUICtrlSetOnEvent(-1,"_RestoreX")
GUICtrlSetCursor(-1,0)
GUICtrlSetCursor(GUICtrlCreateButton("Exit",52,378,47,20),0)
GUICtrlSetOnEvent(-1,"_Exit")
GUICtrlSetCursor(-1,0)

$aResult=DllCall($ghGDIPDll,"uint","GdipCreateBitmapFromScan0","int",$iw,"int",$ih,"int",0,"int",$GDIP_PXF32ARGB,"ptr",0,"int*",0)
$hHBitmap_Preview=_GDIPlus_BitmapCreateHBITMAPFromBitmap($aResult[6])
_GDIPlus_BitmapDispose($aResult[6])
$hDC=_WinAPI_GetWindowDC(GUICtrlGetHandle($RFB_Pic))
$hDC_backbuffer=_WinAPI_CreateCompatibleDC($hDC)
$DC_obj=_WinAPI_SelectObject($hDC_backbuffer,$hHBitmap_Preview)
$hGraphic=_GDIPlus_GraphicsCreateFromHDC($hDC_backbuffer)
_GDIPlus_GraphicsClear($hGraphic,0xFFFFFFFF)

$hIA=_GDIPlus_ImageAttributesCreate()


GUISetOnEvent(-7,"_Drag")

GUIRegisterMsg(276,"WM_HSCROLL");$WM_HSCROLL

GUISetState()


;_Examples()

While Sleep(20)

WEnd


Func _Negative()
    Local $tNegMatrix=_GDIPlus_ColorMatrixCreateNegative()
    _GDIPlus_ImageAttributesSetColorMatrix($hIA,0,True,DllStructGetPtr($tNegMatrix))
    CopyImage2Gfx($hImage,$hGraphic,$hDC,$hDC_backbuffer,$iw,$ih,$hIA)
    _GDIPlus_ImageAttributesSetThreshold($hIA,0,False)

    MsgBox(0,"","Please help to draw the image to the pic control :) ")

EndFunc

Func _SchwarzWeiss() ; genauso wie negativ
    _GDIPlus_ImageAttributesSetThreshold($hIA,0,True,.4);$iThreshold);"Range is from 0 to 1"
    Local $tBWMatrix=_GDIPlus_ColorMatrixCreateGrayScale()
    _GDIPlus_ImageAttributesSetColorMatrix($hIA,0,True,DllStructGetPtr($tBWMatrix))
    CopyImage2Gfx($hImage,$hGraphic,$hDC,$hDC_backbuffer,$iw,$ih,$hIA)
    _GDIPlus_ImageAttributesSetThreshold($hIA,0,False)

    MsgBox(0,"","Please help to draw the image to the pic control :) ")

EndFunc

Func WM_HSCROLL($hWnd, $Msg, $wParam, $lParam)
    If $hWnd=$RFB_Controls Then;oder evtl msg ein ausschalten
        Local $iCode=BitAND($wParam,0xFFFF)
        If $iCode=$SB_ENDSCROLL Or $iCode=$SB_THUMBPOSITION Then Return 0
        ;ich muss ja nicht wissen welcher ausgelöst hat
        ;For $i=0 To UBound($Sliders)-1
        ;   If $lParam=$Sliders[$i][1] Then
        ;       ToolTip(" "&GUICtrlRead($Sliders[$i][0])&" ")
        ;       ExitLoop
        ;   EndIf
        ;Next
        _Restore()
        _Effekt($tBrightnessContrast,$GDIP_BRIGHTNESSCONTRASTEFFECT,GUICtrlRead($Sliders[0][0]),GUICtrlRead($Sliders[1][0]));-255-255; -100-100
        _Effekt($tSharpen,$GDIP_SHARPENEFFECT,GUICtrlRead($Sliders[2][0]),GUICtrlRead($Sliders[3][0]));"Range is from 0 to 255";"Range is from 0 to 100"
        _Effekt($tBlur,$GDIP_BLUREFFECT,GUICtrlRead($Sliders[4][0]));0-255; False/True
        _SetImage()
        ;Beep(300,20)
    EndIf
    Return "GUI_RUNDEFMSG"
EndFunc

Func _Effekt($tEffect,$gEffect,$param1,$param2=False)
    ;alle effekte in eine dll ? geht nicht
    If $param1=0 And $param2=0 Then Return
    DllStructSetData($tEffect,1,$param1)
    DllStructSetData($tEffect,2,$param2)
    Local $pEffect=_GDIPlus_EffectCreate($gEffect)
    _GDIPlus_EffectsSetParameters($pEffect,$tEffect)
    ;   convert
    Local $hClone=_GDIPlus_ImageClone($hImage);_GDIPlus_BitmapCloneArea($hImage,0,0,$iw,$ih)
    Local $hGraphics=_GDIPlus_ImageGetGraphicsContext($hClone)
    _GDIPlus_DrawImageFX($hGraphics,$hImage,$tRECTF,$pEffect)
    DllCall($ghGDIPDll,"uint","GdipDeleteEffect","hwnd",$pEffect)
    DllCall($ghGDIPDll,"int","GdipDeleteGraphics","handle",$hGraphics)
    DllCall($ghGDIPDll,"int","GdipDisposeImage","handle",$hImage)
    $hImage=$hClone
EndFunc

Func _SetImage()
    Local $hBitmap=_GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    _WinAPI_SetWindowLong($RFB_Handle,0xFFFFFFF0,BitOR(_WinAPI_GetWindowLong($RFB_Handle,0xFFFFFFF0),0x0E));$__SS_BITMAP;; $GWL_STYLE)
    _WinAPI_DeleteObject(_SendMessage($RFB_Handle,0x0172,0,$hBitmap));$__STM_SETIMAGE
    _WinAPI_DeleteObject($hBitmap);das global behalten ???
EndFunc

Func _RestoreX()
    _Restore()
    _SetImage()
    For $i=0 To UBound($Sliders)-1
        GUICtrlSetData($Sliders[$i][0],0)
    Next
EndFunc

Func _Restore()
    DllCall($ghGDIPDll,"int","GdipDisposeImage","handle",$hImage)
    $hImage=$O_Image
    $O_Image=_GDIPlus_ImageClone($hImage);_GDIPlus_BitmapCloneArea($hImage,0,0,$iw,$ih)
EndFunc

Func _Zoom($x=1)
    $ret=DllCall($ghGDIPDll,"int","GdipGetImageThumbnail","ptr",$hImage,"int",$iw*$x,"int",$ih*$x,"ptr*",0,"ptr",0,"ptr",0)
    $hImage=$ret[4]
    _SetImage()
EndFunc

;    _GDIPlus_ImageAttributesSetColorMatrix($hIA, 0, True, $pColorMatrix)
;    _GDIPlus_ImageAttributesSetGamma($hIA, 0, True, $nGamma)

Func _GDIPlus_ColorMatrixCreateGrayScale()
    Local $iI, $iJ, $tCM, $aLums[4] = [.333,.333,.333,0];[.31, .61, .08, 0]
    $tCM = DllStructCreate($tagGDIPCOLORMATRIX)
    For $iI = 0 To 3
        For $iJ = 1 To 3
            DllStructSetData($tCM, "m", $aLums[$iI], $iI * 5 + $iJ)
        Next
    Next
    DllStructSetData($tCM, "m", 1, 19)
    DllStructSetData($tCM, "m", 1, 25)
    Return $tCM
EndFunc   ;==>_GDIPlus_ColorMatrixCreateGrayScale

Func _GDIPlus_ColorMatrixCreateNegative()
    Local $iI, $tCM
    $tCM = _GDIPlus_ColorMatrixCreateScale(-1, -1, -1, 1)
    For $iI = 1 To 4
        DllStructSetData($tCM, "m", 1, 20 + $iI)
    Next
    Return $tCM
EndFunc   ;==>_GDIPlus_ColorMatrixCreateNegative

Func _GDIPlus_ColorMatrixCreateScale($nRed, $nGreen, $nBlue, $nAlpha = 1)
    Local $tCM
    $tCM = DllStructCreate($tagGDIPCOLORMATRIX)
    DllStructSetData($tCM, "m", $nRed, 1)
    DllStructSetData($tCM, "m", $nGreen, 7)
    DllStructSetData($tCM, "m", $nBlue, 13)
    DllStructSetData($tCM, "m", $nAlpha, 19)
    DllStructSetData($tCM, "m", 1, 25)
    Return $tCM
EndFunc   ;==>_GDIPlus_ColorMatrixCreateScale

Func _GDIPlus_ImageAttributesSetColorMatrix($hImageAttributes, $iColorAdjustType = 0, $fEnable = False, $pClrMatrix = 0, $pGrayMatrix = 0, $iColorMatrixFlags = 0)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipSetImageAttributesColorMatrix", "handle", $hImageAttributes, "int", $iColorAdjustType, "int", $fEnable, "ptr", $pClrMatrix, "ptr", $pGrayMatrix, "int", $iColorMatrixFlags)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0] = 0
EndFunc   ;==>_GDIPlus_ImageAttributesSetColorMatrix

Func CopyImage2Gfx($hBmp, $hGraphic, $hDC, $hDC_backbuffer, $bW, $bH, $hIA = 0)
    _GDIPlus_GraphicsClear($hGraphic,0xFFFFFFFF)
    If $hIA Then
        _GDIPlus_GraphicsDrawImageRectRectIA($hGraphic,$hBmp,0,0,$iw,$ih,0,0,$iw,$ih,$hIA)
    Else
        _GDIPlus_GraphicsDrawImageRect($hGraphic,$hBmp,0,0,$iw,$ih)
    EndIf
    DllCall($hDLL_GDI32,"bool","BitBlt","handle",$hDC,"int",0,"int",0,"int", $iw,"int",$ih,"handle",$hDC_backbuffer,"int",0,"int",0,"dword",$SRCCOPY)
EndFunc   ;==>CopyImage2Gfx

Func _GDIPlus_GraphicsDrawImageRectRectIA($hGraphics, $hImage, $nSrcX, $nSrcY, $nSrcWidth, $nSrcHeight, $nDstX, $nDstY, $nDstWidth, $nDstHeight, $hImageAttributes = 0, $iUnit = 2)
    Local $aResult = DllCall($ghGDIPDll, "int", "GdipDrawImageRectRect", "handle", $hGraphics, "handle", $hImage, "float", $nDstX, "float", _
            $nDstY, "float", $nDstWidth, "float", $nDstHeight, "float", $nSrcX, "float", $nSrcY, "float", $nSrcWidth, "float", _
            $nSrcHeight, "int", $iUnit, "handle", $hImageAttributes, "int", 0, "int", 0)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0] = 0
EndFunc   ;==>_GDIPlus_GraphicsDrawImageRectRectIA

Func _GDIPlus_ImageAttributesSetThreshold($hImageAttributes, $iColorAdjustType = 0, $fEnable = False, $nThreshold = 0)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipSetImageAttributesThreshold", "handle", $hImageAttributes, "int", $iColorAdjustType, "int", $fEnable, "float", $nThreshold)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0] = 0
EndFunc   ;==>_GDIPlus_ImageAttributesSetThreshold

;   _GDIPlus_ImageAttributesSetGamma($hIA, 0, True, $nGamma)
; #FUNCTION# ====================================================================================================================
; Name...........: _GDIPlus_ImageAttributesSetGamma
; Description ...: Sets or clears the gamma value for a specified category
; Syntax.........: _GDIPlus_ImageAttributesSetGamma($hImageAttributes[, $iColorAdjustType = 0[, $fEnable = False[, $nGamma = 0]]])
; Parameters ....: $hImageAttributes - Pointer to an ImageAttribute object
;                  $iColorAdjustType - The category for which the gamma value is set or cleared:
;                  |0 - Gamma adjustment applies to all categories that do not have adjustment settings of their own
;                  |1 - Gamma adjustment applies to bitmapped images
;                  |2 - Gamma adjustment applies to brush operations in metafiles
;                  |3 - Gamma adjustment applies to pen operations in metafiles
;                  |4 - Gamma adjustment applies to text drawn in metafiles
;                  $fEnable          - If True, gamma correction for the specified category is applied, otherwise cleared
;                  $nGamma           - Real number that specifies the gamma value
; Return values .: Success      - True
;                  Failure      - False and either:
;                  |@error and @extended are set if DllCall failed
;                  |$GDIP_STATUS contains a non zero value specifying the error code
; Remarks .......: Gamma correction controls the overall brightness of an image, typical range is from 1.0  to  2.2;  however,
;                  +values from 0.1 to 5.0 could prove useful under some circumstances
; Related .......: None
; Link ..........; @@MsdnLink@@ GdipSetImageAttributesGamma
; Example .......; No
; ===============================================================================================================================
Func _GDIPlus_ImageAttributesSetGamma($hImageAttributes, $iColorAdjustType = 0, $fEnable = False, $nGamma = 0)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipSetImageAttributesGamma", "hwnd", $hImageAttributes, "int", $iColorAdjustType, "int", $fEnable, "float", $nGamma)

    If @error Then Return SetError(@error, @extended, False)
    $GDIP_STATUS = $aResult[0]
    Return $aResult[0] = 0
EndFunc   ;==>_GDIPlus_ImageAttributesSetGamma

Func _GDIPlus_DrawImageFX($hGraphics, $hBitmap, $tRECTF, $pEffect, $hMatrix = 0, $pImgAttributes = 0, $iUnit = 2)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipDrawImageFX", "handle", $hGraphics, _
            "handle", $hBitmap, _
            "struct*", $tRECTF, _
            "handle", $hMatrix, _
            "ptr", $pEffect, _
            "ptr", $pImgAttributes, _
            "uint", $iUnit)
    If @error Then Return SetError(@error, @extended, 0)
    Return SetError($aResult[0], 0, $aResult[0] = 0)
EndFunc   ;==>_GDIPlus_DrawImageFX

Func _GDIPlus_EffectsSetParameters($pEffectObject, $tEffectParameters, $iSizeAdj = 1)
    Local $aSize = DllCall($ghGDIPDll, "uint", "GdipGetEffectParameterSize", "ptr", $pEffectObject, "uint*", 0)
    Local $iSize = $aSize[2] * $iSizeAdj
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipSetEffectParameters", "ptr", $pEffectObject, "struct*", $tEffectParameters, "uint", $iSize)
    If @error Then Return SetError(@error, @extended, 0)
    Return SetError($aResult[0], 0, $aResult[3])
EndFunc   ;==>_GDIPlus_EffectsSetParameters

Func _GDIPlus_BitmapApplyEffect($hBitmap, $hEffect, $pROI = 0)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipBitmapApplyEffect", "hwnd", $hBitmap, "hwnd", $hEffect, "ptr", $pROI, "int", 0, "ptr*", 0, "int*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    Return SetError($aResult[0], 0, $aResult[0] = 0)
EndFunc

Func _GDIPlus_BitmapCreateWithEffect($hBitmap, $hEffect, $pROI = 0, $pOutRect = 0)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipBitmapCreateApplyEffect", "ptr*", $hBitmap, "int", 1, "hwnd", $hEffect, "ptr", $pROI, "ptr", $pOutRect, "int*", 0, "int", 0, "ptr*", 0, "int*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    Return SetError($aResult[0], 0, $aResult[6])
EndFunc

Func _GDIPlus_EffectCreate($sEffectGUID, $pEffect = 0)
    Local $iI, $tGUID, $pGUID, $tElem, $aElem[4], $aResult
    $tGUID = _WinAPI_GUIDFromString($sEffectGUID)
    $pGUID = DllStructGetPtr($tGUID)
    $tElem = DllStructCreate("uint[4]", $pGUID)
    For $iI = 1 To 4
        $aElem[$iI - 1] = DllStructGetData($tElem, 1, $iI)
    Next
    $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateEffect", "uint", $aElem[0], "uint", $aElem[1], "uint", $aElem[2], "uint", $aElem[3], "uint*", $pEffect)
    If @error Then Return SetError(@error, @extended, 0)
    Return SetError($aResult[0], 0, $aResult[5])
EndFunc   ;==>_GDIPlus_EffectCreate

Func _GDIPlus_ImageAttributesCreate()
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateImageAttributes", "int*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[1]
EndFunc   ;==>_GDIPlus_ImageAttributesCreate

Func _GDIPlus_ImageClone($hImage)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCloneImage", "handle", $hImage, "int*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[2]
EndFunc   ;==>_GDIPlus_ImageClone

Func _TurnL()
    _Rotate(3)
EndFunc

Func _TurnR()
    _Rotate(1)
EndFunc

Func _FlipH()
    _Rotate(6)
EndFunc

Func _FlipV()
    _Rotate(4)
EndFunc

Func _Rotate($x)
;    $RotateNoneFlipNone = 0 , _
;    $Rotate90FlipNone = 1 , _
;    $Rotate180FlipNone = 2 , _
;    $Rotate270FlipNone = 3 , _
;    $RotateNoneFlipX = 4 , _
;    $Rotate90FlipX = 5 , _
;    $Rotate180FlipX = 6 , _
;    $Rotate270FlipX = 7 , _
;    $RotateNoneFlipY = 6 , _
;    $Rotate90FlipY = 7 , _
;    $Rotate180FlipY = 4 , _
;    $Rotate270FlipY = 5 , _
;    $RotateNoneFlipXY = 6 , _
;    $Rotate90FlipXY = 7 , _
;    $Rotate180FlipXY = 0 , _
;    $Rotate270FlipXY = 1
    DllCall($ghGDIPDll,"int","GdipImageRotateFlip","hwnd",$hImage,"long",$x)
    _SetImage()
EndFunc

Func _Exit()
    DllCall($ghGDIPDll,"int","GdipDisposeImage","handle",$O_Image)
    DllCall($ghGDIPDll,"int","GdipDisposeImage","handle",$hImage)
        DllCall($ghGDIPDll, "uint","GdipDisposeImageAttributes","handle",$hIA)
        _GDIPlus_GraphicsDispose($hGraphic)
        _WinAPI_SelectObject($hDC_backbuffer,$DC_obj)
        _WinAPI_DeleteObject($hHBitmap_Preview)
        _WinAPI_ReleaseDC(GUICtrlGetHandle($RFB_Pic),$hDC)
        _WinAPI_DeleteDC($hDC)
        DllClose($hDLL_GDI32)
    _GDIPlus_Shutdown()
    Exit
EndFunc

Func _Drag()
    DllCall("user32.dll","int","SendMessage","hwnd",@GUI_WinHandle,"int",274,"int",0xF012,"int",0)
EndFunc

Func __GDIPlus_Startup()
    If $giGDIPRef > 0 Then Return True

    ; check version first
    Local $tGDIPDLL="GDIPlus.dll"
    If Number(FileGetVersion($tGDIPDLL))<6 Then; OS Vista or higher v 6.x.x.x

        ; OS XP v 5.x.x.x
        $tGDIPDLL=@ScriptDir&"\GDIPlus.dll"; check local
        If Number(FileGetVersion($tGDIPDLL))<6 Then
            MsgBox(0x40010,"Error","This script only runs on OS Vista or higher."&@CRLF&@CRLF&"For XP you need a GDIPlus.dll v1.1 in the script directory, refer to:       "&@CRLF&"http://www.winsxs.org/?OtherTech/thread-13-1-1")
            Return False
        EndIf
    EndIf

    $ghGDIPDll = DllOpen($tGDIPDLL)
    If $ghGDIPDll = -1 Then
        $giGDIPRef = 0
        Return SetError(1, 2, False)
    EndIf

    $giGDIPRef += 1

    Local $tInput = DllStructCreate($tagGDIPSTARTUPINPUT)
    Local $pInput = DllStructGetPtr($tInput)
    Local $tToken = DllStructCreate("int Data")
    Local $pToken = DllStructGetPtr($tToken)
    DllStructSetData($tInput, "Version", 1)
    Local $aResult = DllCall($ghGDIPDll, "int", "GdiplusStartup", "ptr", $pToken, "ptr", $pInput, "ptr", 0)
    ;Local $aResult = DllCall($ghGDIPDll, "int", "GdiplusStartup", "struct*", $tToken, "struct*", $tInput, "ptr", 0)
    If @error Then Return SetError(@error, @extended, False)
    $giGDIPToken = DllStructGetData($tToken, "Data")
    Return $aResult[0] = 0
EndFunc   ;==>__GDIPlus_Startup

Func _Examples()
    MsgBox(0,"GDIPlus effects","now zoom ...")
    _Zoom(2)
    MsgBox(0,"GDIPlus effects","... and restore")
    _Zoom()
    MsgBox(0,"GDIPlus effects","Blur")
    _Effekt($tBlur,$GDIP_BLUREFFECT,10);0-255; False/True
    _SetImage()
    MsgBox(0,"GDIPlus effects","... and restore")
    _Restore()
    _SetImage()
    MsgBox(0,"GDIPlus effects","Sharpen")
    _Effekt($tSharpen,$GDIP_SHARPENEFFECT,100,50);"Range is from 0 to 255";"Range is from 0 to 100"
    _SetImage()
    MsgBox(0,"GDIPlus effects","... and restore")
    _Restore()
    _SetImage()
    MsgBox(0,"GDIPlus effects","Brightness Contrast")
    _Effekt($tBrightnessContrast,$GDIP_BRIGHTNESSCONTRASTEFFECT,100,50);-255-255; -100-100
    _SetImage()
    MsgBox(0,"GDIPlus effects","... and restore")
    _Restore()
    _SetImage()
EndFunc

.

with UEZ' help i got the slider effects working. now i have problems with the colormatrix functions (negative and black/white). i want the results to be drawn to the image handle $hImage, that will be set into the pic control.

the usual coding with CopyImage2Gfx() only paints the graphic over the pic control. what i need is probably GdipDrawImage(). http://www.jose.it-berater.org/gdiplus/iframe/index.htm

GdipDrawImage

 

 

Description

Draws an image at a specified location.

Syntax

GpStatus WINGDIPAPI GdipDrawImage(_

    GpGraphics *graphics,

    GpImage *image,

    REAL x,

    REAL y

);

PowerBASIC Syntax

DECLARE FUNCTION GdipDrawImage ( _

    BYVAL graphics AS DWORD, _

    BYVAL pImage AS DWORD, _

    BYVAL x AS SINGLE, _

    BYVAL y AS SINGLE _

) AS LONG

Parameters

 

graphics

[in] Pointer to the
Graphics
object.

image

[in] Pointer to an
Image
object that specifies the image to be drawn.

x

[in] Simple precision value that specifies the x-coordinate of the upper-left corner of the rendered image.

y

[in] Simple precision value that specifies the y-coordinate of the upper-left corner of the rendered image.

.

but i am lost on how to use it with all the device contexts, image attributes, backbuffers and matrices. i suspect the answer is not too difficult, so please help me out.

thx E.

[color=rgb(255,0,0);][font="'comic sans ms', cursive;"]FukuLeaks[/color][/font]

Link to comment
Share on other sites

What I did is always to apply the effect to a temp bitmap in the background. E.g. if you apply any effect it will be copied to main image.

Look at the Case $iBtnApply section.

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

i don't exactly understand it. is it a workaround ? you mean $hCtx_tmp resp. $hBmp_tmp ? i don't see how you make this work.

My brain is already fried.

[color=rgb(255,0,0);][font="'comic sans ms', cursive;"]FukuLeaks[/color][/font]

Link to comment
Share on other sites

okay,  i made it ! :)

instead of your CopyImage2Gfx() function, you can simply use "GdipDrawImageFX" to draw the matrix into the image, like it is done with the effects. there is once more the "ptr" / "handle" issue, but then it works.

will need some more hours to get the example re-scripted.

[color=rgb(255,0,0);][font="'comic sans ms', cursive;"]FukuLeaks[/color][/font]

Link to comment
Share on other sites

i posted an example script >here.

the magical function that combines all effects, matrices and image attributes without workarounds is:

.

GdipDrawImageFX

 

 

Description

Syntax

Draws a portion of an image after applying a specified effect.


GpStatus WINGDIPAPI GdipDrawImageFX(

    GpGraphics *graphics,

    GpImage *image,

    GpRectF *source,

    GpMatrix *xForm,

    CGpEffect *effect,

    GpImageAttributes *imageAttributes,

    GpUnit srcUnit

);

 


Parameters

 

graphics

[in] Pointer to the
Graphics
object.

image

[in] Pointer to an
Image
object that specifies the image to be drawn.

source

[in] Pointer to a RectF object that specifies the portion of the image to be drawn.

xForm

[in]
Pointer to a
Matrix
object
that specifies the parallelogram in which the image portion is rendered. The destination parallelogram is calculated by applying the affine transformation stored in the matrix to the source rectangle.

effect

[in]
Pointer to an
Effect
object
that specifies an effect or adjustment (for example, a change in contrast) that is applied to the image before rendering. The image is not permanently altered by the effect.

imageAttributes

[in]
Pointer to an
ImageAttributes
object
that specifies color adjustments to be applied when the image is rendered. Can be NULL.

srcUnit

[in]   Element of the
Unit
enumeration that specifies the unit of measure for the source rectangle.

Minimum availability: GDI+ 1.1

.

there we have the pointers to a matrix, an effect, and an image object.

Edited by Edano

[color=rgb(255,0,0);][font="'comic sans ms', cursive;"]FukuLeaks[/color][/font]

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...