ImagePut - A core library for images in AutoHotkey (Now supports HEIC & WEBP)

Post your working scripts, libraries and tools.
AHK_user
Posts: 515
Joined: 04 Dec 2015, 14:52
Location: Belgium

Re: ImagePut - Image library for converting to files, streams, windows, base64, urls, cursors, screen coordinates, clipb

21 Oct 2023, 14:42

Can somebody explain me how you can get the Base64 of an HIcon ?
Preferably by inputting an exe or a window to copy their Icon to a base64 string.

I once managed to get the icon of notepad, but cannot remember how I got the Base64 of the Icon.

Code: Select all

base64 := "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAKNSURBVDhPjZHLTxNRFMbZm7j2/zG6cEPUxK1xZ9wZEk0kBBIKWpB3CuENlldQaSihgGKhtKXTx/QxnVfn3VL6gLbauJbPO4NSG1lwkpNzM5P7/b7v3JbrqnNsCjeZ/9VkSmXvP3oC6rSCe62P4TXK1tyUT625xGWt+Z7iMBBIwmlv7fpztaXFI0m3B6KZolL7CaFSR7L8HeFCFb6Tc+zqJbiIyDKfxSyjweaLo9+fwIjtWcOJkzPuOhKyKFXr4M7qiBdrOM5X4M2Wsa0W8Fk6gZM3MJVU0fUtitmY0CzgSEg9y6xxRGkn8Ks5eCUDHl6DKy1jNSFinuYxTqUt8suNr1ijuWaBwVhmf1PKu5izH6BLNYSI/cNcGTt6kdjPY0Ug9tM6RmgZbVtHSJaqzQL2MK/vaaU5n5LDfuaSvkHoa4kMFmiB0FkMBRl0H9J4vrINvVxpCPTvJW/1RcSsWz6djxSrCObPrewejdClS/pcWoMjoaI3xOK1J4BfFxcNAXuIezAWl+PrYm5hT9Th5lR8YiSskOxzMTM7oQdS6DmK440niHb3AWr1ekOgLyz2zaTUHSerL/ryZ/hilLClFPCRbH6JbH6G0UEAsEdFdHppOEJpmHUl0Evx/kVyeTqlfnCxCtZTEpxxAdMxDg6y+QGTTt6+fT+GNpcXi1Sq2YHtmNdnGG3cEVeWPFoBGyT3qpDDPGtgIqlgiJbwNiyiI2DmDyJKXF456Dxg77wLC9JsSpuYSirLf7Obm5+McBg9ZtBPHPQSBx3eKF6sepAplBsOOvzMQxvFwx4RLdIIyTpM3nqYnAfNjmUwSr6ZPRjN4NVuyKKbdRXh35I1w1K/SV8rMNz91G3+uEk77a1dvwG4Tq7njMk9LQAAAABJRU5ErkJggg=="
newIcon := ImagePutHIcon(base64)
TraySetIcon("HICON:" . newIcon)
Gui().Show("h100 w300")
wind0204
Posts: 3
Joined: 11 Dec 2023, 01:56
Contact:

Re: ImagePut - Image library for converting to files, streams, windows, base64, urls, cursors, screen coordinates, clipb

11 Dec 2023, 02:04

Hello, guys.

I'd like to allow ImageSearchAll function to have tolerance(variation) in each pixel comparison, but do not know how to get the Base64 encoded code to DllCall in Autohotkey.

Does anybody know and can tell me how to produce the Base64 encoded code for a C function?

Thanks in advance!

Code: Select all

@@ -1,4 +1,4 @@
-unsigned int * imagesearch(unsigned int * start, unsigned int width, unsigned int height, unsigned int * s, unsigned int w, unsigned int h) 
>+unsigned int * imagesearch(unsigned int * start, unsigned int width, unsigned int height, unsigned int * s, unsigned int w, unsigned int , unsigned int variation) {
     // width, height, start, current, end refer to the haystack (main image)
     // x, y, w, h, s, c, e refer to the needle (search image)
 
@@ -35,7 +35,7 @@
                 e = c + w;
                 while (c < e) {
                     if (*((unsigned char *) c + 3)) { // skip transparent pixels in search image
-                        if (*c != *p)
+                        if (*c - *p > variation && *c - *p < (0 - variation))
                             goto next;
                     }
                     c++; // Here simply incrementing will interate the entire image
wind0204
Posts: 3
Joined: 11 Dec 2023, 01:56
Contact:

Re: ImagePut - Image library for converting to files, streams, windows, base64, urls, cursors, screen coordinates, clipb

11 Dec 2023, 02:23

AHK_user wrote:
21 Oct 2023, 14:42
Can somebody explain me how you can get the Base64 of an HIcon ?
Preferably by inputting an exe or a window to copy their Icon to a base64 string.
@AHK_user, it seems like https://www.autohotkey.com/docs/v2/lib/LoadPicture.htm can be set to output the handle to an icon via &OutImageType parameter.

And one of the input types allowed for ImagePut functions is hIcon according to https://github.com/iseahound/ImagePut/wiki/Input-Types-&-Output-Functions#input-types

Have you tried using the above with ImagePutBase64? ( https://github.com/iseahound/ImagePut/wiki/Input-Types-&-Output-Functions#imageputbase64image-extension-quality )
wind0204
Posts: 3
Joined: 11 Dec 2023, 01:56
Contact:

Re: ImagePut - Image library for converting to files, streams, windows, base64, urls, cursors, screen coordinates, clipb

11 Dec 2023, 03:24

I've received the answer here: https://github.com/iseahound/ImagePut/discussions/34
wind0204 wrote:
11 Dec 2023, 02:04
Hello, guys.

I'd like to allow ImageSearchAll function to have tolerance(variation) in each pixel comparison, but do not know how to get the Base64 encoded code to DllCall in Autohotkey.

Does anybody know and can tell me how to produce the Base64 encoded code for a C function?

Thanks in advance!
william_ahk
Posts: 496
Joined: 03 Dec 2018, 20:02

Re: ImagePut - Image library for converting to files, streams, windows, base64, urls, cursors, screen coordinates, clipb

20 Dec 2023, 05:24

I'm tempting to migrate one of my projects from tic's Gdip to ImagePut. I need to pass an image to the SQLite database as blob. Can ImagePut add support for this?
iseahound
Posts: 1446
Joined: 13 Aug 2016, 21:04
Contact:

Re: ImagePut - Image library for converting to files, streams, windows, base64, urls, cursors, screen coordinates, clipb

20 Dec 2023, 07:58

What is a SQL blob? If it's binary data ImagePut should already support that
william_ahk
Posts: 496
Joined: 03 Dec 2018, 20:02

Re: ImagePut - Image library for converting to files, streams, windows, base64, urls, cursors, screen coordinates, clipb

20 Dec 2023, 09:14

Yes it's binary data. Which type corresponds to binary in ImagePut? The closest I found is hex but that's the string representation.
I was doing it this way and didn't find similar code in ImagePut.
viewtopic.php?f=76&t=124137#p551913
iseahound
Posts: 1446
Joined: 13 Aug 2016, 21:04
Contact:

Re: ImagePut - Image library for converting to files, streams, windows, base64, urls, cursors, screen coordinates, clipb

23 Dec 2023, 23:15

This would generally fall under ImagePutStream. You would then call:

Code: Select all

DllCall("ole32\GetHGlobalFromStream", "ptr",pStream, "uint*",hData)
	pData := DllCall("GlobalLock", "ptr",hData, "ptr")
	nSize := DllCall("GlobalSize", "uint",pData) 

to get the pointer and the size.

I suppose because AutoHotkey supports buffer objects, it would be more useful to you if I returned a Buffer containing the encoded image along with Ptr and Size. What would you call this function however? It can't be ImagePutBlob because that's SQL specific, but I'm not convinced of ImagePutBinary either. Trying to minimize confusion between the already existing ImagePutBuffer and this.

Edit: Another option is to return an array of [pointer, size]


Thoughts on names?
Last edited by iseahound on 23 Dec 2023, 23:33, edited 1 time in total.
iseahound
Posts: 1446
Joined: 13 Aug 2016, 21:04
Contact:

Re: ImagePut - Image library for converting to files, streams, windows, base64, urls, cursors, screen coordinates, clipb

23 Dec 2023, 23:19

ImagePutHex - Returns a hexadecimal string.
ImagePutBase64 - Returns a base64 string.

This implies ImagePutBinary returns a string like "010100010111000010101", which isn't the case.

ImagePutMemory?
ImagePutStreamBuffer?
ImagePutEncodedBuffer?

idk.
iseahound
Posts: 1446
Joined: 13 Aug 2016, 21:04
Contact:

Re: ImagePut - Image library for converting to files, streams, windows, base64, urls, cursors, screen coordinates, clipb

23 Dec 2023, 23:30

Another thought: A pointer to a stream can be cast to a Stream COM object (?) via query interface or ComObjQuery. This "wraps" (possibly wrong word, Lexikos would hate me for this) the Stream pointer into a com object which should (???) support ptr and size in a more native fashion. I'll double check, and if it doesn't, I'll map all of the stream methods as well.

Basically you'd get all of this:
https://github.com/iseahound/10/blob/1e47ab6205f4312e4b998ddb154756a28771dcca/10.0.10240.0/um/ObjIdlbase.h#L2307

And a better .size in case the size of the stream changes.
william_ahk
Posts: 496
Joined: 03 Dec 2018, 20:02

Re: ImagePut - Image library for converting to files, streams, windows, base64, urls, cursors, screen coordinates, clipb

24 Dec 2023, 23:25

If we're going for a separate function, I suppose EncodedBuffer makes more sense contextually as there are encoded hex, base64, and then buffer. But I think Binary is more widely accepted in AHK? Maybe implement both the string and memory binary as Bin and Binary to sort out the potential confusion. :lol:

A Stream COM object sounds like what a blob does, would be fantastic if it's possible.
User avatar
Jescoimea
Posts: 1
Joined: 26 Dec 2023, 06:37
Contact:

Re: ImagePut - Image library for converting to files, streams, windows, base64, urls, cursors, screen coordinates, clipb

30 Dec 2023, 07:52

How do you handle image encoding in your AutoHotkey projects, and have you considered using ImagePut for managing icons and binary data?
iseahound
Posts: 1446
Joined: 13 Aug 2016, 21:04
Contact:

Re: ImagePut - Image library for converting to files, streams, windows, base64, urls, cursors, screen coordinates, clipb

31 Dec 2023, 11:25

I'm not sure if I understand your question. I assume you're asking about JPG / PNG etc. ImagePut will choose the fastest route for conversions. In the case a JPG is input, and the output "type" supports JPG, then no decoding will be done. This is the case for "cats.jpg"base64 string. It would not be the case for ImagePutWindow, which must decode the JPG format into pixels to show on the screen.

To disable this "fast track" and force decoding of image formats into pixels set decode to True.

See: https://github.com/iseahound/ImagePut/wiki/Crop,-Scale,-&-Other-Flags#decode
Descolada
Posts: 1141
Joined: 23 Dec 2021, 02:30

Re: ImagePut - Image library for converting to files, streams, windows, base64, urls, cursors, screen coordinates, clipb

25 Jan 2024, 13:19

@iseahound, I have a feature request: allow object-type inputs with a ptr property. For example, I'd like to use the following format with my Media library:

Code: Select all

#Requires AutoHotkey v2
#include Media.ahk
#include ImagePut.ahk
thumbnail := Media.GetCurrentSession().Thumbnail
ImagePutClipboard(thumbnail)
instead of manually specifying thumbnail.ptr. Currently this throws a "This value of type "Media.IBase" has no property named "__Item"." error.
iseahound
Posts: 1446
Joined: 13 Aug 2016, 21:04
Contact:

Re: ImagePut - Image library for converting to files, streams, windows, base64, urls, cursors, screen coordinates, clipb

25 Jan 2024, 17:17

@Descolada Latest version should work now. Let me know if you run into any bugs, these types of changes are hard to test. Also, this may be controversial, but I changed the logic to use gotos.

EDIT: Fixed a bug where Notepad changed my unicode characters into "?"
iseahound
Posts: 1446
Joined: 13 Aug 2016, 21:04
Contact:

Re: ImagePut - A core library for images in AutoHotkey (Now supports HEIC & WEBP)

25 Feb 2024, 16:41

@william_ahk Can you experiment with the latest version using ImagePutEncodedBuffer? You will obviously have to use buf.ptr on AutoHotkey v1, and it should operate like a normal buffer object on v2. Feel free to "construct" a buffer via {ptr: ptr, size: size} as well. https://github.com/iseahound/ImagePut

Code: Select all

buf := ImagePutEncodedBuffer("cats.jpg")
imageshow(buf)
buf := ""

buf := ImagePutEncodedBuffer([0, 0, 500, 500])
imageshow(buf)
buf := ""
iseahound
Posts: 1446
Joined: 13 Aug 2016, 21:04
Contact:

Re: ImagePut - A core library for images in AutoHotkey (Now supports HEIC & WEBP)

27 Feb 2024, 12:12

Nice to hear. In case anyone was wondering, the latest update searches the first few bytes of the buffer object (ptr and size) for magic numbers that might indicate if it was a png or a gif. If not, it then looks to see if the buffer object has a width or pitch/stride or height property, and it assumes that the binary data describes a 32bpp ARGB image. Finally, if that doesn't work, it tests the pointer to see if it's a known com object such as an IStream or a IWICBitmap.

I've been meaning to release ImagePut v1.11 with all the newer changes described, bit it may take some more time to iron out any remaining inconsistencies.

Return to “Scripts and Functions (v2)”

Who is online

Users browsing this forum: No registered users and 108 guests