Jump to content
Sign in to follow this  
UEZ

GDI+ Show Histogram v0.98 beta build 2015-07-13

Recommended Posts

Here a little tool to display the histogram of an image (inspired by this thread):

)

post-29844-0-08200900-1359724336_thumb.p

;#AutoIt3Wrapper_Icon=Histogram1.ico
#AutoIt3Wrapper_Compile_Both=y
;#AutoIt3Wrapper_Res_Field=CompanyName|UEZ Software Development
;#AutoIt3Wrapper_Res_Field=ProductName|GDI+ Show Histogram
;#AutoIt3Wrapper_Res_Field=ProductVersion|%AutoItVer%
#AutoIt3Wrapper_Res_Fileversion=0.9.8.0
;#AutoIt3Wrapper_Res_Field=Build|2015-07-10
#AutoIt3Wrapper_Res_LegalCopyright=UEZ Software Development
#AutoIt3Wrapper_Res_Language=1033
;#AutoIt3Wrapper_Res_Field=URL|http://www.autoitscript.com/forum/index.php?showtopic=147777
#AutoIt3Wrapper_Run_Au3Stripper=y
#Au3Stripper_Parameters=/so /pe /rm
#AutoIt3Wrapper_Run_After=del /f /q "%scriptdir%\%scriptfile%_stripped.au3"
#AutoIt3Wrapper_UseUpx=y
#AutoIt3Wrapper_UPX_Parameters=--best --lzma
#AutoIt3Wrapper_Run_After=upx.exe --best --lzma "GDI+ Show Histogram_x64.exe"
#AutoIt3Wrapper_UseX64=n

#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
#include <WindowsConstants.au3>

Opt("MustDeclareVars", 1)
Opt("MouseCoordMode", 2)

_GDIPlus_Startup()
If @error Then Exit MsgBox(0x40010, "Error", "GDI+ Show Histogram can run on operating systems Vista or newer only!")

Global $ghGDIPDll = $__g_hGDIPDll, $aRes
Global Const $hFullScreen = WinGetHandle("[TITLE:Program Manager;CLASS:Progman]")
Global Const $aFullScreen = WinGetPos($hFullScreen)

Global Enum $HistogramFormatARGB, $HistogramFormatPARGB, $HistogramFormatRGB, $HistogramFormatGray, _ ;http://msdn.microsoft.com/en-us/library/windows/desktop/ms534129(v=vs.85).aspx
        $HistogramFormatB, $HistogramFormatG, $HistogramFormatR, $HistogramFormatA

Global $tStructChannel0 = DllStructCreate("uint channel0[256]")
Global $pStructChannel0 = DllStructGetPtr($tStructChannel0)
Global $tStructChannel1 = DllStructCreate("uint channel1[256]")
Global $pStructChannel1 = DllStructGetPtr($tStructChannel1)
Global $tStructChannel2 = DllStructCreate("uint channel2[256]")
Global $pStructChannel2 = DllStructGetPtr($tStructChannel2)
Global $tStructChannel3 = DllStructCreate("uint channel3[256]")
Global $pStructChannel3 = DllStructGetPtr($tStructChannel3)

Global $s, $sFile, $hImage, $bImgLoaded = False, $aLuminosity[257], $aCRGB[257]
Global Const $STM_SETIMAGE = 0x0172, $iLineJoinBevel = 1, $frY = 0.299, $fgY = 0.587, $fbY = 0.114

Global Const $hGUI = GUICreate("GDI+ Show Histogram v0.98 beta by UEZ build 2015-07-13", 468, 310, -1, -1, Default, Default)
GUISetBkColor(0xFFFFFF, $hGUI)
Global Const $sLabel_Titel_Txt = "GDI+ Show Histogram"
Global Const $iPosX_Label = 20, $iPosY_Label = 12
Global Const $iLabel_Titel_Shadow = GUICtrlCreateLabel($sLabel_Titel_Txt, $iPosX_Label, $iPosY_Label, 429, 57)
GUICtrlSetFont(-1, 30, 400, 0, "Comic Sans MS", 4)
GUICtrlSetColor(-1, 0xC0C0D8)
Global Const $iLabel_Titel = GUICtrlCreateLabel($sLabel_Titel_Txt, $iPosX_Label - 4, $iPosY_Label - 4, 429, 57)
GUICtrlSetFont(-1, 30, 400, 0, "Comic Sans MS", 4)
GUICtrlSetColor(-1, 0x0000C0)
GUICtrlSetBkColor(-1, -2)
Global Const $iPic_Histogram = GUICtrlCreatePic("", 20, 90, 255, 127, -1, $WS_EX_STATICEDGE)
GUICtrlSetCursor(-1, 14)
Global Const $iPic_ColorGradient = GUICtrlCreatePic("", 20, 220, 255, 24, -1, $WS_EX_STATICEDGE)

Global Const $iGroup = GUICtrlCreateGroup("Channel", 290, 84, 160, 164)
Global Const $iRadio_L = GUICtrlCreateRadio("Luminosit&y (gray)", 300, 100, 110, 20)
GUICtrlSetTip(-1, $frY & "*R,  " & $fgY & "*G, " & $fbY & "*B")
GUICtrlSetState($iRadio_L, $GUI_CHECKED)
Global Const $iRadio_C = GUICtrlCreateRadio("&cRGB", 300, 130, 60, 20)
GUICtrlSetTip(-1, "Combined average of RGB values")
Global Const $iRadio_R = GUICtrlCreateRadio("&Red", 300, 160, 60, 20)
Global Const $iRadio_G = GUICtrlCreateRadio("&Green", 300, 190, 60, 20)
Global Const $iRadio_B = GUICtrlCreateRadio("&Blue", 300, 220, 60, 20)
GUICtrlCreateGroup("", -99, -99, 1, 1)
Global Const $iButton_Save = GUICtrlCreateButton("&Save", 209, 265, 70, 30)
GUICtrlSetTip(-1, "Click button to save all histogram images")
GUICtrlSetState(-1, $GUI_DISABLE)
Global Const $iButton_Load = GUICtrlCreateButton("&Load", 290, 265, 70, 30)
GUICtrlSetTip(-1, "Click button to load an image")
Global Const $iButton_Exit = GUICtrlCreateButton("E&xit", 390, 265, 60, 30)

Global $sLabelCredit_Txt = "coded by UEZ'13"
Global $aLabelCredit_Pos[StringLen($sLabelCredit_Txt)][4], $u, $iFS = 6.5, $iY = 280
For $u = 0 To UBound($aLabelCredit_Pos) - 1
    $aLabelCredit_Pos[$u][0] = StringMid($sLabelCredit_Txt, $u + 1, 1)
    $aLabelCredit_Pos[$u][1] = 20 + $u * ($iFS - 0.25)
    $aLabelCredit_Pos[$u][2] = $iY
    $aLabelCredit_Pos[$u][3] = GUICtrlCreateLabel($aLabelCredit_Pos[$u][0], $aLabelCredit_Pos[$u][1], $aLabelCredit_Pos[$u][2], $iFS, $iFS * 1.8)
    GUICtrlSetFont(-1, $iFS, 400, 0, "Comic Sans MS", 2)
    GUICtrlSetColor(-1, 0x006000)
Next
Global $aLabelCredit_AnimPos[300]
For $u = 0 To UBound($aLabelCredit_AnimPos) - 1
    $aLabelCredit_AnimPos[$u] = $iY
Next
Global Const $fLimes = 2.2, $fStep = 0.1
Global $iPT = 0, $z = Int((UBound($aLabelCredit_AnimPos) - ($fLimes * $fStep * 100)) / 2)
For $u = 0 To $fLimes Step $fStep
    $aLabelCredit_AnimPos[$z] = $iY + Sin($iPT * 4) * 10
    $z += 1
    $iPT += 0.075
Next

Global $ihGui_PreviewSize = 256, $iBGColor = 0xF0F0F0
Global $hGui_Preview = GUICreate("", $ihGui_PreviewSize, $ihGui_PreviewSize + 58, -1, -1, $WS_POPUP + $WS_BORDER, $WS_EX_TOPMOST, $hGUI)
Global $iPic_Preview = GUICtrlCreatePic("", 0, 0, $ihGui_PreviewSize, $ihGui_PreviewSize)
Global $idLabel_Info = GUICtrlCreateLabel("", 0, $ihGui_PreviewSize, $ihGui_PreviewSize * 2, 58)
GUICtrlSetFont(-1, 8.5, 400, 0, "Arial", 5)
GUICtrlSetColor(-1, $iBGColor)
GUICtrlSetBkColor(-1, 0x333333)

Global Const $hTexture_Checkerboard = _GDIPlus_CreateCheckerboardTexture(8, 0xFFFBFBFB, 0xFFFFFFFF)

Global $hHBmp_L = _GDIPlus_CreateColorGradient("L", 256, 24)
Global $hHBmp_C = _GDIPlus_CreateColorGradient("C", 256, 24)
Global $hHBmp_R = _GDIPlus_CreateColorGradient("R", 256, 24)
Global $hHBmp_G = _GDIPlus_CreateColorGradient("G", 256, 24)
Global $hHBmp_B = _GDIPlus_CreateColorGradient("B", 256, 24)
Global Const $hHBmp_HL = _GDIPlus_BitmapCreateFromScan0(256, 127)
Global Const $hCtxt_HL = _GDIPlus_ImageGetGraphicsContext($hHBmp_HL)
Global Const $hHBmp_HC = _GDIPlus_BitmapCloneArea($hHBmp_HL, 0, 0, 256, 127, 0x0026200A)
Global Const $hCtxt_HC = _GDIPlus_ImageGetGraphicsContext($hHBmp_HC)
Global Const $hHBmp_HR = _GDIPlus_BitmapCloneArea($hHBmp_HL, 0, 0, 256, 127, 0x0026200A)
Global Const $hCtxt_HR = _GDIPlus_ImageGetGraphicsContext($hHBmp_HR)
Global Const $hHBmp_HG = _GDIPlus_BitmapCloneArea($hHBmp_HL, 0, 0, 256, 127, 0x0026200A)
Global Const $hCtxt_HG = _GDIPlus_ImageGetGraphicsContext($hHBmp_HG)
Global Const $hHBmp_HB = _GDIPlus_BitmapCloneArea($hHBmp_HL, 0, 0, 256, 127, 0x0026200A)
Global Const $hCtxt_HB = _GDIPlus_ImageGetGraphicsContext($hHBmp_HB)
_GDIPlus_GraphicsClear($hCtxt_HL, 0xFFFFFFFF)

_hBmpToPicControl($iPic_ColorGradient, $hHBmp_L)

Global $hB_H = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hHBmp_HL)
_hBmpToPicControl($iPic_Histogram, $hB_H, 1)

GUISetState(@SW_HIDE, $hGui_Preview)
GUISetState(@SW_SHOW, $hGUI)
ControlFocus($hGUI, "", $iButton_Load)

Global $hPen_H = _GDIPlus_PenCreate()

$s = "L"
Global $iDummyL = GUICtrlCreateDummy(), $iDummyC = GUICtrlCreateDummy(), $iDummyR = GUICtrlCreateDummy(), $iDummyG = GUICtrlCreateDummy(), $iDummyB = GUICtrlCreateDummy()
Global $iHistogramFormat, $hHBmp_Preview, $aPosCtrl, $aPosWin, $aMouseInfo, $aPos_hWnd, $imp, $iVal, $iMpos_oldx, $iMpos_oldy, $sType, $iPaletteType, $iPixelFormat
Global $fAverage_L, $fAverage_cRGB, $iAverage_R, $iAverage_B, $iAverage_G, $o = 0
Global  $bShow = False, $bHide = False, $bIsAlpha = False, $bIsGray = False
Global Const $iEntries = 256
Global Const $tagCOLORPALETTE = "uint Flags;" & _               ; Palette flags
                                "uint Count;" & _               ; Number of color entries
                                "uint ARGB[" & $iEntries & "];" ; Palette color

AdlibRegister("AnimateLabel", 60)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $iButton_Exit
            AdlibUnRegister("AnimateLabel")
            GUIDelete($hGui_Preview)
            GUIDelete($hGUI)
            _WinAPI_DeleteObject($hHBmp_L)
            _WinAPI_DeleteObject($hHBmp_C)
            _WinAPI_DeleteObject($hHBmp_L)
            _WinAPI_DeleteObject($hHBmp_R)
            _WinAPI_DeleteObject($hHBmp_G)
            _WinAPI_DeleteObject($hHBmp_B)
            If $hHBmp_Preview Then _WinAPI_DeleteObject($hHBmp_Preview)
            _GDIPlus_PenDispose($hPen_H)
            _GDIPlus_BrushDispose($hTexture_Checkerboard)
            _GDIPlus_GraphicsDispose($hCtxt_HL)
            _GDIPlus_GraphicsDispose($hCtxt_HC)
            _GDIPlus_GraphicsDispose($hCtxt_HR)
            _GDIPlus_GraphicsDispose($hCtxt_HG)
            _GDIPlus_GraphicsDispose($hCtxt_HB)
            _GDIPlus_BitmapDispose($hHBmp_HL)
            _GDIPlus_BitmapDispose($hHBmp_HC)
            _GDIPlus_BitmapDispose($hHBmp_HR)
            _GDIPlus_BitmapDispose($hHBmp_HG)
            _GDIPlus_BitmapDispose($hHBmp_HB)
            _GDIPlus_Shutdown()
            $tStructChannel0 = 0
            $tStructChannel1 = 0
            $tStructChannel2 = 0
            $tStructChannel3 = 0
            Exit
        Case $iRadio_L, $iDummyL
            If $s <> "L" Then
                _hBmpToPicControl($iPic_ColorGradient, $hHBmp_L)
                If $bImgLoaded Then
                    $hB_H = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hHBmp_HL)
                    _hBmpToPicControl($iPic_Histogram, $hB_H, 1)
                EndIf
                $s = "L"
            EndIf
        Case $iRadio_C, $iDummyC
            If $s <> "C" Then
                _hBmpToPicControl($iPic_ColorGradient, $hHBmp_C)
                If $bImgLoaded Then
                    $hB_H = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hHBmp_HC)
                    _hBmpToPicControl($iPic_Histogram, $hB_H, 1)
                EndIf
                $s = "C"
            EndIf
        Case $iRadio_R, $iDummyR
            If $s <> "R" Then
                _hBmpToPicControl($iPic_ColorGradient, $hHBmp_R)
                If $bImgLoaded Then
                    $hB_H = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hHBmp_HR)
                    _hBmpToPicControl($iPic_Histogram, $hB_H, 1)
                EndIf
                $s = "R"
            EndIf
        Case $iRadio_G, $iDummyG
            If $s <> "G" Then
                _hBmpToPicControl($iPic_ColorGradient, $hHBmp_G)
                If $bImgLoaded Then
                    $hB_H = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hHBmp_HG)
                    _hBmpToPicControl($iPic_Histogram, $hB_H, 1)
                EndIf
                $s = "G"
            EndIf
        Case $iRadio_B, $iDummyB
            If $s <> "B" Then
                _hBmpToPicControl($iPic_ColorGradient, $hHBmp_B)
                If $bImgLoaded Then
                    $hB_H = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hHBmp_HB)
                    _hBmpToPicControl($iPic_Histogram, $hB_H, 1)
                EndIf
                $s = "B"
            EndIf
        Case $iButton_Load
            $sFile = FileOpenDialog("Select  an image", "", "Images (*.jpg;*.png;*.bmp;*.gif)", 3)
            If @error Then ContinueCase
            If $bImgLoaded Then _GDIPlus_ImageDispose($hImage)
            $hImage = _GDIPlus_ImageLoadFromFile($sFile)
            If @error Then
                MsgBox(0x40010, "Error", "Unable to load image", 30)
                ContinueCase
            EndIf
            GUICtrlSetState($iButton_Save, $GUI_ENABLE)
            $aRes = _GDIPlus_ImageGetFlags($hImage)
            If BitAND($aRes[0], $GDIP_IMAGEFLAGS_HASALPHA) Then
                $bIsAlpha = True
            Else
                $bIsAlpha = False
            EndIf
            If BitAND($aRes[0], $GDIP_IMAGEFLAGS_COLORSPACE_GRAY) Then
                $bIsGray = True
            Else
                $bIsGray = False
            EndIf
            $hHBmp_Preview = _GetImage($sFile, $ihGui_PreviewSize, $iBGColor)
            _hBmpToPicControl($iPic_Preview, $hHBmp_Preview, 1)
            If Not $bIsAlpha Then
                $pStructChannel3 = 0
                $iHistogramFormat = $HistogramFormatRGB
            Else
                $pStructChannel3 = DllStructGetPtr($tStructChannel3)
                $iHistogramFormat = $HistogramFormatARGB
            EndIf
            _GDIPlus_BitmapGetHistogram($hImage, $iHistogramFormat, _GDIPlus_BitmapGetHistogramSize($iHistogramFormat), $pStructChannel0, $pStructChannel1, $pStructChannel2, $pStructChannel3)
            _GDIPlus_CreateHistogram()
            $bImgLoaded = True
            If BitAND(GUICtrlRead($iRadio_L), $GUI_CHECKED) Then
                $s = ""
                GUICtrlSendToDummy($iDummyL)
            ElseIf BitAND(GUICtrlRead($iRadio_C), $GUI_CHECKED) Then
                $s = ""
                GUICtrlSendToDummy($iDummyC)
            ElseIf BitAND(GUICtrlRead($iRadio_R), $GUI_CHECKED) Then
                $s = ""
                GUICtrlSendToDummy($iDummyR)
            ElseIf BitAND(GUICtrlRead($iRadio_G), $GUI_CHECKED) Then
                $s = ""
                GUICtrlSendToDummy($iDummyG)
            Else
                $s = ""
                GUICtrlSendToDummy($iDummyB)
            EndIf
        Case $iButton_Save
            If $sFile = "" Then ContinueLoop
            $sType = "png"
            $o += _GDIPlus_ImageSaveToFile($hHBmp_HL, StringRegExpReplace($sFile, "(.*)\..*", "$1") & "_Luminosity." & $sType)
            $o += _GDIPlus_ImageSaveToFile($hHBmp_HC, StringRegExpReplace($sFile, "(.*)\..*", "$1") & "_cRGB." & $sType)
            $o += _GDIPlus_ImageSaveToFile($hHBmp_HR, StringRegExpReplace($sFile, "(.*)\..*", "$1") & "_Red." & $sType)
            $o += _GDIPlus_ImageSaveToFile($hHBmp_HG, StringRegExpReplace($sFile, "(.*)\..*", "$1") & "_Green." & $sType)
            $o += _GDIPlus_ImageSaveToFile($hHBmp_HB, StringRegExpReplace($sFile, "(.*)\..*", "$1") & "_Blue." & $sType)
            If $o = 5 Then
                MsgBox(64 + 262144, "Information", "Images properly saved to " & StringRegExpReplace($sFile, "(.*)\\.*", "$1"), 30, $hGUI)
            Else
                MsgBox(16 + 262144, "Error", "One or more images could not saved to " & StringRegExpReplace($sFile, "(.*)\\.*", "$1") & ".", 30, $hGUI)
            EndIf
    EndSwitch
    If WinActive($hGUI) Then
        $aMouseInfo = GUIGetCursorInfo($hGUI)
        Switch $aMouseInfo[4]
            Case $iPic_Histogram
                If $bImgLoaded Then
                    $aPos_hWnd = WinGetPos($hGUI)
                    $imp = Max(1, Min(256, -19 + $aMouseInfo[0]))
                    Switch $s
                        Case "L"
                            $iVal = $aLuminosity[$imp]
                        Case "C"
                            $iVal = $aCRGB[$imp]
                        Case "R"
                            $iVal = DllStructGetData($tStructChannel0, "channel0", $imp)
                        Case "G"
                            $iVal = DllStructGetData($tStructChannel1, "channel1", $imp)
                        Case "B"
                            $iVal = DllStructGetData($tStructChannel2, "channel2", $imp)
                    EndSwitch
                    If $iMpos_oldx <> $aMouseInfo[0] Or $iMpos_oldy <> $aMouseInfo[1] Then
                        ToolTip("Index: " & $imp & ", Value: " & Round($iVal, 0) & ", Average: " & Round($fAverage_L, 2), $aPos_hWnd[0] + $aMouseInfo[0] - 60, $aMouseInfo[1] + $aPos_hWnd[1] - 20)
                        $iMpos_oldx = $aMouseInfo[0]
                        $iMpos_oldy = $aMouseInfo[1]
                    EndIf
                    ShowPreview($iPic_Histogram)
                    $bShow = True
                    $bHide = False

                EndIf
            Case Else
                If Not $bHide Then
                    GUISetState(@SW_HIDE, $hGui_Preview)
                    $bHide = True
                    ToolTip("")
                EndIf
                $bShow = False
        EndSwitch
    EndIf
WEnd

Func AnimateLabel()
    Local Static $v = Int((UBound($aLabelCredit_AnimPos) - ($fLimes * $fStep * 100)) / 2)
    Local $u
    For $u = 0 To UBound($aLabelCredit_Pos) - 1
        GUICtrlSetPos($aLabelCredit_Pos[$u][3], $aLabelCredit_Pos[$u][1], $aLabelCredit_AnimPos[$v - $u])
    Next
    If $v - $u < 0 Then $v = UBound($aLabelCredit_AnimPos) - 1
    $v -= 1
EndFunc   ;==>AnimateLabel

Func Min($a, $b)
    If $a < $b Then Return $a
    Return $b
EndFunc   ;==>Min

Func Max($a, $b)
    If $a > $b Then Return $a
    Return $b
EndFunc   ;==>Max

Func ShowPreview($iCtrl)
    $aPosWin = WinGetPos($hGUI)
    $aPosCtrl = ControlGetPos($hGUI, "", $iCtrl)
    Local $iNewX, $iNewX1 = $aPosWin[0] - $ihGui_PreviewSize + 10, $iNewX2 = $aPosWin[0] + $aPosWin[2] - 10
    $iNewX = $iNewX1
    If $iNewX1 < $aFullScreen[0] Then
        $iNewX = $iNewX2
    EndIf
    WinMove($hGui_Preview, "", $iNewX, $aPosWin[1] + 50)
    GUISetState(@SW_SHOWNOACTIVATE, $hGui_Preview)
EndFunc   ;==>ShowPreview

Func _GetImage($sFile, $iWH, $iBkClr = 0xFFFFFF, $bCheckerboard_Bg = True)
    Local $hBmp1, $hBitmap, $hGraphic, $hImage, $iW, $iH, $aGS, $hBmp2, $aFTS
    $aFTS = FileGetTime($sFile)
    If @error Then Return SetError(1, 0, 0)
    $hBmp1 = _WinAPI_CreateBitmap($iWH, $iWH, 1, 32)
    $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBmp1)
    $hGraphic = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _WinAPI_DeleteObject($hBmp1)
    $hImage = _GDIPlus_ImageLoadFromFile($sFile)
    $iW = _GDIPlus_ImageGetWidth($hImage)
    $iH = _GDIPlus_ImageGetHeight($hImage)
    GUICtrlSetData($idLabel_Info,  StringRegExpReplace($sFile, ".*\\(.*)", "$1") & @LF & Round(FileGetSize($sFile) / 1024, 0) & " kb (" & $iW & " x " & $iH & ")" & @LF & $aFTS[0] & "/" & $aFTS[1] & "/" & $aFTS[2] & " " & $aFTS[3] & ":" & $aFTS[4] & ":" & $aFTS[5] & @LF & "Alpha: " & $bIsAlpha & ", Gray: " & $bIsGray)
    $aGS = _GetScale($iW, $iH, $iWH)
    Switch $bCheckerboard_Bg
        Case True
;~          _GDIPlus_GraphicsFillRect($hGraphic, 0, 0, $iWH, $iWH, $hTexture_Checkerboard)
            _GDIPlus_GraphicsClear($hGraphic, BitOR(0xFF000000, $iBkClr))
            _GDIPlus_GraphicsFillRect($hGraphic, $aGS[0], $aGS[1], $aGS[2], $aGS[3], $hTexture_Checkerboard)
        Case False
            _GDIPlus_GraphicsClear($hGraphic, BitOR(0xFF000000, $iBkClr))
    EndSwitch
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, $aGS[0], $aGS[1], $aGS[2], $aGS[3])
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_GraphicsDispose($hGraphic)
    $hBmp2 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
    _GDIPlus_BitmapDispose($hBitmap)
    Return $hBmp2
EndFunc   ;==>_GetImage

Func _GetScale($iW, $iH, $iWH)
    Local $aRet[4]
    If $iW <= $iWH And $iH <= $iWH Then
        $aRet[2] = $iW
        $aRet[3] = $iH
        $aRet[0] = ($iWH - $aRet[2]) / 2
        $aRet[1] = ($iWH - $aRet[3]) / 2
    ElseIf $iW > $iH Then
        $aRet[2] = $iWH
        $aRet[3] = $iH / ($iW / $iWH)
        $aRet[0] = 0
        $aRet[1] = ($iWH - $aRet[3]) / 2
    ElseIf $iW < $iH Then
        $aRet[2] = $iW / ($iH / $iWH)
        $aRet[3] = $iWH
        $aRet[0] = ($iWH - $aRet[2]) / 2
        $aRet[1] = 0
    ElseIf $iW = $iH Then
        $aRet[2] = $iWH
        $aRet[3] = $iWH
        $aRet[0] = 0
        $aRet[1] = 0
    EndIf
    Return $aRet
EndFunc   ;==>_GetScale

Func _hBmpToPicControl($iCID, ByRef $hBmp, $iFlag = 0)
    Local $hOldBmp
    $hOldBmp = GUICtrlSendMsg($iCID, $STM_SETIMAGE, $IMAGE_BITMAP, $hBmp)
    If $hOldBmp Then _WinAPI_DeleteObject($hOldBmp)
    If $iFlag Then _WinAPI_DeleteObject($hBmp)
EndFunc   ;==>_hBmpToPicControl

Func _GDIPlus_CreateHistogram($sRounding = "Ceiling")
    Local $iMaxL, $iMaxC, $iMaxR, $iMaxG, $iMaxB, $a, $r, $g, $b, $yR, $yG, $yB, $iRedAv, $iGreenAv, $iBlueAv
    For $i = 1 + $bIsAlpha To 256
        If $bIsAlpha Then
;~          ConsoleWrite("Alpha: " & DllStructGetData($tStructChannel0, "channel0", $i) & @CRLF)
            $r = DllStructGetData($tStructChannel1, "channel1", $i)
            $yR = $r * $frY
            If DllStructGetData($tStructChannel1 , "channel1", $i) > $iMaxR Then $iMaxR = $r

            $g = DllStructGetData($tStructChannel2, "channel2", $i)
            $yG = $g * $fgY
            If DllStructGetData($tStructChannel2 , "channel2", $i) > $iMaxG Then $iMaxG = $g

            $b = DllStructGetData($tStructChannel3, "channel3", $i)
            $yB = $b * $fbY
            If DllStructGetData($tStructChannel3 , "channel3", $i) > $iMaxB Then $iMaxB = $b
            $fAverage_cRGB += $r + $g + $b
            $fAverage_L += $yR + $yG + $yB
        Else
            $r = DllStructGetData($tStructChannel0, "channel0", $i)
            $yR = $r * $frY
            If DllStructGetData($tStructChannel0 , "channel0", $i) > $iMaxR Then $iMaxR = $r

            $g = DllStructGetData($tStructChannel1, "channel1", $i)
            $yG = $g * $fgY
            If DllStructGetData($tStructChannel1 , "channel1", $i) > $iMaxG Then $iMaxG = $g

            $b = DllStructGetData($tStructChannel2, "channel2", $i)
            $yB = $b * $fbY
            If DllStructGetData($tStructChannel2 , "channel2", $i) > $iMaxB Then $iMaxB = $b
        EndIf

        $fAverage_cRGB += $r + $g + $b
        $fAverage_L += $yR + $yG + $yB

        $aLuminosity[$i] = $yR + $yG + $yB
        If $aLuminosity[$i] > $iMaxL Then $iMaxL = $aLuminosity[$i]

        $aCRGB[$i] = ($r + $g + $b) / 3
        If $aCRGB[$i] > $iMaxC Then $iMaxC = $aCRGB[$i]
    Next
    $fAverage_cRGB /= 256 * 3
    $fAverage_L /= 256

    _GDIPlus_GraphicsClear($hCtxt_HL, 0xFFFFFFFF)
    _GDIPlus_GraphicsClear($hCtxt_HC, 0xFFFFFFFF)
    _GDIPlus_GraphicsClear($hCtxt_HR, 0xFFFFFFFF)
    _GDIPlus_GraphicsClear($hCtxt_HG, 0xFFFFFFFF)
    _GDIPlus_GraphicsClear($hCtxt_HB, 0xFFFFFFFF)

    Local $iDL = 1, $iDC = 1, $iDR = 1, $iDG = 1, $iDB = 1
    Local $sRoundings = "Round,Ceiling,Floor,"
    If Not StringInStr($sRoundings, $sRounding) Then $sRounding = "Ceiling"
    If $iMaxL > 128 Then
;~      $iDL = Ceiling($iMaxL / 128)
        $iDL = Execute($sRounding & "(" & $iMaxL / 128 & ")")
    Else
        $iDL = 1 / (128 / $iMaxL)
    EndIf
    If $iMaxC > 128 Then
;~      $iDC = Ceiling($iMaxC / 128)
        $iDC = Execute($sRounding & "(" & $iMaxC / 128 & ")")
    Else
        $iDC = 1 / (128 / $iMaxC)
    EndIf
    If $iMaxR > 128 Then
;~      $iDR = Ceiling($iMaxR / 128)
        $iDR = Execute($sRounding & "(" & $iMaxR / 128 & ")")
    Else
        $iDR = 1 / (128 / $iMaxR)
    EndIf
    If $iMaxG > 128 Then
;~      $iDG = Ceiling($iMaxG / 128)
        $iDG = Execute($sRounding & "(" & $iMaxG / 128 & ")")
    Else
        $iDG = 1 / (128 / $iMaxG)
    EndIf
    If $iMaxB > 128 Then
;~      $iDB = Ceiling($iMaxB / 128)
        $iDB = Execute($sRounding & "(" & $iMaxB / 128 & ")")
    Else
        $iDB = 1 / (128 / $iMaxB)
    EndIf
    For $i = 1 To 256
        _GDIPlus_PenSetColor($hPen_H, 0xFF000000)
        _GDIPlus_GraphicsDrawLine($hCtxt_HL, $i - 1, 127, $i - 1, 127 - (Int($aLuminosity[$i] / $iDL)), $hPen_H)
        _GDIPlus_PenSetColor($hPen_H, 0xFF000000)
        _GDIPlus_GraphicsDrawLine($hCtxt_HC, $i - 1, 127, $i - 1, 127 - (Int($aCRGB[$i] / $iDC)), $hPen_H)
        _GDIPlus_PenSetColor($hPen_H, 0xFFB00000)
        If $bIsAlpha Then
            _GDIPlus_GraphicsDrawLine($hCtxt_HR, $i - 1, 127, $i - 1, 127 - (Int(DllStructGetData($tStructChannel1, "channel1", $i) / $iDR)), $hPen_H)
            _GDIPlus_PenSetColor($hPen_H, 0xFF00B000)
            _GDIPlus_GraphicsDrawLine($hCtxt_HG, $i - 1, 127, $i - 1, 127 - (Int(DllStructGetData($tStructChannel2, "channel2", $i) / $iDG)), $hPen_H)
            _GDIPlus_PenSetColor($hPen_H, 0xFF0000B0)
            _GDIPlus_GraphicsDrawLine($hCtxt_HB, $i - 1, 127, $i - 1, 127 - (Int(DllStructGetData($tStructChannel3, "channel3", $i) / $iDB)), $hPen_H)
        Else
            _GDIPlus_GraphicsDrawLine($hCtxt_HR, $i - 1, 127, $i - 1, 127 - (Int(DllStructGetData($tStructChannel0, "channel0", $i) / $iDR)), $hPen_H)
            _GDIPlus_PenSetColor($hPen_H, 0xFF00B000)
            _GDIPlus_GraphicsDrawLine($hCtxt_HG, $i - 1, 127, $i - 1, 127 - (Int(DllStructGetData($tStructChannel1, "channel1", $i) / $iDG)), $hPen_H)
            _GDIPlus_PenSetColor($hPen_H, 0xFF0000B0)
            _GDIPlus_GraphicsDrawLine($hCtxt_HB, $i - 1, 127, $i - 1, 127 - (Int(DllStructGetData($tStructChannel2, "channel2", $i) / $iDB)), $hPen_H)
        EndIf
    Next

EndFunc   ;==>_GDIPlus_CreateHistogram

Func _GDIPlus_CreateColorGradient($sColorChannel, $iW, $iH, $bHBitmap = True)
    Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH)
    Local $hCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap)
;~  _GDIPlus_GraphicsSetSmoothingMode($hCtxt, 2)
    Local $hPen = _GDIPlus_PenCreate()
    _GDIPlus_PenSetLineJoin($hPen, $iLineJoinBevel)
    Local $i, $c
    For $i = 0 To $iW
        $c = Hex($i, 2)
        Switch $sColorChannel
            Case "L"
                _GDIPlus_PenSetColor($hPen, "0xFF" & $c & $c & $c)
            Case "C"
                _GDIPlus_PenSetColor($hPen, "0xFF" & $c & $c & $c)
            Case "R"
                _GDIPlus_PenSetColor($hPen, "0xFF" & $c & "0000")
            Case "G"
                _GDIPlus_PenSetColor($hPen, "0xFF00" & $c & "00")
            Case "B"
                _GDIPlus_PenSetColor($hPen, "0xFF0000" & $c)
        EndSwitch
        _GDIPlus_GraphicsDrawLine($hCtxt, $i, 0, $i, $iH, $hPen)
    Next
    _GDIPlus_GraphicsDispose($hCtxt)
    _GDIPlus_PenDispose($hPen)
    If $bHBitmap Then
        Local $hHBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
        _GDIPlus_BitmapDispose($hBitmap)
        Return $hHBmp
    EndIf
    Return $hBitmap
EndFunc   ;==>_GDIPlus_CreateColorGradient

Func _GDIPlus_CreateCheckerboardTexture($iSquareSize = 80, $iCol1 = 0xFFECECEC, $iCol2 = 0xFFDFDFDF)
    Local $hPatternBitmap = _GDIPlus_BitmapCreateFromScan0(2 * $iSquareSize, 2 * $iSquareSize)
    Local $hCtxt = _GDIPlus_ImageGetGraphicsContext($hPatternBitmap)
    Local $hBrush0 = _GDIPlus_BrushCreateSolid($iCol1)
    Local $hBrush1 = _GDIPlus_BrushCreateSolid($iCol2)
    _GDIPlus_GraphicsFillRect($hCtxt, 0, 0, $iSquareSize, $iSquareSize, $hBrush0)
    _GDIPlus_GraphicsFillRect($hCtxt, $iSquareSize, 0, $iSquareSize, $iSquareSize, $hBrush1)
    _GDIPlus_GraphicsFillRect($hCtxt, 0, $iSquareSize, $iSquareSize, $iSquareSize, $hBrush1)
    _GDIPlus_GraphicsFillRect($hCtxt, $iSquareSize, $iSquareSize, $iSquareSize, $iSquareSize, $hBrush0)
    Local $hTexture = _GDIPlus_TextureCreate($hPatternBitmap)
    _GDIPlus_GraphicsDispose($hCtxt)
    _GDIPlus_BitmapDispose($hPatternBitmap)
    _GDIPlus_BitmapDispose($hBrush0)
    _GDIPlus_BitmapDispose($hBrush1)
    Return $hTexture
EndFunc   ;==>_CreatePatternTexture

 

GdipBitmapGetHistogram(), GdipBitmapGetHistogramSize() and 2 more GDI+ functions requires GDI+ v1.1 which means this will only run on Vista or higher operating systems.

I hope the values are correct especially the value for luminosity.

Br,

UEZ

Edited by 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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

impressive, great job.

thanks for sharing UEZ.

I guess it would be nice to also have the historgram of the combined RGB channels.


Contributions

CheckUpdate - SelfUpdating script ------- Self updating script

Dynamic input validation ------------------- Use a Input masks can make your life easier and Validation can be as simple

MsgBox with CountDown ------------------- MsgBox with visual countdown

Display Multiline text cells in ListView ---- Example of pop-up or ToolTip for multiline text items in ListView

Presentation Manager ---------------------- Program to display and refresh different Border-less GUI's on a Display (large screen TV)

USB Drive Tools ------------------------------ Tool to help you with your USB drive management

Input Period udf ------------------------------ GUI for a period input

Excel ColorPicker ---------------------------- Color pickup tool will allow you to select a color from the standard Excel color palette

Excel Chart UDF ----------------------------- Collaboration project with water 

GetDateInString ------------------------------ Find date/time in a string using a date format notation like DD Mon YYYY hh:mm

TaskListAllDetailed --------------------------- List All Scheduled Tasks

Computer Info --------------------------------- A collection of information for helpdesk

Shared memory Demo ----------------------- Demo: Two applications communicate with each other through means of a memory share (using Nomad function, 32bit only)

Universal Date Format Conversion -------- Universal date converter from your PC local date format to any format

Disable Windows DetailsPane -------------- Disable Windows Explorer Details Pane

Oracle SQL Report Generator -------------  Oracle Report generator using SQL

SQLite Report Generator -------------------  SQLite Report generator using SQL

SQLite ListView and BLOB demo ---------- Demo: shows how binary (image) objects can be recognized natively in a database BLOB field

DSN-Less Database connection demo --- Demo: ActiveX Data Objects DSN-Less Database access

Animated animals ----------------------------- Fun: Moving animated objects

Perforated image in GUI --------------------- Fun: Perforate your image with image objects

UEZ's Perforator major update ------------- Fun: Pro version of Perforator by UEZ

Visual Crop Tool (GUI) ----------------------- Easy to use Visual Image Crop tool

Visual Image effect (GUI) -------------------- Visually apply effects on an image

 

 

 

Share this post


Link to post
Share on other sites

Typical UEZ, you solve a problem and then create an example for us, while most of us (me included) create examples and then solve probs.

5 Stars from me...


----------------------------------------

:bye: Hey there, was I helpful?

----------------------------------------

My Current OS: Win8 PRO (64-bit); Current AutoIt Version: v3.3.8.1

Share this post


Link to post
Share on other sites

@all: thank you for your comments. :rolleyes:

@GreenCan: "combined RGB channels" is the luminosity radio button here, isn't it?

Br,

UEZ

Edited by 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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Hi UEZ,

The luminosity (or gray) histogram is calculated with a formula that isolate the brightness from the color information giving a different enphasis to the RGB values. In a way, it is closer to what your eye perceives as brightness.

Formulawise Luminosity is calculated like this: ( 0.299*R + 0.587*G + 0.114*B ), you set the values as constants in line 41 and the formula is used in _GDIPlus_CreateHistogram()

There are also other variants of this formula, but this is good enough.

RGB histogram is the combined average of the RGB values, the formula looks like this: cRGB = ( R + G + B ) / 3

Now comes the stigmatizing part for me …J

I looked into the code, but I don’t quite understand yet how this all works.

Anyhow, You enumerate all the Histogram Formats in line 27 but you don’t seem to use the $HistogramFormatGray format. Maybe the label of the default radio button should then be RGB and not ‘Luminosity’?

I tried to replace $HistogramFormatRGB by $HistogramFormatGray but that does not function, I guess the reason is that $pStructChannel0, $pStructChannel1, $pStructChannel2 should then be set to Null. At least that is what I understand from: http://msdn.microsoft.com/en-us/library/windows/desktop/ms534129(v=vs.85).aspx

A last remark, assuming the default histogram in your script is combined RGB (it looks like this is what you do), the histogram shown is not exactly the RGB one that I see in my Graphic Viewer (FastStone) or in Photoshop. Neither does the Gray histogram corresponds…

The Red, Green and Blue histograms are indeed identical.


Contributions

CheckUpdate - SelfUpdating script ------- Self updating script

Dynamic input validation ------------------- Use a Input masks can make your life easier and Validation can be as simple

MsgBox with CountDown ------------------- MsgBox with visual countdown

Display Multiline text cells in ListView ---- Example of pop-up or ToolTip for multiline text items in ListView

Presentation Manager ---------------------- Program to display and refresh different Border-less GUI's on a Display (large screen TV)

USB Drive Tools ------------------------------ Tool to help you with your USB drive management

Input Period udf ------------------------------ GUI for a period input

Excel ColorPicker ---------------------------- Color pickup tool will allow you to select a color from the standard Excel color palette

Excel Chart UDF ----------------------------- Collaboration project with water 

GetDateInString ------------------------------ Find date/time in a string using a date format notation like DD Mon YYYY hh:mm

TaskListAllDetailed --------------------------- List All Scheduled Tasks

Computer Info --------------------------------- A collection of information for helpdesk

Shared memory Demo ----------------------- Demo: Two applications communicate with each other through means of a memory share (using Nomad function, 32bit only)

Universal Date Format Conversion -------- Universal date converter from your PC local date format to any format

Disable Windows DetailsPane -------------- Disable Windows Explorer Details Pane

Oracle SQL Report Generator -------------  Oracle Report generator using SQL

SQLite Report Generator -------------------  SQLite Report generator using SQL

SQLite ListView and BLOB demo ---------- Demo: shows how binary (image) objects can be recognized natively in a database BLOB field

DSN-Less Database connection demo --- Demo: ActiveX Data Objects DSN-Less Database access

Animated animals ----------------------------- Fun: Moving animated objects

Perforated image in GUI --------------------- Fun: Perforate your image with image objects

UEZ's Perforator major update ------------- Fun: Pro version of Perforator by UEZ

Visual Crop Tool (GUI) ----------------------- Easy to use Visual Image Crop tool

Visual Image effect (GUI) -------------------- Visually apply effects on an image

 

 

 

Share this post


Link to post
Share on other sites

Thanks for the clarification. I've no knowledge in this kind of graphical stuff but it should be easy to add cRGB = ( R + G + B ) / 3 to display the combined RGB.

Regarding the luminosity: I compared it also with some other tools and it looks sometimes different. Let me check this again ...

Thanks four your feedback.

Br,

UEZ

Edited by 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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

@GreenCan: I added cRGB and modified the calculation for luminosity. Can you check whether it fits now better?

Luminosity looks similar to cRGB...

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

This is perfect UEZ.

The histograms match perfectly now. Good show!

And I like your wave too :thumbsup:

What OS are you running on?

When I run the script on Windows 7 64bit, the histograms are shown, but if I do the same on a W7 32bit, I don't see the histogram.

If this is correct I would change line 23 as follows:

[/autoit][autoit]If @OSBuild < 6000 Or @OSArch = "X86" Then Exit MsgBox(0x40010, "Error", "GDI+ Show Histogram can run on 64bit operating systems Vista or newer only!")

Thanks

GreenCan


Contributions

CheckUpdate - SelfUpdating script ------- Self updating script

Dynamic input validation ------------------- Use a Input masks can make your life easier and Validation can be as simple

MsgBox with CountDown ------------------- MsgBox with visual countdown

Display Multiline text cells in ListView ---- Example of pop-up or ToolTip for multiline text items in ListView

Presentation Manager ---------------------- Program to display and refresh different Border-less GUI's on a Display (large screen TV)

USB Drive Tools ------------------------------ Tool to help you with your USB drive management

Input Period udf ------------------------------ GUI for a period input

Excel ColorPicker ---------------------------- Color pickup tool will allow you to select a color from the standard Excel color palette

Excel Chart UDF ----------------------------- Collaboration project with water 

GetDateInString ------------------------------ Find date/time in a string using a date format notation like DD Mon YYYY hh:mm

TaskListAllDetailed --------------------------- List All Scheduled Tasks

Computer Info --------------------------------- A collection of information for helpdesk

Shared memory Demo ----------------------- Demo: Two applications communicate with each other through means of a memory share (using Nomad function, 32bit only)

Universal Date Format Conversion -------- Universal date converter from your PC local date format to any format

Disable Windows DetailsPane -------------- Disable Windows Explorer Details Pane

Oracle SQL Report Generator -------------  Oracle Report generator using SQL

SQLite Report Generator -------------------  SQLite Report generator using SQL

SQLite ListView and BLOB demo ---------- Demo: shows how binary (image) objects can be recognized natively in a database BLOB field

DSN-Less Database connection demo --- Demo: ActiveX Data Objects DSN-Less Database access

Animated animals ----------------------------- Fun: Moving animated objects

Perforated image in GUI --------------------- Fun: Perforate your image with image objects

UEZ's Perforator major update ------------- Fun: Pro version of Perforator by UEZ

Visual Crop Tool (GUI) ----------------------- Easy to use Visual Image Crop tool

Visual Image effect (GUI) -------------------- Visually apply effects on an image

 

 

 

Share this post


Link to post
Share on other sites

I just checked the code in my vm running Vista x64 and saw that it didn't work properly. I added _GDIPlus11_Startup() which loads the DLL appropriately and now it runs also on Vista x64 (thanks to Authenticity for the code). I don't have x86 installed to test.

My main os is Win7 x64 with Aero enabled.

Btw, I don't know what I should do with the information about the histogram information...

Br,

UEZ

Edited by 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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Btw, I don't know what I should do with the information about the histogram information...

There are many application for this kind of the histogram information.

Let's have a look on the this article:

http://io9.com/5060911/magnetic-anomaly-map-of-the-world

There, red indicates a stronger magnetic tug, and blue a weaker one (white lines are the edges of tectonic plates). As you can see, disturbances are fairly regularly distributed, but that doesn't stop UFO enthusiasts from saying aliens have a hand in these magnetic fluctuations. Science, however, has a slightly different explanation for why certain objects (including submarines) create a shift in the magnetic field.According to the Geological Survey of Finland, which created the map out of years of survey research:

Posted Image

Now you can help UFO enthusiasts and scientists to research the Magnetic Anomaly of the World.

:thumbsup:

Share this post


Link to post
Share on other sites

This is truly amazing UEZ!

For me the next logical step would be the Effects Class in GDIPlus v1.1.

With the histogram we could apply 'Levels' or 'Colorcurve' maybe?

Authenticity already started this a while back but I found there was one Dllcall that I needed missing...

(My first dllcall so please correct any mistakes)

Func _GDIPlus_EffectsSetParameters($hEffectObject, $pEffectParameters)

Local $aSize = DllCall($ghGDIPDll, "uint", "GdipGetEffectParameterSize", "hwnd", $hEffectObject, "uint*", 0)
Local $size = $aSize[2]
Local $aResult = DllCall($ghGDIPDll, "uint", "GdipSetEffectParameters", "hwnd", $hEffectObject, "ptr", $pEffectParameters, "uint", $size)

If @error Then Return SetError(@error, @extended, 0)

Return SetError($aResult[0], 0, $aResult[3])
EndFunc

Here's a very quick and simple example (excuse the messy code!)

#include <GDIPlus.au3>
#include <WinAPI.au3>

Global Const $GDIP_BLUREFFECT = "{633C80A4-1843-482b-9EF2-BE2834C5FDD4}"
Global Const $GDIP_SHARPENEFFECT = "{63CBF3EE-C526-402c-8F71-62C540BF5142}"
Global Const $GDIP_COLORMATRIXEFFECT = "{718F2615-7933-40e3-A511-5F68FE14DD74}"
Global Const $GDIP_COLORLUTEFFECT = "{A7CE72A9-0F7F-40d7-B3CC-D0C02D5C3212}"
Global Const $GDIP_BRIGHTNESSCONTRASTEFFECT = "{D3A1DBE1-8EC4-4c17-9F4C-EA97AD1C343D}"
Global Const $GDIP_HUESATURATIONLIGHTNESSEFFECT = "{8B2DD6C3-EB07-4d87-A5F0-7108E26A9C5F}"
Global Const $GDIP_LEVELSEFFECT = "{99C354EC-2A31-4f3a-8C34-17A803B33A25}"
Global Const $GDIP_TINTEFFECT = "{1077AF00-2848-4441-9489-44AD4C2D7A2C}"
Global Const $GDIP_COLORBALANCEEFFECT = "{537E597D-251E-48da-9664-29CA496B70F8}"
Global Const $GDIP_REDEYECORRECTIONEFFECT = "{74D29D05-69A4-4266-9549-3CC52836B632}"
Global Const $GDIP_COLORCURVEEFFECT = "{DD6A0022-58E4-4a67-9D9B-D48EB881A53D}"
Global Enum _
$AdjustExposure = 0, _
$AdjustDensity = 1, _
$AdjustContrast = 2, _
$AdjustHighlight = 3, _
$AdjustShadow = 4, _
$AdjustMidtone = 5, _
$AdjustWhiteSaturation = 6, _
$AdjustBlackSaturation = 7
Global Enum _
$CurveChannelAll = 0, _
$CurveChannelRed = 1, _
$CurveChannelGreen = 2, _
$CurveChannelBlue = 3

Local $file = @ScriptDir & "\Test.jpg"
Global $highlight, $midtone, $shadow
$type = $AdjustExposure
$channel = $CurveChannelAll
$value = 100
Global $LevelsParams = DllStructCreate("int type;int channel;int value")
Global $pLevelsParams = DllStructGetPtr($LevelsParams)
DllStructSetData($LevelsParams, "type", $AdjustHighlight)
DllStructSetData($LevelsParams, "channel", $CurveChannelAll)
DllStructSetData($LevelsParams, "value", 90)

_GDIPlus_Startup()
If @error Then Exit MsgBox(0x10, "Error", "GDIPlus v1.1 is not installed")
Local $hGUI, $hGraphics, $hImage, $hAlteredImage, $hEffect
$hGUI = GUICreate("", 1400, 800)
GUISetState()
$hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI)
$hImage = _GDIPlus_ImageLoadFromFile($file)

_GDIPlus_GraphicsDrawImage($hGraphics, $hImage, 0, 0)
Sleep(2000)
$hEffect = _GDIPlus_EffectCreate($GDIP_COLORCURVEEFFECT)
_GDIPlus_EffectsSetParameters($hEffect, $pLevelsParams)
$hAlteredImage = _GDIPlus_BitmapCreateWithEffect($hImage, $hEffect)
_GDIPlus_GraphicsDrawImage($hGraphics, $hAlteredImage, 0, 0)

Do
Until GUIGetMsg() = -3
_GDIPlus_BitmapDispose($hAlteredImage)
_GDIPlus_EffectDispose($hEffect)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_Shutdown()

Func _GDIPlus_EffectsSetParameters($hEffectObject, $pEffectParameters)
Local $aSize = DllCall($ghGDIPDll, "uint", "GdipGetEffectParameterSize", "hwnd", $hEffectObject, "uint*", 0)
Local $size = $aSize[2]
Local $aResult = DllCall($ghGDIPDll, "uint", "GdipSetEffectParameters", "hwnd", $hEffectObject, "ptr", $pEffectParameters, "uint", $size)
If @error Then Return SetError(@error, @extended, 0)
Return SetError($aResult[0], 0, $aResult[3])
EndFunc
;Following functions written by Authenticity (Thank You!)
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)
Local $iI, $tGUID, $pGUID, $tElem, $aElem[4], $aResult
$tGUID = _WinAPI_GUIDFromString($sEffectGUID)
$pGUID = DllStructGetPtr($tGUID)
$tElem = DllStructCreate("int[4]", $pGUID)
For $iI = 1 To 4
     $aElem[$iI-1] = DllStructGetData($tElem, 1, $iI)
Next

$aResult = DllCall($ghGDIPDll, "uint", "GdipCreateEffect", "int", $aElem[0], "int", $aElem[1], "int", $aElem[2], "int", $aElem[3], "int*", 0)
If @error Then Return SetError(@error, @extended, 0)
Return SetError($aResult[0], 0, $aResult[5])
EndFunc
Func _GDIPlus_EffectDispose($hEffect)
Local $aResult = DllCall($ghGDIPDll, "uint", "GdipDeleteEffect", "hwnd", $hEffect)
If @error Then Return SetError(@error, @extended, 0)
Return SetError($aResult[0], 0, $aResult[0] = 0)
EndFunc

#cs
Func _GDIPlus11_Startup()
Local $pInput, $tInput, $pToken, $tToken, $aResult
$giGDIPRef += 1
If $giGDIPRef > 1 Then Return True
$ghGDIPDll = DllOpen(@WindowsDir & "\WinSxS\x86_microsoft.windows.gdiplus_6595b64144ccf1df_1.1.9200.16384_none_ba245425e0986353\gdiplus.dll")
;$ghGDIPDll = DllOpen(@WindowsDir & "\winsxs\x86_microsoft.windows.gdiplus_6595b64144ccf1df_1.1.6000.16386_none_8df21b8362744ace\gdiplus.dll")
_WinAPI_Check("_GDIPlus_Startup (GDIPlus.dll not found)", @error, False)
$tInput = DllStructCreate($tagGDIPSTARTUPINPUT)
$pInput = DllStructGetPtr($tInput)
$tToken = DllStructCreate("int Data")
$pToken = DllStructGetPtr($tToken)
DllStructSetData($tInput, "Version", 1)
$aResult = DllCall($ghGDIPDll, "int", "GdiplusStartup", "ptr", $pToken, "ptr", $pInput, "ptr", 0)
If @error Then Return SetError(@error, @extended, False)
$giGDIPToken = DllStructGetData($tToken, "Data")
Return $aResult[0] == 0
EndFunc
Func _GDIPlus11_Shutdown()
If $ghGDIPDll = 0 Then Return SetError(-1, -1, False)
$giGDIPRef -= 1
If $giGDIPRef = 0 Then
     DllCall($ghGDIPDll, "none", "GdiplusShutdown", "ptr", $giGDIPToken)
     DllClose($ghGDIPDll)
     $ghGDIPDll = 0
EndIf
Return True
EndFunc
Func _WinAPI_Check($sFunction, $fError, $vError, $fTranslate = False)
If $fError Then
If $fTranslate Then $vError = _WinAPI_GetLastErrorMessage()
_WinAPI_ShowError($sFunction & ": " & $vError)
EndIf
EndFunc ;==>_WinAPI_Check
#ce

Share this post


Link to post
Share on other sites

@Jardz: I started this already some month ago but failed to modify e.g. settings for blur. It applies always the same settings although I change the values.

But this issue will highjack this topic.

Maybe you open a new thread and we can try to figure it out there.

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

I found my mistake. :)

Here what I got so far:

 

I don't know how you want to use the histogram for the color effects you mentioned above.

Br,

UEZ

Edited by 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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

@UEZ, Glad you got it sorted! Nice set of examples as always :)

Don't want to drift off thread topic but with regards the histogram, I was thinking about three adjustments in colorcurves; Values set by dragging pointers under the histogram (same as Photoshop, gimp etc)

Was also considering simple calculations for auto adjusting...Might have to revisit calculus :wacko:

Extract from http://gdiplus.ru/gdiplus/gdiplusreference/enumerations/curveadjustments.htm

AdjustMidtone

Lightens or darkens an image. Color channel values in the middle of the intensity range are altered more than color channel values near the minimum or maximum intensity. You can use this adjustment to lighten (or darken) an image without loosing the contrast between the darkest and lightest portions of the image. When you set the adjustment member of a ColorCurveParams object to AdjustMidtone, you should set the adjustValue member to an integer in the range -100 through 100. A value of 0 specifies no change. Positive values specify that the midtones are made lighter, and negative values specify that the midtones are made darker.

AdjustWhiteSaturation

When you set the adjustment member of a ColorCurveParams object to AdjustWhiteSaturation, you should set the adjustValue member to an integer in the range 0 through 255. A value of t specifies that the interval [0, t] is mapped linearly to the interval [0, 255]. For example, if adjustValue is equal to 240, then color channel values in the interval [0, 240] are adjusted so that they spread out over the interval [0, 255]. Color channel values greater than 240 are set to 255.

AdjustBlackSaturation

When you set the adjustment member of a ColorCurveParams object to AdjustBlackSaturation, you should set the adjustValue member to an integer in the range 0 through 255. A value of t specifies that the interval [t, 255] is mapped linearly to the interval [0, 255]. For example, if adjustValue is equal to 15, then color channel values in the interval [15, 255] are adjusted so that they spread out over the interval [0, 255]. Color channel values less than 15 are set to 0.

Share this post


Link to post
Share on other sites

Here a little tool to display the histogram of an image (inspired by this thread: )

post-29844-0-08200900-1359724336_thumb.p

#AutoIt3Wrapper_Compile_Both=y
://////=__=
://////=__=+
://////=__=
#AutoIt3Wrapper_Res_Fileversion=0.9.7.0
://////=__=--
#AutoIt3Wrapper_Res_LegalCopyright=UEZ Software Development
#AutoIt3Wrapper_Res_Language=1033
://////=__=://.=.com/forum/index.php?showtopic=147777
#AutoIt3Wrapper_Run_Obfuscator=y
#Obfuscator_Parameters=/om /sv /sf /cs=0 /cn=0
#AutoIt3Wrapper_Run_After=del /f /q "%scriptdir%\%scriptfile%_Obfuscated.au3"
#AutoIt3Wrapper_UseUpx=y
#AutoIt3Wrapper_UPX_Parameters=--best --lzma

#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
#include <WindowsConstants.au3>

Opt("MustDeclareVars", 1)
Opt("MouseCoordMode", 2)

_GDIPlus11_Startup()
If @error Then Exit MsgBox(0x40010, "Error", "GDI+ Show Histogram can run on operating systems Vista or newer only!")

Global Const $hFullScreen = WinGetHandle("[TITLE:Program Manager;CLASS:Progman]")
Global Const $aFullScreen = WinGetPos($hFullScreen)

Global Enum $HistogramFormatARGB, $HistogramFormatPARGB, $HistogramFormatRGB, $HistogramFormatGray, _ ;http://msdn.microsoft.com/en-us/library/windows/desktop/ms534129(v=vs.85).aspx
        $HistogramFormatB, $HistogramFormatG, $HistogramFormatR, $HistogramFormatA

Global Enum $DitherTypeNone = 0, $DitherTypeSolid, $DitherTypeOrdered4x4, $DitherTypeOrdered8x8, $DitherTypeOrdered16x16, $DitherTypeOrdered91x91, _
                            $DitherTypeSpiral4x4, $DitherTypeSpiral8x8, $DitherTypeDualSpiral4x4, $DitherTypeDualSpiral8x8, $DitherTypeErrorDiffusion
Global Enum $PaletteTypeCustom = 0, $PaletteTypeOptimal, $PaletteTypeFixedBW, $PaletteTypeFixedHalftone8, $PaletteTypeFixedHalftone27, $PaletteTypeFixedHalftone64, _
                            $PaletteTypeFixedHalftone125, $PaletteTypeFixedHalftone216, $PaletteTypeFixedHalftone252, $PaletteTypeFixedHalftone256

;http://msdn.microsoft.com/en-us/library/windows/desktop/ms534136(v=vs.85).aspx
Global Const $ImageFlagsNone = 0
Global Const $ImageFlagsScalable = 0x0001
Global Const $ImageFlagsHasAlpha = 0x0002
Global Const $ImageFlagsHasTranslucent = 0x0004
Global Const $ImageFlagsPartiallyScalable = 0x0008
Global Const $ImageFlagsColorSpaceRGB = 0x0010
Global Const $ImageFlagsColorSpaceCMYK = 0x0020
Global Const $ImageFlagsColorSpaceGRAY = 0x0040
Global Const $ImageFlagsColorSpaceYCBCR = 0x0080
Global Const $ImageFlagsColorSpaceYCCK = 0x0100
Global Const $ImageFlagsHasRealDPI = 0x1000
Global Const $ImageFlagsHasRealPixelSize = 0x2000
Global Const $ImageFlagsReadOnly = 0x00010000
Global Const $ImageFlagsCaching = 0x00020000

Global $tStructChannel0 = DllStructCreate("uint channel0[256]")
Global $pStructChannel0 = DllStructGetPtr($tStructChannel0)
Global $tStructChannel1 = DllStructCreate("uint channel1[256]")
Global $pStructChannel1 = DllStructGetPtr($tStructChannel1)
Global $tStructChannel2 = DllStructCreate("uint channel2[256]")
Global $pStructChannel2 = DllStructGetPtr($tStructChannel2)
Global $tStructChannel3 = DllStructCreate("uint channel3[256]")
Global $pStructChannel3 = DllStructGetPtr($tStructChannel3)

Global $s, $sFile, $hImage, $bImgLoaded = False, $aLuminosity[257], $aCRGB[257]
Global Const $STM_SETIMAGE = 0x0172, $iLineJoinBevel = 1, $frY = 0.299, $fgY = 0.587, $fbY = 0.114

Global Const $hGUI = GUICreate("GDI+ Show Histogram v0.97 beta by UEZ build 2013-02-05", 468, 310, -1, -1, Default, Default)
Global Const $sLabel_Titel_Txt = "GDI+ Show Histogram"
Global Const $iPosX_Label = 20, $iPosY_Label = 12
Global Const $iLabel_Titel_Shadow = GUICtrlCreateLabel($sLabel_Titel_Txt, $iPosX_Label, $iPosY_Label, 429, 57)
GUICtrlSetFont(-1, 30, 400, 0, "Comic Sans MS", 4)
GUICtrlSetColor(-1, 0xC0C0D8)
Global Const $iLabel_Titel = GUICtrlCreateLabel($sLabel_Titel_Txt, $iPosX_Label - 4, $iPosY_Label - 4, 429, 57)
GUICtrlSetFont(-1, 30, 400, 0, "Comic Sans MS", 4)
GUICtrlSetColor(-1, 0x0000C0)
GUICtrlSetBkColor(-1, -2)
Global Const $iPic_Histogram = GUICtrlCreatePic("", 20, 90, 255, 127, -1, $WS_EX_STATICEDGE)
GUICtrlSetCursor(-1, 14)
Global Const $iPic_ColorGradient = GUICtrlCreatePic("", 20, 220, 255, 24, -1, $WS_EX_STATICEDGE)

Global Const $iGroup = GUICtrlCreateGroup("Channel", 290, 84, 160, 164)
Global Const $iRadio_L = GUICtrlCreateRadio("Luminosit&y (gray)", 300, 100, 110, 20)
GUICtrlSetTip(-1, $frY & "*R, " & $fgY & "*G, " & $fbY & "*B")
GUICtrlSetState($iRadio_L, $GUI_CHECKED)
Global Const $iRadio_C = GUICtrlCreateRadio("&cRGB", 300, 130, 60, 20)
GUICtrlSetTip(-1, "Combined average of RGB values")
Global Const $iRadio_R = GUICtrlCreateRadio("&Red", 300, 160, 60, 20)
Global Const $iRadio_G = GUICtrlCreateRadio("&Green", 300, 190, 60, 20)
Global Const $iRadio_B = GUICtrlCreateRadio("&Blue", 300, 220, 60, 20)
GUICtrlCreateGroup("", -99, -99, 1, 1)
Global Const $iButton_Save = GUICtrlCreateButton("&Save", 209, 265, 70, 30)
GUICtrlSetTip(-1, "Click button to save all histogram images")
GUICtrlSetState(-1, $GUI_DISABLE)
Global Const $iButton_Load = GUICtrlCreateButton("&Load", 290, 265, 70, 30)
GUICtrlSetTip(-1, "Click button to load an image")
Global Const $iButton_Exit = GUICtrlCreateButton("E&xit", 390, 265, 60, 30)

Global $sLabelCredit_Txt = "coded by UEZ'13"
Global $aLabelCredit_Pos[StringLen($sLabelCredit_Txt)][4], $u, $iFS = 6.5, $iY = 280
For $u = 0 To UBound($aLabelCredit_Pos) - 1
    $aLabelCredit_Pos[$u][0] = StringMid($sLabelCredit_Txt, $u + 1, 1)
    $aLabelCredit_Pos[$u][1] = 20 + $u * ($iFS - 0.25)
    $aLabelCredit_Pos[$u][2] = $iY
    $aLabelCredit_Pos[$u][3] = GUICtrlCreateLabel($aLabelCredit_Pos[$u][0], $aLabelCredit_Pos[$u][1], $aLabelCredit_Pos[$u][2], $iFS, $iFS * 1.8)
    GUICtrlSetFont(-1, $iFS, 400, 0, "Comic Sans MS", 2)
    GUICtrlSetColor(-1, 0x006000)
Next
Global $aLabelCredit_AnimPos[300]
For $u = 0 To UBound($aLabelCredit_AnimPos) - 1
    $aLabelCredit_AnimPos[$u] = $iY
Next
Global Const $fLimes = 2.2, $fStep = 0.1
Global $iPT = 0, $z = Int((UBound($aLabelCredit_AnimPos) - ($fLimes * $fStep * 100)) / 2)
For $u = 0 To $fLimes Step $fStep
    $aLabelCredit_AnimPos[$z] = $iY + Sin($iPT * 4) * 10
    $z += 1
    $iPT += 0.075
Next

Global $ihGui_PreviewSize = 200, $iBGColor = 0xF0F0F0
Global $hGui_Preview = GUICreate("", $ihGui_PreviewSize, $ihGui_PreviewSize + 58, -1, -1, $WS_POPUP + $WS_BORDER, $WS_EX_TOPMOST, $hGUI)
Global $iPic_Preview = GUICtrlCreatePic("", 0, 0, $ihGui_PreviewSize, $ihGui_PreviewSize)
Global $idLabel_Info = GUICtrlCreateLabel("", 0, $ihGui_PreviewSize, $ihGui_PreviewSize * 2, 58)
GUICtrlSetFont(-1, 8.5, 400, 0, "Arial", 5)
GUICtrlSetColor(-1, $iBGColor)
GUICtrlSetBkColor(-1, 0x333333)

Global $hHBmp_L = _GDIPlus_CreateColorGradient("L", 256, 24)
Global $hHBmp_C = _GDIPlus_CreateColorGradient("C", 256, 24)
Global $hHBmp_R = _GDIPlus_CreateColorGradient("R", 256, 24)
Global $hHBmp_G = _GDIPlus_CreateColorGradient("G", 256, 24)
Global $hHBmp_B = _GDIPlus_CreateColorGradient("B", 256, 24)
Global $aRes = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", 256, "int", 127, "int", 0, "int", 0x0026200A, "ptr", 0, "int*", 0)
Global Const $hHBmp_HL = $aRes[6]
Global Const $hCtxt_HL = _GDIPlus_ImageGetGraphicsContext($hHBmp_HL)
Global Const $hHBmp_HC = _GDIPlus_BitmapCloneArea($hHBmp_HL, 0, 0, 256, 127, 0x0026200A)
Global Const $hCtxt_HC = _GDIPlus_ImageGetGraphicsContext($hHBmp_HC)
Global Const $hHBmp_HR = _GDIPlus_BitmapCloneArea($hHBmp_HL, 0, 0, 256, 127, 0x0026200A)
Global Const $hCtxt_HR = _GDIPlus_ImageGetGraphicsContext($hHBmp_HR)
Global Const $hHBmp_HG = _GDIPlus_BitmapCloneArea($hHBmp_HL, 0, 0, 256, 127, 0x0026200A)
Global Const $hCtxt_HG = _GDIPlus_ImageGetGraphicsContext($hHBmp_HG)
Global Const $hHBmp_HB = _GDIPlus_BitmapCloneArea($hHBmp_HL, 0, 0, 256, 127, 0x0026200A)
Global Const $hCtxt_HB = _GDIPlus_ImageGetGraphicsContext($hHBmp_HB)
_GDIPlus_GraphicsClear($hCtxt_HL, 0xFFFFFFFF)

_hBmpToPicControl($iPic_ColorGradient, $hHBmp_L)

Global $hB_H = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hHBmp_HL)
_hBmpToPicControl($iPic_Histogram, $hB_H, 1)

GUISetState(@SW_HIDE, $hGui_Preview)
GUISetState(@SW_SHOW, $hGUI)
ControlFocus($hGUI, "", $iButton_Load)

Global $hPen_H = _GDIPlus_PenCreate()

$s = "L"
Global $iDummyL = GUICtrlCreateDummy(), $iDummyC = GUICtrlCreateDummy(), $iDummyR = GUICtrlCreateDummy(), $iDummyG = GUICtrlCreateDummy(), $iDummyB = GUICtrlCreateDummy()
Global $iHistogramFormat, $hHBmp_Preview, $aPosCtrl, $aPosWin, $aMouseInfo, $aPos_hWnd, $imp, $iVal, $iMpos_oldx, $iMpos_oldy, $sType, $iPaletteType, $iPixelFormat, $fAverage_L, $fAverage_cRGB, $o = 0
Global $bShow = False, $bHide = False, $bIsAlpha = False, $bIsGray = False
Global Const $iEntries = 1024
Global Const $tagCOLORPALETTE = "uint Flags;" & _       ; Palette flags
                                                                            "uint Count;" & _   ; Number of color entries
                                                                            "uint ARGB[" & $iEntries & "];" ; Palette color

$iPaletteType = $PaletteTypeFixedHalftone8
$iPixelFormat = $GDIP_PXF08INDEXED
Global $tPalette = DllStructCreate($tagCOLORPALETTE)
DllStructSetData($tPalette, "Flags", $iPaletteType)
DllStructSetData($tPalette, "Count", $iEntries)
Global $pPalette = DllStructGetPtr($tPalette)
DllCall($ghGDIPDll, "int", "GdipInitializePalette", "struct*", $pPalette, "long", $iPaletteType, "int", 0, "bool", True, "handle", 0)

AdlibRegister("AnimateLabel", 60)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $iButton_Exit
            AdlibUnRegister("AnimateLabel")
            GUIDelete($hGui_Preview)
            GUIDelete($hGUI)
            _WinAPI_DeleteObject($hHBmp_L)
            _WinAPI_DeleteObject($hHBmp_C)
            _WinAPI_DeleteObject($hHBmp_L)
            _WinAPI_DeleteObject($hHBmp_R)
            _WinAPI_DeleteObject($hHBmp_G)
            _WinAPI_DeleteObject($hHBmp_B)
            If $hHBmp_Preview Then _WinAPI_DeleteObject($hHBmp_Preview)
            _GDIPlus_PenDispose($hPen_H)
            _GDIPlus_GraphicsDispose($hCtxt_HL)
            _GDIPlus_GraphicsDispose($hCtxt_HC)
            _GDIPlus_GraphicsDispose($hCtxt_HR)
            _GDIPlus_GraphicsDispose($hCtxt_HG)
            _GDIPlus_GraphicsDispose($hCtxt_HB)
            _GDIPlus_BitmapDispose($hHBmp_HL)
            _GDIPlus_BitmapDispose($hHBmp_HC)
            _GDIPlus_BitmapDispose($hHBmp_HR)
            _GDIPlus_BitmapDispose($hHBmp_HG)
            _GDIPlus_BitmapDispose($hHBmp_HB)
            _GDIPlus_Shutdown()
            $tStructChannel0 = 0
            $tStructChannel1 = 0
            $tStructChannel2 = 0
            $tStructChannel3 = 0
            Exit
        Case $iRadio_L, $iDummyL
            If $s <> "L" Then
                _hBmpToPicControl($iPic_ColorGradient, $hHBmp_L)
                If $bImgLoaded Then
                    $hB_H = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hHBmp_HL)
                    _hBmpToPicControl($iPic_Histogram, $hB_H, 1)
                EndIf
                $s = "L"
            EndIf
        Case $iRadio_C, $iDummyC
            If $s <> "C" Then
                _hBmpToPicControl($iPic_ColorGradient, $hHBmp_C)
                If $bImgLoaded Then
                    $hB_H = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hHBmp_HC)
                    _hBmpToPicControl($iPic_Histogram, $hB_H, 1)
                EndIf
                $s = "C"
            EndIf
        Case $iRadio_R, $iDummyR
            If $s <> "R" Then
                _hBmpToPicControl($iPic_ColorGradient, $hHBmp_R)
                If $bImgLoaded Then
                    $hB_H = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hHBmp_HR)
                    _hBmpToPicControl($iPic_Histogram, $hB_H, 1)
                EndIf
                $s = "R"
            EndIf
        Case $iRadio_G, $iDummyG
            If $s <> "G" Then
                _hBmpToPicControl($iPic_ColorGradient, $hHBmp_G)
                If $bImgLoaded Then
                    $hB_H = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hHBmp_HG)
                    _hBmpToPicControl($iPic_Histogram, $hB_H, 1)
                EndIf
                $s = "G"
            EndIf
        Case $iRadio_B, $iDummyB
            If $s <> "B" Then
                _hBmpToPicControl($iPic_ColorGradient, $hHBmp_B)
                If $bImgLoaded Then
                    $hB_H = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hHBmp_HB)
                    _hBmpToPicControl($iPic_Histogram, $hB_H, 1)
                EndIf
                $s = "B"
            EndIf
        Case $iButton_Load
            $sFile = FileOpenDialog("Select an image", "", "Images (*.jpg;*.png;*.bmp;*.gif)", 3)
            If @error Then ContinueCase
            If $bImgLoaded Then _GDIPlus_ImageDispose($hImage)
            $hImage = _GDIPlus_ImageLoadFromFile($sFile)
            If @error Then
                MsgBox(0x40010, "Error", "Unable to load image", 30)
                ContinueCase
            EndIf
            GUICtrlSetState($iButton_Save, $GUI_ENABLE)
            $aRes = DllCall($ghGDIPDll, "int", "GdipGetImageFlags", "handle", $hImage, "uint*", 0)
            If BitAND($aRes[2], $ImageFlagsHasAlpha) Then
                $bIsAlpha = True
            Else
                $bIsAlpha = False
            EndIf
            If BitAND($aRes[2], $ImageFlagsColorSpaceGRAY) Then
                $bIsGray = True
            Else
                $bIsGray = False
            EndIf
            $hHBmp_Preview = _GetImage($sFile, $ihGui_PreviewSize, $iBGColor)
            _hBmpToPicControl($iPic_Preview, $hHBmp_Preview, 1)
            If Not $bIsAlpha Then
                $pStructChannel3 = 0
                $iHistogramFormat = $HistogramFormatRGB
            Else
                $pStructChannel3 = DllStructGetPtr($tStructChannel3)
                $iHistogramFormat = $HistogramFormatARGB
            EndIf
            _GDIPlus_BitmapGetHistogram($hImage, $iHistogramFormat, _GDIPlus_BitmapGetHistogramSize($iHistogramFormat), $pStructChannel0, $pStructChannel1, $pStructChannel2, $pStructChannel3)
            _GDIPlus_CreateHistogram()
            $bImgLoaded = True
            If BitAND(GUICtrlRead($iRadio_L), $GUI_CHECKED) Then
                $s = ""
                GUICtrlSendToDummy($iDummyL)
            ElseIf BitAND(GUICtrlRead($iRadio_C), $GUI_CHECKED) Then
                $s = ""
                GUICtrlSendToDummy($iDummyC)
            ElseIf BitAND(GUICtrlRead($iRadio_R), $GUI_CHECKED) Then
                $s = ""
                GUICtrlSendToDummy($iDummyR)
            ElseIf BitAND(GUICtrlRead($iRadio_G), $GUI_CHECKED) Then
                $s = ""
                GUICtrlSendToDummy($iDummyG)
            Else
                $s = ""
                GUICtrlSendToDummy($iDummyB)
            EndIf
        Case $iButton_Save
            If $sFile = "" Then ContinueLoop
            $sType = "png"
            DllCall($ghGDIPDll, "int", "GdipBitmapConvertFormat", "handle", $hHBmp_HL, "long", $iPixelFormat, "long", $DitherTypeSolid, "long", $iPaletteType, "struct*", $pPalette, "float", 0.0)
            DllCall($ghGDIPDll, "int", "GdipBitmapConvertFormat", "handle", $hHBmp_HC, "long", $iPixelFormat, "long", $DitherTypeSolid, "long", $iPaletteType, "struct*", $pPalette, "float", 0.0)
            DllCall($ghGDIPDll, "int", "GdipBitmapConvertFormat", "handle", $hHBmp_HR, "long", $iPixelFormat, "long", $DitherTypeSolid, "long", $iPaletteType, "struct*", $pPalette, "float", 0.0)
            DllCall($ghGDIPDll, "int", "GdipBitmapConvertFormat", "handle", $hHBmp_HG, "long", $iPixelFormat, "long", $DitherTypeSolid, "long", $iPaletteType, "struct*", $pPalette, "float", 0.0)
            DllCall($ghGDIPDll, "int", "GdipBitmapConvertFormat", "handle", $hHBmp_HB, "long", $iPixelFormat, "long", $DitherTypeSolid, "long", $iPaletteType, "struct*", $pPalette, "float", 0.0)
            $o += _GDIPlus_ImageSaveToFile($hHBmp_HL, StringRegExpReplace($sFile, "(.*)\..*", "$1") & "_Luminosity." & $sType)
            $o += _GDIPlus_ImageSaveToFile($hHBmp_HC, StringRegExpReplace($sFile, "(.*)\..*", "$1") & "_cRGB." & $sType)
            $o += _GDIPlus_ImageSaveToFile($hHBmp_HR, StringRegExpReplace($sFile, "(.*)\..*", "$1") & "_Red." & $sType)
            $o += _GDIPlus_ImageSaveToFile($hHBmp_HG, StringRegExpReplace($sFile, "(.*)\..*", "$1") & "_Green." & $sType)
            $o += _GDIPlus_ImageSaveToFile($hHBmp_HB, StringRegExpReplace($sFile, "(.*)\..*", "$1") & "_Blue." & $sType)
            If $o = 5 Then
                MsgBox(64 + 262144, "Information", "Images properly saved to " & StringRegExpReplace($sFile, "(.*)\\.*", "$1"), 30, $hGUI)
            Else
                MsgBox(16 + 262144, "Error", "One or more images could not saved to " & StringRegExpReplace($sFile, "(.*)\\.*", "$1") & ".", 30, $hGUI)
            EndIf
    EndSwitch
    If WinActive($hGUI) Then
        $aMouseInfo = GUIGetCursorInfo($hGUI)
        Switch $aMouseInfo[4]
            Case $iPic_Histogram
                If $bImgLoaded Then
                    $aPos_hWnd = WinGetPos($hGUI)
                    $imp = Max(1, Min(256, -19 + $aMouseInfo[0]))
                    Switch $s
                        Case "L"
                            $iVal = $aLuminosity[$imp]
                        Case "C"
                            $iVal = $aCRGB[$imp]
                        Case "R"
                            $iVal = DllStructGetData($tStructChannel0, "channel0", $imp)
                        Case "G"
                            $iVal = DllStructGetData($tStructChannel1, "channel1", $imp)
                        Case "B"
                            $iVal = DllStructGetData($tStructChannel2, "channel2", $imp)
                    EndSwitch
                    If $iMpos_oldx <> $aMouseInfo[0] Or $iMpos_oldy <> $aMouseInfo[1] Then
                        ToolTip("Index: " & $imp & ", Value: " & Round($iVal, 0) & ", Average: " & Round($fAverage_L, 2), $aPos_hWnd[0] + $aMouseInfo[0] - 60, $aMouseInfo[1] + $aPos_hWnd[1] - 20)
                        $iMpos_oldx = $aMouseInfo[0]
                        $iMpos_oldy = $aMouseInfo[1]
                    EndIf
                    ShowPreview($iPic_Histogram)
                    $bShow = True
                    $bHide = False

                EndIf
            Case Else
                If Not $bHide Then
                    GUISetState(@SW_HIDE, $hGui_Preview)
                    $bHide = True
                    ToolTip("")
                EndIf
                $bShow = False
        EndSwitch
    EndIf
WEnd

Func AnimateLabel()
    Local Static $v = Int((UBound($aLabelCredit_AnimPos) - ($fLimes * $fStep * 100)) / 2)
    Local $u
    For $u = 0 To UBound($aLabelCredit_Pos) - 1
        GUICtrlSetPos($aLabelCredit_Pos[$u][3], $aLabelCredit_Pos[$u][1], $aLabelCredit_AnimPos[$v - $u])
    Next
    If $v - $u < 0 Then $v = UBound($aLabelCredit_AnimPos) - 1
    $v -= 1
EndFunc ;==>AnimateLabel

Func Min($a, $b)
    If $a < $b Then Return $a
    Return $b
EndFunc ;==>Min

Func Max($a, $b)
    If $a > $b Then Return $a
    Return $b
EndFunc ;==>Max

Func ShowPreview($iCtrl)
    $aPosWin = WinGetPos($hGUI)
    $aPosCtrl = ControlGetPos($hGUI, "", $iCtrl)
    Local $iNewX, $iNewX1 = $aPosWin[0] - $ihGui_PreviewSize + 10, $iNewX2 = $aPosWin[0] + $aPosWin[2] - 10
    $iNewX = $iNewX1
    If $iNewX1 < $aFullScreen[0] Then
        $iNewX = $iNewX2
    EndIf
    WinMove($hGui_Preview, "", $iNewX, $aPosWin[1] + 50)
    GUISetState(@SW_SHOWNOACTIVATE, $hGui_Preview)
EndFunc ;==>ShowPreview

Func _GetImage($sFile, $iWH, $iBkClr = 0xFFFFFF)
    Local $hBmp1, $hBitmap, $hGraphic, $hImage, $iW, $iH, $aGS, $hBmp2, $aFTS
    $aFTS = FileGetTime($sFile)
    If @error Then Return SetError(1, 0, 0)
    $hBmp1 = _WinAPI_CreateBitmap($iWH, $iWH, 1, 32)
    $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBmp1)
    $hGraphic = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _WinAPI_DeleteObject($hBmp1)
    _GDIPlus_GraphicsClear($hGraphic, BitOR(0xFF000000, $iBkClr))
    $hImage = _GDIPlus_ImageLoadFromFile($sFile)
    $iW = _GDIPlus_ImageGetWidth($hImage)
    $iH = _GDIPlus_ImageGetHeight($hImage)
    GUICtrlSetData($idLabel_Info, StringRegExpReplace($sFile, ".*\\(.*)", "$1") & @LF & Round(FileGetSize($sFile) / 1024, 0) & " kb (" & $iW & " x " & $iH & ")" & @LF & $aFTS[0] & "/" & $aFTS[1] & "/" & $aFTS[2] & " " & $aFTS[3] & ":" & $aFTS[4] & ":" & $aFTS[5] & @LF & "Alpha: " & $bIsAlpha & ", Gray: " & $bIsGray)
    $aGS = _GetScale($iW, $iH, $iWH)
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, $aGS[0], $aGS[1], $aGS[2], $aGS[3])
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_GraphicsDispose($hGraphic)
    $hBmp2 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
    _GDIPlus_BitmapDispose($hBitmap)
    Return $hBmp2
EndFunc ;==>_GetImage

Func _GetScale($iW, $iH, $iWH)
    Local $aRet[4]
    If $iW <= $iWH And $iH <= $iWH Then
        $aRet[2] = $iW
        $aRet[3] = $iH
        $aRet[0] = ($iWH - $aRet[2]) / 2
        $aRet[1] = ($iWH - $aRet[3]) / 2
    ElseIf $iW > $iH Then
        $aRet[2] = $iWH
        $aRet[3] = $iH / ($iW / $iWH)
        $aRet[0] = 0
        $aRet[1] = ($iWH - $aRet[3]) / 2
    ElseIf $iW < $iH Then
        $aRet[2] = $iW / ($iH / $iWH)
        $aRet[3] = $iWH
        $aRet[0] = ($iWH - $aRet[2]) / 2
        $aRet[1] = 0
    ElseIf $iW = $iH Then
        $aRet[2] = $iWH
        $aRet[3] = $iWH
        $aRet[0] = 0
        $aRet[1] = 0
    EndIf
    Return $aRet
EndFunc ;==>_GetScale

Func _hBmpToPicControl($iCID, ByRef $hBmp, $iFlag = 0)
    Local $hOldBmp
    $hOldBmp = GUICtrlSendMsg($iCID, $STM_SETIMAGE, $IMAGE_BITMAP, $hBmp)
    If $hOldBmp Then _WinAPI_DeleteObject($hOldBmp)
    If $iFlag Then _WinAPI_DeleteObject($hBmp)
EndFunc ;==>_hBmpToPicControl

Func _GDIPlus_CreateHistogram($sRounding = "Ceiling")
    Local $iMaxL, $iMaxC, $iMaxR, $iMaxG, $iMaxB, $a, $r, $g, $b, $yR, $yG, $yB
    For $i = 1 + $bIsAlpha To 256
        If $bIsAlpha Then
;~          ConsoleWrite("Alpha: " & DllStructGetData($tStructChannel0, "channel0", $i) & @CRLF)
            $r = DllStructGetData($tStructChannel1, "channel1", $i)
            $yR = $r * $frY
            If DllStructGetData($tStructChannel1 , "channel1", $i) > $iMaxR Then $iMaxR = $r

            $g = DllStructGetData($tStructChannel2, "channel2", $i)
            $yG = $g * $fgY
            If DllStructGetData($tStructChannel2 , "channel2", $i) > $iMaxG Then $iMaxG = $g

            $b = DllStructGetData($tStructChannel3, "channel3", $i)
            $yB = $b * $fbY
            If DllStructGetData($tStructChannel3 , "channel3", $i) > $iMaxB Then $iMaxB = $b

            $fAverage_cRGB += $r + $g + $b
            $fAverage_L += $yR + $yG + $yB
        Else
            $r = DllStructGetData($tStructChannel0, "channel0", $i)
            $yR = $r * $frY
            If DllStructGetData($tStructChannel0 , "channel0", $i) > $iMaxR Then $iMaxR = $r

            $g = DllStructGetData($tStructChannel1, "channel1", $i)
            $yG = $g * $fgY
            If DllStructGetData($tStructChannel1 , "channel1", $i) > $iMaxG Then $iMaxG = $g

            $b = DllStructGetData($tStructChannel2, "channel2", $i)
            $yB = $b * $fbY
            If DllStructGetData($tStructChannel2 , "channel2", $i) > $iMaxB Then $iMaxB = $b
        EndIf

        $fAverage_cRGB += $r + $g + $b
        $fAverage_L += $yR + $yG + $yB

        $aLuminosity[$i] = $yR + $yG + $yB
        If $aLuminosity[$i] > $iMaxL Then $iMaxL = $aLuminosity[$i]

        $aCRGB[$i] = ($r + $g + $b) / 3
        If $aCRGB[$i] > $iMaxC Then $iMaxC = $aCRGB[$i]
    Next
    $fAverage_cRGB /= 256 * 3
    $fAverage_L /= 256

    _GDIPlus_GraphicsClear($hCtxt_HL, 0xFFFFFFFF)
    _GDIPlus_GraphicsClear($hCtxt_HC, 0xFFFFFFFF)
    _GDIPlus_GraphicsClear($hCtxt_HR, 0xFFFFFFFF)
    _GDIPlus_GraphicsClear($hCtxt_HG, 0xFFFFFFFF)
    _GDIPlus_GraphicsClear($hCtxt_HB, 0xFFFFFFFF)

    Local $iDL = 1, $iDC = 1, $iDR = 1, $iDG = 1, $iDB = 1
    Local $sRoundings = "Round,Ceiling,Floor,"
    If Not StringInStr($sRoundings, $sRounding) Then $sRounding = "Ceiling"
    If $iMaxL > 128 Then
;~      $iDL = Ceiling($iMaxL / 128)
        $iDL = Execute($sRounding & "(" & $iMaxL / 128 & ")")
    Else
        $iDL = 1 / (128 / $iMaxL)
    EndIf
    If $iMaxC > 128 Then
;~      $iDC = Ceiling($iMaxC / 128)
        $iDC = Execute($sRounding & "(" & $iMaxC / 128 & ")")
    Else
        $iDC = 1 / (128 / $iMaxC)
    EndIf
    If $iMaxR > 128 Then
;~      $iDR = Ceiling($iMaxR / 128)
        $iDR = Execute($sRounding & "(" & $iMaxR / 128 & ")")
    Else
        $iDR = 1 / (128 / $iMaxR)
    EndIf
    If $iMaxG > 128 Then
;~      $iDG = Ceiling($iMaxG / 128)
        $iDG = Execute($sRounding & "(" & $iMaxG / 128 & ")")
    Else
        $iDG = 1 / (128 / $iMaxG)
    EndIf
    If $iMaxB > 128 Then
;~      $iDB = Ceiling($iMaxB / 128)
        $iDB = Execute($sRounding & "(" & $iMaxB / 128 & ")")
    Else
        $iDB = 1 / (128 / $iMaxB)
    EndIf
    For $i = 1 To 256
        _GDIPlus_PenSetColor($hPen_H, 0xFF000000)
        _GDIPlus_GraphicsDrawLine($hCtxt_HL, $i - 1, 127, $i - 1, 127 - (Int($aLuminosity[$i] / $iDL)), $hPen_H)
        _GDIPlus_PenSetColor($hPen_H, 0xFF000000)
        _GDIPlus_GraphicsDrawLine($hCtxt_HC, $i - 1, 127, $i - 1, 127 - (Int($aCRGB[$i] / $iDC)), $hPen_H)
        _GDIPlus_PenSetColor($hPen_H, 0xFFB00000)
        If $bIsAlpha Then
            _GDIPlus_GraphicsDrawLine($hCtxt_HR, $i - 1, 127, $i - 1, 127 - (Int(DllStructGetData($tStructChannel1, "channel1", $i) / $iDR)), $hPen_H)
            _GDIPlus_PenSetColor($hPen_H, 0xFF00B000)
            _GDIPlus_GraphicsDrawLine($hCtxt_HG, $i - 1, 127, $i - 1, 127 - (Int(DllStructGetData($tStructChannel2, "channel2", $i) / $iDG)), $hPen_H)
            _GDIPlus_PenSetColor($hPen_H, 0xFF0000B0)
            _GDIPlus_GraphicsDrawLine($hCtxt_HB, $i - 1, 127, $i - 1, 127 - (Int(DllStructGetData($tStructChannel3, "channel3", $i) / $iDB)), $hPen_H)
        Else
            _GDIPlus_GraphicsDrawLine($hCtxt_HR, $i - 1, 127, $i - 1, 127 - (Int(DllStructGetData($tStructChannel0, "channel0", $i) / $iDR)), $hPen_H)
            _GDIPlus_PenSetColor($hPen_H, 0xFF00B000)
            _GDIPlus_GraphicsDrawLine($hCtxt_HG, $i - 1, 127, $i - 1, 127 - (Int(DllStructGetData($tStructChannel1, "channel1", $i) / $iDG)), $hPen_H)
            _GDIPlus_PenSetColor($hPen_H, 0xFF0000B0)
            _GDIPlus_GraphicsDrawLine($hCtxt_HB, $i - 1, 127, $i - 1, 127 - (Int(DllStructGetData($tStructChannel2, "channel2", $i) / $iDB)), $hPen_H)
        EndIf
    Next

EndFunc ;==>_GDIPlus_CreateHistogram

Func _GDIPlus_CreateColorGradient($sColorChannel, $iW, $iH, $bHBitmap = True)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iW, "int", $iH, "int", 0, "int", 0x0026200A, "ptr", 0, "int*", 0)
    Local $hCtxt = _GDIPlus_ImageGetGraphicsContext($aResult[6])
;~  _GDIPlus_GraphicsSetSmoothingMode($hCtxt, 2)
    Local $hPen = _GDIPlus_PenCreate()
    DllCall($ghGDIPDll, "uint", "GdipSetPenLineJoin", "handle", $hPen, "int", $iLineJoinBevel)
    Local $i, $c
    For $i = 0 To $iW
        $c = Hex($i, 2)
        Switch $sColorChannel
            Case "L"
                _GDIPlus_PenSetColor($hPen, "0xFF" & $c & $c & $c)
            Case "C"
                _GDIPlus_PenSetColor($hPen, "0xFF" & $c & $c & $c)
            Case "R"
                _GDIPlus_PenSetColor($hPen, "0xFF" & $c & "0000")
            Case "G"
                _GDIPlus_PenSetColor($hPen, "0xFF00" & $c & "00")
            Case "B"
                _GDIPlus_PenSetColor($hPen, "0xFF0000" & $c)
        EndSwitch
        _GDIPlus_GraphicsDrawLine($hCtxt, $i, 0, $i, $iH, $hPen)
    Next
    _GDIPlus_GraphicsDispose($hCtxt)
    _GDIPlus_PenDispose($hPen)
    If $bHBitmap Then
        Local $hHBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($aResult[6])
        _GDIPlus_BitmapDispose($aResult[6])
        Return $hHBmp
    EndIf
    Return $aResult[6]
EndFunc ;==>_GDIPlus_CreateColorGradient

;http://msdn.microsoft.com/en-us/library/windows/desktop/ms536307(v=vs.85).aspx
Func _GDIPlus_BitmapGetHistogram($hBitmap, $iFormat, $iGetHistogramSize, $pStructChannel0, $pStructChannel1, $pStructChannel2, $pStructChannel3 = 0)
    Local $aRes = DllCall($ghGDIPDll, "bool", "GdipBitmapGetHistogram", "handle", $hBitmap, "uint", $iFormat, "uint", $iGetHistogramSize, "struct*", $pStructChannel0, "struct*", $pStructChannel1, "struct*", $pStructChannel2, "struct*", $pStructChannel3)
    If @error Then Return SetError(1, @error, 0)
    Return 1
EndFunc ;==>_GDIPlus_BitmapGetHistogram

;http://msdn.microsoft.com/en-us/library/windows/desktop/ms536308(v=vs.85).aspx
Func _GDIPlus_BitmapGetHistogramSize($iFormat)
    Local $aRes = DllCall($ghGDIPDll, "int", "GdipBitmapGetHistogramSize", "uint", $iFormat, "dword*", 0)
    If @error Then Return SetError(1, @error, 0)
    Return $aRes[2]
EndFunc ;==>_GDIPlus_BitmapGetHistogramSize

Func _GDIPlus11_Startup() ;code by Authenticity - modified by UEZ
    Local $pInput, $tInput, $pToken, $tToken, $aResult, $os

    $giGDIPRef += 1
    If $giGDIPRef > 1 Then Return True

    Switch @OSVersion
        Case "WIN_VISTA", "WIN_2008"
            $ghGDIPDll = DllOpen(@WindowsDir & "\winsxs\x86_microsoft.windows.gdiplus_6595b64144ccf1df_1.1.6000.16386_none_8df21b8362744ace\gdiplus.dll")
        Case "WIN_2008R2", "WIN_7", "WIN_8"
            $ghGDIPDll = DllOpen(@SystemDir & "\gdiplus.dll")
        Case Else
            Return SetError(1)
    EndSwitch
;~ _WinAPI_Check("_GDIPlus_Startup (GDIPlus.dll not found)", @error, False)

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

Download: GDI+ Show Histogram.au3 (80 downloads previously)

GdipBitmapGetHistogram(), GdipBitmapGetHistogramSize() and 2 more GDI+ functions requires GDI+ v1.1 which means this will only run on Vista or higher operating systems.

I hope the values are correct especially the value for luminosity.

Br,

UEZ

There is no explanation in this topic UEZ :P

صرح السماء كان هنا

 

Share this post


Link to post
Share on other sites

:shocked:

Is this not enough?

Here a little tool to display the histogram of an image...

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
Quote

Change that to $__g_hGDIPDll 

I don't like bringing up old threads, but I just saw a topic—from 2010—that addressed this same problem.

Well, I made the above changes to this very worthwhile histogram utility ... and it runs ... but the histogram area is always blank. (The file, itself, reads and displays.)

Has anyone updated this to produce a working result?

Thanks for any help.

 

Share this post


Link to post
Share on other sites

Try the updated version from 2015 -> see post#1. It still runs with current and beta version properly (3.3.14.5 / 3.3.15.1).

 


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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

UEZ, thanks for your quick response. It now runs (after I removed the wrapper statements) but the histogram doesn't seem right for the page I'm testing. Everything seems skewed to the right.

Any ideas for what to look for?

Histogram.PNG.a741f6d05e98f375d9b4ba6d7ac4aae2.PNG

Share this post


Link to post
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
Sign in to follow this  

  • Similar Content

    • By UEZ
      Here a little script to load a TGA image file and create a GDI+ bitmap. Currently supported TGA formats are  1/8/15/16/24 and 32-bit.
      As v0.85 is written completely in AutoIt, it might take some time to convert larger 8/15/16/24/32-bit images. ☕
       
      _GDIPlus_TGAImageLoadFromFile.au3 UDF
      v0.85 without assembler acceleration code but with RLE support:
      ;Coded by UEZ #AutoIt3Wrapper_UseX64=n #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <WinAPIFiles.au3> ; #FUNCTION# ==================================================================================================================== ; Name ..........: _GDIPlus_TGAImageLoadFromFile ; Description ...: Loads a TGA compressed (RLE) / uncompressed image file (1/8/15/16/24/32-bit) and converts it to a GDI+ bitmap format. ; Syntax ........: _GDIPlus_TGAImageLoadFromFile($sFile[, $bPrintInfo = False.]) ; Parameters ....: $sFile - TGA file name to load from disk. ; $bPrintInfo - [optional] Prints some information about the TGA image to console. Default is False. ; Return values .: Success: GDI+ bitmap handle ; Failure: error 1 - file cannot be opened ; error 2 - TGA image is not in one of these formats: 1/8/15/16/24/32-bit ; error 3 - unsupported TGA image type ; error 4 - unable to read file to struct ; error 5 - unknown TGA pixel depth ; error 6 - return bitmap cannot be created ; Version .......: v0.85 build 2019-11-08 beta ; Author ........: UEZ ; Remarks .......: 8/15/16/24/32-bit images might be slow on converting ^^ ; Related .......: _GDIPlus_BitmapCreateFromScan0, _GDIPlus_ImageRotateFlip, DllStructCreate, _WinAPI_CreateFile, _WinAPI_SetFilePointer ; Link ..........: https://www.loc.gov/preservation/digital/formats/fdd/fdd000180.shtml, http://www.fileformat.info/format/tga/egff.htm ; Example .......: Yes ; =============================================================================================================================== Func _GDIPlus_TGAImageLoadFromFile($sFile, $bPrintInfo = False) Local Const $hFile = _WinAPI_CreateFile($sFile, 2, 2) If Not $hFile Then Return SetError(1, 0, 0) Local Const $tagTGAHeader = "align 1;byte idLength;byte colormapType;byte imageType;word firstEntryIndex;word colormapLength;byte colormapEntrySize;word xOrigin;word yOrigin;word width;word height;byte pixelDepth;byte imageDescriptor" Local Const $tagTGAFooter = "dword extAreaOffset;dword devDirOffset;byte imageID[18]" Local Const $tagTGAExtention = "align 1;word extSize;byte authorName[41];byte authorComments[324];word timeM;word timeD;word timeY;word timeHr;word timeMin;word timeSec;byte jobName[41];word jobTimeHr;word jobTimeMin;word jobTimeSec;byte swID[41];word swVersionNr;byte swVersionLetter;long keyColor;word pxAspectRatioNum;word pxAspectRatioDom;word gammaNum;word gammaDom;dword colCorrOffset;dword postStampOffset;dword scanLineOffset;byte attribType" Local Const $tTGAHeader = DllStructCreate($tagTGAHeader) Local $tTGAFooter = DllStructCreate($tagTGAFooter) Local Const $tTGAExtention = DllStructCreate($tagTGAExtention) Local $dwBytesRead, $tTGAImageID, $tagTGAImageID, $iColorValuesStartPos = 0 _WinAPI_ReadFile($hFile, $tTGAHeader, DllStructGetSize($tTGAHeader), $dwBytesRead) $iColorValuesStartPos += $dwBytesRead If $tTGAHeader.idLength > 0 Then $tagTGAImageID = "byte imageID[" & $tTGAHeader.idLength & "]" $tTGAImageID = DllStructCreate($tagTGAImageID) _WinAPI_ReadFile($hFile, $tTGAImageID, $tTGAHeader.idLength, $dwBytesRead) $iColorValuesStartPos += $dwBytesRead EndIf Local Const $iPxDepth = $tTGAHeader.pixelDepth If Not BitOR($iPxDepth = 32, $iPxDepth = 24, $iPxDepth = 16, $iPxDepth = 15, $iPxDepth = 8, $iPxDepth = 1) Then _WinAPI_CloseHandle($hFile) Return SetError(2, 0, 0) EndIf #cs ImageType Image Data Type Colormap Encoding 0 No image data included in file No No 1 Colormapped image data Yes No 2 Truecolor image data No No 3 Monochrome image data No No 9 Colormapped image data Yes Yes 10 Truecolor image data No Yes 11 Monochrome image data No Yes #ce If Not BitOR($tTGAHeader.imageType = 0x01, $tTGAHeader.imageType = 0x02, $tTGAHeader.imageType = 0x03, $tTGAHeader.imageType = 0x09, $tTGAHeader.imageType = 0x0A, $tTGAHeader.imageType = 0x0B) Then _WinAPI_CloseHandle($hFile) Return SetError(3, 0, 0) EndIf Local $iW = $tTGAHeader.width, $iH = $tTGAHeader.height, $colorwidth = $tTGAHeader.colormapEntrySize / 8, _ $colorTblSize = $tTGAHeader.colormapLength * $colorwidth Local $dwBufferSize = FileGetSize($sFile) Local $tSrcBmp = DllStructCreate("ubyte color[" & $dwBufferSize & "]") _WinAPI_ReadFile($hFile, $tSrcBmp, $dwBufferSize, $dwBytesRead) _WinAPI_SetFilePointer($hFile, -26, $FILE_END) _WinAPI_ReadFile($hFile, $tTGAFooter, 26, $dwBytesRead) Local $sFooter = StringTrimRight(BinaryToString($tTGAFooter.imageID), 1), $iOffset = 0, $iOffset2, $iOffset3 If Not StringCompare($sFooter, "TRUEVISION-XFILE.") Then ;read extension information to struct if available $iOffset = $tTGAFooter.extAreaOffset _WinAPI_SetFilePointer($hFile, $iOffset, $FILE_BEGIN) _WinAPI_ReadFile($hFile, $tTGAExtention, 0x01EF, $dwBytesRead) Else $tTGAFooter.extAreaOffset = 0 EndIf _WinAPI_CloseHandle($hFile) If $dwBytesRead = 0 Then Return SetError(4, _WinAPI_GetLastError(), 0) Local $bRLE = BitOR($tTGAHeader.imageType = 0x09, $tTGAHeader.imageType = 0x0A, $tTGAHeader.imageType = 0x0B) If $bPrintInfo Then ConsoleWrite("idLength: " & $tTGAHeader.idLength & @CRLF) ConsoleWrite("colormapType: " & $tTGAHeader.colormapType & @CRLF) ConsoleWrite("imageType: " & $tTGAHeader.imageType & @CRLF) ConsoleWrite("firstEntryIndex: " & $tTGAHeader.firstEntryIndex & @CRLF) ConsoleWrite("colormapLength: " & $tTGAHeader.colormapLength & @CRLF) ConsoleWrite("colormapEntrySize: " & $tTGAHeader.colormapEntrySize & @CRLF) ConsoleWrite("xOrigin: " & $tTGAHeader.xOrigin & @CRLF) ConsoleWrite("yOrigin: " & $tTGAHeader.yOrigin & @CRLF) ConsoleWrite("width: " & $tTGAHeader.width & @CRLF) ConsoleWrite("height: " & $tTGAHeader.height & @CRLF) ConsoleWrite("pixelDepth: " & $iPxDepth & @CRLF) ConsoleWrite("imageDescriptor: " & $tTGAHeader.imageDescriptor & @CRLF) If $tTGAHeader.idLength > 0 Then ConsoleWrite("ImageID: " & RemoveNullChars($tTGAImageID.imageID) & @CRLF) If $iOffset Then ConsoleWrite("authorName: " & RemoveNullChars($tTGAExtention.authorName) & @CRLF) ConsoleWrite("authorComments: " & RemoveNullChars($tTGAExtention.authorComments) & @CRLF) ConsoleWrite("jobName: " & RemoveNullChars($tTGAExtention.jobName) & @CRLF) ConsoleWrite("swID: " & RemoveNullChars($tTGAExtention.swID) & @CRLF) EndIf ConsoleWrite("RLE packed: " & $bRLE & @CRLF) EndIf Local Static $tDestBmp ;must be static otherwise bitmap data might get corrupted or in worst case script will crash Local $stride, $iPixelFormat Switch $iPxDepth Case 1 ;1-bit $iPixelFormat = $GDIP_PXF01INDEXED $stride = BitAND(($iW * 1) + 1, BitNOT(1)) $tDestBmp = DllStructCreate("uint color[" & $stride * $iH & "];") Case 8, 24 $iPixelFormat = $GDIP_PXF24RGB $stride = BitAND(($iW * 3) + 3, BitNOT(3)) $tDestBmp = DllStructCreate("ubyte color[" & $stride * $iH & "];") Case 15, 16 $iPixelFormat = $GDIP_PXF16RGB555 $stride = BitAND(($iW * 2) + 2, BitNOT(2)) $tDestBmp = DllStructCreate("ubyte color[" & $stride * $iH & "];") Case 32 $iPixelFormat = $GDIP_PXF32ARGB $stride = $iW * 4 $tDestBmp = DllStructCreate("ubyte color[" & $stride * $iH & "];") Case Else Return SetError(5, 0, 0) EndSwitch If Mod($stride, 4) <> 0 Then $stride += 4 - Mod($stride, 4) Local Const $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH, $iPixelFormat, $stride, $tDestBmp) If @error Or Not $hBitmap Then Return SetError(6, @error, 0) Local $c, $q, $x, $y, $t1, $t2, $t3, $t4, $col, $red, $green, $blue, $alpha, $iLen, $iStart, $iEnd, $iLength, $iWW Local Const $hDLL = DllOpen("msvcrt.dll") Switch $iPxDepth Case 1 ;1-bit For $y = 0 To $iH - 1 $t1 = $y * $stride DllCall($hDLL, "ptr:cdecl", "memcpy", "ptr", DllStructGetPtr($tDestBmp) + $t1, "ptr", DllStructGetPtr($tSrcBmp) + BitShift($t1, 3), "uint", $stride) Next Case 8 ;8-bit ;if a color table is available, just use it If $tTGAHeader.colormapType = 1 Then Local $tMapColorTbl = DllStructCreate("ubyte bgr[" & $colorTblSize & "]", DllStructGetPtr($tSrcBmp, "color") + $tTGAHeader.firstEntryIndex) Switch $bRLE Case 0 For $y = 0 To ($iH - 1) $iOffset = $y * $iW + $colorTblSize $iOffset2 = $y * $stride For $x = 0 To ($iW - 1) $t1 = $iOffset2 + $x * 3 $t2 = $tSrcBmp.color($iOffset + $x + 1) * $colorwidth Switch $colorwidth Case 3, 4 $tDestBmp.color($t1 + 1) = $tMapColorTbl.bgr($t2 + 1) $tDestBmp.color($t1 + 2) = $tMapColorTbl.bgr($t2 + 2) $tDestBmp.color($t1 + 3) = $tMapColorTbl.bgr($t2 + 3) Case 2 ;convert from RGB555 to RGB $col = BitOR(BitShift($tMapColorTbl.bgr($t2 + 2), -8), $tMapColorTbl.bgr($t2 + 1)) ;RGB555 $tDestBmp.color($t1 + 1) = BitShift(BitAND($col, 0x001F), -3) ;B $tDestBmp.color($t1 + 2) = BitShift(BitShift(BitAND($col, 0x03E0), 5), -3) ;G $tDestBmp.color($t1 + 3) = BitShift(BitShift(BitAND($col, 0x7C00), 10), -3) ;R EndSwitch Next Next Case Else ;RLE encoded TGA images $c = 0 $x = 0 $y = 0 $iOffset = $colorTblSize + 1 $iStart = Int($iColorValuesStartPos + $colorTblSize) $iEnd = $tTGAFooter.extAreaOffset > 0 ? $tTGAFooter.extAreaOffset : $dwBufferSize $iLength = $iEnd - $iStart - 1 $iWW = $iW - 1 $t3 = $colorwidth = 2 ? 2 : 3 While $c <= $iLength $iOffset2 = Int($tSrcBmp.color($iOffset + $c)) $iLen = BitAND($iOffset2, 0x7F) + 1 If BitAND($iOffset2, 0x80) Then ; check for packet format ;run length packet format $c += 1 $iOffset3 = Int($tSrcBmp.color($iOffset + $c)) * $t3 $t2 = $y * $stride For $q = 1 To $iLen $t1 = $t2 + $x * 3 Switch $colorwidth Case 3, 4 $tDestBmp.color($t1 + 1) = $tMapColorTbl.bgr($iOffset3 + 1) $tDestBmp.color($t1 + 2) = $tMapColorTbl.bgr($iOffset3 + 2) $tDestBmp.color($t1 + 3) = $tMapColorTbl.bgr($iOffset3 + 3) Case 2 ;convert from RGB555 to RGB $col = BitOR(BitShift($tMapColorTbl.bgr($iOffset3 + 2), -8), $tMapColorTbl.bgr($iOffset3 + 1)) ;RGB555 $tDestBmp.color($t1 + 1) = BitShift(BitAND($col, 0x001F), -3) ;B $tDestBmp.color($t1 + 2) = BitShift(BitShift(BitAND($col, 0x03E0), 5), -3) ;G $tDestBmp.color($t1 + 3) = BitShift(BitShift(BitAND($col, 0x7C00), 10), -3) ;R EndSwitch $x += 1 If $x > $iWW Then $x = 0 $y += 1 $t2 = $y * $stride EndIf Next $c += 1 Else ;raw packet format $c += 1 $t2 = $y * $stride For $q = 1 To $iLen $iOffset3 = Int($tSrcBmp.color($iOffset + $c)) * $t3 $t1 = $t2 + $x * 3 Switch $colorwidth Case 3, 4 $tDestBmp.color($t1 + 1) = $tMapColorTbl.bgr($iOffset3 + 1) $tDestBmp.color($t1 + 2) = $tMapColorTbl.bgr($iOffset3 + 2) $tDestBmp.color($t1 + 3) = $tMapColorTbl.bgr($iOffset3 + 3) Case 2 ;convert from RGB555 to RGB $col = BitOR(BitShift($tMapColorTbl.bgr($iOffset3 + 2), -8), $tMapColorTbl.bgr($iOffset3 + 1)) ;RGB555 $tDestBmp.color($t1 + 1) = BitShift(BitAND($col, 0x001F), -3) ;B $tDestBmp.color($t1 + 2) = BitShift(BitShift(BitAND($col, 0x03E0), 5), -3) ;G $tDestBmp.color($t1 + 3) = BitShift(BitShift(BitAND($col, 0x7C00), 10), -3) ;R EndSwitch $x += 1 If $x > $iWW Then $x = 0 $y += 1 $t2 = $y * $stride EndIf $c += 1 Next EndIf WEnd EndSwitch Else ;convert it to grayscale Switch $bRLE Case 0 For $y = 0 To $iH - 1 $iOffset = $y * $iW + $colorTblSize $iOffset2 = $y * $stride For $x = 0 To $iW - 1 $t1 = $iOffset + $x - 2 $t2 = $iOffset2 + $x * 3 $blue = $tSrcBmp.color($t1 + 1) $green = $tSrcBmp.color($t1 + 2) $red = $tSrcBmp.color($t1 + 3) $col = $red $col = $col < 0 ? 0 : $col > 255 ? 255 : $col $tDestBmp.color($t2 + 1) = $col $tDestBmp.color($t2 + 2) = $col $tDestBmp.color($t2 + 3) = $col Next Next Case Else $c = 0 $x = 0 $y = 0 $iOffset = $colorTblSize + 1 $iStart = Int($iColorValuesStartPos + $colorTblSize) $iEnd = $tTGAFooter.extAreaOffset > 0 ? $tTGAFooter.extAreaOffset : $dwBufferSize $iLength = $iEnd - $iStart - 1 $iWW = $iW - 1 While $c <= $iLength $iOffset2 = Int($tSrcBmp.color($iOffset + $c)) $iLen = BitAND($iOffset2, 0x7F) + 1 If BitAND($iOffset2, 0x80) Then ; check for packet format ;run length packet format $c += 1 $iOffset3 = Int($tSrcBmp.color($iOffset + $c)) * 3 $blue = $iOffset3 $green = $iOffset3 + 1 $red = $iOffset3 + 2 $col = ($red + $green + $blue) / 9 $col = $col < 0 ? 0 : $col > 255 ? 255 : $col $t2 = $y * $stride For $q = 1 To $iLen $t1 = $t2 + $x * 3 $tDestBmp.color($t1 + 1) = $col $tDestBmp.color($t1 + 2) = $col $tDestBmp.color($t1 + 3) = $col $x += 1 If $x > $iWW Then $x = 0 $y += 1 $t2 = $y * $stride EndIf Next $c += 1 Else ;raw packet format $c += 1 $t2 = $y * $stride For $q = 1 To $iLen $iOffset3 = Int($tSrcBmp.color($iOffset + $c)) * 3 $blue = $iOffset3 $green = $iOffset3 + 1 $red = $iOffset3 + 2 $col = ($red + $green + $blue) / 9 $col = $col < 0 ? 0 : $col > 255 ? 255 : $col $t1 = $t2 + $x * 3 $tDestBmp.color($t1 + 1) = $col $tDestBmp.color($t1 + 2) = $col $tDestBmp.color($t1 + 3) = $col $x += 1 If $x > $iWW Then $x = 0 $y += 1 $t2 = $y * $stride EndIf $c += 1 Next EndIf WEnd EndSwitch EndIf Case 15, 16, 24, 32 ;15/16/24/32-bit, as the bitmap format is the same we can use memcpy to copy the pixel data directly to the memory. ;Exeptions are 15/16/24-bit images whose width is not a divider of 4! If BitOR($iPxDepth = 15, $iPxDepth = 16, $iPxDepth = 24) Then If BitOR(Mod($iW, 4), $bRLE) Then Switch $iPxDepth Case 15, 16 Switch $bRLE Case 0 $t4 = $iW * 2 For $y = 0 To ($iH - 1) $iOffset = $y * $t4 $iOffset2 = $y * $stride For $x = 0 To ($iW - 1) $t3 = $x * 2 $t1 = $iOffset + $t3 $t2 = $iOffset2 + $t3 ;RGB555 $tDestBmp.color($t2 + 1) = $tSrcBmp.color($t1 + $colorTblSize + 1) $tDestBmp.color($t2 + 2) = $tSrcBmp.color($t1 + $colorTblSize + 2) Next Next Case Else $c = 0 $x = 0 $y = 0 $iStart = Int($iColorValuesStartPos + $colorTblSize) $iEnd = $tTGAFooter.extAreaOffset > 0 ? $tTGAFooter.extAreaOffset : $dwBufferSize $iLength = $iEnd - $iStart - 1 $iWW = $iW - 1 While $c <= $iLength $iOffset2 = Int($tSrcBmp.color($colorTblSize + $c + 1)) $iLen = BitAND($iOffset2, 0x7F) + 1 If BitAND($iOffset2, 0x80) Then ; check for packet format ;run length packet format $c += 1 $t3 = $y * $stride For $q = 1 To $iLen $t1 = $t3 + $x * 2 $t2 = $colorTblSize + $c $tDestBmp.color($t1 + 1) = $tSrcBmp.color($t2 + 1) $tDestBmp.color($t1 + 2) = $tSrcBmp.color($t2 + 2) $x += 1 If $x > $iWW Then $x = 0 $y += 1 $t3 = $y * $stride EndIf Next $c += 2 Else ;raw packet format $c += 1 $t3 = $y * $stride For $q = 1 To $iLen $t1 = $t3 + $x * 2 $t2 = $colorTblSize + $c $tDestBmp.color($t1 + 1) = $tSrcBmp.color($t2 + 1) $tDestBmp.color($t1 + 2) = $tSrcBmp.color($t2 + 2) $x += 1 If $x > $iWW Then $x = 0 $y += 1 $t3 = $y * $stride EndIf $c += 2 Next EndIf WEnd EndSwitch Case 24 Switch $bRLE Case 0 $t4 = $iW * 3 For $y = 0 To $iH - 1 $iOffset = $y * $t4 $iOffset2 = $y * $stride For $x = 0 To ($iW - 1) $t3 = $x * 3 $t1 = $iOffset + $t3 $blue = $tSrcBmp.color($t1 + 1) $green = $tSrcBmp.color($t1 + 2) $red = $tSrcBmp.color($t1 + 3) $t2 = $iOffset2 + $t3 $tDestBmp.color($t2 + 1) = $blue $tDestBmp.color($t2 + 2) = $green $tDestBmp.color($t2 + 3) = $red Next Next Case Else $c = 0 $x = 0 $y = 0 $iStart = Int($iColorValuesStartPos + $colorTblSize) $iEnd = $tTGAFooter.extAreaOffset > 0 ? $tTGAFooter.extAreaOffset : $dwBufferSize $iLength = $iEnd - $iStart - 1 $iWW = $iW - 1 While $c <= $iLength $iOffset2 = Int($tSrcBmp.color($c + 1)) $iLen = BitAND($iOffset2, 0x7F) + 1 If BitAND($iOffset2, 0x80) Then ; check for packet format ;run length packet format $c += 1 $blue = $tSrcBmp.color($c + 1) $green = $tSrcBmp.color($c + 2) $red = $tSrcBmp.color($c + 3) $t2 = $y * $stride For $q = 1 To $iLen $t1 = $t2 + $x * 3 $tDestBmp.color($t1 + 1) = $blue $tDestBmp.color($t1 + 2) = $green $tDestBmp.color($t1 + 3) = $red $x += 1 If $x > $iWW Then $x = 0 $y += 1 $t2 = $y * $stride EndIf Next $c += 3 Else ;raw packet format $c += 1 $t2 = $y * $stride For $q = 1 To $iLen $blue = $tSrcBmp.color($c + 1) $green = $tSrcBmp.color($c + 2) $red = $tSrcBmp.color($c + 3) $t1 = $t2 + $x * 3 $tDestBmp.color($t1 + 1) = $blue $tDestBmp.color($t1 + 2) = $green $tDestBmp.color($t1 + 3) = $red $x += 1 If $x > $iWW Then $x = 0 $y += 1 $t2 = $y * $stride EndIf $c += 3 Next EndIf WEnd EndSwitch EndSwitch Else For $y = 0 To $iH - 1 $t1 = $y * $stride DllCall($hDLL, "ptr:cdecl", "memcpy", "ptr", DllStructGetPtr($tDestBmp) + $t1, "ptr", DllStructGetPtr($tSrcBmp) + $t1, "uint", $stride) Next EndIf Else Switch $bRLE Case 0 For $y = 0 To $iH - 1 $t1 = $y * $stride DllCall($hDLL, "ptr:cdecl", "memcpy", "ptr", DllStructGetPtr($tDestBmp) + $t1, "ptr", DllStructGetPtr($tSrcBmp) + $t1, "uint", $stride) Next Case Else $c = 0 $x = 0 $y = 0 $iStart = Int($iColorValuesStartPos + $colorTblSize) $iEnd = $tTGAFooter.extAreaOffset > 0 ? $tTGAFooter.extAreaOffset : $dwBufferSize $iLength = $iEnd - $iStart - 1 $iWW = $iW - 1 While $c <= $iLength $iOffset2 = Int($tSrcBmp.color($c + 1)) $iLen = BitAND($iOffset2, 0x7F) + 1 If BitAND($iOffset2, 0x80) Then ; check for packet format ;run length packet format $c += 1 $blue = $tSrcBmp.color($c + 1) $green = $tSrcBmp.color($c + 2) $red = $tSrcBmp.color($c + 3) $alpha = $tSrcBmp.color($c + 4) $t2 = $y * $stride For $q = 1 To $iLen $t1 = $t2 + $x * 4 $tDestBmp.color($t1 + 1) = $blue $tDestBmp.color($t1 + 2) = $green $tDestBmp.color($t1 + 3) = $red $tDestBmp.color($t1 + 4) = $alpha $x += 1 If $x > $iWW Then $x = 0 $y += 1 $t2 = $y * $stride EndIf Next $c += 4 Else ;raw packet format $c += 1 $t2 = $y * $stride For $q = 1 To $iLen $blue = $tSrcBmp.color($c + 1) $green = $tSrcBmp.color($c + 2) $red = $tSrcBmp.color($c + 3) $alpha = $tSrcBmp.color($c + 4) $t1 = $t2 + $x * 4 $tDestBmp.color($t1 + 1) = $blue $tDestBmp.color($t1 + 2) = $green $tDestBmp.color($t1 + 3) = $red $tDestBmp.color($t1 + 4) = $alpha $x += 1 If $x > $iWW Then $x = 0 $y += 1 $t2 = $y * $stride EndIf $c += 4 Next EndIf WEnd EndSwitch EndIf EndSwitch DllClose($hDLL) ;TGA image is stored bottom up in file. Need to flip it. If BitAND($tTGAHeader.imageDescriptor, 0x30) <> 0x20 Then _GDIPlus_ImageRotateFlip($hBitmap, $GDIP_Rotate180FlipX) $tSrcBmp = 0 Return $hBitmap EndFunc ;==>_GDIPlus_TGAImageLoadFromFile ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name ..........: RemoveNullChars ; Description ...: Converts a null terminated binary string to a string ; Author ........: UEZ ; =============================================================================================================================== Func RemoveNullChars($bin) Local $a = StringRegExp($bin, "[[:xdigit:]+]{2}", 3), $s, $i If @error Then Return $s For $i = 0 To UBound($a) - 1 If $a[$i] = "00" Then ExitLoop $s &= Chr(Dec($a[$i])) Next Return $s EndFunc ;==>RemoveNullChars ;------------- Example ------------- Global $sFile = FileOpenDialog("Select a TGA file", "", "TGA image(*.tga)") If @error Then Exit _GDIPlus_Startup() Global $endtime, $timer = TimerInit() Global $hImage = _GDIPlus_TGAImageLoadFromFile($sFile, True) If @error Then ConsoleWrite(@error & " / " & @extended & @CRLF) _GDIPlus_Shutdown() Exit EndIf $endtime = TimerDiff($timer) ;~ _GDIPlus_ImageSaveToFile($hImage, @ScriptDir & "\Converted.png") ;~ ShellExecute(@ScriptDir & "\Converted.png") Global $iW = _GDIPlus_ImageGetWidth($hImage), $iH = _GDIPlus_ImageGetHeight($hImage) Global $hGui = GUICreate("TGA Image Loader by UEZ", $iW, $iH) GUISetState() Global $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui) _GDIPlus_GraphicsDrawImageRect($hGraphics, $hImage, 0, 0, $iW, $iH) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE _GDIPlus_BitmapDispose($hImage) _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_Shutdown() Exit Case $GUI_EVENT_RESTORE _GDIPlus_GraphicsDrawImageRect($hGraphics, $hImage, 0, 0, $iW, $iH) EndSwitch WEnd  
      v0.80 with assembler acceleration (thanks to AndyG for Assembleit2) but without RLE support yet:
      ;Coded by UEZ #AutoIt3Wrapper_Compile_Both=y #AutoIt3Wrapper_UseX64=n #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <Memory.au3> #include <WinAPIFiles.au3> ; #FUNCTION# ==================================================================================================================== ; Name ..........: _GDIPlus_TGAImageLoadFromFile ; Description ...: Loads an uncompressed TGA image file (1/8/15/16/24/32-bit) and converts it to a GDI+ bitmap format. ; Syntax ........: _GDIPlus_TGAImageLoadFromFile($sFile[, $bPrintInfo = False.]) ; Parameters ....: $sFile - TGA file name to load from disk. ; $bPrintInfo - [optional] Prints some information about the TGA image to console. Default is False. ; Return values .: Success: GDI+ bitmap handle ; Failure: error 1 - file cannot be opened ; error 2 - TGA image is not in one of these formats: 1/8/15/16/24/32-bit ; error 3 - unsupported TGA image type ; error 4 - unable to read file to struct ; error 5 - unknown TGA pixel depth ; error 6 - return bitmap cannot be created ; Version .......: v0.80 build 2019-10-23 beta ; Author ........: UEZ - thanks to AndyG for Assembleit2 ; Remarks .......: No RLE compressed TGA image support yet! ; Related .......: _GDIPlus_BitmapCreateFromScan0, _GDIPlus_ImageRotateFlip, DllStructCreate, _WinAPI_CreateFile, _WinAPI_SetFilePointer ; Link ..........: https://www.loc.gov/preservation/digital/formats/fdd/fdd000180.shtml, http://www.fileformat.info/format/tga/egff.htm ; Example .......: Yes ; =============================================================================================================================== Func _GDIPlus_TGAImageLoadFromFile($sFile, $bPrintInfo = False) Local Const $hFile = _WinAPI_CreateFile($sFile, 2, 2) If Not $hFile Then Return SetError(1, 0, 0) Local Const $tagTGAHeader = "align 1;byte idLength;byte colormapType;byte imageType;word firstEntryIndex;word colormapLength;byte colormapEntrySize;word xOrigin;word yOrigin;word width;word height;byte pixelDepth;byte imageDescriptor" Local Const $tagTGAFooter = "dword extAreaOffset;dword devDirOffset;byte imageID[18]" Local Const $tagTGAExtention = "align 1;word extSize;byte authorName[41];byte authorComments[324];word timeM;word timeD;word timeY;word timeHr;word timeMin;word timeSec;byte jobName[41];word jobTimeHr;word jobTimeMin;word jobTimeSec;byte swID[41];word swVersionNr;byte swVersionLetter;long keyColor;word pxAspectRatioNum;word pxAspectRatioDom;word gammaNum;word gammaDom;dword colCorrOffset;dword postStampOffset;dword scanLineOffset;byte attribType" Local Const $tTGAHeader = DllStructCreate($tagTGAHeader) Local Const $tTGAFooter = DllStructCreate($tagTGAFooter) Local Const $tTGAExtention = DllStructCreate($tagTGAExtention) Local $dwBytesRead, $tTGAImageID, $tagTGAImageID _WinAPI_ReadFile($hFile, $tTGAHeader, DllStructGetSize($tTGAHeader), $dwBytesRead) If $tTGAHeader.idLength > 0 Then $tagTGAImageID = "byte imageID[" & $tTGAHeader.idLength & "]" $tTGAImageID = DllStructCreate($tagTGAImageID) _WinAPI_ReadFile($hFile, $tTGAImageID, $tTGAHeader.idLength, $dwBytesRead) EndIf Local Const $iPxDepth = $tTGAHeader.pixelDepth If Not BitOR($iPxDepth = 32, $iPxDepth = 24, $iPxDepth = 16, $iPxDepth = 15, $iPxDepth = 8, $iPxDepth = 1) Then _WinAPI_CloseHandle($hFile) Return SetError(2, 0, 0) EndIf #cs ImageType Image Data Type Colormap Encoding 0 No image data included in file No No 1 Colormapped image data Yes No 2 Truecolor image data No No 3 Monochrome image data No No 9 Colormapped image data Yes Yes 10 Truecolor image data No Yes 11 Monochrome image data No Yes #ce If Not BitOR($tTGAHeader.imageType = 0x01, $tTGAHeader.imageType = 0x02, $tTGAHeader.imageType = 0x03) Then _WinAPI_CloseHandle($hFile) Return SetError(3, 0, 0) EndIf Local $iW = $tTGAHeader.width, $iH = $tTGAHeader.height, $bytesPerPixel = $iPxDepth / 8, $colorwidth = $tTGAHeader.colormapEntrySize / 8, _ $colorTblSize = $tTGAHeader.colormapLength * $colorwidth If $tTGAHeader.colormapEntrySize < 24 Then $bytesPerPixel = 4 Local Const $dwBufferSize = FileGetSize($sFile) Local $tSrcBmp = DllStructCreate("ubyte color[" & $dwBufferSize + $colorTblSize & "]") _WinAPI_ReadFile($hFile, $tSrcBmp, $dwBufferSize + $colorTblSize, $dwBytesRead) _WinAPI_SetFilePointer($hFile, -26, $FILE_END) _WinAPI_ReadFile($hFile, $tTGAFooter, 26, $dwBytesRead) Local $sFooter = StringTrimRight(BinaryToString($tTGAFooter.imageID), 1), $iOffset = 0, $iOffset2 If Not StringCompare($sFooter, "TRUEVISION-XFILE.") Then ;read extension information to struct if available $iOffset = $tTGAFooter.extAreaOffset _WinAPI_SetFilePointer($hFile, $iOffset, $FILE_BEGIN) _WinAPI_ReadFile($hFile, $tTGAExtention, 0x01EF, $dwBytesRead) EndIf _WinAPI_CloseHandle($hFile) If $dwBytesRead = 0 Then Return SetError(4, _WinAPI_GetLastError(), 0) If $bPrintInfo Then ConsoleWrite("idLength: " & $tTGAHeader.idLength & @CRLF) ConsoleWrite("colormapType: " & $tTGAHeader.colormapType & @CRLF) ConsoleWrite("imageType: " & $tTGAHeader.imageType & @CRLF) ConsoleWrite("firstEntryIndex: " & $tTGAHeader.firstEntryIndex & @CRLF) ConsoleWrite("colormapLength: " & $tTGAHeader.colormapLength & @CRLF) ConsoleWrite("colormapEntrySize: " & $tTGAHeader.colormapEntrySize & @CRLF) ConsoleWrite("xOrigin: " & $tTGAHeader.xOrigin & @CRLF) ConsoleWrite("yOrigin: " & $tTGAHeader.yOrigin & @CRLF) ConsoleWrite("width: " & $tTGAHeader.width & @CRLF) ConsoleWrite("height: " & $tTGAHeader.height & @CRLF) ConsoleWrite("pixelDepth: " & $iPxDepth & @CRLF) ConsoleWrite("imageDescriptor: " & $tTGAHeader.imageDescriptor & @CRLF) If $tTGAHeader.idLength > 0 Then ConsoleWrite("ImageID: " & RemoveNullChars($tTGAImageID.imageID) & @CRLF) If $iOffset Then ConsoleWrite("authorName: " & RemoveNullChars($tTGAExtention.authorName) & @CRLF) ConsoleWrite("authorComments: " & RemoveNullChars($tTGAExtention.authorComments) & @CRLF) ConsoleWrite("jobName: " & RemoveNullChars($tTGAExtention.jobName) & @CRLF) ConsoleWrite("swID: " & RemoveNullChars($tTGAExtention.swID) & @CRLF) EndIf EndIf Local Static $tDestBmp ;must be static otherwise bitmap data might get corrupted or in worst case script will crash Local $stride, $iPixelFormat Switch $iPxDepth Case 1 ;1-bit $iPixelFormat = $GDIP_PXF01INDEXED $stride = BitAND(($iW * 1) + 1, BitNOT(1)) $tDestBmp = DllStructCreate("uint color[" & $stride * $iH + 1 & "];") Case 8, 24 $iPixelFormat = $GDIP_PXF24RGB $stride = BitAND(($iW * 3) + 3, BitNOT(3)) $tDestBmp = DllStructCreate("uint color[" & $stride * $iH + 1 & "];") Case 15, 16 $iPixelFormat = $GDIP_PXF16RGB555 $stride = BitAND(($iW * 2) + 2, BitNOT(2)) $tDestBmp = DllStructCreate("uint color[" & $stride * $iH + 1 & "];") Case 32 $iPixelFormat = $GDIP_PXF32ARGB $stride = $iW * 4 $tDestBmp = DllStructCreate("uint color[" & $stride * $iH + 1 & "];") Case Else Return SetError(5, 0, 0) EndSwitch If Mod($stride, 4) <> 0 Then $stride += 4 - Mod($stride, 4) Local Const $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH, $iPixelFormat, $stride, $tDestBmp) If @error Or Not $hBitmap Then Return SetError(6, @error, 0) Local $fTimer = TimerInit() Local $x, $x1, $y, $t1 Local Const $hDLL = DllOpen("msvcrt.dll") Local Const $tagParam = "ptr tSrcBmp;ptr tDestBmp;dword strideSrc;dword strideDest;dword w;dword h;dword colorTblSize;dword t1;dword t2" Local $tParam If @AutoItX64 Then $tParam = _DLLStructCreate64($tagParam) Else $tParam = DLLStructCreate($tagParam) EndIf $tParam.tSrcBmp = DllStructGetPtr($tSrcBmp) $tParam.tDestBmp = DllStructGetPtr($tDestBmp) $tParam.strideDest = $stride $tParam.w = ($iW - 1) $tParam.h = ($iH - 1) $tParam.colorTblSize = $colorTblSize Switch $iPxDepth Case 1 ;1-bit For $y = 0 To $iH - 1 $t1 = $y * $stride DllCall($hDLL, "ptr:cdecl", "memcpy", "ptr", DllStructGetPtr($tDestBmp) + $t1, "ptr", DllStructGetPtr($tSrcBmp) + BitShift($t1, 3), "uint", $stride) Next Case 8 ;8-bit ConsoleWrite("Using Assembler code to speed-up..." & @CRLF) ;if a color table is available, just use it If $tTGAHeader.colormapType = 1 Then Local $tMapColorTbl = DllStructCreate("ubyte bgr[" & $colorTblSize & "]", DllStructGetPtr($tSrcBmp, "color") + $tTGAHeader.firstEntryIndex) Local $tParam2, $tagParam2 = "align 1;ptr tSrcBmp;ptr tDestBmp;ptr colormap;dword strideSrc;dword strideDest;dword w;dword h;dword colorTblSize;dword colorwidth;dword t1;dword t2;byte r5;byte g5;byte b5;" If @AutoItX64 Then $tParam2 = _DLLStructCreate64($tagParam2) Else $tParam2 = DllStructCreate($tagParam2) EndIf $tParam2.tSrcBmp = DllStructGetPtr($tSrcBmp) $tParam2.tDestBmp = DllStructGetPtr($tDestBmp) $tParam2.colormap = DllStructGetPtr($tMapColorTbl) $tParam2.strideSrc = $iW $tParam2.strideDest = $stride $tParam2.colorwidth = $colorwidth $tParam2.w = ($iW - 1) $tParam2.h = ($iH - 1) $tParam2.colorTblSize = $colorTblSize Switch @AutoItX64 Case False Local Const $bBinASM8cm_x86 = Binary("0x608B7C242431C990909090909090909089C8F7670C03471C89472489C8F7671089472831DB8B472401D8030789C231C08A02F767208B570801C28B32B803000000F7E303472803470489C5837F200275476689F26683E21F66C1E20388572E6689F26681E2E00366C1EA0566C1E20388572D6689F26681E2007C66C1EA0A66C1E20388572C31C00A472CC1E0080A472DC1E0080A472E89C6897500433B5F147684413B4F180F8665FFFFFF61C20400") Local $tBinASM8cm_x86 = DllStructCreate("ubyte asm[" & BinaryLen($bBinASM8cm_x86) & "]") $tBinASM8cm_x86.asm = $bBinASM8cm_x86 DllCallAddress("none", DllStructGetPtr($tBinASM8cm_x86), "ptr", DllStructGetPtr($tParam2)) Case Else Local Const $bBinASM8cm_x64 = Binary("0x575653554989CF41BE000000009090904489F041F7671841034728418947304489F041F7671C418947344531ED418B47304401E84903074889C24831C08A0241F7672C498B57104801C2448B0A4831C048C7C00300000041F7E541034734490347084989C041837F2C02755A4831D2664489CA6683E21F66C1E2034188573A4831D2664489CA6681E2E00366C1EA0566C1E203418857394831D2664489CA6681E2007C66C1EA0A66C1E2034188573831C0410A4738C1E008410A4739C1E008410A473A4189C145890841FFC5453B6F200F8657FFFFFF41FFC6453B77240F862DFFFFFF5D5B5E5FC20800") Local $tBinASM8cm_x64 = _DLLStructCreate64("ubyte asm[" & BinaryLen($bBinASM8cm_x64) & "]") $tBinASM8cm_x64.asm = $bBinASM8cm_x64 DllCallAddress("none", DllStructGetPtr($tBinASM8cm_x64), "ptr", DllStructGetPtr($tParam2)) EndSwitch Else ;convert it 1:1 directly Switch @AutoItX64 Case False $tParam.strideSrc = $iW $tParam.colorTblSize -= 2 Local Const $bBinASM8_x86 = Binary("0x8B7C2404BB00000000B900000000909089C8F7670889471C89C8F7670C8947208B471C01D8034718030789C252B803000000F7E30347200347045A8B328930433B5F1076DB31DB413B4F1476C3C20400") Local $tBinASM8_x86 = DllStructCreate("ubyte asm[" & BinaryLen($bBinASM8_x86) & "]") $tBinASM8_x86.asm = $bBinASM8_x86 DllCallAddress("none", DllStructGetPtr($tBinASM8_x86), "ptr", DllStructGetPtr($tParam)) Case Else $tParam.strideSrc = $iW Local Const $bBinASM8_x64 = Binary("0x575653554989CF49836F2002BB00000000B9000000009090909090909090909089C841F767104989C289C841F767144989C34D89D04901D84D0347204D030748C7C00300000048F7E34C01D8490347084D8B08448908FFC3413B5F1876D44831DBFFC1413B4F1C76B75D5B5E5FC20800") Local $tBinASM8_x64 = _DLLStructCreate64("ubyte asm[" & BinaryLen($bBinASM8_x64) & "]") $tBinASM8_x64.asm = $bBinASM8_x64 DllCallAddress("none", DllStructGetPtr($tBinASM8_x64), "ptr", DllStructGetPtr($tParam)) EndSwitch EndIf Case 15, 16, 24, 32 ;15/16/24/32-bit, as the bitmap format is the same we can use memcpy to copy the pixel data directly to the memory. ;Exeptions are 15/16/24-bit images whose width is not a divider of 4! If BitOR($iPxDepth = 15, $iPxDepth = 16, $iPxDepth = 24) And Mod($iW, 4) Then ConsoleWrite("Using Assembler code to speed-up..." & @CRLF) Switch $iPxDepth Case 15, 16 $tParam.strideSrc = $iW * 2 Switch @AutoItX64 Case False Local Const $bBinASM1516_x86 = Binary("0x8B7C2404BB00000000B900000000909089C8F7670889471C89C8F7670C894720B802000000F7E35003471C034718030789C2580347200347048B32668930433B5F1076DC31DB413B4F1476C4C20400") Local $tBinASM1516_x86 = DllStructCreate("ubyte asm[" & BinaryLen($bBinASM1516_x86) & "]") $tBinASM1516_x86.asm = $bBinASM1516_x86 DllCallAddress("none", DllStructGetPtr($tBinASM1516_x86), "ptr", DllStructGetPtr($tParam)) Case Else Local Const $bBinASM1516_x64 = Binary("0x575653554989CFBB00000000B90000000090909090909090909090909090909089C841F767104989C189C841F767144989C25389D8D1E04C89D24801C2490357084D89C84901C04D0347204D0307498B00488902FFC3FFC3413B5F1876D55BFFC1413B4F1C76B95D5B5E5FC20800") Local $tBinASM1516_x64 = _DLLStructCreate64("ubyte asm[" & BinaryLen($bBinASM1516_x64) & "]") $tBinASM1516_x64.asm = $bBinASM1516_x64 DllCallAddress("none", DllStructGetPtr($tBinASM1516_x64), "ptr", DllStructGetPtr($tParam)) EndSwitch Case 24 $tParam.strideSrc = $iW * 3 Switch @AutoItX64 Case False Local Const $bBinASM24_x86 = Binary("0x8B7C2404BB00000000B900000000909089C8F7670889471C89C8F7670C894720B803000000F7E35003471C034718030789C2580347200347048B328930433B5F1076DD31DB413B4F1476C5C20400") Local $tBinASM24_x86 = DllStructCreate("ubyte asm[" & BinaryLen($bBinASM24_x86) & "]") $tBinASM24_x86.asm = $bBinASM24_x86 DllCallAddress("none", DllStructGetPtr($tBinASM24_x86), "ptr", DllStructGetPtr($tParam)) Case Else Local Const $bBinASM24_x64 = Binary("0x575653554989CF4831C990909090909089C841F767104989C189C841F767144989C24831DB48C7C00300000048F7E34C89D24801C2490357084D89C84901C04D0347204D0307498B00488902FFC3FFC3413B5F1876CFFFC1413B4F1C76B25D5B5E5FC20800") Local $tBinASM24_x64 = _DLLStructCreate64("ubyte asm[" & BinaryLen($bBinASM24_x64) & "]") $tBinASM24_x64.asm = $bBinASM24_x64 DllCallAddress("none", DllStructGetPtr($tBinASM24_x64), "ptr", DllStructGetPtr($tParam)) EndSwitch EndSwitch Else For $y = 0 To $iH - 1 $t1 = $y * $stride DllCall($hDLL, "ptr:cdecl", "memcpy", "ptr", DllStructGetPtr($tDestBmp) + $t1, "ptr", DllStructGetPtr($tSrcBmp) + $t1, "uint", $stride) Next EndIf EndSwitch ConsoleWrite(TimerDiff($fTimer) & " ms" & @CRLF) DllClose($hDLL) ;TGA image is stored bottom up in file. Need to flip it. If BitAND($tTGAHeader.imageDescriptor, 0x30) <> 0x20 Then _GDIPlus_ImageRotateFlip($hBitmap, $GDIP_Rotate180FlipX) $tSrcBmp = 0 Return $hBitmap EndFunc ;==>_GDIPlus_TGAImageLoadFromFile ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name ..........: RemoveNullChars ; Description ...: Converts a null terminated binary string to a string ; Author ........: UEZ ; =============================================================================================================================== Func RemoveNullChars($bin) Local $a = StringRegExp($bin, "[[:xdigit:]+]{2}", 3), $s, $i If @error Then Return $s For $i = 0 To UBound($a) - 1 If $a[$i] = "00" Then ExitLoop $s &= Chr(Dec($a[$i])) Next Return $s EndFunc ;==>RemoveNullChars ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name ..........: _DLLStructCreate64 ; Description ...: Creates a struct for x64 assembler code execution ; Author ........: AndyG ; =============================================================================================================================== Func _DLLStructCreate64($struct) ;align auf 16-byte Adresse Local $temp = DllStructCreate($struct) Local $tempsize = DllStructGetSize($temp) + 64 Local $ptr = DllStructGetPtr($struct) Local $a1 = Mod(Number($ptr), 64) Local $temp = 0 Local $mem = _MemVirtualAlloc($ptr + $a1, $tempsize, $MEM_COMMIT, $PAGE_EXECUTE_READWRITE) Local $mem_dllstructcreate64_internal = $mem Local $a2 = Mod(Number($mem), 64) ;rest div 16 adresse = offset Local $sstruct = DllStructCreate($struct, (Number($mem) - $a2 + 64)) Return $sstruct ;auf 16 alingned pointer EndFunc ;==>_DLLStructCreate64 Global $sFile = FileOpenDialog("Select a TGA file", "", "TGA image(*.tga)") If @error Then Exit _GDIPlus_Startup() Global $hImage = _GDIPlus_TGAImageLoadFromFile($sFile, True) If @error Then ConsoleWrite(@error & " / " & @extended & @CRLF) _GDIPlus_Shutdown() Exit EndIf ;save result ;~ _GDIPlus_ImageSaveToFile($hImage, @ScriptDir & "\Converted.png") ;~ ShellExecute(@ScriptDir & "\Converted.png") Global $iW = _GDIPlus_ImageGetWidth($hImage), $iH = _GDIPlus_ImageGetHeight($hImage) Global $hGui = GUICreate("TGA Image Loader by UEZ", $iW, $iH) GUISetState() Global $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui) _GDIPlus_GraphicsDrawImageRect($hGraphics, $hImage, 0, 0, $iW, $iH) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE _GDIPlus_BitmapDispose($hImage) _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_Shutdown() Exit Case $GUI_EVENT_RESTORE _GDIPlus_GraphicsDrawImageRect($hGraphics, $hImage, 0, 0, $iW, $iH) EndSwitch WEnd  
      Here my rookie assembler code ^^:
      #cs _ASM8cm_x86 use32 define tSrcBmp dword[edi] define tDestBmp dword[edi + 04] define colortable dword[edi + 08] define strideSrc dword[edi + 12] define strideDest dword[edi + 16] define w dword[edi + 20] define h dword[edi + 24] define colorTblSize dword[edi + 28] define colorwidth dword[edi + 32] define iOffset dword[edi + 36] define iOffset2 dword[edi + 40] define r5 byte[edi + 44] define g5 byte[edi + 45] define b5 byte[edi + 46] pushad ;~ _ASMDBG_() mov edi, dword[esp + 36] ;pointer to the struct xor ecx, ecx; y = 0 align 16 _y: mov eax, ecx mul strideSrc add eax, colorTblSize mov iOffset, eax ;iOffset = y * $strideSrc + $colorTblSize mov eax, ecx mul strideDest mov iOffset2, eax ;iOffset2 = y * $strideDest xor ebx, ebx ;x = 0 _x: mov eax, iOffset add eax, ebx ;iOffset + x add eax, tSrcBmp mov edx, eax ;edx = iOffset + x + tSrcBmp xor eax, eax mov al, byte[edx] ;get index from color table mul colorwidth ;multiply it with colorwidth -> eax = index of the color table mov edx, colortable add edx, eax mov esi, dword[edx] ;get the color from the color table mov eax, 3 mul ebx ; add eax, iOffset2 ; add eax, tDestBmp ;$x * 3 + iOffset2 + tDestBmp = t1 mov ebp, eax cmp colorwidth, 2 jne _col_rgb mov dx, si ;BitShift(BitAND($col, 0x001F), -3) ;B and dx, 0x001F shl dx, 3 mov b5, dl mov dx, si ;BitShift(BitShift(BitAND($col, 0x03E0), 5), -3) ;G and dx, 0x03E0 shr dx, 5 shl dx, 3 mov g5, dl mov dx, si ;BitShift(BitShift(BitAND($col, 0x7C00), 10), -3) ;R and dx, 0x7C00 shr dx, 10 shl dx, 3 mov r5, dl xor eax, eax ;eax = 0 or al, r5 ;generate rgb value from rgb555 shl eax, 8 or al, g5 shl eax, 8 or al, b5 mov esi, eax _col_rgb: mov dword[ebp], esi ;write to destination inc ebx cmp ebx, w jbe _x inc ecx cmp ecx, h jbe _y ;~ _ASMDBG_() popad ret ;4 #ce _ASM8cm_x86 #cs _ASM8cm_x64 use64 define tSrcBmp qword[r15] define tDestBmp qword[r15 + 08] define colortable qword[r15 + 16] define strideSrc dword[r15 + 24] define strideDest dword[r15 + 28] define w dword[r15 + 32] define h dword[r15 + 36] define colorTblSize dword[r15 + 40] define colorwidth dword[r15 + 44] define iOffset dword[r15 + 48] define iOffset2 dword[r15 + 52] define r5 byte[r15 + 56] define g5 byte[r15 + 57] define b5 byte[r15 + 58] define x r13d define y r14d push rdi push rsi push rbx push rbp mov qword r15, rcx mov y, 0 align 16 _y: mov eax, y mul strideSrc add eax, colorTblSize mov iOffset, eax ;iOffset = y * $strideSrc + $colorTblSize mov eax, y mul strideDest mov iOffset2, eax ;iOffset2 = y * $strideDest xor x, x ;x = 0 _x: mov eax, iOffset add eax, x ;iOffset + x add rax, tSrcBmp mov rdx, rax ;edx = iOffset + x + tSrcBmp xor rax, rax mov al, byte[rdx] ;get index from color table mul colorwidth ;multiply it with colorwidth -> eax = index of the color table mov rdx, colortable add rdx, rax mov r9d, dword[rdx] ;get the color from the color table xor rax, rax mov rax, 3 mul x ; add eax, iOffset2 ; add rax, tDestBmp ;$x * 3 + iOffset2 + tDestBmp = t1 mov r8, rax cmp colorwidth, 2 jne _col_rgb xor rdx, rdx mov dx, r9w ;BitShift(BitAND($col, 0x001F), -3) ;B and dx, 0x001F shl dx, 3 mov b5, dl xor rdx, rdx mov dx, r9w ;BitShift(BitShift(BitAND($col, 0x03E0), 5), -3) ;G and dx, 0x03E0 shr dx, 5 shl dx, 3 mov g5, dl xor rdx, rdx mov dx, r9w ;BitShift(BitShift(BitAND($col, 0x7C00), 10), -3) ;R and dx, 0x7C00 shr dx, 10 shl dx, 3 mov r5, dl xor eax, eax ;eax = 0 or al, r5 ;generate rgb value from rgb555 shl eax, 8 or al, g5 shl eax, 8 or al, b5 mov r9d, eax _col_rgb: mov dword[r8], r9d ;write to destination inc x cmp x, w jbe _x inc y cmp y, h jbe _y pop rbp pop rbx pop rsi pop rdi ret 8 #ce #cs _ASM8_x86 use32 pushad mov edi, dword[esp + 36] ;pointer to the struct define tSrcBmp dword[edi] define tDestBmp dword[edi + 04] define strideSrc dword[edi + 08] define strideDest dword[edi + 12] define w dword[edi + 16] define h dword[edi + 20] define colorTblSize dword[edi + 24] define iOffset dword[edi + 28] define iOffset2 dword[edi + 32] mov ecx, 0 ; y align 16 _y: mov eax, ecx mul strideSrc add eax, colorTblSize mov iOffset, eax ;iOffset = y * $strideSrc + $colorTblSize mov eax, ecx mul strideDest mov iOffset2, eax ;iOffset2 = y * $strideDest xor ebx, ebx ;x = 0 _x: mov ebp, iOffset sub ebp, 2 add ebp, ebx add ebp, tSrcBmp ;ebp = t1 mov eax, 3 mul ebx add eax, iOffset2 add eax, tDestBmp ;eax = t2 mov esi, dword[ebp] ;get the color from source bitmap mov dword[eax], esi ;write to destination inc ebx cmp ebx, w jbe _x inc ecx cmp ecx, h jbe _y popad ret ;4 #ce _ASM8_x86 #cs _ASM8_x64 use64 push rdi push rsi push rbx push rbp define tSrcBmp qword[r15] define tDestBmp qword[r15 + 08] define strideSrc [r15 + 16] define strideDest [r15 + 20] define w [r15 + 24] define h [r15 + 28] define colorTblSize [r15 + 32] define iOffset [r15 + 36] define iOffset2 [r15 + 40] mov qword r15, rcx sub qword colorTblSize, 2 mov ebx, 0 ;w - 1 mov ecx, 0 ;h - 1 align 16 _y: mov eax, ecx mul dword strideSrc mov r10, rax ;r10 = y * $strideSrc mov eax, ecx mul dword strideDest mov r11, rax ;r11 = y * $strideDest _x: mov r8, r10 add r8, rbx add r8, colorTblSize add r8, tSrcBmp ;r8 = t1 mov rax, 3 mul rbx add rax, r11 add rax, tDestBmp ;eax = t2 mov r9, [r8] ;get the color from source bitmap mov dword[rax], r9d ;write to destination inc ebx cmp ebx, w jbe _x xor rbx, rbx inc ecx cmp ecx, h jbe _y pop rbp pop rbx pop rsi pop rdi ret 8 #ce _ASM8_x64 #cs _ASM1516_x86 use32 mov edi, dword[esp + 4] ;pointer to the struct define tSrcBmp ptr[edi] define tDestBmp ptr[edi + 04] define strideSrc dword[edi + 08] define strideDest dword[edi + 12] define w dword[edi + 16] define h dword[edi + 20] define colorTblSize dword[edi + 24] define iOffset dword[edi + 28] define iOffset2 dword[edi + 32] mov ebx, 0 ; x mov ecx, 0 ; y align 16 _y: mov eax, ecx mul strideSrc mov iOffset, eax ;iOffset = y * $strideSrc mov eax, ecx mul strideDest mov iOffset2, eax ;iOffset2 = y * $strideDest _x: mov eax, 2 mul ebx ;x * 2 push eax add eax, iOffset add eax, colorTblSize add eax, tSrcBmp mov edx, eax ;edx = t1 pop eax ;restore x * 2 add eax, iOffset2 add eax, tDestBmp ;eax = t2 mov esi, dword[edx] ;get the color from source bitmap mov word[eax], si ;write to destination inc ebx cmp ebx, w jbe _x xor ebx, ebx inc ecx cmp ecx, h jbe _y ret ;4 #ce _ASM1516_x86 #cs _ASM1516_x64 use64 ;~ define tSrcBmp dword[r15 + 0] ;~ define tDestBmp dword[r15 + 8] ;~ define strideS dword[r15 + 16] ;~ define strideD dword[r15 + 20] ;~ define width dword[r15 + 24] ;~ define height dword[r15 + 28] ;~ define colorTblSize dword[r15 + 32] ;~ define t1 dword[r15 + 36] ;not needed ;~ define t2 dword[r15 + 40] ;not needed push rdi push rsi push rbx push rbp mov qword r15, rcx mov ebx, 0 ;dword[r15 + 24] ;ebx = w - 1 mov ecx, 0 ;dword[r15 + 28] ;ecx = h - 1 align 16 _y: mov eax, ecx mul dword[r15 + 16] mov r9, rax mov eax, ecx mul dword[r15 + 20] mov r10, rax push rbx _x: mov eax, ebx shl eax, 1 mov rdx, r10 add rdx, rax add rdx, [r15 + 8] mov r8, r9 add r8, rax add r8, [r15 + 32] add r8, [r15] mov rax, [r8] mov [rdx], rax inc ebx inc ebx cmp ebx, dword[r15 + 24] jbe _x pop rbx inc ecx cmp ecx, dword[r15 + 28] jbe _y pop rbp pop rbx pop rsi pop rdi ret 8 #ce _ASM1516_x64 #cs _ASM24_x86 use32 mov edi, dword[esp + 4] ;pointer to the struct define tSrcBmp dword[edi] define tDestBmp dword[edi + 04] define strideSrc dword[edi + 08] define strideDest dword[edi + 12] define w dword[edi + 16] define h dword[edi + 20] define colorTblSize dword[edi + 24] define iOffset dword[edi + 28] define iOffset2 dword[edi + 32] mov ebx, 0 ; x mov ecx, 0 ; y align 16 _y: mov eax, ecx mul strideSrc mov iOffset, eax ;iOffset = y * $strideSrc mov eax, ecx mul strideDest mov iOffset2, eax ;iOffset2 = y * $strideDest _x: mov eax, 3 mul ebx ;x * 3 push eax add eax, iOffset add eax, colorTblSize add eax, tSrcBmp mov edx, eax ;edx = t1 pop eax ;restore x * 3 add eax, iOffset2 add eax, tDestBmp ;eax = t2 mov esi, dword[edx] ;get the color from source bitmap mov dword[eax], esi ;write to destination inc ebx cmp ebx, w jbe _x xor ebx, ebx inc ecx cmp ecx, h jbe _y ret ;4 #ce _ASM24_x86 #cs _ASM24_x64 use64 ;~ define tSrcBmp dword[r15 + 0] ;~ define tDestBmp dword[r15 + 8] ;~ define strideS dword[r15 + 16] ;~ define strideD dword[r15 + 20] ;~ define width dword[r15 + 24] ;~ define height dword[r15 + 28] ;~ define colorTblSize dword[r15 + 32] ;~ define t1 dword[r15 + 36] ;not needed ;~ define t2 dword[r15 + 40] ;not needed push rdi push rsi push rbx push rbp mov qword r15, rcx xor rcx, rcx align 16 _y: mov eax, ecx mul dword[r15 + 16] mov r9, rax mov eax, ecx mul dword[r15 + 20] mov r10, rax xor rbx, rbx _x: mov rax, 3 mul rbx mov rdx, r10 add rdx, rax add rdx, [r15 + 8] mov r8, r9 add r8, rax add r8, [r15 + 32] add r8, [r15] mov rax, [r8] mov [rdx], rax ;copy 64 bits inc ebx inc ebx cmp ebx, dword[r15 + 24] jbe _x inc ecx cmp ecx, dword[r15 + 28] jbe _y pop rbp pop rbx pop rsi pop rdi ret 8 #ce _ASM24_x64  
      If you find a TGA image which is in scope of this script but doesn't convert it properly, please report it here.
      Thanks.
    • By UEZ
      Since monoceres has released 
      I searched for a way to map the 2D image of the earth to a 3D sphere with rotation.
       
      Here the result (after 9 years of research ^^) as a non realistic physical animation:
       ==> 
       
      Due to the fact that AutoIt / GDI+ are not that fast I couldn't add a moon animation additionally.
       
      Thanks to one of Eukalyptus' code to pointing me to the right direction. U rock man. 
       
      Source code extract only - not working because of missing binary data (images):
      ;coded by UEZ build 2017-03-18 #pragma compile(x64, false) #pragma compile(Icon, "c:\Program Files (x86)\AutoIt3\Icons\au3.ico") #AutoIt3Wrapper_Run_Au3Stripper=y #Au3Stripper_Parameters=/so /pe /rm #AutoIt3Wrapper_Run_After=del /f /q "%scriptdir%\%scriptfile%_stripped.au3" #include <GDIPlus.au3> #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> _GDIPlus_Startup() Global $hGUI, $iFPS = 0, $iShowFPS = 0, $bExit Global Const $iW = 800, $iW2 = ($iW - 100) / 2, $iH = 500, $fRad = ACos(-1) / 180, $sTitle = "GDI+ Rotating Earth v1.7 coded by UEZ 2017" AutoItSetOption("GUIOnEventMode", 1) GDIPlus_RotatingEarth() AutoItSetOption("GUIOnEventMode", 0) _GDIPlus_Shutdown() Func GDIPlus_RotatingEarth() $bExit = False $hGUI = GUICreate($sTitle, $iW, $iH) GUISetState(@SW_SHOW, $hGUI) ;create canvas elements Local Const $hDC = _WinAPI_GetDC($hGUI) Local Const $hHBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $iW, $iH) Local Const $hDC_backbuffer = _WinAPI_CreateCompatibleDC($hDC) Local Const $DC_obj = _WinAPI_SelectObject($hDC_backbuffer, $hHBitmap) Local Const $hCanvas = _GDIPlus_GraphicsCreateFromHDC($hDC_backbuffer) _GDIPlus_GraphicsSetInterpolationMode($hCanvas, $GDIP_INTERPOLATIONMODE_NEARESTNEIGHBOR) _GDIPlus_GraphicsSetPixelOffsetMode($hCanvas, $GDIP_PIXELOFFSETMODE_HALF) Local Const $hBrush_Clr = _GDIPlus_BrushCreateSolid(0xFF000000), _ $hBrush_FPS = _GDIPlus_BrushCreateSolid(0xFFF0F0F0), _ $hFormat_FPS = _GDIPlus_StringFormatCreate(), _ $hFamily_FPS = _GDIPlus_FontFamilyCreate("Arial"), _ $hFont_FPS = _GDIPlus_FontCreate($hFamily_FPS, 8), _ $tLayout_FPS = _GDIPlus_RectFCreate(0, 0, 60, 16), _ $hImage_Earth = _GDIPlus_BitmapCreateFromMemory(_Earth()), _ $hImage_Galaxy = _GDIPlus_BitmapCreateFromMemory(_Galaxy()), _ $hImage_Clouds = _GDIPlus_BitmapCreateFromMemory(_Clouds()), _ $hImage_Moon = _GDIPlus_BitmapCreateFromMemory(_Moon()), _ $hImage_USSE = _GDIPlus_BitmapCreateFromMemory(_USSE()), _ $hMatrix = _GDIPlus_MatrixCreate(), $hMatrix2 = _GDIPlus_MatrixCreate(), _ $hPath = _GDIPlus_PathCreate(), $hPath2 = _GDIPlus_PathCreate(), _ $hPen = _GDIPlus_PenCreate(0xC0FFFFFF, 1) _GDIPlus_ImageRotateFlip($hImage_USSE, 4) Local $aDim = _GDIPlus_ImageGetDimension($hImage_Earth) Local $hGfx = _GDIPlus_ImageGetGraphicsContext($hImage_Earth) _GDIPlus_GraphicsDrawStringEx($hGfx, "Coded by UEZ 2017 ^^", $hFont_FPS, _GDIPlus_RectFCreate(0, $aDim[1] / 2 - 4, 120, 12), $hFormat_FPS, $hBrush_FPS) _GDIPlus_ImageDispose($hGfx) Local Const $hTexture_Earth = _GDIPlus_TextureCreate($hImage_Earth), $hTexture_Clouds = _GDIPlus_TextureCreate($hImage_Clouds) DllCall($__g_hGDIPDll, "int", "GdipTranslateTextureTransform", "ptr", $hTexture_Earth, "float", -200, "float", 0, "long", 0) DllCall($__g_hGDIPDll, "int", "GdipTranslateTextureTransform", "ptr", $hTexture_Clouds, "float", -100, "float", 0, "long", 0) Local $iDiameter = $aDim[0] < $aDim[1] ? $aDim[0] : $aDim[1], _ $fDiameter2 = $iDiameter / 2, _ $fDX = ($iW - $iDiameter) / 2, $fDY = ($iH - $iDiameter) / 2 _GDIPlus_PathAddEllipse($hPath, $fDX - 1, $fDY - 1, $iDiameter + 2, $iDiameter + 2) Local Const $hBrush = _GDIPlus_PathBrushCreateFromPath($hPath) _GDIPlus_PathBrushSetCenterColor($hBrush, 0x02000008) _GDIPlus_PathBrushSetCenterPoint($hBrush, $fDX + $fDiameter2 + 1, $fDY + $fDiameter2 + 1) _GDIPlus_PathBrushSetSurroundColor($hBrush, 0xF8000000) _GDIPlus_PathBrushSetGammaCorrection($hBrush, 1) _GDIPlus_PathBrushSetFocusScales($hBrush, 0.50, 0.50) _GDIPlus_PathAddEllipse($hPath2, -1, -1, 201, 201) Local Const $hBrush2 = _GDIPlus_PathBrushCreateFromPath($hPath2) _GDIPlus_PathBrushSetCenterColor($hBrush2, 0x0800000) _GDIPlus_PathBrushSetCenterPoint($hBrush2, 100, 100) _GDIPlus_PathBrushSetSurroundColor($hBrush2, 0xFF000000) _GDIPlus_PathBrushSetGammaCorrection($hBrush2, 1) _GDIPlus_PathBrushSetFocusScales($hBrush2, 0.50, 0.50) $hGfx = _GDIPlus_ImageGetGraphicsContext($hImage_Moon) _GDIPlus_GraphicsFillEllipse($hGfx, -1, -1, 201, 201, $hBrush2) _GDIPlus_ImageDispose($hGfx) $iFPS = 0 GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit_About") AdlibRegister("CalcFPS", 1000) Local $fTimer1, $fTimer2, $fScale, $fTmp, $fX, $fSin, $fZ, $fS, $zz, $z = 90, $iStep = 4 ;the higher $iStep is the faster the animation but lower the quality. Local $fPosX, $fPosY, $fSize, $fSpeed, $aMeteor[4] = [0, 10 + Random() * ($iH - 20), 5 + Random() * 10, 5 + Random() * 10] $fPosX = $iW + 60 $fPosY = Random() * ($iH - 100) + 50 $fSize = 0.5 + Random() * 2 $fSpeed = Random() * 3 + 1 $fTimer1 = TimerInit() $fTimer2 = TimerInit() Do DllCall($__g_hGDIPDll, "int", "GdipDrawImageRect", "handle", $hCanvas, "handle", $hImage_Galaxy, "float", 0, "float", 0, _ "float", $iW, "float", $iH) DllCall($__g_hGDIPDll, "int", "GdipSetSmoothingMode", "handle", $hCanvas, "int", 4) If TimerDiff($fTimer1) > 10000 Then DllCall($__g_hGDIPDll, "int", "GdipDrawLine", "handle", $hCanvas, "handle", $hPen, "float", $aMeteor[0], "float", $aMeteor[1], _ "float", $aMeteor[0] + $aMeteor[2] * 3, "float", $aMeteor[1] + $aMeteor[3] * 3) $aMeteor[0] += $aMeteor[2] $aMeteor[1] += $aMeteor[3] If BitOR($aMeteor[0] > $iW, $aMeteor[1] > $iH, $aMeteor[0] < 0, $aMeteor[1] < 0) Then $aMeteor[0] = 0 $aMeteor[1] = Random() * ($iH * 0.75) $aMeteor[2] = 8 + Random() * 12 $aMeteor[3] = 7 + Random() * 10 $fTimer1 = TimerInit() EndIf EndIf If TimerDiff($fTimer2) > 30000 Then DllCall($__g_hGDIPDll, "int", "GdipDrawImageRect", "handle", $hCanvas, "handle", $hImage_USSE, "float", $fPosX, "float", $fPosY, _ "float", 50 * $fSize, "float", 12 * $fSize) $fPosX -= $fSpeed If $fPosX < -100 Then $fPosX = $iW + 30 $fPosY = Random() * ($iH - 100) + 50 $fSize = Random() * 2 $fSpeed = Random() * 3 + 1 $fTimer2 = TimerInit() EndIf EndIf $zz = $z * $fRad $fX = $iW2 - Cos($zz) * 345 $z -= 0.5 $fZ = Sin($zz) $fS = 100 - $fZ * 50 DllCall($__g_hGDIPDll, "int", "GdipSetSmoothingMode", "handle", $hCanvas, "int", 1) DllCall($__g_hGDIPDll, "int", "GdipTranslateTextureTransform", "ptr", $hTexture_Earth, "float", 0.75, "float", 0, "long", 0) DllCall($__g_hGDIPDll, "int", "GdipTranslateTextureTransform", "ptr", $hTexture_Clouds, "float", 1.25, "float", 0, "long", 0) If $fZ > 0 Then _GDIPlus_GraphicsDrawImageRect($hCanvas, $hImage_Moon, $fX, 110, $fS, $fS) For $i = 1 To $fDiameter2 Step $iStep $fScale = 1 + $i / $fDiameter2 DllCall($__g_hGDIPDll, "int", "GdipSetMatrixElements", "handle", $hMatrix, "float", 1.0, "float", 0.0, "float", 0.0, "float", 1.0, "float", 0.0, "float", 0.0) DllCall($__g_hGDIPDll, "int", "GdipTranslateMatrix", "handle", $hMatrix, "float", $fDX + $fDiameter2, "float", $fDY + $fDiameter2, "int", 0) DllCall($__g_hGDIPDll, "int", "GdipScaleMatrix", "handle", $hMatrix, "float", $fScale, "float", $fScale, "int", 0) DllCall($__g_hGDIPDll, "int", "GdipTranslateMatrix", "handle", $hMatrix, "float", -$fDiameter2, "float", -$fDiameter2, "int", 0) DllCall($__g_hGDIPDll, "int", "GdipSetWorldTransform", "handle", $hCanvas, "handle", $hMatrix) DllCall($__g_hGDIPDll, "int", "GdipFillEllipse", "handle", $hCanvas, "handle", $hTexture_Earth, _ "float", $i, "float", $i, "float", $iDiameter -2 * $i, "float", $iDiameter - 2 * $i) DllCall($__g_hGDIPDll, "int", "GdipFillEllipse", "handle", $hCanvas, "handle", $hTexture_Clouds, _ "float", $i, "float", $i, "float", $iDiameter -2 * $i, "float", $iDiameter - 2 * $i) Next _GDIPlus_MatrixSetElements($hMatrix) _GDIPlus_GraphicsSetTransform($hCanvas, $hMatrix) DllCall($__g_hGDIPDll, "int", "GdipFillRectangle", "handle", $hCanvas, "handle", $hBrush, "float", $fDX, "float", $fDY, "float", $iDiameter, "float", $iDiameter) Else For $i = 1 To $fDiameter2 Step $iStep $fScale = 1 + $i / $fDiameter2 DllCall($__g_hGDIPDll, "int", "GdipSetMatrixElements", "handle", $hMatrix, "float", 1.0, "float", 0.0, "float", 0.0, "float", 1.0, "float", 0.0, "float", 0.0) DllCall($__g_hGDIPDll, "int", "GdipTranslateMatrix", "handle", $hMatrix, "float", $fDX + $fDiameter2, "float", $fDY + $fDiameter2, "int", 0) DllCall($__g_hGDIPDll, "int", "GdipScaleMatrix", "handle", $hMatrix, "float", $fScale, "float", $fScale, "int", 0) DllCall($__g_hGDIPDll, "int", "GdipTranslateMatrix", "handle", $hMatrix, "float", -$fDiameter2, "float", -$fDiameter2, "int", 0) DllCall($__g_hGDIPDll, "int", "GdipSetWorldTransform", "handle", $hCanvas, "handle", $hMatrix) DllCall($__g_hGDIPDll, "int", "GdipFillEllipse", "handle", $hCanvas, "handle", $hTexture_Earth, _ "float", $i, "float", $i, "float", $iDiameter - 2 * $i, "float", $iDiameter - 2 * $i) DllCall($__g_hGDIPDll, "int", "GdipFillEllipse", "handle", $hCanvas, "handle", $hTexture_Clouds, _ "float", $i, "float", $i, "float", $iDiameter - 2 * $i, "float", $iDiameter - 2 * $i) Next _GDIPlus_MatrixSetElements($hMatrix) _GDIPlus_GraphicsSetTransform($hCanvas, $hMatrix) DllCall($__g_hGDIPDll, "int", "GdipFillRectangle", "handle", $hCanvas, "handle", $hBrush, "float", $fDX, "float", $fDY, "float", $iDiameter, "float", $iDiameter) _GDIPlus_GraphicsDrawImageRect($hCanvas, $hImage_Moon, $fX, 110, $fS, $fS) EndIf _GDIPlus_GraphicsDrawStringEx($hCanvas, "FPS: " & $iShowFPS, $hFont_FPS, $tLayout_FPS, $hFormat_FPS, $hBrush_FPS) ;draw background message text _WinAPI_BitBlt($hDC, 0, 0, $iW, $iH, $hDC_backbuffer, 0, 0, $SRCCOPY) ;blit drawn bitmap to GUI $iFPS += 1 If $bExit Then ExitLoop Until False ;Not Sleep(10) AdlibUnRegister("CalcFPS") ;release resources _GDIPlus_PenDispose($hPen) _GDIPlus_BrushDispose($hBrush) _GDIPlus_BrushDispose($hBrush2) _GDIPlus_PathDispose($hPath) _GDIPlus_PathDispose($hPath2) _GDIPlus_MatrixDispose($hMatrix) _GDIPlus_MatrixDispose($hMatrix2) _GDIPlus_ImageDispose($hImage_Earth) _GDIPlus_ImageDispose($hImage_Galaxy) _GDIPlus_ImageDispose($hImage_Clouds) _GDIPlus_ImageDispose($hImage_Moon) _GDIPlus_ImageDispose($hImage_USSE) _GDIPlus_BrushDispose($hTexture_Earth) _GDIPlus_BrushDispose($hTexture_Clouds) _GDIPlus_FontDispose($hFont_FPS) _GDIPlus_FontFamilyDispose($hFamily_FPS) _GDIPlus_StringFormatDispose($hFormat_FPS) _GDIPlus_BrushDispose($hBrush_Clr) _GDIPlus_BrushDispose($hBrush_FPS) _GDIPlus_GraphicsDispose($hCanvas) _WinAPI_SelectObject($hDC_backbuffer, $DC_obj) _WinAPI_DeleteDC($hDC_backbuffer) _WinAPI_DeleteObject($hHBitmap) _WinAPI_ReleaseDC($hGUI, $hDC) GUIDelete($hGUI) EndFunc ;==>GDIPlus_RotatingEarth Func _Exit_About() $bExit = True EndFunc ;==>_Exit_About Func CalcFPS() ;display FPS $iShowFPS = $iFPS $iFPS = 0 EndFunc ;==>CalcFPS ;Code below was generated by: 'File to Base64 String' Code Generator v1.20 Build 2016-12-01 ...  
      Download: Rotating Earth v1.7.au3
      In line 92 you can modify the $iStep variable -> the higher $iStep is the faster the animation & lower the quality.
       
      So long...
    • By UEZ
      AutoIt Windows Screenshooter
      Key Features:
      takes easily a screenshot from any visible window capture any region of the desktop incl. freehand capturing capture GUI controls and GUI menus separately capture a marked area every x seconds for a duration of y seconds create a GIF animation from saved frames (Vista or higher os required) capture to AVI file (without audio!) takes a screenshot from web sites (available only on Win7+ os and when Aero is enabled) put images to clipboard to paste to other applications easily color picker save image in different formats and also to PDF! add timestamp to saved images simple image editing options: greyscale, b&w, invert, rotate +-90° send image to printer and default email client preview of captured screens incl. zoom option multi monitor support display pixel color under mouse ruler basic image editor (paint, highlight, ellipse, rectangle, text and some graphic FX) watermark captured image no 3rd party tools or DLLs used - pure AutoIt! fully portable - no installation is needed multi language feature (Eng, Ger, Tur, Fra and Rus only) drag'n'drop an image to the app for editing To do:
      capture content of scrollable window/control capture cascaded menus Due to DllCall("User32.dll", "int", "PrintWindow", "hwnd", $hWnd, "handle", $hMemDC, "int", 0) limitation some windows cannot be captured properly (GDI+, ProgDVB, etc.) but can take screenshots of hidden windows. One workaround is to use full screen capturing (F11/F12) or "Grab Screen" function! Or try double click with rmb on listview items (beta).
      Download source code (9460 downloads previously): AutoIt Windows Screenshooter v1.84 Build 2019-08-18.7z (version 3.3.12.0+ needed!)
      You are not allowed to sell this code or just parts of it in a commercial project or modify it and distribute it with a different name!
      Download compiled Exe only: 4shared / Media Fire  / Softpedia (1.58mb)
      Distributing copies of the program in compiled format (exe) must be free of any fee!
      -----> click here to Donate!  
      (Current donators: 1. Cuong N.) 
       
       
      It is designed for Win7+ operating systems with AERO enabled! E.g. on WinXP machines some functions are not working properly and might crash the application!
      AV scanners may have a negative impact the execution of compiled exe and might report any malware. I guarantee that there is no malicious code in the source code / exe!!! 
      Main GUI:

       
       
      About Intro:

       
       
      Basic Image Editor:

       
       
      Watermark:

       
       
      Click link for an enhanced version of Watermark Image.
      Credits:
      main code by UEZ additional code (alphabetical order) by Authenticity, AutoItObject Team, Eemuli, Eukalyptus, funkey, _Kurt, martin, monoceres, ProgAndy, taietel, trancexx, Ward, wolf9228 and Yashied! mesale0077 for turkish translation wakillon for french translation AZJIO for russian translation Keys:
      Main GUI:
      User your mouse to scroll preview window or
      Numpad 8: Scroll preview window up
      Numpad 2: Scroll preview window down
      Numpad 4: Scroll preview window left
      Numpad 6: Scroll preview window right
      Numpad +: zoom in preview window or mouse wheel down
      Numpad -: zoom out preview window or mouse wheel up
      F1: capture again on last position
      F5: refresh Windows Name list
      PRINTSCREEN: take screenshot from whole screen
      ALT+PRINTSCR: take a screenshot from active window
      F10: Undo made changes with Image Editing function
      F11: take screenshot from whole screen incl mouse cursor
      F12: take screenshot from whole screen
      Ctrl+Alt+F9 start "Grab Screen" mode
      Ctrl+Alt+F12: take a screenshot from active window using alternative screenshot functionality (beta)!
      Ctrl+r: call ruler
      Ctrl+s: save current displayed image
      Ctrl+x: exit program
      ctrl+w: call web grab input field (available only when Aero is enabled)
      Ctrl+i: call image editor
      Ctrl+m: call watermark editor
      Ctrl+z: undo
      Only available on Vista+ os: double click with rmb on list items to use alternative screenshot functionality (beta)!
      When 'Grab Screen' is clicked you can hold down the ctrl key to switch to 'grab controls' mode. Control under mouse will be framed red.
      ctrl + shift will take the screenshot of appropriate control. To capture GUI menus you can press rmb which simulates the lmb. When a menu is opened press shift additionally to capture it.
      Press and hold only the shift key to capture any region on the desktop using freehand capturing - release it so capture marked regions!
      Or just mark resize able area which you want to grab. Press CTRL key to grab marked area or right mouse button to capture the marked area every x seconds for a duration of y seconds.
      When saving the image just enter the extension you wish to use (*.jpg;*.png;*.bmp;*.gif;*.tif;*.pdf). Big thanks to taietel for his PDF UDF!
      Image Editor:
      s: save
      c: copy
      n: send
      h: highlighter
      p: pen
      r: rectangle
      e: ellipse
      a: arrow
      o: color
      t: text
      g: text config
      Ctrl+z: undo
      Watermark editor:
      Ctrl+z: undo
       
      To start the app minimized just call it "Windows Screenshooter.exe /min"
      Maybe it is useful for someone...
      Any kind of comment is welcome.
      Br,
      UEZ
      Change log:
       


    • By Beege
      Heres a function for searching for a bitmap within another bitmap. The heart of it is written assembly (source included) and working pretty quick I feel. I have included an example which is pretty basic and should be easily enough for anyone to get the concept. 
      You will be given a small blue window that will take a screencapture of that size:

       
      It will then take a full screenshot and highlight all locations that it found

      Please let me know if you have any issues or questions. Thanks!
       
      Update 8/5/2019:
      Rewrote for fasmg. Added full source with everything needed to modify
      BmpSearch_8-5-2019.7z
      BmpSearch.zip
       
      GAMERS - Asking for help with ANY kind of game automation is against the forum rules. DON'T DO IT.
×
×
  • Create New...