MCode for 64bit Gdip_AlphaMask Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
User avatar
noname
Posts: 509
Joined: 19 Nov 2013, 09:15

MCode for 64bit Gdip_AlphaMask

28 Oct 2017, 09:21

Can someone help to make a 64bit compatible mcode from Tic's example for Gdip_AlphaMask , the one posted is x86 machine code only.
Or am i wrong to think that this is the reason it works with ahk 32bit and not with ahk 64bit or does it depend on the cpu only?
Thank you in advance :)

see https://autohotkey.com/board/topic/1034 ... -aliasing/

Code: Select all

int Gdip_AlphaMask(unsigned int * Bitmap, unsigned int * BitmapMask, unsigned int * BitmapNew, int w1, int h1, int w2, int h2, int Stride1, int Stride2, int sx, int sy, int invert)
{
    int o1 = Stride1/4, o2 = Stride2/4;
    if (!invert)
    {
        for (int y = 0; y < h2; ++y)
        {
            for (int x = 0; x < w2; ++x)
            {
                BitmapNew[(x+sx)+(y+sy)*o1] = (BitmapMask[x+(y*o2)] & 0xff000000) | (Bitmap[(x+sx)+(y+sy)*o1] & 0x00ffffff);
            }
        }
    }
    else
    {
        for (int y = 0; y < h2; ++y)
        {
            for (int x = 0; x < w2; ++x)
            {
                BitmapNew[(x+sx)+(y+sy)*o1] = (0xff000000 - (BitmapMask[x+(y*o2)] & 0xff000000)) | (Bitmap[(x+sx)+(y+sy)*o1] & 0x00ffffff);
            }
        }
    }
    return 0;
}
soundcloud.com/user-32706894
User avatar
LinearSpoon
Posts: 156
Joined: 29 Sep 2013, 22:55

Re: MCode for 64bit Gdip_AlphaMask  Topic is solved

28 Oct 2017, 10:10

You are correct, the MCode will be different for 32 bit vs 64 bit. I've rewritten the function to work on any version of AHK. Be sure to use a 64 bit compatible version of GDIP (gdip_all.ahk).

Code: Select all

MCode(mcode)
{
  static e := {1:4, 2:1}, c := (A_PtrSize=8) ? "x64" : "x86"
  if (!regexmatch(mcode, "^([0-9]+),(" c ":|.*?," c ":)([^,]+)", m))
    return
  if (!DllCall("crypt32\CryptStringToBinary", "str", m3, "uint", 0, "uint", e[m1], "ptr", 0, "uint*", s, "ptr", 0, "ptr", 0))
    return
  p := DllCall("GlobalAlloc", "uint", 0, "ptr", s, "ptr")
  if (c="x64")
    DllCall("VirtualProtect", "ptr", p, "ptr", s, "uint", 0x40, "uint*", op)
  if (DllCall("crypt32\CryptStringToBinary", "str", m3, "uint", 0, "uint", e[m1], "ptr", p, "uint*", s, "ptr", 0, "ptr", 0))
    return p
  DllCall("GlobalFree", "ptr", p)
}


Gdip_AlphaMask(pBitmap, pBitmapMask, x, y, invert=0) {    ; by Tic. http://www.autohotkey.com/board/topic/103475-gdi-cutting-anti-aliasing/#entry638772
    static _AlphaMask := MCode("
(LTrim Join
1,x86:518b4424249983e2035355568d0c028b4424349983e203c1f902578d3402c1fe02837c2444000f85980000008b4424
308944243885c00f8e340100008d1c8d000000000faf4c24408d14b500000000895c24348b7424208b5c241c89542444034c
243c8d2c8e8b4c242c8b742434669085c97e3b8b7c24188bd52b7c24208bc38bf18b0c178d40043348fc8d520481e1ffffff
003348fc894afc83ee0175e38b4424388b4c242c8b5424448b74243403ee03da83e8018944243875b45f5e5d33c05b59c38b
5424308954241085d20f8e9c0000008b7c24208d04b5000000008b6c241c894424348d048d000000000faf4c24408b5c2434
894424388bf0034c243c8d048f8b4c242c894424440f1f400085c97e4b8b5c24188bd02bdf8bf58bf98b068d760425000000
ff8d5204b9000000ff2bc88b441afc25ffffff000bc8894afc83ef0175d98b4424448b5424108b4c242c8b5c24348b742438
8b7c242003c603eb83ea01894424448954241075a05f5e5d33c05b59c3,x64:48895c24084c8944241848895424105556574
1544155415641574883ec108b8424900000004c8bc248637424789983e2034c8be903c2c1f8024c63d08b842488000000998
3e20303c2c1f80283bc24a8000000004863c848890c240f85a60000008b8c248000000085c90f8e3a0100004c63bc24a0000
0004e8d3495000000004c63a424980000004533c9458bd9498bea498bd88bf94885f67e584c8b5424604b8d1439480faf142
4488bc3492bd34903d448c1e202492bd04c03d24e8d042a488bd60f1f4000660f1f840000000000418b0c003308488d40048
1e1ffffff003348fc41894c02fc4883ea0175e24c8b4424584c03dd4903de49ffc14883ef017594e9a30000008b842480000
00085c00f8e940000004c63b424a00000004533c94c63bc2498000000418bd94c8b642458498bea8bf84885f67e634c8b542
4604b8d1431480fafd14c8bdb4c2bda4d2bdf49c1e3024a8d043a4d2bdd4c8d0485000000004d03dc4d03c5488bd64d2bd54
38b04184d8d400425000000ffb9000000ff2bc8418b40fc25ffffff000bc843894c02fc4883ea0175d6488b0c244803dd49f
fc14883ef01758c33c0488b5c24504883c410415f415e415d415c5f5e5dc3
)")

    Gdip_GetDimensions(pBitmap, w1, h1), Gdip_GetDimensions(pBitmapMask, w2, h2)
    pBitmapNew := Gdip_CreateBitmap(w1, h1)
    if !pBitmapNew
        return -1

    E1 := Gdip_LockBits(pBitmap, 0, 0, w1, h1, Stride1, Scan01, BitmapData1)
    E2 := Gdip_LockBits(pBitmapMask, 0, 0, w2, h2, Stride2, Scan02, BitmapData2)
    E3 := Gdip_LockBits(pBitmapNew, 0, 0, w1, h1, Stride3, Scan03, BitmapData3)
    if (E1 || E2 || E3)
        return -2

    E := DllCall(_AlphaMask, "ptr", Scan01, "ptr", Scan02, "ptr", Scan03, "int", w1, "int", h1, "int", w2, "int", h2, "int", Stride1, "int", Stride2, "int", x, "int", y, "int", invert, "cdecl int")
    Gdip_UnlockBits(pBitmap, BitmapData1), Gdip_UnlockBits(pBitmapMask, BitmapData2), Gdip_UnlockBits(pBitmapNew, BitmapData3)

    return (E = "") ? -3 : pBitmapNew
}
User avatar
noname
Posts: 509
Joined: 19 Nov 2013, 09:15

Re: MCode for 64bit Gdip_AlphaMask

28 Oct 2017, 10:16

Thank you very much LinearSpoon, much appreciated :)
soundcloud.com/user-32706894

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], Bort P, flyingDman, Google [Bot], MannyKSoSo and 208 guests