Je suis actuellement sur de la manipulation d'image (en RAM).
J'ai fait un programme qui me permet d'ajouter un filtre sur une image (exemple : la rendre plus rouge, moins verte, etc...), il fonctionne très bien mais sur de petites images (16*16) dès que l'on passe à des images pus grande (35 * 35 par exemple), le traitement dure 270ms, ce qui est beaucoup trop long pour de la "retouche en direct".
Un flag est aussi possible pour indiquer que la couleur du pixel aux coordonnées 0, 0 ne sera pas traitée.
Voici le script :
► Afficher le texteexemple
Code : Tout sélectionner
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include "ImageManip.au3"
Opt("MustDeclareVars", 1)
Opt("GuiOnEventMode", 1)
Global $gui
Global $icon
Global $slider[3]
Global $tailleIcon = [16, 16]
Global $taille[2] = [410, $tailleIcon[1]+150]
;~ Global $cheminIcon = @ScriptDir & "\Cadenas.ico"
Global $cheminIcon = @ScriptDir & "\Colors.ico"
Global $colorsName = ["Rouge", "Vert", "Bleu"]
Global $bitmap
Global $bordure = 5
Global $changing = False
$gui = GUICreate("", $taille[0], $taille[1])
GUISetOnEvent($GUI_EVENT_CLOSE, "quit", $gui)
$icon = GUICtrlCreatePicPng($cheminIcon, ($taille[0]-$tailleIcon[0])/2, 20, $tailleIcon[0], $tailleIcon[1])
For $i = 0 To UBound($slider, 1)-1
$slider[$i] = GUICtrlCreateLabel($colorsName[$i] & " :", $bordure, 50+$tailleIcon[1]+$bordure+$i*30, 40, 20)
$slider[$i] = GUICtrlCreateSlider(2*$bordure+40, 50+$tailleIcon[1]+$bordure+$i*30, $taille[0]-(2*$bordure+40), 20)
GUICtrlSetLimit($slider[$i], 255, -255)
Next
GUISetState(@SW_SHOW, $gui)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
While(True)
Sleep(10)
WEnd
Func WM_NOTIFY($hwnd, $msg, $wParam, $lParam)
Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
Local $iEvent = DllStructGetData($tNMHDR, "Code")
Local $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
If(Not($changing) And $hwnd = $gui And $iEvent = -12) Then
Local $found = -1
For $i = 0 To UBound($slider, 1)-1
If($wParam = $slider[$i]) Then
$found = $i
ExitLoop
EndIf
Next
If($found >= 0) Then
Local $timer = TimerInit()
If(IsPtr($bitmap)) Then _GDIPlus_BitmapDispose($bitmap)
$bitmap = _GDIPlus_BitmapCreateFromFile($cheminIcon)
Local $readRed = GUICtrlRead($slider[0])
Local $readGreen = GUICtrlRead($slider[1])
Local $readBlue = GUICtrlRead($slider[2])
Local $red = "0x" & Hex(String(Abs($readRed)), 2) & "0000"
Local $green = "0x00" & Hex(String(Abs($readGreen)), 2) & "00"
Local $blue = "0x0000" & Hex(String(Abs($readBlue)), 2)
ConsoleWrite($red & ", " & $green & ", " & $blue & @CRLF)
$changing = True
ImageSetMask($bitmap, $red, $readRed >= 0)
ImageSetMask($bitmap, $green, $readGreen >= 0)
ImageSetMask($bitmap, $blue, $readBlue >= 0)
GUICtrlSetPng($icon, $bitmap)
$changing = False
ConsoleWrite(TimerDiff($timer) & @CRLF)
EndIf
EndIf
Return $GUI_RUNDEFMSG
EndFunc
Func quit()
Exit
EndFunc
► Afficher le texteImageManip.au3
Code : Tout sélectionner
#include <GDIPlus.au3>
#include <Math.au3>
_GDIPlus_Startup()
OnAutoItExitRegister("_exit_iconmanip")
Func ImageSetMask($iconName, $mask, $add = True, $trans = True)
$mask = "0x" & Hex($mask, 8)
Local $bitmap = IsPtr($iconName) ? $iconName : _GDIPlus_BitmapCreateFromFile($iconName)
Local $transCol = $trans ? "0x" & Hex(_GDIPlus_BitmapGetPixel($bitmap, 0, 0), 8) : -1
For $y = 0 To _GDIPlus_ImageGetHeight($bitmap)-1
For $x = 0 To _GDIPlus_ImageGetWidth($bitmap)-1
Local $color = "0x" & Hex(_GDIPlus_BitmapGetPixel($bitmap, $x, $y), 8)
;~ ConsoleWrite($color & "->")
If($color <> $transCol) Then
If($add) Then
$color = ColorAddProportion($color, $mask)
Else
$color = ColorSubProportion($color, $mask)
EndIf
_GDIPlus_BitmapSetPixel($bitmap, $x, $y, $color)
EndIf
;~ ConsoleWrite($color & ", ")
Next
;~ ConsoleWrite(@CRLF)
Next
Return $bitmap
EndFunc
Func ColorAddProportion($color, $mask)
Local $colors[2][3] = [ [_WinAPI_GetRValue($color), _WinAPI_GetGValue($color), _WinAPI_GetBValue($color)], _
[_WinAPI_GetRValue($mask), _WinAPI_GetGValue($mask), _WinAPI_GetBValue($mask)]]
Local $retour = StringTrimRight($color, 6)
For $i = 0 To UBound($colors, 2)-1
$retour &= Hex($colors[0][$i]+$colors[1][$i]-Floor(($colors[0][$i]*$colors[1][$i])/255), 2)
Next
Return $retour
EndFunc
Func ColorSubProportion($color, $mask)
Local $colors[2][3] = [ [_WinAPI_GetRValue($color), _WinAPI_GetGValue($color), _WinAPI_GetBValue($color)], _
[_WinAPI_GetRValue($mask), _WinAPI_GetGValue($mask), _WinAPI_GetBValue($mask)]]
Local $retour = StringTrimRight($color, 6)
For $i = 0 To UBound($colors, 2)-1
$retour &= Hex($colors[0][$i]-Floor(($colors[0][$i]*$colors[1][$i])/255), 2)
Next
Return $retour
EndFunc
Func ColorAdd($color, $mask)
Local $colors[2][3] = [ [_WinAPI_GetRValue($color), _WinAPI_GetGValue($color), _WinAPI_GetBValue($color)], _
[_WinAPI_GetRValue($mask), _WinAPI_GetGValue($mask), _WinAPI_GetBValue($mask)]]
Local $retour = StringTrimRight($color, 6)
For $i = 0 To UBound($colors, 2)-1
$retour &= Hex(_Min($colors[0][$i]+$colors[1][$i], 255), 2)
Next
Return $retour
EndFunc
Func ColorSub($color, $mask)
Local $colors[2][3] = [ [_WinAPI_GetRValue($color), _WinAPI_GetGValue($color), _WinAPI_GetBValue($color)], _
[_WinAPI_GetRValue($mask), _WinAPI_GetGValue($mask), _WinAPI_GetBValue($mask)]]
Local $retour = "0x"
For $i = 0 To UBound($colors, 2)-1
$retour &= Hex(_Max($colors[0][$i]-$colors[1][$i], 0), 2)
Next
Return $retour
EndFunc
Func GUICtrlCreatePicPng($file, $x, $y, $w = Default, $h = Default, $disable = Default, $xSub = Default, $ySub = Default)
Local $hImg = $file
Local $dispose = False
If(Not(IsPtr($hImg))) Then
$dispose = True
$hImg = _GDIPlus_ImageLoadFromFile($file)
EndIf
If($w = Default) Then $w = IsPtr($hImg) ? _GDIPlus_ImageGetWidth($hImg) : 1
If($h = Default) Then $h = IsPtr($hImg) ? _GDIPlus_ImageGetHeight($hImg) : 1
If($disable = Default) Then $disable = False
If($xSub = Default) Then $xSub = 0
If($ySub = Default) Then $ySub = 0
Local $id = GUICtrlCreatePic("", $x-$xSub*$w, $y-$ySub*$h, $w, $h)
GUICtrlSetPng($id, $hImg, $dispose)
If($disable) Then GUICtrlSetState($id, $GUI_DISABLE)
Return $id
EndFunc
Func GUICtrlSetPng($id, $file, $dispose = True)
Local $retour = False
Local $hImg = $file
If(FileExists($file)) Then
$hImg = _GDIPlus_ImageLoadFromFile($file)
$dispose = True
EndIf
If(IsPtr($hImg)) Then
Local $hBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImg)
_WinAPI_DeleteObject(GUICtrlSendMsg($id, 0x0172, 0, $hBmp))
If($dispose) Then _GDIPlus_ImageDispose($hImg)
_WinAPI_InvalidateRect(GUICtrlGetHandle($id))
$retour = True
EndIf
Return $retour
EndFunc
Func _exit_iconmanip()
_GDIPlus_Shutdown()
EndFuncMa question est donc : Peut ajouter un "masque" sur une image de façon plus rapide, tout en gardant la possibilité de ne pas traiter une couleur précise (en 0, 0) ?
Merci.


