Network_Guy Posted July 10, 2019 Share Posted July 10, 2019 (edited) hi community, i built a script to get every pixel on a high quality image (4000*6000 pixel) and alter them if needed , the problem is my code is so slow , any suggestion ? here is the code and some random HQ image #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <WinAPIHObj.au3> #include <AutoItConstants.au3> _GDIPlus_Startup() $ImagePath="image.jpg" $hBitmap = _GDIPlus_BitmapCreateFromFile($ImagePath) $width = _GDIPlus_ImageGetWidth($hBitmap) $height = _GDIPlus_ImageGetHeight($hBitmap) $Count=0 $total=$width*$height ProgressOn("Filter","Progress Percent", "0%", -1, -1, BitOR($DLG_NOTONTOP, $DLG_MOVEABLE)) for $iX=0 to $width-1 for $iY=0 to $height-1 $iColor = _GDIPlus_BitmapGetPixel($hBitmap, $iX, $iY) ;get current pixel color $iR = BitShift(BitAND($iColor, 0x00FF0000), 16) ;extract red color channel $iG = BitShift(BitAND($iColor, 0x0000FF00), 8) ;extract green color channel $iB = BitAND($iColor, 0x000000FF) if $iR>150 or $iG>150 or $iB> 140 then _GDIPlus_BitmapSetPixel($hBitmap, $iX, $iY, "0xFFFFFFFF" ) $Count+=1 $percent=($Count/$total)*100 ;~ MsgBox(0,"",$percent&@crlf&$Count&@crlf&$total&@crlf) ProgressSet($percent,$Count) Next Next _GDIPlus_ImageSaveToFile($hBitmap,"Result.jpg") _GDIPlus_BitmapDispose($hBitmap) ProgressOff() _GDIPlus_Shutdown() Edited July 10, 2019 by Network_Guy Link to comment Share on other sites More sharing options...
TheXman Posted July 10, 2019 Share Posted July 10, 2019 9 minutes ago, Network_Guy said: $total=$width&$height What is the above line supposed to be doing? It certainly isn't the correct syntax for multiplication. CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
Network_Guy Posted July 10, 2019 Author Share Posted July 10, 2019 (edited) 6 hours ago, TheXman said: What is the above line supposed to be doing? It certainly isn't the correct syntax for multiplication. sry i missed that i edited the code , but same performance Edited July 10, 2019 by Network_Guy Link to comment Share on other sites More sharing options...
InnI Posted July 11, 2019 Share Posted July 11, 2019 #include <GDIPlus.au3> $t = TimerInit() _GDIPlus_Startup() $ImagePath = "image.jpg" $hBitmap = _GDIPlus_BitmapCreateFromFile($ImagePath) $Width = _GDIPlus_ImageGetWidth($hBitmap) $Height = _GDIPlus_ImageGetHeight($hBitmap) Global $aColors[] = [0x970000,0x009700,0x00008D] ; if $iR>0x96 or $iG>0x96 or $iB>0x8C => $hIA = _GDIPlus_ImageAttributesCreate() $hNewImg = _GDIPlus_BitmapCloneArea($hBitmap, 0, 0, $Width, $Height, $GDIP_PXF32PARGB) _GDIPlus_BitmapDispose($hBitmap) For $i = 0 To 2 $hBufImg = _GDIPlus_BitmapCreateFromScan0($Width, $Height) $hBufGra = _GDIPlus_ImageGetGraphicsContext($hBufImg) _GDIPlus_GraphicsClear($hBufGra, 0xFFFFFFFF) ; => then _GDIPlus_BitmapSetPixel($hBitmap, $iX, $iY, 0xFFFFFFFF) _GDIPlus_ImageAttributesSetColorKeys($hIA, 0, True, $aColors[$i], 0xFFFFFFFF) _GDIPlus_GraphicsDrawImageRectRect($hBufGra, $hNewImg, 0, 0, $Width, $Height, 0, 0, $Width, $Height, $hIA) _GDIPlus_ImageDispose($hNewImg) _GDIPlus_GraphicsDispose($hBufGra) $hNewImg = _GDIPlus_BitmapCloneArea($hBufImg, 0, 0, $Width, $Height, $GDIP_PXF32PARGB) _GDIPlus_ImageDispose($hBufImg) Next _GDIPlus_ImageAttributesDispose($hIA) _GDIPlus_ImageSaveToFile($hNewImg,"Result.jpg") _GDIPlus_BitmapDispose($hNewImg) _GDIPlus_Shutdown() ConsoleWrite(TimerDiff($t) & @CRLF) Network_Guy 1 Link to comment Share on other sites More sharing options...
Network_Guy Posted July 12, 2019 Author Share Posted July 12, 2019 (edited) 16 hours ago, InnI said: #include <GDIPlus.au3> $t = TimerInit() _GDIPlus_Startup() $ImagePath = "image.jpg" $hBitmap = _GDIPlus_BitmapCreateFromFile($ImagePath) $Width = _GDIPlus_ImageGetWidth($hBitmap) $Height = _GDIPlus_ImageGetHeight($hBitmap) Global $aColors[] = [0x970000,0x009700,0x00008D] ; if $iR>0x96 or $iG>0x96 or $iB>0x8C => $hIA = _GDIPlus_ImageAttributesCreate() $hNewImg = _GDIPlus_BitmapCloneArea($hBitmap, 0, 0, $Width, $Height, $GDIP_PXF32PARGB) _GDIPlus_BitmapDispose($hBitmap) For $i = 0 To 2 $hBufImg = _GDIPlus_BitmapCreateFromScan0($Width, $Height) $hBufGra = _GDIPlus_ImageGetGraphicsContext($hBufImg) _GDIPlus_GraphicsClear($hBufGra, 0xFFFFFFFF) ; => then _GDIPlus_BitmapSetPixel($hBitmap, $iX, $iY, 0xFFFFFFFF) _GDIPlus_ImageAttributesSetColorKeys($hIA, 0, True, $aColors[$i], 0xFFFFFFFF) _GDIPlus_GraphicsDrawImageRectRect($hBufGra, $hNewImg, 0, 0, $Width, $Height, 0, 0, $Width, $Height, $hIA) _GDIPlus_ImageDispose($hNewImg) _GDIPlus_GraphicsDispose($hBufGra) $hNewImg = _GDIPlus_BitmapCloneArea($hBufImg, 0, 0, $Width, $Height, $GDIP_PXF32PARGB) _GDIPlus_ImageDispose($hBufImg) Next _GDIPlus_ImageAttributesDispose($hIA) _GDIPlus_ImageSaveToFile($hNewImg,"Result.jpg") _GDIPlus_BitmapDispose($hNewImg) _GDIPlus_Shutdown() ConsoleWrite(TimerDiff($t) & @CRLF) Pure Awesomeness : Mycode=385200 Sec ~1H:7M@InnI code = 3 sec Thank you very much . Edited July 12, 2019 by Network_Guy Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now