Modify

Opened 17 years ago

Closed 16 years ago

#1155 closed Feature Request (Fixed)

_WinAPI_CreateSolidBitmap() is too slow

Reported by: Yashied Owned by: J-Paul Mesnage
Milestone: 3.3.1.2 Component: AutoIt
Version: Severity: None
Keywords: _WinAPI_CreateSolidBitmap Cc:

Description

As this is a very useful function is too slow, I suggest to replace it with the following code. My tests for the current function (_WinAPI_CreateSolidBitmap(0, 800, 600, 0xFFFFFF)) - ~1.211 seconds. For function, which I suggest to - 0.203 seconds (almost six times faster, and it is only for a single bitmap).

; #FUNCTION# ====================================================================================================================
; Name...........: _WinAPI_CreateSolidBitmap
; Description....: Creates a solid color bitmap
; Syntax.........: _WinAPI_CreateSolidBitmap($hWnd, $iColor, $iWidth, $iHeight, $fRGB)
; Parameters.....: $hWnd        - Handle to the window where the bitmap will be displayed
;                  $iColor      - The color of the bitmap, depends on the $fRGB value
;                  $iWidth      - The width of the bitmap
;                  $iHeight     - The height of the bitmap
;                  $fRGB        - Type of $iColor passed in, valid values:
;                  |0 - BGR
;                  |1 - RGB (Default)
; Return values..: Success      - Handle to the bitmap
;                  Failure      - 0 and sets the @error flag to non-zero
; Author.........: Paul Campbell (PaulIA)
; Modified.......: Yashied
; Remarks........: When you no longer need the bitmap, call the _WinAPI_DeleteObject() function to delete it.
; Related........: _WinAPI_CreateCompatibleBitmap
; Link...........:
; Example........:
; ===============================================================================================================================

Func __WinAPI_CreateSolidBitmap($hWnd, $iColor, $iWidth, $iHeight, $fRGB = 1)

	Local $tRect, $hBitmap, $hBrush, $hOld, $hDC, $hDestDC, $hDestSv

	$hDC = _WinAPI_GetDC($hWnd)
	$hDestDC = _WinAPI_CreateCompatibleDC($hDC)
	$hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $iWidth, $iHeight)
	$hOld = _WinAPI_SelectObject($hDestDC, $hBitmap)
	$tRect = DllStructCreate($tagRECT)
	DllStructSetData($tRect, 1, 0)
	DllStructSetData($tRect, 2, 0)
	DllStructSetData($tRect, 3, $iWidth)
	DllStructSetData($tRect, 4, $iHeight)
	If $fRGB Then
		$iColor = BitOR(BitAND($iColor, 0x00FF00), BitShift(BitAND($iColor, 0x0000FF), -16), BitShift(BitAND($iColor, 0xFF0000), 16))
	EndIf
	$hBrush = _WinAPI_CreateSolidBrush($iColor)
	_WinAPI_FillRect($hDestDC, DllStructGetPtr($tRect), $hBrush)
	If @error Then
		_WinAPI_DeleteObject($hBitmap)
		$hBitmap = 0
	EndIf
	_WinAPI_DeleteObject($hBrush)
	_WinAPI_ReleaseDC($hWnd, $hDC)
	_WinAPI_SelectObject($hDestDC, $hOld)
	_WinAPI_DeleteDC($hDestDC)
	Return SetError(($hBitmap = 0), 0, $hBitmap)
EndFunc   ;==>__WinAPI_CreateSolidBitmap

Attachments (1)

_WinAPI_CreateSolidBitmap.au3 (2.3 KB ) - added by Yashied 17 years ago.

Download all attachments as: .zip

Change History (8)

by Yashied, 17 years ago

comment:1 by TicketCleanup, 17 years ago

Version: 3.3.1.1

Automatic ticket cleanup.

comment:2 by Zedna, 17 years ago

Another way for the case Developers don't want to touch original version
is to add this as new UDF _WinAPI_CreateSolidBitmapEx()

comment:3 by Yashied, 17 years ago

Sorry, I made a wrong benchmark (looked in SciTE console). The correct results are as follows.

Current functions: ~0.975121 seconds
My functions: ~0.000426 seconds

Ie almost instantaneously. I think _WinAPI_CreateSolidBitmap() should be updated.

Thanks.

comment:4 by J-Paul Mesnage, 16 years ago

I try the following code renaming your function just for local test

#include <WinAPI.au3>

$start	= TimerInit()
$ret	= _WinAPI_CreateSolidBitmap_(0, 800, 600, 0xFFFFFF)
$elapse	= TimerDiff($start)

and I get an autoIt error running under Vista

_WinAPI_CreateCompatibleBitmap: incorrect parameter

Can I have a working script?

comment:5 by Yashied, 16 years ago

You mixed up the parameters.

#include <WinAPI.au3>

$start	= TimerInit()
$ret	= _WinAPI_CreateSolidBitmap_(0, 0xFFFFFF, 800, 600)
$elapse	= TimerDiff($start)

comment:6 by J-Paul Mesnage, 16 years ago

Thanks,
I hope it is doing the same job

comment:7 by J-Paul Mesnage, 16 years ago

Milestone: 3.3.1.2
Owner: set to J-Paul Mesnage
Resolution: Fixed
Status: newclosed

Fixed in version: 3.3.1.2

Modify Ticket

Action
as closed The owner will remain J-Paul Mesnage.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.