Jump to content
Sign in to follow this  
UEZ

GDI+ Show Histogram v0.97 beta build 2013-02-05

Recommended Posts

UEZ

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

Edited by UEZ
  • Like 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
GreenCan

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
stormbreaker

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
UEZ

@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
GreenCan

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
UEZ

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
UEZ

@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
GreenCan

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
UEZ

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
ValeryVal

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:


The point of world view

Share this post


Link to post
Share on other sites
Jardz

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
UEZ

@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
UEZ

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
Jardz

@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
wolf9228

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
UEZ

: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

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

    • Xandy
      By Xandy
      MapIt is a tile world editor.  MapIt was built around the concept of reversing Dragon Warrior map images.  MapIt can take image input and produce a tile and world array.
      MapIt features Unity style dragable labels that adjust property values.

      MapParser is a C++ project that scans images for unique tiles.  MapParser is very fast.  Due to hard drive failure, many bugs were restored b/c I had to rewind many years.  Frustrated with the design, I wrote a new version from the ground up.  This New Version:  AutoIt Front-end, command line controls, and shared with the world; so that I can't lose it again.
      You can toggle the C++ MapParser off to see the difference in speeds between the MapParser CPP verse AutoIt function.  Function is named Scan_Tiles() in AutoIt.  You can also chose to download without MapParser.exe.
      At the moment Scanning a image resets the arrays, but you can add tiles after scanning.
      Images can be added as tiles without scan image at all.  Then configure settings to give your world parameters and manually fill the world data with tile indexes.
      Using the settings you can change tile size after a scan.  Example: you wanted to replace a map with different sized tiles.
      Changing and replacing tile / world data is easy.  B/c tile world editor.

      Hotkeys, I use CTRL+R in image above to signal replace tile action and I use "G" to Get the tile under mouse.
      Hotkeys are not saved to disk and thus are set to default between sessions.
      I might draw the world to pre-rendered surfaces and use them as multi-layer someday.  I do that in my AutoIt, DragonWarrior Remake but I could spend forever unsure what features are important for this.  The DW_Remake has a method of replacing a tile with a tile on two layers.  So you could replace a tree on the first layer with a grass, and a tree in the second layer.  This is all getting very confusing.
      I attempted to write the good code.  If something could be better, please advise.
      Fifth release.  Enjoy.
      For download, videos, and example of created world file data; please visit the MapIt webpage: http://songersoft.com/programming/mapit/mapit_about.phtml
      Special thanks: @AdmiralAlkex, @Melba23, @MrCreatoR
      Main AutoIt source file: Will not run without other Includes and SDL DLLs.
      Last Update: 5/26/2018 3:45 PM EST
      REMOVED CODE BLOCK:  I was informed the this page loaded very slowly, one solution so far has been to remove the 2k lines in the code block.
      When I recieve more feedback from the User I may reduce image size or remove images.
      Next Version Added: $eSETTING_TILE_LAST_PATH I have the weekend, I want to write world layers with aBoard surfaces.  
    • UEZ
      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 Vista+ 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) 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 (5771 downloads previously): AutoIt Windows Screenshooter v1.79 Build 2018-05-08.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.54mb)
      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 Vista+ 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 mousewheel down
      Numpad -: zoom out preview window or mousewheel 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 (availabe 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 menues you can press rmb which simulates the lmb. When a menu is opened press shift additionaly 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 resizeable 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 whish 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:
       
    • c.haslam
      By c.haslam
      I think that _GDIPlus_ImageGetPropertyItem should return a Property Item that can readily be set as a property of another image. Why would one want to do this? A script might (as one of mine does) edit an image of a .jpg file then write the result to a .jpg file. In editing it, in my case, the number of horizontal and vertical pixels change, and the date/time edited should be set as a property. All other property items remain the same. Other GDI+ users may change other properties.
      So an approach is to copy all the property items from image1 to image2, then update a few properties.
      M$ provides a Property Item class (id, length, pointer to an array of values) but _GDIPlus_ImageGetPropertyItem returns something different.
      I think that, wherever reasonable, UDFs that are wrappers for M$ methods should work like M$'s methods. _GDIPlus_ImageGetPropertyItem does not do this:
      While M$ returns 2 values for a value that is a ratio of 2 numbers,  _GDIPlus_ImageGetPropertyItem returns numerator/denominator as a single value (often a Double). _GDIPlus_ImageSetPropertyItem (when included in GDIPlus.au3) will be unable to set ratio property items properly because it cannot know what the numerator and denominator are. So copying such property items will not work properly. M$ has a Void* buffer where the buffer is an array of values but _GDIPlus_ImageGetPropertyItem() returns the values in the same 1-d array as id, length and type. M$'s approach produces a 1-d array with the same number of elements for all property items while _GDIPlus_ImageGetPropertyItem produces a 1-d array with various numbers of elements. To me, this is not good programming practice. For a photo from a Sony camera, the worst case has 1-d array with 67 elements. When combined into a 2-d array with the property items of all properties, there are 66 rows and 67 columns, with many elements not used. So I suggest that _GDIPlus_ImageGetPropertyItem look like this:
      ; #FUNCTION# ==================================================================================================================== ; Name ..........: cGDIPlus_ImageGetPropertyItem ; Description ...: Gets a specified property item (piece of meta data) from an Image object ; Syntax ........: cGDIPlus_ImageGetPropertyItem($hImage, $iPropID) ; Parameters ....: $hImage - Pointer to an image object ; $iPropID - Identifier of the property item to be retrieved ; Return values .: Success: Array containing the values of the property item ; [0] - identifier ; [1] - size, in bytes, of the value array ; [2] - type of value(s) in the value array ; [3] - value array ; Failure: Sets the @error flag to non-zero, @extended may contain GPSTATUS error code ($GPID_ERR*). ; Author ........: Eukalyptus ; Modified ......: c.haslam ; Remarks .......: types: unsigned byte = 1, ASCII string = 2, unsigned short = 3, unsigned long = 4, ; unsinged rational = 5, undefined = 7, signed long = 9, signed rational = 10 ; Related .......: _GDIPlus_ImageGetPropertyIdList ; Link ..........: https://msdn.microsoft.com/en-us/library/windows/desktop/ms535390(v=vs.85).aspx, ; https://msdn.microsoft.com/en-us/library/windows/desktop/ms534493(v=vs.85).aspx, ; https://msdn.microsoft.com/en-us/library/windows/desktop/ms534414(v=vs.85).aspx ; Example .......: Yes ; =============================================================================================================================== Func cGDIPlus_ImageGetPropertyItem($hImage, $iPropID) Local $iSize = __GDIPlus_ImageGetPropertyItemSize($hImage, $iPropID) If @error Then Return SetError(@error, @extended, -1) Local $tBuffer = DllStructCreate("byte[" & $iSize & "];") Local $pBuffer = DllStructGetPtr($tBuffer) Local $aResult = DllCall($__g_hGDIPDll, "int", "GdipGetPropertyItem", "handle", $hImage, "uint", _ $iPropID, "uint", $iSize, "struct*", $tBuffer) If @error Then Return SetError(@error, @extended, -1) If $aResult[0] Then Return SetError(10, $aResult[0], False) Local $tPropertyItem = DllStructCreate("int id; int length; short type; ptr pvalue;", $pBuffer) Local $iBytes = DllStructGetData($tPropertyItem, "length") Local $pValue = DllStructGetData($tPropertyItem, "pvalue") Local $aRet[4] Local $type = DllStructGetData($tPropertyItem,'type') Local $tValues, $iValues Switch $type Case 2 ;ASCII String $iValues = 1 $tValues = DllStructCreate("char[" & $iBytes & "];", $pValue) Case 3 ;Array of UShort $iValues = Int($iBytes / 2) $tValues = DllStructCreate("ushort[" & $iValues & "];", $pValue) Case 4, 5 ;Array of UInt / Fraction $iValues = Int($iBytes / 4) $tValues = DllStructCreate("uint[" & $iValues & "];", $pValue) Case 9, 10 ;Array of Int / Fraction $iValues = Int($iBytes / 4) $tValues = DllStructCreate("int[" & $iValues & "];", $pValue) Case Else ;Array of Bytes $iValues = 1 $tValues = DllStructCreate("byte[" & $iBytes & "];", $pValue) EndSwitch $aRet[0] = DllStructGetData($tPropertyItem,'id') $aRet[1] = $iBytes $aRet[2] = $type Local $aVals[$iValues] If $type=2 Or $type=7 Then ; ASCII string or undefined $aVals[0] = DllStructGetData($tValues,1) Else For $i = 0 To $iValues-1 $aVals[$i] = DllStructGetData($tValues,1,$i+1) Next EndIf $aRet[3] = $aVals Return $aRet EndFunc And here is an example:
      #include <GDIPlus.au3> #include <Array.au3> Example() Func Example() _GDIPlus_Startup() Local $hImage = _GDIPlus_ImageLoadFromFile(RegRead((@AutoItX64 = True ? "HKLM\SOFTWARE\Wow6432Node\AutoIt v3\AutoIt" : "HKLM\SOFTWARE\AutoIt v3\AutoIt"), "InstallDir") & "\Examples\GUI\Torus.png") If @error Then _GDIPlus_Shutdown() MsgBox(16, "", "An error has occured - unable to load image!", 30) Return False EndIf Local $ar = _GDIPlus_ImageGetPropertyIdList($hImage) Local $vPropNbrs[UBound($ar,1)-1] ; Extract ID numbers For $i = 1 To UBound($ar,1)-1 $vPropNbrs[$i-1] = $ar[$i][0] Next ; Get all property items Local $aPropItems[UBound($vPropNbrs)][4],$vPropItem For $i = 0 To UBound($vPropNbrs)-1 $vPropItem = cGDIPlus_ImageGetPropertyItem($hImage,$vPropNbrs[$i]) For $j = 0 To 3 $aPropItems[$i][$j] = $vPropItem[$j] Next Next ; Collapse values arrays so _ArrayDisplay can display them Local $ar = $aPropItems For $i = 0 To UBound($aPropItems,1)-1 $ar[$i][0] = '0x'&Hex($ar[$i][0],4) $ar[$i][3] = '' For $j = 0 To UBound($aPropItems[$i][3])-1 $ar[$i][3] &= ($aPropItems[$i][3])[$j]&'|' Next $ar[$i][3] = StringTrimRight($ar[$i][3],1) Next _ArrayDisplay($ar) _GDIPlus_Shutdown() EndFunc Unfortunately this example (based on one now in the Help) does not exercise most of the item types, but I do not know of a file with EXIF metadata that is on most PCs. I have tested this code by updating and adding property items to torus.jpg and to a photo taken by a Sony camera. The code for implementing and calling _GDIPlus_ImageSetPropertyItem will be fairly simple [see below].
       
      Your thoughts?
       
    • c.haslam
      By c.haslam
      I have a strange symptom of a problem somewhere in my code, or in a UDF: when I add code to get all properties of a GDI+ image to a 6000-line script,  the variable type of a parameter is reported as a pointer when the caller clearly has this argument as a string. If I comment out my code that gets the properties, the function properly sees the parameter as a string.
      [Edit: The reporting as a pointer and getting image properties are miles apart, both in where they are in the script code and in where they are run.]
      At this point, I am looking for clues as to why this is happening, so the hunt is on!
      I have noticed one odd thing, in _GDIPlus_ImageGetPropertyIdList() I see a line that begins Local $sPropertyTagInfo = . This "line" is split into 2 lines. SCiTE shows that the first line is 2454 characters and the second 2400. Adding these numbers I get 4854 characters.
      But the Help for AutoIt3 Limits/defaults says that MAXLINESIZE, Maximum size for a line of script, is 4096 characters.
      The line would exceed the limit if AutoIt considers the subject line to be 1 line and not 2 lines.
      My question: is this line legal? Is buffer overun possible?
    • c.haslam
      By c.haslam
      I find _GDIPlus_ImageClone in the Help, but neither in SciTe auto-complete nor in GDIPlus.au3
      Shoud this be reported in Trac?
      By searching the forum (and changing the name of the first arguement ot DLLCall, the code appears to be:
      Func _GDIPlus_ImageClone($hImage) Local $aResult = DllCall($__g_hGDIPDll, "uint", "GdipCloneImage", "handle", $hImage, "int*", 0) If @error Then Return SetError(@error, @extended, 0) Return $aResult[2] EndFunc ;==>_GDIPlus_ImageClone  
×