Base64PNG_to_HICON() : Uses native PNG Decompression (requires WIN VISTA and later)

Post your working scripts, libraries and tools
User avatar
jNizM
Posts: 2422
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: Base64PNG_to_HICON() : Uses native PNG Decompression (requires WIN VISTA and later)

05 Sep 2017, 08:05

Should be also possible with ComObjCreate("Msxml2.DOMDocument"), createElement("base64") and dataType := "bin.base64"
[AHK] 1.1.30.03 x64 Unicode | [WIN] 10 Pro (Version 1903) x64 | [GitHub] Profile
Donations are appreciated if I could help you
User avatar
jNizM
Posts: 2422
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: Base64PNG_to_HICON() : Uses native PNG Decompression (requires WIN VISTA and later)

05 Sep 2017, 09:03

Code: Select all

hICON := b64Decode(PNG10x10, 48, 48)

b64Decode(b64, w := 16, h := 16) ; borrowed from uberi
{
    static CharSet := "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
    VarSetCapacity(bin, Ceil(((len := StrLen(b64)) / 4) * 3), 0), i := 1, p := 0
    loop % len // 4 {
        b := ((InStr(CharSet, SubStr(b64, i,     1), true) - 1) << 0x12)
           | ((InStr(CharSet, SubStr(b64, i + 1, 1), true) - 1) << 0x0c)
           | ((InStr(CharSet, SubStr(b64, i + 2, 1), true) - 1) << 0x06)
           | ((InStr(CharSet, SubStr(b64, i + 3, 1), true) - 1)        )
        NumPut((b >> 0x10) | (((b >> 0x08) & 0xff) << 0x08) | ((b & 0xff) << 0x10), bin, p, "uint")
        i += 4, p += 3
    }
    if (len & 3) {
        b := ((InStr(CharSet, SubStr(b64, i, 1), true) - 1) << 0x12) | ((InStr(CharSet, SubStr(b64, i + 1, 1), true) - 1) << 0x0c)
        NumPut(b >> 0x10, bin, p, "uchar")
        if (len & 1) {
            b |= ((InStr(CharSet, SubStr(b64, i + 2, 1), true) - 1) << 0x06)
            NumPut((b >> 0x08) & 0xff, bin, p + 1, "uchar")
        }
    }
    return DllCall("CreateIconFromResourceEx", "ptr", &bin, "uint", len, "int", true, "uint", 0x30000, "int", W, "int", H, "uint", 0, "uptr") 
}
[AHK] 1.1.30.03 x64 Unicode | [WIN] 10 Pro (Version 1903) x64 | [GitHub] Profile
Donations are appreciated if I could help you
Helgef
Posts: 3778
Joined: 17 Jul 2016, 01:02
Contact:

Re: Base64PNG_to_HICON() : Uses native PNG Decompression (requires WIN VISTA and later)

05 Sep 2017, 13:36

SKAN wrote: Its my policy. I will specifically mention, if my function is not meant for XP.
:salute:
SKAN wrote:A perfect one-liner to avoid the additional DllCall() would be a good improvement for that function.
round(strlen(B64)/4*3) or round(strlen(strReplace( B64,"=","=",e))/4*3-e), either will work, I prefer the first. I wouldn't do the floor, I'd worry about potentally rounding down exactSize-0.0000000000x to exactSize-1 when there is no padding.
I guess you eliminate the size calculation dllcall for the Base64Enc function too, nChars:=ceil(nBytes/4*3)+linebreaks+spaces. :?:

@ jNizM, hi and interesting code :wave: (My guess is your nick is the most copy-pasted on the forum, I can't remeber how to spell it at least :D )

Cheers.
User avatar
SKAN
Posts: 363
Joined: 29 Sep 2013, 16:58

Re: Base64PNG_to_HICON() : Uses native PNG Decompression (requires WIN VISTA and later)

06 Sep 2017, 12:02

@ jNizM
Thanks for sharing :)
PS: I miss uberi.
Helgef wrote:round(strlen(B64)/4*3) or round(strlen(strReplace( B64,"=","=",e))/4*3-e), either will work, I prefer the first.
Thank you. I will it and revert. :)

Return to “Scripts and Functions”

Who is online

Users browsing this forum: robodesign and 35 guests