Jump to content

GDI_BitMap Get&Set help


Recommended Posts

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()

 

image.jpg

Edited by Network_Guy
Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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 by Network_Guy
Link to comment
Share on other sites

#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)

 

Link to comment
Share on other sites

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 by Network_Guy
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...