Modify

Opened 10 years ago

Closed 10 years ago

#1155 closed Feature Request (Fixed)

_WinAPI_CreateSolidBitmap() is too slow

Reported by: Yashied Owned by: Jpm
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 10 years ago.

Download all attachments as: .zip

Change History (8)

Changed 10 years ago by Yashied

comment:1 Changed 10 years ago by TicketCleanup

  • Version 3.3.1.1 deleted

Automatic ticket cleanup.

comment:2 Changed 10 years ago by Zedna

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

comment:3 Changed 10 years ago by Yashied

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 Changed 10 years ago by Jpm

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 Changed 10 years ago by Yashied

You mixed up the parameters.

#include <WinAPI.au3>

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

comment:6 Changed 10 years ago by Jpm

Thanks,
I hope it is doing the same job

comment:7 Changed 10 years ago by Jpm

  • Milestone set to 3.3.1.2
  • Owner set to Jpm
  • Resolution set to Fixed
  • Status changed from new to closed

Fixed in version: 3.3.1.2

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The owner will remain Jpm.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.