Gdip - v2 ready

Post your working scripts, libraries and tools
iPhilip
Posts: 197
Joined: 02 Oct 2013, 12:21

Gdip - v2 ready

06 Feb 2016, 20:56

Hi Folks,

I updated Gdip (the latest version found here) so that it runs under AHK v1 & v2 (up to 2.0-a072 U32/U64). I thought I would share it in case you are interested.

Code: [Select all] [Download] (Gdip_All_v2.ahk)GeSHi © Codebox Plus

; Work in progress. I will update this page as soon as possible.

Below is a zip file that contains the above code and tutorial files for AHK v1 and v2. If the file name does not indicate a version, it means that it runs as it is under both versions. I did not include BRA.ahk and its associated tutorial as it seems to run only under ANSI code.

*** Work in progress. I will update the zip file as soon as possible ***

Cheers!
Last edited by iPhilip on 09 Feb 2016, 18:55, edited 1 time in total.
Windows 7 Pro (64 bit) - AutoHotkey v1.1+ (Unicode 32-bit)
User avatar
oldbrother
Posts: 134
Joined: 23 Oct 2013, 05:08

Re: Gdip - v2 ready

06 Feb 2016, 22:45

Thanks a lot!
guest3456
Posts: 2025
Joined: 09 Oct 2013, 10:31

Re: Gdip - v2 ready

07 Feb 2016, 00:16

great

however, you might want to edit out the comments at the top of the script, as well in your post text, because i don't believe this supports AHK_Basic, since default values for function parameters must use = instead of := in AHK Basic (v1.0). probably this only supports AHK_L+ (AHK v1.1+)

lexikos
Posts: 5410
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Gdip - v2 ready

07 Feb 2016, 05:00

That's right, and given that it doesn't support v1.0, there's no point in Ptr := A_PtrSize ? "UPtr" : "UInt"; may as well just use "Ptr".
just me
Posts: 4685
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Gdip - v2 ready

07 Feb 2016, 05:39

... also, all conversions like

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

might be replaced by StrGet() / StrPut() respectively WStr.
Remaining with AHK 1.1.25.02 until v2 will become beta.
guest3456
Posts: 2025
Joined: 09 Oct 2013, 10:31

Re: Gdip - v2 ready

17 Nov 2016, 23:04

iPhilip wrote:I updated Gdip so that it runs under AHK v1 & v2 (up to 2.0-a072 U32/U64).

*** Work in progress. I will update the zip file as soon as possible ***


I've tried to tackle this as well and its working good so far.

You can find my updates here:

https://github.com/mmikeww/AHKv2-Gdip

arcticir
Posts: 471
Joined: 17 Nov 2013, 11:32

Re: Gdip - v2 ready

19 Nov 2016, 11:53

guest3456 wrote:
iPhilip wrote:I updated Gdip so that it runs under AHK v1 & v2 (up to 2.0-a072 U32/U64).

*** Work in progress. I will update the zip file as soon as possible ***


I've tried to tackle this as well and its working good so far.

You can find my updates here:

https://github.com/mmikeww/AHKv2-Gdip



V1 and V2 have been broken
The pursuit of their compatibility, there is no need.
And will lose the V2 unique elegance.
So you can separate them?
Unless you use them at the same time.
But I can not imagine, because I only use V2.
egocarib
Posts: 67
Joined: 21 May 2015, 18:21

Re: Gdip - v2 ready

25 Sep 2017, 11:33

I am trying to convert Gdip_ImageSearch to work in AHKv2. I am using mmikeww's AHKv2 version of Gdip as a base.

So far, ImageSearch works only if I do not specify coordinates for the search. When I specify coordinates, it no longer works.

After debugging a bit, the problem appears to be in Gdip_LockBits. The BitmapData coming from this function seems incorrect or corrupted somehow, because when ImageSearch tries to extract the height and width from the BitmapData, it is getting extremely huge integers. Since Gdip_LockBits doesn't seem to be used by very many functions (besides Gdip_ImageSearch), I am guessing perhaps there is a bug here that no one noticed because they weren't really using this function in the base library without image search.

Anyone know what the issue might be?



Gdip_LockBits from mmikeww's AHKv2 version of Gdip (_E seems to always be 0 when I debug)

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



This is the part of Gdip_ImageSearch that is pulling width/height from LockBits' BitmapData (see the final three lines)

Code: [Select all] [Download] GeSHi © Codebox Plus

    ; Getting the dimensions and locking the bits [haystack]
Gdip_GetImageDimensions(pBitmapHaystack,hWidth,hHeight)
; Last parameter being 1 says the LockMode flag is "READ only"
If Gdip_LockBits(pBitmapHaystack,0,0,hWidth,hHeight,hStride,hScan,hBitmapData,1)
OR !(hWidth := NumGet(hBitmapData,0))
OR !(hHeight := NumGet(hBitmapData,4))
Return -1004


Full code of Gdip_ImageSearch I've been translating to work in AHKv2 (Ignore the OutputDebug statements I've added)

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Helgef
Posts: 2252
Joined: 17 Jul 2016, 01:02
Contact:

Re: Gdip - v2 ready

25 Sep 2017, 12:00

Code: [Select all] [Download] GeSHi © Codebox Plus

(hWidth := NumGet(hBitmapData,0))
OR !(hHeight := NumGet(hBitmapData,4))

This was mentioned somewhere recently, you need to specify "uint" for the numgets if on ahk 64 bit.
Cheers.
User avatar
jeeswg
Posts: 2252
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Gdip - v2 ready

25 Sep 2017, 12:26

I just checked my copy of Gdip_ImageSearch and indeed there are four instances of NumGet that don't specify the type, presumably UInt. However, this would suggest that Gdip_ImageSearch does not work on x64, (or that maybe it can work on x64 even if it gets this wrong,) is this the case?

Note: sometimes you can leave out the type, if it's Ptr/UPtr for NumPut, or UPtr for NumGet (although AutoHotkey reads a UInt64 as an Int64).
egocarib
Posts: 67
Joined: 21 May 2015, 18:21

Re: Gdip - v2 ready

25 Sep 2017, 12:31

That was the problem. Thanks, Helgef!

I'm guessing those other NumGets should be fine, because they are all handling pointers, and UPtr is the default type used according to the v2 docs. Right?
As far as I can tell, it is working on x64 now without problem. If there are memory or other x64 issues that might cause unseen problems here, please let me know.


Here's my currently working version of Gdip_ImageSearch for AHKv2 64bit (I started from MasterFocus' version):

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



Here's a diff of the changes I made to make it v2 compatible (refer to +/- in left margin):

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Last edited by egocarib on 25 Sep 2017, 13:12, edited 2 times in total.
User avatar
jeeswg
Posts: 2252
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Gdip - v2 ready

25 Sep 2017, 12:43

I had a browse through your script and the original script:

This doesn't look like a particularly bad script to convert, my only comments that I could think would be:

Do these work? If not you could use RegExMatch.

Code: [Select all] [Download] GeSHi © Codebox Plus

    If Trans is "number" && Trans >= 0 && Trans <= 0xFFFFFF

If !(TransColor is "number" && TransColor >= 0 && TransColor <= 0xFFFFFF)


One possibility, this may not be necessary:
Sometimes you might need to force a string/number:
"" var, var+0

Did you try the original Gdip_ImageSearch with both AHK v1 x64 and x32 first?
Helgef
Posts: 2252
Joined: 17 Jul 2016, 01:02
Contact:

Re: Gdip - v2 ready

25 Sep 2017, 13:01

If there are memory or other x64 issues that might cause unseen problems here, please let me know.

Hello, I know nothing about this :wave:
Here's a diff of the changes I made to make it v2 compatible (refer to +/- in left margin):

Comma in Loop, LEN is not ok, is in expression is ok ;)

Cheers.
egocarib
Posts: 67
Joined: 21 May 2015, 18:21

Re: Gdip - v2 ready

25 Sep 2017, 13:17

jeeswg wrote:Do these work? If not you could use RegExMatch.

Code: [Select all] [Download] GeSHi © Codebox Plus

 If Trans is "number" && Trans >= 0 && Trans <= 0xFFFFFF
If !(TransColor is "number" && TransColor >= 0 && TransColor <= 0xFFFFFF)

Yes, they seem to work (and I assume are better performance than Regex). I ran some tests and it doesn't seem to matter what format is used for Trans (even if it's passed as a string literal).
I didn't try the AHKv1 x32 or x64 versions because I am using this for a codebase that is already heavily invested in v2.

Helgef wrote:Comma in Loop, LEN is not ok, is in expression is ok ;)

Thanks again. I updated the code and the diff in the post above to remove the comma from Loop, LEN
guest3456
Posts: 2025
Joined: 09 Oct 2013, 10:31

Re: Gdip - v2 ready

07 Oct 2017, 20:53

egocarib wrote:That was the problem. Thanks, Helgef!

I'm guessing those other NumGets should be fine, because they are all handling pointers, and UPtr is the default type used according to the v2 docs. Right?
As far as I can tell, it is working on x64 now without problem. If there are memory or other x64 issues that might cause unseen problems here, please let me know.
..

Here's a diff of the changes I made to make it v2 compatible (refer to +/- in left margin):

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



i have already created a pull request for the NumGet changes, but it doesnt seem like MasterFocus has even logged into github recently

https://github.com/MasterFocus/AutoHotkey/pull/1

Perhaps you can make a pull request for your changes as well, assuming that they are backward compatible with both v1 and v2, otherwise might not be much point. but thanks a lot for sharing your changes


egocarib wrote: I am using mmikeww's AHKv2 version of Gdip as a base.

and if you have any new changes for the gdip library for the recent v2 releases, please submit a pull request and i will add them. i believe that was only tested up until ahk v2-a79


Return to “Scripts and Functions”

Who is online

Users browsing this forum: Delta Pythagorean and 11 guests