@iseahound if you can help me, it would be great.
I need to capture part of the screen as 512 color. And convert into base64 string to compare images strings in bin file.
my goal is compare and get most similar string as result in fastest way. Currently bin file has 625 image total 121MB.
I store the png files into ".bin" file with using "`n" as delimiter.
Code: Select all
str := ImagePutBase64(FileName, "png") ; Returns base64 string.
fileappend, %str% `n, %A_ScriptDir%\ABase64PNG.bin
Code: Select all
FileRead, base64Strings, %A_ScriptDir%\ABase64PNG.bin
base64Array := StrSplit(base64Strings, "`n")
The png files are 512 color range.
Color composition of 512 color is:
R-G-B;
dec : 0, 36, 72, 109, 145, 182, 218, 255
hex : 0x00, 0x24, 0x48, 0x6D, 0x91, 0xB6, 0xDA, 0xFF
Code: Select all
Gdip_PNGtoQ8PNG(thebitmap, RGBQuantize := 8) {
pToken := Gdip_Startup()
; Load the png with LoadPicture()
pBitmapResource := Gdip_CreateARGBBitmapFromHBITMAP(thebitmap)
Gdip_GetImageDimensions(pBitmapResource, wResource, hResource)
Gdip_LockBits(pBitmapResource, 0, 0, wResource, hResource, strideResource, scanResource, bitmapDataResource)
lookup := {1:0, 2:36, 3:72, 4:109, 5:145, 6:182, 7:218, 8:255}
; quantization with 512 color = (Photoshop posterization by 8)
loop, % hResource
{
y := A_Index - 1
loop, % wResource
{
x := A_Index - 1
pixelColorResource := NumGet(ScanResource+0, (A_Index-1)*4 + y*StrideResource, "uint")
if (pixelColorResource != 0x000000)
{
Red := (pixelColorResource >> 16) & 0xFF
Green := (pixelColorResource >> 8) & 0xFF
Blue := pixelColorResource & 0xFF
Red := lookup[(Red // 32) + 1]
Green := lookup[(Green // 32) + 1]
Blue := lookup[(Blue // 32) + 1]
; add 0xFF000000
pixelColorResource := (Red << 16) | (Green << 8) | Blue
pixelColorResource := pixelColorResource | 0xFF000000
NumPut(pixelColorResource, ScanResource+0, (A_Index-1)*4 + y*StrideResource, "uint")
}
}
}
Gdip_UnlockBits(pBitmapResource, bitmapDataResource)
; Save the bitmap to a file
Gdip_SaveBitmapToFile(pBitmapResource, "C:\Q8\" thebitmapnowName ".png")
Gdip_DisposeImage(pBitmapResource)
Gdip_Shutdown(pToken)
return
}