Page 19 of 23
Re: GDI+ standard library 1.45 by tic
Posted: 24 May 2020, 05:35
by robodesign
R0nya wrote: ↑17 May 2020, 17:37
This one works for me
You gave me an incomplete function. However I found it entirely on:
https://github.com/MasterFocus/AutoHotkey/blob/master/Functions/Gdip_ImageSearch/Gdip_ImageSearch.ahk
It does not qualify to add it, because it relies on Machine Code and it does not include editions for x32 and x64.
Best regards, Marius.
Re: GDI+ standard library 1.45 by tic
Posted: 24 May 2020, 05:39
by malcev
robodesign wrote: ↑24 May 2020, 05:35
It does not qualify to add it, because it relies on Machine Code and it does not include editions for x32 and x64.
It has:
Code: Select all
if ( A_PtrSize == 8 ) ; x64, after comma
MCode_ImageSearch := SubStr(MCode_ImageSearch,InStr(MCode_ImageSearch,",")+1)
else ; x86, before comma
MCode_ImageSearch := SubStr(MCode_ImageSearch,1,InStr(MCode_ImageSearch,",")-1)
https://github.com/MasterFocus/AutoHotkey/blob/master/Functions/Gdip_ImageSearch/Gdip_ImageSearch.ahk#L548
Re: GDI+ standard library 1.45 by tic
Posted: 24 May 2020, 06:48
by guest3456
for GdipImageSearch, keep in mind that MasterFocus explicitly chose a copyleft license with a viral component, ala the GPL, which means that if you build upon that func, you must also release your code publicly under the same terms. that's why i hadn't added it to the v2 version of the gdip lib, as i don't believe its compatible with other freely shared unlicensed code. i'm not a fan of these licenses, but i understand why a user would choose it
Re: GDI+ standard library 1.45 by tic
Posted: 24 May 2020, 06:55
by robodesign
@malcev. Okay, thank you. My bad - I admit I did not peruse the code.
@guest3456. Thank you for this heads-up about this. Does this mean that I cannot include functions / code licensed under GPL in the library ? I'll mention who made it and give a link to the source, and I'll mention it is under GPL license. Is this fine? I'm not proficient in such matters.....
Right now I'm working on the ahk v2 edition on the library and I'm trying to release it soon.
Best regards, Marius.
Re: GDI+ standard library 1.45 by tic
Posted: 24 May 2020, 07:05
by guest3456
robodesign wrote: ↑24 May 2020, 06:55
@guest3456. Thank you for this heads-up about this. Does this mean that I cannot include functions / code licensed under GPL in the library ? I'll mention who made it and give a link to the source, and I'll mention it is under GPL license. Is this fine? I'm not proficient in such matters.....
i am not a lawyer myself. from here:
https://www.gnu.org/licenses/gpl-faq.en.html
If a library is released under the GPL (not the LGPL), does that mean that any software which uses it has to be under the GPL or a GPL-compatible license? (#IfLibraryIsGPL)
Yes, because the program actually links to the library. As such, the terms of the GPL apply to the entire combination. The software modules that link with the library may be under various GPL compatible licenses, but the work as a whole must be licensed under the GPL.
i take that to mean that the entire compilation library itself would have to be GPL'd... but since we're not the authors of everyone else's code, we certainly don't have the right to apply a license to their code that they wrote. especially not a restrictive license like this.
the fact that the GPL has so many issues, and also requires such a long webpage of FAQs, tells me all i need to know about that license: its complicated and cumbersome. there are many words written all over the web about the pain in the ass that is the GPL. i believe the license MasterFocus chose has similar complications
this is why i like the WTFPL
sidenote:
AutoHotkey itself is licensed under the GPL, and its been common over the years for people to ask whether or not every script they write is forced to also be licensed under the GPL as well. according to that same link above:
If a programming language interpreter is released under the GPL, does that mean programs written to be interpreted by it must be under GPL-compatible licenses? (#IfInterpreterIsGPL)
When the interpreter just interprets a language, the answer is no. The interpreted program, to the interpreter, is just data; a free software license like the GPL, based on copyright law, cannot limit what data you use the interpreter on. You can run it on any data (interpreted program), any way you like, and there are no requirements about licensing that data to anyone.
Re: GDI+ standard library 1.45 by tic
Posted: 24 May 2020, 11:09
by robodesign
Thank you. I'll not include it then.
I just pushed a new version of the GDI+ library... and now the repository includes a specific edition for v2, but I have no projects to test it with thoroughly. Therefore, I am quite confident that bugs are still present. Pull requests are welcome.
Best regards, Marius.
Re: GDI+ standard library 1.45 by tic
Posted: 04 Jul 2020, 10:12
by xelowek
Hi, Marius.
Maybe i wrong, but it seems that there is an error in the
Gdip_TextToGraphics function (library v.1.84). Vertical alignment works incorrectly (the 'Top', 'Up', 'Bottom', 'Down' parameters).
line 4062
Code: Select all
; original: always aligned on the 'top edge' of canvas
ypos := 0
; must be
ypos += 0
line 4064
Code: Select all
; original: always aligned on the 'top edge + height (parameter from func call)'
ypos := Height-ReturnRC[4]
; must be
ypos += Height-ReturnRC[4]
line 4056-4068
Code: Select all
If vPos
{
ReturnRC := StrSplit(ReturnRC, "|")
if (vPos[0] = "vCentre") || (vPos[0] = "vCenter")
ypos += (Height-ReturnRC[4])//2
else if (vPos[0] = "Top") || (vPos[0] = "Up")
ypos := 0 ; <------------------------------------------------------
else if (vPos[0] = "Bottom") || (vPos[0] = "Down")
ypos := Height-ReturnRC[4] ; <-------------------------------------
CreateRectF(RC, xpos, ypos, Width, ReturnRC[4])
ReturnRC := Gdip_MeasureString(pGraphics, Text, hFont, hStringFormat, RC)
}
Re: GDI+ standard library 1.45 by tic
Posted: 04 Jul 2020, 11:28
by guest3456
xelowek wrote: ↑04 Jul 2020, 10:12
Maybe i wrong, but it seems that there is an error in the
Gdip_TextToGraphics function (library v.1.84). Vertical alignment works incorrectly (the 'Top', 'Up', 'Bottom', 'Down' parameters).
its been discussed extensively a few years ago, see this github issue for various different fixes:
https://github.com/mmikeww/AHKv2-Gdip/issues/17
Re: GDI+ standard library 1.45 by tic
Posted: 04 Jul 2020, 11:53
by robodesign
@boiler and @Guest3456 . Yes, I am aware of this issue and my next version release will have this fixed. I saw the disscussion Guest mentioned and I already chose for the next release to use += ...
However , right now I am working on new functions with MCode for alpha masking, apply blending modes and so on. When I am ready I will release the update.
Thank you for the report. If you find other errors, please let me know .
Best regards, Marius.
Re: GDI+ standard library 1.45 by tic
Posted: 30 Aug 2020, 15:13
by robodesign
Hello, guys!
As promised, I am back, with the aforementioned functions: set alpha channel to bitmaps and... blend two bitmaps using blending modes. The new version of the library also comes with bug fixes.
Change log: GDI+ extended/compilation library edition. v1.85.
Added functions:
- Gdip_SetAlphaChannel() - uses MCode
- Gdip_BlendBitmaps() - uses MCode; 18 blending modes supported
- Gdip_CreateBitmapFromStream()
Modified/fixed/improved functions:
- Gdip_RetrieveBitmapChannel() - fixes
- Gdip_TextToGraphics() - fixes
- Gdip_CreateBitmapFromClipboard() - fixes
- Gdip_BitmapApplyEffect()
- Gdip_FontFamilyCreate()
- Gdip_MeasureString()
- Gdip_DrawString()
- Gdip_CreateBitmapFromFile()
- Gdip_SaveBitmapToFile()
- Gdip_BlurBitmap()
- Gdip_GraphicsFromHWND()
- Gdip_GraphicsFromImage()
The following functions were removed, because I will publish a specific GDI library soonish...
- Gdi_StretchDIBits()
- Gdi_SetDIBitsToDevice()
- Gdi_GetDIBits()
- Gdi_CreateBitmap()
- Gdi_CreateDIBitmap()
... side note: these were previously added by me to this GDI+ library edition.
Link:
https://github.com/marius-sucan/AHK-GDIp-Library-Compilation
Best regards, Marius.
Re: GDI+ standard library 1.45 by tic
Posted: 25 Sep 2020, 07:52
by xelowek
Hi, Marius. I didn't find function 'GdipGetStringFormatFlags' in 'GDip_All', can you add it? Thank you.
Code: Select all
Gdip_GdipGetStringFormatFlags(hStringFormat)
{
result := 0
E := DllCall("gdiplus\GdipGetStringFormatFlags", "UPtr", hStringFormat, "int*", result)
If E
Return -1
Return result
}
Re: GDI+ standard library 1.45 by tic
Posted: 25 Sep 2020, 10:55
by robodesign
xelowek wrote: ↑25 Sep 2020, 07:52
Hi, Marius. I didn't find function 'GdipGetStringFormatFlags' in 'GDip_All', can you add it? Thank you.
Code: Select all
Gdip_GdipGetStringFormatFlags(hStringFormat)
{
result := 0
E := DllCall("gdiplus\GdipGetStringFormatFlags", "UPtr", hStringFormat, "int*", result)
If E
Return -1
Return result
}
Thank you . I will add it. Can you please also provide possible interpretations for the result, more precisely, the possible flags?
Best regards, Marius.
Re: GDI+ standard library 1.45 by tic
Posted: 25 Sep 2020, 13:34
by xelowek
Flags are described here: 'Gdip_StringFormatCreate' line 4310 (GDip_All v1.85).
Also 'Gdip_SetStringFormatFlags' have notes: 'see Gdip_StringFormatCreate() for possible StringFormatFlags'.
Re: GDI+ standard library 1.45 by tic
Posted: 25 Sep 2020, 13:58
by robodesign
xelowek wrote: ↑25 Sep 2020, 13:34
Flags are described here: 'Gdip_StringFormatCreate' line 4310 (GDip_All v1.85).
Also 'Gdip_SetStringFormatFlags' have notes: 'see Gdip_StringFormatCreate() for possible StringFormatFlags'.
Ah, yes; thank you ... my bad, I forgot about those.
The next release will have this.
Best regards, Marius.
Re: GDI+ standard library 1.45 by tic
Posted: 16 Nov 2020, 07:14
by ewerybody
Hello people! I'm just going over things from the 1.8.5 GDI+ lib to get screen grabs from apps and windows.
There is the
Gdip_BitmapFromScreen function which can have a string input for
Screen like
hwnd:0xc70736
and then there is the
Gdip_BitmapFromHWND which can take the
hwnd string directly like
0xc70736
I actually get the a little different results from both which are
both offset to the left:
•
Gdip_BitmapFromScreen with
hwnd:0xc70736
- test Gdip_BitmapFromScreen hwnd.png (34.41 KiB) Viewed 5492 times
- border on the left captured the window behind
- cut off on the right
- the title is black
•
Gdip_BitmapFromHWND with
0xc70736
- test Gdip_BitmapFromHWND.png (33.37 KiB) Viewed 5492 times
- big black border on the left
- cut off on the right
- the title is alright tho ✔
•
Gdip_BitmapFromHWND with
clientOnly:=1
- test Gdip_BitmapFromHWND client.png (34.12 KiB) Viewed 5492 times
- contrary to function doc the window title is included!
- Other than that it's alright! ✔
• finally
Gdip_BitmapFromScreen with area given as
x|y|w|h results in the same BUT with the thin 1px border included. Which is actually perfect ✔
So finally:
• I'd actually rather use a dedicated function that takes the
hwnd but seems these have issues. Is reporting
here the way to do it?
• Do you see problems with always using
Gdip_BitmapFromScreen with area?
• And what about
tests for these functions? Would you use
Yunit?
Re: GDI+ standard library 1.45 by tic
Posted: 25 Jan 2021, 11:53
by tuzi
@robodesign
hi,Marius.
I found that the two functions
Gdip_FillRoundedRectangle and Gdip_FillRoundedRectangle2
both could not draw perfectly rounded rectangles, and we can see obvious deviations with the naked eye.
I know you are a digital image artist, and I am sure you can see the difference too.
- 1.png (33.54 KiB) Viewed 5247 times
here is the test code.
Code: Select all
#SingleInstance, Force
#NoEnv
SetBatchLines, -1
#Include, Gdip_All.ahk
gosub, init
Gdip_FillRoundedRectangle(G, pBrush, 0, 0, PicWidth-500, PicHeight, 20)
UpdateLayeredWindow(hwnd1, hdc, 200, 200, DisplayAreaWidth, DisplayAreaHeight)
Return
init:
If !pToken := Gdip_Startup()
{
MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
ExitApp
}
OnExit, Exit
Gui, 1: -Caption +E0x80000 +LastFound +AlwaysOnTop +ToolWindow +OwnDialogs +Hwndhwnd1
Gui, 1: Show, NA
Loop, Files, %A_WinDir%\Web\WallPaper\*.jpg, R
ImgPath := A_LoopFileLongPath
pBitmap := Gdip_CreateBitmapFromFile(ImgPath)
If !pBitmap
{
MsgBox, 48, WallPaper loading error!
ExitApp
}
PicWidth := Gdip_GetImageWidth(pBitmap), PicHeight := Gdip_GetImageHeight(pBitmap)
DisplayAreaWidth:=A_ScreenWidth, DisplayAreaHeight:=A_ScreenHeight
hbm := CreateDIBSection(DisplayAreaWidth, DisplayAreaHeight)
hdc := CreateCompatibleDC()
obm := SelectObject(hdc, hbm)
G := Gdip_GraphicsFromHDC(hdc)
Gdip_SetInterpolationMode(G, 7)
pBitmap:=Gdip_ResizeBitmap(pBitmap, PicWidth//3, PicHeight//3, 0)
PicWidth := Gdip_GetImageWidth(pBitmap), PicHeight := Gdip_GetImageHeight(pBitmap)
pBrush:= Gdip_CreateTextureBrush(pBitmap, WrapMode:=1)
Return
GuiClose:
GuiEscape:
Exit:
SelectObject(hdc, obm)
DeleteObject(hbm)
DeleteDC(hdc)
Gdip_DeleteGraphics(G)
Gdip_DisposeImage(pBitmap)
Gdip_Shutdown(pToken)
ExitApp
Return
Re: GDI+ standard library 1.45 by tic
Posted: 25 Jan 2021, 14:17
by robodesign
@tuzi .... thank you for the feedback. Yes, I am aware of the problem, but those functions were not implemented by me. I have not struggled to fix/improve them in that regard... If you are willing to improve this function, to have a proper rounded rectangle, please do so.
I would like to replace the two functions in the library with one good function, but it must work with small, large rounded corners, with small and large boxes - all combinations.
Thank you in advance.
Best regards, Marius.
Re: GDI+ standard library 1.45 by tic
Posted: 25 Jan 2021, 17:56
by iseahound
@ewerybody
malcev has some good screengrabbing code using DirectX that is much faster than both existing methods.
Re: GDI+ standard library 1.45 by tic
Posted: 25 Jan 2021, 18:14
by iseahound
@tuzi
This implementation is bad.
Code: Select all
Gdip_FillRoundedRectangle(pGraphics, pBrush, x, y, w, h, r)
{
Region := Gdip_GetClipRegion(pGraphics)
Gdip_SetClipRect(pGraphics, x-r, y-r, 2*r, 2*r, 4)
Gdip_SetClipRect(pGraphics, x+w-r, y-r, 2*r, 2*r, 4)
Gdip_SetClipRect(pGraphics, x-r, y+h-r, 2*r, 2*r, 4)
Gdip_SetClipRect(pGraphics, x+w-r, y+h-r, 2*r, 2*r, 4)
_E := Gdip_FillRectangle(pGraphics, pBrush, x, y, w, h)
Gdip_SetClipRegion(pGraphics, Region, 0)
Gdip_SetClipRect(pGraphics, x-(2*r), y+r, w+(4*r), h-(2*r), 4)
Gdip_SetClipRect(pGraphics, x+r, y-(2*r), w-(2*r), h+(4*r), 4)
Gdip_FillEllipse(pGraphics, pBrush, x, y, 2*r, 2*r)
Gdip_FillEllipse(pGraphics, pBrush, x+w-(2*r), y, 2*r, 2*r)
Gdip_FillEllipse(pGraphics, pBrush, x, y+h-(2*r), 2*r, 2*r)
Gdip_FillEllipse(pGraphics, pBrush, x+w-(2*r), y+h-(2*r), 2*r, 2*r)
Gdip_SetClipRegion(pGraphics, Region, 0)
Gdip_DeleteRegion(Region)
return _E
}
Use this solution by justme
Code: Select all
;#####################################################################################
; Function Gdip_FillRoundedRectangle
; Description This function uses a brush to fill a rounded rectangle in the Graphics of a bitmap
;
; pGraphics Pointer to the Graphics of a bitmap
; pBrush Pointer to a brush
; x x-coordinate of the top left of the rounded rectangle
; y y-coordinate of the top left of the rounded rectangle
; w width of the rectanlge
; h height of the rectangle
; r radius of the rounded corners
;
; return status enumeration. 0 = success
Gdip_FillRoundedRectanglePath(pGraphics, pBrush, X, Y, W, H, R) {
; Create a GraphicsPath
DllCall("Gdiplus.dll\GdipCreatePath", "UInt", 0, "PtrP", pPath)
; Create a rounded rectabgle
D := (R * 2), W -= D, H -= D
DllCall("Gdiplus.dll\GdipAddPathArc", "Ptr", pPath, "Float", X, "Float", Y, "Float", D, "Float", D, "Float", 180, "Float", 90)
DllCall("Gdiplus.dll\GdipAddPathArc", "Ptr", pPath, "Float", X + W, "Float", Y, "Float", D, "Float", D, "Float", 270, "Float", 90)
DllCall("Gdiplus.dll\GdipAddPathArc", "Ptr", pPath, "Float", X + W, "Float", Y + H, "Float", D, "Float", D, "Float", 0, "Float", 90)
DllCall("Gdiplus.dll\GdipAddPathArc", "Ptr", pPath, "Float", X, "Float", Y + H, "Float", D, "Float", D, "Float", 90, "Float", 90)
DllCall("Gdiplus.dll\GdipClosePathFigure", "Ptr", pPath)
; Fill the path
RS := DllCall("Gdiplus.dll\GdipFillPath", "Ptr", pGraphics, "Ptr", pBrush, "Ptr", pPath)
; Free resources
DllCall("Gdiplus.dll\GdipDeletePath", "Ptr", pPath)
Return RS
}
https://www.autohotkey.com/boards/viewtopic.php?t=46250
Re: GDI+ standard library 1.45 by tic
Posted: 25 Jan 2021, 18:34
by robodesign
@tuzi . Please let me know if the function by just-me is working well. As stated previously, if it's a good one, I'll replace the ones in the library.
@iseahound .thank you for this. I'll test it as well.
Best regards, Marius.