I put the image in a struct and looped the dither stuff, faster but no preview.
#include <GDIPlus.au3>
HotKeySet("{ESC}", "_exit")
_GDIPlus_Startup()
Global $Floyd[12] = [7, 3, 5, 1, 1, -1, 0, 1, 0, 1, 1, 1]
Global $Image = _GDIPlus_BitmapCreateFromFile("graytest.png")
Global $Width = _GDIPlus_ImageGetWidth($Image), $Height = _GDIPlus_ImageGetHeight($Image)
$Gui = GUICreate("Floyd-Steinberg Dithering", $Width, $Height)
GUISetState()
$Graphics = _GDIPlus_GraphicsCreateFromHWND($Gui)
_GDIPlus_GraphicsDrawImageRect($Graphics, $Image, 0, 0, $Width, $Height)
$Bitmap1 = _GDIPlus_BitmapLockBits($Image, 0, 0, $Width, $Height, BitOR($GDIP_ILMWRITE, $GDIP_ILMREAD), $GDIP_PXF32ARGB)
$Pixels1 = DllStructCreate("dword[" & $Width * $Height & "];", DllStructGetData($Bitmap1, "Scan0"))
$floatstruct = DllStructCreate("float")
$dwordstruct = DllStructCreate("dword", DllStructGetPtr($floatstruct))
;AARRGGBB to float
For $y = 0 To $Height - 1
$RowOffset = $y * $Width + 1
For $x = 0 To $Width - 1
$oldPixel = Dec(Hex(DllStructGetData($Pixels1, 1, $x + $RowOffset), 2)) / 255
DllStructSetData($floatstruct, 1, $oldPixel) ;write into float struct
$oldPixel = DllStructGetData($dwordstruct, 1) ;read as dword (aka "pixel" AARRGGBB)
DllStructSetData($Pixels1, 1, $oldPixel, $x + $RowOffset) ;store the float number as "pixel" AARRGGBB
Next
Next
For $y = 0 To $Height - 1
$RowOffset = $y * $Width + 1
For $x = 0 To $Width - 1
$oldpixel = DllStructGetData($Pixels1, 1, $x + $RowOffset)
DllStructSetData($dwordstruct, 1, $oldPixel) ;write into dwordstruct (place of floatstruct)
$oldPixel = DllStructGetData($floatstruct, 1) ;read float
$newpixel = ($oldpixel <= 0.5) ? 0:1
DllStructSetData($Pixels1, 1, "0xFF" & Hex($newpixel * 255, 2) & Hex($newpixel * 255, 2) & Hex($newpixel * 255, 2), $x + $RowOffset)
$quant_error = $oldPixel - $newpixel
;-------Floyd-Steinberg
For $Loop = 0 To 3
$pixel = DllStructGetData($Pixels1, 1, ($x + $Floyd[$Loop+4]) + ($y + $Floyd[$Loop+8]) * $Width + 1);get pixel integer/DWORD AARRGGBB
DllStructSetData($dwordstruct, 1, $pixel) ;set into DWORD struct
$col = DllStructGetData($floatstruct, 1) ;read float from DWORD
$float = $col + ($Floyd[$Loop] / 16 * $quant_error) ;calculate with float
DllStructSetData($floatstruct, 1, $float) ;write into float struct
$pixel = DllStructGetData($dwordstruct, 1) ;get dword from float and
DllStructSetData($Pixels1, 1, $pixel, ($x + $Floyd[$Loop+4]) + ($y + $Floyd[$Loop+8]) * $Width + 1) ;write the "float" as a "pixel"
Next
Next
Next
_GDIPlus_BitmapUnlockBits($Image, $Bitmap1)
_GDIPlus_GraphicsDrawImageRect($Graphics, $Image, 0, 0, $Width, $Height)
While GUIGetMsg <> -3
Sleep(10)
WEnd
Func _exit()
Exit
EndFunc