Automage

Untitled

Jun 3rd, 2025
5
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 381.21 KB | None | 0 0
  1. ; Gdip_All.ahk - GDI+ library compilation of user contributed GDI+ functions
  2. ; made by Marius Șucan: https://github.com/marius-sucan/AHK-GDIp-Library-Compilation
  3. ; a fork from: https://github.com/mmikeww/AHKv2-Gdip
  4. ; based on https://github.com/tariqporter/Gdip
  5. ; Supports: AHK_L / AHK_H Unicode/ANSI x86/x64 and AHK v2 alpha
  6. ; This file is the AHK v1.1 edition; for AHK v2 compatible edition, please see the repository.
  7. ;
  8. ; AHK forums: https://www.autohotkey.com/boards/viewtopic.php?f=6&t=6517
  9. ;
  10. ; NOTES: The drawing of GDI+ Bitmaps is limited to a size of 32767 pixels
  11. ; in either direction (width, height). This limit applies only if the
  12. ; interpolation mode is set to NearestNeighbor for the Graphics Object.
  13. ;
  14. ; To calculate the largest bitmap you can create:
  15. ; The maximum object size is 2GB = 2,147,483,648 bytes
  16. ; Default bitmap is 32bpp (4 bytes), the largest area we can have is 2GB / 4 = 536,870,912 bytes
  17. ; If we want a square, the largest we can get is sqrt(2GB/4) = 23,170 pixels (536 mgpx)
  18. ; For 24-bits: sqrt(2GB/3) = 26,755 pixels (715 mgpx)
  19. ; Gdip_DrawImage() will fail with images above 536 mgpx,
  20. ; even if these are below 32 bits.
  21. ;
  22. ; Gdip standard library versions:
  23. ; by Marius Șucan - gathered user-contributed functions and implemented hundreds of new functions
  24. ; - v1.97 [28/01/2025]
  25. ; - v1.96 [22/08/2023]
  26. ; - v1.95 [21/04/2023]
  27. ; - v1.94 [23/03/2023]
  28. ; - v1.93 [27/06/2022]
  29. ; - v1.92 [28/10/2021]
  30. ; - v1.91 [11/10/2021]
  31. ; - v1.90 [09/10/2021]
  32. ; - v1.89 [08/10/2021]
  33. ; - v1.88 [05/10/2021]
  34. ; - v1.87 [29/09/2021]
  35. ; - v1.85 [24/08/2020]
  36. ; - v1.84 [05/06/2020]
  37. ; - v1.83 [24/05/2020]
  38. ; - v1.82 [11/03/2020]
  39. ; - v1.81 [25/02/2020]
  40. ; - v1.80 [01/11/2019]
  41. ; - v1.79 [28/10/2019]
  42. ; - v1.78 [27/10/2019]
  43. ; - v1.77 [06/10/2019]
  44. ; - v1.76 [27/09/2019]
  45. ; - v1.75 [23/09/2019]
  46. ; - v1.74 [19/09/2019]
  47. ; - v1.73 [17/09/2019]
  48. ; - v1.72 [16/09/2019]
  49. ; - v1.71 [15/09/2019]
  50. ; - v1.70 [13/09/2019]
  51. ; - v1.69 [12/09/2019]
  52. ; - v1.68 [11/09/2019]
  53. ; - v1.67 [10/09/2019]
  54. ; - v1.66 [09/09/2019]
  55. ; - v1.65 [08/09/2019]
  56. ; - v1.64 [07/09/2019]
  57. ; - v1.63 [06/09/2019]
  58. ; - v1.62 [05/09/2019]
  59. ; - v1.61 [04/09/2019]
  60. ; - v1.60 [03/09/2019]
  61. ; - v1.59 [01/09/2019]
  62. ; - v1.58 [29/08/2019]
  63. ; - v1.57 [23/08/2019]
  64. ; - v1.56 [21/08/2019]
  65. ; - v1.55 [14/08/2019]
  66. ;
  67. ; bug fixes and AHK v2 alpha compatibility by mmikeww and others
  68. ; - v1.54 [15/11/2017]
  69. ; - v1.53 [19/06/2017]
  70. ; - v1.52 [11/06/2017]
  71. ; - v1.51 [27/01/2017]
  72. ; - v1.50 [20/11/2016]
  73. ; - v1.47 [20/02/2014] [?]
  74. ;
  75. ; modified by Rseding91 using fincs 64 bit compatible
  76. ; - v1.45 [01/05/2013]
  77. ;
  78. ; by tic (Tariq Porter)
  79. ; - v1.45 [09/07/2011]
  80. ; - v1.01 [05/31/2008]
  81. ;
  82. ; Detailed history:
  83. ; - 28/01/2025 = added the Gdip_GraphicsPathIterator class ; users can now work with subpaths/figures; added Gdip_BitmapApplyHSL(), Gdip_BitmapApplyTint(), Gdip_BitmapApplyBrightnessContrast()
  84. ; - 22/08/2023 = bug fix related to Gdip_SaveBitmapToFile() and other minor changes
  85. ; - 21/04/2023 = bug fixes related to Gdip_TextToGraphics() and private font collections
  86. ; - 23/03/2023 = added Gdip_SaveAddImage(), Gdip_SaveImagesInTIFF(), Gdip_GetFrameDelay(), Gdip_GetImageEncodersList(), and other fixes, and minor functions
  87. ; - 27/06/2022 = various minor fixes
  88. ; - 28/10/2021 = Added Gdip_TranslatePath(), Gdip_ScalePath() and Gdip_RotatePath(). Improved Gdip_RotatePathAtCenter()
  89. ; - 11/10/2021 = more bug fixes; Gdip_CreatePath() now accepts passing a flat array object that defines the new path; some functions will now return values separated by pipe | instead of a comma [for better consistency across functions]
  90. ; - 09/10/2021 = [important release] major bug fixes for regressions introduced in previous version
  91. ; - 08/10/2021 = added more functions
  92. ; - 05/10/2021 = all functions that rely on CreatePointsF() or AllocateBinArray() can now handle being given an array or a string [to maintain compatibility); added Gdip_GaussianBlur(), Gdip_FillRoundedRectanglePath(), Gdip_DrawRoundedRectanglePath()
  93. ; - 24/08/2020 = Bug fixes and added Gdip_BlendBitmaps() and Gdip_SetAlphaChannel()
  94. ; - 05/06/2020 = Synchronized with mmikeww's repository and fixed a few bugs
  95. ; - 24/05/2020 = Added a few more functions and fixed or improved already exiting functions
  96. ; - 11/02/2020 = Imported updated MDMF functions from mmikeww, and AHK v2 examples, and other minor changes
  97. ; - 25/02/2020 = Added several new functions, including for color conversions [from Tidbit], improved/fixed several functions
  98. ; - 01/11/2019 = Implemented support for a private font file for Gdip_AddPathStringSimplified()
  99. ; - 28/10/2019 = Added 7 new GDI+ functions and fixes related to Gdip_CreateFontFamilyFromFile()
  100. ; - 27/10/2019 = Added 5 new GDI+ functions and bug fixes for Gdip_TestBitmapUniformity(), Gdip_RotateBitmapAtCenter() and Gdip_ResizeBitmap()
  101. ; - 06/10/2019 = Added more parameters to Gdip_GraphicsFromImage/HDC/HWND and added Gdip_GetPixelColor()
  102. ; - 27/09/2019 = bug fixes
  103. ; - 23/09/2019 = Added 4 new functions and improved Gdip_CreateBitmap() [ Marius Șucan ]
  104. ; - 19/09/2019 = Added 4 new functions and improved Gdip_RotateBitmapAtCenter() [ Marius Șucan ]
  105. ; - 17/09/2019 = Added 6 new GDI+ functions and renamed curve related functions [ Marius Șucan ]
  106. ; - 16/09/2019 = Added 10 new GDI+ functions [ Marius Șucan ]
  107. ; - 15/09/2019 = Added 3 new GDI+ functions and improved Gdip_DrawStringAlongPolygon() [ Marius Șucan ]
  108. ; - 13/09/2019 = Added 10 new GDI+ functions [ Marius Șucan ]
  109. ; - 12/09/2019 = Added 6 new GDI+ functions [ Marius Șucan ]
  110. ; - 11/09/2019 = Added 10 new GDI+ functions [ Marius Șucan ]
  111. ; - 10/09/2019 = Added 17 new GDI+ functions [ Marius Șucan ]
  112. ; - 09/09/2019 = Added 14 new GDI+ functions [ Marius Șucan ]
  113. ; - 08/09/2019 = Added 3 new functions and fixed Gdip_SetPenDashArray() [ Marius Șucan ]
  114. ; - 07/09/2019 = Added 12 new functions [ Marius Șucan ]
  115. ; - 06/09/2019 = Added 14 new GDI+ functions [ Marius Șucan ]
  116. ; - 05/09/2019 = Added 27 new GDI+ functions [ Marius Șucan ]
  117. ; - 04/09/2019 = Added 36 new GDI+ functions [ Marius Șucan ]
  118. ; - 03/09/2019 = Added about 37 new GDI+ functions [ Marius Șucan ]
  119. ; - 29/08/2019 = Fixed Gdip_GetPropertyTagName() [on AHK v2], Gdip_GetPenColor() and Gdip_GetSolidFillColor(), added Gdip_LoadImageFromFile()
  120. ; - 23/08/2019 = Added Gdip_FillRoundedRectangle2() and Gdip_DrawRoundedRectangle2(); extracted from Gdip2 by Tariq [tic] and corrected functions names
  121. ; - 21/08/2019 = Added GenerateColorMatrix() by Marius Șucan
  122. ; - 19/08/2019 = Added 12 functions. Extracted from a class wrapper for GDI+ written by nnnik in 2017.
  123. ; - 18/08/2019 = Added Gdip_AddPathRectangle() and eight PathGradient related functions by JustMe
  124. ; - 16/08/2019 = Added Gdip_DrawImageFX(), Gdip_CreateEffect() and other related functions [ Marius Șucan ]
  125. ; - 15/08/2019 = Added Gdip_DrawRoundedLine() by DevX and Rabiator
  126. ; - 15/08/2019 = Added 11 GraphicsPath related functions by "Learning one" and updated by Marius Șucan
  127. ; - 14/08/2019 = Added Gdip_IsVisiblePathPoint() and RotateAtCenter() by RazorHalo
  128. ; - 08/08/2019 = Added Gdi_GetDIBits() and Gdi_CreateDIBitmap() by Marius Șucan
  129. ; - 19/07/2019 = Added Gdip_GetHistogram() by swagfag and GetProperty GDI+ functions by JustMe
  130. ; - 15/11/2017 = compatibility with both AHK v2 and v1, restored by nnnik
  131. ; - 19/06/2017 = Fixed few bugs from old syntax by Bartlomiej Uliasz
  132. ; - 11/06/2017 = made code compatible with new AHK v2.0-a079-be5df98 by Bartlomiej Uliasz
  133. ; - 27/01/2017 = fixed some bugs and made #Warn All compatible by Bartlomiej Uliasz
  134. ; - 20/11/2016 = fixed Gdip_BitmapFromBRA() by 'just me'
  135. ; - 18/11/2016 = backward compatible support for both AHK v1.1 and AHK v2
  136. ; - 15/11/2016 = initial AHK v2 support by guest3456
  137. ; - 20/02/2014 = fixed Gdip_CreateRegion() and Gdip_GetClipRegion() on AHK Unicode x86
  138. ; - 13/05/2013 = fixed Gdip_SetBitmapToClipboard() on AHK Unicode x64
  139. ; - 09/07/2011 = v1.45 release by tic (Tariq Porter)
  140. ; - 05/31/2008 = v1.01 release by tic (Tariq Porter)
  141. ;
  142. ;#####################################################################################
  143. ; STATUS ENUMERATION
  144. ; Return values for functions specified to have status enumerated return type
  145. ;#####################################################################################
  146. ;
  147. ; Ok = = 0
  148. ; GenericError = 1
  149. ; InvalidParameter = 2
  150. ; OutOfMemory = 3
  151. ; ObjectBusy = 4
  152. ; InsufficientBuffer = 5
  153. ; NotImplemented = 6
  154. ; Win32Error = 7
  155. ; WrongState = 8
  156. ; Aborted = 9
  157. ; FileNotFound = 10
  158. ; ValueOverflow = 11
  159. ; AccessDenied = 12
  160. ; UnknownImageFormat = 13
  161. ; FontFamilyNotFound = 14
  162. ; FontStyleNotFound = 15
  163. ; NotTrueTypeFont = 16
  164. ; UnsupportedGdiplusVersion= 17
  165. ; GdiplusNotInitialized = 18
  166. ; PropertyNotFound = 19
  167. ; PropertyNotSupported = 20
  168. ; ProfileNotFound = 21
  169. ;
  170. ;#####################################################################################
  171. ; FUNCTIONS LIST
  172. ; See functions-list.txt file.
  173. ;#####################################################################################
  174.  
  175. ; Function: UpdateLayeredWindow
  176. ; Description: Updates a layered window with the handle to the DC of a gdi bitmap
  177. ;
  178. ; hwnd Handle of the layered window to update
  179. ; hdc Handle to the DC of the GDI bitmap to update the window with
  180. ; x, y x, y coordinates to place the window
  181. ; w, h Width and height of the window
  182. ; Alpha Default = 255 : The transparency (0-255) to set the window transparency
  183. ;
  184. ; return If the function succeeds, the return value is nonzero
  185. ;
  186. ; notes If x or y are omitted, the layered window will use its current coordinates
  187. ; If w or h are omitted, the current width and height will be used
  188.  
  189. UpdateLayeredWindow(hwnd, hdcSrc, x:="", y:="", w:="", h:="", Alpha:=255) {
  190. if (x!="" && y!="")
  191. CreatePointF(pt, x, y, "uint")
  192.  
  193. if (w="" || h="")
  194. GetWindowRect(hwnd, W, H)
  195.  
  196. return DllCall("UpdateLayeredWindow"
  197. , "UPtr", hwnd
  198. , "UPtr", 0
  199. , "UPtr", ((x = "") && (y = "")) ? 0 : &pt
  200. , "int64*", w|h<<32
  201. , "UPtr", hdcSrc
  202. , "Int64*", 0
  203. , "UInt", 0
  204. , "UInt*", Alpha<<16|1<<24
  205. , "UInt", 2)
  206. }
  207.  
  208. ;#####################################################################################
  209.  
  210. ; Function BitBlt
  211. ; Description The BitBlt function performs a bit-block transfer of the color data corresponding to a rectangle
  212. ; of pixels from the specified source device context into a destination device context.
  213. ;
  214. ; dDC handle to destination DC
  215. ; dX, dY x, y coordinates of the destination upper-left corner
  216. ; dW, dH width and height of the area to copy
  217. ; sDC handle to source DC
  218. ; sX, sY x, y coordinates of the source upper-left corner
  219. ; Raster raster operation code
  220. ;
  221. ; return If the function succeeds, the return value is nonzero
  222. ;
  223. ; notes If no raster operation is specified, then SRCCOPY is used, which copies the source directly to the destination rectangle
  224. ;
  225. ; Raster operation codes:
  226. ; BLACKNESS = 0x00000042
  227. ; NOTSRCERASE = 0x001100A6
  228. ; NOTSRCCOPY = 0x00330008
  229. ; SRCERASE = 0x00440328
  230. ; DSTINVERT = 0x00550009
  231. ; PATINVERT = 0x005A0049
  232. ; SRCINVERT = 0x00660046
  233. ; SRCAND = 0x008800C6
  234. ; MERGEPAINT = 0x00BB0226
  235. ; MERGECOPY = 0x00C000CA
  236. ; SRCCOPY = 0x00CC0020
  237. ; SRCPAINT = 0x00EE0086
  238. ; PATCOPY = 0x00F00021
  239. ; PATPAINT = 0x00FB0A09
  240. ; WHITENESS = 0x00FF0062
  241. ; CAPTUREBLT = 0x40000000
  242. ; NOMIRRORBITMAP = 0x80000000
  243.  
  244. BitBlt(ddc, dx, dy, dw, dh, sdc, sx, sy, raster:="") {
  245. ; This function works only with GDI hBitmaps that
  246. ; are Device-Dependent Bitmaps [DDB].
  247.  
  248. return DllCall("gdi32\BitBlt"
  249. , "UPtr", dDC
  250. , "int", dX, "int", dY
  251. , "int", dW, "int", dH
  252. , "UPtr", sDC
  253. , "int", sX, "int", sY
  254. , "uint", Raster ? Raster : 0x00CC0020)
  255. }
  256.  
  257. ;#####################################################################################
  258.  
  259. ; Function StretchBlt
  260. ; Description The StretchBlt function copies a bitmap from a source rectangle into a destination rectangle,
  261. ; stretching or compressing the bitmap to fit the dimensions of the destination rectangle, if necessary.
  262. ; The system stretches or compresses the bitmap according to the stretching mode currently set in the destination device context.
  263. ;
  264. ; ddc handle to destination DC
  265. ; dX, dY x, y coordinates of the destination upper-left corner
  266. ; dW, dH width and height of the destination rectangle
  267. ; sdc handle to source DC
  268. ; sX, sY x, y coordinates of the source upper-left corner
  269. ; sW, sH width and height of the source rectangle
  270. ; Raster raster operation code
  271. ;
  272. ; return If the function succeeds, the return value is nonzero
  273. ;
  274. ; notes If no raster operation is specified, then SRCCOPY is used. It uses the same raster operations as BitBlt
  275.  
  276. StretchBlt(ddc, dx, dy, dw, dh, sdc, sx, sy, sw, sh, Raster:="") {
  277. return DllCall("gdi32\StretchBlt"
  278. , "UPtr", ddc
  279. , "int", dX, "int", dY
  280. , "int", dW, "int", dH
  281. , "UPtr", sdc
  282. , "int", sX, "int", sY
  283. , "int", sW, "int", sH
  284. , "uint", Raster ? Raster : 0x00CC0020)
  285. }
  286.  
  287. ;#####################################################################################
  288.  
  289. ; Function SetStretchBltMode
  290. ; Description The SetStretchBltMode function sets the bitmap stretching mode in the specified device context
  291. ;
  292. ; hdc handle to the DC
  293. ; iStretchMode The stretching mode, describing how the target will be stretched
  294. ;
  295. ; return If the function succeeds, the return value is the previous stretching mode. If it fails it will return 0
  296. ;
  297.  
  298. SetStretchBltMode(hdc, iStretchMode:=4) {
  299. ; iStretchMode options:
  300. ; BLACKONWHITE = 1
  301. ; COLORONCOLOR = 3
  302. ; HALFTONE = 4
  303. ; WHITEONBLACK = 2
  304. ; STRETCH_ANDSCANS = BLACKONWHITE
  305. ; STRETCH_DELETESCANS = COLORONCOLOR
  306. ; STRETCH_HALFTONE = HALFTONE
  307. ; STRETCH_ORSCANS = WHITEONBLACK
  308.  
  309. return DllCall("gdi32\SetStretchBltMode"
  310. , "UPtr", hdc, "int", iStretchMode)
  311. }
  312.  
  313. ;#####################################################################################
  314.  
  315. ; Function SetImage
  316. ; Description Associates a new image with a static control
  317. ;
  318. ; hwnd handle of the control to update
  319. ; hBitmap a GDI bitmap to associate the static control with
  320. ;
  321. ; return If the function succeeds, the return value is nonzero
  322.  
  323. SetImage(hwnd, hBitmap) {
  324. ; STM_SETIMAGE = 0x172
  325. ; Example: Gui, Add, Text, 0xE w500 h300 hwndhPic ; SS_Bitmap = 0xE
  326. If (!hBitmap || !hwnd)
  327. Return
  328.  
  329. E := DllCall("SendMessage", "UPtr", hwnd, "UInt", 0x172, "UInt", 0x0, "UPtr", hBitmap)
  330. DeleteObject(E)
  331. return E
  332. }
  333.  
  334. ;#####################################################################################
  335.  
  336. ; Function Gdip_SetPbitmapCtrl
  337. ; Description Associates a GDI+ bitmap with a static control
  338. ; note the control should be a static text with +0xE -Border
  339.  
  340. ; hwnd handle of the control to update
  341. ; pBitmap a GDI+ bitmap to associate the static control with
  342.  
  343. ; return If the function succeeds, the return value is nonzero
  344.  
  345. Gdip_SetPbitmapCtrl(hwnd, pBitmap, w:=0, h:=0, quality:=7, KeepRatio:=0) {
  346. If (!pBitmap || !hwnd)
  347. Return 0
  348.  
  349. If (!w || !h)
  350. WinGetPos, , , w, h, ahk_id %hwnd%
  351.  
  352. Gdip_GetImageDimensions(pBitmap, imgW, imgH)
  353. If (imgW!=w || imgH!=h)
  354. fbmp := Gdip_ResizeBitmap(pBitmap, w, h, KeepRatio, quality)
  355. Else
  356. fbmp := Gdip_CloneBitmap(pBitmap)
  357.  
  358. If !fbmp
  359. Return 0
  360.  
  361. hBitmap := Gdip_CreateHBITMAPFromBitmap(fbmp)
  362. E := SetImage(hwnd, hBitmap)
  363. DeleteObject(hBitmap)
  364. Gdip_DisposeImage(fbmp)
  365. return E
  366. }
  367.  
  368. ;#####################################################################################
  369.  
  370. ; Function SetSysColorToControl
  371. ; Description Sets a solid colour to a control
  372. ;
  373. ; hwnd handle of the control to update
  374. ; SysColor A system colour to set to the control
  375. ;
  376. ; return If the function succeeds, the return value is zero
  377. ;
  378. ; notes A control must have the 0xE style set to it so it is recognised as a bitmap
  379. ; By default SysColor=15 is used which is COLOR_3DFACE. This is the standard background for a control
  380.  
  381. SetSysColorToControl(hwnd, SysColor:=15) {
  382. ; SysColor options:
  383. ; 3DDKSHADOW = 21
  384. ; 3DFACE = 15
  385. ; 3DHIGHLIGHT = 20
  386. ; 3DHILIGHT = 20
  387. ; 3DLIGHT = 22
  388. ; 3DSHADOW = 16
  389. ; ACTIVEBORDER = 10
  390. ; ACTIVECAPTION = 2
  391. ; APPWORKSPACE = 12
  392. ; BACKGROUND = 1
  393. ; BTNFACE = 15
  394. ; BTNHIGHLIGHT = 20
  395. ; BTNHILIGHT = 20
  396. ; BTNSHADOW = 16
  397. ; BTNTEXT = 18
  398. ; CAPTIONTEXT = 9
  399. ; DESKTOP = 1
  400. ; GRADIENTACTIVECAPTION 27
  401. ; GRADIENTINACTIVECAPTION = 28
  402. ; GRAYTEXT = 17
  403. ; HIGHLIGHT = 13
  404. ; HIGHLIGHTTEXT = 14
  405. ; HOTLIGHT = 26
  406. ; INACTIVEBORDER = 11
  407. ; INACTIVECAPTION = 3
  408. ; INACTIVECAPTIONTEXT = 19
  409. ; INFOBK = 24
  410. ; INFOTEXT = 23
  411. ; MENU = 4
  412. ; MENUHILIGHT = 29
  413. ; MENUBAR = 30
  414. ; MENUTEXT = 7
  415. ; SCROLLBAR = 0
  416. ; WINDOW = 5
  417. ; WINDOWFRAME = 6
  418. ; WINDOWTEXT = 8
  419.  
  420. GetWindowRect(hwnd, W, H)
  421. bc := DllCall("GetSysColor", "Int", SysColor, "UInt")
  422. pBrushClear := Gdip_BrushCreateSolid(0xff000000 | (bc >> 16 | bc & 0xff00 | (bc & 0xff) << 16))
  423. pBitmap := Gdip_CreateBitmap(w, h)
  424. G := Gdip_GraphicsFromImage(pBitmap)
  425. Gdip_FillRectangle(G, pBrushClear, 0, 0, w, h)
  426. hBitmap := Gdip_CreateHBITMAPFromBitmap(pBitmap)
  427. SetImage(hwnd, hBitmap)
  428. Gdip_DeleteBrush(pBrushClear)
  429. Gdip_DeleteGraphics(G)
  430. Gdip_DisposeImage(pBitmap)
  431. DeleteObject(hBitmap)
  432. return 0
  433. }
  434.  
  435. ;#####################################################################################
  436.  
  437. ; Function Gdip_BitmapFromScreen
  438. ; Description Gets a gdi+ bitmap from the screen
  439. ;
  440. ; Screen 0 = All screens
  441. ; Any numerical value = Just that screen
  442. ; x|y|w|h = Take specific coordinates with a width and height
  443. ; Raster raster operation code
  444. ;
  445. ; return If the function succeeds, the return value is a pointer to a gdi+ bitmap
  446. ; -1: one or more of x,y,w,h parameters were not passed properly
  447. ;
  448. ; notes If no raster operation is specified, then SRCCOPY is used to the returned bitmap
  449.  
  450. Gdip_BitmapFromScreen(Screen:=0, Raster:="") {
  451. hhdc := 0
  452. if (Screen = 0)
  453. {
  454. _x := DllCall("GetSystemMetrics", "Int", 76)
  455. _y := DllCall("GetSystemMetrics", "Int", 77)
  456. _w := DllCall("GetSystemMetrics", "Int", 78)
  457. _h := DllCall("GetSystemMetrics", "Int", 79)
  458. } else if (SubStr(Screen, 1, 5) = "hwnd:")
  459. {
  460. hwnd := SubStr(Screen, 6)
  461. if !WinExist("ahk_id " hwnd)
  462. return -2
  463.  
  464. GetWindowRect(hwnd, _w, _h)
  465. _x := _y := 0
  466. hhdc := GetDCEx(hwnd, 3)
  467. } else if IsInteger(Screen)
  468. {
  469. M := GetMonitorInfo(Screen)
  470. _x := M.Left, _y := M.Top, _w := M.Right-M.Left, _h := M.Bottom-M.Top
  471. } else
  472. {
  473. S := StrSplit(Screen, "|")
  474. _x := S[1], _y := S[2], _w := S[3], _h := S[4]
  475. }
  476.  
  477. if (_x = "") || (_y = "") || (_w = "") || (_h = "")
  478. return -1
  479.  
  480. chdc := CreateCompatibleDC()
  481. hbm := CreateDIBSection(_w, _h, chdc)
  482. obm := SelectObject(chdc, hbm)
  483. hhdc := hhdc ? hhdc : GetDC()
  484. BitBlt(chdc, 0, 0, _w, _h, hhdc, _x, _y, Raster)
  485. ReleaseDC(hhdc)
  486.  
  487. pBitmap := Gdip_CreateBitmapFromHBITMAP(hbm)
  488. SelectObject(chdc, obm), DeleteObject(hbm), DeleteDC(hhdc), DeleteDC(chdc)
  489. return pBitmap
  490. }
  491.  
  492. ;#####################################################################################
  493.  
  494. ; Function Gdip_BitmapFromHWND
  495. ; Description Uses PrintWindow to get a handle to the specified window and return a bitmap from it
  496. ;
  497. ; hwnd handle to the window to get a bitmap from
  498. ; clientOnly capture only the client area of the window, without title bar and border
  499. ;
  500. ; return If the function succeeds, the return value is a pointer to a gdi+ bitmap
  501.  
  502. Gdip_BitmapFromHWND(hwnd, clientOnly:=0) {
  503. ; Restore the window if minimized! Must be visible for capture.
  504. if DllCall("IsIconic", "uptr", hwnd)
  505. DllCall("ShowWindow", "uptr", hwnd, "int", 4)
  506.  
  507. thisFlag := 0
  508. If (clientOnly=1)
  509. {
  510. VarSetCapacity(rc, 16, 0)
  511. DllCall("GetClientRect", "uptr", hwnd, "uptr", &rc)
  512. Width := NumGet(rc, 8, "int")
  513. Height := NumGet(rc, 12, "int")
  514. thisFlag := 1
  515. } Else GetWindowRect(hwnd, Width, Height)
  516.  
  517. hbm := CreateDIBSection(Width, Height)
  518. hdc := CreateCompatibleDC()
  519. obm := SelectObject(hdc, hbm)
  520. PrintWindow(hwnd, hdc, 2 + thisFlag)
  521. pBitmap := Gdip_CreateBitmapFromHBITMAP(hbm)
  522. SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc)
  523. return pBitmap
  524. }
  525.  
  526. ;#####################################################################################
  527.  
  528. ; Function CreateRectF
  529. ; Description Creates a RectF object, containing a the coordinates and dimensions of a rectangle
  530. ;
  531. ; RectF Name to call the RectF object
  532. ; x, y x, y coordinates of the upper left corner of the rectangle
  533. ; w, h Width and height of the rectangle
  534. ;
  535. ; return No return value
  536.  
  537. CreateRectF(ByRef RectF, x, y, w, h, dtype:="float", ds:=4) {
  538. VarSetCapacity(RectF, ds*4, 0)
  539. NumPut(x, RectF, 0, dtype), NumPut(y, RectF, ds, dtype)
  540. NumPut(w, RectF, ds*2, dtype), NumPut(h, RectF, ds*3, dtype)
  541. }
  542.  
  543. RetrieveRectF(ByRef RectF, dtype:="float", ds:=4) {
  544. rData := {}
  545. rData.x := NumGet(&RectF, 0, dtype)
  546. rData.y := NumGet(&RectF, ds, dtype)
  547. rData.w := NumGet(&RectF, ds*2, dtype)
  548. rData.h := NumGet(&RectF, ds*3, dtype)
  549. return rData
  550. }
  551.  
  552. ;#####################################################################################
  553.  
  554. ; Function CreatePointF
  555. ; Description Creates a SizeF object, containing two values
  556. ;
  557. ; SizeF Name to call the SizeF object
  558. ; x, y x, y values for the SizeF object
  559. ;
  560. ; return No Return value
  561.  
  562. CreatePointF(ByRef PointF, x, y, dtype:="float", ds:=4) {
  563. VarSetCapacity(PointF, ds*2, 0)
  564. NumPut(x, PointF, 0, dtype)
  565. NumPut(y, PointF, ds, dtype)
  566. }
  567.  
  568. CreatePointsF(ByRef PointsF, inPoints, dtype:="float", ds:=4) {
  569. If IsObject(inPoints)
  570. {
  571. PointsCount := inPoints.Length()
  572. VarSetCapacity(PointsF, ds * PointsCount, 0)
  573. Loop % PointsCount
  574. NumPut(inPoints[A_Index], &PointsF, ds * (A_Index-1), dtype)
  575. Return PointsCount//2
  576. } Else
  577. {
  578. dss := ds*2
  579. Points := StrSplit(inPoints, "|")
  580. PointsCount := Points.Length()
  581. VarSetCapacity(PointsF, dss * PointsCount, 0)
  582. for eachPoint, Point in Points
  583. {
  584. Coord := StrSplit(Point, ",")
  585. NumPut(Coord[1], &PointsF, dss * (A_Index-1), dtype)
  586. NumPut(Coord[2], &PointsF, (dss * (A_Index-1)) + ds, dtype)
  587. }
  588. Return PointsCount
  589. }
  590. }
  591.  
  592. AllocateBinArray(ByRef BinArray, inArray, dtype:="float", ds:=4) {
  593. ; ds = data size
  594. ; dtypes and their corresponding ds
  595. ; "Int64" : 8, "Char" : 1
  596. ; , "UChar" : 1, "Short" : 2
  597. ; , "UShort" : 2, "Int" : 4
  598. ; , "UInt" : 4, "Float" : 4
  599. ; , "Double" : 8, "UPtr" : A_PtrSize
  600. ; , "UPtr" : A_PtrSize
  601. ; function inspired by MCL's CreateBinArray()
  602.  
  603. If IsObject(inArray)
  604. {
  605. totals := inArray.Length()
  606. VarSetCapacity(BinArray, ds * totals, 0)
  607. Loop %totals%
  608. NumPut(inArray[A_Index], &BinArray, ds * (A_Index - 1), dtype)
  609. } Else
  610. {
  611. arrayElements := StrSplit(inArray, "|")
  612. totals := arrayElements.Length()
  613. VarSetCapacity(BinArray, ds * totals, 0)
  614. Loop %totals%
  615. NumPut(arrayElements[A_Index], &BinArray, ds * (A_Index - 1), dtype)
  616. }
  617. Return totals
  618. }
  619.  
  620. ;#####################################################################################
  621.  
  622. ; Function CreateDIBSection
  623. ; Description The CreateDIBSection function creates a DIB (Device Independent Bitmap) that applications can write to directly
  624. ;
  625. ; w, h width and height of the bitmap to create
  626. ; hdc a handle to the device context to use the palette from
  627. ; bpp bits per pixel (32 = ARGB)
  628. ; ppvBits A pointer to a variable that receives a pointer to the location of the DIB bit values
  629. ;
  630. ; return returns a DIB. A gdi bitmap
  631. ;
  632. ; notes ppvBits will receive the location of the pixels in the DIB
  633.  
  634. CreateDIBSection(w, h, hdc:="", bpp:=32, ByRef ppvBits:=0, Usage:=0, hSection:=0, Offset:=0) {
  635. ; A GDI function that creates a new hBitmap,
  636. ; a device-independent bitmap [DIB].
  637. ; A DIB consists of two distinct parts:
  638. ; a BITMAPINFO structure describing the dimensions
  639. ; and colors of the bitmap, and an array of bytes
  640. ; defining the pixels of the bitmap.
  641.  
  642. hdc2 := hdc ? hdc : GetDC()
  643. VarSetCapacity(bi, 40, 0)
  644. NumPut(40, bi, 0, "uint")
  645. NumPut(w, bi, 4, "uint")
  646. NumPut(h, bi, 8, "uint")
  647. NumPut(1, bi, 12, "ushort")
  648. NumPut(bpp, bi, 14, "ushort")
  649. NumPut(0, bi, 16, "uInt")
  650.  
  651. hbm := DllCall("CreateDIBSection"
  652. , "UPtr", hdc2
  653. , "UPtr", &bi ; BITMAPINFO
  654. , "UInt", Usage
  655. , "UPtr*", ppvBits
  656. , "UPtr", hSection
  657. , "UInt", OffSet, "UPtr")
  658.  
  659. if !hdc
  660. ReleaseDC(hdc2)
  661. return hbm
  662. }
  663.  
  664. ;#####################################################################################
  665.  
  666. ; Function PrintWindow
  667. ; Description The PrintWindow function copies a visual window into the specified device context (DC), typically a printer DC
  668. ;
  669. ; hwnd A handle to the window that will be copied
  670. ; hdc A handle to the device context
  671. ; Flags Drawing options
  672. ;
  673. ; return If the function succeeds, it returns a nonzero value
  674. ;
  675. ; PW_CLIENTONLY = 1
  676.  
  677. PrintWindow(hwnd, hdc, Flags:=2) {
  678. ; set Flags to 2, to capture hardware accelerated windows
  679. ; this only applies on Windows 8.1 and later versions.
  680.  
  681. If ((A_OSVersion="WIN_XP" || A_OSVersion="WIN_7" || A_OSVersion="WIN_2000" || A_OSVersion="WIN_2003") && flags=2)
  682. flags := 0
  683.  
  684. return DllCall("PrintWindow", "UPtr", hwnd, "UPtr", hdc, "uint", Flags)
  685. }
  686.  
  687. ;#####################################################################################
  688.  
  689. ; Function DestroyIcon
  690. ; Description Destroys an icon and frees any memory the icon occupied
  691. ;
  692. ; hIcon Handle to the icon to be destroyed. The icon must not be in use
  693. ;
  694. ; return If the function succeeds, the return value is nonzero
  695.  
  696. DestroyIcon(hIcon) {
  697. return DllCall("DestroyIcon", "UPtr", hIcon)
  698. }
  699.  
  700. ;#####################################################################################
  701.  
  702. ; Function: GetIconDimensions
  703. ; Description: Retrieves a given icon/cursor's width and height
  704. ;
  705. ; hIcon Pointer to an icon or cursor
  706. ; Width, Height ByRef variables. These variables are set to the icon's width and height
  707. ;
  708. ; return If the function succeeds, the return value is zero, otherwise:
  709. ; -1 = Could not retrieve the icon's info. Check A_LastError for extended information
  710. ; -2 = Could not delete the icon's bitmask bitmap
  711. ; -3 = Could not delete the icon's color bitmap
  712.  
  713. GetIconDimensions(hIcon, ByRef Width, ByRef Height) {
  714. Width := Height := 0
  715.  
  716. VarSetCapacity(ICONINFO, size := 16 + 2 * A_PtrSize, 0)
  717. if !DllCall("user32\GetIconInfo", "UPtr", hIcon, "UPtr", &ICONINFO)
  718. return -1
  719.  
  720. hbmMask := NumGet(&ICONINFO, 16, "UPtr")
  721. hbmColor := NumGet(&ICONINFO, 16 + A_PtrSize, "UPtr")
  722. VarSetCapacity(BITMAP, size, 0)
  723. if DllCall("gdi32\GetObject", "UPtr", hbmColor, "Int", size, "UPtr", &BITMAP)
  724. {
  725. Width := NumGet(&BITMAP, 4, "Int")
  726. Height := NumGet(&BITMAP, 8, "Int")
  727. }
  728.  
  729. if !DeleteObject(hbmMask)
  730. return -2
  731.  
  732. if !DeleteObject(hbmColor)
  733. return -3
  734.  
  735. return 0
  736. }
  737.  
  738. PaintDesktop(hdc) {
  739. return DllCall("PaintDesktop", "UPtr", hdc)
  740. }
  741.  
  742. ;#####################################################################################
  743.  
  744. ; Function CreateCompatibleDC
  745. ; Description This function creates a memory device context (DC) compatible with the specified device
  746. ;
  747. ; hdc Handle to an existing device context
  748. ;
  749. ; return returns the handle to a device context or 0 on failure
  750. ;
  751. ; notes If this handle is 0 (by default), the function creates a memory device context compatible with the application's current screen
  752.  
  753. CreateCompatibleDC(hdc:=0) {
  754. return DllCall("CreateCompatibleDC", "UPtr", hdc)
  755. }
  756.  
  757. ;#####################################################################################
  758.  
  759. ; Function SelectObject
  760. ; Description The SelectObject function selects an object into the specified device context (DC). The new object replaces the previous object of the same type
  761. ;
  762. ; hdc Handle to a DC
  763. ; hgdiobj A handle to the object to be selected into the DC
  764. ;
  765. ; return If the selected object is not a region and the function succeeds, the return value is a handle to the object being replaced
  766. ;
  767. ; notes The specified object must have been created by using one of the following functions
  768. ; Bitmap - CreateBitmap, CreateBitmapIndirect, CreateCompatibleBitmap, CreateDIBitmap, CreateDIBSection (A single bitmap cannot be selected into more than one DC at the same time)
  769. ; Brush - CreateBrushIndirect, CreateDIBPatternBrush, CreateDIBPatternBrushPt, CreateHatchBrush, CreatePatternBrush, CreateSolidBrush
  770. ; Font - CreateFont, CreateFontIndirect
  771. ; Pen - CreatePen, CreatePenIndirect
  772. ; Region - CombineRgn, CreateEllipticRgn, CreateEllipticRgnIndirect, CreatePolygonRgn, CreateRectRgn, CreateRectRgnIndirect
  773. ;
  774. ; notes If the selected object is a region and the function succeeds, the return value is one of the following value
  775. ;
  776. ; SIMPLEREGION = 2 Region consists of a single rectangle
  777. ; COMPLEXREGION = 3 Region consists of more than one rectangle
  778. ; NULLREGION = 1 Region is empty
  779.  
  780. SelectObject(hdc, hgdiobj) {
  781. return DllCall("SelectObject", "UPtr", hdc, "UPtr", hgdiobj)
  782. }
  783.  
  784. ;#####################################################################################
  785.  
  786. ; Function DeleteObject
  787. ; Description This function deletes a logical pen, brush, font, bitmap, region, or palette, freeing all system resources associated with the object
  788. ; After the object is deleted, the specified handle is no longer valid
  789. ;
  790. ; hObject Handle to a logical pen, brush, font, bitmap, region, or palette to delete
  791. ;
  792. ; return Nonzero indicates success. Zero indicates that the specified handle is not valid or that the handle is currently selected into a device context
  793.  
  794. DeleteObject(hObject) {
  795. return DllCall("DeleteObject", "UPtr", hObject)
  796. }
  797.  
  798. ;#####################################################################################
  799.  
  800. ; Function GetDC
  801. ; Description This function retrieves a handle to a display device context (DC) for the client area of the specified window.
  802. ; The display device context can be used in subsequent graphics display interface (GDI) functions to draw in the client area of the window.
  803. ;
  804. ; hwnd Handle to the window whose device context is to be retrieved. If this value is NULL, GetDC retrieves the device context for the entire screen
  805. ;
  806. ; return The handle the device context for the specified window's client area indicates success. NULL indicates failure
  807.  
  808. GetDC(hwnd:=0) {
  809. return DllCall("GetDC", "UPtr", hwnd)
  810. }
  811.  
  812. GetDCEx(hwnd, flags:=0, hrgnClip:=0) {
  813. ; Device Context extended flags:
  814. ; DCX_CACHE = 0x2
  815. ; DCX_CLIPCHILDREN = 0x8
  816. ; DCX_CLIPSIBLINGS = 0x10
  817. ; DCX_EXCLUDERGN = 0x40
  818. ; DCX_EXCLUDEUPDATE = 0x100
  819. ; DCX_INTERSECTRGN = 0x80
  820. ; DCX_INTERSECTUPDATE = 0x200
  821. ; DCX_LOCKWINDOWUPDATE = 0x400
  822. ; DCX_NORECOMPUTE = 0x100000
  823. ; DCX_NORESETATTRS = 0x4
  824. ; DCX_PARENTCLIP = 0x20
  825. ; DCX_VALIDATE = 0x200000
  826. ; DCX_WINDOW = 0x1
  827.  
  828. return DllCall("GetDCEx", "UPtr", hwnd, "UPtr", hrgnClip, "int", flags)
  829. }
  830.  
  831. ;#####################################################################################
  832.  
  833. ; Function ReleaseDC
  834. ; Description This function releases a device context (DC), freeing it for use by other applications. The effect of ReleaseDC depends on the type of device context
  835. ;
  836. ; hdc Handle to the device context to be released
  837. ; hwnd Handle to the window whose device context is to be released
  838. ;
  839. ; return 1 = released
  840. ; 0 = not released
  841. ;
  842. ; notes The application must call the ReleaseDC function for each call to the GetWindowDC function and for each call to the GetDC function that retrieves a common device context
  843. ; An application cannot use the ReleaseDC function to release a device context that was created by calling the CreateDC function; instead, it must use the DeleteDC function.
  844.  
  845. ReleaseDC(hdc, hwnd:=0) {
  846. return DllCall("ReleaseDC", "UPtr", hwnd, "UPtr", hdc)
  847. }
  848.  
  849. ;#####################################################################################
  850.  
  851. ; Function DeleteDC
  852. ; Description The DeleteDC function deletes the specified device context (DC)
  853. ;
  854. ; hdc A handle to the device context
  855. ;
  856. ; return If the function succeeds, the return value is nonzero
  857. ;
  858. ; notes An application must not delete a DC whose handle was obtained by calling the GetDC function. Instead, it must call the ReleaseDC function to free the DC
  859.  
  860. DeleteDC(hdc) {
  861. return DllCall("DeleteDC", "UPtr", hdc)
  862. }
  863.  
  864. ;#####################################################################################
  865.  
  866. ; Function Gdip_LibraryVersion
  867. ; Description Get the current library version
  868. ;
  869. ; return the library version
  870. ;
  871. ; notes This is useful for non compiled programs to ensure that a person doesn't run an old version when testing your scripts
  872.  
  873. Gdip_LibraryVersion() {
  874. return 1.45
  875. }
  876.  
  877. ;#####################################################################################
  878.  
  879. ; Function Gdip_LibrarySubVersion
  880. ; Description Get the current library sub version
  881. ;
  882. ; return the library sub version
  883. ;
  884. ; notes This is the sub-version currently maintained by Rseding91
  885. ; Updated by guest3456 preliminary AHK v2 support
  886. ; Updated by Marius Șucan reflecting the work on Gdip_all extended compilation
  887.  
  888. Gdip_LibrarySubVersion() {
  889. return 1.97 ; 28/01/2025
  890. }
  891.  
  892. ;#####################################################################################
  893.  
  894. ; Function: Gdip_BitmapFromBRA
  895. ; Description: Gets a pointer to a gdi+ bitmap from a BRA file
  896. ;
  897. ; BRAFromMemIn The variable for a BRA file read to memory
  898. ; File The name of the file, or its number that you would like (This depends on alternate parameter)
  899. ; Alternate Changes whether the File parameter is the file name or its number
  900. ;
  901. ; return If the function succeeds, the return value is a pointer to a gdi+ bitmap
  902. ; -1 = The BRA variable is empty
  903. ; -2 = The BRA has an incorrect header
  904. ; -3 = The BRA has information missing
  905. ; -4 = Could not find file inside the BRA
  906.  
  907. Gdip_BitmapFromBRA(ByRef BRAFromMemIn, File, Alternate := 0) {
  908. pBitmap := 0
  909. pStream := 0
  910.  
  911. If !(BRAFromMemIn)
  912. Return -1
  913.  
  914. Headers := StrSplit(StrGet(&BRAFromMemIn, 256, "CP0"), "`n")
  915. Header := StrSplit(Headers.1, "|")
  916. If (Header.Length() != 4) || (Header.2 != "BRA!")
  917. Return -2
  918.  
  919. _Info := StrSplit(Headers.2, "|")
  920. If (_Info.Length() != 3)
  921. Return -3
  922.  
  923. OffsetTOC := StrPut(Headers.1, "CP0") + StrPut(Headers.2, "CP0") ; + 2
  924. OffsetData := _Info.2
  925. TOC := StrGet(&BRAFromMemIn + OffsetTOC, OffsetData - OffsetTOC - 1, "CP0")
  926. RX1 := A_AhkVersion < "2" ? "mi`nO)^" : "mi`n)^"
  927. Offset := Size := 0
  928. If RegExMatch(TOC, RX1 . (Alternate ? File "\|.+?" : "\d+\|" . File) . "\|(\d+)\|(\d+)$", FileInfo) {
  929. Offset := OffsetData + FileInfo.1
  930. Size := FileInfo.2
  931. }
  932. If (Size=0)
  933. Return -4
  934.  
  935. hData := DllCall("GlobalAlloc", "UInt", 2, "UInt", Size, "UPtr")
  936. pData := DllCall("GlobalLock", "Ptr", hData, "UPtr")
  937. DllCall("RtlMoveMemory", "Ptr", pData, "Ptr", &BRAFromMemIn + Offset, "Ptr", Size)
  938. DllCall("GlobalUnlock", "Ptr", hData)
  939. DllCall("Ole32.dll\CreateStreamOnHGlobal", "Ptr", hData, "Int", 1, "PtrP", pStream)
  940. pBitmap := Gdip_CreateBitmapFromStream(pStream)
  941. ObjRelease(pStream)
  942. Return pBitmap
  943. }
  944.  
  945. ;#####################################################################################
  946.  
  947. ; Function: Gdip_BitmapToBase64
  948. ; Description: Creates a Base64 encoded string from a pBitmap.
  949. ;
  950. ; pBitmap The handle of a GDI+ image object
  951. ; Format The format or encoder to use. Supported extensions and formats: BMP, DIB, RLE, JPG, JPEG, JPE, JFIF, GIF, TIF, TIFF, PNG
  952. ; Quality If saving as jpg (.JPG,.JPEG,.JPE,.JFIF) then quality can be 1-100
  953. ;
  954. ; return If the function succeeds, the base64 encoded string is returned. otherwise:
  955. ; -1 = Extension supplied is not a supported image file encoder
  956. ; -2 = Could not get a list of encoders on system
  957. ; -3 = Could not find matching encoder for specified file format
  958. ; -6 = Could not save image to stream [for base64]
  959. ; -7 = Could not convert to base64
  960.  
  961. Gdip_BitmapToBase64(pBitmap, Format, Quality:=90) {
  962. Format := "none." Format
  963. Return Gdip_SaveBitmapToFile(pBitmap, Format, Quality, 1)
  964. }
  965.  
  966. ;#####################################################################################
  967.  
  968. ; Function: Gdip_BitmapFromBase64
  969. ; Description: Creates a bitmap from a Base64 encoded string
  970. ;
  971. ; Base64 ByRef variable. Base64 encoded string. Immutable, ByRef to avoid performance overhead of passing long strings.
  972. ;
  973. ; return If the function succeeds, the return value is a pointer to a bitmap, otherwise:
  974. ; -1 = Could not calculate the length of the required buffer
  975. ; -2 = Could not decode the Base64 encoded string
  976. ; -3 = Could not create a memory stream
  977.  
  978. Gdip_BitmapFromBase64(ByRef Base64) {
  979. pBitmap := 0
  980. DecLen := 0
  981. ; calculate the length of the buffer needed
  982. if !(DllCall("crypt32\CryptStringToBinary", "UPtr", &Base64, "UInt", 0, "UInt", 0x01, "UPtr", 0, "UIntP", DecLen, "UPtr", 0, "UPtr", 0))
  983. return -1
  984.  
  985. ; decode the Base64 encoded string
  986. VarSetCapacity(Dec, DecLen, 0)
  987. if !(DllCall("crypt32\CryptStringToBinary", "UPtr", &Base64, "UInt", 0, "UInt", 0x01, "UPtr", &Dec, "UIntP", DecLen, "UPtr", 0, "UPtr", 0))
  988. return -2
  989.  
  990. ; create a memory stream
  991. if !(pStream := DllCall("shlwapi\SHCreateMemStream", "UPtr", &Dec, "UInt", DecLen, "UPtr"))
  992. return -3
  993.  
  994. pBitmap := Gdip_CreateBitmapFromStream(pStream, 1)
  995. ObjRelease(pStream)
  996. return pBitmap
  997. }
  998.  
  999. Gdip_CreateBitmapFromStream(pStream, useICM:=0) {
  1000. pBitmap := 0
  1001. function2call := (useICM=1) ? "ICM" : ""
  1002. gdipLastError := DllCall("gdiplus\GdipCreateBitmapFromStream" function2call, "UPtr", pStream, "PtrP", pBitmap)
  1003. Return pBitmap
  1004. }
  1005.  
  1006. ;#####################################################################################
  1007.  
  1008. ; Function Gdip_DrawRectangle
  1009. ; Description This function uses a pen to draw the outline of a rectangle into the Graphics of a bitmap
  1010. ;
  1011. ; pGraphics Pointer to the Graphics of a bitmap
  1012. ; pPen Pointer to a pen
  1013. ; x, y x, y coordinates of the top left of the rectangle
  1014. ; w, h width and height of the rectangle
  1015. ;
  1016. ; return status enumeration. 0 = success
  1017. ;
  1018. ; notes as all coordinates are taken from the top left of each pixel, then the entire width/height should be specified as subtracting the pen width
  1019.  
  1020. Gdip_DrawRectangle(pGraphics, pPen, x, y, w, h:=0) {
  1021. If (!pGraphics || !pPen || !w)
  1022. Return 2
  1023.  
  1024. if (h<=0 || !h)
  1025. h := w
  1026.  
  1027. Return DllCall("gdiplus\GdipDrawRectangle", "UPtr", pGraphics, "UPtr", pPen, "float", x, "float", y, "float", w, "float", h)
  1028. }
  1029.  
  1030. Gdip_DrawRectangleC(pGraphics, pPen, cx, cy, rx, ry := "") {
  1031. If (ry == "")
  1032. ry := rx
  1033.  
  1034. Return Gdip_DrawRectangle(pGraphics, pPen, cx-rx, cy-ry, rx*2, ry*2)
  1035. }
  1036.  
  1037.  
  1038. ;#####################################################################################
  1039.  
  1040. ; Function Gdip_DrawRoundedRectangle
  1041. ; Description This function uses a pen to draw the outline of a rounded rectangle into the Graphics of a bitmap
  1042. ;
  1043. ; pGraphics Pointer to the Graphics of a bitmap
  1044. ; pPen Pointer to a pen
  1045. ; x, y x, y coordinates of the top left of the rounded rectangle
  1046. ; w, h width and height of the rectanlge
  1047. ; r radius of the rounded corners
  1048. ;
  1049. ; return status enumeration. 0 = success
  1050. ;
  1051. ; notes as all coordinates are taken from the top left of each pixel, then the entire width/height should be specified as subtracting the pen width
  1052.  
  1053. Gdip_DrawRoundedRectangle(pGraphics, pPen, x, y, w, h, r) {
  1054. If (!pGraphics || !pPen || !w || !h)
  1055. Return 2
  1056.  
  1057. Gdip_SetClipRect(pGraphics, x-r, y-r, 2*r, 2*r, 4)
  1058. Gdip_SetClipRect(pGraphics, x+w-r, y-r, 2*r, 2*r, 4)
  1059. Gdip_SetClipRect(pGraphics, x-r, y+h-r, 2*r, 2*r, 4)
  1060. Gdip_SetClipRect(pGraphics, x+w-r, y+h-r, 2*r, 2*r, 4)
  1061. _E := Gdip_DrawRectangle(pGraphics, pPen, x, y, w, h)
  1062. Gdip_ResetClip(pGraphics)
  1063. Gdip_SetClipRect(pGraphics, x-(2*r), y+r, w+(4*r), h-(2*r), 4)
  1064. Gdip_SetClipRect(pGraphics, x+r, y-(2*r), w-(2*r), h+(4*r), 4)
  1065. Gdip_DrawEllipse(pGraphics, pPen, x, y, 2*r, 2*r)
  1066. Gdip_DrawEllipse(pGraphics, pPen, x+w-(2*r), y, 2*r, 2*r)
  1067. Gdip_DrawEllipse(pGraphics, pPen, x, y+h-(2*r), 2*r, 2*r)
  1068. Gdip_DrawEllipse(pGraphics, pPen, x+w-(2*r), y+h-(2*r), 2*r, 2*r)
  1069. Gdip_ResetClip(pGraphics)
  1070. return _E
  1071. }
  1072.  
  1073. ;#####################################################################################
  1074. ; function by just me found on:
  1075. ; https://www.autohotkey.com/boards/viewtopic.php?t=46250
  1076. ; modified by Marius Șucan
  1077. ;
  1078. ; Function Gdip_DrawRoundedRectanglePath
  1079. ; Description This function uses a pen to draw a rounded rectangle in the Graphics of a bitmap
  1080. ;
  1081. ; pGraphics Pointer to the Graphics of a bitmap
  1082. ; pPen Pointer to a pPen
  1083. ; x x-coordinate of the top left of the rounded rectangle
  1084. ; y y-coordinate of the top left of the rounded rectangle
  1085. ; w width of the rectanlge
  1086. ; h height of the rectangle
  1087. ; r radius of the rounded corners
  1088. ;
  1089. ; return status enumeration. 0 = success
  1090.  
  1091. Gdip_DrawRoundedRectanglePath(pGraphics, pPen, X, Y, W, H, R, angle:=0) {
  1092. pPath := Gdip_CreatePath()
  1093. Gdip_AddPathRoundedRectangle(pPath, X, Y, W, H, R, angle)
  1094. E := Gdip_DrawPath(pGraphics, pPen, pPath)
  1095. Gdip_DeletePath(pPath)
  1096. Return E
  1097. }
  1098.  
  1099. ;#####################################################################################
  1100. ; Function Gdip_DrawEllipse
  1101. ; Description This function uses a pen to draw the outline of an ellipse into the Graphics of a bitmap
  1102. ;
  1103. ; pGraphics Pointer to the Graphics of a bitmap
  1104. ; pPen Pointer to a pen
  1105. ; x, y x, y coordinates of the top left of the rectangle the ellipse will be drawn into
  1106. ; w, h width and height of the ellipse
  1107. ;
  1108. ; return status enumeration. 0 = success
  1109. ;
  1110. ; notes as all coordinates are taken from the top left of each pixel, then the entire width/height should be specified as subtracting the pen width
  1111.  
  1112. Gdip_DrawEllipse(pGraphics, pPen, x, y, w, h:=0) {
  1113. If (!pGraphics || !pPen || !w)
  1114. Return 2
  1115.  
  1116. if (h<=0 || !h)
  1117. h := w
  1118.  
  1119. Return DllCall("gdiplus\GdipDrawEllipse", "UPtr", pGraphics, "UPtr", pPen, "float", x, "float", y, "float", w, "float", h)
  1120. }
  1121.  
  1122. Gdip_DrawEllipseC(pGraphics, pPen, cx, cy, rx, ry := "") {
  1123. If (ry == "")
  1124. ry := rx
  1125.  
  1126. Return Gdip_DrawEllipse(pGraphics, pPen, cx-rx, cy-ry, rx*2, ry*2)
  1127. }
  1128.  
  1129.  
  1130. ;#####################################################################################
  1131.  
  1132. ; Function Gdip_DrawBezier
  1133. ; Description This function uses a pen to draw the outline of a bezier (a weighted curve) into the Graphics of a bitmap
  1134. ; A Bezier spline does not pass through its control points. The control points act as magnets, pulling the curve
  1135. ; in certain directions to influence the way the spline bends.
  1136.  
  1137. ; pGraphics Pointer to the Graphics of a bitmap
  1138. ; pPen Pointer to a pen
  1139. ; x1, y1 x, y coordinates of the start of the bezier
  1140. ; x2, y2 x, y coordinates of the first arc of the bezier
  1141. ; x3, y3 x, y coordinates of the second arc of the bezier
  1142. ; x4, y4 x, y coordinates of the end of the bezier
  1143. ;
  1144. ; return status enumeration. 0 = success
  1145. ;
  1146. ; notes as all coordinates are taken from the top left of each pixel, then the entire width/height should be specified as subtracting the pen width
  1147.  
  1148. Gdip_DrawBezier(pGraphics, pPen, x1, y1, x2, y2, x3, y3, x4, y4) {
  1149. If (!pGraphics || !pPen)
  1150. Return 2
  1151.  
  1152. Return DllCall("gdiplus\GdipDrawBezier"
  1153. , "UPtr", pGraphics, "UPtr", pPen
  1154. , "float", x1, "float", y1
  1155. , "float", x2, "float", y2
  1156. , "float", x3, "float", y3
  1157. , "float", x4, "float", y4)
  1158. }
  1159.  
  1160. ;#####################################################################################
  1161.  
  1162. ; Function Gdip_DrawBezierCurve
  1163. ; Description This function uses a pen to draw beziers
  1164. ; Parameters:
  1165. ; pGraphics Pointer to the Graphics of a bitmap
  1166. ; pPen Pointer to a pen
  1167. ; Points
  1168. ; An array of starting and control points of a Bezier line
  1169. ; A single Bezier line consists of 4 points a starting point 2 control
  1170. ; points and an end point.
  1171. ; The line never actually goes through the control points.
  1172. ; The control points define the tangent in the starting and end points and their
  1173. ; distance controls how strongly the curve follows there.
  1174. ;
  1175. ; Return: status enumeration. 0 = success
  1176. ;
  1177. ; This function was extracted and modified by Marius Șucan from
  1178. ; a class based wrapper around the GDI+ API made by nnnik.
  1179. ; Source: https://github.com/nnnik/classGDIp
  1180. ;
  1181. ; Points parameter can be an array or a string with the following format:
  1182. ; Points := "x1,y1|x2,y2|x3,y3|x4,y4" [... and so on]
  1183.  
  1184. Gdip_DrawBezierCurve(pGraphics, pPen, Points) {
  1185. If (!pGraphics || !pPen || !Points)
  1186. Return 2
  1187.  
  1188. iCount := CreatePointsF(PointsF, Points)
  1189. Return DllCall("gdiplus\GdipDrawBeziers", "UPtr", pGraphics, "UPtr", pPen, "UPtr", &PointsF, "UInt", iCount)
  1190. }
  1191.  
  1192. Gdip_DrawClosedCurve(pGraphics, pPen, Points, Tension:="") {
  1193. ; Draws a closed cardinal spline on a pGraphics object using a pPen object.
  1194. ; A cardinal spline is a curve that passes through each point in the array.
  1195.  
  1196. ; Tension: Non-negative real number that controls the length of the curve and how the curve bends. A value of
  1197. ; zero specifies that the spline is a sequence of straight lines. As the value increases, the curve becomes fuller.
  1198. ; Number that specifies how tightly the curve bends through the coordinates of the closed cardinal spline.
  1199.  
  1200. ; Points parameter can be an array or a string with the following format:
  1201. ; Points := "x1,y1|x2,y2|x3,y3" [and so on]
  1202. ; At least three points must be defined.
  1203. If (!pGraphics || !pPen || !Points)
  1204. Return 2
  1205.  
  1206. iCount := CreatePointsF(PointsF, Points)
  1207. If IsNumber(Tension)
  1208. Return DllCall("gdiplus\GdipDrawClosedCurve2", "UPtr", pGraphics, "UPtr", pPen, "UPtr", &PointsF, "UInt", iCount, "float", Tension)
  1209. Else
  1210. Return DllCall("gdiplus\GdipDrawClosedCurve", "UPtr", pGraphics, "UPtr", pPen, "UPtr", &PointsF, "UInt", iCount)
  1211. }
  1212.  
  1213. Gdip_DrawCurve(pGraphics, pPen, Points, Tension:="") {
  1214. ; Draws an open spline on a pGraphics object using a pPen object.
  1215. ; A cardinal spline is a curve that passes through each point in the array.
  1216.  
  1217. ; Tension: Non-negative real number that controls the length of the curve and how the curve bends. A value of
  1218. ; zero specifies that the spline is a sequence of straight lines. As the value increases, the curve becomes fuller.
  1219. ; Number that specifies how tightly the curve bends through the coordinates of the closed cardinal spline.
  1220.  
  1221. ; Points parameter can be an array or a string with the following format:
  1222. ; Points := "x1,y1|x2,y2|x3,y3" [and so on]
  1223. ; At least three points must be defined.
  1224. If (!pGraphics || !pPen || !Points)
  1225. Return 2
  1226.  
  1227. iCount := CreatePointsF(PointsF, Points)
  1228. If IsNumber(Tension)
  1229. Return DllCall("gdiplus\GdipDrawCurve2", "UPtr", pGraphics, "UPtr", pPen, "UPtr", &PointsF, "UInt", iCount, "float", Tension)
  1230. Else
  1231. Return DllCall("gdiplus\GdipDrawCurve", "UPtr", pGraphics, "UPtr", pPen, "UPtr", &PointsF, "UInt", iCount)
  1232. }
  1233.  
  1234. Gdip_DrawPolygon(pGraphics, pPen, Points) {
  1235. ; Draws a closed polygonal line on a pGraphics object using a pPen object.
  1236. ;
  1237. ; Points parameter can be an array or a string with the following format:
  1238. ; Points := "x1,y1|x2,y2|x3,y3" [and so on]
  1239. If (!pGraphics || !pPen || !Points)
  1240. Return 2
  1241.  
  1242. iCount := CreatePointsF(PointsF, Points)
  1243. Return DllCall("gdiplus\GdipDrawPolygon", "UPtr", pGraphics, "UPtr", pPen, "UPtr", &PointsF, "UInt", iCount)
  1244. }
  1245.  
  1246. ;#####################################################################################
  1247.  
  1248. ; Function Gdip_DrawArc
  1249. ; Description This function uses a pen to draw the outline of an arc into the Graphics of a bitmap
  1250. ;
  1251. ; pGraphics Pointer to the Graphics of a bitmap
  1252. ; pPen Pointer to a pen
  1253. ; x, y x, y coordinates of the start of the arc
  1254. ; w, h width and height of the arc
  1255. ; StartAngle specifies the angle between the x-axis and the starting point of the arc
  1256. ; SweepAngle specifies the angle between the starting and ending points of the arc
  1257. ;
  1258. ; return status enumeration. 0 = success
  1259. ;
  1260. ; notes as all coordinates are taken from the top left of each pixel, then the entire width/height should be specified as subtracting the pen width
  1261.  
  1262. Gdip_DrawArc(pGraphics, pPen, x, y, w, h, StartAngle, SweepAngle) {
  1263. If (!pGraphics || !pPen || !w || !h)
  1264. Return 2
  1265.  
  1266. Return DllCall("gdiplus\GdipDrawArc"
  1267. , "UPtr", pGraphics
  1268. , "UPtr", pPen
  1269. , "float", x, "float", y
  1270. , "float", w, "float", h
  1271. , "float", StartAngle
  1272. , "float", SweepAngle)
  1273. }
  1274.  
  1275. ;#####################################################################################
  1276.  
  1277. ; Function Gdip_DrawPie
  1278. ; Description This function uses a pen to draw the outline of a pie into the Graphics of a bitmap
  1279. ;
  1280. ; pGraphics Pointer to the Graphics of a bitmap
  1281. ; pPen Pointer to a pen
  1282. ; x, y x, y coordinates of the start of the pie
  1283. ; w, h width and height of the pie
  1284. ; StartAngle specifies the angle between the x-axis and the starting point of the pie
  1285. ; SweepAngle specifies the angle between the starting and ending points of the pie
  1286. ;
  1287. ; return status enumeration. 0 = success
  1288. ;
  1289. ; notes as all coordinates are taken from the top left of each pixel, then the entire width/height should be specified as subtracting the pen width
  1290.  
  1291. Gdip_DrawPie(pGraphics, pPen, x, y, w, h, StartAngle, SweepAngle) {
  1292. If (!pGraphics || !pPen || !w || !h)
  1293. Return 2
  1294.  
  1295. Return DllCall("gdiplus\GdipDrawPie", "UPtr", pGraphics, "UPtr", pPen, "float", x, "float", y, "float", w, "float", h, "float", StartAngle, "float", SweepAngle)
  1296. }
  1297.  
  1298. Gdip_DrawPieC(pGraphics, pPen, cx, cy, rx, ry, StartAngle, SweepAngle) {
  1299. Return Gdip_DrawPie(pGraphics, pPen, cx-rx, cy-ry, rx*2, ry*2, StartAngle, SweepAngle)
  1300. }
  1301.  
  1302. ;#####################################################################################
  1303.  
  1304. ; Function Gdip_DrawLine
  1305. ; Description This function uses a pen to draw a line into the Graphics of a bitmap
  1306. ;
  1307. ; pGraphics Pointer to the Graphics of a bitmap
  1308. ; pPen Pointer to a pen
  1309. ; x1, y1 x, y coordinates of the start of the line
  1310. ; x2, y2 x, y coordinates of the end of the line
  1311. ;
  1312. ; return status enumeration. 0 = success
  1313.  
  1314. Gdip_DrawLine(pGraphics, pPen, x1, y1, x2, y2) {
  1315. If (!pGraphics || !pPen)
  1316. Return 2
  1317.  
  1318. Return DllCall("gdiplus\GdipDrawLine"
  1319. , "UPtr", pGraphics, "UPtr", pPen
  1320. , "float", x1, "float", y1
  1321. , "float", x2, "float", y2)
  1322. }
  1323.  
  1324. ;#####################################################################################
  1325.  
  1326. ; Function Gdip_DrawLines
  1327. ; Description This function uses a pen to draw a series of joined lines into the Graphics of a bitmap
  1328. ;
  1329. ; pGraphics Pointer to the Graphics of a bitmap
  1330. ; pPen Pointer to a pen
  1331. ; Points parameter can be an array or a string with the following format:
  1332. ; "x1,y1|x2,y2|x3,y3" and so on.
  1333. ;
  1334. ; return status enumeration. 0 = success
  1335.  
  1336. Gdip_DrawLines(pGraphics, pPen, Points) {
  1337. If (!pGraphics || !pPen || !Points)
  1338. Return 2
  1339.  
  1340. iCount := CreatePointsF(PointsF, Points)
  1341. Return DllCall("gdiplus\GdipDrawLines", "UPtr", pGraphics, "UPtr", pPen, "UPtr", &PointsF, "int", iCount)
  1342. }
  1343.  
  1344. ;#####################################################################################
  1345.  
  1346. ; Function Gdip_FillRectangle
  1347. ; Description This function uses a brush to fill a rectangle in the Graphics of a bitmap
  1348. ;
  1349. ; pGraphics Pointer to the Graphics of a bitmap
  1350. ; pBrush Pointer to a brush
  1351. ; x, y x, y coordinates of the top left of the rectangle
  1352. ; w, h width and height of the rectangle
  1353. ;
  1354. ; return status enumeration. 0 = success
  1355.  
  1356. Gdip_FillRectangle(pGraphics, pBrush, x, y, w, h:=0) {
  1357. If (!pGraphics || !pBrush || !w)
  1358. Return 2
  1359.  
  1360. if (h<=0 || !h)
  1361. h := w
  1362.  
  1363. Return DllCall("gdiplus\GdipFillRectangle"
  1364. , "UPtr", pGraphics
  1365. , "UPtr", pBrush
  1366. , "float", x, "float", y
  1367. , "float", w, "float", h)
  1368. }
  1369.  
  1370. Gdip_FillRectangleC(pGraphics, pBrush, cx, cy, rx, ry := "") {
  1371. If (ry == "")
  1372. ry := rx
  1373.  
  1374. Return Gdip_FillRectangle(pGraphics, pBrush, cx-rx, cy-ry, rx*2, ry*2)
  1375. }
  1376.  
  1377.  
  1378. ;#####################################################################################
  1379.  
  1380. ; Function Gdip_FillRoundedRectangle
  1381. ; Description This function uses a brush to fill a rounded rectangle in the Graphics of a bitmap
  1382. ;
  1383. ; pGraphics Pointer to the Graphics of a bitmap
  1384. ; pBrush Pointer to a brush
  1385. ; x, y x, y coordinates of the top left of the rounded rectangle
  1386. ; w, h width and height of the rectanlge
  1387. ; r radius of the rounded corners
  1388. ;
  1389. ; return status enumeration. 0 = success
  1390.  
  1391. Gdip_FillRoundedRectangle(pGraphics, pBrush, x, y, w, h, r) {
  1392. Region := Gdip_GetClipRegion(pGraphics)
  1393. Gdip_SetClipRect(pGraphics, x-r, y-r, 2*r, 2*r, 4)
  1394. Gdip_SetClipRect(pGraphics, x+w-r, y-r, 2*r, 2*r, 4)
  1395. Gdip_SetClipRect(pGraphics, x-r, y+h-r, 2*r, 2*r, 4)
  1396. Gdip_SetClipRect(pGraphics, x+w-r, y+h-r, 2*r, 2*r, 4)
  1397. _E := Gdip_FillRectangle(pGraphics, pBrush, x, y, w, h)
  1398. Gdip_SetClipRegion(pGraphics, Region, 0)
  1399. Gdip_SetClipRect(pGraphics, x-(2*r), y+r, w+(4*r), h-(2*r), 4)
  1400. Gdip_SetClipRect(pGraphics, x+r, y-(2*r), w-(2*r), h+(4*r), 4)
  1401. Gdip_FillEllipse(pGraphics, pBrush, x, y, 2*r, 2*r)
  1402. Gdip_FillEllipse(pGraphics, pBrush, x+w-(2*r), y, 2*r, 2*r)
  1403. Gdip_FillEllipse(pGraphics, pBrush, x, y+h-(2*r), 2*r, 2*r)
  1404. Gdip_FillEllipse(pGraphics, pBrush, x+w-(2*r), y+h-(2*r), 2*r, 2*r)
  1405. Gdip_SetClipRegion(pGraphics, Region, 0)
  1406. Gdip_DeleteRegion(Region)
  1407. return _E
  1408. }
  1409.  
  1410. ;#####################################################################################
  1411. ; function by just me found on:
  1412. ; https://www.autohotkey.com/boards/viewtopic.php?t=46250
  1413. ; Function Gdip_FillRoundedRectanglePath
  1414. ; Description This function uses a brush to fill a rounded rectangle in the Graphics of a bitmap
  1415. ;
  1416. ; pGraphics Pointer to the Graphics of a bitmap
  1417. ; pBrush Pointer to a brush
  1418. ; x x-coordinate of the top left of the rounded rectangle
  1419. ; y y-coordinate of the top left of the rounded rectangle
  1420. ; w width of the rectanlge
  1421. ; h height of the rectangle
  1422. ; r radius of the rounded corners
  1423. ;
  1424. ; return status enumeration. 0 = success
  1425.  
  1426. Gdip_FillRoundedRectanglePath(pGraphics, pBrush, X, Y, W, H, R, angle:=0) {
  1427. pPath := Gdip_CreatePath()
  1428. Gdip_AddPathRoundedRectangle(pPath, X, Y, W, H, R, angle)
  1429. E := Gdip_FillPath(pGraphics, pBrush, pPath)
  1430. Gdip_DeletePath(pPath)
  1431. Return E
  1432. }
  1433.  
  1434. ;#####################################################################################
  1435.  
  1436. ; Function Gdip_FillPolygon
  1437. ; Description This function uses a brush to fill a polygon in the Graphics of a bitmap
  1438. ;
  1439. ; pGraphics Pointer to the Graphics of a bitmap
  1440. ; pBrush Pointer to a brush
  1441. ; Points parameter can be an array or a string with the following format:
  1442. ; "x1,y1|x2,y2|x3,y3" and so on.
  1443. ;
  1444. ; return status enumeration. 0 = success
  1445. ;
  1446. ; notes Alternate will fill the polygon as a whole, wheras winding will fill each new "segment"
  1447. ; Alternate = 0
  1448. ; Winding = 1
  1449.  
  1450. Gdip_FillPolygon(pGraphics, pBrush, Points, FillMode:=0) {
  1451. If (!pGraphics || !pBrush || !Points)
  1452. Return 2
  1453.  
  1454. iCount := CreatePointsF(PointsF, Points)
  1455. Return DllCall("gdiplus\GdipFillPolygon", "UPtr", pGraphics, "UPtr", pBrush, "UPtr", &PointsF, "int", iCount, "int", FillMode)
  1456. }
  1457.  
  1458. ;#####################################################################################
  1459.  
  1460. ; Function Gdip_FillPie
  1461. ; Description This function uses a brush to fill a pie in the Graphics of a bitmap
  1462. ;
  1463. ; pGraphics Pointer to the Graphics of a bitmap
  1464. ; pBrush Pointer to a brush
  1465. ; x, y x, y coordinates of the top left of the pie
  1466. ; w, h width and height of the pie
  1467. ; StartAngle specifies the angle between the x-axis and the starting point of the pie
  1468. ; SweepAngle specifies the angle between the starting and ending points of the pie
  1469. ;
  1470. ; return status enumeration. 0 = success
  1471.  
  1472. Gdip_FillPie(pGraphics, pBrush, x, y, w, h, StartAngle, SweepAngle) {
  1473. If (!pGraphics || !pBrush || !w || !h)
  1474. Return 2
  1475.  
  1476. Return DllCall("gdiplus\GdipFillPie"
  1477. , "UPtr", pGraphics
  1478. , "UPtr", pBrush
  1479. , "float", x, "float", y
  1480. , "float", w, "float", h
  1481. , "float", StartAngle
  1482. , "float", SweepAngle)
  1483. }
  1484.  
  1485. Gdip_FillPieC(pGraphics, pBrush, cx, cy, rx, ry, StartAngle, SweepAngle) {
  1486. Return Gdip_FillPie(pGraphics, pBrush, cx-rx, cy-ry, rx*2, ry*2, StartAngle, SweepAngle)
  1487. }
  1488.  
  1489.  
  1490. ;#####################################################################################
  1491.  
  1492. ; Function Gdip_FillEllipse
  1493. ; Description This function uses a brush to fill an ellipse in the Graphics of a bitmap
  1494. ;
  1495. ; pGraphics Pointer to the Graphics of a bitmap
  1496. ; pBrush Pointer to a brush
  1497. ; x, y x, y coordinates of the top left of the ellipse
  1498. ; w, h width and height of the ellipse
  1499. ;
  1500. ; return status enumeration. 0 = success
  1501.  
  1502. Gdip_FillEllipse(pGraphics, pBrush, x, y, w, h:=0) {
  1503. If (!pGraphics || !pBrush || !w)
  1504. Return 2
  1505.  
  1506. if (h<=0 || !h)
  1507. h := w
  1508.  
  1509. Return DllCall("gdiplus\GdipFillEllipse", "UPtr", pGraphics, "UPtr", pBrush, "float", x, "float", y, "float", w, "float", h)
  1510. }
  1511.  
  1512. Gdip_FillEllipseC(pGraphics, pBrush, cx, cy, rx, ry := "") {
  1513. If (ry == "")
  1514. ry := rx
  1515.  
  1516. Return Gdip_FillEllipse(pGraphics, pBrush, cx-rx, cy-ry, rx*2, ry*2)
  1517. }
  1518.  
  1519. ;#####################################################################################
  1520.  
  1521. ; Function Gdip_FillRegion
  1522. ; Description This function uses a brush to fill a region in the Graphics of a bitmap
  1523. ;
  1524. ; pGraphics Pointer to the Graphics of a bitmap
  1525. ; pBrush Pointer to a brush
  1526. ; Region Pointer to a Region
  1527. ;
  1528. ; return status enumeration. 0 = success
  1529. ;
  1530. ; notes You can create a region Gdip_CreateRegion() and then add to this
  1531.  
  1532. Gdip_FillRegion(pGraphics, pBrush, hRegion) {
  1533. If (!pGraphics || !pBrush || !hRegion)
  1534. Return 2
  1535.  
  1536. Return DllCall("gdiplus\GdipFillRegion", "UPtr", pGraphics, "UPtr", pBrush, "UPtr", hRegion)
  1537. }
  1538.  
  1539. ;#####################################################################################
  1540.  
  1541. ; Function Gdip_FillPath
  1542. ; Description This function uses a brush to fill a path in the Graphics of a bitmap
  1543. ;
  1544. ; pGraphics Pointer to the Graphics of a bitmap
  1545. ; pBrush Pointer to a brush
  1546. ; Region Pointer to a Path
  1547. ;
  1548. ; return status enumeration. 0 = success
  1549.  
  1550. Gdip_FillPath(pGraphics, pBrush, pPath) {
  1551. If (!pGraphics || !pBrush || !pPath)
  1552. Return 2
  1553.  
  1554. Return DllCall("gdiplus\GdipFillPath", "UPtr", pGraphics, "UPtr", pBrush, "UPtr", pPath)
  1555. }
  1556.  
  1557. ;#####################################################################################
  1558.  
  1559. ; Function Gdip_FillClosedCurve
  1560. ; Description This function fills a closed cardinal spline on a pGraphics object
  1561. ; using a pBrush object.
  1562. ; A cardinal spline is a curve that passes through each point in the array.
  1563. ;
  1564. ; pGraphics Pointer to the Graphics of a bitmap
  1565. ; pBrush Pointer to a brush
  1566. ;
  1567. ; Points parameter can be an array or a string with the following format:
  1568. ; Points := "x1,y1|x2,y2|x3,y3|x4,y4" [... and so on]
  1569. ;
  1570. ; Tension Non-negative real number that controls the length of the curve and how the curve bends. A value of
  1571. ; zero specifies that the spline is a sequence of straight lines. As the value increases, the curve becomes fuller.
  1572. ; Number that specifies how tightly the curve bends through the coordinates of the closed cardinal spline.
  1573. ;
  1574. ; Fill mode: 0 - [Alternate] The areas are filled according to the even-odd parity rule
  1575. ; 1 - [Winding] The areas are filled according to the non-zero winding rule
  1576. ;
  1577. ; return status enumeration. 0 = success
  1578.  
  1579. Gdip_FillClosedCurve(pGraphics, pBrush, Points, Tension:="", FillMode:=0) {
  1580. If (!pGraphics || !pBrush || !Points)
  1581. Return 2
  1582.  
  1583. iCount := CreatePointsF(PointsF, Points)
  1584. If IsNumber(Tension)
  1585. Return DllCall("gdiplus\GdipFillClosedCurve2", "UPtr", pGraphics, "UPtr", pBrush, "UPtr", &PointsF, "int", iCount, "float", Tension, "int", FillMode)
  1586. Else
  1587. Return DllCall("gdiplus\GdipFillClosedCurve", "UPtr", pGraphics, "UPtr", pBrush, "UPtr", &PointsF, "int", iCount)
  1588. }
  1589.  
  1590. ;#####################################################################################
  1591.  
  1592. ; Function Gdip_DrawImagePointsRect
  1593. ; Description This function draws a bitmap into the Graphics of another bitmap and skews it
  1594. ;
  1595. ; pGraphics Pointer to the Graphics of a bitmap
  1596. ; pBitmap Pointer to a bitmap to be drawn
  1597. ; Points Points passed as x1,y1|x2,y2|x3,y3 (3 points: top left, top right, bottom left) describing the drawing of the bitmap; it can be an array also
  1598. ; sX, sY x, y coordinates of the source upper-left corner
  1599. ; sW, sH width and height of the source rectangle
  1600. ; Matrix a color matrix used to alter image attributes when drawing
  1601. ; Unit see Gdip_DrawImage()
  1602. ; Return status enumeration. 0 = success
  1603. ;
  1604. ; Notes If sx, sy, sw, sh are omitted the entire source bitmap will be used.
  1605. ; Matrix can be omitted to just draw with no alteration to ARGB.
  1606. ; Matrix may be passed as a digit from 0 - 1 to change just transparency.
  1607. ; Matrix can be passed as a matrix with "|" delimiter.
  1608. ; To generate a color matrix using user-friendly parameters,
  1609. ; use GenerateColorMatrix()
  1610.  
  1611. Gdip_DrawImagePointsRect(pGraphics, pBitmap, Points, sx:="", sy:="", sw:="", sh:="", Matrix:=1, Unit:=2, ImageAttr:=0) {
  1612.  
  1613. iCount := CreatePointsF(PointsF, Points)
  1614. If (iCount!=3)
  1615. Return 2
  1616.  
  1617. If !ImageAttr
  1618. {
  1619. if !IsNumber(Matrix)
  1620. ImageAttr := Gdip_SetImageAttributesColorMatrix(Matrix)
  1621. else if (Matrix != 1)
  1622. ImageAttr := Gdip_SetImageAttributesColorMatrix("1|0|0|0|0|0|1|0|0|0|0|0|1|0|0|0|0|0|" Matrix "|0|0|0|0|0|1")
  1623. } Else usrImageAttr := 1
  1624.  
  1625. if (sx="" && sy="" && sw="" && sh="")
  1626. {
  1627. sx := sy := 0
  1628. Gdip_GetImageDimensions(pBitmap, sw, sh)
  1629. }
  1630.  
  1631. E := DllCall("gdiplus\GdipDrawImagePointsRect"
  1632. , "UPtr", pGraphics
  1633. , "UPtr", pBitmap
  1634. , "UPtr", &PointsF
  1635. , "int", iCount
  1636. , "float", sX, "float", sY
  1637. , "float", sW, "float", sH
  1638. , "int", Unit
  1639. , "UPtr", ImageAttr ? ImageAttr : 0
  1640. , "UPtr", 0, "UPtr", 0)
  1641.  
  1642. If (E=1 && A_LastError=8) ; out of memory
  1643. E := 3
  1644.  
  1645. if (ImageAttr && usrImageAttr!=1)
  1646. Gdip_DisposeImageAttributes(ImageAttr)
  1647.  
  1648. return E
  1649. }
  1650.  
  1651. ;#####################################################################################
  1652.  
  1653. ; Function Gdip_DrawImage
  1654. ; Description This function draws a bitmap into the Graphics of another bitmap
  1655. ; Note The function will fail with images above 536 mgpx, even if these are below 32 bits.
  1656. ;
  1657. ; pGraphics Pointer to the Graphics of a bitmap
  1658. ; pBitmap Pointer to a bitmap to be drawn
  1659. ; dX, dY x, y coordinates of the destination upper-left corner
  1660. ; dW, dH width and height of the destination image
  1661. ; sX, sY x, y coordinates of the source upper-left corner
  1662. ; sW, sH width and height of the source image
  1663. ; Matrix a color matrix used to alter image attributes when drawing
  1664. ; Unit Unit of measurement:
  1665. ; 0 - World coordinates, a nonphysical unit
  1666. ; 1 - Display units
  1667. ; 2 - A unit is 1 pixel
  1668. ; 3 - A unit is 1 point or 1/72 inch
  1669. ; 4 - A unit is 1 inch
  1670. ; 5 - A unit is 1/300 inch
  1671. ; 6 - A unit is 1 millimeter
  1672. ;
  1673. ; return status enumeration. 0 = success
  1674. ;
  1675. ; notes When sx,sy,sw,sh are omitted the entire source bitmap will be used
  1676. ; Gdip_DrawImage performs faster.
  1677. ; Matrix can be omitted to just draw with no alteration to ARGB
  1678. ; Matrix may be passed as a digit from 0.0 - 1.0 to change just transparency
  1679. ; Matrix can be passed as a matrix with "|" as delimiter. For example:
  1680. ; MatrixBright=
  1681. ; (
  1682. ; 1.5 |0 |0 |0 |0
  1683. ; 0 |1.5 |0 |0 |0
  1684. ; 0 |0 |1.5 |0 |0
  1685. ; 0 |0 |0 |1 |0
  1686. ; 0.05 |0.05 |0.05 |0 |1
  1687. ; )
  1688. ;
  1689. ; example color matrix:
  1690. ; MatrixBright = 1.5|0|0|0|0|0|1.5|0|0|0|0|0|1.5|0|0|0|0|0|1|0|0.05|0.05|0.05|0|1
  1691. ; MatrixGreyScale = 0.299|0.299|0.299|0|0|0.587|0.587|0.587|0|0|0.114|0.114|0.114|0|0|0|0|0|1|0|0|0|0|0|1
  1692. ; MatrixNegative = -1|0|0|0|0|0|-1|0|0|0|0|0|-1|0|0|0|0|0|1|0|1|1|1|0|1
  1693. ; To generate a color matrix using user-friendly parameters,
  1694. ; use GenerateColorMatrix()
  1695.  
  1696. Gdip_DrawImage(pGraphics, pBitmap, dx:="", dy:="", dw:="", dh:="", sx:="", sy:="", sw:="", sh:="", Matrix:=1, Unit:=2, ImageAttr:=0) {
  1697. If (!pGraphics || !pBitmap)
  1698. Return 2
  1699.  
  1700. If !ImageAttr
  1701. {
  1702. if !IsNumber(Matrix)
  1703. ImageAttr := Gdip_SetImageAttributesColorMatrix(Matrix)
  1704. else if (Matrix!=1)
  1705. ImageAttr := Gdip_SetImageAttributesColorMatrix("1|0|0|0|0|0|1|0|0|0|0|0|1|0|0|0|0|0|" Matrix "|0|0|0|0|0|1")
  1706. } Else usrImageAttr := 1
  1707.  
  1708. If (dx!="" && dy!="" && dw="" && dh="" && sx="" && sy="" && sw="" && sh="")
  1709. {
  1710. sx := sy := 0
  1711. sw := dw := Gdip_GetImageWidth(pBitmap)
  1712. sh := dh := Gdip_GetImageHeight(pBitmap)
  1713. } Else If (sx="" && sy="" && sw="" && sh="")
  1714. {
  1715. If (dx="" && dy="" && dw="" && dh="")
  1716. {
  1717. sx := dx := 0, sy := dy := 0
  1718. sw := dw := Gdip_GetImageWidth(pBitmap)
  1719. sh := dh := Gdip_GetImageHeight(pBitmap)
  1720. } Else
  1721. {
  1722. sx := sy := 0
  1723. Gdip_GetImageDimensions(pBitmap, sw, sh)
  1724. }
  1725. }
  1726.  
  1727. E := DllCall("gdiplus\GdipDrawImageRectRect"
  1728. , "UPtr", pGraphics
  1729. , "UPtr", pBitmap
  1730. , "float", dX, "float", dY
  1731. , "float", dW, "float", dH
  1732. , "float", sX, "float", sY
  1733. , "float", sW, "float", sH
  1734. , "int", Unit
  1735. , "UPtr", ImageAttr ? ImageAttr : 0
  1736. , "UPtr", 0, "UPtr", 0)
  1737.  
  1738. If (E=1 && A_LastError=8) ; out of memory
  1739. E := 3
  1740.  
  1741. if (ImageAttr && usrImageAttr!=1)
  1742. Gdip_DisposeImageAttributes(ImageAttr)
  1743.  
  1744. return E
  1745. }
  1746.  
  1747. Gdip_DrawImageFast(pGraphics, pBitmap, X:=0, Y:=0) {
  1748. ; This function performs faster than Gdip_DrawImage().
  1749. ; X, Y - the coordinates of the destination upper-left corner
  1750. ; where the pBitmap will be drawn.
  1751.  
  1752. return DllCall("gdiplus\GdipDrawImage"
  1753. , "UPtr", pGraphics
  1754. , "UPtr", pBitmap
  1755. , "float", X
  1756. , "float", Y)
  1757. }
  1758.  
  1759. Gdip_DrawImageRect(pGraphics, pBitmap, X, Y, W, H) {
  1760. ; X, Y - the coordinates of the destination upper-left corner
  1761. ; where the pBitmap will be drawn.
  1762. ; W, H - the width and height of the destination rectangle, where the pBitmap will be drawn.
  1763.  
  1764. return DllCall("gdiplus\GdipDrawImageRect"
  1765. , "UPtr", pGraphics
  1766. , "UPtr", pBitmap
  1767. , "float", X, "float", Y
  1768. , "float", W, "float", H)
  1769. }
  1770.  
  1771. ;#####################################################################################
  1772.  
  1773. ; Function Gdip_SetImageAttributesColorMatrix
  1774. ; Description This function creates an image color matrix ready for drawing if no ImageAttr is given.
  1775. ; It can set or clear the color and/or grayscale-adjustment matrices for a specified ImageAttr object.
  1776. ;
  1777. ; clrMatrix A color-adjustment matrix used to alter image attributes when drawing
  1778. ; passed with "|" as delimeter.
  1779. ; grayMatrix A grayscale-adjustment matrix used to alter image attributes when drawing
  1780. ; passed with "|" as delimeter. This applies only when ColorMatrixFlag=2.
  1781. ;
  1782. ; ColorAdjustType The category for which the color and grayscale-adjustment matrices are set or cleared.
  1783. ; 0 - adjustments apply to all categories that do not have adjustment settings of their own
  1784. ; 1 - adjustments apply to bitmapped images
  1785. ; 2 - adjustments apply to brush operations in metafiles
  1786. ; 3 - adjustments apply to pen operations in metafiles
  1787. ; 4 - adjustments apply to text drawn in metafiles
  1788. ;
  1789. ; fEnable If True, the specified matrices (color, grayscale or both) adjustments for the specified
  1790. ; category are applied; otherwise the category is cleared
  1791. ;
  1792. ; ColorMatrixFlag Type of image and color that will be affected by the adjustment matrices:
  1793. ; 0 - All color values (including grays) are adjusted by the same color-adjustment matrix.
  1794. ; 1 - Colors are adjusted but gray shades are not adjusted.
  1795. ; A gray shade is any color that has the same value for its red, green, and blue components.
  1796. ; 2 - Colors are adjusted by one matrix and gray shades are adjusted by another matrix.
  1797.  
  1798. ; ImageAttr A pointer to an ImageAttributes object.
  1799. ; If this parameter is omitted, a new one is created.
  1800.  
  1801. ; return It return 0 on success, if an ImageAttr object was given,
  1802. ; otherwise, it returns the handle of a new ImageAttr object [if succesful].
  1803. ;
  1804. ; notes MatrixBright = 1.5|0|0|0|0|0|1.5|0|0|0|0|0|1.5|0|0|0|0|0|1|0|0.05|0.05|0.05|0|1
  1805. ; MatrixGreyScale = 0.299|0.299|0.299|0|0|0.587|0.587|0.587|0|0|0.114|0.114|0.114|0|0|0|0|0|1|0|0|0|0|0|1
  1806. ; MatrixNegative = -1|0|0|0|0|0|-1|0|0|0|0|0|-1|0|0|0|0|0|1|0|1|1|1|0|1
  1807. ; To generate a color matrix using user-friendly parameters,
  1808. ; use GenerateColorMatrix()
  1809. ;
  1810. ; additional remarks:
  1811. ; In my tests, it seems that the grayscale matrix is not functioning properly.
  1812. ; Grayscale images are rendered invisible [with zero opacity] for some reason...
  1813. ; TO DO: fix this?
  1814.  
  1815. Gdip_SetImageAttributesColorMatrix(clrMatrix, ImageAttr:=0, grayMatrix:=0, ColorAdjustType:=1, fEnable:=1, ColorMatrixFlag:=0) {
  1816. If (StrLen(clrMatrix)<5 && ImageAttr)
  1817. Return -1
  1818.  
  1819. If (StrLen(clrMatrix)<5) || (ColorMatrixFlag=2 && StrLen(grayMatrix)<5)
  1820. Return
  1821.  
  1822. CreateColourMatrix(clrMatrix, ColourMatrix)
  1823. If (ColorMatrixFlag=2)
  1824. CreateColourMatrix(grayMatrix, GrayscaleMatrix)
  1825.  
  1826. If !ImageAttr
  1827. {
  1828. created := 1
  1829. ImageAttr := Gdip_CreateImageAttributes()
  1830. }
  1831.  
  1832. E := DllCall("gdiplus\GdipSetImageAttributesColorMatrix"
  1833. , "UPtr", ImageAttr
  1834. , "int", ColorAdjustType
  1835. , "int", fEnable
  1836. , "UPtr", &ColourMatrix
  1837. , "UPtr", &GrayscaleMatrix
  1838. , "int", ColorMatrixFlag)
  1839.  
  1840. gdipLastError := E
  1841. E := created=1 ? ImageAttr : E
  1842. return E
  1843. }
  1844.  
  1845. CreateColourMatrix(clrMatrix, ByRef ColourMatrix) {
  1846. VarSetCapacity(ColourMatrix, 100, 0)
  1847. Matrix := RegExReplace(RegExReplace(clrMatrix, "^[^\d-\.]+([\d\.])", "$1", , 1), "[^\d-\.]+", "|")
  1848. Matrix := StrSplit(Matrix, "|")
  1849. Loop 25
  1850. {
  1851. M := (Matrix[A_Index] != "") ? Matrix[A_Index] : Mod(A_Index - 1, 6) ? 0 : 1
  1852. NumPut(M, ColourMatrix, (A_Index - 1)*4, "float")
  1853. }
  1854. }
  1855.  
  1856. Gdip_CreateImageAttributes() {
  1857. ImageAttr := 0
  1858. gdipLastError := DllCall("gdiplus\GdipCreateImageAttributes", "UPtr*", ImageAttr)
  1859. return ImageAttr
  1860. }
  1861.  
  1862. Gdip_CloneImageAttributes(ImageAttr) {
  1863. newImageAttr := 0
  1864. gdipLastError := DllCall("gdiplus\GdipCloneImageAttributes", "UPtr", ImageAttr, "UPtr*", newImageAttr)
  1865. return newImageAttr
  1866. }
  1867.  
  1868. Gdip_SetImageAttributesThreshold(ImageAttr, Threshold, ColorAdjustType:=1, fEnable:=1) {
  1869. ; Sets or clears the threshold (transparency range) for a specified category by ColorAdjustType
  1870. ; The threshold is a value from 0 through 1 that specifies a cutoff point for each color component. For example,
  1871. ; suppose the threshold is set to 0.7, and suppose you are rendering a color whose red, green, and blue
  1872. ; components are 230, 50, and 220. The red component, 230, is greater than 0.7ª255, so the red component will
  1873. ; be changed to 255 (full intensity). The green component, 50, is less than 0.7ª255, so the green component will
  1874. ; be changed to 0. The blue component, 220, is greater than 0.7ª255, so the blue component will be changed to 255.
  1875.  
  1876. return DllCall("gdiplus\GdipSetImageAttributesThreshold", "UPtr", ImageAttr, "int", ColorAdjustType, "int", fEnable, "float", Threshold)
  1877. }
  1878.  
  1879. Gdip_SetImageAttributesResetMatrix(ImageAttr, ColorAdjustType) {
  1880. ; Sets the color-adjustment matrix of a specified category to the identity matrix.
  1881.  
  1882. return DllCall("gdiplus\GdipSetImageAttributesToIdentity", "UPtr", ImageAttr, "int", ColorAdjustType)
  1883. }
  1884.  
  1885. Gdip_SetImageAttributesGamma(ImageAttr, Gamma, ColorAdjustType:=1, fEnable:=1) {
  1886. ; Gamma from 0.1 to 5.0
  1887.  
  1888. return DllCall("gdiplus\GdipSetImageAttributesGamma", "UPtr", ImageAttr, "int", ColorAdjustType, "int", fEnable, "float", Gamma)
  1889. }
  1890.  
  1891. Gdip_SetImageAttributesToggle(ImageAttr, ColorAdjustType, fEnable) {
  1892. ; Turns on or off color adjustment for a specified category defined by ColorAdjustType
  1893. ; fEnable - 0 or 1
  1894. ; ColorAdjustType - The category for which color adjustment is reset:
  1895. ; see Gdip_SetImageAttributesColorMatrix() for details.
  1896.  
  1897. return DllCall("gdiplus\GdipSetImageAttributesNoOp", "UPtr", ImageAttr, "int", ColorAdjustType, "int", fEnable)
  1898. }
  1899.  
  1900. Gdip_SetImageAttributesOutputChannel(ImageAttr, ColorChannelFlags, ColorAdjustType:=1, fEnable:=1) {
  1901. ; ColorChannelFlags - The output channel, can be any combination:
  1902. ; 0 - Cyan color channel
  1903. ; 1 - Magenta color channel
  1904. ; 2 - Yellow color channel
  1905. ; 3 - Black color channel
  1906. ; 4 - The previous selected channel
  1907.  
  1908. return DllCall("gdiplus\GdipSetImageAttributesOutputChannel", "UPtr", ImageAttr, "int", ColorAdjustType, "int", fEnable, "int", ColorChannelFlags)
  1909. }
  1910.  
  1911. Gdip_SetImageAttributesColorKeys(ImageAttr, ARGBLow, ARGBHigh, ColorAdjustType:=1, fEnable:=1) {
  1912. ; initial tests of this function lead to a crash of the application ...
  1913.  
  1914. Return DllCall("gdiplus\GdipSetImageAttributesColorKeys", "UPtr", ImageAttr, "int", ColorAdjustType, "int", fEnable, "uint", ARGBLow, "uint", ARGBHigh)
  1915. }
  1916.  
  1917. Gdip_SetImageAttributesWrapMode(ImageAttr, WrapMode, ARGB:=0) {
  1918. ; ImageAttr - Pointer to an ImageAttribute object
  1919. ; WrapMode - Specifies how repeated copies of an image are used to tile an area:
  1920. ; 0 - Tile - Tiling without flipping
  1921. ; 1 - TileFlipX - Tiles are flipped horizontally as you move from one tile to the next in a row
  1922. ; 2 - TileFlipY - Tiles are flipped vertically as you move from one tile to the next in a column
  1923. ; 3 - TileFlipXY - Tiles are flipped horizontally as you move along a row and flipped vertically as you move along a column
  1924. ; 4 - Clamp - No tiling takes place
  1925. ; ARGB - Alpha, Red, Green and Blue components of the color of pixels outside of a rendered image.
  1926. ; This color is visible if the wrap mode is set to 4 and the source rectangle of the image is greater than the
  1927. ; image itself.
  1928.  
  1929. Return DllCall("gdiplus\GdipSetImageAttributesWrapMode", "UPtr", ImageAttr, "int", WrapMode, "uint", ARGB, "int", 0)
  1930. }
  1931.  
  1932. Gdip_ResetImageAttributes(ImageAttr, ColorAdjustType) {
  1933. ; Clears all color and grayscale-adjustment settings for a specified category defined by ColorAdjustType.
  1934. ;
  1935. ; ImageAttr - a pointer to an ImageAttributes object.
  1936. ; ColorAdjustType - The category for which color adjustment is reset:
  1937. ; see Gdip_SetImageAttributesColorMatrix() for details.
  1938.  
  1939. Return DllCall("gdiplus\GdipResetImageAttributes", "UPtr", ImageAttr, "int", ColorAdjustType)
  1940. }
  1941.  
  1942. ;#####################################################################################
  1943.  
  1944. ; Function Gdip_GraphicsFromImage
  1945. ; Description This function gets the graphics for a bitmap used for drawing functions
  1946. ;
  1947. ; pBitmap Pointer to a bitmap to get the pointer to its graphics
  1948. ;
  1949. ; return Returns a pointer to the graphics of a bitmap
  1950. ;
  1951. ; remarks A bitmap can be drawn into the graphics of another bitmap.
  1952. ; This function will fail with these bitmap pixel formats:
  1953. ; PXF01INDEXED, PXF04INDEXED, PXF16GRAYSCALE
  1954. ; PXF16ARGB1555, PXF64PARGB, PXF32CMYK
  1955. ; See Gdip_GetImagePixelFormat() for more details.
  1956.  
  1957. Gdip_GraphicsFromImage(pBitmap, InterpolationMode:="", SmoothingMode:="", PageUnit:="", CompositingQuality:="") {
  1958. pGraphics := 0
  1959. gdipLastError := DllCall("gdiplus\GdipGetImageGraphicsContext", "UPtr", pBitmap, "UPtr*", pGraphics)
  1960. If (gdipLastError=1 && A_LastError=8) ; out of memory
  1961. gdipLastError := 3
  1962.  
  1963. If (pGraphics!="" && !gdipLastError)
  1964. {
  1965. If (InterpolationMode!="")
  1966. Gdip_SetInterpolationMode(pGraphics, InterpolationMode)
  1967. If (SmoothingMode!="")
  1968. Gdip_SetSmoothingMode(pGraphics, SmoothingMode)
  1969. If (PageUnit!="")
  1970. Gdip_SetPageUnit(pGraphics, PageUnit)
  1971. If (CompositingQuality!="")
  1972. Gdip_SetCompositingQuality(pGraphics, CompositingQuality)
  1973. }
  1974. return pGraphics
  1975. }
  1976.  
  1977. ;#####################################################################################
  1978.  
  1979. ; Function Gdip_GraphicsFromHDC
  1980. ; Description This function gets the graphics from the handle of a device context.
  1981. ;
  1982. ; hDC The handle to the device context.
  1983. ; hDevice Handle to a device that will be associated with the new Graphics object.
  1984. ;
  1985. ; return A pointer to the graphics of a bitmap.
  1986. ;
  1987. ; notes You can draw a bitmap into the graphics of another bitmap.
  1988.  
  1989. Gdip_GraphicsFromHDC(hDC, hDevice:="", InterpolationMode:="", SmoothingMode:="", PageUnit:="", CompositingQuality:="") {
  1990. pGraphics := 0
  1991. If hDevice
  1992. gdipLastError := DllCall("Gdiplus\GdipCreateFromHDC2", "UPtr", hDC, "UPtr", hDevice, "UPtr*", pGraphics)
  1993. Else
  1994. gdipLastError := DllCall("gdiplus\GdipCreateFromHDC", "UPtr", hdc, "UPtr*", pGraphics)
  1995.  
  1996. If (gdipLastError=1 && A_LastError=8) ; out of memory
  1997. gdipLastError := 3
  1998.  
  1999. If (pGraphics!="" && !gdipLastError)
  2000. {
  2001. If (InterpolationMode!="")
  2002. Gdip_SetInterpolationMode(pGraphics, InterpolationMode)
  2003. If (SmoothingMode!="")
  2004. Gdip_SetSmoothingMode(pGraphics, SmoothingMode)
  2005. If (PageUnit!="")
  2006. Gdip_SetPageUnit(pGraphics, PageUnit)
  2007. If (CompositingQuality!="")
  2008. Gdip_SetCompositingQuality(pGraphics, CompositingQuality)
  2009. }
  2010.  
  2011. return pGraphics
  2012. }
  2013.  
  2014. Gdip_GraphicsFromHWND(HWND, useICM:=0, InterpolationMode:="", SmoothingMode:="", PageUnit:="", CompositingQuality:="") {
  2015. ; Creates a pGraphics object that is associated with a specified window handle [HWND]
  2016. ; If useICM=1, the created graphics uses ICM [color management - (International Color Consortium = ICC)].
  2017. pGraphics := 0
  2018. function2call := (useICM=1) ? "ICM" : ""
  2019. gdipLastError := DllCall("gdiplus\GdipCreateFromHWND" function2call, "UPtr", HWND, "UPtr*", pGraphics)
  2020. If (gdipLastError=1 && A_LastError=8) ; out of memory
  2021. gdipLastError := 3
  2022.  
  2023. If (pGraphics!="" && !gdipLastError)
  2024. {
  2025. If (InterpolationMode!="")
  2026. Gdip_SetInterpolationMode(pGraphics, InterpolationMode)
  2027. If (SmoothingMode!="")
  2028. Gdip_SetSmoothingMode(pGraphics, SmoothingMode)
  2029. If (PageUnit!="")
  2030. Gdip_SetPageUnit(pGraphics, PageUnit)
  2031. If (CompositingQuality!="")
  2032. Gdip_SetCompositingQuality(pGraphics, CompositingQuality)
  2033. }
  2034. return pGraphics
  2035. }
  2036.  
  2037. ;#####################################################################################
  2038.  
  2039. ; Function Gdip_GetDC
  2040. ; Description This function gets the device context of the passed Graphics
  2041. ;
  2042. ; hDC This is the handle to the device context
  2043. ;
  2044. ; return returns the device context for the graphics of a bitmap
  2045.  
  2046. Gdip_GetDC(pGraphics) {
  2047. hDC := 0
  2048. gdipLastError := DllCall("gdiplus\GdipGetDC", "UPtr", pGraphics, "UPtr*", hDC)
  2049. return hDC
  2050. }
  2051.  
  2052. ;#####################################################################################
  2053.  
  2054. ; Function Gdip_ReleaseDC
  2055. ; Description This function releases a device context from use for further use
  2056. ;
  2057. ; pGraphics Pointer to the graphics of a bitmap
  2058. ; hdc This is the handle to the device context
  2059. ;
  2060. ; return status enumeration. 0 = success
  2061.  
  2062. Gdip_ReleaseDC(pGraphics, hdc) {
  2063. return DllCall("gdiplus\GdipReleaseDC", "UPtr", pGraphics, "UPtr", hdc)
  2064. }
  2065.  
  2066. ;#####################################################################################
  2067.  
  2068. ; Function Gdip_GraphicsClear
  2069. ; Description Clears the graphics of a bitmap ready for further drawing
  2070. ;
  2071. ; pGraphics Pointer to the graphics of a bitmap
  2072. ; ARGB The colour to clear the graphics to
  2073. ;
  2074. ; return status enumeration. 0 = success
  2075. ;
  2076. ; notes By default this will make the background invisible
  2077. ; Using clipping regions you can clear a particular area on the graphics rather than clearing the entire graphics
  2078.  
  2079. Gdip_GraphicsClear(pGraphics, ARGB:=0x00ffffff) {
  2080. If (pGraphics="")
  2081. return 2
  2082.  
  2083. return DllCall("gdiplus\GdipGraphicsClear", "UPtr", pGraphics, "int", ARGB)
  2084. }
  2085.  
  2086. Gdip_GraphicsFlush(pGraphics, intent) {
  2087. ; intent - Specifies whether the method returns immediately or waits for any existing operations to finish:
  2088. ; 0 - Flush all batched rendering operations and return immediately
  2089. ; 1 - Flush all batched rendering operations and wait for them to complete
  2090. If (pGraphics="")
  2091. return 2
  2092.  
  2093. return DllCall("gdiplus\GdipFlush", "UPtr", pGraphics, "int", intent)
  2094. }
  2095.  
  2096. Gdip_GaussianBlur(pBitmap, radius, fastMode:=0) {
  2097. ; radius between 1 and 255
  2098.  
  2099. Static offsets := {20:18, 19:16, 18:14, 17:12, 16:10, 15:8, 14:6, 13:4, 12:2, 11:1, 10:2, 9:2, 8:2, 7:2, 6:2, 5:2, 4:2, 3:2, 2:1, 1:1, 0:2}
  2100. If (pBitmap="" || radius<2)
  2101. Return 2
  2102.  
  2103. If (radius>255)
  2104. radius := 255
  2105.  
  2106. If (radius>20 || fastMode=1)
  2107. {
  2108. zA := Gdip_CreateEffect(1, radius, 0, 0)
  2109. If zA
  2110. {
  2111. E := Gdip_BitmapApplyEffect(pBitmap, zA)
  2112. Gdip_DisposeEffect(zA)
  2113. }
  2114. Return E
  2115. }
  2116.  
  2117. If offsets[radius]
  2118. radius += offsets[radius]
  2119.  
  2120. zA := Gdip_CreateEffect(1, radius//2, 0, 0)
  2121. zB := Gdip_CreateEffect(1, radius//2, 0, 0)
  2122. Gdip_ImageRotateFlip(pBitmap, 1)
  2123. Gdip_BitmapApplyEffect(pBitmap, zA)
  2124. Gdip_ImageRotateFlip(pBitmap, 3)
  2125. E := Gdip_BitmapApplyEffect(pBitmap, zB)
  2126. Gdip_DisposeEffect(zA)
  2127. Gdip_DisposeEffect(zB)
  2128. Return E
  2129. }
  2130.  
  2131. ;#####################################################################################
  2132.  
  2133. ; Function Gdip_BlurBitmap
  2134. ; Description Gives a pointer to a blurred bitmap from a pointer to a bitmap
  2135. ;
  2136. ; pBitmap Pointer to a bitmap to be blurred
  2137. ; BlurAmount The Amount to blur a bitmap by from 1 (least blur) to 100 (most blur)
  2138. ; usePARGB option to convert to PARGB pixel format
  2139. ; quality option to set resizing quality [0 - 7]; see Gdip_SetInterpolationMode()
  2140. ;
  2141. ; return If the function succeeds, the return value is a pointer to the new blurred bitmap
  2142. ; -1 = The blur parameter is outside the range 1-100
  2143. ;
  2144. ; notes This function will not dispose of the original bitmap
  2145.  
  2146. Gdip_BlurBitmap(pBitmap, BlurAmount, usePARGB:=0, quality:=7, softEdges:=1) {
  2147. ; suggested quality is 6;
  2148. ; quality 7 creates sharpening effect
  2149. ; for higher speed set usePARGB to 1
  2150.  
  2151. If (!pBitmap || !IsNumber(BlurAmount))
  2152. Return
  2153.  
  2154. If (BlurAmount>100)
  2155. BlurAmount := 100
  2156. Else If (BlurAmount<1)
  2157. BlurAmount := 1
  2158.  
  2159. PixelFormat := (usePARGB=1) ? "0xE200B" : "0x26200A"
  2160. Gdip_GetImageDimensions(pBitmap, sWidth, sHeight)
  2161. dWidth := sWidth//BlurAmount
  2162. dHeight := sHeight//BlurAmount
  2163.  
  2164. pBitmap1 := Gdip_CreateBitmap(dWidth, dHeight, PixelFormat)
  2165. If !pBitmap1
  2166. Return
  2167.  
  2168. G1 := Gdip_GraphicsFromImage(pBitmap1, quality)
  2169. If !G1
  2170. {
  2171. Gdip_DisposeImage(pBitmap1, 1)
  2172. Return
  2173. }
  2174.  
  2175. E1 := Gdip_DrawImage(G1, pBitmap, 0, 0, dWidth, dHeight, 0, 0, sWidth, sHeight)
  2176. Gdip_DeleteGraphics(G1)
  2177. If E1
  2178. {
  2179. Gdip_DisposeImage(pBitmap1, 1)
  2180. Return
  2181. }
  2182.  
  2183. If (softEdges=1)
  2184. pBitmap2 := Gdip_CreateBitmap(sWidth, sHeight, PixelFormat)
  2185. Else
  2186. pBitmap2 := Gdip_CloneBitmapArea(pBitmap, 0, 0, sWidth, sHeight, PixelFormat, 0)
  2187.  
  2188. If !pBitmap2
  2189. {
  2190. Gdip_DisposeImage(pBitmap1, 1)
  2191. Return
  2192. }
  2193.  
  2194. G2 := Gdip_GraphicsFromImage(pBitmap2, quality)
  2195. If !G2
  2196. {
  2197. Gdip_DisposeImage(pBitmap1, 1)
  2198. Gdip_DisposeImage(pBitmap2, 1)
  2199. Return
  2200. }
  2201.  
  2202. E2 := Gdip_DrawImage(G2, pBitmap1, 0, 0, sWidth, sHeight, 0, 0, dWidth, dHeight)
  2203. Gdip_DeleteGraphics(G2)
  2204. Gdip_DisposeImage(pBitmap1)
  2205. If E2
  2206. {
  2207. Gdip_DisposeImage(pBitmap2, 1)
  2208. Return
  2209. }
  2210.  
  2211. return pBitmap2
  2212. }
  2213.  
  2214. Gdip_GetImageEncoder(Extension, ByRef pCodec, ByRef ci) {
  2215. ; The function returns the handle to the GDI+ image encoder for the given file extension, if it is available
  2216. ; on error, it returns -1
  2217. ; CI must be a ByRef to not have AHK destroy the struct needed by pCodec.
  2218.  
  2219. Static mimeTypeOffset := 48
  2220. , sizeImageCodecInfo := 76
  2221.  
  2222. nCount := nSize := pCodec := 0
  2223. DllCall("gdiplus\GdipGetImageEncodersSize", "uint*", nCount, "uint*", nSize)
  2224. VarSetCapacity(ci, nSize, 0)
  2225. DllCall("gdiplus\GdipGetImageEncoders", "uint", nCount, "uint", nSize, "UPtr", &ci)
  2226.  
  2227. If !(nCount && nSize)
  2228. {
  2229. ci := ""
  2230. Return -1
  2231. }
  2232.  
  2233. If (A_IsUnicode)
  2234. {
  2235. Loop, % nCount
  2236. {
  2237. idx := (mimeTypeOffset + 7*A_PtrSize) * (A_Index-1)
  2238. sString := StrGet(NumGet(ci, idx + 32 + 3*A_PtrSize), "UTF-16")
  2239. If !InStr(sString, "*" Extension)
  2240. Continue
  2241.  
  2242. pCodec := &ci + idx
  2243. Break
  2244. }
  2245. } Else
  2246. {
  2247. Loop, % nCount
  2248. {
  2249. Location := NumGet(ci, sizeImageCodecInfo*(A_Index-1) + 44)
  2250. nSize := DllCall("WideCharToMultiByte", "uint", 0, "uint", 0, "uint", Location, "int", -1, "uint", 0, "int", 0, "uint", 0, "uint", 0)
  2251. VarSetCapacity(sString, nSize, 0)
  2252. DllCall("WideCharToMultiByte", "uint", 0, "uint", 0, "uint", Location, "int", -1, "str", sString, "int", nSize, "uint", 0, "uint", 0)
  2253. If !InStr(sString, "*" Extension)
  2254. Continue
  2255.  
  2256. pCodec := &ci + sizeImageCodecInfo*(A_Index-1)
  2257. Break
  2258. }
  2259. }
  2260. }
  2261.  
  2262. Gdip_GetImageEncodersList() {
  2263. ; The function returns GDI+ available image encoders, by supported file extensions,
  2264. ; the file extensions are separated by ; [semicolon]
  2265. ; the codecs are separated by `n [new line]
  2266. ; on error, it returns -1
  2267.  
  2268. Static mimeTypeOffset := 48
  2269. , sizeImageCodecInfo := 76
  2270.  
  2271. r := DllCall("gdiplus\GdipGetImageEncodersSize", "uint*", nCount, "uint*", nSize)
  2272. If !r
  2273. {
  2274. VarSetCapacity(ci, nSize)
  2275. r := DllCall("gdiplus\GdipGetImageEncoders", "uint", nCount, "uint", nSize, "UPtr", &ci)
  2276. }
  2277.  
  2278. If !(nCount && nSize)
  2279. Return -1
  2280.  
  2281. encodersList := ""
  2282. If (A_IsUnicode)
  2283. {
  2284. Loop, % nCount
  2285. {
  2286. idx := (mimeTypeOffset + 7*A_PtrSize) * (A_Index-1)
  2287. sString := StrGet(NumGet(ci, idx + 32 + 3*A_PtrSize), "UTF-16")
  2288. If sString
  2289. encodersList .= sString "`n"
  2290. }
  2291. } Else
  2292. {
  2293. Loop, % nCount
  2294. {
  2295. Location := NumGet(ci, sizeImageCodecInfo*(A_Index-1) + 44)
  2296. nSize := DllCall("WideCharToMultiByte", "uint", 0, "uint", 0, "uint", Location, "int", -1, "uint", 0, "int", 0, "uint", 0, "uint", 0)
  2297. VarSetCapacity(sString, nSize, 0)
  2298. DllCall("WideCharToMultiByte", "uint", 0, "uint", 0, "uint", Location, "int", -1, "str", sString, "int", nSize, "uint", 0, "uint", 0)
  2299. If sString
  2300. encodersList .= sString "`n"
  2301. sString := ""
  2302. }
  2303. }
  2304.  
  2305. Return encodersList
  2306. }
  2307.  
  2308. Gdip_SaveAddImage(multiBitmap, newBitmap, params) {
  2309. ; to be used only with TIFF encoder, to create multi-paged TIFFs.
  2310. ; params must be a pointer to an EncoderParameters struct
  2311.  
  2312. Return DllCall("gdiplus\GdipSaveAddImage", "UPtr", multiBitmap, "UPtr", newBitmap, "uint", params)
  2313. }
  2314.  
  2315. Gdip_SaveImagesInTIFF(filesListArray, destFilePath) {
  2316. ; this function is for creating multipaged TIFFs.
  2317.  
  2318. ; filesListArray - a mono-dimensional array, a list of files, full paths and file names
  2319. ; destFilePath - the file to save, complete path, it will be a tiff with multiple pages
  2320. ; return values:
  2321. ; >0 = the number of files that failed to make it into the created .tiff
  2322. ; 0 = complete succes
  2323. ; -1 = failed to initialize the .TIFF encoder
  2324. ; -2 = failed to get the encoder parameters
  2325. ; -3 = failed to create the tiff file ; after the dot, isgdi+ the error code, returned by GdipSaveImageToFile
  2326.  
  2327. Static EncoderParameterValueTypeLong := 4
  2328. , EncoderValueFrameDimensionPage := 23
  2329. , EncoderValueMultiFrame := 18
  2330. , EncoderValueFlush := 20
  2331.  
  2332. rg := Gdip_GetImageEncoder(".tif", pCodec, ci)
  2333. If !pCodec
  2334. rg := Gdip_GetImageEncoder(".tif", pCodec, ci)
  2335. If !pCodec
  2336. rg := Gdip_GetImageEncoder(".tif", pCodec, ci)
  2337.  
  2338. If !pCodec
  2339. Return -1
  2340.  
  2341. failedFiles := countTFilez := 0
  2342. fatalError := _p := elem := selectedFiles := 0
  2343. pad := (A_PtrSize=8) ? 4 : 0
  2344. encoderParameters := 0
  2345. Loop, % filesListArray.count()
  2346. {
  2347. imgPath := filesListArray[A_Index]
  2348. If !imgPath
  2349. Continue
  2350.  
  2351. countTFilez++
  2352. thisBitmap := Gdip_CreateBitmapFromFile(imgPath)
  2353. If StrLen(thisBitmap)<2
  2354. {
  2355. failedFiles++
  2356. Continue
  2357. }
  2358.  
  2359. selectedFiles++
  2360. If (selectedFiles=1)
  2361. {
  2362. multiBitmap := thisBitmap
  2363. nCount := Gdip_GetEncoderParameterList(multiBitmap, pCodec, EncoderParameters)
  2364. If !nCount
  2365. nCount := Gdip_GetEncoderParameterList(multiBitmap, pCodec, EncoderParameters)
  2366.  
  2367. If !nCount
  2368. {
  2369. fatalError := -2
  2370. Break
  2371. }
  2372.  
  2373. Loop, % nCount
  2374. {
  2375. elem := (24+A_PtrSize)*(A_Index-1) + 4 + pad
  2376. If (NumGet(EncoderParameters, elem+16, "UInt") = 1) ; number of values = 1
  2377. && (NumGet(EncoderParameters, elem+20, "UInt") = EncoderParameterValueTypeLong)
  2378. {
  2379. _p := elem + &EncoderParameters - pad - 4
  2380. NumPut(EncoderValueMultiFrame, NumGet(NumPut(4, NumPut(1, _p+0)+20, "UInt")), "UInt")
  2381. Break
  2382. }
  2383. }
  2384.  
  2385. _E := DllCall("gdiplus\GdipSaveImageToFile", "UPtr", multiBitmap, "WStr", destFilePath, "UPtr", pCodec, "uint", _p)
  2386. If _E
  2387. {
  2388. fatalError := "-3." _E
  2389. Break
  2390. }
  2391. } Else
  2392. {
  2393. If (selectedFiles=2)
  2394. NumPut(EncoderValueFrameDimensionPage, NumGet(NumPut(4, NumPut(1, _p+0)+20, "UInt")), "UInt")
  2395.  
  2396. _E := Gdip_SaveAddImage(multiBitmap, thisBitmap, _p)
  2397. If _E
  2398. failedFiles++
  2399.  
  2400. Gdip_DisposeImage(thisBitmap)
  2401. }
  2402. }
  2403.  
  2404. NumPut(EncoderValueFlush, NumGet(NumPut(4, NumPut(1, _p+0)+20, "UInt")), "UInt")
  2405. _E := DllCall("gdiplus\GdipSaveAddImage", "UPtr", multiBitmap, "uint", _p)
  2406. ; this call fails, I do not know why; err-code = 2 ; invalid parameter;
  2407. ; however the file is created succesfully
  2408. Gdip_DisposeImage(multiBitmap)
  2409. encoderParameters := ""
  2410. r := fatalError ? fatalError : failedFiles
  2411. Return r
  2412. }
  2413.  
  2414. Gdip_GetEncoderParameterList(pBitmap, pCodec, ByRef EncoderParameters) {
  2415. nSize := 0
  2416. DllCall("gdiplus\GdipGetEncoderParameterListSize", "UPtr", pBitmap, "UPtr", pCodec, "uint*", nSize)
  2417. VarSetCapacity(EncoderParameters, nSize, 0) ; struct size
  2418. DllCall("gdiplus\GdipGetEncoderParameterList", "UPtr", pBitmap, "UPtr", pCodec, "uint", nSize, "UPtr", &EncoderParameters)
  2419. Return NumGet(EncoderParameters, "UInt") ; number of parameters possible
  2420. }
  2421.  
  2422.  
  2423. ;#####################################################################################
  2424.  
  2425. ; Function: Gdip_SaveBitmapToFile
  2426. ; Description: Saves a bitmap to a file in any supported format onto disk
  2427. ;
  2428. ; pBitmap Pointer to a GDI+ bitmap
  2429. ; sOutput The name of the file that the bitmap will be saved to. Supported extensions and formats: .BMP,.DIB,.RLE,.JPG,.JPEG,.JPE,.JFIF,.GIF,.TIF,.TIFF,.PNG
  2430. ; When using toBase64=1, the file extension will be used to choose the image encoder.
  2431. ;
  2432. ; Quality If saving as jpg (.JPG,.JPEG,.JPE,.JFIF) then quality can be 1-100
  2433. ;
  2434. ; toBase64orStream = 0, saves the image file [this is the default]
  2435. ; toBase64orStream = 1, instead of saving the file to disk, the function will return on success the base64 encoded data.
  2436. ; A "base64" string is the binary image data encoded into text using only 64 characters.
  2437. ; To convert it back into an image use: Gdip_BitmapFromBase64().
  2438. ; toBase64orStream = 2, instead of saving the file to disk, the function will save the image into a newly created memory stream.
  2439. ; On success, the handle of the stream is returned.
  2440. ; To load it again, use Gdip_CreateBitmapFromStream().
  2441. ;
  2442. ; return if toBase64orStream = 1, the function returns the encoded binary data on success.
  2443. ; if toBase64orStream = 2, on success, the function returns a newly created stream handle where the image is saved.
  2444. ; Possible error codes:
  2445. ; 0 = file saved succesfully [only when toBase64orStream=0]
  2446. ; -1 = Extension supplied is not a supported image file format
  2447. ; -2 = Could not get a list of encoders on the system
  2448. ; -3 = Could not find matching encoder for specified file format
  2449. ; -4 = Could not get WideChar name of output file
  2450. ; -5 = Could not save file to disk
  2451. ; -6 = Could not save image to stream [when using toBase64orStream set to 1 or 2]
  2452. ; -7 = Could not convert to base64 [when toBase64orStream=1]
  2453. ; -8 = Could not retrieve and modify the jpeg encoder properties
  2454. ;
  2455. ; notes This function will use the extension supplied from the sOutput parameter to determine the output format
  2456.  
  2457. Gdip_SaveBitmapToFile(pBitmap, sOutput, Quality:=75, toBase64orStream:=0) {
  2458. nCount := nSize := 0
  2459. pStream := hData := ci := 0
  2460. _p := pCodec := 0
  2461.  
  2462. SplitPath sOutput,,, Extension
  2463. If !RegExMatch(Extension, "^(?i:BMP|DIB|RLE|JPG|JPEG|JPE|JFIF|GIF|TIF|TIFF|PNG)$")
  2464. Return -1
  2465.  
  2466. Extension := "." Extension
  2467. r := Gdip_GetImageEncoder(Extension, pCodec, ci)
  2468. If (r=-1)
  2469. Return -2
  2470.  
  2471. If (pCodec="" || pCodec=0)
  2472. Return -3
  2473.  
  2474. If (Quality!=75)
  2475. {
  2476. Quality := (Quality < 0) ? 0 : (Quality > 100) ? 100 : Quality
  2477. If (quality>95 && toBase64=1)
  2478. Quality := 95
  2479.  
  2480. If RegExMatch(Extension, "^\.(?i:JPG|JPEG|JPE|JFIF)$")
  2481. {
  2482. Static EncoderParameterValueTypeLongRange := 6
  2483. If !(nCount := Gdip_GetEncoderParameterList(pBitmap, pCodec, EncoderParameters))
  2484. Return -8
  2485.  
  2486. pad := (A_PtrSize = 8) ? 4 : 0
  2487. Loop, % nCount
  2488. {
  2489. elem := (24+A_PtrSize)*(A_Index-1) + 4 + pad
  2490. If (NumGet(EncoderParameters, elem+16, "UInt") = 1) ; number of values = 1
  2491. && (NumGet(EncoderParameters, elem+20, "UInt") = EncoderParameterValueTypeLongRange)
  2492. {
  2493. ; MsgBox, % "nc=" nCount " | " A_Index
  2494. _p := elem + &EncoderParameters - pad - 4
  2495. NumPut(Quality, NumGet(NumPut(4, NumPut(1, _p+0)+20, "UInt")), "UInt")
  2496. Break
  2497. }
  2498. }
  2499. }
  2500. }
  2501.  
  2502. If (toBase64orStream=1 || toBase64orStream=2)
  2503. {
  2504. ; part of the function extracted from ImagePut by iseahound
  2505. ; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=76301&sid=bfb7c648736849c3c53f08ea6b0b1309
  2506. DllCall("ole32\CreateStreamOnHGlobal", "ptr",0, "int",true, "ptr*",pStream)
  2507. gdipLastError := DllCall("gdiplus\GdipSaveImageToStream", "uptr",pBitmap, "ptr",pStream, "ptr",pCodec, "uint", _p ? _p : 0)
  2508. If gdipLastError
  2509. Return -6
  2510.  
  2511. If (toBase64orStream=2)
  2512. Return pStream
  2513.  
  2514. DllCall("ole32\GetHGlobalFromStream", "ptr",pStream, "uint*",hData)
  2515. pData := DllCall("GlobalLock", "ptr",hData, "ptr")
  2516. nSize := DllCall("GlobalSize", "uint",pData)
  2517.  
  2518. VarSetCapacity(bin, nSize, 0)
  2519. DllCall("RtlMoveMemory", "ptr",&bin, "ptr",pData, "uptr",nSize)
  2520. DllCall("GlobalUnlock", "ptr",hData)
  2521. ObjRelease(pStream)
  2522. DllCall("GlobalFree", "ptr",hData)
  2523.  
  2524. ; Using CryptBinaryToStringA saves about 2MB in memory.
  2525. DllCall("Crypt32.dll\CryptBinaryToStringA", "ptr",&bin, "uint",nSize, "uint",0x40000001, "ptr",0, "uint*",base64Length)
  2526. VarSetCapacity(base64, base64Length, 0)
  2527. _E := DllCall("Crypt32.dll\CryptBinaryToStringA", "ptr",&bin, "uint",nSize, "uint",0x40000001, "ptr",&base64, "uint*",base64Length)
  2528. If !_E
  2529. Return -7
  2530.  
  2531. VarSetCapacity(bin, 0)
  2532. Return StrGet(&base64, base64Length, "CP0")
  2533. }
  2534.  
  2535. _E := DllCall("gdiplus\GdipSaveImageToFile", "UPtr", pBitmap, "WStr", sOutput, "UPtr", pCodec, "uint", _p ? _p : 0)
  2536. ; msgbox, % "lol`nr=" r "`npC=" pCodec "`n" extension "`n" sOutput "`nerr=" _E
  2537. gdipLastError := _E
  2538. Return _E ? -5 : 0
  2539. }
  2540.  
  2541.  
  2542. ;#####################################################################################
  2543.  
  2544. ; Function: Gdip_SaveBitmapToStream
  2545. ; Description: Saves the provided pBitmap to a newly created memory stream.
  2546. ;
  2547. ; pBitmap The handle of a GDI+ image object
  2548. ; Format The format or encoder to use. Supported extensions and formats: BMP, DIB, RLE, JPG, JPEG, JPE, JFIF, GIF, TIF, TIFF, PNG
  2549. ; Quality If saving as jpg (.JPG,.JPEG,.JPE,.JFIF) then quality can be 1-100
  2550. ;
  2551. ; return If the function succeeds, the handle to the memory stream is returned. otherwise:
  2552. ; -1 = Extension supplied is not a supported image file encoder
  2553. ; -2 = Could not get a list of encoders on system
  2554. ; -3 = Could not find matching encoder for specified file format
  2555. ; -6 = Could not save image to stream
  2556.  
  2557. Gdip_SaveBitmapToStream(pBitmap, Format, Quality:=90) {
  2558. Format := "none." Format
  2559. Return Gdip_SaveBitmapToFile(pBitmap, Format, Quality, 2)
  2560. }
  2561.  
  2562. Gdip_CreateStreamOnFile(sFile, accessMode:="rw") {
  2563. ; function by MCL
  2564. access := (0
  2565. | ((access ~= "[rR]") ? 0x80000000 : 0)
  2566. | ((access ~= "[wW]") ? 0x40000000 : 0) )
  2567.  
  2568. streamPtr := 0
  2569. gdipLastError := DllCall("gdiplus\GdipCreateStreamOnFile", "WStr", sFile, "UInt", accessMode, "Ptr*", streamPtr)
  2570. Return streamPtr
  2571. }
  2572.  
  2573. ;#####################################################################################
  2574.  
  2575. ; Function Gdip_GetPixel
  2576. ; Description Gets the ARGB of a pixel in a bitmap
  2577. ;
  2578. ; pBitmap Pointer to a bitmap
  2579. ; x, y x, y coordinates of the pixel
  2580. ;
  2581. ; return Returns the ARGB value of the pixel
  2582.  
  2583. Gdip_GetPixel(pBitmap, x, y) {
  2584. ARGB := ""
  2585. gdipLastError := DllCall("gdiplus\GdipBitmapGetPixel", "UPtr", pBitmap, "int", x, "int", y, "uint*", ARGB)
  2586. Return ARGB
  2587. ; should use Format("{1:#x}", ARGB)
  2588. }
  2589.  
  2590. Gdip_GetPixelColor(pBitmap, x, y, Format) {
  2591. ARGBdec := Gdip_GetPixel(pBitmap, x, y)
  2592. If (ARGBdec="")
  2593. Return
  2594.  
  2595. If (format=1) ; in ARGB [HEX; 00-FF] with 0x prefix
  2596. {
  2597. Return Format("{1:#x}", ARGBdec)
  2598. } Else If (format=2) ; in RGBA [0-255], returns an object
  2599. {
  2600. Gdip_FromARGB(ARGBdec, A, R, G, B)
  2601. Return [R, G, B, A]
  2602. } Else If (format=3) ; in BGR [HEX; 00-FF] with 0x prefix
  2603. {
  2604. clr := Format("{1:#x}", ARGBdec)
  2605. Return "0x" SubStr(clr, -1) SubStr(clr, 7, 2) SubStr(clr, 5, 2)
  2606. } Else If (format=4) ; in RGB [HEX; 00-FF] with no prefix
  2607. {
  2608. Return SubStr(Format("{1:#x}", ARGBdec), 5)
  2609. } Else Return ARGBdec
  2610. }
  2611.  
  2612. ;#####################################################################################
  2613.  
  2614. ; Function Gdip_SetPixel
  2615. ; Description Sets the ARGB of a pixel in a bitmap
  2616. ;
  2617. ; pBitmap Pointer to a bitmap
  2618. ; x, y x, y coordinates of the pixel
  2619. ;
  2620. ; return status enumeration. 0 = success
  2621.  
  2622. Gdip_SetPixel(pBitmap, x, y, ARGB) {
  2623. return DllCall("gdiplus\GdipBitmapSetPixel", "UPtr", pBitmap, "int", x, "int", y, "int", ARGB)
  2624. }
  2625.  
  2626. ;#####################################################################################
  2627.  
  2628. ; Function Gdip_GetImageWidth
  2629. ; Description Gives the width of a bitmap
  2630. ;
  2631. ; pBitmap Pointer to a bitmap
  2632. ;
  2633. ; return Returns the width in pixels of the supplied bitmap
  2634.  
  2635. Gdip_GetImageWidth(pBitmap) {
  2636. Width := 0
  2637. gdipLastError := DllCall("gdiplus\GdipGetImageWidth", "UPtr", pBitmap, "uint*", Width)
  2638. return Width
  2639. }
  2640.  
  2641. ;#####################################################################################
  2642.  
  2643. ; Function Gdip_GetImageHeight
  2644. ; Description Gives the height of a bitmap
  2645. ;
  2646. ; pBitmap Pointer to a bitmap
  2647. ;
  2648. ; return Returns the height in pixels of the supplied bitmap
  2649.  
  2650. Gdip_GetImageHeight(pBitmap) {
  2651. Height := 0
  2652. gdipLastError := DllCall("gdiplus\GdipGetImageHeight", "UPtr", pBitmap, "uint*", Height)
  2653. return Height
  2654. }
  2655.  
  2656. ;#####################################################################################
  2657.  
  2658. ; Function Gdip_GetImageDimensions
  2659. ; Description Gives the width and height of a bitmap
  2660. ;
  2661. ; pBitmap Pointer to a bitmap
  2662. ; Width ByRef variable. This variable will be set to the width of the bitmap
  2663. ; Height ByRef variable. This variable will be set to the height of the bitmap
  2664. ;
  2665. ; return GDI+ status enumeration return value
  2666.  
  2667. Gdip_GetImageDimensions(pBitmap, ByRef Width, ByRef Height) {
  2668. Width := 0, Height := 0
  2669. If StrLen(pBitmap)<3
  2670. Return 2
  2671.  
  2672. E := Gdip_GetImageDimension(pBitmap, Width, Height)
  2673. Width := Round(Width)
  2674. Height := Round(Height)
  2675. return E
  2676. }
  2677.  
  2678. Gdip_GetImageDimension(pBitmap, ByRef w, ByRef h) {
  2679. w := 0, h := 0
  2680. If !pBitmap
  2681. Return 2
  2682.  
  2683. return DllCall("gdiplus\GdipGetImageDimension", "UPtr", pBitmap, "float*", w, "float*", h)
  2684. }
  2685.  
  2686. Gdip_GetImageBounds(pBitmap) {
  2687. If !pBitmap
  2688. Return 2
  2689.  
  2690. VarSetCapacity(RectF, 16, 0)
  2691. E := DllCall("gdiplus\GdipGetImageBounds", "UPtr", pBitmap, "UPtr", &RectF, "Int*", 0)
  2692. If !E
  2693. Return RetrieveRectF(RectF)
  2694. Else
  2695. Return E
  2696. }
  2697.  
  2698. Gdip_GetImageFlags(pBitmap) {
  2699. ; Gets a set of flags that indicate certain attributes of this Image object.
  2700. ; Returns an element of the ImageFlags Enumeration that holds a set of single-bit flags.
  2701. ; ImageFlags enumeration
  2702. ; None := 0x0000 ; Specifies no format information.
  2703. ; ; Low-word: shared with SINKFLAG_x:
  2704. ; Scalable := 0x00001 ; the image can be scaled.
  2705. ; HasAlpha := 0x00002 ; the pixel data contains alpha values.
  2706. ; HasTranslucent := 0x00004 ; the pixel data has alpha values other than 0 (transparent) and 255 (opaque).
  2707. ; PartiallyScalable := 0x00008 ; the pixel data is partially scalable with some limitations.
  2708. ; ; Low-word: color space definition:
  2709. ; ColorSpaceRGB := 0x00010 ; the image is stored using an RGB color space.
  2710. ; ColorSpaceCMYK := 0x00020 ; the image is stored using a CMYK color space.
  2711. ; ColorSpaceGRAY := 0x00040 ; the image is a grayscale image.
  2712. ; ColorSpaceYCBCR := 0x00080 ; the image is stored using a YCBCR color space.
  2713. ; ColorSpaceYCCK := 0x00100 ; the image is stored using a YCCK color space.
  2714. ; ; Low-word: image size info:
  2715. ; HasRealDPI := 0x01000 ; dots per inch information is stored in the image.
  2716. ; HasRealPixelSize := 0x02000 ; the pixel size is stored in the image.
  2717. ; ; High-word:
  2718. ; ReadOnly := 0x10000 ; the pixel data is read-only.
  2719. ; Caching := 0x20000 ; the pixel data can be cached for faster access.
  2720. ; function extracted from : https://github.com/flipeador/Library-AutoHotkey/tree/master/graphics
  2721. ; by flipeador
  2722.  
  2723. Flags := 0
  2724. gdipLastError := DllCall("gdiplus\GdipGetImageFlags", "UPtr", pBitmap, "UInt*", Flags)
  2725. Return Flags
  2726. }
  2727.  
  2728. Gdip_GetImageRawFormat(pBitmap) {
  2729. ; retrieves the pBitmap [file] format
  2730.  
  2731. Static RawFormatsList := {"{B96B3CA9-0728-11D3-9D7B-0000F81EF32E}":"Undefined", "{B96B3CAA-0728-11D3-9D7B-0000F81EF32E}":"MemoryBMP", "{B96B3CAB-0728-11D3-9D7B-0000F81EF32E}":"BMP", "{B96B3CAC-0728-11D3-9D7B-0000F81EF32E}":"EMF", "{B96B3CAD-0728-11D3-9D7B-0000F81EF32E}":"WMF", "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}":"JPEG", "{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}":"PNG", "{B96B3CB0-0728-11D3-9D7B-0000F81EF32E}":"GIF", "{B96B3CB1-0728-11D3-9D7B-0000F81EF32E}":"TIFF", "{B96B3CB2-0728-11D3-9D7B-0000F81EF32E}":"EXIF", "{B96B3CB5-0728-11D3-9D7B-0000F81EF32E}":"Icon"}
  2732. ; DEFINE_GUID(ImageFormatHEIF, 0xb96b3cb6,0x0728,0x11d3,0x9d,0x7b,0x00,0x00,0xf8,0x1e,0xf3,0x2e);
  2733. ; DEFINE_GUID(ImageFormatWEBP, 0xb96b3cb7,0x0728,0x11d3,0x9d,0x7b,0x00,0x00,0xf8,0x1e,0xf3,0x2e);
  2734. If (pBitmap="")
  2735. Return
  2736.  
  2737. VarSetCapacity(pGuid, 16, 0)
  2738. gdipLastError := DllCall("gdiplus\GdipGetImageRawFormat", "UPtr", pBitmap, "UPtr", &pGuid)
  2739.  
  2740. size := VarSetCapacity(sguid, (38 << !!A_IsUnicode) + 1, 0)
  2741. E2 := DllCall("ole32.dll\StringFromGUID2", "uptr", &pguid, "uptr", &sguid, "int", size)
  2742. R1 := E2 ? StrGet(&sguid) : E2
  2743. R2 := RawFormatsList[R1]
  2744. sguid := "" , pGuid := ""
  2745. Return R2 ? R2 : R1
  2746. }
  2747.  
  2748. Gdip_GetImagePixelFormat(pBitmap, mode:=0) {
  2749. ; Mode options
  2750. ; 0 - in decimal
  2751. ; 1 - in hex
  2752. ; 2 - in human readable format
  2753. ;
  2754. ; *PXF01INDEXED = 0x00030101 ; 1 bpp, indexed
  2755. ; *PXF04INDEXED = 0x00030402 ; 4 bpp, indexed
  2756. ; PXF08INDEXED = 0x00030803 ; 8 bpp, indexed
  2757. ; *PXF16GRAYSCALE = 0x00101004; 16 bpp, grayscale
  2758. ; PXF16RGB555 = 0x00021005 ; 16 bpp; 5 bits for each RGB
  2759. ; PXF16RGB565 = 0x00021006 ; 16 bpp; 5 bits red, 6 bits green, and 5 bits blue
  2760. ; *PXF16ARGB1555 = 0x00061007 ; 16 bpp; 1 bit for alpha and 5 bits for each RGB component
  2761. ; PXF24RGB = 0x00021808 ; 24 bpp; 8 bits for each RGB
  2762. ; PXF32RGB = 0x00022009 ; 32 bpp; 8 bits for each RGB, no alpha.
  2763. ; PXF32ARGB = 0x0026200A ; 32 bpp; 8 bits for each RGB and alpha
  2764. ; PXF32PARGB = 0x000E200B ; 32 bpp; 8 bits for each RGB and alpha, pre-mulitiplied
  2765. ; PXF48RGB = 0x0010300C ; 48 bpp; 16 bits for each RGB
  2766. ; PXF64ARGB = 0x0034400D ; 64 bpp; 16 bits for each RGB and alpha
  2767. ; *PXF64PARGB = 0x001A400E ; 64 bpp; 16 bits for each RGB and alpha, pre-multiplied
  2768. ; *PXF32CMYK = 0x200F ; 32 bpp; CMYK
  2769.  
  2770. ; *NOTE: GDI+ does not fully support the formats marked with an asterisk (*).
  2771. ; Gdip_GraphicsFromImage() will fail on bitmaps with these pixel formats.
  2772.  
  2773. ; INDEXED [1-bits, 4-bits and 8-bits] pixel formats rely on color palettes.
  2774. ; The color information for the pixels is stored in palettes.
  2775. ; Indexed images always contain a palette - a special table of colors.
  2776. ; Each pixel is an index in this table. Usually a palette contains 256
  2777. ; or less entries. That's why the maximum depth of an indexed pixel is 8 bpp.
  2778. ; Using palettes is a common practice when working with small color depths.
  2779.  
  2780. ; modified by Marius Șucan
  2781.  
  2782. Static PixelFormatsList := {0x30101:"1-INDEXED", 0x30402:"4-INDEXED", 0x30803:"8-INDEXED", 0x101004:"16-GRAYSCALE", 0x021005:"16-RGB555", 0x21006:"16-RGB565", 0x61007:"16-ARGB1555", 0x21808:"24-RGB", 0x22009:"32-RGB", 0x26200A:"32-ARGB", 0xE200B:"32-PARGB", 0x10300C:"48-RGB", 0x34400D:"64-ARGB", 0x1A400E:"64-PARGB", 0x200f:"32-CMYK"}
  2783. PixelFormat := 0
  2784. gdipLastError := DllCall("gdiplus\GdipGetImagePixelFormat", "UPtr", pBitmap, "UPtr*", PixelFormat)
  2785. If gdipLastError
  2786. Return -1
  2787.  
  2788. If (mode=0)
  2789. Return PixelFormat
  2790.  
  2791. inHEX := Format("{1:#x}", PixelFormat)
  2792. If (PixelFormatsList.Haskey(inHEX) && mode=2)
  2793. result := PixelFormatsList[inHEX]
  2794. Else
  2795. result := inHEX
  2796. return result
  2797. }
  2798.  
  2799. Gdip_GetImageType(pBitmap) {
  2800. ; RETURN VALUES:
  2801. ; UNKNOWN = 0
  2802. ; BITMAP = 1
  2803. ; METAFILE = 2
  2804. ; ERROR = -1
  2805.  
  2806. result := 0
  2807. gdipLastError := DllCall("gdiplus\GdipGetImageType", "UPtr", pBitmap, "int*", result)
  2808. If gdipLastError
  2809. Return -1
  2810. Return result
  2811. }
  2812.  
  2813. Gdip_GetDPI(pGraphics, ByRef DpiX, ByRef DpiY) {
  2814. DpiX := Gdip_GetDpiX(pGraphics)
  2815. DpiY := Gdip_GetDpiY(pGraphics)
  2816. }
  2817.  
  2818. Gdip_GetDpiX(pGraphics) {
  2819. dpix := 0
  2820. gdipLastError := DllCall("gdiplus\GdipGetDpiX", "UPtr", pGraphics, "float*", dpix)
  2821. return Round(dpix)
  2822. }
  2823.  
  2824. Gdip_GetDpiY(pGraphics) {
  2825. dpiy := 0
  2826. gdipLastError := DllCall("gdiplus\GdipGetDpiY", "UPtr", pGraphics, "float*", dpiy)
  2827. return Round(dpiy)
  2828. }
  2829.  
  2830. Gdip_GetImageHorizontalResolution(pBitmap) {
  2831. dpix := 0
  2832. gdipLastError := DllCall("gdiplus\GdipGetImageHorizontalResolution", "UPtr", pBitmap, "float*", dpix)
  2833. return Round(dpix)
  2834. }
  2835.  
  2836. Gdip_GetImageVerticalResolution(pBitmap) {
  2837. dpiy := 0
  2838. gdipLastError := DllCall("gdiplus\GdipGetImageVerticalResolution", "UPtr", pBitmap, "float*", dpiy)
  2839. return Round(dpiy)
  2840. }
  2841.  
  2842. Gdip_BitmapSetResolution(pBitmap, dpix, dpiy) {
  2843. return DllCall("gdiplus\GdipBitmapSetResolution", "UPtr", pBitmap, "float", dpix, "float", dpiy)
  2844. }
  2845.  
  2846. Gdip_BitmapGetDPIResolution(pBitmap, ByRef dpix, ByRef dpiy) {
  2847. dpix := dpiy := 0
  2848. If StrLen(pBitmap)<3
  2849. Return 2
  2850.  
  2851. dpix := Gdip_GetImageHorizontalResolution(pBitmap)
  2852. dpiy := Gdip_GetImageVerticalResolution(pBitmap)
  2853. }
  2854.  
  2855. Gdip_CreateBitmapFromGraphics(pGraphics, Width, Height) {
  2856. pBitmap := 0
  2857. gdipLastError := DllCall("gdiplus\GdipCreateBitmapFromGraphics", "int", Width, "int", Height, "UPtr", pGraphics, "UPtr*", pBitmap)
  2858. Return pBitmap
  2859. }
  2860.  
  2861. Gdip_CreateBitmapFromFile(sFile, IconNumber:=1, IconSize:="", useICM:=0) {
  2862. pBitmap := 0, pBitmapOld := 0, hIcon := 0
  2863. SplitPath sFile,,, Extension
  2864. if RegExMatch(Extension, "^(?i:exe|dll)$")
  2865. {
  2866. Sizes := IconSize ? IconSize : 256 "|" 128 "|" 64 "|" 48 "|" 32 "|" 16
  2867. BufSize := 16 + (2*A_PtrSize)
  2868.  
  2869. VarSetCapacity(buf, BufSize, 0)
  2870. For eachSize, Size in StrSplit( Sizes, "|" )
  2871. {
  2872. DllCall("PrivateExtractIcons", "str", sFile, "int", IconNumber-1, "int", Size, "int", Size, "UPtr*", hIcon, "UPtr*", 0, "uint", 1, "uint", 0)
  2873. if !hIcon
  2874. continue
  2875.  
  2876. if !DllCall("GetIconInfo", "UPtr", hIcon, "UPtr", &buf)
  2877. {
  2878. DestroyIcon(hIcon)
  2879. continue
  2880. }
  2881.  
  2882. ; hbmMask := NumGet(buf, 12 + (A_PtrSize - 4))
  2883. hbmColor := NumGet(buf, 12 + (A_PtrSize - 4) + A_PtrSize)
  2884. if !(hbmColor && DllCall("GetObject", "UPtr", hbmColor, "int", BufSize, "UPtr", &buf))
  2885. {
  2886. DestroyIcon(hIcon)
  2887. continue
  2888. }
  2889. break
  2890. }
  2891. if !hIcon
  2892. return -1
  2893.  
  2894. Width := NumGet(buf, 4, "int")
  2895. Height := NumGet(buf, 8, "int")
  2896. hbm := CreateDIBSection(Width, -Height)
  2897. hdc := CreateCompatibleDC()
  2898. obm := SelectObject(hdc, hbm)
  2899. if !DllCall("DrawIconEx", "UPtr", hdc, "int", 0, "int", 0, "UPtr", hIcon, "uint", Width, "uint", Height, "uint", 0, "UPtr", 0, "uint", 3)
  2900. {
  2901. SelectObject(hdc, obm)
  2902. DeleteObject(hbm)
  2903. DeleteDC(hdc)
  2904. DestroyIcon(hIcon)
  2905. buf := ""
  2906. return -2
  2907. }
  2908.  
  2909. VarSetCapacity(dib, 104, 0)
  2910. DllCall("GetObject", "UPtr", hbm, "int", A_PtrSize = 8 ? 104 : 84, "UPtr", &dib) ; sizeof(DIBSECTION) = 76+2*(A_PtrSize=8?4:0)+2*A_PtrSize
  2911. Stride := NumGet(dib, 12, "Int")
  2912. Bits := NumGet(dib, 20 + (A_PtrSize = 8 ? 4 : 0), "Int") ; padding
  2913. pBitmapOld := Gdip_CreateBitmap(Width, Height, 0, Stride, Bits)
  2914. pBitmap := Gdip_CreateBitmap(Width, Height)
  2915. _G := Gdip_GraphicsFromImage(pBitmap)
  2916. Gdip_DrawImage(_G, pBitmapOld, 0, 0, Width, Height, 0, 0, Width, Height)
  2917. SelectObject(hdc, obm)
  2918. DeleteObject(hbm)
  2919. DeleteDC(hdc)
  2920. Gdip_DeleteGraphics(_G)
  2921. Gdip_DisposeImage(pBitmapOld)
  2922. DestroyIcon(hIcon)
  2923. dib := "", buf := ""
  2924. } else
  2925. {
  2926. function2call := (useICM=1) ? "ICM" : ""
  2927. gdipLastError := DllCall("gdiplus\GdipCreateBitmapFromFile" function2call, "WStr", sFile, "UPtr*", pBitmap)
  2928. }
  2929.  
  2930. return pBitmap
  2931. }
  2932.  
  2933. Gdip_CreateBitmapFromFileSimplified(sFile, useICM:=0) {
  2934. pBitmap := 0
  2935. function2call := (useICM=1) ? "ICM" : ""
  2936. gdipLastError := DllCall("gdiplus\GdipCreateBitmapFromFile" function2call, "WStr", sFile, "UPtr*", pBitmap)
  2937. return pBitmap
  2938. }
  2939.  
  2940. Gdip_CreateARGBBitmapFromHBITMAP(hImage) {
  2941. ; function by iseahound found on:
  2942. ; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=63345
  2943. ; part of https://github.com/iseahound/Graphics/blob/master/lib/Graphics.ahk
  2944. If (hImage="")
  2945. Return
  2946.  
  2947. ; struct BITMAP - https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/ns-wingdi-tagbitmap
  2948. E := DllCall("GetObject", "uptr", hImage
  2949. , "int", VarSetCapacity(dib, 76+2*(A_PtrSize=8?4:0)+2*A_PtrSize)
  2950. , "uptr", &dib) ; sizeof(DIBSECTION) = x86:84, x64:104
  2951. If !E
  2952. Return
  2953.  
  2954. width := NumGet(dib, 4, "uint")
  2955. height := NumGet(dib, 8, "uint")
  2956. bpp := NumGet(dib, 18, "ushort")
  2957.  
  2958. ; Fallback to built-in method if pixels are not ARGB.
  2959. if (bpp!=32)
  2960. return Gdip_CreateBitmapFromHBITMAP(hImage)
  2961.  
  2962. ; Create a handle to a device context and associate the hImage.
  2963. hdc := CreateCompatibleDC()
  2964. If !hdc
  2965. Return
  2966.  
  2967. obm := SelectObject(hdc, hImage)
  2968. ; Buffer the hImage with a top-down device independent bitmap via negative height.
  2969. ; Note that a DIB is an hBitmap, pixels are formatted as pARGB, and has a pointer to the bits.
  2970. cdc := CreateCompatibleDC(hdc)
  2971. If !cdc
  2972. {
  2973. SelectObject(hdc, obm), DeleteDC(hdc)
  2974. Return
  2975. }
  2976.  
  2977. hbm := CreateDIBSection(width, -height, hdc, 32, pBits)
  2978. If !hbm
  2979. {
  2980. DeleteDC(cdc), SelectObject(hdc, obm), DeleteDC(hdc)
  2981. Return
  2982. }
  2983.  
  2984. ob2 := SelectObject(cdc, hbm)
  2985. ; Create a new Bitmap (different from an hBitmap) which holds ARGB pixel values.
  2986. pBitmap := Gdip_CreateBitmap(width, height)
  2987. If !pBitmap
  2988. {
  2989. SelectObject(cdc, ob2)
  2990. DeleteObject(hbm), DeleteDC(cdc)
  2991. SelectObject(hdc, obm), DeleteDC(hdc)
  2992. Return
  2993. }
  2994.  
  2995. ; Create a Scan0 buffer pointing to pBits. The buffer has pixel format pARGB.
  2996. CreateRectF(Rect, 0, 0, width, height, "uint")
  2997. VarSetCapacity(BitmapData, 16+2*A_PtrSize, 0)
  2998. , NumPut( width, BitmapData, 0, "uint") ; Width
  2999. , NumPut( height, BitmapData, 4, "uint") ; Height
  3000. , NumPut( 4 * width, BitmapData, 8, "int") ; Stride
  3001. , NumPut( 0xE200B, BitmapData, 12, "int") ; PixelFormat
  3002. , NumPut( pBits, BitmapData, 16, "uptr") ; Scan0
  3003.  
  3004. E := DllCall("gdiplus\GdipBitmapLockBits"
  3005. , "uptr", pBitmap
  3006. , "uptr", &Rect
  3007. , "uint", 6 ; ImageLockMode.UserInputBuffer | ImageLockMode.WriteOnly
  3008. , "int", 0xE200B ; Format32bppPArgb
  3009. , "uptr", &BitmapData)
  3010.  
  3011. ; Ensure that our hBitmap (hImage) is top-down by copying it to a top-down bitmap.
  3012. BitBlt(cdc, 0, 0, width, height, hdc, 0, 0)
  3013.  
  3014. ; Convert the pARGB pixels copied into the device independent bitmap (hbm) to ARGB.
  3015. If !E
  3016. DllCall("gdiplus\GdipBitmapUnlockBits", "uptr",pBitmap, "uptr",&BitmapData)
  3017.  
  3018. ; Cleanup the buffer and device contexts.
  3019. SelectObject(cdc, ob2)
  3020. DeleteObject(hbm), DeleteDC(cdc)
  3021. SelectObject(hdc, obm), DeleteDC(hdc)
  3022.  
  3023. return pBitmap
  3024. }
  3025.  
  3026. Gdip_CreateBitmapFromHBITMAP(hBitmap, hPalette:=0) {
  3027. ; Creates a Bitmap GDI+ object from a GDI [DIB] bitmap handle.
  3028. ; hPalette - Handle to a GDI palette used to define the bitmap colors
  3029.  
  3030. ; Do not pass to this function a GDI bitmap or a GDI palette that is
  3031. ; currently is selected into a device context [hDC].
  3032.  
  3033. pBitmap := 0
  3034. If !hBitmap
  3035. {
  3036. gdipLastError := 2
  3037. Return
  3038. }
  3039.  
  3040. gdipLastError := DllCall("gdiplus\GdipCreateBitmapFromHBITMAP", "UPtr", hBitmap, "UPtr", hPalette, "UPtr*", pBitmap)
  3041. return pBitmap
  3042. }
  3043.  
  3044. Gdip_CreateHBITMAPFromBitmap(pBitmap, Background:=0xffffffff) {
  3045. ; background should be zero, to not alter alpha channel of the image
  3046. hBitmap := 0
  3047. If !pBitmap
  3048. {
  3049. gdipLastError := 2
  3050. Return
  3051. }
  3052.  
  3053. gdipLastError := DllCall("gdiplus\GdipCreateHBITMAPFromBitmap", "UPtr", pBitmap, "UPtr*", hBitmap, "int", Background)
  3054. return hBitmap
  3055. }
  3056.  
  3057. Gdip_CreateARGBHBITMAPFromBitmap(ByRef pBitmap) {
  3058. ; function by iseahound ; source: https://github.com/mmikeww/AHKv2-Gdip
  3059. ; modified by Marius Șucan to rely on already present functions [within the library]
  3060. ; and improved error handling
  3061.  
  3062. ; Convert the source pBitmap into a hBitmap manually.
  3063. ; This version is about 25% faster than Gdip_CreateHBITMAPFromBitmap().
  3064. ; struct BITMAPINFOHEADER - https://docs.microsoft.com/en-us/windows/win32/api/wingdi/ns-wingdi-bitmapinfoheader
  3065.  
  3066. If !pBitmap
  3067. Return
  3068.  
  3069. hdc := CreateCompatibleDC()
  3070. If !hdc
  3071. Return
  3072.  
  3073. Gdip_GetImageDimensions(pBitmap, Width, Height)
  3074. hbm := CreateDIBSection(width, -height, hdc, 32, pBits)
  3075. If !hbm
  3076. {
  3077. DeleteObject(hdc)
  3078. Return
  3079. }
  3080.  
  3081. obm := SelectObject(hdc, hbm)
  3082. ; Transfer data from source pBitmap to an hBitmap manually.
  3083. CreateRectF(Rect, 0, 0, width, height, "uint")
  3084. VarSetCapacity(BitmapData, 16+2*A_PtrSize, 0) ; sizeof(BitmapData) = 24, 32
  3085. , NumPut( width, BitmapData, 0, "uint") ; Width
  3086. , NumPut( height, BitmapData, 4, "uint") ; Height
  3087. , NumPut( 4 * width, BitmapData, 8, "int") ; Stride
  3088. , NumPut( 0xE200B, BitmapData, 12, "int") ; PixelFormat
  3089. , NumPut( pBits, BitmapData, 16, "uptr") ; Scan0
  3090.  
  3091. E := DllCall("gdiplus\GdipBitmapLockBits"
  3092. , "uptr", pBitmap
  3093. , "uptr", &Rect
  3094. , "uint", 5 ; ImageLockMode.UserInputBuffer | ImageLockMode.ReadOnly
  3095. , "int", 0xE200B ; Format32bppPArgb
  3096. , "uptr", &BitmapData) ; Contains the pointer (pBits) to the hbm.
  3097. If !E
  3098. DllCall("gdiplus\GdipBitmapUnlockBits", "uptr", pBitmap, "uptr", &BitmapData)
  3099.  
  3100. ; Cleanup the hBitmap and device contexts.
  3101. SelectObject(hdc, obm)
  3102. DeleteObject(hdc)
  3103. return hbm
  3104. }
  3105.  
  3106. Gdip_CreateBitmapFromHICON(hIcon) {
  3107. pBitmap := 0
  3108. gdipLastError := DllCall("gdiplus\GdipCreateBitmapFromHICON", "UPtr", hIcon, "UPtr*", pBitmap)
  3109. return pBitmap
  3110. }
  3111.  
  3112. Gdip_CreateHICONFromBitmap(pBitmap) {
  3113. hIcon := 0
  3114. gdipLastError := DllCall("gdiplus\GdipCreateHICONFromBitmap", "UPtr", pBitmap, "UPtr*", hIcon)
  3115. return hIcon
  3116. }
  3117.  
  3118. Gdip_CreateBitmapFromDirectDrawSurface(IDirectDrawSurface) {
  3119. pBitmap := 0
  3120. gdipLastError := DllCall("GdiPlus\GdipCreateBitmapFromDirectDrawSurface", "UPtr", IDirectDrawSurface, "UPtr*", pBitmap)
  3121. return pBitmap
  3122. }
  3123.  
  3124. Gdip_CreateBitmap(Width, Height, PixelFormat:=0, Stride:=0, Scan0:=0) {
  3125. ; By default, this function creates by default a new 32-ARGB bitmap. Pass a specific PixelFormat if otherwise needed.
  3126. ; scan0 - Optional pointer to an array of bytes that contains the pixel data.
  3127. ; The caller is responsible for allocating and freeing the block of memory pointed to by this parameter
  3128. ; function modified by Marius Șucan
  3129.  
  3130. If (!Width || !Height)
  3131. {
  3132. gdipLastError := 2
  3133. Return
  3134. }
  3135.  
  3136. pBitmap := 0
  3137. If !PixelFormat
  3138. PixelFormat := 0x26200A ; 32-ARGB
  3139.  
  3140. gdipLastError := DllCall("gdiplus\GdipCreateBitmapFromScan0"
  3141. , "int", Width , "int", Height
  3142. , "int", Stride , "int", PixelFormat
  3143. , "UPtr", Scan0 , "UPtr*", pBitmap)
  3144.  
  3145. Return pBitmap
  3146. }
  3147.  
  3148. Gdip_CreateBitmapFromClipboard() {
  3149. ; modified by Marius Șucan
  3150.  
  3151. pid := DllCall("GetCurrentProcessId","uint")
  3152. hwnd := WinExist("ahk_pid " . pid)
  3153. If !DllCall("IsClipboardFormatAvailable", "uint", 8) ; CF_DIB = 8
  3154. {
  3155. If DllCall("IsClipboardFormatAvailable", "uint", 2) ; CF_BITMAP = 2
  3156. {
  3157. If !DllCall("OpenClipboard", "UPtr", hwnd)
  3158. return -1
  3159.  
  3160. hData := DllCall("User32.dll\GetClipboardData", "UInt", 0x0002, "UPtr")
  3161. hBitmap := DllCall("User32.dll\CopyImage", "UPtr", hData, "UInt", 0, "Int", 0, "Int", 0, "UInt", 0x2004, "UPtr")
  3162. DllCall("CloseClipboard")
  3163. pBitmap := Gdip_CreateBitmapFromHBITMAP(hBitmap)
  3164. DeleteObject(hBitmap)
  3165. return pBitmap
  3166. }
  3167. return -2
  3168. }
  3169.  
  3170. If !DllCall("OpenClipboard", "UPtr", hwnd)
  3171. return -1
  3172.  
  3173. hBitmap := DllCall("GetClipboardData", "uint", 2, "UPtr")
  3174. DllCall("CloseClipboard")
  3175. If !hBitmap
  3176. return -3
  3177.  
  3178. pBitmap := Gdip_CreateARGBBitmapFromHBITMAP(hBitmap) ; this function can return a completely empty/transparent bitmap
  3179. DeleteObject(hBitmap)
  3180. if !pBitmap
  3181. return -4
  3182.  
  3183. isUniform := Gdip_TestBitmapUniformity(pBitmap, 7, maxLevelIndex)
  3184. If (isUniform=1 && maxLevelIndex<=2)
  3185. {
  3186. Gdip_DisposeImage(pBitmap, 1)
  3187. pBitmap := Gdip_CreateBitmapFromHBITMAP(hBitmap)
  3188. }
  3189.  
  3190. return pBitmap
  3191. }
  3192.  
  3193. Gdip_SetBitmapToClipboard(pBitmap, hBitmap:=0) {
  3194. ; modified by Marius Șucan to have this function report errors
  3195. ; you can feed this function a hBitmap directly
  3196. ; return value: 0 = succes
  3197.  
  3198. off1 := A_PtrSize = 8 ? 52 : 44
  3199. off2 := A_PtrSize = 8 ? 32 : 24
  3200. r1 := DllCall("OpenClipboard", "UPtr", 0)
  3201. If !r1
  3202. Return -1
  3203.  
  3204. If !hBitmap
  3205. {
  3206. If pBitmap
  3207. hBitmap := Gdip_CreateHBITMAPFromBitmap(pBitmap, 0)
  3208. }
  3209.  
  3210. If !hBitmap
  3211. {
  3212. DllCall("CloseClipboard")
  3213. Return -3
  3214. }
  3215.  
  3216. r2 := DllCall("EmptyClipboard")
  3217. If !r2
  3218. {
  3219. DeleteObject(hBitmap)
  3220. DllCall("CloseClipboard")
  3221. Return -2
  3222. }
  3223.  
  3224. DllCall("GetObject", "UPtr", hBitmap, "int", VarSetCapacity(oi, A_PtrSize = 8 ? 104 : 84, 0), "UPtr", &oi)
  3225. hdib := DllCall("GlobalAlloc", "uint", 2, "UPtr", 40+NumGet(oi, off1, "UInt"), "UPtr")
  3226. pdib := DllCall("GlobalLock", "UPtr", hdib, "UPtr")
  3227. DllCall("RtlMoveMemory", "UPtr", pdib, "UPtr", &oi+off2, "UPtr", 40)
  3228. DllCall("RtlMoveMemory", "UPtr", pdib+40, "UPtr", NumGet(oi, off2 - A_PtrSize, "UPtr"), "UPtr", NumGet(oi, off1, "UInt"))
  3229. DllCall("GlobalUnlock", "UPtr", hdib)
  3230. r3 := DllCall("SetClipboardData", "uint", 8, "UPtr", hdib) ; CF_DIB = 8
  3231. DllCall("CloseClipboard")
  3232. DllCall("GlobalFree", "UPtr", hdib)
  3233. DeleteObject(hBitmap)
  3234. E := r3 ? 0 : -4 ; 0 - success
  3235. Return E
  3236. }
  3237.  
  3238. Gdip_CloneBitmapArea(pBitmap, x:="", y:="", w:=0, h:=0, PixelFormat:=0, KeepPixelFormat:=0) {
  3239. ; The new pBitmap is by default in the 32-ARGB PixelFormat.
  3240. ;
  3241. ; If the specified coordinates exceed the boundaries of pBitmap
  3242. ; the resulted pBitmap is erroneuous / defective.
  3243. If (pBitmap="")
  3244. {
  3245. gdipLastError := 2
  3246. Return
  3247. }
  3248.  
  3249. pBitmapDest := 0
  3250. If !PixelFormat
  3251. PixelFormat := 0x26200A ; 32-ARGB
  3252.  
  3253. If (KeepPixelFormat=1)
  3254. PixelFormat := Gdip_GetImagePixelFormat(pBitmap, 1)
  3255.  
  3256. If (y="")
  3257. y := 0
  3258.  
  3259. If (x="")
  3260. x := 0
  3261.  
  3262. If (!w || !h)
  3263. Gdip_GetImageDimensions(pBitmap, w, h)
  3264.  
  3265. gdipLastError := DllCall("gdiplus\GdipCloneBitmapArea"
  3266. , "float", x, "float", y
  3267. , "float", w, "float", h
  3268. , "int", PixelFormat
  3269. , "UPtr", pBitmap
  3270. , "UPtr*", pBitmapDest)
  3271.  
  3272. return pBitmapDest
  3273. }
  3274.  
  3275. Gdip_CloneBitmap(pBitmap) {
  3276. ; the new pBitmap will have the same PixelFormat, unchanged.
  3277. If !pBitmap
  3278. {
  3279. gdipLastError := 2
  3280. Return
  3281. }
  3282.  
  3283. pBitmapDest := 0
  3284. gdipLastError := DllCall("gdiplus\GdipCloneImage", "UPtr", pBitmap, "UPtr*", pBitmapDest)
  3285. return pBitmapDest
  3286. }
  3287.  
  3288. Gdip_GetFrameDelay(pBitmap, FrameIndex) {
  3289. ItemSize := 0
  3290. R := DllCall("Gdiplus\GdipGetPropertyItemSize", "UPtr", pBitmap, "UInt", 0x5100, "UInt*", ItemSize)
  3291. If (R || !ItemSize)
  3292. Return -1
  3293.  
  3294. VarSetCapacity(Item, ItemSize, 0)
  3295. R := DllCall("Gdiplus\GdipGetPropertyItem", "UPtr", pBitmap, "UInt", 0x5100, "UInt", ItemSize, "UPtr", &Item)
  3296. If R
  3297. Return -1
  3298. Else
  3299. FrameDelay := ((g := NumGet(NumGet(item, 8 + A_PtrSize, "UPtr")+0, (FrameIndex - 1)*4, "UInt") * 10 ) ? g : 100)
  3300. item := ""
  3301. Return FrameDelay
  3302. }
  3303.  
  3304. Gdip_BitmapSelectActiveFrame(pBitmap, FrameIndex) {
  3305. ; Selects as the active frame the given FrameIndex
  3306. ; within an animated GIF or a multi-paged TIFF.
  3307. ; On succes, it returns the frames count.
  3308. ; On fail, the return value is -1.
  3309.  
  3310. Countu := 0
  3311. CountFrames := 0
  3312. DllCall("gdiplus\GdipImageGetFrameDimensionsCount", "UPtr", pBitmap, "UInt*", Countu)
  3313. VarSetCapacity(dIDs, 16, 0)
  3314. DllCall("gdiplus\GdipImageGetFrameDimensionsList", "UPtr", pBitmap, "UPtr", &dIDs, "UInt", Countu)
  3315. DllCall("gdiplus\GdipImageGetFrameCount", "UPtr", pBitmap, "UPtr", &dIDs, "UInt*", CountFrames)
  3316. If (FrameIndex>CountFrames)
  3317. FrameIndex := CountFrames
  3318. Else If (FrameIndex<1)
  3319. FrameIndex := 0
  3320.  
  3321. gdipLastError := DllCall("gdiplus\GdipImageSelectActiveFrame", "UPtr", pBitmap, "UPtr", &dIDs, "UInt", FrameIndex)
  3322. If gdipLastError
  3323. Return -1
  3324. Return CountFrames
  3325. }
  3326.  
  3327. Gdip_GetBitmapFramesCount(pBitmap) {
  3328. ; The function returns the number of frames or pages a given pBitmap has.
  3329. ; GDI+ only supports multi-frames/pages for GIFs and TIFFs.
  3330. ; Function written by SBC in September 2010 and
  3331. ; extracted from his «Picture Viewer» script.
  3332. ; https://autohotkey.com/board/topic/58226-ahk-picture-viewer/
  3333.  
  3334. Countu := 0
  3335. CountFrames := 0
  3336. DllCall("gdiplus\GdipImageGetFrameDimensionsCount", "UPtr", pBitmap, "UInt*", Countu)
  3337. VarSetCapacity(dIDs, 16, 0)
  3338. DllCall("gdiplus\GdipImageGetFrameDimensionsList", "UPtr", pBitmap, "UPtr", &dIDs, "UInt", Countu)
  3339. DllCall("gdiplus\GdipImageGetFrameCount", "UPtr", pBitmap, "UPtr", &dIDs, "UInt*", CountFrames)
  3340. Return CountFrames
  3341. }
  3342.  
  3343. Gdip_CreateCachedBitmap(pBitmap, pGraphics) {
  3344. ; Creates a CachedBitmap object based on a Bitmap object and a pGraphics object. The cached bitmap takes
  3345. ; the pixel data from the Bitmap object and stores it in a format that is optimized for the display device
  3346. ; associated with the pGraphics object.
  3347.  
  3348. pCachedBitmap := 0
  3349. gdipLastError := := DllCall("gdiplus\GdipCreateCachedBitmap", "UPtr", pBitmap, "UPtr", pGraphics, "Ptr*", pCachedBitmap)
  3350. return pCachedBitmap
  3351. }
  3352.  
  3353. Gdip_DeleteCachedBitmap(pCachedBitmap) {
  3354. return DllCall("gdiplus\GdipDeleteCachedBitmap", "UPtr", pCachedBitmap)
  3355. }
  3356.  
  3357. Gdip_DrawCachedBitmap(pGraphics, pCachedBitmap, X, Y) {
  3358. return DllCall("gdiplus\GdipDrawCachedBitmap", "UPtr", pGraphics, "UPtr", pCachedBitmap, "int", X, "int", Y)
  3359. }
  3360.  
  3361. Gdip_ImageRotateFlip(pBitmap, RotateFlipType:=1) {
  3362. ; RotateFlipType options:
  3363. ; RotateNoneFlipNone = 0
  3364. ; Rotate90FlipNone = 1
  3365. ; Rotate180FlipNone = 2
  3366. ; Rotate270FlipNone = 3
  3367. ; RotateNoneFlipX = 4 // flip horizontally
  3368. ; Rotate90FlipX = 5
  3369. ; Rotate180FlipX = 6 // flip vertically
  3370. ; Rotate270FlipX = 7
  3371. ; RotateNoneFlipY = Rotate180FlipX
  3372. ; Rotate90FlipY = Rotate270FlipX
  3373. ; Rotate180FlipY = RotateNoneFlipX
  3374. ; Rotate270FlipY = Rotate90FlipX
  3375. ; RotateNoneFlipXY = Rotate180FlipNone
  3376. ; Rotate90FlipXY = Rotate270FlipNone
  3377. ; Rotate180FlipXY = RotateNoneFlipNone
  3378. ; Rotate270FlipXY = Rotate90FlipNone
  3379.  
  3380. return DllCall("gdiplus\GdipImageRotateFlip", "UPtr", pBitmap, "int", RotateFlipType)
  3381. }
  3382.  
  3383. Gdip_RotateBitmapAtCenter(pBitmap, Angle, pBrush:=0, InterpolationMode:=7, PixelFormat:=0) {
  3384. ; the pBrush will be used to fill the background of the image
  3385. ; by default, it is black.
  3386. ; The function returns the pointer to a new pBitmap.
  3387. If !pBitmap
  3388. Return
  3389.  
  3390. If !Angle
  3391. Return Gdip_CloneBitmap(pBitmap)
  3392.  
  3393. Gdip_GetImageDimensions(pBitmap, Width, Height)
  3394. Gdip_GetRotatedDimensions(Width, Height, Angle, RWidth, RHeight)
  3395. Gdip_GetRotatedTranslation(Width, Height, Angle, xTranslation, yTranslation)
  3396. mpx := Round((RWidth * RHeight)/1000000, 1)
  3397. If (mpx>536.4 || RWidth>32750 || RHeight>32750)
  3398. Return
  3399.  
  3400. PixelFormatReadable := Gdip_GetImagePixelFormat(pBitmap, 2)
  3401. If InStr(PixelFormatReadable, "indexed")
  3402. {
  3403. hbm := CreateDIBSection(RWidth, RHeight,,24)
  3404. If !hbm
  3405. Return
  3406.  
  3407. hDC := CreateCompatibleDC()
  3408. If !hDC
  3409. {
  3410. DeleteDC(hDC)
  3411. Return
  3412. }
  3413.  
  3414. obm := SelectObject(hDC, hbm)
  3415. G := Gdip_GraphicsFromHDC(hDC, InterpolationMode, 4)
  3416. indexedMode := 1
  3417. } Else
  3418. {
  3419. If (PixelFormat=-1)
  3420. PixelFormat := "0xE200B"
  3421.  
  3422. newBitmap := Gdip_CreateBitmap(RWidth, RHeight, PixelFormat)
  3423. If StrLen(newBitmap)>1
  3424. G := Gdip_GraphicsFromImage(newBitmap, InterpolationMode, 4)
  3425. }
  3426.  
  3427. If (!newBitmap || !G)
  3428. {
  3429. Gdip_DisposeImage(newBitmap, 1)
  3430. Gdip_DeleteGraphics(G)
  3431. SelectObject(hDC, obm)
  3432. DeleteObject(hbm)
  3433. DeleteDC(hDC)
  3434. Return
  3435. }
  3436.  
  3437. If (pBrush=0)
  3438. {
  3439. pBrush := Gdip_BrushCreateSolid("0xFF000000")
  3440. defaultBrush := 1
  3441. }
  3442.  
  3443. If StrLen(pBrush)>1
  3444. Gdip_FillRectangle(G, pBrush, 0, 0, RWidth, RHeight)
  3445.  
  3446. Gdip_TranslateWorldTransform(G, xTranslation, yTranslation)
  3447. Gdip_RotateWorldTransform(G, Angle)
  3448. r := Gdip_DrawImage(G, pBitmap, 0, 0, Width, Height)
  3449.  
  3450. If (indexedMode=1)
  3451. {
  3452. newBitmap := !r ? Gdip_CreateBitmapFromHBITMAP(hbm) : ""
  3453. SelectObject(hDC, obm)
  3454. DeleteObject(hbm)
  3455. DeleteDC(hDC)
  3456. } Else If r
  3457. {
  3458. Gdip_DisposeImage(newBitmap, 1)
  3459. newBitmap := ""
  3460. }
  3461.  
  3462. Gdip_DeleteGraphics(G)
  3463. If (defaultBrush=1)
  3464. Gdip_DeleteBrush(pBrush)
  3465.  
  3466. Return newBitmap
  3467. }
  3468.  
  3469. Gdip_ResizeBitmap(pBitmap, givenW, givenH, KeepRatio, InterpolationMode:="", KeepPixelFormat:=0, checkTooLarge:=0, bgrColor:=0) {
  3470. ; KeepPixelFormat can receive a specific PixelFormat.
  3471. ; The function returns a pointer to a new pBitmap.
  3472. ; Default is 0 = 32-ARGB.
  3473. ; For maximum speed, use 0xE200B - 32-PARGB pixel format.
  3474. ; Set bgrColor to have a background colour painted.
  3475.  
  3476. If (!pBitmap || !givenW || !givenH)
  3477. Return
  3478.  
  3479. Gdip_GetImageDimensions(pBitmap, Width, Height)
  3480. If (KeepRatio=1)
  3481. {
  3482. calcIMGdimensions(Width, Height, givenW, givenH, ResizedW, ResizedH)
  3483. } Else
  3484. {
  3485. ResizedW := givenW
  3486. ResizedH := givenH
  3487. }
  3488.  
  3489. If (Width=resizedW && Height=resizedH)
  3490. Return Gdip_CloneBitmap(pBitmap)
  3491.  
  3492. mpx := Round((ResizedW * ResizedH)/1000000, 1)
  3493. PixelFormatReadable := Gdip_GetImagePixelFormat(pBitmap, 2)
  3494. If (KeepPixelFormat=1)
  3495. PixelFormat := Gdip_GetImagePixelFormat(pBitmap, 1)
  3496. Else If (KeepPixelFormat=-1)
  3497. PixelFormat := "0xE200B"
  3498. Else If Strlen(KeepPixelFormat)>3
  3499. PixelFormat := KeepPixelFormat
  3500.  
  3501. If ((mpx>536.4 && (!PixelFormat || PixelFormat=0x22009 || PixelFormat=0xE200B)) || (mpx>715.3 && PixelFormat=0x21808) || max(ResizedW, ResizedH)>32750 && checkTooLarge=1)
  3502. Return
  3503.  
  3504. If (ResizedW=Width && ResizedH=Height)
  3505. InterpolationMode := 5
  3506.  
  3507. If (bgrColor!="")
  3508. pBrush := Gdip_BrushCreateSolid(bgrColor)
  3509.  
  3510. If InStr(PixelFormatReadable, "indexed")
  3511. {
  3512. hbm := CreateDIBSection(ResizedW, ResizedH,,24)
  3513. If !hbm
  3514. Return
  3515.  
  3516. hDC := CreateCompatibleDC()
  3517. If !hDC
  3518. {
  3519. DeleteDC(hdc)
  3520. Return
  3521. }
  3522.  
  3523. obm := SelectObject(hDC, hbm)
  3524. G := Gdip_GraphicsFromHDC(hDC, InterpolationMode, 4)
  3525. Gdip_SetPixelOffsetMode(G, 2)
  3526. If G
  3527. {
  3528. If pBrush
  3529. Gdip_FillRectangle(G, pBrush, 0, 0, ResizedW, ResizedH)
  3530. r := Gdip_DrawImage(G, pBitmap, 0, 0, ResizedW, ResizedH)
  3531. }
  3532.  
  3533. newBitmap := !r ? Gdip_CreateBitmapFromHBITMAP(hbm) : ""
  3534. If (KeepPixelFormat=1 && newBitmap)
  3535. Gdip_BitmapSetColorDepth(newBitmap, SubStr(PixelFormatReadable, 1, 1), 1)
  3536.  
  3537. SelectObject(hdc, obm)
  3538. DeleteObject(hbm)
  3539. DeleteDC(hdc)
  3540. Gdip_DeleteGraphics(G)
  3541. } Else
  3542. {
  3543. newBitmap := Gdip_CreateBitmap(ResizedW, ResizedH, PixelFormat)
  3544. If StrLen(newBitmap)>2
  3545. {
  3546. G := Gdip_GraphicsFromImage(newBitmap, InterpolationMode, 4)
  3547. Gdip_SetPixelOffsetMode(G, 2)
  3548. If G
  3549. {
  3550. If pBrush
  3551. Gdip_FillRectangle(G, pBrush, 0, 0, ResizedW, ResizedH)
  3552. r := Gdip_DrawImage(G, pBitmap, 0, 0, ResizedW, ResizedH)
  3553. }
  3554.  
  3555. Gdip_DeleteGraphics(G)
  3556. If (r || !G)
  3557. {
  3558. Gdip_DisposeImage(newBitmap, 1)
  3559. newBitmap := ""
  3560. }
  3561. }
  3562. }
  3563. If pBrush
  3564. Gdip_DeleteBrush(pBrush)
  3565.  
  3566. Return newBitmap
  3567. }
  3568.  
  3569. ;#####################################################################################
  3570. ; pPen functions
  3571. ; With Gdip_SetPenBrushFill() or Gdip_CreatePenFromBrush() functions,
  3572. ; pPen objects can have gradients or textures.
  3573. ;#####################################################################################
  3574.  
  3575. Gdip_CreatePen(ARGB, w, Unit:=2) {
  3576. pPen := 0
  3577. gdipLastError := DllCall("gdiplus\GdipCreatePen1", "UInt", ARGB, "float", w, "int", Unit, "UPtr*", pPen)
  3578. return pPen
  3579. }
  3580.  
  3581. Gdip_CreatePenFromBrush(pBrush, w, Unit:=2) {
  3582. ; Unit - Unit of measurement for the pen size:
  3583. ; 0 - World coordinates, a non-physical unit
  3584. ; 1 - Display units
  3585. ; 2 - A unit is 1 pixel [default]
  3586. ; 3 - A unit is 1 point or 1/72 inch
  3587. ; 4 - A unit is 1 inch
  3588. ; 5 - A unit is 1/300 inch
  3589. ; 6 - A unit is 1 millimeter
  3590.  
  3591. pPen := 0
  3592. gdipLastError := DllCall("gdiplus\GdipCreatePen2", "UPtr", pBrush, "float", w, "int", 2, "UPtr*", pPen, "int", Unit)
  3593. return pPen
  3594. }
  3595.  
  3596. Gdip_SetPenWidth(pPen, width) {
  3597. return DllCall("gdiplus\GdipSetPenWidth", "UPtr", pPen, "float", width)
  3598. }
  3599.  
  3600. Gdip_GetPenWidth(pPen) {
  3601. width := 0
  3602. E := DllCall("gdiplus\GdipGetPenWidth", "UPtr", pPen, "float*", width)
  3603. If E
  3604. return -1
  3605. return width
  3606. }
  3607.  
  3608. Gdip_GetPenDashStyle(pPen) {
  3609. DashStyle := 0
  3610. E := DllCall("gdiplus\GdipGetPenDashStyle", "UPtr", pPen, "float*", DashStyle)
  3611. If E
  3612. return -1
  3613. return DashStyle
  3614. }
  3615.  
  3616. Gdip_SetPenColor(pPen, ARGB) {
  3617. return DllCall("gdiplus\GdipSetPenColor", "UPtr", pPen, "UInt", ARGB)
  3618. }
  3619.  
  3620. Gdip_GetPenColor(pPen) {
  3621. ARGB := 0
  3622. E := DllCall("gdiplus\GdipGetPenColor", "UPtr", pPen, "UInt*", ARGB)
  3623. If E
  3624. return -1
  3625.  
  3626. return Format("{1:#x}", ARGB)
  3627. }
  3628.  
  3629. Gdip_SetPenBrushFill(pPen, pBrush) {
  3630. return DllCall("gdiplus\GdipSetPenBrushFill", "UPtr", pPen, "UPtr", pBrush)
  3631. }
  3632.  
  3633. Gdip_ResetPenTransform(pPen) {
  3634. Return DllCall("gdiplus\GdipResetPenTransform", "UPtr", pPen)
  3635. }
  3636.  
  3637. Gdip_MultiplyPenTransform(pPen, hMatrix, matrixOrder:=0) {
  3638. Return DllCall("gdiplus\GdipMultiplyPenTransform", "UPtr", pPen, "UPtr", hMatrix, "int", matrixOrder)
  3639. }
  3640.  
  3641. Gdip_RotatePenTransform(pPen, Angle, matrixOrder:=0) {
  3642. Return DllCall("gdiplus\GdipRotatePenTransform", "UPtr", pPen, "float", Angle, "int", matrixOrder)
  3643. }
  3644.  
  3645. Gdip_ScalePenTransform(pPen, ScaleX, ScaleY, matrixOrder:=0) {
  3646. Return DllCall("gdiplus\GdipScalePenTransform", "UPtr", pPen, "float", ScaleX, "float", ScaleY, "int", matrixOrder)
  3647. }
  3648.  
  3649. Gdip_TranslatePenTransform(pPen, X, Y, matrixOrder:=0) {
  3650. Return DllCall("gdiplus\GdipTranslatePenTransform", "UPtr", pPen, "float", X, "float", Y, "int", matrixOrder)
  3651. }
  3652.  
  3653. Gdip_SetPenTransform(pPen, pMatrix) {
  3654. return DllCall("gdiplus\GdipSetPenTransform", "UPtr", pPen, "UPtr", pMatrix)
  3655. }
  3656.  
  3657. Gdip_GetPenTransform(pPen) {
  3658. pMatrix := 0
  3659. gdipLastError := DllCall("gdiplus\GdipGetPenTransform", "UPtr", pPen, "UPtr*", pMatrix)
  3660. Return pMatrix
  3661. }
  3662.  
  3663. Gdip_GetPenBrushFill(pPen) {
  3664. ; Gets the pBrush object that is currently set for the pPen object
  3665. pBrush := 0
  3666. gdipLastError := DllCall("gdiplus\GdipGetPenBrushFill", "UPtr", pPen, "UPtr*", pBrush)
  3667. Return pBrush
  3668. }
  3669.  
  3670. Gdip_GetPenFillType(pPen) {
  3671. ; Description: Gets the type of brush fill currently set for a Pen object
  3672. ; Return values:
  3673. ; 0 - The pen draws with a solid color
  3674. ; 1 - The pen draws with a hatch pattern that is specified by a HatchBrush object
  3675. ; 2 - The pen draws with a texture that is specified by a TextureBrush object
  3676. ; 3 - The pen draws with a color gradient that is specified by a PathGradientBrush object
  3677. ; 4 - The pen draws with a color gradient that is specified by a LinearGradientBrush object
  3678. ; -1 - The pen type is unknown
  3679. ; -2 - Error
  3680.  
  3681. result := 0
  3682. gdipLastError := DllCall("gdiplus\GdipGetPenFillType", "UPtr", pPen, "int*", result)
  3683. If gdipLastError
  3684. return -2
  3685. Return result
  3686. }
  3687.  
  3688. Gdip_GetPenStartCap(pPen) {
  3689. result := 0
  3690. gdipLastError := DllCall("gdiplus\GdipGetPenStartCap", "UPtr", pPen, "int*", result)
  3691. If gdipLastError
  3692. return -1
  3693. Return result
  3694. }
  3695.  
  3696. Gdip_GetPenEndCap(pPen) {
  3697. result := 0
  3698. gdipLastError := DllCall("gdiplus\GdipGetPenEndCap", "UPtr", pPen, "int*", result)
  3699. If gdipLastError
  3700. return -1
  3701. Return result
  3702. }
  3703.  
  3704. Gdip_GetPenDashCaps(pPen) {
  3705. result := 0
  3706. gdipLastError := DllCall("gdiplus\GdipGetPenDashCap197819", "UPtr", pPen, "int*", result)
  3707. If gdipLastError
  3708. return -1
  3709. Return result
  3710. }
  3711.  
  3712. Gdip_GetPenAlignment(pPen) {
  3713. result := 0
  3714. gdipLastError := DllCall("gdiplus\GdipGetPenMode", "UPtr", pPen, "int*", result)
  3715. If gdipLastError
  3716. return -1
  3717. Return result
  3718. }
  3719.  
  3720. ;#####################################################################################
  3721. ; Function - Gdip_SetPenLineCaps
  3722. ; Description - Sets the cap styles for the start, end, and dashes in a line drawn with the pPen object
  3723. ; Parameters
  3724. ; pPen - Pointer to a Pen object. Start and end caps do not apply to closed lines.
  3725. ; - StartCap - Line cap style for the start cap:
  3726. ; 0x00 - Line ends at the last point. The end is squared off
  3727. ; 0x01 - Square cap. The center of the square is the last point in the line. The height and width of the square are the line width.
  3728. ; 0x02 - Circular cap. The center of the circle is the last point in the line. The diameter of the circle is the line width.
  3729. ; 0x03 - Triangular cap. The base of the triangle is the last point in the line. The base of the triangle is the line width.
  3730. ; 0x10 - Line ends are not anchored.
  3731. ; 0x11 - Line ends are anchored with a square. The center of the square is the last point in the line. The height and width of the square are the line width.
  3732. ; 0x12 - Line ends are anchored with a circle. The center of the circle is at the last point in the line. The circle is wider than the line.
  3733. ; 0x13 - Line ends are anchored with a diamond (a square turned at 45 degrees). The center of the diamond is at the last point in the line. The diamond is wider than the line.
  3734. ; 0x14 - Line ends are anchored with arrowheads. The arrowhead point is located at the last point in the line. The arrowhead is wider than the line.
  3735. ; 0xff - Line ends are made from a CustomLineCap object.
  3736. ; EndCap - Line cap style for the end cap (same values as StartCap)
  3737. ; DashCap - Start and end caps for a dashed line:
  3738. ; 0 - A square cap that squares off both ends of each dash
  3739. ; 2 - A circular cap that rounds off both ends of each dash
  3740. ; 3 - A triangular cap that points both ends of each dash
  3741. ; Return value: status enumeration
  3742.  
  3743. Gdip_SetPenLineCaps(pPen, StartCap, EndCap, DashCap) {
  3744. Return DllCall("gdiplus\GdipSetPenLineCap197819", "UPtr", pPen, "int", StartCap, "int", EndCap, "int", DashCap)
  3745. }
  3746.  
  3747. Gdip_SetPenStartCap(pPen, LineCap) {
  3748. Return DllCall("gdiplus\GdipSetPenStartCap", "UPtr", pPen, "int", LineCap)
  3749. }
  3750.  
  3751. Gdip_SetPenEndCap(pPen, LineCap) {
  3752. Return DllCall("gdiplus\GdipSetPenEndCap", "UPtr", pPen, "int", LineCap)
  3753. }
  3754.  
  3755. Gdip_SetPenDashCaps(pPen, LineCap) {
  3756. ; If you set the alignment of a Pen object to
  3757. ; Pen Alignment Inset, you cannot use that pen
  3758. ; to draw triangular dash caps.
  3759.  
  3760. Return DllCall("gdiplus\GdipSetPenDashCap197819", "UPtr", pPen, "int", LineCap)
  3761. }
  3762.  
  3763. Gdip_SetPenAlignment(pPen, Alignment) {
  3764. ; Specifies the alignment setting of the pen relative to the line that is drawn. The default value is Center.
  3765. ; If you set the alignment of a Pen object to Inset, you cannot use that pen to draw compound lines or triangular dash caps.
  3766. ; Alignment options:
  3767. ; 0 [Center] - Specifies that the pen is aligned on the center of the line that is drawn.
  3768. ; 1 [Inset] - Specifies, when drawing a polygon, that the pen is aligned on the inside of the edge of the polygon.
  3769.  
  3770. Return DllCall("gdiplus\GdipSetPenMode", "UPtr", pPen, "int", Alignment)
  3771. }
  3772.  
  3773. Gdip_GetPenCompoundCount(pPen) {
  3774. result := 0
  3775. E := DllCall("gdiplus\GdipGetPenCompoundCount", "UPtr", pPen, "int*", result)
  3776. If E
  3777. Return -1
  3778. Return result
  3779. }
  3780.  
  3781. Gdip_SetPenCompoundArray(pPen, inCompounds) {
  3782. ; Parameters - pPen - Pointer to a pPen object
  3783. ; inCompounds - A string of compound values:
  3784. ; "value1|value2|value3" [and so on]
  3785. ; ExampleCompounds := "0.0|0.2|0.7|1.0"
  3786. ; Remarks - The elements in the string array must be in increasing order, between 0 and not greater than 1.
  3787. ; Suppose you want a pen to draw two parallel lines where the width of the first line is 20 percent of the pen's
  3788. ; width, the width of the space that separates the two lines is 50 percent of the pen's width, and the width
  3789. ; of the second line is 30 percent of the pen's width. Start by creating a pPen object and an array of compound
  3790. ; values. For this, you can then set the compound array by passing the array with the values "0.0|0.2|0.7|1.0".
  3791. ; Return status enumeration
  3792.  
  3793. totalCompounds := AllocateBinArray(pCompounds, inCompounds)
  3794. If totalCompounds
  3795. Return DllCall("gdiplus\GdipSetPenCompoundArray", "UPtr", pPen, "UPtr", &pCompounds, "int", totalCompounds)
  3796. Else
  3797. Return 2
  3798. }
  3799.  
  3800. Gdip_SetPenDashStyle(pPen, DashStyle) {
  3801. ; DashStyle options:
  3802. ; Solid = 0
  3803. ; Dash = 1
  3804. ; Dot = 2
  3805. ; DashDot = 3
  3806. ; DashDotDot = 4
  3807. ; Custom = 5
  3808. ; https://technet.microsoft.com/pt-br/ms534104(v=vs.71).aspx
  3809. ; function by IPhilip
  3810. Return DllCall("gdiplus\GdipSetPenDashStyle", "UPtr", pPen, "Int", DashStyle)
  3811. }
  3812.  
  3813. Gdip_SetPenDashArray(pPen, Dashes) {
  3814. ; Description Sets custom dashes and spaces for the pPen object.
  3815. ;
  3816. ; Parameters pPen - Pointer to a Pen object
  3817. ; Dashes - The string that specifies the length of the custom dashes and spaces:
  3818. ; Format: "dL1|sL1|dL2|sL2|dL3|sL3" [... and so on]
  3819. ; dLn - Dash N length
  3820. ; sLn - Space N length
  3821. ; ExampleDashesArgument := "3|6|8|4|2|1"
  3822. ;
  3823. ; Remarks This function sets the dash style for the pPen object to DashStyleCustom (6).
  3824. ; Return status enumeration.
  3825. PointsCount := AllocateBinArray(pDashes, Dashes)
  3826. If PointsCount
  3827. Return DllCall("gdiplus\GdipSetPenDashArray", "UPtr", pPen, "UPtr", &pDashes, "int", PointsCount)
  3828. Else
  3829. Return 2
  3830. }
  3831.  
  3832. Gdip_SetPenDashOffset(pPen, Offset) {
  3833. ; Sets the distance from the start of the line to the start of the first space in a dashed line
  3834. ; Offset - Real number that specifies the number of times to shift the spaces in a dashed line. Each shift is
  3835. ; equal to the length of a space in the dashed line
  3836.  
  3837. Return DllCall("gdiplus\GdipSetPenDashOffset", "UPtr", pPen, "float", Offset)
  3838. }
  3839.  
  3840. Gdip_GetPenDashArray(pPen) {
  3841. iCount := Gdip_GetPenDashCount(pPen)
  3842. If (iCount=-1)
  3843. Return 0
  3844.  
  3845. VarSetCapacity(PointsF, 4 * iCount, 0)
  3846. gdipLastError := DllCall("gdiplus\GdipGetPenDashArray", "UPtr", pPen, "UPtr", &PointsF, "int", iCount)
  3847. printList := ""
  3848. Loop %iCount%
  3849. {
  3850. A := NumGet(&PointsF, 4*(A_Index-1), "float")
  3851. printList .= A "|"
  3852. }
  3853.  
  3854. Return Trim(printList, "|")
  3855. }
  3856.  
  3857. Gdip_GetPenCompoundArray(pPen) {
  3858. iCount := Gdip_GetPenCompoundCount(pPen)
  3859. VarSetCapacity(PointsF, 4 * iCount, 0)
  3860. gdipLastError := DllCall("gdiplus\GdipGetPenCompoundArray", "UPtr", pPen, "uPtr", &PointsF, "int", iCount)
  3861.  
  3862. printList := ""
  3863. Loop %iCount%
  3864. {
  3865. A := NumGet(&PointsF, 4*(A_Index-1), "float")
  3866. printList .= A "|"
  3867. }
  3868.  
  3869. Return Trim(printList, "|")
  3870. }
  3871.  
  3872. Gdip_SetPenLineJoin(pPen, LineJoin) {
  3873. ; LineJoin - Line join style:
  3874. ; MITER = 0 - it produces a sharp corner or a clipped corner, depending on whether the length of the miter exceeds the miter limit.
  3875. ; BEVEL = 1 - it produces a diagonal corner.
  3876. ; ROUND = 2 - it produces a smooth, circular arc between the lines.
  3877. ; MITERCLIPPED = 3 - it produces a sharp corner or a beveled corner, depending on whether the length of the miter exceeds the miter limit.
  3878.  
  3879. Return DllCall("gdiplus\GdipSetPenLineJoin", "UPtr", pPen, "int", LineJoin)
  3880. }
  3881.  
  3882. Gdip_SetPenMiterLimit(pPen, MiterLimit) {
  3883. ; MiterLimit - Real number that specifies the miter limit of the Pen object. A real number value that is less
  3884. ; than 1.0 will be replaced with 1.0,
  3885. ;
  3886. ; Remarks
  3887. ; The miter length is the distance from the intersection of the line walls on the inside of the join to the
  3888. ; intersection of the line walls outside of the join. The miter length can be large when the angle between two
  3889. ; lines is small. The miter limit is the maximum allowed ratio of miter length to stroke width. The default
  3890. ; value is 10.0.
  3891. ; If the miter length of the join of the intersection exceeds the limit of the join, then the join will be
  3892. ; beveled to keep it within the limit of the join of the intersection
  3893.  
  3894. Return DllCall("gdiplus\GdipSetPenMiterLimit", "UPtr", pPen, "float", MiterLimit)
  3895. }
  3896.  
  3897. Gdip_SetPenUnit(pPen, Unit) {
  3898. ; Sets the unit of measurement for a pPen object.
  3899. ; Unit - New unit of measurement for the pen:
  3900. ; 0 - World coordinates, a non-physical unit
  3901. ; 1 - Display units
  3902. ; 2 - A unit is 1 pixel
  3903. ; 3 - A unit is 1 point or 1/72 inch
  3904. ; 4 - A unit is 1 inch
  3905. ; 5 - A unit is 1/300 inch
  3906. ; 6 - A unit is 1 millimeter
  3907.  
  3908. Return DllCall("gdiplus\GdipSetPenUnit", "UPtr", pPen, "int", Unit)
  3909. }
  3910.  
  3911. Gdip_GetPenDashCount(pPen) {
  3912. result := 0
  3913. E := DllCall("gdiplus\GdipGetPenDashCount", "UPtr", pPen, "int*", result)
  3914. If E
  3915. Return -1
  3916. Return result
  3917. }
  3918.  
  3919. Gdip_GetPenDashOffset(pPen) {
  3920. result := 0
  3921. E := DllCall("gdiplus\GdipGetPenDashOffset", "UPtr", pPen, "float*", result)
  3922. If E
  3923. Return -1
  3924. Return result
  3925. }
  3926.  
  3927. Gdip_GetPenLineJoin(pPen) {
  3928. result := 0
  3929. E := DllCall("gdiplus\GdipGetPenLineJoin", "UPtr", pPen, "int*", result)
  3930. If E
  3931. Return -1
  3932. Return result
  3933. }
  3934.  
  3935. Gdip_GetPenMiterLimit(pPen) {
  3936. result := 0
  3937. E := DllCall("gdiplus\GdipGetPenMiterLimit", "UPtr", pPen, "float*", result)
  3938. If E
  3939. Return -1
  3940. Return result
  3941. }
  3942.  
  3943. Gdip_GetPenUnit(pPen) {
  3944. result := 0
  3945. E := DllCall("gdiplus\GdipGetPenUnit", "UPtr", pPen, "int*", result)
  3946. If E
  3947. Return -1
  3948. Return result
  3949. }
  3950.  
  3951. Gdip_ClonePen(pPen) {
  3952. newPen := 0
  3953. gdipLastError := DllCall("gdiplus\GdipClonePen", "UPtr", pPen, "UPtr*", newPen)
  3954. Return newPen
  3955. }
  3956.  
  3957. ;#####################################################################################
  3958. ; pBrush functions [types: SolidFill, Texture, Hatch patterns, PathGradient and LinearGradient]
  3959. ; pBrush objects can be used by pPen objects via Gdip_SetPenBrushFill()
  3960. ;#####################################################################################
  3961.  
  3962. Gdip_BrushCreateSolid(ARGB:=0xff000000) {
  3963. pBrush := 0
  3964. E := DllCall("gdiplus\GdipCreateSolidFill", "UInt", ARGB, "UPtr*", pBrush)
  3965. return pBrush
  3966. }
  3967.  
  3968. Gdip_SetSolidFillColor(pBrush, ARGB) {
  3969. return DllCall("gdiplus\GdipSetSolidFillColor", "UPtr", pBrush, "UInt", ARGB)
  3970. }
  3971.  
  3972. Gdip_GetSolidFillColor(pBrush) {
  3973. ARGB := 0
  3974. E := DllCall("gdiplus\GdipGetSolidFillColor", "UPtr", pBrush, "UInt*", ARGB)
  3975. If E
  3976. return -1
  3977. return Format("{1:#x}", ARGB)
  3978. }
  3979.  
  3980. Gdip_BrushCreateHatch(ARGBfront, ARGBback, HatchStyle:=0) {
  3981. ; HatchStyle options:
  3982. ; Horizontal = 0
  3983. ; Vertical = 1
  3984. ; ForwardDiagonal = 2
  3985. ; BackwardDiagonal = 3
  3986. ; Cross = 4
  3987. ; DiagonalCross = 5
  3988. ; 05Percent = 6
  3989. ; 10Percent = 7
  3990. ; 20Percent = 8
  3991. ; 25Percent = 9
  3992. ; 30Percent = 10
  3993. ; 40Percent = 11
  3994. ; 50Percent = 12
  3995. ; 60Percent = 13
  3996. ; 70Percent = 14
  3997. ; 75Percent = 15
  3998. ; 80Percent = 16
  3999. ; 90Percent = 17
  4000. ; LightDownwardDiagonal = 18
  4001. ; LightUpwardDiagonal = 19
  4002. ; DarkDownwardDiagonal = 20
  4003. ; DarkUpwardDiagonal = 21
  4004. ; WideDownwardDiagonal = 22
  4005. ; WideUpwardDiagonal = 23
  4006. ; LightVertical = 24
  4007. ; LightHorizontal = 25
  4008. ; NarrowVertical = 26
  4009. ; NarrowHorizontal = 27
  4010. ; DarkVertical = 28
  4011. ; DarkHorizontal = 29
  4012. ; DashedDownwardDiagonal = 30
  4013. ; DashedUpwardDiagonal = 31
  4014. ; DashedHorizontal = 32
  4015. ; DashedVertical = 33
  4016. ; SmallConfetti = 34
  4017. ; LargeConfetti = 35
  4018. ; ZigZag = 36
  4019. ; Wave = 37
  4020. ; DiagonalBrick = 38
  4021. ; HorizontalBrick = 39
  4022. ; Weave = 40
  4023. ; Plaid = 41
  4024. ; Divot = 42
  4025. ; DottedGrid = 43
  4026. ; DottedDiamond = 44
  4027. ; Shingle = 45
  4028. ; Trellis = 46
  4029. ; Sphere = 47
  4030. ; SmallGrid = 48
  4031. ; SmallCheckerBoard = 49
  4032. ; LargeCheckerBoard = 50
  4033. ; OutlinedDiamond = 51
  4034. ; SolidDiamond = 52
  4035. ; Total = 53
  4036. pBrush := 0
  4037. gdipLastError := DllCall("gdiplus\GdipCreateHatchBrush", "int", HatchStyle, "UInt", ARGBfront, "UInt", ARGBback, "UPtr*", pBrush)
  4038. return pBrush
  4039. }
  4040.  
  4041. Gdip_GetHatchBackgroundColor(pHatchBrush) {
  4042. ARGB := 0
  4043. E := DllCall("gdiplus\GdipGetHatchBackgroundColor", "UPtr", pHatchBrush, "uint*", ARGB)
  4044. If E
  4045. Return -1
  4046. return Format("{1:#x}", ARGB)
  4047. }
  4048.  
  4049. Gdip_GetHatchForegroundColor(pHatchBrush) {
  4050. ARGB := 0
  4051. E := DllCall("gdiplus\GdipGetHatchForegroundColor", "UPtr", pHatchBrush, "uint*", ARGB)
  4052. If E
  4053. Return -1
  4054. return Format("{1:#x}", ARGB)
  4055. }
  4056.  
  4057. Gdip_GetHatchStyle(pHatchBrush) {
  4058. result := 0
  4059. E := DllCall("gdiplus\GdipGetHatchStyle", "UPtr", pHatchBrush, "int*", result)
  4060. If E
  4061. Return -1
  4062. Return result
  4063. }
  4064.  
  4065. ;#####################################################################################
  4066.  
  4067. ; Function: Gdip_CreateTextureBrush
  4068. ; Description: Creates a TextureBrush object based on an image, a wrap mode and a defining rectangle.
  4069. ;
  4070. ; pBitmap Pointer to an Image object
  4071. ; WrapMode Wrap mode that specifies how repeated copies of an image are used to tile an area when it is
  4072. ; painted with the texture brush:
  4073. ; 0 - Tile - Tiling without flipping
  4074. ; 1 - TileFlipX - Tiles are flipped horizontally as you move from one tile to the next in a row
  4075. ; 2 - TileFlipY - Tiles are flipped vertically as you move from one tile to the next in a column
  4076. ; 3 - TileFlipXY - Tiles are flipped horizontally as you move along a row and flipped vertically as you move along a column
  4077. ; 4 - Clamp - No tiling takes place
  4078. ; x, y x, y coordinates of the image portion to be used by this brush
  4079. ; w, h Width and height of the image portion
  4080. ; matrix A color matrix to alter the colors of the given pBitmap
  4081. ; ScaleX, ScaleY x, y scaling factor for the texture
  4082. ; Angle Rotates the texture at given angle
  4083. ;
  4084. ; return If the function succeeds, the return value is nonzero
  4085. ; notes If w and h are omitted, the entire pBitmap is used
  4086. ; Matrix can be omitted to just draw with no alteration to the ARGB channels
  4087. ; Matrix may be passed as a digit from 0.0 - 1.0 to change just transparency
  4088. ; Matrix can be passed as a matrix with "|" as delimiter.
  4089. ; Function modified by Marius Șucan, to allow use of color matrix and ImageAttributes object.
  4090.  
  4091. Gdip_CreateTextureBrush(pBitmap, WrapMode:=1, x:=0, y:=0, w:="", h:="", matrix:="", ScaleX:="", ScaleY:="", Angle:=0, ImageAttr:=0) {
  4092. pBrush := 0
  4093. If !(w && h)
  4094. {
  4095. gdipLastError := DllCall("gdiplus\GdipCreateTexture", "UPtr", pBitmap, "int", WrapMode, "UPtr*", pBrush)
  4096. } Else
  4097. {
  4098. If !ImageAttr
  4099. {
  4100. If !IsNumber(Matrix)
  4101. ImageAttr := Gdip_SetImageAttributesColorMatrix(Matrix)
  4102. Else If (Matrix != 1)
  4103. ImageAttr := Gdip_SetImageAttributesColorMatrix("1|0|0|0|0|0|1|0|0|0|0|0|1|0|0|0|0|0|" Matrix "|0|0|0|0|0|1")
  4104. } Else usrImageAttr := 1
  4105.  
  4106. If ImageAttr
  4107. {
  4108. gdipLastError := DllCall("gdiplus\GdipCreateTextureIA", "UPtr", pBitmap, "UPtr", ImageAttr, "float", x, "float", y, "float", w, "float", h, "UPtr*", pBrush)
  4109. If pBrush
  4110. Gdip_SetTextureWrapMode(pBrush, WrapMode)
  4111. } Else
  4112. gdipLastError := DllCall("gdiplus\GdipCreateTexture2", "UPtr", pBitmap, "int", WrapMode, "float", x, "float", y, "float", w, "float", h, "UPtr*", pBrush)
  4113. }
  4114.  
  4115. if (ImageAttr && usrImageAttr!=1)
  4116. Gdip_DisposeImageAttributes(ImageAttr)
  4117.  
  4118. If (ScaleX && ScaleX && pBrush)
  4119. Gdip_ScaleTextureTransform(pBrush, ScaleX, ScaleY)
  4120.  
  4121. If (Angle && pBrush)
  4122. Gdip_RotateTextureTransform(pBrush, Angle)
  4123.  
  4124. return pBrush
  4125. }
  4126.  
  4127. Gdip_RotateTextureTransform(pTexBrush, Angle, MatrixOrder:=0) {
  4128. ; MatrixOrder options:
  4129. ; Prepend = 0; The new operation is applied before the old operation.
  4130. ; Append = 1; The new operation is applied after the old operation.
  4131. ; Order of matrices multiplication:.
  4132.  
  4133. return DllCall("gdiplus\GdipRotateTextureTransform", "UPtr", pTexBrush, "float", Angle, "int", MatrixOrder)
  4134. }
  4135.  
  4136. Gdip_ScaleTextureTransform(pTexBrush, ScaleX, ScaleY, MatrixOrder:=0) {
  4137. return DllCall("gdiplus\GdipScaleTextureTransform", "UPtr", pTexBrush, "float", ScaleX, "float", ScaleY, "int", MatrixOrder)
  4138. }
  4139.  
  4140. Gdip_TranslateTextureTransform(pTexBrush, X, Y, MatrixOrder:=0) {
  4141. return DllCall("gdiplus\GdipTranslateTextureTransform", "UPtr", pTexBrush, "float", X, "float", Y, "int", MatrixOrder)
  4142. }
  4143.  
  4144. Gdip_MultiplyTextureTransform(pTexBrush, hMatrix, matrixOrder:=0) {
  4145. Return DllCall("gdiplus\GdipMultiplyTextureTransform", "UPtr", pTexBrush, "UPtr", hMatrix, "int", matrixOrder)
  4146. }
  4147.  
  4148. Gdip_SetTextureTransform(pTexBrush, hMatrix) {
  4149. return DllCall("gdiplus\GdipSetTextureTransform", "UPtr", pTexBrush, "UPtr", hMatrix)
  4150. }
  4151.  
  4152. Gdip_GetTextureTransform(pTexBrush) {
  4153. hMatrix := 0
  4154. gdipLastError := DllCall("gdiplus\GdipGetTextureTransform", "UPtr", pTexBrush, "UPtr*", hMatrix)
  4155. Return hMatrix
  4156. }
  4157.  
  4158. Gdip_ResetTextureTransform(pTexBrush) {
  4159. return DllCall("gdiplus\GdipResetTextureTransform", "UPtr", pTexBrush)
  4160. }
  4161.  
  4162. Gdip_SetTextureWrapMode(pTexBrush, WrapMode) {
  4163. ; WrapMode options:
  4164. ; 0 - Tile - Tiling without flipping
  4165. ; 1 - TileFlipX - Tiles are flipped horizontally as you move from one tile to the next in a row
  4166. ; 2 - TileFlipY - Tiles are flipped vertically as you move from one tile to the next in a column
  4167. ; 3 - TileFlipXY - Tiles are flipped horizontally as you move along a row and flipped vertically as you move along a column
  4168. ; 4 - Clamp - No tiling takes place
  4169.  
  4170. return DllCall("gdiplus\GdipSetTextureWrapMode", "UPtr", pTexBrush, "int", WrapMode)
  4171. }
  4172.  
  4173. Gdip_GetTextureWrapMode(pTexBrush) {
  4174. result := 0
  4175. E := DllCall("gdiplus\GdipGetTextureWrapMode", "UPtr", pTexBrush, "int*", result)
  4176. If E
  4177. return -1
  4178. Return result
  4179. }
  4180.  
  4181. Gdip_GetTextureImage(pTexBrush) {
  4182. pBitmapDest := 0
  4183. gdipLastError := DllCall("gdiplus\GdipGetTextureImage", "UPtr", pTexBrush, "UPtr*", pBitmapDest)
  4184. Return pBitmapDest
  4185. }
  4186.  
  4187. ;#####################################################################################
  4188. ; LinearGradientBrush functions
  4189. ;#####################################################################################
  4190.  
  4191. Gdip_CreateLineBrush(x1, y1, x2, y2, ARGB1, ARGB2, WrapMode:=1) {
  4192. return Gdip_CreateLinearGrBrush(x1, y1, x2, y2, ARGB1, ARGB2, WrapMode)
  4193. }
  4194.  
  4195. Gdip_CreateLinearGrBrush(x1, y1, x2, y2, ARGB1, ARGB2, WrapMode:=1) {
  4196. ; Linear gradient brush.
  4197. ; WrapMode specifies how the pattern is repeated once it exceeds the defined space
  4198. ; Tile [no flipping] = 0
  4199. ; TileFlipX = 1
  4200. ; TileFlipY = 2
  4201. ; TileFlipXY = 3
  4202. ; Clamp [no tiling] = 4
  4203. CreatePointF(PointF1, x1, y1)
  4204. CreatePointF(PointF2, x2, y2)
  4205. pLinearGradientBrush := 0
  4206. gdipLastError := DllCall("gdiplus\GdipCreateLineBrush", "UPtr", &PointF1, "UPtr", &PointF2, "Uint", ARGB1, "Uint", ARGB2, "int", WrapMode, "UPtr*", pLinearGradientBrush)
  4207. return pLinearGradientBrush
  4208. }
  4209.  
  4210. Gdip_SetLinearGrBrushColors(pLinearGradientBrush, ARGB1, ARGB2) {
  4211. return DllCall("gdiplus\GdipSetLineColors", "UPtr", pLinearGradientBrush, "UInt", ARGB1, "UInt", ARGB2)
  4212. }
  4213.  
  4214. Gdip_GetLinearGrBrushColors(pLinearGradientBrush, ByRef ARGB1, ByRef ARGB2) {
  4215. VarSetCapacity(colors, 8, 0)
  4216. E := DllCall("gdiplus\GdipGetLineColors", "UPtr", pLinearGradientBrush, "UPtr", &colors)
  4217. ARGB1 := NumGet(colors, 0, "UInt")
  4218. ARGB2 := NumGet(colors, 4, "UInt")
  4219. ARGB1 := Format("{1:#x}", ARGB1)
  4220. ARGB2 := Format("{1:#x}", ARGB2)
  4221. return E
  4222. }
  4223.  
  4224. Gdip_CreateLineBrushFromRect(x, y, w, h, ARGB1, ARGB2, LinearGradientMode:=1, WrapMode:=1) {
  4225. return Gdip_CreateLinearGrBrushFromRect(x, y, w, h, ARGB1, ARGB2, LinearGradientMode, WrapMode)
  4226. }
  4227.  
  4228. Gdip_CreateLinearGrBrushFromRect(x, y, w, h, ARGB1, ARGB2, LinearGradientMode:=1, WrapMode:=1) {
  4229. ; WrapMode options [LinearGradientMode]:
  4230. ; Horizontal = 0
  4231. ; Vertical = 1
  4232. ; ForwardDiagonal = 2
  4233. ; BackwardDiagonal = 3
  4234. CreateRectF(RectF, x, y, w, h)
  4235. pLinearGradientBrush := 0
  4236. gdipLastError := DllCall("gdiplus\GdipCreateLineBrushFromRect", "UPtr", &RectF, "int", ARGB1, "int", ARGB2, "int", LinearGradientMode, "int", WrapMode, "UPtr*", pLinearGradientBrush)
  4237. return pLinearGradientBrush
  4238. }
  4239.  
  4240. Gdip_GetLinearGrBrushGammaCorrection(pLinearGradientBrush) {
  4241. result := 0
  4242. gdipLastError := DllCall("gdiplus\GdipGetLineGammaCorrection", "UPtr", pLinearGradientBrush, "int*", result)
  4243. If gdipLastError
  4244. Return -1
  4245. Return result
  4246. }
  4247.  
  4248. Gdip_SetLinearGrBrushGammaCorrection(pLinearGradientBrush, UseGammaCorrection) {
  4249. Return DllCall("gdiplus\GdipSetLineGammaCorrection", "UPtr", pLinearGradientBrush, "int", UseGammaCorrection)
  4250. }
  4251.  
  4252. Gdip_GetLinearGrBrushRect(pLinearGradientBrush) {
  4253. VarSetCapacity(RectF, 16, 0)
  4254. E := DllCall("gdiplus\GdipGetLineRect", "UPtr", pLinearGradientBrush, "UPtr", &RectF)
  4255. If !E
  4256. Return RetrieveRectF(RectF)
  4257. Else
  4258. Return E
  4259. }
  4260.  
  4261. Gdip_ResetLinearGrBrushTransform(pLinearGradientBrush) {
  4262. return DllCall("gdiplus\GdipResetLineTransform", "UPtr", pLinearGradientBrush)
  4263. }
  4264.  
  4265. Gdip_ScaleLinearGrBrushTransform(pLinearGradientBrush, ScaleX, ScaleY, matrixOrder:=0) {
  4266. return DllCall("gdiplus\GdipScaleLineTransform", "UPtr", pLinearGradientBrush, "float", ScaleX, "float", ScaleY, "int", matrixOrder)
  4267. }
  4268.  
  4269. Gdip_MultiplyLinearGrBrushTransform(pLinearGradientBrush, hMatrix, matrixOrder:=0) {
  4270. Return DllCall("gdiplus\GdipMultiplyLineTransform", "UPtr", pLinearGradientBrush, "UPtr", hMatrix, "int", matrixOrder)
  4271. }
  4272.  
  4273. Gdip_TranslateLinearGrBrushTransform(pLinearGradientBrush, X, Y, matrixOrder:=0) {
  4274. return DllCall("gdiplus\GdipTranslateLineTransform", "UPtr", pLinearGradientBrush, "float", X, "float", Y, "int", matrixOrder)
  4275. }
  4276.  
  4277. Gdip_RotateLinearGrBrushTransform(pLinearGradientBrush, Angle, matrixOrder:=0) {
  4278. return DllCall("gdiplus\GdipRotateLineTransform", "UPtr", pLinearGradientBrush, "float", Angle, "int", matrixOrder)
  4279. }
  4280.  
  4281. Gdip_SetLinearGrBrushTransform(pLinearGradientBrush, pMatrix) {
  4282. return DllCall("gdiplus\GdipSetLineTransform", "UPtr", pLinearGradientBrush, "UPtr", pMatrix)
  4283. }
  4284.  
  4285. Gdip_GetLinearGrBrushTransform(pLineGradientBrush) {
  4286. pMatrix := 0
  4287. gdipLastError := DllCall("gdiplus\GdipGetLineTransform", "UPtr", pLineGradientBrush, "UPtr*", pMatrix)
  4288. Return pMatrix
  4289. }
  4290.  
  4291. Gdip_RotateLinearGrBrushAtCenter(pLinearGradientBrush, Angle, MatrixOrder:=1) {
  4292. ; function by Marius Șucan
  4293. ; based on Gdip_RotatePathAtCenter() by RazorHalo
  4294.  
  4295. Rect := Gdip_GetLinearGrBrushRect(pLinearGradientBrush) ; boundaries
  4296. cX := Rect.x + (Rect.w / 2)
  4297. cY := Rect.y + (Rect.h / 2)
  4298. pMatrix := Gdip_CreateMatrix()
  4299. Gdip_TranslateMatrix(pMatrix, -cX , -cY)
  4300. Gdip_RotateMatrix(pMatrix, Angle, MatrixOrder)
  4301. Gdip_TranslateMatrix(pMatrix, cX, cY, MatrixOrder)
  4302. E := Gdip_SetLinearGrBrushTransform(pLinearGradientBrush, pMatrix)
  4303. Gdip_DeleteMatrix(pMatrix)
  4304. Return E
  4305. }
  4306.  
  4307. Gdip_GetLinearGrBrushWrapMode(pLinearGradientBrush) {
  4308. result := 0
  4309. E := DllCall("gdiplus\GdipGetLineWrapMode", "UPtr", pLinearGradientBrush, "int*", result)
  4310. If E
  4311. return -1
  4312. Return result
  4313. }
  4314.  
  4315. Gdip_SetLinearGrBrushLinearBlend(pLinearGradientBrush, nFocus, nScale) {
  4316. ; https://purebasic.developpez.com/tutoriels/gdi/documentation/GdiPlus/LinearGradientBrush/html/GdipSetLineLinearBlend.html
  4317. Return DllCall("gdiplus\GdipSetLineLinearBlend", "UPtr", pLinearGradientBrush, "float", nFocus, "float", nScale)
  4318. }
  4319.  
  4320. Gdip_SetLinearGrBrushSigmaBlend(pLinearGradientBrush, nFocus, nScale) {
  4321. ; https://purebasic.developpez.com/tutoriels/gdi/documentation/GdiPlus/LinearGradientBrush/html/GdipSetLineSigmaBlend.html
  4322. Return DllCall("gdiplus\GdipSetLineSigmaBlend", "UPtr", pLinearGradientBrush, "float", nFocus, "float", nScale)
  4323. }
  4324.  
  4325. Gdip_SetLinearGrBrushWrapMode(pLinearGradientBrush, WrapMode) {
  4326. Return DllCall("gdiplus\GdipSetLineWrapMode", "UPtr", pLinearGradientBrush, "int", WrapMode)
  4327. }
  4328.  
  4329. Gdip_GetLinearGrBrushBlendCount(pLinearGradientBrush) {
  4330. result := 0
  4331. E := DllCall("gdiplus\GdipGetLineBlendCount", "UPtr", pLinearGradientBrush, "int*", result)
  4332. If E
  4333. return -1
  4334. Return result
  4335. }
  4336.  
  4337. Gdip_SetLinearGrBrushPresetBlend(pBrush, _positions, _colors, pathBrush:=0) {
  4338. ; function by TheArkive modified by Marius Șucan
  4339. ; the function accepts only arrays for _positions and _colors
  4340.  
  4341. elements := _colors.Length()
  4342. If (elements>_positions.Length() || elements<2)
  4343. Return 2 ; invalid parameters
  4344.  
  4345. _positions.InsertAt(1, 0.0), _positions.Push(1.0)
  4346. _colors.Push(_colors[elements])
  4347. _colors.InsertAt(1, _colors[1])
  4348. elements := _colors.Length()
  4349.  
  4350. VarSetCapacity(COLORS, elements*4, 0)
  4351. For i, _color in _colors
  4352. NumPut(_color, COLORS, (i-1)*4, "UInt")
  4353.  
  4354. VarSetCapacity(POSITIONS, elements*4, 0)
  4355. For i, _pos in _positions
  4356. NumPut(_pos, POSITIONS, (i-1)*4, "Float")
  4357.  
  4358. func2exec := (pathBrush=1) ? "GdipSetPathGradientPresetBlend" : "GdipSetLinePresetBlend"
  4359. Return DllCall("gdiplus\" func2exec, "UPtr", pBrush, "UPtr", &COLORS, "UPtr", &POSITIONS, "Int", elements)
  4360. }
  4361.  
  4362. Gdip_SetPathGradientPresetBlend(pBrush, _positions, _colors) {
  4363. Return Gdip_SetLinearGrBrushPresetBlend(pBrush, _positions, _colors, 1)
  4364. }
  4365.  
  4366. Gdip_CloneBrush(pBrush) {
  4367. pBrushClone := 0
  4368. gdipLastError := DllCall("gdiplus\GdipCloneBrush", "UPtr", pBrush, "UPtr*", pBrushClone)
  4369. return pBrushClone
  4370. }
  4371.  
  4372. Gdip_GetBrushType(pBrush) {
  4373. ; Possible brush types [return values]:
  4374. ; 0 - Solid color
  4375. ; 1 - Hatch pattern fill
  4376. ; 2 - Texture fill
  4377. ; 3 - Path gradient
  4378. ; 4 - Linear gradient
  4379. ; -1 - error
  4380.  
  4381. result := 0
  4382. E := DllCall("gdiplus\GdipGetBrushType", "UPtr", pBrush, "int*", result)
  4383. If E
  4384. return -1
  4385. Return result
  4386. }
  4387.  
  4388. ;#####################################################################################
  4389. ; Delete resources
  4390. ;#####################################################################################
  4391.  
  4392. Gdip_DeleteRegion(hRegion) {
  4393. If (hRegion!="")
  4394. return DllCall("gdiplus\GdipDeleteRegion", "UPtr", hRegion)
  4395. }
  4396.  
  4397. Gdip_DeletePen(pPen) {
  4398. If (pPen!="")
  4399. return DllCall("gdiplus\GdipDeletePen", "UPtr", pPen)
  4400. }
  4401.  
  4402. Gdip_DeleteBrush(pBrush) {
  4403. If (pBrush!="")
  4404. return DllCall("gdiplus\GdipDeleteBrush", "UPtr", pBrush)
  4405. }
  4406.  
  4407. Gdip_DisposeBitmap(pBitmap, noErr:=0) {
  4408. Return Gdip_DisposeImage(pBitmap, noErr)
  4409. }
  4410.  
  4411. Gdip_DisposeImage(pBitmap, noErr:=0) {
  4412. ; modified by Marius Șucan to help avoid crashes
  4413. ; by disposing a non-existent pBitmap
  4414.  
  4415. If (StrLen(pBitmap)<=2 && noErr=1)
  4416. Return 0
  4417.  
  4418. r := DllCall("gdiplus\GdipDisposeImage", "UPtr", pBitmap)
  4419. If (r=2 || r=1) && (noErr=1)
  4420. r := 0
  4421. Return r
  4422. }
  4423.  
  4424. Gdip_DeleteGraphics(pGraphics) {
  4425. If (pGraphics!="")
  4426. return DllCall("gdiplus\GdipDeleteGraphics", "UPtr", pGraphics)
  4427. }
  4428.  
  4429. Gdip_DisposeImageAttributes(ImageAttr) {
  4430. If (ImageAttr!="")
  4431. return DllCall("gdiplus\GdipDisposeImageAttributes", "UPtr", ImageAttr)
  4432. }
  4433.  
  4434. Gdip_DeleteFont(hFont) {
  4435. If (hFont!="")
  4436. return DllCall("gdiplus\GdipDeleteFont", "UPtr", hFont)
  4437. }
  4438.  
  4439. Gdip_DeleteStringFormat(hStringFormat) {
  4440. return DllCall("gdiplus\GdipDeleteStringFormat", "UPtr", hStringFormat)
  4441. }
  4442.  
  4443. Gdip_DeleteFontFamily(hFontFamily) {
  4444. If (hFontFamily!="")
  4445. return DllCall("gdiplus\GdipDeleteFontFamily", "UPtr", hFontFamily)
  4446. }
  4447.  
  4448. Gdip_DeletePrivateFontCollection(hFontCollection) {
  4449. If (hFontCollection!="")
  4450. return DllCall("gdiplus\GdipDeletePrivateFontCollection", "UPtr*", hFontCollection)
  4451. }
  4452.  
  4453. Gdip_DeleteMatrix(hMatrix) {
  4454. If (hMatrix!="")
  4455. return DllCall("gdiplus\GdipDeleteMatrix", "UPtr", hMatrix)
  4456. }
  4457.  
  4458. ;#####################################################################################
  4459. ; Text functions
  4460. ; Easy to use functions:
  4461. ; Gdip_DrawOrientedString() - allows to draw strings or string contours/outlines,
  4462. ; or both, rotated at any angle. On success, its boundaries are returned.
  4463. ; Gdip_DrawStringAlongPolygon() - allows you to draw a string along a pPath
  4464. ; or multiple given coordinates.
  4465. ; Gdip_TextToGraphics() - allows you to draw strings or measure their boundaries.
  4466. ;#####################################################################################
  4467.  
  4468. Gdip_DrawOrientedString(pGraphics, String, FontName, Size, Style, X, Y, Width, Height, Angle:=0, pBrush:=0, pPen:=0, Align:=0, ScaleX:=1) {
  4469. ; FontName can be a name of an already installed font or it can point to a font file
  4470. ; to be loaded and used to draw the string.
  4471. ; It can also be the handle of a hFontFamily object. Use the "hFont:"" prefix.
  4472.  
  4473. ; Size - in em, in world units [font size]
  4474. ; Remarks: a high value might be required; over 60, 90... to see the text.
  4475. ; X, Y - coordinates for the rectangle where the text will be drawn
  4476. ; W, H - width and heigh for the rectangle where the text will be drawn
  4477. ; Angle - the angle at which the text should be rotated
  4478.  
  4479. ; pBrush - a pointer to a pBrush object to fill the text with
  4480. ; pPen - a pointer to a pPen object to draw the outline [contour] of the text
  4481. ; Remarks: both are optional, but one at least must be given, otherwise
  4482. ; the function fails, returns -3.
  4483. ; For example, if you want only the contour of the text, pass only a pPen object.
  4484.  
  4485. ; Align options:
  4486. ; Near/left = 0
  4487. ; Center = 1
  4488. ; Far/right = 2
  4489.  
  4490. ; Style options:
  4491. ; Regular = 0
  4492. ; Bold = 1
  4493. ; Italic = 2
  4494. ; BoldItalic = 3
  4495. ; Underline = 4
  4496. ; Strikeout = 8
  4497.  
  4498. ; ScaleX - if you want to distort the text [make it wider or narrower]
  4499.  
  4500. ; On success, the function returns an array:
  4501. ; PathBounds.x , PathBounds.y , PathBounds.w , PathBounds.h
  4502.  
  4503. If (!pBrush && !pPen)
  4504. Return -3
  4505.  
  4506. If (SubStr(FontName, 1, 6)="hfont:")
  4507. {
  4508. wasGivenFontFamily := 1
  4509. hFontFamily := SubStr(FontName, 7) ; to be used in conjunction with Gdip_NewPrivateFontCollection()
  4510. } Else If RegExMatch(FontName, "^(.\:\\.)")
  4511. {
  4512. ; it might crash if you execute this in a looped sequence
  4513. hFontCollection := Gdip_NewPrivateFontCollection()
  4514. hFontFamily := Gdip_CreateFontFamilyFromFile(FontName, hFontCollection)
  4515. } Else hFontFamily := Gdip_FontFamilyCreate(FontName)
  4516.  
  4517. If !hFontFamily
  4518. hFontFamily := Gdip_FontFamilyCreateGeneric(1)
  4519.  
  4520. If !hFontFamily
  4521. {
  4522. If (hFontCollection!="")
  4523. Gdip_DeletePrivateFontCollection(hFontCollection)
  4524. Return -1
  4525. }
  4526.  
  4527. FormatStyle := 0x4000
  4528. hStringFormat := Gdip_StringFormatCreate(FormatStyle)
  4529. If !hStringFormat
  4530. hStringFormat := Gdip_StringFormatGetGeneric(1)
  4531.  
  4532. If !hStringFormat
  4533. {
  4534. If (hFontFamily!="" && !wasGivenFontFamily)
  4535. Gdip_DeleteFontFamily(hFontFamily)
  4536.  
  4537. If (hFontCollection!="")
  4538. Gdip_DeletePrivateFontCollection(hFontCollection)
  4539. Return -2
  4540. }
  4541.  
  4542. Gdip_SetStringFormatTrimming(hStringFormat, 3)
  4543. Gdip_SetStringFormatAlign(hStringFormat, Align)
  4544. pPath := Gdip_CreatePath()
  4545.  
  4546. E := Gdip_AddPathString(pPath, String, hFontFamily, Style, Size, hStringFormat, X, Y, Width, Height)
  4547. If (ScaleX>0 && ScaleX!=1)
  4548. {
  4549. hMatrix := Gdip_CreateMatrix()
  4550. Gdip_ScaleMatrix(hMatrix, ScaleX, 1)
  4551. Gdip_TransformPath(pPath, hMatrix)
  4552. Gdip_DeleteMatrix(hMatrix)
  4553. }
  4554.  
  4555. Gdip_RotatePathAtCenter(pPath, Angle)
  4556. If (!E && pBrush)
  4557. E := Gdip_FillPath(pGraphics, pBrush, pPath)
  4558. If (!E && pPen)
  4559. E := Gdip_DrawPath(pGraphics, pPen, pPath)
  4560.  
  4561. PathBounds := Gdip_GetPathWorldBounds(pPath)
  4562. Gdip_DeleteStringFormat(hStringFormat)
  4563. If (hFontFamily!="" && !wasGivenFontFamily)
  4564. Gdip_DeleteFontFamily(hFontFamily)
  4565.  
  4566. Gdip_DeletePath(pPath)
  4567. If (hFontCollection!="")
  4568. Gdip_DeletePrivateFontCollection(hFontCollection)
  4569. Return E ? E : PathBounds
  4570. }
  4571.  
  4572. Gdip_TextToGraphics(pGraphics, Text, Options, Font:="Arial", Width:="", Height:="", Measure:=0, userBrush:=0, Unit:=0, acceptTabStops:=0) {
  4573. ; The FONT parameter can be a name of an already installed font or it can point to a font file
  4574. ; to be loaded and used to draw the string.
  4575. ; It can also be the handle of a hFontFamily object. Use the "hFont:"" prefix.
  4576. ;
  4577. ; Set Unit to 3 [Pts] to have the texts rendered at the same size
  4578. ; with the texts rendered in GUIs with -DPIscale
  4579. ;
  4580. ; userBrush - if a pBrush object is passed, this will be used to draw the text
  4581. ;
  4582. ; Remarks: by changing the alignment, the text will be rendered at a different X
  4583. ; coordinate position; the position of the text is set relative to
  4584. ; the given X position coordinate and the text width..
  4585. ; See also Gdip_SetStringFormatAlign().
  4586. ;
  4587. ; On success, the function returns a string in the following format:
  4588. ; "x|y|width|height|chars|lines"
  4589. ; The first four elements represent the boundaries of the text.
  4590. ; The string is returned by Gdip_MeasureString()
  4591.  
  4592. Static Styles := "Regular|Bold|Italic|BoldItalic|Underline|Strikeout"
  4593. , Alignments := "Near|Left|Centre|Center|Far|Right"
  4594.  
  4595. OWidth := Width
  4596. IWidth := Width, IHeight:= Height
  4597. pattern_opts := (A_AhkVersion < "2") ? "iO)" : "i)"
  4598. RegExMatch(Options, pattern_opts "X([\-\d\.]+)(p*)", xpos)
  4599. RegExMatch(Options, pattern_opts "Y([\-\d\.]+)(p*)", ypos)
  4600. RegExMatch(Options, pattern_opts "W([\-\d\.]+)(p*)", PWidth)
  4601. RegExMatch(Options, pattern_opts "H([\-\d\.]+)(p*)", Height)
  4602. RegExMatch(Options, pattern_opts "C(?!(entre|enter))([a-f\d]+)", Colour)
  4603. RegExMatch(Options, pattern_opts "Top|Up|Bottom|Down|vCentre|vCenter", vPos)
  4604. RegExMatch(Options, pattern_opts "NoWrap", NoWrap)
  4605. RegExMatch(Options, pattern_opts "R(\d)", Rendering)
  4606. RegExMatch(Options, pattern_opts "S(\d+)(p*)", Size)
  4607. Width := PWidth
  4608.  
  4609. if !(IWidth && IHeight) && ((xpos && xpos[2]) || (ypos && ypos[2]) || (Width && Width[2]) || (Height && Height[2]) || (Size && Size[2]))
  4610. return -1
  4611.  
  4612. if (Colour && IsInteger(Colour[2]) && !userBrush && StrLen(Colour[2])!=6 && StrLen(Colour[2])!=8)
  4613. {
  4614. If !Gdip_DeleteBrush(Gdip_CloneBrush(Colour[2]))
  4615. userBrush := Colour[2]
  4616. }
  4617.  
  4618. fColor := (Colour && Colour[2]) ? Colour[2] : "ff000000"
  4619. If (StrLen(fColor)=6)
  4620. fColor := "ff" fColor
  4621.  
  4622. if (fColor && !userBrush)
  4623. pBrush := Gdip_BrushCreateSolid("0x" fColor)
  4624.  
  4625. Style := 0
  4626. For eachStyle, valStyle in StrSplit(Styles, "|")
  4627. {
  4628. if RegExMatch(Options, "\b" valStyle)
  4629. Style |= (valStyle != "StrikeOut") ? (A_Index-1) : 8
  4630. }
  4631.  
  4632. Align := 0
  4633. For eachAlignment, valAlignment in StrSplit(Alignments, "|")
  4634. {
  4635. if RegExMatch(Options, "\b" valAlignment)
  4636. Align |= A_Index//2.1 ; 0|0|1|1|2|2
  4637. }
  4638.  
  4639. xpos := (xpos && (xpos[1] != "")) ? xpos[2] ? IWidth*(xpos[1]/100) : xpos[1] : 0
  4640. ypos := (ypos && (ypos[1] != "")) ? ypos[2] ? IHeight*(ypos[1]/100) : ypos[1] : 0
  4641. Width := (Width && Width[1]) ? Width[2] ? IWidth*(Width[1]/100) : Width[1] : IWidth
  4642. Height := (Height && Height[1]) ? Height[2] ? IHeight*(Height[1]/100) : Height[1] : IHeight
  4643. Rendering := (Rendering && (Rendering[1] >= 0) && (Rendering[1] <= 5)) ? Rendering[1] : 4
  4644. Size := (Size && (Size[1] > 0)) ? Size[2] ? IHeight*(Size[1]/100) : Size[1] : 12
  4645. If (SubStr(Font, 1, 6)="hfont:")
  4646. {
  4647. wasGivenFontFamily := 1
  4648. hFontFamily := SubStr(Font, 7) ; to be used in conjunction with Gdip_NewPrivateFontCollection()
  4649. } Else If RegExMatch(Font, "^(.\:\\.)")
  4650. {
  4651. ; it might crash if you execute this in a looped sequence
  4652. hFontCollection := Gdip_NewPrivateFontCollection()
  4653. hFontFamily := Gdip_CreateFontFamilyFromFile(Font, hFontCollection)
  4654. } Else hFontFamily := Gdip_FontFamilyCreate(Font)
  4655.  
  4656. If !hFontFamily
  4657. hFontFamily := Gdip_FontFamilyCreateGeneric(1)
  4658.  
  4659. hFont := Gdip_FontCreate(hFontFamily, Size, Style, Unit)
  4660. FormatStyle := NoWrap ? 0x4000 | 0x1000 : 0x4000
  4661. hStringFormat := Gdip_StringFormatCreate(FormatStyle)
  4662. If !hStringFormat
  4663. hStringFormat := Gdip_StringFormatGetGeneric(1)
  4664.  
  4665. thisBrush := userBrush ? userBrush : pBrush
  4666. if !(hFontFamily && hFont && hStringFormat && thisBrush && pGraphics)
  4667. {
  4668. E := !pGraphics ? -2 : !hFontFamily ? -3 : !hFont ? -4 : !hStringFormat ? -5 : !pBrush ? -6 : 0
  4669. If pBrush
  4670. Gdip_DeleteBrush(pBrush)
  4671. If hStringFormat
  4672. Gdip_DeleteStringFormat(hStringFormat)
  4673. If hFont
  4674. Gdip_DeleteFont(hFont)
  4675. If (hFontFamily && !wasGivenFontFamily)
  4676. Gdip_DeleteFontFamily(hFontFamily)
  4677. If hFontCollection
  4678. Gdip_DeletePrivateFontCollection(hFontCollection)
  4679. return E
  4680. }
  4681.  
  4682. CreateRectF(RC, xpos, ypos, Width, Height)
  4683. If (acceptTabStops=1)
  4684. Gdip_SetStringFormatTabStops(hStringFormat, [50,100,200])
  4685.  
  4686. Gdip_SetStringFormatAlign(hStringFormat, Align)
  4687. If InStr(Options, "autotrim")
  4688. Gdip_SetStringFormatTrimming(hStringFormat, 3)
  4689.  
  4690. Gdip_SetTextRenderingHint(pGraphics, Rendering)
  4691. ReturnRC := Gdip_MeasureString(pGraphics, Text, hFont, hStringFormat, RC)
  4692. ReturnRCtest := StrSplit(ReturnRC, "|")
  4693. testX := Floor(ReturnRCtest[1]) - 2
  4694. If (testX>xpos && NoWrap && (PWidth>2 || OWidth>2))
  4695. {
  4696. ; error correction of posX for different text alignments
  4697. ; when width is given, but no text wrap
  4698. nxpos := Floor(xpos - (testX - xpos))
  4699. CreateRectF(RC, nxpos, ypos, Width, Height)
  4700. ReturnRC := Gdip_MeasureString(pGraphics, Text, hFont, hStringFormat, RC)
  4701. ; MsgBox, % nxpos "--" xpos "--" ypos "`n" width "--" height "`n" ReturnRC
  4702. }
  4703.  
  4704. If vPos
  4705. {
  4706. ReturnRC := StrSplit(ReturnRC, "|")
  4707. if (vPos[0] = "vCentre") || (vPos[0] = "vCenter")
  4708. ypos += (Height-ReturnRC[4])//2
  4709. else if (vPos[0] = "Top") || (vPos[0] = "Up")
  4710. ypos += 0
  4711. else if (vPos[0] = "Bottom") || (vPos[0] = "Down")
  4712. ypos += Height-ReturnRC[4]
  4713.  
  4714. CreateRectF(RC, xpos, ypos, Width, ReturnRC[4])
  4715. ReturnRC := Gdip_MeasureString(pGraphics, Text, hFont, hStringFormat, RC)
  4716. }
  4717.  
  4718. if !Measure
  4719. _E := Gdip_DrawString(pGraphics, Text, hFont, hStringFormat, thisBrush, RC)
  4720.  
  4721. If pBrush
  4722. Gdip_DeleteBrush(pBrush)
  4723. Gdip_DeleteStringFormat(hStringFormat)
  4724. Gdip_DeleteFont(hFont)
  4725. If (hFontFamily && !wasGivenFontFamily)
  4726. Gdip_DeleteFontFamily(hFontFamily)
  4727. If hFontCollection
  4728. Gdip_DeletePrivateFontCollection(hFontCollection)
  4729.  
  4730. return _E ? _E : ReturnRC
  4731. }
  4732.  
  4733. Gdip_DrawString(pGraphics, sString, hFont, hStringFormat, pBrush, ByRef RectF) {
  4734. return DllCall("gdiplus\GdipDrawString"
  4735. , "UPtr", pGraphics
  4736. , "WStr", sString
  4737. , "int", -1
  4738. , "UPtr", hFont
  4739. , "UPtr", &RectF
  4740. , "UPtr", hStringFormat
  4741. , "UPtr", pBrush)
  4742. }
  4743.  
  4744. Gdip_MeasureString(pGraphics, sString, hFont, hStringFormat, ByRef RectF) {
  4745. ; The function returns a string in the following format:
  4746. ; "x|y|width|height|chars|lines"
  4747. ; The first four elements represent the boundaries of the text
  4748.  
  4749. VarSetCapacity(RC, 16, 0)
  4750. Chars := 0, Lines := 0
  4751. gdipLastError := DllCall("gdiplus\GdipMeasureString"
  4752. , "UPtr", pGraphics
  4753. , "WStr", sString
  4754. , "int", -1
  4755. , "UPtr", hFont
  4756. , "UPtr", &RectF
  4757. , "UPtr", hStringFormat
  4758. , "UPtr", &RC
  4759. , "uint*", Chars
  4760. , "uint*", Lines)
  4761.  
  4762. r := &RC ? NumGet(RC, 0, "float") "|" NumGet(RC, 4, "float") "|" NumGet(RC, 8, "float") "|" NumGet(RC, 12, "float") "|" Chars "|" Lines : 0
  4763. RC := ""
  4764. return r
  4765. }
  4766.  
  4767. Gdip_DrawStringAlongPolygon(pGraphics, String, FontName, FontSize, Style, pBrush, DriverPoints:=0, pPath:=0, minDist:=0, flatness:=4, hMatrix:=0, Unit:=0) {
  4768. ; The function allows you to draw a text string along a polygonal line.
  4769. ; Each point on the line corresponds to a letter.
  4770. ; If they are too close, the letters will overlap. If they are fewer than
  4771. ; the string length, the text is going to be truncated.
  4772. ; If given, a pPath object will be segmented according to the precision defined by «flatness».
  4773. ;
  4774. ; pGraphics - a pointer to a pGraphics object where to draw the text
  4775. ; FontName can be the name of an already installed font or it can point to a font file
  4776. ; to be loaded and used to draw the string.
  4777. ; FontSize - in em, in world units
  4778. ; a high value might be required; over 60, 90... to see the text.
  4779. ; pBrush - a pointer to a pBrush object to fill the text with
  4780. ; DriverPoints - a string with X, Y coordinates where the letters
  4781. ; of the string will be drawn. Each X/Y pair corresponds to a letter.
  4782. ; "x1,y1|x2,y2|x3,y3" [...and so on]
  4783. ; pPath - A pointer to a pPath object.
  4784. ; It will be used only if DriverPoints parameter is omitted.
  4785. ; If both DriverPoints and pPath are omitted, the function will return -4.
  4786. ; Intermmediate points will be generated if there are more glyphs / letters than defined points.
  4787. ;
  4788. ; flatness - from 0.1 to 5; the precision for arcs, beziers and curves segmentation;
  4789. ; the lower the number is, the higher density of points is;
  4790. ; it applies only for given pPath objects
  4791. ;
  4792. ; minDist - the minimum distance between letters; by default it is FontSize/4
  4793. ; does not apply for pPath objects; use the flatness parameter to control points density
  4794. ;
  4795. ; Style options:
  4796. ; Regular = 0
  4797. ; Bold = 1
  4798. ; Italic = 2
  4799. ; BoldItalic = 3
  4800. ; Underline = 4
  4801. ; Strikeout = 8
  4802. ;
  4803. ; Set Unit to 3 [Pts] to have the texts rendered at the same size
  4804. ; with the texts rendered in GUIs with -DPIscale
  4805.  
  4806. If (!minDist || minDist<1)
  4807. minDist := FontSize//4 + 1
  4808.  
  4809. If (pPath && !DriverPoints)
  4810. {
  4811. newPath := Gdip_ClonePath(pPath)
  4812. Gdip_PathOutline(newPath, flatness)
  4813. DriverPoints := Gdip_GetPathPoints(newPath)
  4814. Gdip_DeletePath(newPath)
  4815. If !DriverPoints
  4816. Return -5
  4817. }
  4818.  
  4819. If (!pPath && !DriverPoints)
  4820. Return -4
  4821.  
  4822. If (SubStr(FontName, 1, 6)="hfont:")
  4823. {
  4824. wasGivenFontFamily := 1
  4825. hFontFamily := SubStr(FontName, 7) ; to be used in conjunction with Gdip_NewPrivateFontCollection()
  4826. } Else If RegExMatch(FontName, "^(.\:\\.)")
  4827. {
  4828. ; it might crash if you execute this in a looped sequence
  4829. hFontCollection := Gdip_NewPrivateFontCollection()
  4830. hFontFamily := Gdip_CreateFontFamilyFromFile(FontName, hFontCollection)
  4831. } Else hFontFamily := Gdip_FontFamilyCreate(FontName)
  4832.  
  4833. If !hFontFamily
  4834. hFontFamily := Gdip_FontFamilyCreateGeneric(1)
  4835.  
  4836. If !hFontFamily
  4837. {
  4838. If hFontCollection
  4839. Gdip_DeletePrivateFontCollection(hFontCollection)
  4840. Return -1
  4841. }
  4842.  
  4843. hFont := Gdip_FontCreate(hFontFamily, FontSize, Style, Unit)
  4844. If !hFont
  4845. {
  4846. If (hFontCollection!="")
  4847. Gdip_DeletePrivateFontCollection(hFontCollection)
  4848. If (hFontFamily!="" && !wasGivenFontFamily)
  4849. Gdip_DeleteFontFamily(hFontFamily)
  4850. Return -2
  4851. }
  4852.  
  4853. Points := StrSplit(DriverPoints, "|")
  4854. PointsCount := Points.Length()
  4855. If (PointsCount<2)
  4856. {
  4857. If hFontCollection
  4858. Gdip_DeletePrivateFontCollection(hFontCollection)
  4859.  
  4860. Gdip_DeleteFont(hFont)
  4861. If (hFontFamily!="" && !wasGivenFontFamily)
  4862. Gdip_DeleteFontFamily(hFontFamily)
  4863. Return -3
  4864. }
  4865.  
  4866. txtLen := StrLen(String)
  4867. If (PointsCount<txtLen)
  4868. {
  4869. loopsMax := txtLen * 3
  4870. newDriverPoints := DriverPoints
  4871. Loop %loopsMax%
  4872. {
  4873. newDriverPoints := GenerateIntermediatePoints(newDriverPoints, minDist, totalResult)
  4874. If (totalResult>=txtLen)
  4875. Break
  4876. }
  4877. String := SubStr(String, 1, totalResult)
  4878. } Else newDriverPoints := DriverPoints
  4879.  
  4880. E := Gdip_DrawDrivenString(pGraphics, String, hFont, pBrush, newDriverPoints, 1, hMatrix)
  4881. Gdip_DeleteFont(hFont)
  4882. If (hFontFamily!="" && !wasGivenFontFamily)
  4883. Gdip_DeleteFontFamily(hFontFamily)
  4884.  
  4885. If (hFontCollection!="")
  4886. Gdip_DeletePrivateFontCollection(hFontCollection)
  4887. return E
  4888. }
  4889.  
  4890. GenerateIntermediatePoints(PointsList, minDist, ByRef resultPointsCount) {
  4891. ; function used by Gdip_DrawFreeFormString()
  4892. AllPoints := StrSplit(PointsList, "|")
  4893. PointsCount := AllPoints.Length()
  4894. thizIndex := 0.5
  4895. resultPointsCount := 0
  4896. loopsMax := PointsCount*2
  4897. newPointsList := ""
  4898. Loop %loopsMax%
  4899. {
  4900. thizIndex += 0.5
  4901. thisIndex := InStr(thizIndex, ".5") ? thizIndex : Trim(Round(thizIndex))
  4902. thisPoint := AllPoints[thisIndex]
  4903. theseCoords := StrSplit(thisPoint, ",")
  4904. If (theseCoords[1]!="" && theseCoords[2]!="")
  4905. {
  4906. resultPointsCount++
  4907. newPointsList .= theseCoords[1] "," theseCoords[2] "|"
  4908. } Else
  4909. {
  4910. aIndex := Trim(Round(thizIndex - 0.5))
  4911. bIndex := Trim(Round(thizIndex + 0.5))
  4912. theseAcoords := StrSplit(AllPoints[aIndex], ",")
  4913. theseBcoords := StrSplit(AllPoints[bIndex], ",")
  4914. If (theseAcoords[1]!="" && theseAcoords[2]!="")
  4915. && (theseBcoords[1]!="" && theseBcoords[2]!="")
  4916. {
  4917. newPosX := (theseAcoords[1] + theseBcoords[1])//2
  4918. newPosY := (theseAcoords[2] + theseBcoords[2])//2
  4919. distPosX := newPosX - theseAcoords[1]
  4920. distPosY := newPosY - theseAcoords[2]
  4921. If (distPosX>minDist || distPosY>minDist)
  4922. {
  4923. newPointsList .= newPosX "," newPosY "|"
  4924. resultPointsCount++
  4925. }
  4926. }
  4927. }
  4928. }
  4929. If !newPointsList
  4930. Return PointsList
  4931. Return Trim(newPointsList, "|")
  4932. }
  4933.  
  4934. Gdip_DrawDrivenString(pGraphics, String, hFont, pBrush, DriverPoints, Flags:=1, hMatrix:=0) {
  4935. ; Parameters:
  4936. ; pBrush - pointer to a pBrush object used to draw the text into the given pGraphics
  4937. ; hFont - pointer for a Font object used to draw the given text that determines font, size and style
  4938. ; hMatrix - pointer to a transformation matrix object that specifies the transformation matrix to apply to each value in the DriverPoints
  4939. ; DriverPoints - a list of points coordinates that determines where the glyphs [letters] will be drawn
  4940. ; "x1,y1|x2,y2|x3,y3" [... and so on]
  4941. ; Flags options:
  4942. ; 1 - The string array contains Unicode character values. If this flag is not set, each value in $vText is
  4943. ; interpreted as an index to a font glyph that defines a character to be displayed
  4944. ; 2 - The string is displayed vertically
  4945. ; 4 - The glyph positions are calculated from the position of the first glyph. If this flag is not set, the
  4946. ; glyph positions are obtained from an array of coordinates ($aPoints)
  4947. ; 8 - Less memory should be used for cache of antialiased glyphs. This also produces lower quality. If this
  4948. ; flag is not set, more memory is used, but the quality is higher
  4949.  
  4950. txtLen := -1 ; StrLen(String)
  4951. iCount := CreatePointsF(PointsF, DriverPoints)
  4952. return DllCall("gdiplus\GdipDrawDriverString", "UPtr", pGraphics, "UPtr", &String, "int", txtLen, "UPtr", hFont, "UPtr", pBrush, "UPtr", &PointsF, "int", Flags, "UPtr", hMatrix)
  4953. }
  4954.  
  4955. Gdip_GetStringFormatFlags(hStringFormat) {
  4956. ; please see Gdip_StringFormatCreate()
  4957. ; thanks to xelowek ; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=6517&start=360
  4958.  
  4959. result := 0
  4960. E := DllCall("gdiplus\GdipGetStringFormatFlags", "UPtr", hStringFormat, "int*", result)
  4961. If E
  4962. Return -1
  4963.  
  4964. Return result
  4965. }
  4966.  
  4967.  
  4968. Gdip_StringFormatCreate(FormatFlags:=0, LangID:=0) {
  4969. ; Format options [StringFormatFlags]
  4970. ; DirectionRightToLeft = 0x00000001
  4971. ; - Activates is right to left reading order. For horizontal text, characters are read from right to left. For vertical text, columns are read from right to left.
  4972. ; DirectionVertical = 0x00000002
  4973. ; - Individual lines of text are drawn vertically on the display device.
  4974. ; NoFitBlackBox = 0x00000004
  4975. ; - Parts of characters are allowed to overhang the string's layout rectangle.
  4976. ; DisplayFormatControl = 0x00000020
  4977. ; - Unicode layout control characters are displayed with a representative character.
  4978. ; NoFontFallback = 0x00000400
  4979. ; - Prevent using an alternate font for characters that are not supported in the requested font.
  4980. ; MeasureTrailingSpaces = 0x00000800
  4981. ; - The spaces at the end of each line are included in a string measurement.
  4982. ; NoWrap = 0x00001000
  4983. ; - Disable text wrapping
  4984. ; LineLimit = 0x00002000
  4985. ; - Only entire lines are laid out in the layout rectangle.
  4986. ; NoClip = 0x00004000
  4987. ; - Characters overhanging the layout rectangle and text extending outside the layout rectangle are allowed to show.
  4988.  
  4989. hStringFormat := 0
  4990. gdipLastError := DllCall("gdiplus\GdipCreateStringFormat", "int", FormatFlags, "int", LangID, "UPtr*", hStringFormat)
  4991. return hStringFormat
  4992. }
  4993.  
  4994. Gdip_CloneStringFormat(hStringFormat) {
  4995. newHStringFormat := 0
  4996. gdipLastError := DllCall("gdiplus\GdipCloneStringFormat", "UPtr", hStringFormat, "uint*", newHStringFormat)
  4997. Return newHStringFormat
  4998. }
  4999.  
  5000. Gdip_StringFormatGetGeneric(whichFormat:=0) {
  5001. ; Returns a generic string format.
  5002. ; Default = 0
  5003. ; Typographic := 1
  5004. hStringFormat := 0
  5005. If (whichFormat=1)
  5006. gdipLastError := DllCall("gdiplus\GdipStringFormatGetGenericTypographic", "UPtr*", hStringFormat)
  5007. Else
  5008. gdipLastError := DllCall("gdiplus\GdipStringFormatGetGenericDefault", "UPtr*", hStringFormat)
  5009. Return hStringFormat
  5010. }
  5011.  
  5012. Gdip_SetStringFormatAlign(hStringFormat, Align, LineAlign:="") {
  5013. ; Text alignments:
  5014. ; 0 - [Near / Left] Alignment is towards the origin of the bounding rectangle
  5015. ; 1 - [Center] Alignment is centered between origin and extent (width) of the formatting rectangle
  5016. ; 2 - [Far / Right] Alignment is to the far extent (right side) of the formatting rectangle
  5017. If (LineAlign!="")
  5018. Gdip_SetStringFormatLineAlign(hStringFormat, LineAlign)
  5019. return DllCall("gdiplus\GdipSetStringFormatAlign", "UPtr", hStringFormat, "int", Align)
  5020. }
  5021.  
  5022. Gdip_GetStringFormatAlign(hStringFormat) {
  5023. result := 0
  5024. E := DllCall("gdiplus\GdipGetStringFormatAlign", "UPtr", hStringFormat, "int*", result)
  5025. If E
  5026. Return -1
  5027. Return result
  5028. }
  5029.  
  5030. Gdip_GetStringFormatLineAlign(hStringFormat) {
  5031. result := 0
  5032. E := DllCall("gdiplus\GdipGetStringFormatLineAlign", "UPtr", hStringFormat, "int*", result)
  5033. If E
  5034. Return -1
  5035. Return result
  5036. }
  5037.  
  5038. Gdip_GetStringFormatDigitSubstitution(hStringFormat) {
  5039. result := 0
  5040. E := DllCall("gdiplus\GdipGetStringFormatDigitSubstitution", "UPtr", hStringFormat, "ushort*", 0, "uint*", result)
  5041. If E
  5042. Return -1
  5043. Return result
  5044. }
  5045.  
  5046. Gdip_GetStringFormatHotkeyPrefix(hStringFormat) {
  5047. result := 0
  5048. E := DllCall("gdiplus\GdipGetStringFormatHotkeyPrefix", "UPtr", hStringFormat, "uint*", result)
  5049. If E
  5050. Return -1
  5051. Return result
  5052. }
  5053.  
  5054. Gdip_GetStringFormatTrimming(hStringFormat) {
  5055. result := 0
  5056. E := DllCall("gdiplus\GdipGetStringFormatTrimming", "UPtr", hStringFormat, "int*", result)
  5057. If E
  5058. Return -1
  5059. Return result
  5060. }
  5061.  
  5062. Gdip_SetStringFormatLineAlign(hStringFormat, StringAlign) {
  5063. ; The line alignment setting specifies how to align the string vertically in the layout rectangle.
  5064. ; The layout rectangle is used to position the displayed string
  5065. ; StringAlign - Type of vertical line alignment to use:
  5066. ; 0 - Top
  5067. ; 1 - Center
  5068. ; 2 - Bottom
  5069.  
  5070. Return DllCall("gdiplus\GdipSetStringFormatLineAlign", "UPtr", hStringFormat, "int", StringAlign)
  5071. }
  5072.  
  5073. Gdip_SetStringFormatDigitSubstitution(hStringFormat, DigitSubstitute, LangID:=0) {
  5074. ; Sets the language ID and the digit substitution method that is used by a StringFormat object
  5075. ; DigitSubstitute - Digit substitution method that will be used by the StringFormat object:
  5076. ; 0 - A user-defined substitution scheme
  5077. ; 1 - Digit substitution is disabled
  5078. ; 2 - Substitution digits that correspond with the official national language of the user's locale
  5079. ; 3 - Substitution digits that correspond with the user's native script or language
  5080.  
  5081. return DllCall("gdiplus\GdipSetStringFormatDigitSubstitution", "UPtr", hStringFormat, "ushort", LangID, "uint", DigitSubstitute)
  5082. }
  5083.  
  5084. Gdip_SetStringFormatFlags(hStringFormat, Flags) {
  5085. ; see Gdip_StringFormatCreate() for possible StringFormatFlags
  5086. return DllCall("gdiplus\GdipSetStringFormatFlags", "UPtr", hStringFormat, "int", Flags)
  5087. }
  5088.  
  5089. Gdip_SetStringFormatHotkeyPrefix(hStringFormat, PrefixProcessMode) {
  5090. ; Sets the type of processing that is performed on a string when a hot key prefix (&) is encountered
  5091. ; PrefixProcessMode - Type of hot key prefix processing to use:
  5092. ; 0 - No hot key processing occurs.
  5093. ; 1 - Unicode text is scanned for ampersands (&). All pairs of ampersands are replaced by a single ampersand.
  5094. ; All single ampersands are removed, the first character that follows a single ampersand is displayed underlined.
  5095. ; 2 - Same as 1 but a character following a single ampersand is not displayed underlined.
  5096.  
  5097. return DllCall("gdiplus\GdipSetStringFormatHotkeyPrefix", "UPtr", hStringFormat, "uint", PrefixProcessMode)
  5098. }
  5099.  
  5100. Gdip_SetStringFormatTrimming(hStringFormat, TrimMode) {
  5101. ; TrimMode - The trimming style to use:
  5102. ; 0 - Trim - No trimming is done
  5103. ; 1 - TrimChar - String is broken at the boundary of the last character that is inside the layout rectangle
  5104. ; 2 - TrimWord - String is broken at the boundary of the last word that is inside the layout rectangle
  5105. ; 3 - EllipsisChar - String is broken at the boundary of the last character that is inside the layout rectangle and an ellipsis (...) is inserted after the character
  5106. ; 4 - EllipsisWord - String is broken at the boundary of the last word that is inside the layout rectangle and an ellipsis (...) is inserted after the word
  5107. ; 5 - EllipsisMid - The center is removed from the string and replaced by an ellipsis. The algorithm keeps as much of the last portion of the string as possible
  5108.  
  5109. return DllCall("gdiplus\GdipSetStringFormatTrimming", "UPtr", hStringFormat, "int", TrimMode)
  5110. }
  5111.  
  5112. Gdip_SetStringFormatTabStops(hStringFormat, inTabStops, firstTabOffset:=0) {
  5113. ; aTabStops - an array like this [25, 50, 100, 150] or a string like "25|50|100|150"
  5114. ; added by telppa and modified by Marius Șucan
  5115.  
  5116. totals := AllocateBinArray(tabStops, inTabStops)
  5117. If totals
  5118. Return DllCall("gdiplus\GdipSetStringFormatTabStops", "UPtr", hStringFormat, "float", firstTabOffset, "int", totals, "uptr", &tabStops)
  5119. Else
  5120. Return 2
  5121. }
  5122.  
  5123. Gdip_GetStringFormatTabStopCount(hStringFormat) {
  5124. ; added by telppa
  5125. VarSetCapacity(count, 4, 0)
  5126. gdipLastError := DllCall("gdiplus\GdipGetStringFormatTabStopCount", "UPtr", hStringFormat, "UPtr", &count)
  5127. r := NumGet(count, 0, "int")
  5128. count := ""
  5129. Return r
  5130. }
  5131.  
  5132. Gdip_GetStringFormatTabStops(hStringFormat) {
  5133. ; Returns an array like this [50, 80, 100] .
  5134. ; added by telppa
  5135. count := Gdip_GetStringFormatTabStopCount(hStringFormat)
  5136. firstTabOffset := 0
  5137. VarSetCapacity(tabStops, count * 4, 0)
  5138. gdipLastError := DllCall("gdiplus\GdipGetStringFormatTabStops", "UPtr", hStringFormat, "int", count, "uptr", &firstTabOffset, "uptr", &tabStops)
  5139. ret := []
  5140. Loop % count
  5141. ret.Push(NumGet(tabStops, (A_Index - 1) * 4, "float"))
  5142. tabStops := ""
  5143. Return ret
  5144. }
  5145.  
  5146. Gdip_FontCreate(hFontFamily, Size, Style:=0, Unit:=0) {
  5147. ; Font style options:
  5148. ; Regular = 0
  5149. ; Bold = 1
  5150. ; Italic = 2
  5151. ; BoldItalic = 3
  5152. ; Underline = 4
  5153. ; Strikeout = 8
  5154. ; Unit options: see Gdip_SetPageUnit()
  5155. hFont := 0
  5156. gdipLastError := DllCall("gdiplus\GdipCreateFont", "UPtr", hFontFamily, "float", Size, "int", Style, "int", Unit, "UPtr*", hFont)
  5157. Return hFont
  5158. }
  5159.  
  5160. Gdip_FontFamilyCreate(FontName) {
  5161. hFontFamily := 0
  5162. gdipLastError := DllCall("gdiplus\GdipCreateFontFamilyFromName"
  5163. , "WStr", FontName, "uint", 0, "UPtr*", hFontFamily)
  5164.  
  5165. Return hFontFamily
  5166. }
  5167.  
  5168. Gdip_GetFontCollectionFamilyCount(hFontCollection) {
  5169. counter := 0
  5170. gdipLastError := DllCall("gdiplus\GdipGetFontCollectionFamilyCount", "uptr", hFontCollection, "int*", counter)
  5171. Return counter
  5172. }
  5173.  
  5174. Gdip_NewPrivateFontCollection() {
  5175. hFontCollection := 0
  5176. gdipLastError := DllCall("gdiplus\GdipNewPrivateFontCollection", "uptr*", hFontCollection)
  5177. Return hFontCollection
  5178. }
  5179.  
  5180. Gdip_CreateFontFamilyFromFile(FontFile, hFontCollection, FontName:="") {
  5181. ; hFontCollection - the collection to add the font to
  5182. ; Pass the result of Gdip_NewPrivateFontCollection() to this parameter
  5183. ; to create a private collection of fonts.
  5184. ; After no longer needing the private fonts, use Gdip_DeletePrivateFontCollection()
  5185. ; to free up resources.
  5186. ;
  5187. ; GDI+ does not support PostScript fonts or OpenType fonts which do not have TrueType outlines.
  5188. ;
  5189. ; function by tmplinshi
  5190. ; source: https://www.autohotkey.com/boards/viewtopic.php?f=6&t=813&p=298435#p297794
  5191. ; modified by Marius Șucan
  5192. If (hFontCollection="")
  5193. Return
  5194.  
  5195. hFontFamily := 0
  5196. E := DllCall("gdiplus\GdipPrivateAddFontFile", "uptr", hFontCollection, "str", FontFile)
  5197. if (FontName="" && !E)
  5198. {
  5199. VarSetCapacity(pFontFamily, 10, 0)
  5200. DllCall("gdiplus\GdipGetFontCollectionFamilyList", "uptr", hFontCollection, "int", 1, "uptr", &pFontFamily, "int*", found)
  5201.  
  5202. VarSetCapacity(FontName, 100, 0)
  5203. DllCall("gdiplus\GdipGetFamilyName", "uptr", NumGet(pFontFamily, 0, "uptr"), "str", FontName, "ushort", 1033)
  5204. }
  5205.  
  5206. If !E
  5207. DllCall("gdiplus\GdipCreateFontFamilyFromName", "str", FontName, "uptr", hFontCollection, "uptr*", hFontFamily)
  5208. Return hFontFamily
  5209. }
  5210.  
  5211. Gdip_GetInstalledFontFamilies(nameRegex := "", userFontCollection:=0) {
  5212. ; The results can be filtered. Example: GetInstalledFontFamilies("Arial")
  5213. ; Returns an array with names of installed font families.
  5214. ; Source: https://github.com/mcl-on-github/oGdip.ahk/blob/main/OGdip.ahk
  5215. ; by MCL; modified by Marius Șucan to allow users to point to a given font collection
  5216.  
  5217. Static pFontCollection := 0
  5218. If (pFontCollection == 0)
  5219. DllCall("GdiPlus\GdipNewInstalledFontCollection", "UPtr*", pFontCollection := 0)
  5220.  
  5221. thisFontCollection := (userFontCollection!=0) ? userFontCollection : pFontCollection
  5222. familyCount := Gdip_GetFontCollectionFamilyCount(thisFontCollection)
  5223. VarSetCapacity(familyList, 2 * A_PtrSize * familyCount, 0)
  5224. DllCall("GdiPlus\GdipGetFontCollectionFamilyList"
  5225. , "UPtr", thisFontCollection
  5226. , "Int" , familyCount
  5227. , "UPtr", &familyList
  5228. , "Int*", familyCount)
  5229.  
  5230. langId := 0
  5231. families := []
  5232. Loop % familyCount
  5233. {
  5234. familyPtr := NumGet(familyList, (A_Index - 1) * A_PtrSize, "UPtr")
  5235. VarSetCapacity(familyName, 64, 0) ; LF_FACESIZE = 32 WChars
  5236. DllCall("GdiPlus\GdipGetFamilyName"
  5237. , "UPtr" , familyPtr
  5238. , "WStr" , familyName
  5239. , "UShort", langId)
  5240.  
  5241. If (familyName ~= nameRegex)
  5242. families.Push(familyName)
  5243. }
  5244. familyName := 0, familyList := 0
  5245. Return families
  5246. }
  5247.  
  5248. Gdip_FontFamilyCreateGeneric(whichStyle) {
  5249. ; This function returns a hFontFamily font object that uses a generic font.
  5250. ;
  5251. ; whichStyle options:
  5252. ; 0 - monospace generic font
  5253. ; 1 - sans-serif generic font
  5254. ; 2 - serif generic font
  5255.  
  5256. hFontFamily := 0
  5257. If (whichStyle=0)
  5258. DllCall("gdiplus\GdipGetGenericFontFamilyMonospace", "UPtr*", hFontFamily)
  5259. Else If (whichStyle=1)
  5260. DllCall("gdiplus\GdipGetGenericFontFamilySansSerif", "UPtr*", hFontFamily)
  5261. Else If (whichStyle=2)
  5262. DllCall("gdiplus\GdipGetGenericFontFamilySerif", "UPtr*", hFontFamily)
  5263. Return hFontFamily
  5264. }
  5265.  
  5266. Gdip_GetWindowFont(hwnd) {
  5267. Static WM_GETFONT := 0x31
  5268. ; for this function to work, you must provide a hwnd of button control or something similar
  5269. hFONT := DllCall("User32.dll\SendMessage", "UPtr", HWND, "UInt", WM_GETFONT, "Ptr", 0, "Ptr", 0, "Ptr")
  5270. hDC := GetDC(HWND)
  5271. SelectObject(hDC, hFont)
  5272. pFont := Gdip_CreateFontFromDC(hDC)
  5273. ReleaseDC(hDC, hwnd)
  5274. Return pFONT
  5275. }
  5276.  
  5277. Gdip_CreateFontFromDC(hDC) {
  5278. ; a font must be selected in the hDC for this function to work
  5279. ; function extracted from a class based wrapper around the GDI+ API made by nnnik
  5280.  
  5281. pFont := 0
  5282. gdipLastError := DllCall("gdiplus\GdipCreateFontFromDC", "UPtr", hDC, "UPtr*", pFont)
  5283. Return pFont
  5284. }
  5285.  
  5286. Gdip_CreateFontFromLogfont(hDC, LogFont, type:="W") {
  5287. ; extracted from: https://github.com/flipeador/Library-AutoHotkey/tree/master/graphics
  5288. ; by flipeador
  5289. ;
  5290. ; Creates a Font object directly from a GDI logical font.
  5291. ; The GDI logical font is a LOGFONTW structure, which is the wide character version of a logical font.
  5292. ; Parameters:
  5293. ; hDC:
  5294. ; A handle to a Windows device context that has a font selected.
  5295. ; LogFont:
  5296. ; A LOGFONTW structure that contains attributes of the font.
  5297. ; The LOGFONTW structure is the wide character version of the logical font.
  5298. ; type:
  5299. ; The type of structure: LOGFONTW or LOGFONTA.
  5300. ;
  5301. ; https://docs.microsoft.com/en-us/windows/win32/api/gdiplusheaders/nf-gdiplusheaders-font-font(inhdc_inconstlogfontw)
  5302. pFont := 0
  5303. function2call := (type="w") ? "W" : "A"
  5304. gdipLastError := DllCall("gdiplus\GdipCreateFontFromLogfont" function2call, "UPtr", hDC, "UPtr", LogFont, "UPtr*", pFont)
  5305. return pFont
  5306. }
  5307.  
  5308. Gdip_GetLOGFONT(ByRef LOGFONT, hFont, oGraphics:=0) {
  5309. ; hFont is a pointer to a font created using Gdip_FontCreate()
  5310. ; function originally written by MCL , modified by Marius Șucan
  5311.  
  5312. If oGraphics
  5313. {
  5314. pGraphics := oGraphics
  5315. } Else
  5316. {
  5317. ; Create temporary graphics
  5318. tempHDC := CreateCompatibleDC()
  5319. tempGr := Gdip_GraphicsFromHDC(tempHDC)
  5320. pGraphics := tempGr
  5321. DeleteDC(tempHDC)
  5322. }
  5323.  
  5324. VarSetCapacity(LOGFONT, 28 + 64, 0)
  5325. gdipLastError := DllCall("gdiplus\GdipGetLogFontW", "UPtr", hFont, "UPtr", pGraphics, "UPtr", &LOGFONT)
  5326. If tempGr
  5327. Gdip_DeleteGraphics(tempGr)
  5328. Return gdipLastError
  5329. }
  5330.  
  5331. Gdip_GetFontHeight(hFont, pGraphics:=0) {
  5332. ; Gets the line spacing of a font in the current unit of a specified pGraphics object.
  5333. ; The line spacing is the vertical distance between the base lines of two consecutive lines of text.
  5334. ; Therefore, the line spacing includes the blank space between lines along with the height of
  5335. ; the character itself.
  5336.  
  5337. result := 0
  5338. gdipLastError := DllCall("gdiplus\GdipGetFontHeight", "UPtr", hFont, "UPtr", pGraphics, "float*", result)
  5339. Return result
  5340. }
  5341.  
  5342. Gdip_GetFontHeightGivenDPI(hFont, DPI:=72) {
  5343. ; Remarks: it seems to always yield the same value
  5344. ; regardless of the given DPI.
  5345.  
  5346. result := 0
  5347. gdipLastError := DllCall("gdiplus\GdipGetFontHeightGivenDPI", "UPtr", hFont, "float", DPI, "float*", result)
  5348. Return result
  5349. }
  5350.  
  5351. Gdip_GetFontSize(hFont) {
  5352. result := 0
  5353. gdipLastError := DllCall("gdiplus\GdipGetFontSize", "UPtr", hFont, "float*", result)
  5354. Return result
  5355. }
  5356.  
  5357. Gdip_GetFontStyle(hFont) {
  5358. ; see also Gdip_FontCreate()
  5359. result := 0
  5360. g := DllCall("gdiplus\GdipGetFontStyle", "UPtr", hFont, "int*", result)
  5361. If E
  5362. Return -1
  5363. Return result
  5364. }
  5365.  
  5366. Gdip_GetFontUnit(hFont) {
  5367. ; Gets the unit of measure of a Font object.
  5368. result := 0
  5369. E := DllCall("gdiplus\GdipGetFontUnit", "UPtr", hFont, "int*", result)
  5370. If E
  5371. Return -1
  5372. Return result
  5373. }
  5374.  
  5375. Gdip_GetFontFamily(hFont) {
  5376. ; On success returns a handle to a hFontFamily object
  5377. hFontFamily := 0
  5378. gdipLastError := DllCall("gdiplus\GdipGetFamily", "UPtr", hFont, "UPtr*", hFontFamily)
  5379. Return hFontFamily
  5380. }
  5381.  
  5382. Gdip_CloneFont(hfont) {
  5383. newHFont := 0
  5384. gdipLastError := DllCall("gdiplus\GdipCloneFont", "UPtr", hFont, "UPtr*", newHFont)
  5385. Return newHFont
  5386. }
  5387.  
  5388. Gdip_CloneFontFamily(hFontFamily) {
  5389. newHFontFamily := 0
  5390. gdipLastError := DllCall("gdiplus\GdipCloneFontFamily", "UPtr", hFontFamily, "UPtr*", newHFontFamily)
  5391. Return newHFontFamily
  5392. }
  5393.  
  5394. Gdip_IsFontStyleAvailable(hFontFamily, Style) {
  5395. ; Remarks: given a proper hFontFamily object, it seems to be always
  5396. ; returning 1 [true] regardless of Style...
  5397. result := 0
  5398. E := DllCall("gdiplus\GdipIsStyleAvailable", "UPtr", hFontFamily, "int", Style, "Int*", result)
  5399. If E
  5400. Return -1
  5401. Return result
  5402. }
  5403.  
  5404. Gdip_GetFontFamilyCellScents(hFontFamily, ByRef Ascent, ByRef Descent, Style:=0) {
  5405. ; Ascent and Descent values are given in «design units»
  5406. Ascent := Descent := 0
  5407. E := DllCall("gdiplus\GdipGetCellAscent", "UPtr", hFontFamily, "int", Style, "ushort*", Ascent)
  5408. E := DllCall("gdiplus\GdipGetCellDescent", "UPtr", hFontFamily, "int", Style, "ushort*", Descent)
  5409. Return E
  5410. }
  5411.  
  5412. Gdip_GetFontFamilyEmHeight(hFontFamily, Style:=0) {
  5413. ; EmHeight returned in «design units»
  5414. result := 0
  5415. gdipLastError := DllCall("gdiplus\GdipGetEmHeight", "UPtr", hFontFamily, "int", Style, "ushort*", result)
  5416. Return result
  5417. }
  5418.  
  5419. Gdip_GetFontFamilyLineSpacing(hFontFamily, Style:=0) {
  5420. ; Line spacing returned in «design units»
  5421. result := 0
  5422. gdipLastError := DllCall("gdiplus\GdipGetLineSpacing", "UPtr", hFontFamily, "int", Style, "ushort*", result)
  5423. Return result
  5424. }
  5425.  
  5426. Gdip_GetFontFamilyName(hFontFamily) {
  5427. VarSetCapacity(FontName, 100, 0)
  5428. gdipLastError := DllCall("gdiplus\GdipGetFamilyName", "UPtr", hFontFamily, "UPtr", &FontName, "ushort", 0)
  5429. Return FontName
  5430. }
  5431.  
  5432. ;#####################################################################################
  5433. ; Transformation matrix functions
  5434. ;#####################################################################################
  5435.  
  5436. Gdip_CreateAffineMatrix(m11, m12, m21, m22, dx, dy) {
  5437. ; please see Gdip_SetMatrixElements() for details on the transformation matrix elements
  5438. ; function returns a Transformation Matrix
  5439.  
  5440. hMatrix := 0
  5441. gdipLastError := DllCall("gdiplus\GdipCreateMatrix2", "float", m11, "float", m12, "float", m21, "float", m22, "float", dx, "float", dy, "UPtr*", hMatrix)
  5442. return hMatrix
  5443. }
  5444.  
  5445. Gdip_CreateMatrix(mXel:=0) {
  5446. ; if an object with six elements is provided as a parameter to this function
  5447. ; Gdip_CreateAffineMatrix() is called
  5448. ; function returns a Transformation Matrix
  5449.  
  5450. if (IsObject(mXel) && mXel.Count()=6)
  5451. return Gdip_CreateAffineMatrix(mXel[1], mXel[2], mXel[3], mXel[4], mXel[5], mXel[6])
  5452.  
  5453. hMatrix := 0
  5454. gdipLastError := DllCall("gdiplus\GdipCreateMatrix", "UPtr*", hMatrix)
  5455. return hMatrix
  5456. }
  5457.  
  5458. Gdip_InvertMatrix(hMatrix) {
  5459. ; Replaces the elements of a matrix with the elements of its inverse
  5460. Return DllCall("gdiplus\GdipInvertMatrix", "UPtr", hMatrix)
  5461. }
  5462.  
  5463. Gdip_IsMatrixEqual(hMatrixA, hMatrixB) {
  5464. ; compares two matrices; if identical, the function returns 1
  5465. result := 0
  5466. E := DllCall("gdiplus\GdipIsMatrixEqual", "UPtr", hMatrixA, "UPtr", hMatrixB, "int*", result)
  5467. If E
  5468. Return -1
  5469. Return result
  5470. }
  5471.  
  5472. Gdip_IsMatrixIdentity(hMatrix) {
  5473. ; The identity matrix represents a transformation with no scaling, translation, rotation and conversion, and
  5474. ; represents a transformation that does nothing.
  5475. result := 0
  5476. E := DllCall("gdiplus\GdipIsMatrixIdentity", "UPtr", hMatrix, "int*", result)
  5477. If E
  5478. Return -1
  5479. Return result
  5480. }
  5481.  
  5482. Gdip_IsMatrixInvertible(hMatrix) {
  5483. result := 0
  5484. E := DllCall("gdiplus\GdipIsMatrixInvertible", "UPtr", hMatrix, "int*", result)
  5485. If E
  5486. Return -1
  5487. Return result
  5488. }
  5489.  
  5490. Gdip_MultiplyMatrix(hMatrixA, hMatrixB, matrixOrder) {
  5491. ; Updates hMatrixA with the product of itself and hMatrixB
  5492. ; matrixOrder - Order of matrices multiplication:
  5493. ; 0 - The second matrix is on the left
  5494. ; 1 - The second matrix is on the right
  5495.  
  5496. Return DllCall("gdiplus\GdipMultiplyMatrix", "UPtr", hMatrixA, "UPtr", hMatrixB, "int", matrixOrder)
  5497. }
  5498.  
  5499. Gdip_CloneMatrix(hMatrix) {
  5500. newHMatrix := 0
  5501. gdipLastError := DllCall("gdiplus\GdipCloneMatrix", "UPtr", hMatrix, "UPtr*", newHMatrix)
  5502. return newHMatrix
  5503. }
  5504.  
  5505. Gdip_TransformMatrixPoints(hMatrix, Points, vectors:=0) {
  5506. ; Applies matrix transformation to the given points.
  5507. ; Returns an array of coordinate pairs of transformed points.
  5508. ;
  5509. ; Points parameter can be an array or a string with the following format:
  5510. ; Points := "x1,y1|x2,y2|x3,y3|x4,y4" [... and so on]
  5511.  
  5512. iCount := CreatePointsF(PointsF, Points)
  5513. func2exec := (vectors=1) ? "Vector" : ""
  5514. gdipLastError := DllCall("gdiplus\Gdip" func2exec "TransformMatrixPoints", "UPtr", hMatrix, "UPtr", &PointsF, "Int", iCount)
  5515.  
  5516. retPoints := []
  5517. Loop % iCount
  5518. retPoints.Push(NumGet(PointsF, (A_Index-1)*4, "Float"))
  5519.  
  5520. Return retPoints
  5521. }
  5522.  
  5523. Gdip_TransformMatrixVectors(hMatrix, Points) {
  5524. ; Same as .TransformPoints method, but points are treated as vectors.
  5525. ; This means that the given coordinates may be scaled and rotated but not translated.
  5526. Return Gdip_TransformMatrixPoints(hMatrix, Points, 1)
  5527. }
  5528.  
  5529. ;#####################################################################################
  5530. ; GraphicsPath functions
  5531. ; pPath objects are rendered/drawn by pGraphics object using:
  5532. ; - a) Gdip_FillPath() with an associated pBrush object created with any of the following functions:
  5533. ; - Gdip_BrushCreateSolid() - SolidFill
  5534. ; - Gdip_CreateTextureBrush() - Texture brush derived from a pBitmap
  5535. ; - Gdip_CreateLinearGrBrush() - LinearGradient
  5536. ; - Gdip_BrushCreateHatch() - Hatch pattern
  5537. ; - Gdip_PathGradientCreateFromPath()
  5538. ; - b) Gdip_DrawPath() with an associated pPen created with Gdip_CreatePen()
  5539. ;
  5540. ; A pPath object can be converted using:
  5541. ; - a) Gdip_PathGradientCreateFromPath() to a PathGradient brush object
  5542. ; - b) Gdip_CreateRegionPath() to a region object
  5543. ;#####################################################################################
  5544.  
  5545. Gdip_CreatePath(fillMode:=0, Points:=0, PointTypes:=0) {
  5546. ; Points: the coordinates of all the points passed as x1,y1|x2,y2|x3,y3..... [minimum three points must be given]; the parameter can also be a flat array object
  5547. ; PointTypes: the point types passed as p1|p2|p3..... [minimum three points must be given]; the parameter can also be a flat array object
  5548. ; Types:
  5549. ; 0x00 - Start of a figure;
  5550. ; 0x01 - Start/end of a straight line;
  5551. ; 0x03 - Bezier control/end point; usually in groups of 3 (C, C, E);
  5552. ; 0x10 - DashMode; undocumented and probably not implemented;
  5553. ; 0x20 - Marker;
  5554. ; 0x80 - Close subpath.
  5555.  
  5556. ; FillModes:
  5557. ; Alternate = 0
  5558. ; Winding = 1
  5559.  
  5560. pPath := 0
  5561. If !Points
  5562. {
  5563. gdipLastError := DllCall("gdiplus\GdipCreatePath", "int", fillMode, "UPtr*", pPath)
  5564. } Else
  5565. {
  5566. iCount := CreatePointsF(PointsF, Points)
  5567. If !PointTypes
  5568. {
  5569. PointTypes := []
  5570. Loop % iCount
  5571. PointTypes[A_Index] := 1
  5572. }
  5573. yCount := AllocateBinArray(PointsTF, PointTypes, "UChar", 1)
  5574. fCount := min(iCount, yCount)
  5575. gdipLastError := DllCall("gdiplus\GdipCreatePath2", "UPtr", &PointsF, "UPtr", &PointsTF, "Int", fCount, "UInt", fillMode, "UPtr*", pPath)
  5576. }
  5577. return pPath
  5578. }
  5579.  
  5580. Gdip_AddPathEllipse(pPath, x, y, w, h:=0) {
  5581. if (h<=0 || !h)
  5582. h := w
  5583.  
  5584. return DllCall("gdiplus\GdipAddPathEllipse", "UPtr", pPath, "float", x, "float", y, "float", w, "float", h)
  5585. }
  5586.  
  5587. Gdip_AddPathEllipseC(pPath, cx, cy, rx, ry := "") {
  5588. If (ry == "")
  5589. ry := rx
  5590.  
  5591. Return Gdip_AddPathEllipse(pPath, cx-rx, cy-ry, rx*2, ry*2)
  5592. }
  5593.  
  5594. Gdip_AddPathRectangle(pPath, x, y, w, h:=0) {
  5595. if (h<=0 || !h)
  5596. h := w
  5597.  
  5598. return DllCall("gdiplus\GdipAddPathRectangle", "UPtr", pPath, "float", x, "float", y, "float", w, "float", h)
  5599. }
  5600.  
  5601. Gdip_AddPathRectangleC(pPath, cx, cy, rx, ry := "") {
  5602. If (ry == "")
  5603. ry := rx
  5604.  
  5605. Return Gdip_AddPathRectangle(pPath, cx-rx, cy-ry, rx*2, ry*2)
  5606. }
  5607.  
  5608. Gdip_AddPathRoundedRectangle(pPath, x, y, w, h, r, angle:=0) {
  5609. ; extracted from: https://github.com/tariqporter/Gdip2/blob/master/lib/Object.ahk
  5610. ; and adapted by Marius Șucan
  5611.  
  5612. ; Create a rounded rectabgle
  5613. D := (R * 2), W -= D, H -= D
  5614. Gdip_AddPathArc(pPath, X, Y, D, D, 180, 90)
  5615. Gdip_AddPathArc(pPath, X+W, Y, D, D, 270, 90)
  5616. Gdip_AddPathArc(pPath, X+W, Y+H, D, D, 0, 90)
  5617. Gdip_AddPathArc(pPath, X, Y+H, D, D, 90, 90)
  5618. Gdip_ClosePathFigure(pPath)
  5619. If angle
  5620. Gdip_RotatePathAtCenter(pPath, angle)
  5621.  
  5622. Return
  5623. }
  5624.  
  5625. Gdip_AddPathPolygon(pPath, Points) {
  5626. ; Points: the coordinates of all the points passed as x1,y1|x2,y2|x3,y3..... [minimum three points must be given]
  5627. ; it can also be an object [x1,y1,x2,y2,x3,y3]
  5628.  
  5629. iCount := CreatePointsF(PointsF, Points)
  5630. return DllCall("gdiplus\GdipAddPathPolygon", "UPtr", pPath, "UPtr", &PointsF, "int", iCount)
  5631. }
  5632.  
  5633. Gdip_AddPathClosedCurve(pPath, Points, Tension:=1) {
  5634. ; Adds a closed cardinal spline to a path.
  5635. ; A cardinal spline is a curve that passes through each point in the array.
  5636. ;
  5637. ; Parameters:
  5638. ; pPath: Pointer to the GraphicsPath
  5639. ; Points: the coordinates of all the points passed as x1,y1|x2,y2|x3,y3..... [minimum three points must be given]; the parameter can also be a flat array object
  5640. ; Tension: Non-negative real number that controls the length of the curve and how the curve bends. A value of
  5641. ; zero specifies that the spline is a sequence of straight lines. As the value increases, the curve becomes fuller.
  5642.  
  5643. iCount := CreatePointsF(PointsF, Points)
  5644. If (iCount<3)
  5645. Return 2
  5646.  
  5647. If Tension
  5648. return DllCall("gdiplus\GdipAddPathClosedCurve2", "UPtr", pPath, "UPtr", &PointsF, "int", iCount, "float", Tension)
  5649. Else
  5650. return DllCall("gdiplus\GdipAddPathClosedCurve", "UPtr", pPath, "UPtr", &PointsF, "int", iCount)
  5651. }
  5652.  
  5653. Gdip_AddPathCurve(pPath, Points, Tension:="") {
  5654. ; Adds a cardinal spline to the current figure of a path
  5655. ; A cardinal spline is a curve that passes through each point in the array.
  5656. ;
  5657. ; Parameters:
  5658. ; pPath: Pointer to the GraphicsPath
  5659. ; Points: the coordinates of all the points passed as x1,y1|x2,y2|x3,y3..... [minimum three points must be given]; the parameter can also be a flat array object
  5660. ; Tension: Non-negative real number that controls the length of the curve and how the curve bends. A value of
  5661. ; zero specifies that the spline is a sequence of straight lines. As the value increases, the curve becomes fuller.
  5662.  
  5663. iCount := CreatePointsF(PointsF, Points)
  5664. If (iCount<3)
  5665. Return 2
  5666.  
  5667. If Tension
  5668. return DllCall("gdiplus\GdipAddPathCurve2", "UPtr", pPath, "UPtr", &PointsF, "int", iCount, "float", Tension)
  5669. Else
  5670. return DllCall("gdiplus\GdipAddPathCurve", "UPtr", pPath, "UPtr", &PointsF, "int", iCount)
  5671. }
  5672.  
  5673. Gdip_AddPathPath(pPathA, pPathB, fConnect) {
  5674. Return Gdip_AddPathToPath(pPathA, pPathB, fConnect)
  5675. }
  5676.  
  5677. Gdip_AddPathToPath(pPathA, pPathB, fConnect) {
  5678. ; Adds a path into another path.
  5679. ; pathB will be added / inserted into pathA
  5680. ;
  5681. ; Parameters:
  5682. ; pPathA and pPathB - Pointers to GraphicsPath objects
  5683. ; fConnect - Specifies whether the first figure in the added path is part of the last figure in this path:
  5684. ; 1 - The first figure in the added pPathB is part of the last figure in the pPathB path.
  5685. ; 0 - The first figure in the added pPathB is separated from the last figure in the pPathA path.
  5686. ;
  5687. ; Remarks: Even if the value of the fConnect parameter is 1, this function might not be able to make the first figure
  5688. ; of the added pPathB path part of the last figure of the pPathA path. If either of those figures is closed,
  5689. ; then they must remain separated figures.
  5690.  
  5691. return DllCall("gdiplus\GdipAddPathPath", "UPtr", pPathA, "UPtr", pPathB, "int", fConnect)
  5692. }
  5693.  
  5694. Gdip_AddPathStringSimplified(pPath, String, FontName, Size, Style, X, Y, Width, Height, Align:=0, NoWrap:=0) {
  5695. ; Adds the outline of a given string with the given font name, size and style
  5696. ; to a Path object.
  5697.  
  5698. ; Size - in em, in world units [font size]
  5699. ; Remarks: a high value might be required; over 60, 90... to see the text.
  5700.  
  5701. ; X, Y - coordinates for the rectangle where the text will be placed
  5702. ; W, H - width and heigh for the rectangle where the text will be placed
  5703.  
  5704. ; Align options:
  5705. ; Near/left = 0
  5706. ; Center = 1
  5707. ; Far/right = 2
  5708.  
  5709. ; Style options:
  5710. ; Regular = 0
  5711. ; Bold = 1
  5712. ; Italic = 2
  5713. ; BoldItalic = 3
  5714. ; Underline = 4
  5715. ; Strikeout = 8
  5716.  
  5717. FormatStyle := NoWrap ? 0x4000 | 0x1000 : 0x4000
  5718. If (SubStr(FontName, 1, 6)="hfont:")
  5719. {
  5720. wasGivenFontFamily := 1
  5721. hFontFamily := SubStr(FontName, 7) ; to be used in conjunction with Gdip_NewPrivateFontCollection()
  5722. } Else If RegExMatch(FontName, "^(.\:\\.)")
  5723. {
  5724. ; it might crash if you execute this in a looped sequence
  5725. hFontCollection := Gdip_NewPrivateFontCollection()
  5726. hFontFamily := Gdip_CreateFontFamilyFromFile(FontName, hFontCollection)
  5727. } Else hFontFamily := Gdip_FontFamilyCreate(FontName)
  5728.  
  5729. If !hFontFamily
  5730. hFontFamily := Gdip_FontFamilyCreateGeneric(1)
  5731.  
  5732. If !hFontFamily
  5733. {
  5734. If hFontCollection
  5735. Gdip_DeletePrivateFontCollection(hFontCollection)
  5736. Return -1
  5737. }
  5738.  
  5739. hStringFormat := Gdip_StringFormatCreate(FormatStyle)
  5740. If !hStringFormat
  5741. hStringFormat := Gdip_StringFormatGetGeneric(1)
  5742.  
  5743. If !hStringFormat
  5744. {
  5745. If (hFontFamily!="" && !wasGivenFontFamily)
  5746. Gdip_DeleteFontFamily(hFontFamily)
  5747. If hFontCollection
  5748. Gdip_DeletePrivateFontCollection(hFontCollection)
  5749. Return -2
  5750. }
  5751.  
  5752. Gdip_SetStringFormatTrimming(hStringFormat, 3)
  5753. Gdip_SetStringFormatAlign(hStringFormat, Align)
  5754. E := Gdip_AddPathString(pPath, String, hFontFamily, Style, Size, hStringFormat, X, Y, Width, Height)
  5755. Gdip_DeleteStringFormat(hStringFormat)
  5756. If (hFontFamily!="" && !wasGivenFontFamily)
  5757. Gdip_DeleteFontFamily(hFontFamily)
  5758. If hFontCollection
  5759. Gdip_DeletePrivateFontCollection(hFontCollection)
  5760. Return E
  5761. }
  5762.  
  5763. Gdip_AddPathString(pPath, String, hFontFamily, Style, Size, hStringFormat, X, Y, W, H) {
  5764. CreateRectF(RectF, X, Y, W, H)
  5765. Return DllCall("gdiplus\GdipAddPathString", "UPtr", pPath, "WStr", String, "int", -1, "UPtr", hFontFamily, "int", Style, "float", Size, "UPtr", &RectF, "UPtr", hStringFormat)
  5766. }
  5767.  
  5768. Gdip_SetPathFillMode(pPath, FillMode) {
  5769. ; Parameters
  5770. ; pPath - Pointer to a GraphicsPath object
  5771. ; FillMode - Path fill mode:
  5772. ; 0 - [Alternate] The areas are filled according to the even-odd parity rule
  5773. ; 1 - [Winding] The areas are filled according to the non-zero winding rule
  5774.  
  5775. return DllCall("gdiplus\GdipSetPathFillMode", "UPtr", pPath, "int", FillMode)
  5776. }
  5777.  
  5778. Gdip_GetPathFillMode(pPath) {
  5779. result := 0
  5780. E := DllCall("gdiplus\GdipGetPathFillMode", "UPtr", pPath, "int*", result)
  5781. If E
  5782. Return -1
  5783. Return result
  5784. }
  5785.  
  5786. Gdip_GetPathLastPoint(pPath, ByRef X, ByRef Y) {
  5787. VarSetCapacity(PointF, 8, 0)
  5788. E := DllCall("gdiplus\GdipGetPathLastPoint", "UPtr", pPath, "UPtr", &PointF)
  5789. If !E
  5790. {
  5791. x := NumGet(PointF, 0, "float")
  5792. y := NumGet(PointF, 4, "float")
  5793. }
  5794. PointF := ""
  5795. Return E
  5796. }
  5797.  
  5798. Gdip_GetPathPointsCount(pPath) {
  5799. result := 0
  5800. E := DllCall("gdiplus\GdipGetPointCount", "UPtr", pPath, "int*", result)
  5801. If E
  5802. Return -1
  5803. Return result
  5804. }
  5805.  
  5806. Gdip_GetPathPoints(pPath, returnArray:=0) {
  5807. ; Please note: if the pPath is a Cardinal spline with a tension
  5808. ; higher than 0, GDI+ will return additional points
  5809. ; than the initial points when it was created.
  5810.  
  5811. PointsCount := Gdip_GetPathPointsCount(pPath)
  5812. If (PointsCount=-1)
  5813. Return
  5814.  
  5815. VarSetCapacity(PointsF, 8 * PointsCount, 0)
  5816. gdipLastError := DllCall("gdiplus\GdipGetPathPoints", "UPtr", pPath, "UPtr", &PointsF, "intP", PointsCount)
  5817. If (returnArray=1)
  5818. newArray := []
  5819. Else
  5820. printList := ""
  5821.  
  5822. Loop %PointsCount%
  5823. {
  5824. X := NumGet(&PointsF, 8*(A_Index-1), "float")
  5825. Y := NumGet(&PointsF, (8*(A_Index-1))+4, "float")
  5826. If (returnArray=1)
  5827. {
  5828. newArray[A_Index*2 - 1] := X
  5829. newArray[A_Index*2 + 1 - 1] := Y
  5830. } Else printList .= X "," Y "|"
  5831. }
  5832.  
  5833. PointsF := ""
  5834. If (returnArray=1)
  5835. Return newArray
  5836. Else
  5837. Return Trim(printList, "|")
  5838. }
  5839.  
  5840. Gdip_FlattenPath(pPath, flatness, hMatrix:=0) {
  5841. ; flatness - a precision value that specifies the maximum error between the path and
  5842. ; its flattened [segmented] approximation. Reducing the flatness increases the number
  5843. ; of line segments in the approximation.
  5844. ;
  5845. ; hMatrix - a pointer to a transformation matrix to apply.
  5846. return DllCall("gdiplus\GdipFlattenPath", "UPtr", pPath, "UPtr", hMatrix, "float", flatness)
  5847. }
  5848.  
  5849. Gdip_WidenPath(pPath, pPen, hMatrix:=0, Flatness:=1) {
  5850. ; Replaces this path with curves that enclose the area that is filled when this path is drawn by a specified pen.
  5851. ; This method also flattens the path.
  5852.  
  5853. return DllCall("gdiplus\GdipWidenPath", "UPtr", pPath, "UPtr", pPen, "UPtr", hMatrix, "float", Flatness)
  5854. }
  5855.  
  5856. Gdip_PathOutline(pPath, flatness:=1, hMatrix:=0) {
  5857. ; Transforms and flattens [segmentates] a pPath object, and then converts the path's data points
  5858. ; so that they represent only the outline of the given path.
  5859. ;
  5860. ; flatness - a precision value that specifies the maximum error between the path and
  5861. ; its flattened [segmented] approximation. Reducing the flatness increases the number
  5862. ; of line segments in the resulted approximation.
  5863. ;
  5864. ; hMatrix - a pointer to a transformation matrix to apply.
  5865. return DllCall("gdiplus\GdipWindingModeOutline", "UPtr", pPath, "UPtr", hMatrix, "float", flatness)
  5866. }
  5867.  
  5868. Gdip_ResetPath(pPath) {
  5869. ; Empties a path and sets the fill mode to alternate (0)
  5870. Return DllCall("gdiplus\GdipResetPath", "UPtr", pPath)
  5871. }
  5872.  
  5873. Gdip_ReversePath(pPath) {
  5874. ; Reverses the order of the points that define a path's lines and curves
  5875. Return DllCall("gdiplus\GdipReversePath", "UPtr", pPath)
  5876. }
  5877.  
  5878. Gdip_IsOutlineVisiblePathPoint(pGraphics, pPath, pPen, X, Y) {
  5879. ; pGraphics is optional; you can pass 0 for pGraphics
  5880. result := 0
  5881. E := DllCall("gdiplus\GdipIsOutlineVisiblePathPoint", "UPtr", pPath, "float", X, "float", Y, "UPtr", pPen, "UPtr", pGraphics, "int*", result)
  5882. If E
  5883. Return -1
  5884. Return result
  5885. }
  5886.  
  5887. Gdip_IsVisiblePathPoint(pPath, x, y, pGraphics) {
  5888. ; Function by RazorHalo, modified by Marius Șucan
  5889. ; Hit test function
  5890. result := 0
  5891. E := DllCall("gdiplus\GdipIsVisiblePathPoint", "UPtr", pPath, "float", x, "float", y, "UPtr", pGraphics, "UPtr*", result)
  5892. If E
  5893. return -1
  5894. return result
  5895. }
  5896.  
  5897. Gdip_IsVisiblePathRectEntirely(pGraphics, pPath, X, Y, Width, Height) {
  5898. ; Return values:
  5899. ; -2 - mixed state
  5900. ; -1 - error
  5901. ; 0 - rect is entirely not visible
  5902. ; 1 - rect is entirely visible
  5903.  
  5904. a := Gdip_IsVisiblePathPoint(pPath, X, Y, pGraphics)
  5905. b := Gdip_IsVisiblePathPoint(pPath, X + Width, Y, pGraphics)
  5906. c := Gdip_IsVisiblePathPoint(pPath, X + Width, Y + Height, pGraphics)
  5907. d := Gdip_IsVisiblePathPoint(pPath, X, Y + Height, pGraphics)
  5908. If (a=1 && b=1 && c=1 && d=1)
  5909. Return 1
  5910. Else If (a=-1 || b=-1 || c=-1 || d=-1)
  5911. Return -1
  5912. Else If (a=0 && b=0 && c=0 && d=0)
  5913. Return 0
  5914. Else
  5915. Return -2
  5916. }
  5917.  
  5918. Gdip_DeletePath(pPath) {
  5919. If (pPath!="")
  5920. return DllCall("gdiplus\GdipDeletePath", "UPtr", pPath)
  5921. }
  5922.  
  5923. ;#####################################################################################
  5924. ; pGraphics rendering options functions
  5925. ;#####################################################################################
  5926.  
  5927. Gdip_SetTextRenderingHint(pGraphics, RenderingHint) {
  5928. ; RenderingHint options:
  5929. ; SystemDefault = 0
  5930. ; SingleBitPerPixelGridFit = 1
  5931. ; SingleBitPerPixel = 2
  5932. ; AntiAliasGridFit = 3
  5933. ; AntiAlias = 4
  5934. If !pGraphics
  5935. Return 2
  5936.  
  5937. Return DllCall("gdiplus\GdipSetTextRenderingHint", "UPtr", pGraphics, "int", RenderingHint)
  5938. }
  5939.  
  5940. Gdip_SetInterpolationMode(pGraphics, InterpolationMode) {
  5941. ; InterpolationMode options:
  5942. ; Default = 0
  5943. ; LowQuality = 1
  5944. ; HighQuality = 2
  5945. ; Bilinear = 3
  5946. ; Bicubic = 4 [very slow]
  5947. ; NearestNeighbor = 5 [fastest]
  5948. ; HighQualityBilinear = 6 [fast]
  5949. ; HighQualityBicubic = 7
  5950.  
  5951. ; NOTES: The drawing of GDI+ Bitmaps is limited to a size of 32767 pixels
  5952. ; in either direction (width, height). This limit applies only if the
  5953. ; interpolation mode is set to NearestNeighbor for the Graphics Object.
  5954.  
  5955. If !pGraphics
  5956. Return 2
  5957. Return DllCall("gdiplus\GdipSetInterpolationMode", "UPtr", pGraphics, "int", InterpolationMode)
  5958. }
  5959.  
  5960. Gdip_SetSmoothingMode(pGraphics, SmoothingMode) {
  5961. ; SmoothingMode options:
  5962. ; Default = 0
  5963. ; HighSpeed = 1
  5964. ; HighQuality = 2
  5965. ; None = 3
  5966. ; AntiAlias = 4
  5967. ; AntiAlias8x4 = 5
  5968. ; AntiAlias8x8 = 6
  5969. If !pGraphics
  5970. Return 2
  5971.  
  5972. Return DllCall("gdiplus\GdipSetSmoothingMode", "UPtr", pGraphics, "int", SmoothingMode)
  5973. }
  5974.  
  5975. Gdip_SetCompositingMode(pGraphics, CompositingMode) {
  5976. ; CompositingMode_SourceOver = 0 (blended / default)
  5977. ; CompositingMode_SourceCopy = 1 (overwrite)
  5978. If (pGraphics="")
  5979. Return 2
  5980.  
  5981. return DllCall("gdiplus\GdipSetCompositingMode", "UPtr", pGraphics, "int", CompositingMode)
  5982. }
  5983.  
  5984. Gdip_SetCompositingQuality(pGraphics, CompositionQuality) {
  5985. ; CompositionQuality options:
  5986. ; 0 - Gamma correction is not applied.
  5987. ; 1 - Gamma correction is not applied. High speed, low quality.
  5988. ; 2 - Gamma correction is applied. Composition of high quality and speed.
  5989. ; 3 - Gamma correction is applied.
  5990. ; 4 - Gamma correction is not applied. Linear values are used.
  5991. If (pGraphics="")
  5992. Return 2
  5993.  
  5994. Return DllCall("gdiplus\GdipSetCompositingQuality", "UPtr", pGraphics, "int", CompositionQuality)
  5995. }
  5996.  
  5997. Gdip_SetPageScale(pGraphics, Scale) {
  5998. ; Sets the scaling factor for the page transformation of a pGraphics object.
  5999. ; The page transformation converts page coordinates to device coordinates.
  6000.  
  6001. If (pGraphics="")
  6002. Return 2
  6003.  
  6004. Return DllCall("gdiplus\GdipSetPageScale", "UPtr", pGraphics, "float", Scale)
  6005. }
  6006.  
  6007. Gdip_SetPageUnit(pGraphics, Unit) {
  6008. ; Sets the unit of measurement for a pGraphics object.
  6009. ; Unit of measuremnet options:
  6010. ; 0 - World coordinates, a non-physical unit
  6011. ; 1 - Display units
  6012. ; 2 - A unit is 1 pixel
  6013. ; 3 - A unit is 1 point or 1/72 inch
  6014. ; 4 - A unit is 1 inch
  6015. ; 5 - A unit is 1/300 inch
  6016. ; 6 - A unit is 1 millimeter
  6017. If (pGraphics="")
  6018. Return 2
  6019.  
  6020. Return DllCall("gdiplus\GdipSetPageUnit", "UPtr", pGraphics, "int", Unit)
  6021. }
  6022.  
  6023. Gdip_SetPixelOffsetMode(pGraphics, PixelOffsetMode) {
  6024. ; Sets the pixel offset mode of a pGraphics object.
  6025. ; PixelOffsetMode options:
  6026. ; HighSpeed = QualityModeLow - Default
  6027. ; 0, 1, 3 - Pixel centers have integer coordinates
  6028. ; ModeHalf - ModeHighQuality
  6029. ; 2, 4 - Pixel centers have coordinates that are half way between integer values (i.e. 0.5, 20, 105.5, etc...)
  6030. If !pGraphics
  6031. Return 2
  6032.  
  6033. Return DllCall("gdiplus\GdipSetPixelOffsetMode", "UPtr", pGraphics, "int", PixelOffsetMode)
  6034. }
  6035.  
  6036. Gdip_SetRenderingOrigin(pGraphics, X, Y) {
  6037. ; The rendering origin is used to set the dither origin for 8-bits-per-pixel and 16-bits-per-pixel dithering
  6038. ; and is also used to set the origin for hatch brushes
  6039. If !pGraphics
  6040. Return 2
  6041.  
  6042. Return DllCall("gdiplus\GdipSetRenderingOrigin", "UPtr", pGraphics, "int", X, "int", Y)
  6043. }
  6044.  
  6045. Gdip_SetTextContrast(pGraphics, Contrast) {
  6046. ; Contrast - A number between 0 and 12, which defines the value of contrast used for antialiasing text
  6047. If !pGraphics
  6048. Return 2
  6049.  
  6050. Return DllCall("gdiplus\GdipSetTextContrast", "UPtr", pGraphics, "uint", Contrast)
  6051. }
  6052.  
  6053. Gdip_RestoreGraphics(pGraphics, State) {
  6054. ; Sets the state of this Graphics object to the state stored by a previous call to the Save method of this Graphics object.
  6055. ; Parameters:
  6056. ; State:
  6057. ; A value returned by a previous call to the Save method that identifies a block of saved state.
  6058. ; Return value:
  6059. ; Returns TRUE if successful, or FALSE otherwise. To get extended error information, check «Gdiplus.LastStatus».
  6060. ; https://docs.microsoft.com/en-us/windows/win32/api/gdiplusgraphics/nf-gdiplusgraphics-graphics-restore
  6061. return DllCall("gdiplus\GdipRestoreGraphics", "UPtr", pGraphics, "UInt", State)
  6062. }
  6063.  
  6064. Gdip_SaveGraphics(pGraphics) {
  6065. ; Saves the current state (transformations, clipping region, and quality settings) of this Graphics object.
  6066. ; You can restore the state later by calling the Restore method.
  6067. ; Return value:
  6068. ; Returns a value that identifies the saved state.
  6069. ; Pass this value to the Restore method when you want to restore the state.
  6070. ; Remarks:
  6071. ; The identifier returned by a given call to the Save method can be passed only once to the Restore method.
  6072. ; https://docs.microsoft.com/en-us/windows/win32/api/gdiplusgraphics/nf-gdiplusgraphics-graphics-save
  6073. State := 0
  6074. gdipLastError := DllCall("gdiplus\GdipSaveGraphics", "UPtr", pGraphics, "UInt*", State)
  6075. return State
  6076. }
  6077.  
  6078. Gdip_BeginGraphicsContainer(pGraphics) {
  6079. containerId := 0
  6080. gdipLastError := DllCall("gdiplus\GdipBeginContainer2", "UPtr", pGraphics, "UInt*", containerId)
  6081. Return containerId
  6082. }
  6083.  
  6084. Gdip_EndGraphicsContainer(pGraphics, containerId) {
  6085. containerId := 0
  6086. Return DllCall("gdiplus\GdipBeginContainer2", "UPtr", pGraphics, "UInt", containerId)
  6087. }
  6088.  
  6089. Gdip_GetTextContrast(pGraphics) {
  6090. result := 0
  6091. E := DllCall("gdiplus\GdipGetTextContrast", "UPtr", pGraphics, "uint*", result)
  6092. If E
  6093. return -1
  6094. Return result
  6095. }
  6096.  
  6097. Gdip_GetCompositingMode(pGraphics) {
  6098. result := 0
  6099. E := DllCall("gdiplus\GdipGetCompositingMode", "UPtr", pGraphics, "int*", result)
  6100. If E
  6101. return -1
  6102. Return result
  6103. }
  6104.  
  6105. Gdip_GetCompositingQuality(pGraphics) {
  6106. result := 0
  6107. E := DllCall("gdiplus\GdipGetCompositingQuality", "UPtr", pGraphics, "int*", result)
  6108. If E
  6109. return -1
  6110. Return result
  6111. }
  6112.  
  6113. Gdip_GetInterpolationMode(pGraphics) {
  6114. result := 0
  6115. E := DllCall("gdiplus\GdipGetInterpolationMode", "UPtr", pGraphics, "int*", result)
  6116. If E
  6117. return -1
  6118. Return result
  6119. }
  6120.  
  6121. Gdip_GetSmoothingMode(pGraphics) {
  6122. result := 0
  6123. E := DllCall("gdiplus\GdipGetSmoothingMode", "UPtr", pGraphics, "int*", result)
  6124. If E
  6125. return -1
  6126. Return result
  6127. }
  6128.  
  6129. Gdip_GetPageScale(pGraphics) {
  6130. result := 0
  6131. E := DllCall("gdiplus\GdipGetPageScale", "UPtr", pGraphics, "float*", result)
  6132. If E
  6133. return -1
  6134. Return result
  6135. }
  6136.  
  6137. Gdip_GetPageUnit(pGraphics) {
  6138. result := 0
  6139. E := DllCall("gdiplus\GdipGetPageUnit", "UPtr", pGraphics, "int*", result)
  6140. If E
  6141. return -1
  6142. Return result
  6143. }
  6144.  
  6145. Gdip_GetPixelOffsetMode(pGraphics) {
  6146. result := 0
  6147. E := DllCall("gdiplus\GdipGetPixelOffsetMode", "UPtr", pGraphics, "int*", result)
  6148. If E
  6149. return -1
  6150. Return result
  6151. }
  6152.  
  6153. Gdip_GetRenderingOrigin(pGraphics, ByRef X, ByRef Y) {
  6154. x := 0, y := 0
  6155. return DllCall("gdiplus\GdipGetRenderingOrigin", "UPtr", pGraphics, "uint*", X, "uint*", Y)
  6156. }
  6157.  
  6158. Gdip_GetTextRenderingHint(pGraphics) {
  6159. result := 0
  6160. E := DllCall("gdiplus\GdipGetTextRenderingHint", "UPtr", pGraphics, "int*", result)
  6161. If E
  6162. return -1
  6163. Return result
  6164. }
  6165.  
  6166. ;#####################################################################################
  6167. ; More pGraphics functions
  6168. ;#####################################################################################
  6169.  
  6170. Gdip_RotateWorldTransform(pGraphics, Angle, MatrixOrder:=0) {
  6171. ; MatrixOrder options:
  6172. ; Prepend = 0; The new operation is applied before the old operation.
  6173. ; Append = 1; The new operation is applied after the old operation.
  6174. ; Order of matrices multiplication:.
  6175.  
  6176. return DllCall("gdiplus\GdipRotateWorldTransform", "UPtr", pGraphics, "float", Angle, "int", MatrixOrder)
  6177. }
  6178.  
  6179. Gdip_ScaleWorldTransform(pGraphics, ScaleX, ScaleY, MatrixOrder:=0) {
  6180. return DllCall("gdiplus\GdipScaleWorldTransform", "UPtr", pGraphics, "float", ScaleX, "float", ScaleY, "int", MatrixOrder)
  6181. }
  6182.  
  6183. Gdip_TranslateWorldTransform(pGraphics, x, y, MatrixOrder:=0) {
  6184. return DllCall("gdiplus\GdipTranslateWorldTransform", "UPtr", pGraphics, "float", x, "float", y, "int", MatrixOrder)
  6185. }
  6186.  
  6187. Gdip_MultiplyWorldTransform(pGraphics, hMatrix, matrixOrder:=0) {
  6188. Return DllCall("gdiplus\GdipMultiplyWorldTransform", "UPtr", pGraphics, "UPtr", hMatrix, "int", matrixOrder)
  6189. }
  6190.  
  6191. Gdip_ResetWorldTransform(pGraphics) {
  6192. return DllCall("gdiplus\GdipResetWorldTransform", "UPtr", pGraphics)
  6193. }
  6194.  
  6195. Gdip_ResetPageTransform(pGraphics) {
  6196. return DllCall("gdiplus\GdipResetPageTransform", "UPtr", pGraphics)
  6197. }
  6198.  
  6199. Gdip_SetWorldTransform(pGraphics, hMatrix) {
  6200. return DllCall("gdiplus\GdipSetWorldTransform", "UPtr", pGraphics, "UPtr", hMatrix)
  6201. }
  6202.  
  6203. Gdip_GetRotatedTranslation(Width, Height, Angle, ByRef xTranslation, ByRef yTranslation) {
  6204. Static pi := 3.141592653
  6205. TAngle := Angle*(pi/180)
  6206.  
  6207. Bound := (Angle >= 0) ? Mod(Angle, 360) : 360-Mod(-Angle, -360)
  6208. if ((Bound >= 0) && (Bound <= 90))
  6209. xTranslation := Height*Sin(TAngle), yTranslation := 0
  6210. else if ((Bound > 90) && (Bound <= 180))
  6211. xTranslation := (Height*Sin(TAngle))-(Width*Cos(TAngle)), yTranslation := -Height*Cos(TAngle)
  6212. else if ((Bound > 180) && (Bound <= 270))
  6213. xTranslation := -(Width*Cos(TAngle)), yTranslation := -(Height*Cos(TAngle))-(Width*Sin(TAngle))
  6214. else if ((Bound > 270) && (Bound <= 360))
  6215. xTranslation := 0, yTranslation := -Width*Sin(TAngle)
  6216. }
  6217.  
  6218. Gdip_GetRotatedDimensions(Width, Height, Angle, ByRef RWidth, ByRef RHeight) {
  6219. ; modified by Marius Șucan
  6220. Static pi := 3.141592653
  6221. if !(Width && Height)
  6222. return -1
  6223.  
  6224. TAngle := Angle*(pi/180)
  6225. cTAngle := Cos(TAngle)
  6226. sTAngle := Sin(TAngle)
  6227. RWidth := Abs(Width * cTAngle) + Abs(Height * sTAngle)
  6228. RHeight := Abs(Width * sTAngle) + Abs(Height * cTangle)
  6229. }
  6230.  
  6231. Gdip_GetRotatedEllipseDimensions(Width, Height, Angle, ByRef RWidth, ByRef RHeight) {
  6232. if !(Width && Height)
  6233. return -1
  6234.  
  6235. pPath := Gdip_CreatePath()
  6236. Gdip_AddPathEllipse(pPath, 0, 0, Width, Height)
  6237. ; testAngle := Mod(Angle, 30)
  6238. pMatrix := Gdip_CreateMatrix()
  6239. Gdip_RotateMatrix(pMatrix, Angle, MatrixOrder)
  6240. E := Gdip_TransformPath(pPath, pMatrix)
  6241. Gdip_DeleteMatrix(pMatrix)
  6242.  
  6243. thisBMP := Gdip_CreateBitmap(10, 10)
  6244. dummyG := Gdip_GraphicsFromImage(thisBMP)
  6245. Gdip_SetClipPath(dummyG, pPath) ; it is more accurate to use this instead of Gdip_GetPathWorldBounds()
  6246. pathBounds := Gdip_GetClipBounds(dummyG)
  6247. Gdip_DeletePath(pPath)
  6248. RWidth := pathBounds.w
  6249. RHeight := pathBounds.h
  6250. Gdip_DeleteGraphics(dummyG)
  6251. Gdip_DisposeImage(thisBMP)
  6252. Return E
  6253. }
  6254.  
  6255. Gdip_GetWorldTransform(pGraphics) {
  6256. ; Returns the world transformation matrix of a pGraphics object.
  6257. ; On error, it returns -1
  6258. hMatrix := 0
  6259. gdipLastError := DllCall("gdiplus\GdipGetWorldTransform", "UPtr", pGraphics, "UPtr*", hMatrix)
  6260. Return hMatrix
  6261. }
  6262.  
  6263. Gdip_IsVisibleGraphPoint(pGraphics, X, Y) {
  6264. result := 0
  6265. E := DllCall("gdiplus\GdipIsVisiblePoint", "UPtr", pGraphics, "float", X, "float", Y, "int*", result)
  6266. If E
  6267. Return -1
  6268. Return result
  6269. }
  6270.  
  6271. Gdip_IsVisibleGraphRect(pGraphics, X, Y, Width, Height) {
  6272. result := 0
  6273. E := DllCall("gdiplus\GdipIsVisibleRect", "UPtr", pGraphics, "float", X, "float", Y, "float", Width, "float", Height, "int*", result)
  6274. If E
  6275. Return -1
  6276. Return result
  6277. }
  6278.  
  6279. Gdip_IsVisibleGraphRectEntirely(pGraphics, X, Y, Width, Height) {
  6280. ; Return values:
  6281. ; -2 - mixed state
  6282. ; -1 - error
  6283. ; 0 - rect is entirely not visible
  6284. ; 1 - rect is entirely visible
  6285.  
  6286. a := Gdip_IsVisibleGraphPoint(pGraphics, X, Y)
  6287. b := Gdip_IsVisibleGraphPoint(pGraphics, X + Width, Y)
  6288. c := Gdip_IsVisibleGraphPoint(pGraphics, X + Width, Y + Height)
  6289. d := Gdip_IsVisibleGraphPoint(pGraphics, X, Y + Height)
  6290. If (a=1 && b=1 && c=1 && d=1)
  6291. Return 1
  6292. Else If (a=-1 || b=-1 || c=-1 || d=-1)
  6293. Return -1
  6294. Else If (a=0 && b=0 && c=0 && d=0)
  6295. Return 0
  6296. Else
  6297. Return -2
  6298. }
  6299.  
  6300. ;#####################################################################################
  6301. ; Region and clip functions [pGraphics related]
  6302. ;
  6303. ; One of the properties of the pGraphics class is the clip region.
  6304. ; All drawing done in a given pGraphics object can be restricted
  6305. ; to the clip region of that pGraphics object.
  6306.  
  6307. ; The GDI+ Region class allows you to define a custom shape.
  6308. ; The shape[s] can be made up of lines, polygons, and curves.
  6309. ;
  6310. ; Two common uses for regions are hit testing and clipping.
  6311. ; Hit testing is determining whether the mouse was clicked
  6312. ; in a certain region of the screen.
  6313. ;
  6314. ; Clipping is restricting drawing to a certain region in
  6315. ; a given pGraphics object.
  6316. ;
  6317. ;#####################################################################################
  6318.  
  6319. Gdip_IsClipEmpty(pGraphics) {
  6320. ; Determines whether the clipping region of a pGraphics object is empty
  6321. result := 0
  6322. E := DllCall("gdiplus\GdipIsClipEmpty", "UPtr", pGraphics, "int*", result)
  6323. If E
  6324. Return -1
  6325. Return result
  6326. }
  6327.  
  6328. Gdip_IsVisibleClipEmpty(pGraphics) {
  6329. result := 0
  6330. E := DllCall("gdiplus\GdipIsVisibleClipEmpty", "UPtr", pGraphics, "uint*", result)
  6331. If E
  6332. Return -1
  6333. Return result
  6334. }
  6335.  
  6336. ;#####################################################################################
  6337.  
  6338. ; Name............. Gdip_SetClipFromGraphics
  6339. ;
  6340. ; Parameters:
  6341. ; pGraphicsA Pointer to a pGraphics object
  6342. ; pGrahpicsB Pointer to a pGraphics object that contains the clipping region to be combined with
  6343. ; the clipping region of the pGraphicsA object
  6344. ; CombineMode Regions combination mode:
  6345. ; 0 - The existing region is replaced by the new region
  6346. ; 1 - The existing region is replaced by the intersection of itself and the new region
  6347. ; 2 - The existing region is replaced by the union of itself and the new region
  6348. ; 3 - The existing region is replaced by the result of performing an XOR on the two regions
  6349. ; 4 - The existing region is replaced by the portion of itself that is outside of the new region
  6350. ; 5 - The existing region is replaced by the portion of the new region that is outside of the existing region
  6351. ; return Status enumeration value
  6352.  
  6353. Gdip_SetClipFromGraphics(pGraphics, pGraphicsSrc, CombineMode:=0) {
  6354. return DllCall("gdiplus\GdipSetClipGraphics", "UPtr", pGraphics, "UPtr", pGraphicsSrc, "int", CombineMode)
  6355. }
  6356.  
  6357. Gdip_GetClipBounds(pGraphics) {
  6358. VarSetCapacity(RectF, 16, 0)
  6359. E := DllCall("gdiplus\GdipGetClipBounds", "UPtr", pGraphics, "UPtr", &RectF)
  6360. If !E
  6361. Return RetrieveRectF(RectF)
  6362. Else
  6363. Return E
  6364. }
  6365.  
  6366. Gdip_GetVisibleClipBounds(pGraphics) {
  6367. VarSetCapacity(RectF, 16, 0)
  6368. E := DllCall("gdiplus\GdipGetVisibleClipBounds", "UPtr", pGraphics, "UPtr", &RectF)
  6369. If !E
  6370. Return RetrieveRectF(RectF)
  6371. Else
  6372. Return E
  6373. }
  6374.  
  6375. Gdip_TranslateClip(pGraphics, dX, dY) {
  6376. return DllCall("gdiplus\GdipTranslateClip", "UPtr", pGraphics, "float", dX, "float", dY)
  6377. }
  6378.  
  6379. Gdip_ResetClip(pGraphics) {
  6380. return DllCall("gdiplus\GdipResetClip", "UPtr", pGraphics)
  6381. }
  6382.  
  6383. Gdip_GetClipRegion(pGraphics) {
  6384. hRegion := Gdip_CreateRegion()
  6385. gdipLastError := DllCall("gdiplus\GdipGetClip", "UPtr", pGraphics, "UPtr", hRegion)
  6386. return hRegion
  6387. }
  6388.  
  6389. Gdip_SetClipRegion(pGraphics, hRegion, CombineMode:=0) {
  6390. ; see CombineMode options from Gdip_SetClipRect()
  6391. return DllCall("gdiplus\GdipSetClipRegion", "UPtr", pGraphics, "UPtr", hRegion, "int", CombineMode)
  6392. }
  6393.  
  6394. Gdip_SetClipRect(pGraphics, x, y, w, h, CombineMode:=0) {
  6395. ; CombineMode options:
  6396. ; Replace = 0
  6397. ; Intersect = 1
  6398. ; Union = 2
  6399. ; Xor = 3
  6400. ; Exclude = 4
  6401. ; Complement = 5
  6402.  
  6403. return DllCall("gdiplus\GdipSetClipRect", "UPtr", pGraphics, "float", x, "float", y, "float", w, "float", h, "int", CombineMode)
  6404. }
  6405.  
  6406. Gdip_SetClipPath(pGraphics, pPath, CombineMode:=0) {
  6407. ; this can become very slow with very large paths
  6408. return DllCall("gdiplus\GdipSetClipPath", "UPtr", pGraphics, "UPtr", pPath, "int", CombineMode)
  6409. }
  6410.  
  6411. Gdip_SetClipHRGN(pGraphics, pHRGN, CombineMode:=0) {
  6412. ; pHRGN must be a pointer of a GDI region
  6413. return DllCall("gdiplus\GdipSetClipHrgn", "UPtr", pGraphics, "UPtr" , pHRGN, "UInt", combineMode)
  6414. }
  6415.  
  6416. Gdip_CombineRegionRegion(hRegion1, hRegion2, CombineMode) {
  6417. ; Updates this region to the portion of itself that intersects another region. Added by Learning one
  6418. ; see CombineMode options from Gdip_SetClipRect()
  6419.  
  6420. return DllCall("gdiplus\GdipCombineRegionRegion", "UPtr", hRegion1, "UPtr", hRegion2, "int", CombineMode)
  6421. }
  6422.  
  6423. Gdip_CombineRegionRect(hRegion, x, y, w, h, CombineMode) {
  6424. ; Updates this region to the portion of itself that intersects with the given rectangle.
  6425. ; see CombineMode options from Gdip_SetClipRect()
  6426.  
  6427. CreateRectF(RectF, x, y, w, h)
  6428. return DllCall("gdiplus\GdipCombineRegionRect", "UPtr", hRegion, "UPtr", &RectF, "int", CombineMode)
  6429. }
  6430.  
  6431. Gdip_CombineRegionPath(hRegion, pPath, CombineMode) {
  6432. ; see CombineMode options from Gdip_SetClipRect()
  6433. return DllCall("gdiplus\GdipCombineRegionPath", "UPtr", hRegion, "UPtr", pPath, "int", CombineMode)
  6434. }
  6435.  
  6436. Gdip_CreateRegion() {
  6437. hRegion := 0
  6438. gdipLastError := DllCall("gdiplus\GdipCreateRegion", "UPtr*", hRegion)
  6439. return hRegion
  6440. }
  6441.  
  6442. Gdip_CreateRegionPath(pPath) {
  6443. ; Creates a region that is defined by a GraphicsPath [pPath object]. Written by Learning one.
  6444.  
  6445. hRegion := 0
  6446. gdipLastError := DllCall("gdiplus\GdipCreateRegionPath", "UPtr", pPath, "UPtr*", hRegion)
  6447. return hRegion
  6448. }
  6449.  
  6450. Gdip_CreateRegionRect(x, y, w, h) {
  6451. hRegion := 0
  6452. CreateRectF(RectF, x, y, w, h)
  6453. gdipLastError := DllCall("gdiplus\GdipCreateRegionRect", "UPtr", &RectF, "UPtr*", hRegion)
  6454. return hRegion
  6455. }
  6456.  
  6457. Gdip_CreateRegionHRGN(pHRGN) {
  6458. ; The function creates a GDI+ region that is identical to the region that is specified
  6459. ; by a handle to a Microsoft Windows Graphics Device Interface (GDI) region.
  6460. ; The GDI region defined by pHRGN must be disposed using DeleteObject().
  6461.  
  6462. hRegion := 0
  6463. gdipLastError := DllCall("gdiplus\GdipCreateRegionHrgn", "UPtr", pHRGN, "Ptr*", hRegion)
  6464. return hRegion
  6465. }
  6466.  
  6467. Gdip_CreateRegionRgnData(rgnData, dataSize) {
  6468. ; This function creates a region that is defined by data obtained from another region.
  6469. ; Parameters
  6470. ; rgnData = Pointer to an array of bytes that specifies a region.
  6471. ; The data can be obtained from another region by using the Gdip_GetRegionData.
  6472.  
  6473. ; dataSize = specifies the number of bytes in the rgnData array.
  6474. hRegion := 0
  6475. gdipLastError := DllCall("gdiplus\GdipCreateRegionRgnData", "UPtr" , rgnData, "Int" , dataSize, "Ptr*", hRegion)
  6476. return hRegion
  6477. }
  6478.  
  6479. Gdip_GetRegionHRgn(pGraphics, hRegion) {
  6480. ; This function creates a Microsoft Windows Graphics Device Interface (GDI) region from this region.
  6481. pHRGN := 0
  6482. gdipLastError := DllCall("gdiplus\GdipGetRegionHRgn", "UPtr", hRegion, "UPtr", pGraphics, "Ptr*", pHRGN)
  6483. Return pHRGN
  6484. }
  6485.  
  6486. Gdip_GetRegionData(hRegion, ByRef rgnData, ByRef rgnDataSize) {
  6487. ; Gets binary data that describes hRegion.
  6488. ; function by MCL
  6489.  
  6490. DllCall("GdiPlus\GdipGetRegionDataSize", "UPtr", hRegion, "UInt*", rgnBufferSize := 0)
  6491. VarSetCapacity(rgnData, rgnBufferSize, 0)
  6492. gdipLastError := DllCall("gdiplus\GdipGetRegionData"
  6493. , "UPtr" , hRegion
  6494. , "UPtr" , &rgnData
  6495. , "UInt" , rgnBufferSize
  6496. , "UInt*", rgnDataSize)
  6497. Return gdipLastError
  6498. }
  6499.  
  6500. Gdip_IsEmptyRegion(pGraphics, hRegion) {
  6501. result := 0
  6502. gdipLastError := DllCall("gdiplus\GdipIsEmptyRegion", "UPtr", hRegion, "UPtr", pGraphics, "uInt*", result)
  6503. Return result
  6504. }
  6505.  
  6506. Gdip_IsEqualRegion(pGraphics, hRegion1, hRegion2) {
  6507. result := 0
  6508. gdipLastError := DllCall("gdiplus\GdipIsEqualRegion", "UPtr", hRegion1, "UPtr", hRegion2, "UPtr", pGraphics, "uInt*", result)
  6509. Return result
  6510. }
  6511.  
  6512. Gdip_IsInfiniteRegion(pGraphics, hRegion) {
  6513. result := 0
  6514. E := DllCall("gdiplus\GdipIsInfiniteRegion", "UPtr", hRegion, "UPtr", pGraphics, "uInt*", result)
  6515. If E
  6516. return -1
  6517. Return result
  6518. }
  6519.  
  6520. Gdip_IsVisibleRegionPoint(pGraphics, hRegion, x, y) {
  6521. result := 0
  6522. E := DllCall("gdiplus\GdipIsVisibleRegionPoint", "UPtr", hRegion, "float", X, "float", Y, "UPtr", pGraphics, "uInt*", result)
  6523. If E
  6524. return -1
  6525. Return result
  6526. }
  6527.  
  6528. Gdip_IsVisibleRegionRect(pGraphics, hRegion, x, y, width, height) {
  6529. result := 0
  6530. E := DllCall("gdiplus\GdipIsVisibleRegionRect", "UPtr", hRegion, "float", X, "float", Y, "float", Width, "float", Height, "UPtr", pGraphics, "uInt*", result)
  6531. If E
  6532. return -1
  6533. Return result
  6534. }
  6535.  
  6536. Gdip_IsVisibleRegionRectEntirely(pGraphics, hRegion, X, Y, Width, Height) {
  6537. ; Return values:
  6538. ; -2 - mixed state
  6539. ; -1 - error
  6540. ; 0 - rect is entirely not visible
  6541. ; 1 - rect is entirely visible
  6542.  
  6543. a := Gdip_IsVisibleRegionPoint(pGraphics, hRegion, X, Y)
  6544. b := Gdip_IsVisibleRegionPoint(pGraphics, hRegion, X + Width, Y)
  6545. c := Gdip_IsVisibleRegionPoint(pGraphics, hRegion, X + Width, Y + Height)
  6546. d := Gdip_IsVisibleRegionPoint(pGraphics, hRegion, X, Y + Height)
  6547. If (a=1 && b=1 && c=1 && d=1)
  6548. Return 1
  6549. Else If (a=-1 || b=-1 || c=-1 || d=-1)
  6550. Return -1
  6551. Else If (a=0 && b=0 && c=0 && d=0)
  6552. Return 0
  6553. Else
  6554. Return -2
  6555. }
  6556.  
  6557. Gdip_SetEmptyRegion(hRegion) {
  6558. return DllCall("gdiplus\GdipSetEmpty", "UPtr", hRegion)
  6559. }
  6560.  
  6561. Gdip_SetInfiniteRegion(hRegion) {
  6562. return DllCall("gdiplus\GdipSetInfinite", "UPtr", hRegion)
  6563. }
  6564.  
  6565. Gdip_GetRegionBounds(pGraphics, hRegion) {
  6566. VarSetCapacity(RectF, 16, 0)
  6567. E := DllCall("gdiplus\GdipGetRegionBounds", "UPtr", hRegion, "UPtr", pGraphics, "UPtr", &RectF)
  6568. If !E
  6569. Return RetrieveRectF(RectF)
  6570. Else
  6571. Return E
  6572. }
  6573.  
  6574. Gdip_TranslateRegion(hRegion, X, Y) {
  6575. return DllCall("gdiplus\GdipTranslateRegion", "UPtr", hRegion, "float", X, "float", Y)
  6576. }
  6577.  
  6578. Gdip_RotateRegionAtCenter(pGraphics, Region, Angle, MatrixOrder:=1) {
  6579. ; function by Marius Șucan
  6580. ; based on Gdip_RotatePathAtCenter() by RazorHalo
  6581.  
  6582. Rect := Gdip_GetRegionBounds(pGraphics, Region)
  6583. cX := Rect.x + (Rect.w / 2)
  6584. cY := Rect.y + (Rect.h / 2)
  6585. pMatrix := Gdip_CreateMatrix()
  6586. Gdip_TranslateMatrix(pMatrix, -cX , -cY)
  6587. Gdip_RotateMatrix(pMatrix, Angle, MatrixOrder)
  6588. Gdip_TranslateMatrix(pMatrix, cX, cY, MatrixOrder)
  6589. E := Gdip_TransformRegion(Region, pMatrix)
  6590. Gdip_DeleteMatrix(pMatrix)
  6591. Return E
  6592. }
  6593.  
  6594. Gdip_TransformRegion(Region, pMatrix) {
  6595. return DllCall("gdiplus\GdipTransformRegion", "UPtr", Region, "UPtr", pMatrix)
  6596. }
  6597.  
  6598. Gdip_CloneRegion(Region) {
  6599. newRegion := 0
  6600. gdipLastError := DllCall("gdiplus\GdipCloneRegion", "UPtr", Region, "UInt*", newRegion)
  6601. return newRegion
  6602. }
  6603.  
  6604. ;#####################################################################################
  6605. ; BitmapLockBits
  6606. ;#####################################################################################
  6607.  
  6608. Gdip_LockBits(pBitmap, x, y, w, h, ByRef Stride, ByRef Scan0, ByRef BitmapData, LockMode := 3, PixelFormat := 0x26200a) {
  6609. /*
  6610. BitmapData structure
  6611. Width UINT Number of pixels in one scan line of the bitmap.
  6612. Height UINT Number of scan lines in the bitmap.
  6613. Stride INT Offset, in bytes, between consecutive scan lines of the bitmap. If the stride is positive, the bitmap is top-down. If the stride is negative, the bitmap is bottom-up.
  6614. In other words, it is the amount of bytes to skip to get to the next line of pixels on the image. This is not always equal to "width * bytes per pixel".
  6615. PixFmt PixelFormat Integer that specifies the pixel format to convert to when locking the bits data; for performance, should be the same as the bitmap's pixel format
  6616. on repetitive pixel format conversions, colors might become visibly altered / affected
  6617. Scan0 void* Pointer to the first (index 0) scan line of the bitmap.
  6618. LockModes:
  6619. 1 - Read
  6620. 2 - Write
  6621. 3 - Read/Write
  6622. */
  6623.  
  6624. CreateRectF(Rect, x, y, w, h, "uint")
  6625. VarSetCapacity(BitmapData, 16+2*A_PtrSize, 0)
  6626. _E := DllCall("Gdiplus\GdipBitmapLockBits", "UPtr", pBitmap, "UPtr", &Rect, "uint", LockMode, "int", PixelFormat, "UPtr", &BitmapData)
  6627. Stride := NumGet(BitmapData, 8, "Int")
  6628. Scan0 := NumGet(BitmapData, 16, "UPtr")
  6629. return _E
  6630. }
  6631.  
  6632. Gdip_UnlockBits(pBitmap, ByRef BitmapData) {
  6633. return DllCall("Gdiplus\GdipBitmapUnlockBits", "UPtr", pBitmap, "UPtr", &BitmapData)
  6634. }
  6635.  
  6636. Gdip_SetLockBitPixel(ARGB, Scan0, x, y, Stride) {
  6637. NumPut(ARGB, Scan0+0, (x*4)+(y*Stride), "UInt")
  6638. }
  6639.  
  6640. Gdip_GetLockBitPixel(Scan0, x, y, Stride) {
  6641. return NumGet(Scan0+0, (x*4)+(y*Stride), "UInt")
  6642. }
  6643.  
  6644. ;#####################################################################################
  6645.  
  6646. Gdip_PixelateBitmap(pBitmap, ByRef pBitmapOut, BlockSize) {
  6647. /*
  6648. C/C++ Function by Tic and fixed by Fincs;
  6649. https://autohotkey.com/board/topic/29449-gdi-standard-library-145-by-tic/page-55
  6650.  
  6651. int __stdcall Gdip_PixelateBitmap(unsigned char * sBitmap, unsigned char * dBitmap, int w, int h, int Stride, int Size)
  6652. {
  6653. int sA, sR, sG, sB, rw, rh, o;
  6654.  
  6655. for (int y1 = 0; y1 < h/Size; ++y1)
  6656. {
  6657. for (int x1 = 0; x1 < w/Size; ++x1)
  6658. {
  6659. sA = sR = sG = sB = 0;
  6660. for (int y2 = 0; y2 < Size; ++y2)
  6661. {
  6662. for (int x2 = 0; x2 < Size; ++x2)
  6663. {
  6664. o = 4*(x2+x1*Size)+Stride*(y2+y1*Size);
  6665. sA += sBitmap[3+o];
  6666. sR += sBitmap[2+o];
  6667. sG += sBitmap[1+o];
  6668. sB += sBitmap[o];
  6669. }
  6670. }
  6671.  
  6672. sA /= Size*Size;
  6673. sR /= Size*Size;
  6674. sG /= Size*Size;
  6675. sB /= Size*Size;
  6676. for (int y2 = 0; y2 < Size; ++y2)
  6677. {
  6678. for (int x2 = 0; x2 < Size; ++x2)
  6679. {
  6680. o = 4*(x2+x1*Size)+Stride*(y2+y1*Size);
  6681. dBitmap[3+o] = sA;
  6682. dBitmap[2+o] = sR;
  6683. dBitmap[1+o] = sG;
  6684. dBitmap[o] = sB;
  6685. }
  6686. }
  6687. }
  6688.  
  6689. if (w % Size != 0)
  6690. {
  6691. sA = sR = sG = sB = 0;
  6692. for (int y2 = 0; y2 < Size; ++y2)
  6693. {
  6694. for (int x2 = 0; x2 < w % Size; ++x2)
  6695. {
  6696. o = 4*(x2+(w/Size)*Size)+Stride*(y2+y1*Size);
  6697. sA += sBitmap[3+o];
  6698. sR += sBitmap[2+o];
  6699. sG += sBitmap[1+o];
  6700. sB += sBitmap[o];
  6701. }
  6702. }
  6703.  
  6704. {
  6705. int tmp = (w % Size)*Size;
  6706. sA = tmp ? (sA / tmp) : 0;
  6707. sR = tmp ? (sR / tmp) : 0;
  6708. sG = tmp ? (sG / tmp) : 0;
  6709. sB = tmp ? (sB / tmp) : 0;
  6710. }
  6711. for (int y2 = 0; y2 < Size; ++y2)
  6712. {
  6713. for (int x2 = 0; x2 < w % Size; ++x2)
  6714. {
  6715. o = 4*(x2+(w/Size)*Size)+Stride*(y2+y1*Size);
  6716. dBitmap[3+o] = sA;
  6717. dBitmap[2+o] = sR;
  6718. dBitmap[1+o] = sG;
  6719. dBitmap[o] = sB;
  6720. }
  6721. }
  6722. }
  6723. }
  6724.  
  6725. for (int x1 = 0; x1 < w/Size; ++x1)
  6726. {
  6727. sA = sR = sG = sB = 0;
  6728. for (int y2 = 0; y2 < h % Size; ++y2)
  6729. {
  6730. for (int x2 = 0; x2 < Size; ++x2)
  6731. {
  6732. o = 4*(x2+x1*Size)+Stride*(y2+(h/Size)*Size);
  6733. sA += sBitmap[3+o];
  6734. sR += sBitmap[2+o];
  6735. sG += sBitmap[1+o];
  6736. sB += sBitmap[o];
  6737. }
  6738. }
  6739.  
  6740. {
  6741. int tmp = Size*(h % Size);
  6742. sA = tmp ? (sA / tmp) : 0;
  6743. sR = tmp ? (sR / tmp) : 0;
  6744. sG = tmp ? (sG / tmp) : 0;
  6745. sB = tmp ? (sB / tmp) : 0;
  6746. }
  6747.  
  6748. for (int y2 = 0; y2 < h % Size; ++y2)
  6749. {
  6750. for (int x2 = 0; x2 < Size; ++x2)
  6751. {
  6752. o = 4*(x2+x1*Size)+Stride*(y2+(h/Size)*Size);
  6753. dBitmap[3+o] = sA;
  6754. dBitmap[2+o] = sR;
  6755. dBitmap[1+o] = sG;
  6756. dBitmap[o] = sB;
  6757. }
  6758. }
  6759. }
  6760.  
  6761. sA = sR = sG = sB = 0;
  6762. for (int y2 = 0; y2 < h % Size; ++y2)
  6763. {
  6764. for (int x2 = 0; x2 < w % Size; ++x2)
  6765. {
  6766. o = 4*(x2+(w/Size)*Size)+Stride*(y2+(h/Size)*Size);
  6767. sA += sBitmap[3+o];
  6768. sR += sBitmap[2+o];
  6769. sG += sBitmap[1+o];
  6770. sB += sBitmap[o];
  6771. }
  6772. }
  6773.  
  6774. {
  6775. int tmp = (w % Size)*(h % Size);
  6776. sA = tmp ? (sA / tmp) : 0;
  6777. sR = tmp ? (sR / tmp) : 0;
  6778. sG = tmp ? (sG / tmp) : 0;
  6779. sB = tmp ? (sB / tmp) : 0;
  6780. }
  6781.  
  6782. for (int y2 = 0; y2 < h % Size; ++y2)
  6783. {
  6784. for (int x2 = 0; x2 < w % Size; ++x2)
  6785. {
  6786. o = 4*(x2+(w/Size)*Size)+Stride*(y2+(h/Size)*Size);
  6787. dBitmap[3+o] = sA;
  6788. dBitmap[2+o] = sR;
  6789. dBitmap[1+o] = sG;
  6790. dBitmap[o] = sB;
  6791. }
  6792. }
  6793. return 0;
  6794. }
  6795.  
  6796. */
  6797.  
  6798. static PixelateBitmap
  6799. if (!PixelateBitmap)
  6800. {
  6801. if (A_PtrSize!=8) ; x86 machine code
  6802. MCode_PixelateBitmap := "
  6803. (LTrim Join
  6804. 558BEC83EC3C8B4514538B5D1C99F7FB56578BC88955EC894DD885C90F8E830200008B451099F7FB8365DC008365E000894DC88955F08945E833FF897DD4
  6805. 397DE80F8E160100008BCB0FAFCB894DCC33C08945F88945FC89451C8945143BD87E608B45088D50028BC82BCA8BF02BF2418945F48B45E02955F4894DC4
  6806. 8D0CB80FAFCB03CA895DD08BD1895DE40FB64416030145140FB60201451C8B45C40FB604100145FC8B45F40FB604020145F883C204FF4DE475D6034D18FF
  6807. 4DD075C98B4DCC8B451499F7F98945148B451C99F7F989451C8B45FC99F7F98945FC8B45F899F7F98945F885DB7E648B450C8D50028BC82BCA83C103894D
  6808. C48BC82BCA41894DF48B4DD48945E48B45E02955E48D0C880FAFCB03CA895DD08BD18BF38A45148B7DC48804178A451C8B7DF488028A45FC8804178A45F8
  6809. 8B7DE488043A83C2044E75DA034D18FF4DD075CE8B4DCC8B7DD447897DD43B7DE80F8CF2FEFFFF837DF0000F842C01000033C08945F88945FC89451C8945
  6810. 148945E43BD87E65837DF0007E578B4DDC034DE48B75E80FAF4D180FAFF38B45088D500203CA8D0CB18BF08BF88945F48B45F02BF22BFA2955F48945CC0F
  6811. B6440E030145140FB60101451C0FB6440F010145FC8B45F40FB604010145F883C104FF4DCC75D8FF45E4395DE47C9B8B4DF00FAFCB85C9740B8B451499F7
  6812. F9894514EB048365140033F63BCE740B8B451C99F7F989451CEB0389751C3BCE740B8B45FC99F7F98945FCEB038975FC3BCE740B8B45F899F7F98945F8EB
  6813. 038975F88975E43BDE7E5A837DF0007E4C8B4DDC034DE48B75E80FAF4D180FAFF38B450C8D500203CA8D0CB18BF08BF82BF22BFA2BC28B55F08955CC8A55
  6814. 1488540E038A551C88118A55FC88540F018A55F888140183C104FF4DCC75DFFF45E4395DE47CA68B45180145E0015DDCFF4DC80F8594FDFFFF8B451099F7
  6815. FB8955F08945E885C00F8E450100008B45EC0FAFC38365DC008945D48B45E88945CC33C08945F88945FC89451C8945148945103945EC7E6085DB7E518B4D
  6816. D88B45080FAFCB034D108D50020FAF4D18034DDC8BF08BF88945F403CA2BF22BFA2955F4895DC80FB6440E030145140FB60101451C0FB6440F010145FC8B
  6817. 45F40FB604080145F883C104FF4DC875D8FF45108B45103B45EC7CA08B4DD485C9740B8B451499F7F9894514EB048365140033F63BCE740B8B451C99F7F9
  6818. 89451CEB0389751C3BCE740B8B45FC99F7F98945FCEB038975FC3BCE740B8B45F899F7F98945F8EB038975F88975103975EC7E5585DB7E468B4DD88B450C
  6819. 0FAFCB034D108D50020FAF4D18034DDC8BF08BF803CA2BF22BFA2BC2895DC88A551488540E038A551C88118A55FC88540F018A55F888140183C104FF4DC8
  6820. 75DFFF45108B45103B45EC7CAB8BC3C1E0020145DCFF4DCC0F85CEFEFFFF8B4DEC33C08945F88945FC89451C8945148945103BC87E6C3945F07E5C8B4DD8
  6821. 8B75E80FAFCB034D100FAFF30FAF4D188B45088D500203CA8D0CB18BF08BF88945F48B45F02BF22BFA2955F48945C80FB6440E030145140FB60101451C0F
  6822. B6440F010145FC8B45F40FB604010145F883C104FF4DC875D833C0FF45108B4DEC394D107C940FAF4DF03BC874068B451499F7F933F68945143BCE740B8B
  6823. 451C99F7F989451CEB0389751C3BCE740B8B45FC99F7F98945FCEB038975FC3BCE740B8B45F899F7F98945F8EB038975F88975083975EC7E63EB0233F639
  6824. 75F07E4F8B4DD88B75E80FAFCB034D080FAFF30FAF4D188B450C8D500203CA8D0CB18BF08BF82BF22BFA2BC28B55F08955108A551488540E038A551C8811
  6825. 8A55FC88540F018A55F888140883C104FF4D1075DFFF45088B45083B45EC7C9F5F5E33C05BC9C21800
  6826. )"
  6827. else ; x64 machine code
  6828. MCode_PixelateBitmap := "
  6829. (LTrim Join
  6830. 4489442418488954241048894C24085355565741544155415641574883EC28418BC1448B8C24980000004C8BDA99488BD941F7F9448BD0448BFA8954240C
  6831. 448994248800000085C00F8E9D020000418BC04533E4458BF299448924244C8954241041F7F933C9898C24980000008BEA89542404448BE889442408EB05
  6832. 4C8B5C24784585ED0F8E1A010000458BF1418BFD48897C2418450FAFF14533D233F633ED4533E44533ED4585C97E5B4C63BC2490000000418D040A410FAF
  6833. C148984C8D441802498BD9498BD04D8BD90FB642010FB64AFF4403E80FB60203E90FB64AFE4883C2044403E003F149FFCB75DE4D03C748FFCB75D0488B7C
  6834. 24188B8C24980000004C8B5C2478418BC59941F7FE448BE8418BC49941F7FE448BE08BC59941F7FE8BE88BC69941F7FE8BF04585C97E4048639C24900000
  6835. 004103CA4D8BC1410FAFC94863C94A8D541902488BCA498BC144886901448821408869FF408871FE4883C10448FFC875E84803D349FFC875DA8B8C249800
  6836. 0000488B5C24704C8B5C24784183C20448FFCF48897C24180F850AFFFFFF8B6C2404448B2424448B6C24084C8B74241085ED0F840A01000033FF33DB4533
  6837. DB4533D24533C04585C97E53488B74247085ED7E42438D0C04418BC50FAF8C2490000000410FAFC18D04814863C8488D5431028BCD0FB642014403D00FB6
  6838. 024883C2044403D80FB642FB03D80FB642FA03F848FFC975DE41FFC0453BC17CB28BCD410FAFC985C9740A418BC299F7F98BF0EB0233F685C9740B418BC3
  6839. 99F7F9448BD8EB034533DB85C9740A8BC399F7F9448BD0EB034533D285C9740A8BC799F7F9448BC0EB034533C033D24585C97E4D4C8B74247885ED7E3841
  6840. 8D0C14418BC50FAF8C2490000000410FAFC18D04814863C84A8D4431028BCD40887001448818448850FF448840FE4883C00448FFC975E8FFC2413BD17CBD
  6841. 4C8B7424108B8C2498000000038C2490000000488B5C24704503E149FFCE44892424898C24980000004C897424100F859EFDFFFF448B7C240C448B842480
  6842. 000000418BC09941F7F98BE8448BEA89942498000000896C240C85C00F8E3B010000448BAC2488000000418BCF448BF5410FAFC9898C248000000033FF33
  6843. ED33F64533DB4533D24533C04585FF7E524585C97E40418BC5410FAFC14103C00FAF84249000000003C74898488D541802498BD90FB642014403D00FB602
  6844. 4883C2044403D80FB642FB03F00FB642FA03E848FFCB75DE488B5C247041FFC0453BC77CAE85C9740B418BC299F7F9448BE0EB034533E485C9740A418BC3
  6845. 99F7F98BD8EB0233DB85C9740A8BC699F7F9448BD8EB034533DB85C9740A8BC599F7F9448BD0EB034533D24533C04585FF7E4E488B4C24784585C97E3541
  6846. 8BC5410FAFC14103C00FAF84249000000003C74898488D540802498BC144886201881A44885AFF448852FE4883C20448FFC875E941FFC0453BC77CBE8B8C
  6847. 2480000000488B5C2470418BC1C1E00203F849FFCE0F85ECFEFFFF448BAC24980000008B6C240C448BA4248800000033FF33DB4533DB4533D24533C04585
  6848. FF7E5A488B7424704585ED7E48418BCC8BC5410FAFC94103C80FAF8C2490000000410FAFC18D04814863C8488D543102418BCD0FB642014403D00FB60248
  6849. 83C2044403D80FB642FB03D80FB642FA03F848FFC975DE41FFC0453BC77CAB418BCF410FAFCD85C9740A418BC299F7F98BF0EB0233F685C9740B418BC399
  6850. F7F9448BD8EB034533DB85C9740A8BC399F7F9448BD0EB034533D285C9740A8BC799F7F9448BC0EB034533C033D24585FF7E4E4585ED7E42418BCC8BC541
  6851. 0FAFC903CA0FAF8C2490000000410FAFC18D04814863C8488B442478488D440102418BCD40887001448818448850FF448840FE4883C00448FFC975E8FFC2
  6852. 413BD77CB233C04883C428415F415E415D415C5F5E5D5BC3
  6853. )"
  6854.  
  6855. VarSetCapacity(PixelateBitmap, StrLen(MCode_PixelateBitmap)//2, 0)
  6856. nCount := StrLen(MCode_PixelateBitmap)//2
  6857. N := (A_AhkVersion < 2) ? nCount : "nCount"
  6858. Loop %N%
  6859. NumPut("0x" SubStr(MCode_PixelateBitmap, (2*A_Index)-1, 2), PixelateBitmap, A_Index-1, "UChar")
  6860. DllCall("VirtualProtect", "UPtr", &PixelateBitmap, "UPtr", VarSetCapacity(PixelateBitmap), "uint", 0x40, "UPtr*", 0)
  6861. }
  6862.  
  6863. Gdip_GetImageDimensions(pBitmap, Width, Height)
  6864. if (Width != Gdip_GetImageWidth(pBitmapOut) || Height != Gdip_GetImageHeight(pBitmapOut))
  6865. return -1
  6866.  
  6867. if (BlockSize > Width || BlockSize > Height)
  6868. return -2
  6869.  
  6870. E1 := Gdip_LockBits(pBitmap, 0, 0, Width, Height, Stride1, Scan01, BitmapData1)
  6871. E2 := Gdip_LockBits(pBitmapOut, 0, 0, Width, Height, Stride2, Scan02, BitmapData2)
  6872. if (!E1 && !E2)
  6873. DllCall(&PixelateBitmap, "UPtr", Scan01, "UPtr", Scan02, "int", Width, "int", Height, "int", Stride1, "int", BlockSize)
  6874.  
  6875. If !E1
  6876. Gdip_UnlockBits(pBitmap, BitmapData1)
  6877. If !E2
  6878. Gdip_UnlockBits(pBitmapOut, BitmapData2)
  6879. return 0
  6880. }
  6881.  
  6882. ;#####################################################################################
  6883.  
  6884. Gdip_ToARGB(A, R, G, B) {
  6885. return (A << 24) | (R << 16) | (G << 8) | B
  6886. }
  6887.  
  6888. Gdip_FromARGB(ARGB, ByRef A, ByRef R, ByRef G, ByRef B) {
  6889. A := (0xff000000 & ARGB) >> 24
  6890. R := (0x00ff0000 & ARGB) >> 16
  6891. G := (0x0000ff00 & ARGB) >> 8
  6892. B := 0x000000ff & ARGB
  6893. }
  6894.  
  6895. Gdip_AFromARGB(ARGB) {
  6896. return (0xff000000 & ARGB) >> 24
  6897. }
  6898.  
  6899. Gdip_RFromARGB(ARGB) {
  6900. return (0x00ff0000 & ARGB) >> 16
  6901. }
  6902.  
  6903. Gdip_GFromARGB(ARGB) {
  6904. return (0x0000ff00 & ARGB) >> 8
  6905. }
  6906.  
  6907. Gdip_BFromARGB(ARGB) {
  6908. return 0x000000ff & ARGB
  6909. }
  6910.  
  6911. ;#####################################################################################
  6912.  
  6913. StrGetB(Address, Length:=-1, Encoding:=0) {
  6914. ; Flexible parameter handling:
  6915. if !IsInteger(Length)
  6916. Encoding := Length, Length := -1
  6917.  
  6918. ; Check for obvious errors.
  6919. if (Address+0 < 1024)
  6920. return
  6921.  
  6922. ; Ensure 'Encoding' contains a numeric identifier.
  6923. if (Encoding = "UTF-16")
  6924. Encoding := 1200
  6925. else if (Encoding = "UTF-8")
  6926. Encoding := 65001
  6927. else if SubStr(Encoding,1,2)="CP"
  6928. Encoding := SubStr(Encoding,3)
  6929.  
  6930. if !Encoding ; "" or 0
  6931. {
  6932. ; No conversion necessary, but we might not want the whole string.
  6933. if (Length == -1)
  6934. Length := DllCall("lstrlen", "uint", Address)
  6935. VarSetCapacity(String, Length, 0)
  6936. DllCall("lstrcpyn", "str", String, "uint", Address, "int", Length + 1)
  6937. }
  6938. else if (Encoding = 1200) ; UTF-16
  6939. {
  6940. char_count := DllCall("WideCharToMultiByte", "uint", 0, "uint", 0x400, "uint", Address, "int", Length, "uint", 0, "uint", 0, "uint", 0, "uint", 0)
  6941. VarSetCapacity(String, char_count, 0)
  6942. DllCall("WideCharToMultiByte", "uint", 0, "uint", 0x400, "uint", Address, "int", Length, "str", String, "int", char_count, "uint", 0, "uint", 0)
  6943. }
  6944. else if IsInteger(Encoding)
  6945. {
  6946. ; Convert from target encoding to UTF-16 then to the active code page.
  6947. char_count := DllCall("MultiByteToWideChar", "uint", Encoding, "uint", 0, "uint", Address, "int", Length, "uint", 0, "int", 0)
  6948. VarSetCapacity(String, char_count * 2, 0)
  6949. char_count := DllCall("MultiByteToWideChar", "uint", Encoding, "uint", 0, "uint", Address, "int", Length, "uint", &String, "int", char_count * 2)
  6950. String := StrGetB(&String, char_count, 1200)
  6951. }
  6952.  
  6953. return String
  6954. }
  6955.  
  6956. Gdip_Startup(multipleInstances:=0) {
  6957. pToken := 0
  6958. If (multipleInstances=0)
  6959. {
  6960. if !DllCall("GetModuleHandle", "str", "gdiplus", "UPtr")
  6961. DllCall("LoadLibrary", "str", "gdiplus")
  6962. } Else DllCall("LoadLibrary", "str", "gdiplus")
  6963.  
  6964. VarSetCapacity(si, A_PtrSize = 8 ? 24 : 16, 0), si := Chr(1)
  6965. DllCall("gdiplus\GdiplusStartup", "UPtr*", pToken, "UPtr", &si, "UPtr", 0)
  6966. return pToken
  6967. }
  6968.  
  6969. Gdip_Shutdown(pToken) {
  6970. DllCall("gdiplus\GdiplusShutdown", "UPtr", pToken)
  6971. hModule := DllCall("GetModuleHandle", "Str", "gdiplus", "UPtr")
  6972. if hModule
  6973. DllCall("FreeLibrary", "UPtr", hModule)
  6974. return 0
  6975. }
  6976.  
  6977. ;#####################################################################################
  6978. ; in AHK v1: uses normal 'if var is' command
  6979. ; in AHK v2: all if's are expression-if, so the Integer variable is dereferenced to the string
  6980. ;#####################################################################################
  6981. IsInteger(Var) {
  6982. Static Integer := "Integer"
  6983. If Var Is Integer
  6984. Return 1
  6985. Return 0
  6986. }
  6987.  
  6988. IsNumber(Var) {
  6989. Static number := "number"
  6990. If Var Is number
  6991. Return 1
  6992. Return 0
  6993. }
  6994.  
  6995. ; ======================================================================================================================
  6996. ; Multiple Display Monitors Functions -> msdn.microsoft.com/en-us/library/dd145072(v=vs.85).aspx
  6997. ; by 'just me'
  6998. ; https://autohotkey.com/boards/viewtopic.php?f=6&t=4606
  6999. ; ======================================================================================================================
  7000.  
  7001. GetMonitorCount() {
  7002. Monitors := MDMF_Enum()
  7003. countM := 0
  7004. for k,v in Monitors
  7005. countM++
  7006. return countM
  7007. }
  7008.  
  7009. GetMonitorInfo(MonitorNum) {
  7010. Monitors := MDMF_Enum()
  7011. for k,v in Monitors
  7012. {
  7013. if (v.Num = MonitorNum)
  7014. return v
  7015. }
  7016. }
  7017.  
  7018. GetPrimaryMonitor() {
  7019. Monitors := MDMF_Enum()
  7020. for k,v in Monitors
  7021. {
  7022. If (v.Primary)
  7023. return v.Num
  7024. }
  7025. }
  7026.  
  7027. ; ----------------------------------------------------------------------------------------------------------------------
  7028. ; Name ..........: MDMF - Multiple Display Monitor Functions
  7029. ; Description ...: Various functions for multiple display monitor environments
  7030. ; Tested with ...: AHK 1.1.32.00 (A32/U32/U64) and 2.0-a108-a2fa0498 (U32/U64)
  7031. ; Original Author: just me (https://www.autohotkey.com/boards/viewtopic.php?f=6&t=4606)
  7032. ; Mod Authors ...: iPhilip, guest3456
  7033. ; Changes .......: Modified to work with v2.0-a108 and changed 'Count' key to 'TotalCount' to avoid conflicts
  7034. ; ................ Modified MDMF_Enum() so that it works under both AHK v1 and v2.
  7035. ; ................ Modified MDMF_EnumProc() to provide Count and Primary keys to the Monitors array.
  7036. ; ................ Modified MDMF_FromHWND() to allow flag values that determine the function's return value if the
  7037. ; ................ window does not intersect any display monitor.
  7038. ; ................ Modified MDMF_FromPoint() to allow the cursor position to be returned ByRef if not specified and
  7039. ; ................ allow flag values that determine the function's return value if the point is not contained within
  7040. ; ................ any display monitor.
  7041. ; ................ Modified MDMF_FromRect() to allow flag values that determine the function's return value if the
  7042. ; ................ rectangle does not intersect any display monitor.
  7043. ;................. Modified MDMF_GetInfo() with minor changes.
  7044. ; ----------------------------------------------------------------------------------------------------------------------
  7045. ;
  7046. ; ======================================================================================================================
  7047. ; Multiple Display Monitors Functions -> msdn.microsoft.com/en-us/library/dd145072(v=vs.85).aspx =======================
  7048. ; ======================================================================================================================
  7049. ; Enumerates display monitors and returns an object containing the properties of all monitors or the specified monitor.
  7050. ; ======================================================================================================================
  7051.  
  7052. MDMF_Enum(HMON := "") {
  7053. Static CallbackFunc := Func(A_AhkVersion < "2" ? "RegisterCallback" : "CallbackCreate")
  7054. Static EnumProc := CallbackFunc.Call("MDMF_EnumProc")
  7055. Static Obj := (A_AhkVersion < "2") ? "Object" : "Map"
  7056. Static Monitors := {}
  7057. If (HMON = "") ; new enumeration
  7058. {
  7059. Monitors := %Obj%("TotalCount", 0)
  7060. If !DllCall("User32.dll\EnumDisplayMonitors", "Ptr", 0, "Ptr", 0, "Ptr", EnumProc, "Ptr", &Monitors, "Int")
  7061. Return False
  7062. }
  7063. Return (HMON = "") ? Monitors : Monitors.HasKey(HMON) ? Monitors[HMON] : False
  7064. }
  7065. ; ======================================================================================================================
  7066. ; Callback function that is called by the MDMF_Enum function.
  7067. ; ======================================================================================================================
  7068. MDMF_EnumProc(HMON, HDC, PRECT, ObjectAddr) {
  7069. Monitors := Object(ObjectAddr)
  7070. Monitors[HMON] := MDMF_GetInfo(HMON)
  7071. Monitors["TotalCount"]++
  7072. If (Monitors[HMON].Primary)
  7073. Monitors["Primary"] := HMON
  7074. Return True
  7075. }
  7076. ; ======================================================================================================================
  7077. ; Retrieves the display monitor that has the largest area of intersection with a specified window.
  7078. ; The following flag values determine the function's return value if the window does not intersect any display monitor:
  7079. ; MONITOR_DEFAULTTONULL = 0 - Returns NULL.
  7080. ; MONITOR_DEFAULTTOPRIMARY = 1 - Returns a handle to the primary display monitor.
  7081. ; MONITOR_DEFAULTTONEAREST = 2 - Returns a handle to the display monitor that is nearest to the window.
  7082. ; ======================================================================================================================
  7083. MDMF_FromHWND(HWND, Flag := 0) {
  7084. Return DllCall("User32.dll\MonitorFromWindow", "UPtr", HWND, "UInt", Flag, "Ptr")
  7085. }
  7086. ; ======================================================================================================================
  7087. ; Retrieves the display monitor that contains a specified point.
  7088. ; If either X or Y is empty, the function will use the current cursor position for this value and return it ByRef.
  7089. ; The following flag values determine the function's return value if the point is not contained within any
  7090. ; display monitor:
  7091. ; MONITOR_DEFAULTTONULL = 0 - Returns NULL.
  7092. ; MONITOR_DEFAULTTOPRIMARY = 1 - Returns a handle to the primary display monitor.
  7093. ; MONITOR_DEFAULTTONEAREST = 2 - Returns a handle to the display monitor that is nearest to the point.
  7094. ; ======================================================================================================================
  7095. MDMF_FromPoint(ByRef X := "", ByRef Y := "", Flag := 0) {
  7096. If (X = "") || (Y = "") {
  7097. VarSetCapacity(PT, 8, 0)
  7098. DllCall("User32.dll\GetCursorPos", "UPtr", &PT, "Int")
  7099. If (X = "")
  7100. X := NumGet(PT, 0, "Int")
  7101. If (Y = "")
  7102. Y := NumGet(PT, 4, "Int")
  7103. }
  7104. Return DllCall("User32.dll\MonitorFromPoint", "Int64", (X & 0xFFFFFFFF) | (Y << 32), "UInt", Flag, "Ptr")
  7105. }
  7106. ; ======================================================================================================================
  7107. ; Retrieves the display monitor that has the largest area of intersection with a specified rectangle.
  7108. ; Parameters are consistent with the common AHK definition of a rectangle, which is X, Y, W, H instead of
  7109. ; Left, Top, Right, Bottom.
  7110. ; The following flag values determine the function's return value if the rectangle does not intersect any
  7111. ; display monitor:
  7112. ; MONITOR_DEFAULTTONULL = 0 - Returns NULL.
  7113. ; MONITOR_DEFAULTTOPRIMARY = 1 - Returns a handle to the primary display monitor.
  7114. ; MONITOR_DEFAULTTONEAREST = 2 - Returns a handle to the display monitor that is nearest to the rectangle.
  7115. ; ======================================================================================================================
  7116. MDMF_FromRect(X, Y, W, H, Flag := 0) {
  7117. CreateRectF(RC, X, Y, X + W, Y + H, "int")
  7118. Return DllCall("User32.dll\MonitorFromRect", "UPtr", &RC, "UInt", Flag, "Ptr")
  7119. }
  7120. ; ======================================================================================================================
  7121. ; Retrieves information about a display monitor.
  7122. ; ======================================================================================================================
  7123. MDMF_GetInfo(HMON) {
  7124. NumPut(VarSetCapacity(MIEX, 40 + (32 << !!A_IsUnicode)), MIEX, 0, "UInt")
  7125. If DllCall("User32.dll\GetMonitorInfo", "UPtr", HMON, "Ptr", &MIEX, "Int")
  7126. Return {Name: (Name := StrGet(&MIEX + 40, 32)) ; CCHDEVICENAME = 32
  7127. , Num: RegExReplace(Name, ".*(\d+)$", "$1")
  7128. , Left: NumGet(MIEX, 4, "Int") ; display rectangle
  7129. , Top: NumGet(MIEX, 8, "Int") ; "
  7130. , Right: NumGet(MIEX, 12, "Int") ; "
  7131. , Bottom: NumGet(MIEX, 16, "Int") ; "
  7132. , WALeft: NumGet(MIEX, 20, "Int") ; work area
  7133. , WATop: NumGet(MIEX, 24, "Int") ; "
  7134. , WARight: NumGet(MIEX, 28, "Int") ; "
  7135. , WABottom: NumGet(MIEX, 32, "Int") ; "
  7136. , Primary: NumGet(MIEX, 36, "UInt")} ; contains a non-zero value for the primary monitor.
  7137. Return False
  7138. }
  7139.  
  7140. ;######################################################################################################################################
  7141. ; The following functions are written by Just Me
  7142. ; Taken from https://autohotkey.com/board/topic/85238-get-image-metadata-using-gdi-ahk-l/
  7143. ; October 2013; minimal modifications by Marius Șucan in July 2019
  7144.  
  7145. Gdip_LoadImageFromFile(sFile, useICM:=0) {
  7146. ; An Image object encapsulates a bitmap or a metafile and stores attributes that you can retrieve.
  7147. pImage := 0
  7148. function2call := (useICM=1) ? "ICM" : ""
  7149. gdipLastError := DllCall("gdiplus\GdipLoadImageFromFile" function2call, "WStr", sFile, "UPtr*", pImage)
  7150. Return pImage
  7151. }
  7152.  
  7153. Gdip_LoadImageFromStream(stream, useICM:=0) {
  7154. pImage := 0
  7155. function2call := (useICM=1) ? "ICM" : ""
  7156. gdipLastError := DllCall("gdiplus\GdipLoadImageFromStream" function2call, "UPtr", stream, "UPtr*", pImage)
  7157. Return pImage
  7158. }
  7159.  
  7160. ;######################################################################################################################################
  7161. ; Gdip_GetPropertyCount() - Gets the number of properties (pieces of metadata) stored in this Image object.
  7162. ; Parameters:
  7163. ; pImage - Pointer to the Image object.
  7164. ; Return values:
  7165. ; On success - Number of properties.
  7166. ; On failure - 0, ErrorLevel contains the GDIP status
  7167. ;######################################################################################################################################
  7168.  
  7169. Gdip_GetPropertyCount(pImage) {
  7170. PropCount := 0
  7171. gdipLastError := DllCall("gdiplus\GdipGetPropertyCount", "UPtr", pImage, "UIntP", PropCount)
  7172. Return PropCount
  7173. }
  7174.  
  7175. ;######################################################################################################################################
  7176. ; Gdip_GetPropertyIdList() - Gets an aray of the property identifiers used in the metadata of this Image object.
  7177. ; Parameters:
  7178. ; pImage - Pointer to the Image object.
  7179. ; Return values:
  7180. ; On success - Array containing the property identifiers as integer keys and the name retrieved from
  7181. ; Gdip_GetPropertyTagName(PropID) as values.
  7182. ; The total number of properties is stored in Array.Count.
  7183. ; On failure - False, ErrorLevel contains the GDIP status
  7184. ;######################################################################################################################################
  7185.  
  7186. Gdip_GetPropertyIdList(pImage) {
  7187. PropNum := Gdip_GetPropertyCount(pImage)
  7188. If !PropNum
  7189. Return False
  7190.  
  7191. VarSetCapacity(PropIDList, 4 * PropNum, 0)
  7192. R := DllCall("gdiplus\GdipGetPropertyIdList", "UPtr", pImage, "UInt", PropNum, "UPtr", &PropIDList)
  7193. If (R) {
  7194. ErrorLevel := R
  7195. Return False
  7196. }
  7197.  
  7198. PropArray := {Count: PropNum}
  7199. Loop %PropNum%
  7200. {
  7201. PropID := NumGet(PropIDList, (A_Index - 1) << 2, "UInt")
  7202. PropArray[PropID] := Gdip_GetPropertyTagName(PropID)
  7203. }
  7204. Return PropArray
  7205. }
  7206.  
  7207. ;######################################################################################################################################
  7208. ; Gdip_GetPropertyItem() - Gets a specified property item (piece of metadata) from this Image object.
  7209. ; Parameters:
  7210. ; pImage - Pointer to the Image object.
  7211. ; PropID - Integer that identifies the property item to be retrieved (see Gdip_GetPropertyTagName()).
  7212. ; Return values:
  7213. ; On success - Property item object containing three keys:
  7214. ; Length - Length of the value in bytes.
  7215. ; Type - Type of the value (see Gdip_GetPropertyTagType()).
  7216. ; Value - The value itself.
  7217. ; On failure - False, ErrorLevel contains the GDIP status
  7218. ;######################################################################################################################################
  7219.  
  7220. Gdip_GetPropertyItem(pImage, PropID) {
  7221. PropItem := {Length: 0, Type: 0, Value: ""}
  7222. ItemSize := 0
  7223. R := DllCall("gdiplus\GdipGetPropertyItemSize", "UPtr", pImage, "UInt", PropID, "UIntP", ItemSize)
  7224. If (R) {
  7225. ErrorLevel := R
  7226. Return False
  7227. }
  7228.  
  7229. VarSetCapacity(Item, ItemSize, 0)
  7230. R := DllCall("gdiplus\GdipGetPropertyItem", "UPtr", pImage, "UInt", PropID, "UInt", ItemSize, "UPtr", &Item)
  7231. If (R) {
  7232. ErrorLevel := R
  7233. Return False
  7234. }
  7235. PropLen := NumGet(Item, 4, "UInt")
  7236. PropType := NumGet(Item, 8, "Short")
  7237. PropAddr := NumGet(Item, 8 + A_PtrSize, "UPtr")
  7238. PropItem.Length := PropLen
  7239. PropItem.Type := PropType
  7240. If (PropLen > 0)
  7241. {
  7242. PropVal := ""
  7243. Gdip_GetPropertyItemValue(PropVal, PropLen, PropType, PropAddr)
  7244. If (PropType = 1) || (PropType = 7) {
  7245. PropItem.SetCapacity("Value", PropLen)
  7246. ValAddr := PropItem.GetAddress("Value")
  7247. DllCall("Kernel32.dll\RtlMoveMemory", "UPtr", ValAddr, "UPtr", &PropVal, "Ptr", PropLen)
  7248. } Else {
  7249. PropItem.Value := PropVal
  7250. }
  7251. }
  7252. ErrorLevel := 0
  7253. Return PropItem
  7254. }
  7255.  
  7256. ;######################################################################################################################################
  7257. ; Gdip_GetAllPropertyItems() - Gets all the property items (metadata) stored in this Image object.
  7258. ; Parameters:
  7259. ; pImage - Pointer to the Image object.
  7260. ; Return values:
  7261. ; On success - Properties object containing one integer key for each property ID. Each value is an object
  7262. ; containing three keys:
  7263. ; Length - Length of the value in bytes.
  7264. ; Type - Type of the value (see Gdip_GetPropertyTagType()).
  7265. ; Value - The value itself.
  7266. ; The total number of properties is stored in Properties.Count.
  7267. ; On failure - False, ErrorLevel contains the GDIP status
  7268. ;######################################################################################################################################
  7269.  
  7270. Gdip_GetAllPropertyItems(pImage) {
  7271. BufSize := PropNum := ErrorLevel := 0
  7272. R := DllCall("gdiplus\GdipGetPropertySize", "UPtr", pImage, "UIntP", BufSize, "UIntP", PropNum)
  7273. If (R) || (PropNum = 0) {
  7274. ErrorLevel := R ? R : 19 ; 19 = PropertyNotFound
  7275. Return False
  7276. }
  7277.  
  7278. VarSetCapacity(Buffer, BufSize, 0)
  7279. R := DllCall("gdiplus\GdipGetAllPropertyItems", "UPtr", pImage, "UInt", BufSize, "UInt", PropNum, "UPtr", &Buffer)
  7280. If (R) {
  7281. ErrorLevel := R
  7282. Return False
  7283. }
  7284. PropsObj := {Count: PropNum}
  7285. PropSize := 8 + (2 * A_PtrSize)
  7286.  
  7287. Loop %PropNum%
  7288. {
  7289. OffSet := PropSize * (A_Index - 1)
  7290. PropID := NumGet(Buffer, OffSet, "UInt")
  7291. PropLen := NumGet(Buffer, OffSet + 4, "UInt")
  7292. PropType := NumGet(Buffer, OffSet + 8, "Short")
  7293. PropAddr := NumGet(Buffer, OffSet + 8 + A_PtrSize, "UPtr")
  7294. PropVal := ""
  7295. PropsObj[PropID] := {}
  7296. PropsObj[PropID, "Length"] := PropLen
  7297. PropsObj[PropID, "Type"] := PropType
  7298. PropsObj[PropID, "Value"] := PropVal
  7299. If (PropLen > 0)
  7300. {
  7301. Gdip_GetPropertyItemValue(PropVal, PropLen, PropType, PropAddr)
  7302. If (PropType = 1) || (PropType = 7)
  7303. {
  7304. PropsObj[PropID].SetCapacity("Value", PropLen)
  7305. ValAddr := PropsObj[PropID].GetAddress("Value")
  7306. DllCall("Kernel32.dll\RtlMoveMemory", "UPtr", ValAddr, "UPtr", PropAddr, "UPtr", PropLen)
  7307. } Else {
  7308. PropsObj[PropID].Value := PropVal
  7309. }
  7310. }
  7311. }
  7312. ErrorLevel := 0
  7313. Return PropsObj
  7314. }
  7315.  
  7316. ;######################################################################################################################################
  7317. ; Gdip_GetPropertyTagName() - Gets the name for the integer identifier of this property as defined in "Gdiplusimaging.h".
  7318. ; Parameters:
  7319. ; PropID - Integer that identifies the property item to be retrieved.
  7320. ; Return values:
  7321. ; On success - Corresponding name.
  7322. ; On failure - "Unknown"
  7323. ;######################################################################################################################################
  7324.  
  7325. Gdip_GetPropertyTagName(PropID) {
  7326. ; All tags are taken from "Gdiplusimaging.h", probably there will be more.
  7327. ; For most of them you'll find a description on http://msdn.microsoft.com/en-us/library/ms534418(VS.85).aspx
  7328. ;
  7329. ; modified by Marius Șucan in July/August 2019:
  7330. ; I transformed the function to not yield errors on AHK v2 alpha
  7331.  
  7332. Static PropTagsA := {0x0001:"GPS LatitudeRef",0x0002:"GPS Latitude",0x0003:"GPS LongitudeRef",0x0004:"GPS Longitude",0x0005:"GPS AltitudeRef",0x0006:"GPS Altitude",0x0007:"GPS Time",0x0008:"GPS Satellites",0x0009:"GPS Status",0x000A:"GPS MeasureMode",0x001D:"GPS Date",0x001E:"GPS Differential",0x00FE:"NewSubfileType",0x00FF:"SubfileType",0x0102:"Bits Per Sample",0x0103:"Compression",0x0106:"Photometric Interpolation",0x0107:"ThreshHolding",0x010A:"Fill Order",0x010D:"Document Name",0x010E:"Image Description",0x010F:"Equipment Make",0x0110:"Equipment Model",0x0112:"Orientation",0x0115:"Samples Per Pixel",0x0118:"Min Sample Value",0x0119:"Max Sample Value",0x011D:"Page Name",0x0122:"GrayResponseUnit",0x0123:"GrayResponseCurve",0x0128:"Resolution Unit",0x012D:"Transfer Function",0x0131:"Software Used",0x0132:"Internal Date Time",0x013B:"Artist"
  7333. ,0x013C:"Host Computer",0x013D:"Predictor",0x013E:"White Point",0x013F:"Primary Chromaticities",0x0140:"Color Map",0x014C:"Ink Set",0x014D:"Ink Names",0x014E:"Number Of Inks",0x0150:"Dot Range",0x0151:"Target Printer",0x0152:"Extra Samples",0x0153:"Sample Format",0x0156:"Transfer Range",0x0200:"JPEGProc",0x0205:"JPEGLosslessPredictors",0x0301:"Gamma",0x0302:"ICC Profile Descriptor",0x0303:"SRGB Rendering Intent",0x0320:"Image Title",0x5010:"JPEG Quality",0x5011:"Grid Size",0x501A:"Color Transfer Function",0x5100:"Frame Delay",0x5101:"Loop Count",0x5110:"Pixel Unit",0x5111:"Pixel Per Unit X",0x5112:"Pixel Per Unit Y",0x8298:"Copyright",0x829A:"EXIF Exposure Time",0x829D:"EXIF F Number",0x8773:"ICC Profile",0x8822:"EXIF ExposureProg",0x8824:"EXIF SpectralSense",0x8827:"EXIF ISO Speed",0x9003:"EXIF Date Original",0x9004:"EXIF Date Digitized"
  7334. ,0x9102:"EXIF CompBPP",0x9201:"EXIF Shutter Speed",0x9202:"EXIF Aperture",0x9203:"EXIF Brightness",0x9204:"EXIF Exposure Bias",0x9205:"EXIF Max. Aperture",0x9206:"EXIF Subject Dist",0x9207:"EXIF Metering Mode",0x9208:"EXIF Light Source",0x9209:"EXIF Flash",0x920A:"EXIF Focal Length",0x9214:"EXIF Subject Area",0x927C:"EXIF Maker Note",0x9286:"EXIF Comments",0xA001:"EXIF Color Space",0xA002:"EXIF PixXDim",0xA003:"EXIF PixYDim",0xA004:"EXIF Related WAV",0xA005:"EXIF Interop",0xA20B:"EXIF Flash Energy",0xA20E:"EXIF Focal X Res",0xA20F:"EXIF Focal Y Res",0xA210:"EXIF FocalResUnit",0xA214:"EXIF Subject Loc",0xA215:"EXIF Exposure Index",0xA217:"EXIF Sensing Method",0xA300:"EXIF File Source",0xA301:"EXIF Scene Type",0xA401:"EXIF Custom Rendered",0xA402:"EXIF Exposure Mode",0xA403:"EXIF White Balance",0xA404:"EXIF Digital Zoom Ratio"
  7335. ,0xA405:"EXIF Focal Length In 35mm Film",0xA406:"EXIF Scene Capture Type",0xA407:"EXIF Gain Control",0xA408:"EXIF Contrast",0xA409:"EXIF Saturation",0xA40A:"EXIF Sharpness",0xA40B:"EXIF Device Setting Description",0xA40C:"EXIF Subject Distance Range",0xA420:"EXIF Unique Image ID"}
  7336.  
  7337. Static PropTagsB := {0x0000:"GpsVer",0x000B:"GpsGpsDop",0x000C:"GpsSpeedRef",0x000D:"GpsSpeed",0x000E:"GpsTrackRef",0x000F:"GpsTrack",0x0010:"GpsImgDirRef",0x0011:"GpsImgDir",0x0012:"GpsMapDatum",0x0013:"GpsDestLatRef",0x0014:"GpsDestLat",0x0015:"GpsDestLongRef",0x0016:"GpsDestLong",0x0017:"GpsDestBearRef",0x0018:"GpsDestBear",0x0019:"GpsDestDistRef",0x001A:"GpsDestDist",0x001B:"GpsProcessingMethod",0x001C:"GpsAreaInformation",0x0100:"Original Image Width",0x0101:"Original Image Height",0x0108:"CellWidth",0x0109:"CellHeight",0x0111:"Strip Offsets",0x0116:"RowsPerStrip",0x0117:"StripBytesCount",0x011A:"XResolution",0x011B:"YResolution",0x011C:"Planar Config",0x011E:"XPosition",0x011F:"YPosition",0x0120:"FreeOffset",0x0121:"FreeByteCounts",0x0124:"T4Option",0x0125:"T6Option",0x0129:"PageNumber",0x0141:"Halftone Hints",0x0142:"TileWidth",0x0143:"TileLength",0x0144:"TileOffset"
  7338. ,0x0145:"TileByteCounts",0x0154:"SMin Sample Value",0x0155:"SMax Sample Value",0x0201:"JPEGInterFormat",0x0202:"JPEGInterLength",0x0203:"JPEGRestartInterval",0x0206:"JPEGPointTransforms",0x0207:"JPEGQTables",0x0208:"JPEGDCTables",0x0209:"JPEGACTables",0x0211:"YCbCrCoefficients",0x0212:"YCbCrSubsampling",0x0213:"YCbCrPositioning",0x0214:"REFBlackWhite",0x5001:"ResolutionXUnit",0x5002:"ResolutionYUnit",0x5003:"ResolutionXLengthUnit",0x5004:"ResolutionYLengthUnit",0x5005:"PrintFlags",0x5006:"PrintFlagsVersion",0x5007:"PrintFlagsCrop",0x5008:"PrintFlagsBleedWidth",0x5009:"PrintFlagsBleedWidthScale",0x500A:"HalftoneLPI",0x500B:"HalftoneLPIUnit",0x500C:"HalftoneDegree",0x500D:"HalftoneShape",0x500E:"HalftoneMisc",0x500F:"HalftoneScreen",0x5012:"ThumbnailFormat",0x5013:"ThumbnailWidth",0x5014:"ThumbnailHeight",0x5015:"ThumbnailColorDepth"
  7339. ,0x5016:"ThumbnailPlanes",0x5017:"ThumbnailRawBytes",0x5018:"ThumbnailSize",0x5019:"ThumbnailCompressedSize",0x501B:"ThumbnailData",0x5020:"ThumbnailImageWidth",0x5021:"ThumbnailImageHeight",0x5022:"ThumbnailBitsPerSample",0x5023:"ThumbnailCompression",0x5024:"ThumbnailPhotometricInterp",0x5025:"ThumbnailImageDescription",0x5026:"ThumbnailEquipMake",0x5027:"ThumbnailEquipModel",0x5028:"ThumbnailStripOffsets",0x5029:"ThumbnailOrientation",0x502A:"ThumbnailSamplesPerPixel",0x502B:"ThumbnailRowsPerStrip",0x502C:"ThumbnailStripBytesCount",0x502D:"ThumbnailResolutionX",0x502E:"ThumbnailResolutionY",0x502F:"ThumbnailPlanarConfig",0x5030:"ThumbnailResolutionUnit",0x5031:"ThumbnailTransferFunction",0x5032:"ThumbnailSoftwareUsed",0x5033:"ThumbnailDateTime",0x5034:"ThumbnailArtist",0x5035:"ThumbnailWhitePoint"
  7340. ,0x5036:"ThumbnailPrimaryChromaticities",0x5037:"ThumbnailYCbCrCoefficients",0x5038:"ThumbnailYCbCrSubsampling",0x5039:"ThumbnailYCbCrPositioning",0x503A:"ThumbnailRefBlackWhite",0x503B:"ThumbnailCopyRight",0x5090:"LuminanceTable",0x5091:"ChrominanceTable",0x5102:"Global Palette",0x5103:"Index Background",0x5104:"Index Transparent",0x5113:"Palette Histogram",0x8769:"ExifIFD",0x8825:"GpsIFD",0x8828:"ExifOECF",0x9000:"ExifVer",0x9101:"EXIF CompConfig",0x9290:"EXIF DTSubsec",0x9291:"EXIF DTOrigSS",0x9292:"EXIF DTDigSS",0xA000:"EXIF FPXVer",0xA20C:"EXIF Spatial FR",0xA302:"EXIF CfaPattern"}
  7341.  
  7342. r := PropTagsA.HasKey(PropID) ? PropTagsA[PropID] : "Unknown"
  7343. If (r="Unknown")
  7344. r := PropTagsB.HasKey(PropID) ? PropTagsB[PropID] : "Unknown"
  7345. Return r
  7346. }
  7347.  
  7348. ;######################################################################################################################################
  7349. ; Gdip_GetPropertyTagType() - Gets the name for the type of this property's value as defined in "Gdiplusimaging.h".
  7350. ; Parameters:
  7351. ; PropType - Integer that identifies the type of the property item to be retrieved.
  7352. ; Return values:
  7353. ; On success - Corresponding type.
  7354. ; On failure - "Unknown"
  7355. ;######################################################################################################################################
  7356.  
  7357. Gdip_GetPropertyTagType(PropType) {
  7358. Static PropTypes := {1: "Byte", 2: "ASCII", 3: "Short", 4: "Long", 5: "Rational", 7: "Undefined", 9: "SLong", 10: "SRational"}
  7359. Return PropTypes.HasKey(PropType) ? PropTypes[PropType] : "Unknown"
  7360. }
  7361.  
  7362. Gdip_GetPropertyItemValue(ByRef PropVal, PropLen, PropType, PropAddr) {
  7363. ; Gdip_GetPropertyItemValue() - Reserved for internal use
  7364. PropVal := ""
  7365. If (PropType=2)
  7366. {
  7367. PropVal := StrGet(PropAddr, PropLen, "CP0")
  7368. Return True
  7369. }
  7370.  
  7371. If (PropType=3)
  7372. {
  7373. PropyLen := PropLen // 2
  7374. Loop %PropyLen%
  7375. PropVal .= (A_Index > 1 ? " " : "") . NumGet(PropAddr + 0, (A_Index - 1) << 1, "Short")
  7376. Return True
  7377. }
  7378.  
  7379. If (PropType=4 || PropType=9)
  7380. {
  7381. NumType := PropType = 4 ? "UInt" : "Int"
  7382. PropyLen := PropLen // 4
  7383. Loop %PropyLen%
  7384. PropVal .= (A_Index > 1 ? " " : "") . NumGet(PropAddr + 0, (A_Index - 1) << 2, NumType)
  7385. Return True
  7386. }
  7387.  
  7388. If (PropType=5 || PropType=10)
  7389. {
  7390. NumType := PropType = 5 ? "UInt" : "Int"
  7391. PropyLen := PropLen // 8
  7392. Loop %PropyLen%
  7393. PropVal .= (A_Index > 1 ? " " : "") . NumGet(PropAddr + 0, (A_Index - 1) << 2, NumType)
  7394. . "/" . NumGet(PropAddr + 4, (A_Index - 1) << 2, NumType)
  7395. Return True
  7396. }
  7397.  
  7398. If (PropType=1 || PropType=7)
  7399. {
  7400. VarSetCapacity(PropVal, PropLen, 0)
  7401. DllCall("Kernel32.dll\RtlMoveMemory", "UPtr", &PropVal, "UPtr", PropAddr, "UPtr", PropLen)
  7402. Return True
  7403. }
  7404. Return False
  7405. }
  7406.  
  7407. ;#####################################################################################
  7408. ; RotateAtCenter() and related Functions by RazorHalo
  7409. ; from https://www.autohotkey.com/boards/viewtopic.php?f=6&t=6517&start=260
  7410. ; in April 2019.
  7411. ;#####################################################################################
  7412. ; The Matrix order has to be "Append" for the transformations to be applied
  7413. ; in the correct order - instead of the default "Prepend"
  7414.  
  7415. Gdip_RotatePathAtCenter(pPath, Angle, MatrixOrder:=1, withinBounds:=0, withinBkeepRatio:=1, highAccuracy:=0) {
  7416. ; modified by Marius Șucan - added withinBounds option
  7417. ; and highAccuracy option; this option works only with closed paths
  7418.  
  7419. ; Gets the bounding rectangle of the GraphicsPath
  7420. ; returns array x, y, w, h
  7421. If (highAccuracy=1)
  7422. {
  7423. thisBMP := Gdip_CreateBitmap(10, 10)
  7424. dummyG := Gdip_GraphicsFromImage(thisBMP)
  7425. Gdip_SetClipPath(dummyG, pPath)
  7426. Rect := Gdip_GetClipBounds(dummyG)
  7427. }
  7428.  
  7429. If (!Rect.w || !Rect.h || highAccuracy!=1)
  7430. Rect := Gdip_GetPathWorldBounds(pPath)
  7431.  
  7432. ; Calculate center of bounding rectangle which will be the center of the graphics path
  7433. cX := Rect.x + (Rect.w / 2)
  7434. cY := Rect.y + (Rect.h / 2)
  7435.  
  7436. ; Create a Matrix for the transformations
  7437. pMatrix := Gdip_CreateMatrix()
  7438.  
  7439. ; Move the GraphicsPath center to the origin (0, 0) of the graphics object
  7440. Gdip_TranslateMatrix(pMatrix, -cX , -cY)
  7441.  
  7442. ; Rotate matrix on graphics object origin
  7443. Gdip_RotateMatrix(pMatrix, Angle, MatrixOrder)
  7444.  
  7445. ; Move the GraphicsPath origin point back to its original position
  7446. Gdip_TranslateMatrix(pMatrix, cX, cY, MatrixOrder)
  7447.  
  7448. ; Apply the transformations
  7449. E := Gdip_TransformPath(pPath, pMatrix)
  7450.  
  7451. ; Delete Matrix
  7452. Gdip_DeleteMatrix(pMatrix)
  7453.  
  7454. If (withinBounds=1 && !E && Angle!=0)
  7455. {
  7456. If (highAccuracy=1)
  7457. {
  7458. Gdip_ResetClip(dummyG)
  7459. Gdip_SetClipPath(dummyG, pPath)
  7460. nRect := Gdip_GetClipBounds(dummyG)
  7461. }
  7462.  
  7463. If (!nRect.w || !nRect.h || highAccuracy!=1)
  7464. nRect := Gdip_GetPathWorldBounds(pPath)
  7465.  
  7466. ncX := nRect.x + (nRect.w / 2)
  7467. ncY := nRect.y + (nRect.h / 2)
  7468. pMatrix := Gdip_CreateMatrix()
  7469. Gdip_TranslateMatrix(pMatrix, -ncX , -ncY)
  7470. sX := Rect.w / nRect.w
  7471. sY := Rect.h / nRect.h
  7472. If (withinBkeepRatio=1)
  7473. {
  7474. sX := min(sX, sY)
  7475. sY := min(sX, sY)
  7476. }
  7477. Gdip_ScaleMatrix(pMatrix, sX, sY, MatrixOrder)
  7478. Gdip_TranslateMatrix(pMatrix, ncX, ncY, MatrixOrder)
  7479. If (sX!=0 && sY!=0)
  7480. E := Gdip_TransformPath(pPath, pMatrix)
  7481. Gdip_DeleteMatrix(pMatrix)
  7482. }
  7483.  
  7484. If (highAccuracy=1)
  7485. {
  7486. Gdip_DeleteGraphics(dummyG)
  7487. Gdip_DisposeImage(thisBMP)
  7488. }
  7489.  
  7490. Return E
  7491. }
  7492.  
  7493. Gdip_ScalePathAtCenter(pPath, ScaleX, ScaleY) {
  7494. ; Calculate center of bounding rectangle which will be the center of the graphics path
  7495. Rect := Gdip_GetPathWorldBounds(pPath)
  7496. cX := Rect.x + (Rect.w / 2)
  7497. cY := Rect.y + (Rect.h / 2)
  7498.  
  7499. ; Create a Matrix for the transformations
  7500. pMatrix := Gdip_CreateMatrix()
  7501. Gdip_TranslateMatrix(pMatrix, cX , cY)
  7502. Gdip_ScaleMatrix(pMatrix, ScaleX, ScaleY)
  7503. Gdip_TranslateMatrix(pMatrix, -cX, -cY)
  7504.  
  7505. ; Apply the transformations
  7506. E := Gdip_TransformPath(pPath, pMatrix)
  7507. Gdip_DeleteMatrix(pMatrix)
  7508. Return E
  7509. }
  7510.  
  7511. ;#####################################################################################
  7512. ; Matrix transformations functions by RazorHalo
  7513. ;
  7514. ; NOTE: Be aware of the order that transformations are applied. You may need
  7515. ; to pass MatrixOrder as 1 for "Append"
  7516. ; the (default is 0 for "Prepend") to get the correct results.
  7517.  
  7518. Gdip_ResetMatrix(hMatrix) {
  7519. return DllCall("gdiplus\GdipResetMatrix", "UPtr", hMatrix)
  7520. }
  7521.  
  7522. Gdip_RotateMatrix(hMatrix, Angle, MatrixOrder:=0) {
  7523. return DllCall("gdiplus\GdipRotateMatrix", "UPtr", hMatrix, "float", Angle, "Int", MatrixOrder)
  7524. }
  7525.  
  7526. Gdip_GetPathWorldBounds(pPath, hMatrix:=0, pPen:=0) {
  7527. ; hMatrix to use for calculating the boundaries
  7528. ; pPen to use for calculating the boundaries
  7529. ; Both will not affect the actual GraphicsPath.
  7530. ; Please note: this function yields inaccurate bounds even for mildly complex paths.
  7531. ; Proposed solution:
  7532. ; Set the path you want measured as a clip for a given pGraphics and use Gdip_GetClipBounds() for accurate results.
  7533.  
  7534. VarSetCapacity(RectF, 16, 0)
  7535. E := DllCall("gdiplus\GdipGetPathWorldBounds", "UPtr", pPath, "UPtr", &RectF, "UPtr", hMatrix, "UPtr", pPen)
  7536. If !E
  7537. Return RetrieveRectF(RectF)
  7538. Else
  7539. Return E
  7540. }
  7541.  
  7542. Gdip_ShearMatrix(hMatrix, hx, hy, MatrixOrder:=0) {
  7543. ; it updates given hMatrix with the product of itself and a shearing matrix.
  7544. return DllCall("gdiplus\GdipShearMatrix", "UPtr", hMatrix, "Float", hx, "Float", hy, "UInt", MatrixOrder)
  7545. }
  7546.  
  7547. Gdip_ScaleMatrix(hMatrix, ScaleX, ScaleY, MatrixOrder:=0) {
  7548. return DllCall("gdiplus\GdipScaleMatrix", "UPtr", hMatrix, "float", ScaleX, "float", ScaleY, "Int", MatrixOrder)
  7549. }
  7550.  
  7551. Gdip_TranslateMatrix(hMatrix, offsetX, offsetY, MatrixOrder:=0) {
  7552. return DllCall("gdiplus\GdipTranslateMatrix", "UPtr", hMatrix, "float", offsetX, "float", offsetY, "Int", MatrixOrder)
  7553. }
  7554.  
  7555. Gdip_TransformPath(pPath, hMatrix) {
  7556. return DllCall("gdiplus\GdipTransformPath", "UPtr", pPath, "UPtr", hMatrix)
  7557. }
  7558.  
  7559. Gdip_TranslatePath(pPath, x, y) {
  7560. pMatrix := Gdip_CreateMatrix()
  7561. If !pMatrix
  7562. Return 1
  7563.  
  7564. Gdip_TranslateMatrix(pMatrix, x, y)
  7565. E := Gdip_TransformPath(pPath, pMatrix)
  7566. Gdip_DeleteMatrix(pMatrix)
  7567. Return E
  7568. }
  7569.  
  7570. Gdip_ScalePath(pPath, x, y) {
  7571. pMatrix := Gdip_CreateMatrix()
  7572. If !pMatrix
  7573. Return 1
  7574.  
  7575. Gdip_ScaleMatrix(pMatrix, x, y)
  7576. E := Gdip_TransformPath(pPath, pMatrix)
  7577. Gdip_DeleteMatrix(pMatrix)
  7578. Return E
  7579. }
  7580.  
  7581. Gdip_RotatePath(pPath, angle) {
  7582. If !angle
  7583. Return
  7584.  
  7585. pMatrix := Gdip_CreateMatrix()
  7586. If !pMatrix
  7587. Return 1
  7588.  
  7589. Gdip_RotateMatrix(pMatrix, angle)
  7590. E := Gdip_TransformPath(pPath, pMatrix)
  7591. Gdip_DeleteMatrix(pMatrix)
  7592. Return E
  7593. }
  7594.  
  7595. Gdip_SetMatrixElements(hMatrix, m11, m12, m21, m22, dx, dy) {
  7596. ; Parameters:
  7597. ; hMatrix = pointer to a transformation matrix object
  7598.  
  7599. ; m11 = first column, first line [scale factor on X axis]
  7600. ; m12 = second column, first line [rotation factor on X axis]
  7601.  
  7602. ; m21 = first column, second line [rotation factor on Y axis]
  7603. ; m22 = second column, second line [scale factor on Y axis]
  7604.  
  7605. ; dx = first column, third line [translation factor on X axis]
  7606. ; dy = second column, third line [translation factor on Y axis]
  7607.  
  7608. ; Matrix visualization:
  7609. ; [ m11 = Sx, m12 = Rx, ]
  7610. ; [ m21 = Ry, m22 = Sy, ]
  7611. ; [ dx = Tx, dy = Tx; ]
  7612.  
  7613. ; Please note. There is a trigonometric relationship between the scale factors (m11, m22) and
  7614. ; the rotation factors [m12, m21].
  7615.  
  7616. return DllCall("gdiplus\GdipSetMatrixElements", "UPtr", hMatrix, "float", m11, "float", m12, "float", m21, "float", m22, "float", dx, "float", dy)
  7617. }
  7618.  
  7619. Gdip_GetMatrixElements(hMatrix) {
  7620. ; function by MCL, modified by Marius Șucan
  7621. ; it returns an array of the Transformation Matrix elements
  7622.  
  7623. VarSetCapacity(binMxElems := "", 6*4, 0)
  7624. gdipLastError := DllCall("gdiplus\GdipGetMatrixElements", "UPtr", hMatrix, "UPtr", &binMxElems)
  7625. elemArray := []
  7626. Loop 6
  7627. elemArray[A_Index] := NumGet(binMxElems, (A_Index-1)*4, "Float")
  7628.  
  7629. Return elemArray
  7630. }
  7631.  
  7632. Gdip_GetMatrixLastStatus(hMatrix) {
  7633. ; function nowhere found as documented;
  7634. return DllCall("gdiplus\GdipGetLastStatus", "UPtr", hMatrix)
  7635. }
  7636.  
  7637. ;#####################################################################################
  7638. ; GraphicsPath functions written by Learning one
  7639. ; found on https://autohotkey.com/board/topic/29449-gdi-standard-library-145-by-tic/page-75
  7640. ; Updated on 14/08/2019 by Marius Șucan
  7641. ;#####################################################################################
  7642. ;
  7643. ; Function: Gdip_AddPathBeziers
  7644. ; Description: Adds a sequence of connected Bézier splines to the current figure of this path.
  7645. ; A Bezier spline does not pass through its control points. The control points act as magnets, pulling the curve
  7646. ; in certain directions to influence the way the spline bends.
  7647. ;
  7648. ; pPath: Pointer to the GraphicsPath.
  7649. ; Points: The coordinates of all the points passed as x1,y1|x2,y2|x3,y3... This can also be a flat array object
  7650.  
  7651. ; Return: Status enumeration. 0 = success.
  7652. ; Notes: The first spline is constructed from the first point through the fourth point in the array and
  7653. ; uses the second and third points as control points. Each subsequent spline in the sequence needs
  7654. ; exactly three more points: the ending point of the previous spline is used as the starting point,
  7655. ; the next two points in the sequence are control points, and the third point is the ending point.
  7656.  
  7657. Gdip_AddPathBeziers(pPath, Points) {
  7658. iCount := CreatePointsF(PointsF, Points)
  7659. return DllCall("gdiplus\GdipAddPathBeziers", "UPtr", pPath, "UPtr", &PointsF, "int", iCount)
  7660. }
  7661.  
  7662. Gdip_AddPathBezier(pPath, x1, y1, x2, y2, x3, y3, x4, y4) {
  7663. ; Adds a Bézier spline to the current figure of the given pPath
  7664. return DllCall("gdiplus\GdipAddPathBezier", "UPtr", pPath
  7665. , "float", x1, "float", y1, "float", x2, "float", y2
  7666. , "float", x3, "float", y3, "float", x4, "float", y4)
  7667. }
  7668.  
  7669. ;#####################################################################################
  7670. ; Function: Gdip_AddPathLines
  7671. ; Description: Adds a sequence of connected lines to the current figure of this path.
  7672. ;
  7673. ; pPath: Pointer to the GraphicsPath
  7674. ; Points: the coordinates of all the points passed as x1,y1|x2,y2|x3,y3... ; it can also be an object [x1,y1,x2,y2,x3,y3]
  7675. ;
  7676. ; Return: status enumeration. 0 = success.
  7677.  
  7678. Gdip_AddPathLines(pPath, Points) {
  7679. iCount := CreatePointsF(PointsF, Points)
  7680. return DllCall("gdiplus\GdipAddPathLine2", "UPtr", pPath, "UPtr", &PointsF, "int", iCount)
  7681. }
  7682.  
  7683. Gdip_AddPathLine(pPath, x1, y1, x2, y2) {
  7684. return DllCall("gdiplus\GdipAddPathLine", "UPtr", pPath, "float", x1, "float", y1, "float", x2, "float", y2)
  7685. }
  7686.  
  7687. Gdip_AddPathArc(pPath, x, y, w, h, StartAngle, SweepAngle) {
  7688. return DllCall("gdiplus\GdipAddPathArc", "UPtr", pPath, "float", x, "float", y, "float", w, "float", h, "float", StartAngle, "float", SweepAngle)
  7689. }
  7690.  
  7691. Gdip_AddPathPie(pPath, x, y, w, h, StartAngle, SweepAngle) {
  7692. return DllCall("gdiplus\GdipAddPathPie", "UPtr", pPath, "float", x, "float", y, "float", w, "float", h, "float", StartAngle, "float", SweepAngle)
  7693. }
  7694.  
  7695. Gdip_AddPathPieC(pPath, cx, cy, rx, ry, StartAngle, SweepAngle) {
  7696. Return Gdip_AddPathPie(pPath, cx-rx, cy-ry, rx*2, ry*2, StartAngle, SweepAngle)
  7697. }
  7698.  
  7699. Gdip_StartPathFigure(pPath, closePrev:=0) {
  7700. ; Starts a new figure without closing the current figure.
  7701. ; Subsequent points added to this path are added to the new figure.
  7702. If (closePrev=1)
  7703. Gdip_ClosePathFigure(pPath)
  7704.  
  7705. return DllCall("gdiplus\GdipStartPathFigure", "UPtr", pPath)
  7706. }
  7707.  
  7708. Gdip_ClosePathFigure(pPath, all:=0) {
  7709. ; Closes the current figure of this path.
  7710. If (all=1)
  7711. return DllCall("gdiplus\GdipClosePathFigures", "UPtr", pPath)
  7712. Else
  7713. return DllCall("gdiplus\GdipClosePathFigure", "UPtr", pPath)
  7714. }
  7715.  
  7716. Gdip_ClosePathFigures(pPath) {
  7717. Gdip_ClosePathFigure(pPath, 1)
  7718. }
  7719.  
  7720. ;#####################################################################################
  7721. ; Function: Gdip_DrawPath
  7722. ; Description: Draws a sequence of lines and curves defined by a GraphicsPath object
  7723. ;
  7724. ; pGraphics: Pointer to the Graphics of a bitmap
  7725. ; pPen: Pointer to a pen object
  7726. ; pPath: Pointer to a Path object
  7727. ;
  7728. ; Return: status enumeration. 0 = success.
  7729.  
  7730. Gdip_DrawPath(pGraphics, pPen, pPath) {
  7731. Return DllCall("gdiplus\GdipDrawPath", "UPtr", pGraphics, "UPtr", pPen, "UPtr", pPath)
  7732. }
  7733.  
  7734. Gdip_ClonePath(pPath) {
  7735. pPathClone := 0
  7736. gdipLastError := DllCall("gdiplus\GdipClonePath", "UPtr", pPath, "UPtr*", pPathClone)
  7737. return pPathClone
  7738. }
  7739.  
  7740. ;######################################################################################################################################
  7741. ; The following PathGradient brush functions were written by 'Just Me' in March 2012
  7742. ; source: https://autohotkey.com/board/topic/29449-gdi-standard-library-145-by-tic/page-65
  7743. ;######################################################################################################################################
  7744.  
  7745. Gdip_PathGradientCreateFromPath(pPath) {
  7746. ; Creates and returns a path gradient brush.
  7747. ; pPath path object returned from Gdip_CreatePath()
  7748. pBrush := 0
  7749. gdipLastError := DllCall("gdiplus\GdipCreatePathGradientFromPath", "UPtr", pPath, "UPtr*", pBrush)
  7750. Return pBrush
  7751. }
  7752.  
  7753. Gdip_PathGradientSetCenterPoint(pBrush, x, y) {
  7754. ; Sets the center point of this path gradient brush.
  7755. ; pBrush Brush object returned from Gdip_PathGradientCreateFromPath().
  7756. ; X, Y X, y coordinates in pixels
  7757. CreatePointF(POINTF, x, y)
  7758. Return DllCall("gdiplus\GdipSetPathGradientCenterPoint", "UPtr", pBrush, "UPtr", &POINTF)
  7759. }
  7760.  
  7761. Gdip_PathGradientSetCenterColor(pBrush, CenterColor) {
  7762. ; Sets the center color of this path gradient brush.
  7763. ; pBrush Brush object returned from Gdip_PathGradientCreateFromPath().
  7764. ; CenterColor ARGB color value: A(lpha)R(ed)G(reen)B(lue).
  7765. Return DllCall("gdiplus\GdipSetPathGradientCenterColor", "UPtr", pBrush, "UInt", CenterColor)
  7766. }
  7767.  
  7768. Gdip_PathGradientSetSurroundColors(pBrush, SurroundColors) {
  7769. ; Sets the surround colors of this path gradient brush.
  7770. ; pBrush Brush object returned from Gdip_PathGradientCreateFromPath().
  7771. ; SurroundColours One or more ARGB color values seperated by pipe (|)).
  7772. ; updated by Marius Șucan
  7773.  
  7774. tColors := AllocateBinArray(ColorsArray, SurroundColors, "uint")
  7775. If tColors
  7776. Return DllCall("gdiplus\GdipSetPathGradientSurroundColorsWithCount", "UPtr", pBrush, "UPtr", &ColorsArray, "IntP", tColors)
  7777. Else
  7778. Return -3
  7779. }
  7780.  
  7781. Gdip_PathGradientSetSigmaBlend(pBrush, Focus, Scale:=1) {
  7782. ; Sets the blend shape of this path gradient brush to bell shape.
  7783. ; pBrush Brush object returned from Gdip_PathGradientCreateFromPath().
  7784. ; Focus Number that specifies where the center color will be at its highest intensity.
  7785. ; Values: 1.0 (center) - 0.0 (border)
  7786. ; Scale Number that specifies the maximum intensity of center color that gets blended with
  7787. ; the boundary color.
  7788. ; Values: 1.0 (100 %) - 0.0 (0 %)
  7789. Return DllCall("gdiplus\GdipSetPathGradientSigmaBlend", "UPtr", pBrush, "Float", Focus, "Float", Scale)
  7790. }
  7791.  
  7792. Gdip_PathGradientSetLinearBlend(pBrush, Focus, Scale:=1) {
  7793. ; Sets the blend shape of this path gradient brush to triangular shape.
  7794. ; pBrush Brush object returned from Gdip_PathGradientCreateFromPath()
  7795. ; Focus Number that specifies where the center color will be at its highest intensity.
  7796. ; Values: 1.0 (center) - 0.0 (border)
  7797. ; Scale Number that specifies the maximum intensity of center color that gets blended with
  7798. ; the boundary color.
  7799. ; Values: 1.0 (100 %) - 0.0 (0 %)
  7800. Return DllCall("gdiplus\GdipSetPathGradientLinearBlend", "UPtr", pBrush, "Float", Focus, "Float", Scale)
  7801. }
  7802.  
  7803. Gdip_PathGradientSetFocusScales(pBrush, xScale, yScale) {
  7804. ; Sets the focus scales of this path gradient brush.
  7805. ; pBrush Brush object returned from Gdip_PathGradientCreateFromPath().
  7806. ; xScale Number that specifies the x focus scale.
  7807. ; Values: 0.0 (0 %) - 1.0 (100 %)
  7808. ; yScale Number that specifies the y focus scale.
  7809. ; Values: 0.0 (0 %) - 1.0 (100 %)
  7810. Return DllCall("gdiplus\GdipSetPathGradientFocusScales", "UPtr", pBrush, "Float", xScale, "Float", yScale)
  7811. }
  7812.  
  7813. Gdip_AddPathGradient(pGraphics, x, y, w, h, cX, cY, cClr, sClr, BlendFocus, ScaleX, ScaleY, Shape, Angle:=0) {
  7814. ; Parameters:
  7815. ; X, Y - coordinates where to add the gradient path object
  7816. ; W, H - the width and height of the path gradient object
  7817. ; cX, cY - the coordinates of the Center Point of the gradient within the wdith and height object boundaries
  7818. ; cClr - the center color in 0xARGB
  7819. ; sClr - the surrounding color in 0xARGB
  7820. ; BlendFocus - 0.0 to 1.0; where the center color reaches the highest intensity
  7821. ; Shape - 1 = rectangle ; 0 = ellipse
  7822. ; Angle - Rotate the pPathGradientBrush at given angle
  7823. ;
  7824. ; function based on the example provided by Just Me for the path gradient functions
  7825. ; adaptations/modifications by Marius Șucan
  7826.  
  7827. pPath := Gdip_CreatePath()
  7828. If (Shape=1)
  7829. Gdip_AddPathRectangle(pPath, x, y, W, H)
  7830. Else
  7831. Gdip_AddPathEllipse(pPath, x, y, W, H)
  7832. zBrush := Gdip_PathGradientCreateFromPath(pPath)
  7833. If (Angle!=0)
  7834. Gdip_RotatePathGradientAtCenter(zBrush, Angle)
  7835. Gdip_PathGradientSetCenterPoint(zBrush, cX, cY)
  7836. Gdip_PathGradientSetCenterColor(zBrush, cClr)
  7837. Gdip_PathGradientSetSurroundColors(zBrush, sClr)
  7838. Gdip_PathGradientSetSigmaBlend(zBrush, BlendFocus)
  7839. Gdip_PathGradientSetLinearBlend(zBrush, BlendFocus)
  7840. Gdip_PathGradientSetFocusScales(zBrush, ScaleX, ScaleY)
  7841. E := Gdip_FillPath(pGraphics, zBrush, pPath)
  7842. Gdip_DeleteBrush(zBrush)
  7843. Gdip_DeletePath(pPath)
  7844. Return E
  7845. }
  7846.  
  7847. ;######################################################################################################################################
  7848. ; The following PathGradient brush functions were written by Marius Șucan
  7849. ;######################################################################################################################################
  7850.  
  7851. Gdip_CreatePathGradient(Points, WrapMode) {
  7852. ; Creates a PathGradientBrush object based on an array of points and initializes the wrap mode of the brush
  7853. ;
  7854. ; Points array format:
  7855. ; Points := "x1,y1|x2,y2|x3,y3|x4,y4" [... and so on]
  7856. ;
  7857. ; WrapMode options: specifies how an area is tiled when it is painted with a brush:
  7858. ; 0 - Tile - Tiling without flipping
  7859. ; 1 - TileFlipX - Tiles are flipped horizontally as you move from one tile to the next in a row
  7860. ; 2 - TileFlipY - Tiles are flipped vertically as you move from one tile to the next in a column
  7861. ; 3 - TileFlipXY - Tiles are flipped horizontally as you move along a row and flipped vertically as you move along a column
  7862. ; 4 - Clamp - No tiling
  7863.  
  7864. pPathGradientBrush := 0
  7865. iCount := CreatePointsF(PointsF, Points)
  7866. gdipLastError := DllCall("gdiplus\GdipCreatePathGradient", "UPtr", &PointsF, "int", iCount, "int", WrapMode, "uptr*", pPathGradientBrush)
  7867. Return pPathGradientBrush
  7868. }
  7869.  
  7870. Gdip_PathGradientGetGammaCorrection(pPathGradientBrush) {
  7871. result := 0
  7872. E := DllCall("gdiplus\GdipGetPathGradientGammaCorrection", "UPtr", pPathGradientBrush, "uint*", result)
  7873. If E
  7874. return -1
  7875. Return result
  7876. }
  7877.  
  7878. Gdip_PathGradientGetPointCount(pPathGradientBrush) {
  7879. result := 0
  7880. E := DllCall("gdiplus\GdipGetPathGradientPointCount", "UPtr", pPathGradientBrush, "int*", result)
  7881. If E
  7882. return -1
  7883. Return result
  7884. }
  7885.  
  7886. Gdip_PathGradientGetWrapMode(pPathGradientBrush) {
  7887. result := 0
  7888. E := DllCall("gdiplus\GdipGetPathGradientWrapMode", "UPtr", pPathGradientBrush, "int*", result)
  7889. If E
  7890. return -1
  7891. Return result
  7892. }
  7893.  
  7894. Gdip_PathGradientGetRect(pPathGradientBrush) {
  7895. VarSetCapacity(RectF, 16, 0)
  7896. E := DllCall("gdiplus\GdipGetPathGradientRect", "UPtr", pPathGradientBrush, "UPtr", &RectF)
  7897. If !E
  7898. Return RetrieveRectF(RectF)
  7899. Else
  7900. Return E
  7901. }
  7902.  
  7903. Gdip_PathGradientResetTransform(pPathGradientBrush) {
  7904. return DllCall("gdiplus\GdipResetPathGradientTransform", "UPtr", pPathGradientBrush)
  7905. }
  7906.  
  7907. Gdip_PathGradientRotateTransform(pPathGradientBrush, Angle, matrixOrder:=0) {
  7908. return DllCall("gdiplus\GdipRotatePathGradientTransform", "UPtr", pPathGradientBrush, "float", Angle, "int", matrixOrder)
  7909. }
  7910.  
  7911. Gdip_PathGradientScaleTransform(pPathGradientBrush, ScaleX, ScaleY, matrixOrder:=0) {
  7912. return DllCall("gdiplus\GdipScalePathGradientTransform", "UPtr", pPathGradientBrush, "float", ScaleX, "float", ScaleY, "int", matrixOrder)
  7913. }
  7914.  
  7915. Gdip_PathGradientTranslateTransform(pPathGradientBrush, X, Y, matrixOrder:=0) {
  7916. Return DllCall("gdiplus\GdipTranslatePathGradientTransform", "UPtr", pPathGradientBrush, "float", X, "float", Y, "int", matrixOrder)
  7917. }
  7918.  
  7919. Gdip_PathGradientMultiplyTransform(pPathGradientBrush, hMatrix, matrixOrder:=0) {
  7920. Return DllCall("gdiplus\GdipMultiplyPathGradientTransform", "UPtr", pPathGradientBrush, "UPtr", hMatrix, "int", matrixOrder)
  7921. }
  7922.  
  7923. Gdip_PathGradientSetTransform(pPathGradientBrush, pMatrix) {
  7924. return DllCall("gdiplus\GdipSetPathGradientTransform", "UPtr", pPathGradientBrush, "UPtr", pMatrix)
  7925. }
  7926.  
  7927. Gdip_PathGradientGetTransform(pPathGradientBrush) {
  7928. pMatrix := 0
  7929. gdipLastError := DllCall("gdiplus\GdipGetPathGradientTransform", "UPtr", pPathGradientBrush, "UPtr*", pMatrix)
  7930. Return pMatrix
  7931. }
  7932.  
  7933. Gdip_RotatePathGradientAtCenter(pPathGradientBrush, Angle, MatrixOrder:=1) {
  7934. ; function by Marius Șucan
  7935. ; based on Gdip_RotatePathAtCenter() by RazorHalo
  7936.  
  7937. Rect := Gdip_PathGradientGetRect(pPathGradientBrush)
  7938. cX := Rect.x + (Rect.w / 2)
  7939. cY := Rect.y + (Rect.h / 2)
  7940. pMatrix := Gdip_CreateMatrix()
  7941. Gdip_TranslateMatrix(pMatrix, -cX , -cY)
  7942. Gdip_RotateMatrix(pMatrix, Angle, MatrixOrder)
  7943. Gdip_TranslateMatrix(pMatrix, cX, cY, MatrixOrder)
  7944. E := Gdip_PathGradientSetTransform(pPathGradientBrush, pMatrix)
  7945. Gdip_DeleteMatrix(pMatrix)
  7946. Return E
  7947. }
  7948.  
  7949.  
  7950. Gdip_PathGradientSetGammaCorrection(pPathGradientBrush, UseGammaCorrection) {
  7951. ; Specifies whether gamma correction is enabled for a path gradient brush
  7952. ; UseGammaCorrection: 1 or 0.
  7953. return DllCall("gdiplus\GdipSetPathGradientGammaCorrection", "UPtr", pPathGradientBrush, "int", UseGammaCorrection)
  7954. }
  7955.  
  7956. Gdip_PathGradientSetWrapMode(pPathGradientBrush, WrapMode) {
  7957. ; WrapMode options: specifies how an area is tiled when it is painted with a brush:
  7958. ; 0 - Tile - Tiling without flipping
  7959. ; 1 - TileFlipX - Tiles are flipped horizontally as you move from one tile to the next in a row
  7960. ; 2 - TileFlipY - Tiles are flipped vertically as you move from one tile to the next in a column
  7961. ; 3 - TileFlipXY - Tiles are flipped horizontally as you move along a row and flipped vertically as you move along a column
  7962. ; 4 - Clamp - No tiling
  7963.  
  7964. return DllCall("gdiplus\GdipSetPathGradientWrapMode", "UPtr", pPathGradientBrush, "int", WrapMode)
  7965. }
  7966.  
  7967. Gdip_PathGradientGetCenterColor(pPathGradientBrush) {
  7968. ARGB := 0
  7969. E := DllCall("gdiplus\GdipGetPathGradientCenterColor", "UPtr", pPathGradientBrush, "uint*", ARGB)
  7970. If E
  7971. return -1
  7972. Return Format("{1:#x}", ARGB)
  7973. }
  7974.  
  7975. Gdip_PathGradientGetCenterPoint(pPathGradientBrush, ByRef X, ByRef Y) {
  7976. VarSetCapacity(PointF, 8, 0)
  7977. E := DllCall("gdiplus\GdipGetPathGradientCenterPoint", "UPtr", pPathGradientBrush, "UPtr", &PointF)
  7978. If !E
  7979. {
  7980. x := NumGet(PointF, 0, "float")
  7981. y := NumGet(PointF, 4, "float")
  7982. }
  7983. Return E
  7984. }
  7985.  
  7986. Gdip_PathGradientGetFocusScales(pPathGradientBrush, ByRef X, ByRef Y) {
  7987. x := y := 0
  7988. Return DllCall("gdiplus\GdipGetPathGradientFocusScales", "UPtr", pPathGradientBrush, "float*", X, "float*", Y)
  7989. }
  7990.  
  7991. Gdip_PathGradientGetSurroundColorCount(pPathGradientBrush) {
  7992. result := 0
  7993. E := DllCall("gdiplus\GdipGetPathGradientSurroundColorCount", "UPtr", pPathGradientBrush, "int*", result)
  7994. If E
  7995. return -1
  7996. Return result
  7997. }
  7998.  
  7999. Gdip_GetPathGradientSurroundColors(pPathGradientBrush) {
  8000. iCount := Gdip_PathGradientGetSurroundColorCount(pPathGradientBrush)
  8001. If (iCount=-1)
  8002. Return 0
  8003.  
  8004. VarSetCapacity(sColors, 8 * iCount, 0)
  8005. gdipLastError := DllCall("gdiplus\GdipGetPathGradientSurroundColorsWithCount", "UPtr", pPathGradientBrush, "UPtr", &sColors, "intP", iCount)
  8006. printList := ""
  8007. Loop %iCount%
  8008. {
  8009. A := NumGet(&sColors, 8*(A_Index-1), "uint")
  8010. printList .= Format("{1:#x}", A) "|"
  8011. }
  8012.  
  8013. Return Trim(printList, "|")
  8014. }
  8015.  
  8016. ;######################################################################################################################################
  8017. ; Function written by swagfag in July 2019
  8018. ; source https://www.autohotkey.com/boards/viewtopic.php?f=6&t=62550
  8019. ; modified by Marius Șucan
  8020.  
  8021. ; whichFormat parameter defines what channels to extract the histogram from:
  8022. ; choose as a parameter the number based on the channel[s] that interest you
  8023. ; ARGB: 0, PARGB: 1, RGB: 2, Gray: 3, B: 4, G: 5, R: 6, A: 7
  8024.  
  8025. ; Return: Status enumerated return type; 0 = OK/Success
  8026.  
  8027. Gdip_GetHistogram(pBitmap, whichFormat, ByRef newArrayA, ByRef newArrayB, ByRef newArrayC, ByRef newArrayD:=0) {
  8028. Static sizeofUInt := 4
  8029.  
  8030. z := DllCall("gdiplus\GdipBitmapGetHistogramSize", "UInt", whichFormat, "UInt*", numEntries)
  8031. newArrayA := []
  8032. VarSetCapacity(ch0, numEntries * sizeofUInt, 0)
  8033. If (whichFormat<=2)
  8034. {
  8035. newArrayB := [], newArrayC := [], newArrayD := []
  8036. VarSetCapacity(ch1, numEntries * sizeofUInt, 0)
  8037. VarSetCapacity(ch2, numEntries * sizeofUInt, 0)
  8038. If (whichFormat<2)
  8039. VarSetCapacity(ch3, numEntries * sizeofUInt, 0)
  8040. }
  8041.  
  8042. E := DllCall("gdiplus\GdipBitmapGetHistogram", "UPtr", pBitmap, "UInt", whichFormat, "UInt", numEntries, "UPtr", &ch0
  8043. , "UPtr", (whichFormat<=2) ? &ch1 : 0
  8044. , "UPtr", (whichFormat<=2) ? &ch2 : 0
  8045. , "UPtr", (whichFormat<2) ? &ch3 : 0)
  8046.  
  8047. If (E=1 && A_LastError=8)
  8048. E := 3
  8049.  
  8050. Loop %numEntries%
  8051. {
  8052. i := A_Index - 1
  8053. newArrayA[i] := NumGet(&ch0+0, i * sizeofUInt, "UInt")
  8054. If (whichFormat<=2)
  8055. {
  8056. newArrayB[i] := NumGet(&ch1+0, i * sizeofUInt, "UInt")
  8057. newArrayC[i] := NumGet(&ch2+0, i * sizeofUInt, "UInt")
  8058. If (whichFormat<2)
  8059. newArrayD[i] := NumGet(&ch3+0, i * sizeofUInt, "UInt")
  8060. }
  8061. }
  8062. ch0 := "", ch1 := ""
  8063. ch2 := "", ch3 := ""
  8064.  
  8065. Return E
  8066. }
  8067.  
  8068. Gdip_DrawRoundedLine(G, x1, y1, x2, y2, LineWidth, LineColor) {
  8069. ; function by DevX and Rabiator found on:
  8070. ; https://autohotkey.com/board/topic/29449-gdi-standard-library-145-by-tic/page-11
  8071.  
  8072. pPen := Gdip_CreatePen(LineColor, LineWidth)
  8073. Gdip_DrawLine(G, pPen, x1, y1, x2, y2)
  8074. Gdip_DeletePen(pPen)
  8075.  
  8076. pPen := Gdip_CreatePen(LineColor, LineWidth/2)
  8077. Gdip_DrawEllipse(G, pPen, x1-LineWidth/4, y1-LineWidth/4, LineWidth/2, LineWidth/2)
  8078. Gdip_DrawEllipse(G, pPen, x2-LineWidth/4, y2-LineWidth/4, LineWidth/2, LineWidth/2)
  8079. Gdip_DeletePen(pPen)
  8080. }
  8081.  
  8082. Gdip_CreateBitmapFromGdiDib(BITMAPINFO, BitmapData) {
  8083. pBitmap := 0
  8084. gdipLastError := DllCall("gdiplus\GdipCreateBitmapFromGdiDib", "UPtr", BITMAPINFO, "UPtr", BitmapData, "UPtr*", pBitmap)
  8085. Return pBitmap
  8086. }
  8087.  
  8088. ;#####################################################################################
  8089.  
  8090. ; Function Gdip_DrawImageFX
  8091. ; Description This function draws a bitmap into the pGraphics that can use an Effect.
  8092. ;
  8093. ; pGraphics Pointer to the Graphics of a bitmap
  8094. ; pBitmap Pointer to a bitmap to be drawn
  8095. ; dX, dY x, y coordinates of the destination upper-left corner where the image will be painted
  8096. ; sX, sY x, y coordinates of the source upper-left corner
  8097. ; sW, sH width and height of the source image
  8098. ; Matrix a color matrix used to alter image attributes when drawing
  8099. ; pEffect a pointer to an Effect object to apply when drawing the image
  8100. ; hMatrix a pointer to a transformation matrix
  8101. ; Unit Unit of measurement:
  8102. ; 0 - World coordinates, a nonphysical unit
  8103. ; 1 - Display units
  8104. ; 2 - A unit is 1 pixel
  8105. ; 3 - A unit is 1 point or 1/72 inch
  8106. ; 4 - A unit is 1 inch
  8107. ; 5 - A unit is 1/300 inch
  8108. ; 6 - A unit is 1 millimeter
  8109. ;
  8110. ; return status enumeration. 0 = success
  8111. ;
  8112. ; notes on the color matrix:
  8113. ; Matrix can be omitted to just draw with no alteration to ARGB
  8114. ; Matrix may be passed as a digit from 0.0 - 1.0 to change just transparency
  8115. ; Matrix can be passed as a matrix with "|" as delimiter. For example:
  8116. ; MatrixBright=
  8117. ; (
  8118. ; 1.5 |0 |0 |0 |0
  8119. ; 0 |1.5 |0 |0 |0
  8120. ; 0 |0 |1.5 |0 |0
  8121. ; 0 |0 |0 |1 |0
  8122. ; 0.05 |0.05 |0.05 |0 |1
  8123. ; )
  8124. ;
  8125. ; example color matrix:
  8126. ; MatrixBright = 1.5|0|0|0|0|0|1.5|0|0|0|0|0|1.5|0|0|0|0|0|1|0|0.05|0.05|0.05|0|1
  8127. ; MatrixGreyScale = 0.299|0.299|0.299|0|0|0.587|0.587|0.587|0|0|0.114|0.114|0.114|0|0|0|0|0|1|0|0|0|0|0|1
  8128. ; MatrixNegative = -1|0|0|0|0|0|-1|0|0|0|0|0|-1|0|0|0|0|0|1|0|1|1|1|0|1
  8129. ; To generate a color matrix using user-friendly parameters,
  8130. ; use GenerateColorMatrix()
  8131. ; Function written by Marius Șucan.
  8132.  
  8133.  
  8134. Gdip_DrawImageFX(pGraphics, pBitmap, dX:="", dY:="", sX:="", sY:="", sW:="", sH:="", matrix:="", pEffect:="", ImageAttr:=0, hMatrix:=0, Unit:=2) {
  8135. If !ImageAttr
  8136. {
  8137. if !IsNumber(Matrix)
  8138. ImageAttr := Gdip_SetImageAttributesColorMatrix(Matrix)
  8139. else if (Matrix != 1)
  8140. ImageAttr := Gdip_SetImageAttributesColorMatrix("1|0|0|0|0|0|1|0|0|0|0|0|1|0|0|0|0|0|" Matrix "|0|0|0|0|0|1")
  8141. } Else usrImageAttr := 1
  8142.  
  8143. if (sX="" && sY="")
  8144. sX := sY := 0
  8145.  
  8146. if (sW="" && sH="")
  8147. Gdip_GetImageDimensions(pBitmap, sW, sH)
  8148.  
  8149. if (!hMatrix && dX!="" && dY!="")
  8150. {
  8151. hMatrix := dhMatrix := Gdip_CreateMatrix()
  8152. Gdip_TranslateMatrix(dhMatrix, dX, dY, 1)
  8153. }
  8154.  
  8155. CreateRectF(sourceRect, sX, sY, sW, sH)
  8156. gdipLastError := DllCall("gdiplus\GdipDrawImageFX"
  8157. , "UPtr", pGraphics
  8158. , "UPtr", pBitmap
  8159. , "UPtr", &sourceRect
  8160. , "UPtr", hMatrix ? hMatrix : 0 ; transformation matrix
  8161. , "UPtr", pEffect ? pEffect : 0
  8162. , "UPtr", ImageAttr ? ImageAttr : 0
  8163. , "Uint", Unit) ; srcUnit
  8164. ; r4 := GetStatus(A_LineNumber ":GdipDrawImageFX",r4)
  8165.  
  8166. If dhMatrix
  8167. Gdip_DeleteMatrix(dhMatrix)
  8168.  
  8169. If (ImageAttr && usrImageAttr!=1)
  8170. Gdip_DisposeImageAttributes(ImageAttr)
  8171.  
  8172. Return E
  8173. }
  8174.  
  8175. Gdip_BitmapApplyEffect(pBitmap, pEffect, x:="", y:="", w:="", h:="") {
  8176. ; X, Y - coordinates for the rectangle where the effect is applied
  8177. ; W, H - width and heigh for the rectangle where the effect is applied
  8178. ; If X, Y, W or H are omitted , the effect is applied on the entire pBitmap
  8179. ;
  8180. ; written by Marius Șucan
  8181. ; many thanks to Drugwash for the help provided
  8182. If (InStr(pEffect, "err-") || !pEffect || !pBitmap)
  8183. Return 2
  8184.  
  8185. If (!x && !y && !w && !h)
  8186. none := 1
  8187. Else
  8188. CreateRectF(Rect, x, y, x + w, y + h, "uint")
  8189.  
  8190. E := DllCall("gdiplus\GdipBitmapApplyEffect"
  8191. , "UPtr", pBitmap
  8192. , "UPtr", pEffect
  8193. , "UPtr", (none=1) ? 0 : &Rect
  8194. , "UPtr", 0 ; useAuxData
  8195. , "UPtr", 0 ; auxData
  8196. , "UPtr", 0) ; auxDataSize
  8197. Return E
  8198. }
  8199.  
  8200. COM_CLSIDfromString(ByRef CLSID, String) {
  8201. VarSetCapacity(CLSID, 16, 0)
  8202. Return DllCall("ole32\CLSIDFromString", "WStr", String, "UPtr", &CLSID)
  8203. }
  8204.  
  8205. Gdip_CreateEffect(whichFX, paramA, paramB, paramC:=0) {
  8206. /*
  8207. whichFX options:
  8208. 1 - Blur
  8209. paramA - radius [0, 255]
  8210. paramB - bool [0, 1]
  8211. 2 - Sharpen
  8212. paramA - radius [0, 255]
  8213. paramB - amount [0, 100]
  8214. 3 - ColorMatrix
  8215. paramA - color matrix example:
  8216. matrixBright := "1.5|0|0|0|0|0|1.5|0|0|0|0|0|1.5|0|0|0|0|0|1|0|0.05|0.05|0.05|0|1"
  8217. 4 - ! ColorLUT
  8218. 5 - BrightnessContrast
  8219. paramA - brightness [-255, 255]
  8220. paramB - contrast [-100, 100]
  8221. 6 - HueSaturationLightness
  8222. paramA - hue [-180, 180]
  8223. paramB - saturation [-100, 100]
  8224. paramC - light [-100, 100]
  8225. 7 - LevelsAdjust
  8226. paramA - highlights [0, 100]
  8227. paramB - midtones [-100, 100]
  8228. paramC - shadows [0, 100]
  8229. 8 - Tint
  8230. paramA - hue [-180, 180]
  8231. paramB - amount [0, 100]
  8232. 9 - ColorBalance
  8233. paramA - Cyan / Red [-100, 100]
  8234. paramB - Magenta / Green [-100, 100]
  8235. paramC - Yellow / Blue [-100, 100]
  8236. 10 - ! RedEyeCorrection
  8237. 11 - ColorCurve
  8238. paramA - Type of adjustments [0, 7]
  8239. 0 - AdjustExposure [-255, 255]
  8240. 1 - AdjustDensity [-255, 255]
  8241. 2 - AdjustContrast [-100, 100]
  8242. 3 - AdjustHighlight [-100, 100]
  8243. 4 - AdjustShadow [-100, 100]
  8244. 5 - AdjustMidtone [-100, 100]
  8245. 6 - AdjustWhiteSaturation [0, 255]
  8246. 7 - AdjustBlackSaturation [0, 255]
  8247.  
  8248. paramB - Apply ColorCurve on channels [1, 4]
  8249. 1 - Red
  8250. 2 - Green
  8251. 3 - Blue
  8252. 4 - All channels
  8253.  
  8254. paramC - An adjust value within range according to paramA
  8255.  
  8256. Effects marked with "!" are not yet implemented.
  8257. Through ParamA, ParamB and ParamC, the effects can be controlled.
  8258. Function written by Marius Șucan. Many thanks to Drugwash for the help provided,
  8259. */
  8260.  
  8261. Static gdipImgFX := {1:"633C80A4-1843-482b-9EF2-BE2834C5FDD4", 2:"63CBF3EE-C526-402c-8F71-62C540BF5142", 3:"718F2615-7933-40e3-A511-5F68FE14DD74", 4:"A7CE72A9-0F7F-40d7-B3CC-D0C02D5C3212", 5:"D3A1DBE1-8EC4-4c17-9F4C-EA97AD1C343D", 6:"8B2DD6C3-EB07-4d87-A5F0-7108E26A9C5F", 7:"99C354EC-2A31-4f3a-8C34-17A803B33A25", 8:"1077AF00-2848-4441-9489-44AD4C2D7A2C", 9:"537E597D-251E-48da-9664-29CA496B70F8", 10:"74D29D05-69A4-4266-9549-3CC52836B632", 11:"DD6A0022-58E4-4a67-9D9B-D48EB881A53D"}
  8262. pEffect := 0
  8263. r1 := COM_CLSIDfromString(eFXguid, "{" gdipImgFX[whichFX] "}" )
  8264. If r1
  8265. Return "err-" r1
  8266.  
  8267. If (A_PtrSize=4) ; 32 bits
  8268. {
  8269. r2 := DllCall("gdiplus\GdipCreateEffect"
  8270. , "UInt", NumGet(eFXguid, 0, "UInt")
  8271. , "UInt", NumGet(eFXguid, 4, "UInt")
  8272. , "UInt", NumGet(eFXguid, 8, "UInt")
  8273. , "UInt", NumGet(eFXguid, 12, "UInt")
  8274. , "Ptr*", pEffect)
  8275. } Else
  8276. {
  8277. r2 := DllCall("gdiplus\GdipCreateEffect"
  8278. , "UPtr", &eFXguid
  8279. , "Ptr*", pEffect)
  8280. }
  8281. If r2
  8282. Return "err-" r2
  8283.  
  8284. ; r2 := GetStatus(A_LineNumber ":GdipCreateEffect", r2)
  8285. If (whichFX=3) ; Color matrix
  8286. CreateColourMatrix(paramA, FXparams)
  8287. Else
  8288. VarSetCapacity(FXparams, 12, 0)
  8289.  
  8290. If (whichFX=1) ; Blur FX
  8291. {
  8292. If (paramA>255)
  8293. paramA := 255
  8294. FXsize := 8
  8295. NumPut(paramA, FXparams, 0, "Float") ; radius [0, 255]
  8296. NumPut(paramB, FXparams, 4, "Uchar") ; bool 0, 1
  8297. } Else If (whichFX=3) ; Color matrix
  8298. {
  8299. FXsize := 100
  8300. } Else If (whichFX=2) ; Sharpen FX
  8301. {
  8302. FXsize := 8
  8303. NumPut(paramA, FXparams, 0, "Float") ; radius [0, 255]
  8304. NumPut(paramB, FXparams, 4, "Float") ; amount [0, 100]
  8305. } Else If (whichFX=5) ; Brightness / Contrast
  8306. {
  8307. FXsize := 8
  8308. NumPut(paramA, FXparams, 0, "Int") ; brightness [-255, 255]
  8309. NumPut(paramB, FXparams, 4, "Int") ; contrast [-100, 100]
  8310. } Else If (whichFX=6) ; Hue / Saturation / Lightness
  8311. {
  8312. FXsize := 12
  8313. NumPut(paramA, FXparams, 0, "Int") ; hue [-180, 180]
  8314. NumPut(paramB, FXparams, 4, "Int") ; saturation [-100, 100]
  8315. NumPut(paramC, FXparams, 8, "Int") ; light [-100, 100]
  8316. } Else If (whichFX=7) ; Levels adjust
  8317. {
  8318. FXsize := 12
  8319. NumPut(paramA, FXparams, 0, "Int") ; highlights [0, 100]
  8320. NumPut(paramB, FXparams, 4, "Int") ; midtones [-100, 100]
  8321. NumPut(paramC, FXparams, 8, "Int") ; shadows [0, 100]
  8322. } Else If (whichFX=8) ; Tint adjust
  8323. {
  8324. FXsize := 8
  8325. NumPut(paramA, FXparams, 0, "Int") ; hue [180, 180]
  8326. NumPut(paramB, FXparams, 4, "Int") ; amount [0, 100]
  8327. } Else If (whichFX=9) ; Colors balance
  8328. {
  8329. FXsize := 12
  8330. NumPut(paramA, FXparams, 0, "Int") ; Cyan / Red [-100, 100]
  8331. NumPut(paramB, FXparams, 4, "Int") ; Magenta / Green [-100, 100]
  8332. NumPut(paramC, FXparams, 8, "Int") ; Yellow / Blue [-100, 100]
  8333. } Else If (whichFX=11) ; ColorCurve
  8334. {
  8335. FXsize := 12
  8336. NumPut(paramA, FXparams, 0, "Int") ; Type of adjustment [0, 7]
  8337. NumPut(paramB, FXparams, 4, "Int") ; Channels to affect [1, 4]
  8338. NumPut(paramC, FXparams, 8, "Int") ; Adjustment value [based on the type of adjustment]
  8339. }
  8340.  
  8341. ; DllCall("gdiplus\GdipGetEffectParameterSize", "UPtr", pEffect, "uint*", FXsize)
  8342. r3 := DllCall("gdiplus\GdipSetEffectParameters", "UPtr", pEffect, "UPtr", &FXparams, "UInt", FXsize)
  8343. If r3
  8344. {
  8345. Gdip_DisposeEffect(pEffect)
  8346. Return "err-" r3
  8347. }
  8348. ; r3 := GetStatus(A_LineNumber ":GdipSetEffectParameters", r3)
  8349. ; ToolTip, % r1 " -- " r2 " -- " r3 " -- " r4,,, 2
  8350. Return pEffect
  8351. }
  8352.  
  8353. Gdip_DisposeEffect(pEffect) {
  8354. If (pEffect && !InStr(pEffect, "err"))
  8355. r := DllCall("gdiplus\GdipDeleteEffect", "UPtr", pEffect)
  8356. Return r
  8357. }
  8358.  
  8359. GenerateColorMatrix(modus, bright:=1, contrast:=0, saturation:=1, alph:=1, chnRdec:=0, chnGdec:=0, chnBdec:=0) {
  8360. ; parameters ranges / intervals:
  8361. ; bright: [0.001 - 20.0]
  8362. ; contrast: [-20.0 - 1.00]
  8363. ; saturation: [0.001 - 5.00]
  8364. ; alph: [0.001 - 5.00]
  8365. ;
  8366. ; modus options:
  8367. ; 0 - personalized colors based on the bright, contrast [hue], saturation parameters
  8368. ; 1 - personalized colors based on the bright, contrast, saturation parameters
  8369. ; 2 - grayscale image
  8370. ; 3 - grayscale R channel
  8371. ; 4 - grayscale G channel
  8372. ; 5 - grayscale B channel
  8373. ; 6 - negative / invert image
  8374. ; 7 - alpha channel as grayscale image
  8375. ; 8 - sepia
  8376. ;
  8377. ; chnRdec, chnGdec, chnBdec only apply in modus=1
  8378. ; these represent offsets for the RGB channels
  8379.  
  8380. ; in modus=0 the parameters have other ranges:
  8381. ; bright: [-5.00 - 5.00]
  8382. ; hue: [-1.57 - 1.57] ; pi/2 - contrast stands for hue in this mode
  8383. ; saturation: [0.001 - 5.00]
  8384. ; formulas for modus=0 were written by Smurth
  8385. ; extracted from https://autohotkey.com/board/topic/29449-gdi-standard-library-145-by-tic/page-86
  8386. ;
  8387. ; function written by Marius Șucan
  8388. ; infos from http://www.graficaobscura.com/matrix/index.html
  8389. ; NTSC // CCIR 601 luma RGB weights:
  8390. ; r := 0.29970, g := 0.587130, b := 0.114180
  8391.  
  8392. Static NTSCr := 0.308, NTSCg := 0.650, NTSCb := 0.095 ; personalized values
  8393. matrix := ""
  8394.  
  8395. If (modus=2) ; grayscale
  8396. {
  8397. LGA := (bright<=1) ? bright/1.5 - 0.6666 : bright - 1
  8398. Ra := NTSCr + LGA
  8399. If (Ra<0)
  8400. Ra := 0
  8401. Ga := NTSCg + LGA
  8402. If (Ga<0)
  8403. Ga := 0
  8404. Ba := NTSCb + LGA
  8405. If (Ba<0)
  8406. Ba := 0
  8407. matrix := Ra "|" Ra "|" Ra "|0|0|" Ga "|" Ga "|" Ga "|0|0|" Ba "|" Ba "|" Ba "|0|0|0|0|0|" alph "|0|" contrast "|" contrast "|" contrast "|0|1"
  8408. } Else If (modus=3) ; grayscale R
  8409. {
  8410. Ga := 0, Ba := 0, GGA := 0
  8411. Ra := bright
  8412. matrix := Ra "|" Ra "|" Ra "|0|0|" Ga "|" Ga "|" Ga "|0|0|" Ba "|" Ba "|" Ba "|0|0|0|0|0|" alph "|0|" GGA+0.01 "|" GGA "|" GGA "|0|1"
  8413. } Else If (modus=4) ; grayscale G
  8414. {
  8415. Ra := 0, Ba := 0, GGA := 0
  8416. Ga := bright
  8417. matrix := Ra "|" Ra "|" Ra "|0|0|" Ga "|" Ga "|" Ga "|0|0|" Ba "|" Ba "|" Ba "|0|0|0|0|0|" alph "|0|" GGA "|" GGA+0.01 "|" GGA "|0|1"
  8418. } Else If (modus=5) ; grayscale B
  8419. {
  8420. Ra := 0, Ga := 0, GGA := 0
  8421. Ba := bright
  8422. matrix := Ra "|" Ra "|" Ra "|0|0|" Ga "|" Ga "|" Ga "|0|0|" Ba "|" Ba "|" Ba "|0|0|0|0|0|" alph "|0|" GGA "|" GGA "|" GGA+0.01 "|0|1"
  8423. } Else If (modus=6) ; negative / invert
  8424. {
  8425. matrix := "-1|0|0|0|0|0|-1|0|0|0|0|0|-1|0|0|0|0|0|" alph "|0|1|1|1|0|1"
  8426. } Else If (modus=1) ; personalized saturation, contrast and brightness
  8427. {
  8428. bL := bright, aL := alph
  8429. G := contrast, sL := saturation
  8430. sLi := 1 - saturation
  8431. bLa := bright - 1
  8432. If (sL>1)
  8433. {
  8434. z := (bL<1) ? bL : 1
  8435. sL := sL*z
  8436. If (sL<0.98)
  8437. sL := 0.98
  8438.  
  8439. y := z*(1 - sL)
  8440. mA := z*(y*NTSCr + sL + bLa + chnRdec)
  8441. mB := z*(y*NTSCr)
  8442. mC := z*(y*NTSCr)
  8443. mD := z*(y*NTSCg)
  8444. mE := z*(y*NTSCg + sL + bLa + chnGdec)
  8445. mF := z*(y*NTSCg)
  8446. mG := z*(y*NTSCb)
  8447. mH := z*(y*NTSCb)
  8448. mI := z*(y*NTSCb + sL + bLa + chnBdec)
  8449. mtrx:= mA "|" mB "|" mC "| 0 |0"
  8450. . "|" mD "|" mE "|" mF "| 0 |0"
  8451. . "|" mG "|" mH "|" mI "| 0 |0"
  8452. . "| 0 | 0 | 0 |" aL "|0"
  8453. . "|" G "|" G "|" G "| 0 |1"
  8454. } Else
  8455. {
  8456. z := (bL<1) ? bL : 1
  8457. tR := NTSCr - 0.5 + bL/2
  8458. tG := NTSCg - 0.5 + bL/2
  8459. tB := NTSCb - 0.5 + bL/2
  8460. rB := z*(tR*sLi+bL*(1 - sLi) + chnRdec)
  8461. gB := z*(tG*sLi+bL*(1 - sLi) + chnGdec)
  8462. bB := z*(tB*sLi+bL*(1 - sLi) + chnBdec) ; Formula used: A*w + B*(1 – w)
  8463. rF := z*(NTSCr*sLi + (bL/2 - 0.5)*sLi)
  8464. gF := z*(NTSCg*sLi + (bL/2 - 0.5)*sLi)
  8465. bF := z*(NTSCb*sLi + (bL/2 - 0.5)*sLi)
  8466.  
  8467. rB := rB*z+rF*(1 - z)
  8468. gB := gB*z+gF*(1 - z)
  8469. bB := bB*z+bF*(1 - z) ; Formula used: A*w + B*(1 – w)
  8470. If (rB<0)
  8471. rB := 0
  8472. If (gB<0)
  8473. gB := 0
  8474. If (bB<0)
  8475. bB := 0
  8476. If (rF<0)
  8477. rF := 0
  8478.  
  8479. If (gF<0)
  8480. gF := 0
  8481.  
  8482. If (bF<0)
  8483. bF := 0
  8484.  
  8485. ; ToolTip, % rB " - " rF " --- " gB " - " gF
  8486. mtrx:= rB "|" rF "|" rF "| 0 |0"
  8487. . "|" gF "|" gB "|" gF "| 0 |0"
  8488. . "|" bF "|" bF "|" bB "| 0 |0"
  8489. . "| 0 | 0 | 0 |" aL "|0"
  8490. . "|" G "|" G "|" G "| 0 |1"
  8491. ; matrix adjusted for lisibility
  8492. }
  8493. matrix := StrReplace(mtrx, A_Space)
  8494. } Else If (modus=0) ; personalized hue, saturation and brightness
  8495. {
  8496. s1 := contrast ; in this mode, contrast stands for hue
  8497. s2 := saturation
  8498. s3 := bright
  8499. aL := alph
  8500.  
  8501. s1 := s2*sin(s1)
  8502. sc := 1-s2
  8503. r := NTSCr*sc-s1
  8504. g := NTSCg*sc-s1
  8505. b := NTSCb*sc-s1
  8506.  
  8507. rB := r+s2+3*s1
  8508. gB := g+s2+3*s1
  8509. bB := b+s2+3*s1
  8510. mtrx := rB "|" r "|" r "| 0 |0"
  8511. . "|" g "|" gB "|" g "| 0 |0"
  8512. . "|" b "|" b "|" bB "| 0 |0"
  8513. . "| 0 | 0 | 0 |" aL "|0"
  8514. . "|" s3 "|" s3 "|" s3 "| 0 |1"
  8515. matrix := StrReplace(mtrx, A_Space)
  8516. } Else If (modus=7) ; alpha channel
  8517. {
  8518. matrix := "0|0|0|0|0"
  8519. . "|0|0|0|0|0"
  8520. . "|0|0|0|0|0"
  8521. . "|1|1|1|25|0"
  8522. . "|0|0|0|0|1"
  8523. ; matrix := StrReplace(mtrx, A_Space)
  8524. } Else If (modus=8) ; sepia
  8525. {
  8526. matrix := "0.39|0.34|0.27|0|0"
  8527. . "|0.76|0.58|0.33|0|0"
  8528. . "|0.19|0.16|0.13|0|0"
  8529. . "|0|0|0|" alph "|0"
  8530. . "|0|0|0|0|1"
  8531. ; matrix := StrReplace(mtrx, A_Space)
  8532. } Else If (modus=9) ; partial alpha channel remover
  8533. {
  8534. matrix := "1|0|0|0|0"
  8535. . "|0|1|0|0|0"
  8536. . "|0|0|1|0|0"
  8537. . "|0|0|0|" alph "|0"
  8538. . "|0|0|0|0|1"
  8539. ; matrix := StrReplace(mtrx, A_Space)
  8540. }
  8541. Return matrix
  8542. }
  8543.  
  8544. Gdip_CompareBitmaps(pBitmapA, pBitmapB, accuracy:=25) {
  8545. ; On success, it returns the percentage of similarity between the given pBitmaps.
  8546. ; If the given pBitmaps do not have the same resolution,
  8547. ; the return value is -1.
  8548. ;
  8549. ; Function by Tic, from June 2010
  8550. ; Source: https://autohotkey.com/board/topic/29449-gdi-standard-library-145-by-tic/page-27
  8551. ;
  8552. ; Warning: it can be very slow with really large images and high accuracy.
  8553. ;
  8554. ; Updated and modified by Marius Șucan in September 2019.
  8555. ; Added accuracy factor.
  8556.  
  8557. If (!pBitmapA || !pBitmapB)
  8558. Return -1
  8559.  
  8560. If (accuracy>99)
  8561. accuracy := 100
  8562. Else If (accuracy<5)
  8563. accuracy := 5
  8564.  
  8565. Gdip_GetImageDimensions(pBitmapA, WidthA, HeightA)
  8566. Gdip_GetImageDimensions(pBitmapB, WidthB, HeightB)
  8567. If (accuracy!=100)
  8568. {
  8569. pBitmap1 := Gdip_ResizeBitmap(pBitmapA, Floor(WidthA*(accuracy/100)), Floor(HeightA*(accuracy/100)), 0, 5)
  8570. pBitmap2 := Gdip_ResizeBitmap(pBitmapB, Floor(WidthB*(accuracy/100)), Floor(HeightB*(accuracy/100)), 0, 5)
  8571. If (!pBitmap1 || !pBitmap2)
  8572. {
  8573. Gdip_DisposeImage(pbitmap1, 1)
  8574. Gdip_DisposeImage(pbitmap2, 1)
  8575. Return -1
  8576. }
  8577. } Else
  8578. {
  8579. pBitmap1 := pBitmapA
  8580. pBitmap2 := pBitmapB
  8581. }
  8582.  
  8583. Gdip_GetImageDimensions(pBitmap1, Width1, Height1)
  8584. Gdip_GetImageDimensions(pBitmap2, Width2, Height2)
  8585. if (!Width1 || !Height1 || !Width2 || !Height2
  8586. || Width1 != Width2 || Height1 != Height2)
  8587. {
  8588. If (accuracy!=100)
  8589. {
  8590. Gdip_DisposeImage(pBitmap1, 1)
  8591. Gdip_DisposeImage(pBitmap2, 1)
  8592. }
  8593. Return -1
  8594. }
  8595.  
  8596. E1 := Gdip_LockBits(pBitmap1, 0, 0, Width1, Height1, Stride1, Scan01, BitmapData1)
  8597. E2 := Gdip_LockBits(pBitmap2, 0, 0, Width2, Height2, Stride2, Scan02, BitmapData2)
  8598. If (E1 || E2)
  8599. {
  8600. If !E1
  8601. Gdip_UnlockBits(pBitmap1, BitmapData1)
  8602. If !E2
  8603. Gdip_UnlockBits(pBitmap2, BitmapData2)
  8604.  
  8605. If (accuracy!=100)
  8606. {
  8607. Gdip_DisposeImage(pBitmap1, 1)
  8608. Gdip_DisposeImage(pBitmap2, 1)
  8609. }
  8610. Return -1
  8611. }
  8612.  
  8613. z := 0
  8614. Loop %Height1%
  8615. {
  8616. y++
  8617. Loop %Width1%
  8618. {
  8619. Gdip_FromARGB(Gdip_GetLockBitPixel(Scan01, A_Index-1, y-1, Stride1), A1, R1, G1, B1)
  8620. Gdip_FromARGB(Gdip_GetLockBitPixel(Scan02, A_Index-1, y-1, Stride2), A2, R2, G2, B2)
  8621. z += Abs(A2-A1) + Abs(R2-R1) + Abs(G2-G1) + Abs(B2-B1)
  8622. }
  8623. }
  8624.  
  8625. Gdip_UnlockBits(pBitmap1, BitmapData1)
  8626. Gdip_UnlockBits(pBitmap2, BitmapData2)
  8627. If (accuracy!=100)
  8628. {
  8629. Gdip_DisposeImage(pBitmap1)
  8630. Gdip_DisposeImage(pBitmap2)
  8631. }
  8632.  
  8633. Return z/(Width1*Width2*3*255/100)
  8634. }
  8635.  
  8636. Gdip_RetrieveBitmapChannel(pBitmap, channel, PixelFormat:=0) {
  8637. ; Channel to retrive:
  8638. ; 1 - Red
  8639. ; 2 - Green
  8640. ; 3 - Blue
  8641. ; 4 - Alpha
  8642. ; On success, the function will return a pBitmap
  8643. ; in 24-RGB PixelFormat containing a grayscale
  8644. ; rendition of the retrieved channel.
  8645.  
  8646. If !pBitmap
  8647. Return
  8648.  
  8649. Gdip_GetImageDimensions(pBitmap, imgW, imgH)
  8650. If (!imgW || !imgH)
  8651. Return
  8652.  
  8653. newBitmap := Gdip_CreateBitmap(imgW, imgH, PixelFormat)
  8654. If !newBitmap
  8655. Return
  8656.  
  8657. G := Gdip_GraphicsFromImage(newBitmap, 7)
  8658. If !G
  8659. {
  8660. Gdip_DisposeImage(newBitmap, 1)
  8661. Return
  8662. }
  8663.  
  8664. If (channel=1)
  8665. matrix := GenerateColorMatrix(3)
  8666. Else If (channel=2)
  8667. matrix := GenerateColorMatrix(4)
  8668. Else If (channel=3)
  8669. matrix := GenerateColorMatrix(5)
  8670. Else If (channel=4)
  8671. matrix := GenerateColorMatrix(7)
  8672. Else Return
  8673.  
  8674. Gdip_GraphicsClear(G, "0xff000000")
  8675. E := Gdip_DrawImage(G, pBitmap, 0, 0, imgW, imgH, 0, 0, imgW, imgH, matrix)
  8676. If E
  8677. {
  8678. Gdip_DisposeImage(newBitmap, 1)
  8679. Return
  8680. }
  8681.  
  8682. Gdip_DeleteGraphics(G)
  8683. Return newBitmap
  8684. }
  8685.  
  8686. Gdip_RenderPixelsOpaque(pBitmap, pBrush:=0, alphaLevel:=0, PixelFormat:=0) {
  8687. ; alphaLevel - from 0 [transparent] to 1 or beyond [opaque]
  8688. ;
  8689. ; This function is meant to make opaque partially transparent pixels.
  8690. ; It returns a pointer to a new pBitmap.
  8691. ;
  8692. ; If pBrush is given, the background of the image is filled using it,
  8693. ; otherwise, the pixels that are 100% transparent
  8694. ; might remain transparent.
  8695.  
  8696. Gdip_GetImageDimensions(pBitmap, imgW, imgH)
  8697. newBitmap := Gdip_CreateBitmap(imgW, imgH, PixelFormat)
  8698. If newBitmap
  8699. G := Gdip_GraphicsFromImage(newBitmap, 7)
  8700.  
  8701. If (!newBitmap || !G)
  8702. {
  8703. Gdip_DisposeImage(newBitmap, 1)
  8704. Gdip_DeleteGraphics(G)
  8705. Return
  8706. }
  8707.  
  8708. If alphaLevel
  8709. matrix := GenerateColorMatrix(0, 0, 0, 1, alphaLevel)
  8710. Else
  8711. matrix := GenerateColorMatrix(0, 0, 0, 1, 25)
  8712.  
  8713. If pBrush
  8714. Gdip_FillRectangle(G, pBrush, 0, 0, imgW, imgH)
  8715.  
  8716. E := Gdip_DrawImage(G, pBitmap, 0, 0, imgW, imgH, 0, 0, imgW, imgH, matrix)
  8717. Gdip_DeleteGraphics(G)
  8718. If E
  8719. {
  8720. Gdip_DisposeImage(newBitmap, 1)
  8721. Return
  8722. }
  8723.  
  8724. Return newBitmap
  8725. }
  8726.  
  8727. Gdip_TestBitmapUniformity(pBitmap, HistogramFormat:=3, ByRef maxLevelIndex:=0, ByRef maxLevelPixels:=0, ByRef avgLevel:=0) {
  8728. ; This function tests whether the given pBitmap
  8729. ; is in a single shade [color] or not.
  8730.  
  8731. ; If HistogramFormat parameter is set to 3, the function
  8732. ; retrieves the intensity/gray histogram and checks
  8733. ; how many pixels are for each level [0, 255].
  8734. ;
  8735. ; If all pixels are found at a single level,
  8736. ; the return value is 1, because the pBitmap is considered
  8737. ; uniform, in a single shade.
  8738. ;
  8739. ; One can set the HistogramFormat to 4 [R], 5 [G], 6 [B] or 7 [A]
  8740. ; to test for the uniformity of a specific channel.
  8741. ;
  8742. ; A threshold value of 0.0005% of all the pixels, is used.
  8743. ; This is to ensure that a few pixels do not change the status.
  8744.  
  8745. If !pBitmap
  8746. Return -1
  8747.  
  8748. LevelsArray := []
  8749. maxLevelIndex := maxLevelPixels := nrPixels := 9
  8750. Gdip_GetImageDimensions(pBitmap, Width, Height)
  8751. E := Gdip_GetHistogram(pBitmap, HistogramFormat, LevelsArray, 0, 0)
  8752. If E
  8753. Return -2
  8754.  
  8755. histoList := ""
  8756. counter := sum := 0
  8757. Loop 256
  8758. {
  8759. nrPixels := Round(LevelsArray[A_Index - 1])
  8760. If (nrPixels>0)
  8761. {
  8762. counter++
  8763. histoList .= nrPixels "." A_Index - 1 "|"
  8764. sum += A_Index - 1
  8765. }
  8766. }
  8767.  
  8768. avgLevel := Round(sum/counter, 1)
  8769. Sort histoList, NURD|
  8770. histoList := Trim(histoList, "|")
  8771. histoListSortedArray := StrSplit(histoList, "|")
  8772. maxLevel := StrSplit(histoListSortedArray[1], ".")
  8773. maxLevelIndex := maxLevel[2]
  8774. maxLevelPixels := maxLevel[1]
  8775. pixelsThreshold := Round((Width * Height) * 0.0065) + 1
  8776. ; ToolTip, % pixelsThreshold "|" maxLevelIndex " -- " maxLevelPixels " | " histoListSortedArray[1] "`n" histoList, , , 3
  8777. If (Floor(histoListSortedArray[2])<pixelsThreshold)
  8778. Return 1
  8779. Else
  8780. Return 0
  8781. }
  8782.  
  8783. Gdip_SetAlphaChannel(pBitmap, pBitmapMask, invertAlphaMask:=0, replaceSourceAlphaChannel:=0, whichChannel:=1) {
  8784. /*
  8785. Function written with help provided by Spawnova. Thank you very much.
  8786. pBitmap and pBitmapMask must be the same width and height
  8787. and in 32-ARGB format: PXF32ARGB - 0x26200A.
  8788.  
  8789. The alpha channel will be applied directly on the pBitmap provided.
  8790.  
  8791. For best results, pBitmapMask should be grayscale.
  8792.  
  8793. Original code:
  8794. int SetAlphaChannel(int *imageData, int *maskData, int w, int h, int invert, int replaceAlpha, int whichChannel) {
  8795. if (whichChannel==1) // red
  8796. whichChannel = 16;
  8797. else if (whichChannel==2) // green
  8798. whichChannel = 8;
  8799. else if (whichChannel==3) // blue
  8800. whichChannel = 0;
  8801. else if (whichChannel==4) // alpha
  8802. whichChannel = 24;
  8803.  
  8804. int px;
  8805. if (replaceAlpha==1) {
  8806. for (int x = 0; x < w; x++) {
  8807. for (int y = 0; y < h; y++) {
  8808. px = x+y*w;
  8809. unsigned char alpha = maskData[px] >> whichChannel;
  8810. int alpha2 = (invert==1) ? 255 - alpha : alpha;
  8811. imageData[px] = (alpha2 << 24) | (imageData[px] & 0x00ffffff);
  8812. }
  8813. }
  8814. } else {
  8815. for (int x = 0; x < w; x++) {
  8816. for (int y = 0; y < h; y++) {
  8817. px = x+y*w;
  8818. unsigned char a = imageData[px] >> 24;
  8819. unsigned char alpha = maskData[px] >> whichChannel;
  8820. int alpha2 = alpha - (255-a); // handles bitmaps that already have alpha
  8821. if (alpha2<0) {
  8822. alpha2 = 0;
  8823. }
  8824.  
  8825. if (invert==1) {
  8826. alpha2 = 255 - alpha2;
  8827. }
  8828. imageData[px] = (alpha2 << 24) | (imageData[px] & 0x00ffffff);
  8829. }
  8830. }
  8831. }
  8832. return 1;
  8833. }
  8834. */
  8835.  
  8836. static mCodeFunc := 0
  8837. if (mCodeFunc=0)
  8838. {
  8839. if (A_PtrSize=8)
  8840. base64enc := "
  8841. (LTrim Join
  8842. 2,x64:QVdBVkFVQVRVV1ZTRItsJGhJicuLTCR4SInWg/kBD4TZAQAAg/kCD4SyAAAAg/kDD4TRAQAAg/kEuBgAAAAPRMiDfCRwAQ+EowAAAEWFwA+OZgEAAEWNcP9NY8Ax7UG8/wAAAEqNHIUAAAAAMf9mkEWFyX5YQYP9AQ+E2QAAAEyNB
  8843. K0AAAAAMdIPH4AAAAAAR4sUA0KLBAZFidfT+EHB7xgPtsBCjYQ4Af///4XAD0jHQYHi////AIPCAcHgGEQJ0EOJBANJAdhBOdF1w0iNRQFMOfUPhOEAAABIicXrkYN8JHABuQgAAAAPhV3///9FhcAPjsMAAABBjXj/TWPAMdtOjRSFAAAA
  8844. AA8fgAAAAABFhcl+MUGD/QEPhLEAAABIjQSdAAAAAEUxwGYPH0QAAIsUBkGDwAHT+kGIVAMDTAHQRTnBdepIjUMBSDnfdGxIicPrvA8fQABIjRStAAAAAEUxwA8fRAAARYsUE4sEFkWJ19P4QcHvGA+2wEKNhDgB////RYnnhcAPSMdBgeL
  8845. ///8AQYPAAUEpx0SJ+MHgGEQJ0EGJBBNIAdpFOcF1ukiNRQFMOfUPhR////+4AQAAAFteX11BXEFdQV5BX8MPHwBIjRSdAAAAAEUxwA8fRAAAiwQWQYPAAdP499BBiEQTA0wB0kU5wXXo6Un///+5EAAAAOk6/v//McnpM/7//w==
  8846. )"
  8847. else
  8848. base64enc := "
  8849. (LTrim Join
  8850. 2,x86:VVdWU4PsBIN8JDABD4T1AQAAg3wkMAIPhBwBAACDfCQwAw+E7AEAAIN8JDAEuBgAAAAPRUQkMIlEJDCDfCQsAQ+EBgEAAItUJCCF0g+OiQAAAItEJCDHBCQAAAAAjSyFAAAAAI10JgCLRCQkhcB+XosEJItcJBgx/400hQAAAAAB8wN0JByDfCQ
  8851. oAXRjjXYAixOLBg+2TCQw0/iJ0cHpGA+2wI2ECAH///+5AAAAAIXAD0jBgeL///8Ag8cBAe7B4BgJwokTAes5fCQkdcKDBCQBiwQkOUQkIHWNg8QEuAEAAABbXl9dw420JgAAAACQixOLBg+2TCQw0/iJ0cHpGA+2wI2ECAH///+5AAAAAIXAD0jBuf8A
  8852. AACB4v///wAB7oPHASnBicjB4BgJwokTAes5fCQkdbnrlYN8JCwBx0QkMAgAAAAPhfr+//+LTCQghcl+hzH/i0QkIItsJCSJPCSLTCQwjTSFAAAAAI10JgCF7X42g3wkKAGLBCR0Sot8JByNFIUAAAAAMdsB1wNUJBiNtCYAAAAAiweDwwEB99P4iEIDA
  8853. fI53XXugwQkAYsEJDlEJCB1uYPEBLgBAAAAW15fXcONdCYAi1wkHMHgAjHSAcMDRCQYiceNtCYAAAAAiwODwgEB89P499CIRwMB9znVdeyDBCQBiwQkOUQkIA+Fa////+uwx0QkMBAAAADpJ/7//8dEJDAAAAAA6Rr+//8=
  8854. )"
  8855.  
  8856. ; FileRead, base64enc, E:\Sucan twins\_small-apps\AutoHotkey\other scripts\MCode4GCC-master\temp-mcode.txt
  8857. mCodeFunc := Gdip_RunMCode(base64enc)
  8858. }
  8859.  
  8860. ; thisStartZeit := A_TickCount
  8861. Gdip_GetImageDimensions(pBitmap, w, h)
  8862. Gdip_GetImageDimensions(pBitmapMask, w2, h2)
  8863. If (w2!=w || h2!=h || !pBitmap || !pBitmapMask)
  8864. Return 0
  8865.  
  8866. E1 := Gdip_LockBits(pBitmap, 0, 0, w, h, stride, iScan, iData)
  8867. E2 := Gdip_LockBits(pBitmapMask, 0, 0, w, h, stride, mScan, mData)
  8868. If (!E1 && !E2)
  8869. r := DllCall(mCodeFunc, "UPtr", iScan, "UPtr", mScan, "Int", w, "Int", h, "Int", invertAlphaMask, "Int", replaceSourceAlphaChannel, "Int", whichChannel)
  8870.  
  8871. If !E1
  8872. Gdip_UnlockBits(pBitmap, iData)
  8873. If !E2
  8874. Gdip_UnlockBits(pBitmapMask, mData)
  8875. ; ToolTip, % A_TickCount - thisStartZeit, , , 2
  8876. return r
  8877. }
  8878.  
  8879. Gdip_BlendBitmaps(pBitmap, pBitmap2Blend, blendMode) {
  8880. /*
  8881. pBitmap and pBitmap2Blend must be the same width and height
  8882. and in 32-ARGB format: PXF32ARGB - 0x26200A.
  8883.  
  8884. Original code:
  8885. int blendBitmaps(int *bgrImageData, int *otherData, int w, int h, int blendMode) {
  8886. float rT, gT, bT; // these must be INT for x32, to not crashes
  8887. int rO, gO, bO, rB, gB, bB;
  8888. unsigned char rF, gF, bF, aB, aO, aX;
  8889. for (int x = 0; x < w; x++)
  8890. {
  8891. for (int y = 0; y < h; y++)
  8892. {
  8893. unsigned int BGRcolor = bgrImageData[x+(y*w)];
  8894. if (BGRcolor!=0x0)
  8895. {
  8896. unsigned int colorO = otherData[x+(y*w)];
  8897. aO = (colorO >> 24) & 0xFF;
  8898. aB = (BGRcolor >> 24) & 0xFF;
  8899. aX = (aO<aB) ? aO : aB;
  8900. if (aX<1)
  8901. {
  8902. bgrImageData[x+(y*w)] = 0;
  8903. continue;
  8904. }
  8905.  
  8906. rO = (colorO >> 16) & 0xFF;
  8907. gO = (colorO >> 8) & 0xFF;
  8908. bO = colorO & 0xFF;
  8909.  
  8910. rB = (BGRcolor >> 16) & 0xFF;
  8911. gB = (BGRcolor >> 8) & 0xFF;
  8912. bB = BGRcolor & 0xFF;
  8913.  
  8914. if (blendMode==1) { // darken
  8915. rT = (rO < rB) ? rO : rB;
  8916. gT = (gO < gB) ? gO : gB;
  8917. bT = (bO < bB) ? bO : bB;
  8918. } else if (blendMode==2) { // multiply
  8919. rT = (rO * rB)/255;
  8920. gT = (gO * gB)/255;
  8921. bT = (bO * bB)/255;
  8922. } else if (blendMode==3) { // linear burn
  8923. rT = ((rO + rB - 255) < 0) ? 0 : rO + rB - 255;
  8924. gT = ((gO + gB - 255) < 0) ? 0 : gO + gB - 255;
  8925. bT = ((bO + bB - 255) < 0) ? 0 : bO + bB - 255;
  8926. } else if (blendMode==4) { // color burn
  8927. rT = (255 - ((255 - rB) * 255) / (1 + rO) < 1) ? 0 : 255 - ((255 - rB) * 255) / (1 + rO);
  8928. gT = (255 - ((255 - gB) * 255) / (1 + gO) < 1) ? 0 : 255 - ((255 - gB) * 255) / (1 + gO);
  8929. bT = (255 - ((255 - bB) * 255) / (1 + bO) < 1) ? 0 : 255 - ((255 - bB) * 255) / (1 + bO);
  8930. } else if (blendMode==5) { // lighten
  8931. rT = (rO > rB) ? rO : rB;
  8932. gT = (gO > gB) ? gO : gB;
  8933. bT = (bO > bB) ? bO : bB;
  8934. } else if (blendMode==6) { // screen
  8935. rT = 255 - (((255 - rO) * (255 - rB))/255);
  8936. gT = 255 - (((255 - gO) * (255 - gB))/255);
  8937. bT = 255 - (((255 - bO) * (255 - bB))/255);
  8938. } else if (blendMode==7) { // linear dodge [add]
  8939. rT = ((rO + rB) > 255) ? 255 : rO + rB;
  8940. gT = ((gO + gB) > 255) ? 255 : gO + gB;
  8941. bT = ((bO + bB) > 255) ? 255 : bO + bB;
  8942. } else if (blendMode==8) { // hard light
  8943. rT = (rO < 127) ? (2 * rO * rB)/255 : 255 - ((2 * (255 - rO) * (255 - rB))/255);
  8944. gT = (gO < 127) ? (2 * gO * gB)/255 : 255 - ((2 * (255 - gO) * (255 - gB))/255);
  8945. bT = (bO < 127) ? (2 * bO * bB)/255 : 255 - ((2 * (255 - bO) * (255 - bB))/255);
  8946. } else if (blendMode==9) { // overlay
  8947. rT = (rB < 127) ? (2 * rO * rB)/255 : 255 - ((2 * (255 - rO) * (255 - rB))/255);
  8948. gT = (gB < 127) ? (2 * gO * gB)/255 : 255 - ((2 * (255 - gO) * (255 - gB))/255);
  8949. bT = (bB < 127) ? (2 * bO * bB)/255 : 255 - ((2 * (255 - bO) * (255 - bB))/255);
  8950. } else if (blendMode==10) { // hard mix
  8951. rT = (rO <= (255 - rB)) ? 0 : 255;
  8952. gT = (gO <= (255 - gB)) ? 0 : 255;
  8953. bT = (bO <= (255 - bB)) ? 0 : 255;
  8954. } else if (blendMode==11) { // linear light
  8955. rT = ((rB + (2*rO) - 255) > 254) ? 255 : rB + (2*rO) - 255;
  8956. gT = ((gB + (2*gO) - 255) > 254) ? 255 : gB + (2*gO) - 255;
  8957. bT = ((bB + (2*bO) - 255) > 254) ? 255 : bB + (2*bO) - 255;
  8958. } else if (blendMode==12) { // color dodge
  8959. rT = ((rB * 255) / (256 - rO) > 255) ? 255 : (rB * 255) / (256 - rO);
  8960. gT = ((gB * 255) / (256 - gO) > 255) ? 255 : (gB * 255) / (256 - gO);
  8961. bT = ((bB * 255) / (256 - bO) > 255) ? 255 : (bB * 255) / (256 - bO);
  8962. } else if (blendMode==13) { // vivid light
  8963. if (rO < 128)
  8964. rT = (255 - ((255 - rB) * 255) / (1 + 2*rO) < 1) ? 0 : 255 - ((255 - rB) * 255) / (1 + 2*rO);
  8965. else
  8966. rT = ((rB * 255) / (2*(256 - rO)) > 255) ? 255 : (rB * 255) / (2*(256 - rO));
  8967.  
  8968. if (gO < 128)
  8969. gT = (255 - ((255 - gB) * 255) / (1 + 2*gO) < 1) ? 0 : 255 - ((255 - gB) * 255) / (1 + 2*gO);
  8970. else
  8971. gT = ((gB * 255) / (2*(256 - gO)) > 255) ? 255 : (gB * 255) / (2*(256 - gO));
  8972.  
  8973. if (bO < 128)
  8974. bT = (255 - ((255 - bB) * 255) / (1 + 2*bO) < 1) ? 0 : 255 - ((255 - bB) * 255) / (1 + 2*bO);
  8975. else
  8976. bT = ((bB * 255) / (2*(256 - bO)) > 255) ? 255 : (bB * 255) / (2*(256 - bO));
  8977.  
  8978. } else if (blendMode==14) { // division
  8979. rT = ((rB * 255) / (1 + rO) > 255) ? 255 : (rB * 255) / (1 + rO);
  8980. gT = ((gB * 255) / (1 + gO) > 255) ? 255 : (gB * 255) / (1 + gO);
  8981. bT = ((bB * 255) / (1 + bO) > 255) ? 255 : (bB * 255) / (1 + bO);
  8982. } else if (blendMode==15) { // exclusion
  8983. rT = rO + rB - 2*((rO * rB)/255);
  8984. gT = gO + gB - 2*((gO * gB)/255);
  8985. bT = bO + bB - 2*((bO * bB)/255);
  8986. } else if (blendMode==16) { // difference
  8987. rT = (rO > rB) ? rO - rB : rB - rO;
  8988. gT = (gO > gB) ? gO - gB : gB - gO;
  8989. bT = (bO > bB) ? bO - bB : bB - bO;
  8990. } else if (blendMode==17) { // substract
  8991. rT = ((rB - rO) <= 0) ? 0 : rB - rO;
  8992. gT = ((gB - gO) <= 0) ? 0 : gB - gO;
  8993. bT = ((bB - bO) <= 0) ? 0 : bB - bO;
  8994. } else if (blendMode==18) { // inverted difference
  8995. rT = (rO > rB) ? 255 - rO - rB : 255 - rB - rO;
  8996. gT = (gO > gB) ? 255 - gO - gB : 255 - gB - gO;
  8997. bT = (bO > bB) ? 255 - bO - bB : 255 - bB - bO;
  8998. }
  8999.  
  9000. if (blendMode!=10) {
  9001. if (rT<0)
  9002. rT += 255;
  9003. if (gT<0)
  9004. gT += 255;
  9005. if (bT<0)
  9006. bT += 255;
  9007.  
  9008. if (rT<0)
  9009. rT = 0;
  9010. if (gT<0)
  9011. gT = 0;
  9012. if (bT<0)
  9013. bT = 0;
  9014. }
  9015.  
  9016. rF = rT;
  9017. gF = gT;
  9018. bF = bT;
  9019. bgrImageData[x+(y*w)] = (aX << 24) | ((rF & 0xFF) << 16) | ((gF & 0xFF) << 8) | (bF & 0xFF);
  9020. }
  9021. }
  9022. }
  9023. return 1;
  9024. }
  9025. */
  9026.  
  9027. static mCodeFunc := 0
  9028. if (mCodeFunc=0)
  9029. {
  9030. if (A_PtrSize=8)
  9031. base64enc := "
  9032. (LTrim Join
  9033. 2,x64:QVdBVkFVQVRVV1ZTSIHsiAAAAA8pdCQgDyl8JDBEDylEJEBEDylMJFBEDylUJGBEDylcJHBEi6wk8AAAAEiJlCTYAAAASInORYXAD46XBAAARYXJD46OBAAAQY1A/01jwGYP7+TzDxA9AAAAAEiJRCQQRA8o3EQPKNRFic5OjSSFAAAAAEQPKM9EDyjHSMdEJAgAAAAASItEJAhNiedmkGYP7/ZMjQSFAAAAAEUx0g8o7mYPH0QAAEKLDAaFyQ+E5QEAAEiLhCTYAAAAQYnJQcHpGEKLHACJ2MHoGE
  9034. E4wUQPQ8hFhMkPhPQBAACJ2InaD7btRA+228HoCMHqEIlEJBgPtscPtvpBicSJyA+2ycHoEA+2wEGD/QEPhAEBAABBg/0CD4QHAgAAQYP9Aw+EnQIAAEGD/QQPhPMCAABBg/0FD4RhAwAAQYP9Bg+E1wMAAEGD/QcPhJQEAABBg/0ID4TPBAAAQYP9CQ+ETAUAAEGD/QoPhEUGAABBg/0LD4RnBwAAQYP9DA+E6gYAAEGD/Q0PhMkHAABBg/0OD4T5CAAAQYP9Dw+EXQgAAEGD/RAPhKgJAABBg/0RD4TYCQ
  9035. AAQYP9Eg+FqQEAALr/AAAAOccPjkUKAAAp+mYP78kpwvMPKsq4/wAAAEE57A+OGQoAAEQp4GYP79Ip6PMPKtC4/wAAAEE5yw+O7AkAAEQp2GYP78ApyPMPKsDpVQEAAA8fADnHD42YAQAAZg/vyfMPKs9BOewPjXcBAABmD+/S80EPKtRBOcsPjU0BAABmD+/AZg/v2/NBDyrDDy/YdgTzD1jHDy/ZD4eWAAAA8w8swQ+2wMHgEA8v2onCD4ePAAAA8w8s2g+228HjCA8v2A+HigAAAPMPLMAPtsAJ0EHB4R
  9036. hBCcFBCdlGiQwGQYPCAU0B+EU51g+F//3//0iLfCQISI1HAUg5fCQQD4QbAgAASIlEJAjpyf3//2YPH4QAAAAAAEGDwgFCxwQGAAAAAE0B+EU51g+FwP3//+u/Zg8fRAAAMdIPL9oPKMsPhnH///8x2w8v2A8o0w+Gdv///zHADyjD6XP///9mLg8fhAAAAAAAD6/4Zg/vyWYP79JBD6/sZg/vwEEPr8uJ+L+BgICASA+vx0gPr+9ID6/PSMHoJ0jB7SfzDyrISMHpJ/MPKtXzDyrBDy/hDyjcdgXzQQ9YyQ
  9037. 8v2g+G0P7///NBD1jQ6cb+//9mDx9EAABmD+/ADyjd8w8qwemw/v//Dx+EAAAAAABmD+/S8w8q1emF/v//Dx8AZg/vyfMPKsjpY/7//w8fAAHHZg/vyWYP79K6/wAAAIH//wAAAGYP78APTPpEAeWB7/8AAACB/f8AAAAPTOrzDyrPRAHZge3/AAAAgfn/AAAAD0zK8w8q1YHp/wAAAPMPKsHpS////2YPH4QAAAAAALv/AAAAZg/vyWYP79KDxwGJ2mYP78APKN4pwonQweAIKdCZ9/+J2jH/KcKJ0InaD0
  9038. jHKepBjWwkAfMPKsiJ0MHgCCnQmff9idopwonQidoPSMcpykGDwwHzDyrQidDB4Agp0JlB9/spww9I3/MPKsPpxf3//w8fADnHD44yAQAAZg/vyfMPKs9BOewPjhQBAABmD+/S80EPKtRBOcsPjvEAAABmD+/AZg/v2/NBDyrD6Zr+//8PHwAPKHQkIA8ofCQwuAEAAABEDyhEJEBEDyhMJFBEDyhUJGBEDyhcJHBIgcSIAAAAW15fXUFcQV1BXkFfww8fRAAAuv8AAABmD+/JZg/v0onTKfuJ1ynHifgPr8
  9039. NIY9hIaduBgICASMHrIAHDwfgfwfsHKdiJ0wX/AAAARCnj8w8qyInQKegPr8NIY9hIaduBgICASMHrIAHDwfgfwfsHKdgF/wAAAPMPKtCJ0CnKRCnYD6/CSGPQZg/vwEhp0oGAgIBIweogAcLB+B/B+gcp0AX/AAAA8w8qwOmu/f//Zg/vwEEPKNrzDyrB6ar9//9mD+/S8w8q1eno/v//Zg/vyfMPKsjpyf7//2YP78lmD+/SZg/vwAHHgf//AAAAuP8AAAAPT/hEAeWB/f8AAAAPT+jzDyrPRAHZgfn/AA
  9040. AAD0/I8w8q1fMPKsHpPv3//4P/fg+PRgEAAA+vx7+BgICAZg/vyQHASA+vx0jB6CfzDyrIQYP8fg+P5gAAAEEPr+y/gYCAgGYP79KNRC0ASA+vx0jB6CfzDyrQQYP7fn8hQQ+vy7+BgICAZg/vwI0ECUgPr8dIwegn8w8qwOnN/P//uv8AAACJ0CnKRCnYD6/CAcDp3/7//4P4fg+OVQEAALr/AAAAZg/vyYnTKcIp+w+v040EEkhj0Ehp0oGAgIBIweogAcLB+B/B+gcp0AX/AAAA8w8qyIP9fg+POQEAAE
  9041. SJ4L+BgICAZg/v0g+vxQHASA+vx0jB6CfzDyrQg/l+f4BEidi/gYCAgGYP78APr8EBwEgPr8dIwegn8w8qwOkr/P//uv8AAABmD+/SidAp6kQp4A+v0I0EEkhj0Ehp0oGAgIBIweogAcLB+B/B+gcp0AX/AAAA8w8q0On7/v//uv8AAABmD+/JidMpwin7D6/TjQQSSGPQSGnSgYCAgEjB6iABwsH4H8H6BynQBf8AAADzDyrI6Zn+//+6/wAAACnCOfoPjYgBAADzDxANAAAAALoAAP8AuP8AAAAp6EQ54A
  9042. +NYAEAAPMPEBUAAAAAuwD/AAC4/wAAACnIRDnYD404AQAA8w8QBQAAAAC4/wAAAOmA+v//D6/Hv4GAgIBmD+/JAcBID6/HSMHoJ/MPKsiD/X4Pjsf+//+4/wAAAGYP79KJwinoRCniD6/CAcBIY9BIadKBgICASMHqIAHCwfgfwfoHKdAF/wAAAPMPKtDpqf7//4nCZg/vyWYP79K7AAEAAMHiCCn7Zg/vwL8AAQAAKcKJ0Jn3+7v/AAAAPf8AAAAPT8NEKedBvAABAADzDyrIiejB4Agp6Jn3/z3/AAAAD0
  9043. /DRSnc8w8q0InIweAIKciZQff8Pf8AAAAPT8PzDyrA6Yj6//+NBHhmD+/JZg/v0rr+AQAAPf4BAABmD+/AD0/CLf8AAADzDyrIQo1EZQA9/gEAAA9Pwi3/AAAA8w8q0EKNBFk9/gEAAA9Pwi3/AAAA8w8qwOkz+v//McBmD+/A6U/5//8x22YP79Lpov7//zHSZg/vyel6/v//geKAAAAAiVQkHA+E+AAAAInCZg/vycHiCCnCuAABAAAp+I08AInQmff/uv8AAAA9/wAAAA9PwvMPKsiBZCQYgAAAAA+Fhg
  9044. EAAL//AAAAZg/v0on6KeqJ1cHlCInoQ41sJAEp0Jn3/SnHD0h8JBjzDyrXgeOAAAAAD4UjAQAAv/8AAABmD+/AifopykONTBsBidDB4Agp0Jn3+SnHD0j78w8qx+lq+f//jRQHZg/vyWYP79IPr8e/gYCAgGYP78BID6/HSMHoJwHAKcJEieAPr8XzDyrKQY0ULEgPr8dIwegnAcApwkSJ2A+vwfMPKtJBjRQLSA+vx0jB6CcBwCnC8w8qwukK+f//uv8AAACNfD8BZg/vySnCidDB4ggpwonQmff/v/8AAA
  9045. Apx4n4D0hEJBzzDyrI6QH///+JwoPHAWYP78m7/wAAAMHiCGYP79JmD+/AKcKJ0Jn3/0GNfCQBPf8AAAAPT8PzDyrIiejB4Agp6Jn3/z3/AAAAD0/DQYPDAfMPKtCJyMHgCCnImUH3+z3/AAAAD0/D8w8qwOlx+P//ichmD+/AweAIKci5AAEAAEQp2ZkByff5uv8AAAA9/wAAAA9PwvMPKsDpQ/j//4novwABAABmD+/SweAIRCnnKegB/5n3/7r/AAAAPf8AAAAPT8LzDyrQ6XX+//85xw+OgwAAACnHZg
  9046. /vyfMPKs9BOex+Z0SJ4GYP79Ip6PMPKtBBOct+RUEpy2YP78DzQQ8qw+nb9///Zg/vyWYP79JmD+/AMdIp+EEPKNsPSMJEKeUPSOpEKdnzDyrID0jK8w8q1fMPKsHpn/b//0Qp2WYP78DzDyrB6Zf3//9EKeVmD+/S8w8q1euZKfhmD+/J8w8qyOl4////KchmD+/ARCnY8w8qwOlp9///KehmD+/SRCng8w8q0Oni9f//KcJmD+/JidAp+PMPKsjptPX//5CQAAB/Qw==
  9047. )"
  9048. else
  9049. base64enc := "
  9050. (LTrim Join
  9051. 2,x86:VVdWU4PsMItcJEyF2w+OdAIAAItUJFCF0g+OaAIAAItEJEzHRCQkAAAAAMHgAolEJAiNtgAAAACLRCQki3QkRIlMJAQx/4n9weACAcYDRCRIiQQkjXQmAIsOhckPhPgBAACLBCSJz8HvGIsYifqJ2MHoGDjCD0LHiEQkFITAD4QUAgAAidqJz4nYweoIwe8QiVQkLA+218HoEIN8JFQBiVQkGA+204lUJByJ+g+2+g+21YlEJCgPtsmJVCQgD7bAD4QSAQAAg3wkVAIPhM8BAACDfCRUAw+EBAIAAI
  9052. N8JFQED4RRAgAAg3wkVAUPhM4CAACDfCRUBg+E8wIAAIN8JFQHD4R8AwAAg3wkVAgPhLoDAACDfCRUCQ+EfwQAAIN8JFQKD4RYBQAAg3wkVAsPhH4GAACDfCRUDA+EAAYAAIN8JFQND4TABgAAg3wkVA4PhPIHAACDfCRUDw+EWwcAAIN8JFQQD4R3CAAAg3wkVBEPhLAIAACDfCRUEg+FuAMAADn4D470CAAAu/8AAAApw4nYKfiJRCQMi1wkGIt8JCC4/wAAADn7D46/CAAAKdgp+IlEJBCLRCQcuv8AAA
  9053. A5yA+OlwgAACnCKcqJVCQE6VYDAACNdCYAkItcJBg5+A9O+InQOdMPTsOJfCQMiUQkEItEJBw5yInCD0/RiVQkBItcJAy4AAAAAItMJAS/AAAAAIXbD0nDi1wkEIXbiUQkDA9J+7sAAAAAhcmJ2g9J0cHgEIl8JBCJw8HnCIlUJAQPtsqB4wAA/wAPt/+LRCQUCdnB4BgJwQn5iQ6LRCQIg8UBAQQkAcY5bCRQD4Xo/f//g0QkJAGLTCQEi0QkJDlEJEwPhbH9//+DxDC4AQAAAFteX13DjXQmAMcGAAAAAO
  9054. u6D6/4u4GAgIAPr0wkHIn49+PB6geJVCQMi1QkGA+vVCQgidD344nIweoHiVQkEPfjweoHiVQkBOkj////jXQmAAHHuP8AAACLVCQYgf//AAAAD0z4A1QkIIH6/wAAAA9M0ANMJByNnwH///+B+f8AAACJXCQMD0zIjZoB////iVwkEI2BAf///4lEJATpzv7//420JgAAAAC6/wAAACn6idPB4wgp04najVgBidCZ9/u7/wAAALr/AAAAKcO4AAAAAA9JwytUJCCLXCQYiUQkDInQg8MBweAIKdCZ9/u7/w
  9055. AAALr/AAAAKcO4AAAAAA9JwynKi0wkHIlEJBCJ0IPBAcHgCCnQmff5uv8AAAApwrgAAAAAD0nCiUQkBOk//v//OfiLXCQYD034i0QkIDnDiXwkDA9Nw4lEJBCLRCQcOciJwg9M0YlUJATpEf7//2aQuv8AAAC7gYCAgCnCuP8AAAAp+InXD6/4ifj364n4wfgfAfrB+gcp0Lr/AAAAK1QkGAX/AAAAideJRCQMuP8AAAArRCQgD6/4ifj364n4wfgfAfrB+gcp0Lr/AAAAK1QkHAX/AAAAiUQkELj/AAAAKc
  9056. iJ0Q+vyInI9+uNHArB+R/B+wcp2Y2B/wAAAIlEJATpe/3//wH4u/8AAACLVCQcPf8AAAAPTtiLRCQYA0QkID3/AAAAiVwkDLv/AAAAD07YAcq4/wAAAIH6/wAAAA9OwolcJBCJRCQE6TL9//+D+H4Pj3QBAAAPr/i6gYCAgI0EP/fiweoHiVQkDItEJBiD+H4PjxgBAAAPr0QkILqBgICAAcD34sHqB4lUJBCLRCQcg/h+f08Pr8iNBAm6gYCAgPfiweoHiVQkBItEJAyFwHkIgUQkDP8AAACLRCQQhcB5CQ
  9057. X/AAAAiUQkEItEJASFwA+Jqfz//wX/AAAAiUQkBOmb/P//uv8AAAC4/wAAACtUJBwpyInRuoGAgIAPr8gByYnI9+qNBArB+R/B+AeJyinCjYL/AAAAiUQkBOuMg/9+D44+AQAAuv8AAAApwrj/AAAAKfgPr8K6gYCAgI0cAInY9+qJ2MH4HwHai1wkIMH6BynQBf8AAACJRCQMg/t+D48fAQAAi0QkGLqBgICAD6/DAcD34sHqB4lUJBCD+X4Pj1////8Pr0wkHOkJ////uv8AAAC4/wAAACtUJBgrRCQgD6
  9058. /CuoGAgICNHACJ2PfqidjB+B8B2sH6BynQBf8AAACJRCQQ6cL+//+6/wAAACnCuP8AAAAp+A+vwrqBgICAjRwAidj36onYwfgfAdrB+gcp0AX/AAAAiUQkDOlp/v//uv8AAAC7AAD/ACn6vwAAAAA5wrj/AAAAifoPTccPTd+/AP8AAIlEJAy4/wAAACtEJCA7RCQYuP8AAAAPTcIPTfqJRCQQuP8AAAApyDtEJBy4/wAAAA9NwolEJASJweln+///D6/HuoGAgICLXCQgAcD34sHqB4lUJAyD+34PjuH+//
  9059. +6/wAAALj/AAAAK1QkGCtEJCAPr8K6gYCAgI0cAInY9+qJ2MH4HwHawfoHKdAF/wAAAIlEJBDpvf7//4n6uwABAADB4ggp+onfKceJ0Jn3/7//AAAAido9/wAAAA9Px4t8JCArVCQYiUQkDIn4weAIKfiJ15n3/7//AAAAPf8AAAAPT8eJRCQQicjB4AgpyInZK0wkHJn3+br/AAAAPf8AAAAPTtCJVCQE6U36//+NFEe4/gEAAIt8JBiB+v4BAAAPT9CNmgH///+JXCQMi1wkII0Ue4H6/gEAAA9P0I2aAf
  9060. ///4lcJBCLXCQcjRRZgfr+AQAAD0/QjYIB////iUQkBOkf/f//i1QkKIHigAAAAIlUJAQPhPsAAACJ+sHiCCn6vwABAAApx4nQjTw/mff/v/8AAAA9/wAAAA9Px4lEJAyLfCQsgeeAAAAAD4VdAQAAuv8AAAArVCQgidDB4Agp0A+2141UEgGJVCQEmfd8JAS6/wAAACnCD0n6iXwkEIHjgAAAAA+FDAEAALr/AAAAKcqLTCQcidDB4AiNTAkBKdCZ9/m6/wAAACnCD0naiVwkBOlE+f//jRw4D6/HiVwkBL
  9061. uBgICAi3wkBPfjidCLVCQgwegHAcApx4tEJBiJfCQMiccPr8IB1/fjidDB6AcBwCnHi0QkHIl8JBCNPAgPr8H344nQwegHAcApx4l8JATpEPz//7r/AAAAKfqJ18HiCCn6jXwAAYnQmff/v/8AAAApx4tEJAQPSceJRCQM6f7+//+J+o1YAcHiCCn6v/8AAACJ0Jn3+4tcJCA9/wAAAA9Px4lEJAyJ2MHgCCnYi1wkGJmDwwH3+z3/AAAAD0/HiUQkEInIweAIKciLTCQcg8EB6f79//+JyMHgCCnIuQABAA
  9062. ArTCQcAcnp5/3//4t8JCC6AAEAACtUJBiJ+MHgCCn4jTwSmff/v/8AAAA9/wAAAA9Px4lEJBDpof7//4nCifspwyn6OfiLfCQgD07Ti1wkGIlUJAyJ2In6Kdop+Dn7i1wkHA9OwonKKdqJRCQQidgpyDnLD07CiUQkBOkD+///Kce4AAAAALsAAAAAD0nHiUQkDItEJCArRCQYD0nYK0wkHLgAAAAAD0nBiVwkEIlEJATpovf//ynKK1QkHIlUJATpvfr//ytEJCArRCQYiUQkEOk49///uv8AAAAp+inCiV
  9063. QkDOkJ9///
  9064. )"
  9065. ; FileRead, base64enc, E:\Sucan twins\_small-apps\AutoHotkey\other scripts\MCode4GCC-master\temp-mcode.txt
  9066.  
  9067. mCodeFunc := Gdip_RunMCode(base64enc)
  9068. }
  9069.  
  9070. Gdip_GetImageDimensions(pBitmap, w, h)
  9071. Gdip_GetImageDimensions(pBitmap2Blend, w2, h2)
  9072. If (w2!=w || h2!=h || !pBitmap || !pBitmap2Blend)
  9073. Return 0
  9074.  
  9075. E1 := Gdip_LockBits(pBitmap, 0, 0, w, h, stride, iScan, iData)
  9076. E2 := Gdip_LockBits(pBitmap2Blend, 0, 0, w, h, stride, mScan, mData)
  9077. ; thisStartZeit := A_TickCount
  9078. If (!E1 && !E2)
  9079. r := DllCall(mCodeFunc, "UPtr", iScan, "UPtr", mScan, "Int", w, "Int", h, "Int", blendMode)
  9080. ; ToolTip, % "mcode == " A_TickCount - thisStartZeit, , , 2
  9081. ; ToolTip, % r " = r" , , , 2
  9082. If !E1
  9083. Gdip_UnlockBits(pBitmap, iData)
  9084. If !E2
  9085. Gdip_UnlockBits(pBitmap2Blend, mData)
  9086. return r
  9087. }
  9088.  
  9089.  
  9090. Gdip_BoxBlurBitmap(pBitmap, passes) {
  9091. ; the blur will be applied on the provided pBitmap
  9092. /*
  9093. C/C++ function by Tic:
  9094. https://autohotkey.com/board/topic/29449-gdi-standard-library-145-by-tic/page-30
  9095.  
  9096. void BoxBlurBitmap(unsigned char * Bitmap, int w, int h, int Stride, int Passes)
  9097. {
  9098. int A1, R1, G1, B1, A2, R2, G2, B2, A3, R3, G3, B3;
  9099. for (int i = 0; i < Passes; ++i)
  9100. {
  9101. for (int y = 0; y < h*Stride; y += Stride)
  9102. {
  9103. A1 = R1 = G1 = B1 = A2 = R2 = G2 = B2 = 0;
  9104. for (int x = 0 ; x < w; ++x)
  9105. {
  9106. A3 = Bitmap[3+(4*x)+y];
  9107. R3 = Bitmap[2+(4*x)+y];
  9108. G3 = Bitmap[1+(4*x)+y];
  9109. B3 = Bitmap[(4*x)+y];
  9110.  
  9111. Bitmap[3+(4*x)+y] = (A1+A2+A3)/3;
  9112. Bitmap[2+(4*x)+y] = (R1+R2+R3)/3;
  9113. Bitmap[1+(4*x)+y] = (G1+G2+G3)/3;
  9114. Bitmap[(4*x)+y] = (B1+B2+B3)/3;
  9115.  
  9116. A1 = A2; R1 = R2; G1 = G2; B1 = B2; A2 = A3; R2 = R3; G2 = G3; B2 = B3;
  9117. }
  9118.  
  9119. A1 = R1 = G1 = B1 = A2 = R2 = G2 = B2 = 0;
  9120. for (int x = w-1 ; x >= 0; --x)
  9121. {
  9122. A3 = Bitmap[3+(4*x)+y];
  9123. R3 = Bitmap[2+(4*x)+y];
  9124. G3 = Bitmap[1+(4*x)+y];
  9125. B3 = Bitmap[(4*x)+y];
  9126.  
  9127. Bitmap[3+(4*x)+y] = (A1+A2+A3)/3;
  9128. Bitmap[2+(4*x)+y] = (R1+R2+R3)/3;
  9129. Bitmap[1+(4*x)+y] = (G1+G2+G3)/3;
  9130. Bitmap[(4*x)+y] = (B1+B2+B3)/3;
  9131.  
  9132. A1 = A2; R1 = R2; G1 = G2; B1 = B2; A2 = A3; R2 = R3; G2 = G3; B2 = B3;
  9133. }
  9134. }
  9135.  
  9136. for (int x = 0; x < w; ++x)
  9137. {
  9138. A1 = R1 = G1 = B1 = A2 = R2 = G2 = B2 = 0;
  9139. for (int y = 0; y < h*Stride; y += Stride)
  9140. {
  9141. A3 = Bitmap[3+(4*x)+y];
  9142. R3 = Bitmap[2+(4*x)+y];
  9143. G3 = Bitmap[1+(4*x)+y];
  9144. B3 = Bitmap[(4*x)+y];
  9145.  
  9146. Bitmap[3+(4*x)+y] = (A1+A2+A3)/3;
  9147. Bitmap[2+(4*x)+y] = (R1+R2+R3)/3;
  9148. Bitmap[1+(4*x)+y] = (G1+G2+G3)/3;
  9149. Bitmap[(4*x)+y] = (B1+B2+B3)/3;
  9150.  
  9151. A1 = A2; R1 = R2; G1 = G2; B1 = B2; A2 = A3; R2 = R3; G2 = G3; B2 = B3;
  9152. }
  9153.  
  9154. A1 = R1 = G1 = B1 = A2 = R2 = G2 = B2 = 0;
  9155. for (int y = (h-1)*Stride; y >= 0; y -= Stride)
  9156. {
  9157. A3 = Bitmap[3+(4*x)+y];
  9158. R3 = Bitmap[2+(4*x)+y];
  9159. G3 = Bitmap[1+(4*x)+y];
  9160. B3 = Bitmap[(4*x)+y];
  9161.  
  9162. Bitmap[3+(4*x)+y] = (A1+A2+A3)/3;
  9163. Bitmap[2+(4*x)+y] = (R1+R2+R3)/3;
  9164. Bitmap[1+(4*x)+y] = (G1+G2+G3)/3;
  9165. Bitmap[(4*x)+y] = (B1+B2+B3)/3;
  9166.  
  9167. A1 = A2; R1 = R2; G1 = G2; B1 = B2; A2 = A3; R2 = R3; G2 = G3; B2 = B3;
  9168. }
  9169. }
  9170. }
  9171. }
  9172.  
  9173. */
  9174.  
  9175. static mCodeFunc := 0
  9176. if (mCodeFunc=0)
  9177. {
  9178.  
  9179. if (A_PtrSize=8)
  9180. base64enc := "
  9181. (LTrim Join
  9182. 2,x64:QVdBVkFVQVRVV1ZTSIPsWESLnCTAAAAASImMJKAAAABEicCJlCSoAAAARImMJLgAAABFhdsPjtoDAABEiceD6AHHRCQ8AAAAAEG+q6qqqkEPr/lBD6/BiXwkBInXg+8BiUQkJIn4iXwkOEiNdIEESPfYSIl0JEBIjTSFAAAAAI0EvQAAAABJY/lImEiJdCRISI1EBvxIiXwkCEiJRCQwRInI99hImEiJRCQQDx9EAABIi0QkQMdEJCAAAAAASIlEJBhIi0QkSEiD6ARIiUQkKItEJASFwA+OegEAAA8fQABEi4wkqAAAAEWFyQ+OPwMAAEiLRCQoTIt8JBgx9jHbRTHbRTHSRTHJRTHATAH4Mckx0mYPH0QAAEWJ1UQPtlADRYn
  9183. cRA+2WAJEAepEAeGJ3Q+2WAFEAdJBAeiJ9w+2MEkPr9ZBAflIg8AESMHqIYhQ/0KNFBlEieFJD6/WSMHqIYhQ/kGNFBhBiehJD6/WSMHqIYhQ/UGNFDFBiflJD6/WSMHqIYhQ/ESJ6kw5+HWJi3wkOEiLRCQwMfYx20gDRCQYRTHbRTHSRTHJRTHAMckx0g8fgAAAAABFiddED7ZQA0WJ3UQPtlgCRAH6RAHpQYncD7ZYAUQB0kUB4In1D7YwSQ+v1kEB6YPvAUiD6ARIweohiFAHQo0UGUSJ6UkPr9ZIweohiFAGQY0UGEWJ4EkPr9ZIweohiFAFQY0UMUGJ6UkPr9ZIweohiFAERIn6g///dYWLvCS4AAAASItcJAgBfCQgi0QkIEgB
  9184. XCQYO0QkBA+Miv7//0SLhCSoAAAAx0QkGAMAAADHRCQgAAAAAEWFwA+OiAEAAGYPH4QAAAAAAItUJASF0g+OpAAAAEhjRCQYMf8x9jHbSAOEJKAAAABFMdtFMdIxyUUxyUUxwDHSkEWJ10QPthBFid1ED7ZY/0QB+kQB6UGJ3A+2WP5EAdJFAeCJ9Q+2cP1JD6/WQQHpA7wkuAAAAEjB6iGIEEKNFBlEielJD6/WSMHqIYhQ/0GNFBhFieBJD6/WSMHqIYhQ/kGNFDFBielJD6/WSMHqIYhQ/UgDRCQIRIn6O3wkBHyAi0wkJIXJD4ioAAAATGNUJCRIY0QkGDH/MfYx20Ux20UxyUUxwEwB0DHJSAOEJKAAAAAx0g8fQABFid9ED7YYQ
  9185. YndD7ZY/0QB+kQB6UGJ9A+2cP5EAdpFAeCJ/Q+2eP1JD6/WQQHpSMHqIYgQjRQZSItMJBBJD6/WSQHKSMHqIYhQ/0GNFDBFieBJD6/WSMHqIYhQ/kGNFDlBielJD6/WSMHqIYhQ/UgByESJ+kSJ6UWF0nmEg0QkIAGLRCQgg0QkGAQ5hCSoAAAAD4WB/v//g0QkPAGLRCQ8OYQkwAAAAA+Fm/z//0iDxFhbXl9dQVxBXUFeQV/DZi4PH4QAAAAAAESLVCQ4RYXSD4j1/f//6Uz9//8=
  9186. )"
  9187. else
  9188. base64enc := "
  9189. (LTrim Join
  9190. 2,x86:VVdWU4PsPItsJGCLRCRYhe0PjncEAACLfCRcx0QkNAAAAAAPr/iD6AEPr0QkXIl8JCSLfCRUiUQkLItEJFCD7wGJfCQwi3wkVI0EuIlEJDiLRCQ4x0QkKAAAAACJRCQgi0QkJIXAD47pAQAAjXQmAIt0JFSF9g+OJAQAAMdEJAwAAAAAi0wkKDHtMf/HRCQYAAAAAANMJFAx9jHAx0QkFAAAAADHRCQQAAAAAI10JgCLVCQMD7ZZA4k0JIPBBA+2cf6JfCQEiVQkHAHCD7Z5/QHaiVwkDLurqqqqidCJbCQID7Zp/Pfji1wkEAMcJNHqiFH/idq7q6qqqgHyidD344tcJBQDXCQE0eqIUf6J2rurqqqqAfqJ0Pfj0eqIUf2LVCQ
  9191. YA1QkCAHqidD344scJItEJByJXCQQi1wkBNHqiVwkFItcJAiIUfyJXCQYO0wkIA+FWf///4tEJDDHBCQAAAAAMe0x/8dEJBwAAAAAi0wkIDH2x0QkGAAAAADHRCQUAAAAAIlEJAQxwI22AAAAAIscJA+2Uf+JdCQIg+kED7ZxAol8JAyJFCSNFBgDFCSJ0LqrqqqqD7Z5AYlsJBD34g+2KYNsJAQB0eqIUQOLVCQUA1QkCAHyidC6q6qqqvfi0eqIUQKLVCQYA1QkDAH6idC6q6qqqvfi0eqIUQGLVCQcA1QkEAHqidC6q6qqqvfiidiLXCQIiVwkFItcJAzR6ogRi1QkBIlcJBiLXCQQiVwkHIP6/w+FVf///4t8JFwBfCQoAXwkIItE
  9192. JCg7RCQkD4wb/v//i0QkUItcJFTHRCQoAAAAAPfYiUQkDIXbD44IAgAAjXQmAJCLVCQkhdIPjugAAAAx9otMJAzHRCQIAAAAADHtx0QkGAAAAAAx/zHAx0QkFAAAAAD32cdEJBAAAAAAiTQkjXYAi1QkCA+2cQOJfCQEixwkD7Z5AYlUJCABwgHyiXQkCL6rqqqqidCJXCQcD7ZZAvfmi3QkHItEJBCJHCSJ6w+2KQHwiXQkEIt0JAzR6ohRA4sUJAHCidC6q6qqqvfii0QkFANEJATR6ohRAonCAfqJ0Lqrqqqq9+KLRCQYiVwkGAHY0eqIUQGJwgHqidC6q6qqqvfii0QkINHqiBGLVCQEA0wkXIlUJBSNFDE5VCQkD49M////i0wkL
  9193. IXJD4jrAAAAMfbHRCQQAAAAAItMJCwx7cdEJBwAAAAAK0wkDDH/McDHRCQYAAAAAMdEJBQAAAAAiTQkjXQmAJCLHCSLVCQQiXwkBA+2cQMPtnkBiWwkCIlcJCAPtlkCiXQkEA+2KYkcJInTAcIB8r6rqqqqidD35ot0JCCLRCQUAfCJdCQUi3QkDNHqiFEDixQkAcKJ0Lqrqqqq9+KLRCQYA0QkBNHqiFECicIB+onQuquqqqr34otEJBwDRCQI0eqIUQGJwgHqidC6q6qqqvfiidjR6ogRi1QkBCtMJFyJVCQYi1QkCAHOiVQkHA+JTf///4NEJCgBi0QkKINsJAwEOUQkVA+F/f3//4NEJDQBi0QkNDlEJGAPhcL7//+DxDxbXl9dw4
  9194. 20JgAAAACNdgCLfCQwhf8PiI/9///ppvz//w==
  9195. )"
  9196.  
  9197. mCodeFunc := Gdip_RunMCode(base64enc)
  9198. }
  9199.  
  9200. Gdip_GetImageDimensions(pBitmap,w,h)
  9201. E1 := Gdip_LockBits(pBitmap,0,0,w,h,stride,iScan,iData)
  9202. If E1
  9203. Return
  9204.  
  9205. r := DllCall(mCodeFunc, "UPtr",iScan, "Int",w, "Int",h, "Int",stride, "Int",passes)
  9206. Gdip_UnlockBits(pBitmap,iData)
  9207. ; DllCall("GlobalFree", "ptr", mCodeFunc)
  9208. return r
  9209. }
  9210.  
  9211. Gdip_RunMCode(mcode) {
  9212. static e := {1:4, 2:1}
  9213. , c := (A_PtrSize=8) ? "x64" : "x86"
  9214.  
  9215. if (!regexmatch(mcode, "^([0-9]+),(" c ":|.*?," c ":)([^,]+)", m))
  9216. return
  9217.  
  9218. if (!DllCall("crypt32\CryptStringToBinary", "str", m3, "uint", StrLen(m3), "uint", e[m1], "ptr", 0, "uintp", s, "ptr", 0, "ptr", 0))
  9219. return
  9220.  
  9221. p := DllCall("GlobalAlloc", "uint", 0, "ptr", s, "ptr")
  9222. ; if (c="x64")
  9223. DllCall("VirtualProtect", "ptr", p, "ptr", s, "uint", 0x40, "uint*", op)
  9224.  
  9225. if (DllCall("crypt32\CryptStringToBinary", "str", m3, "uint", StrLen(m3), "uint", e[m1], "ptr", p, "uint*", s, "ptr", 0, "ptr", 0))
  9226. return p
  9227.  
  9228. DllCall("GlobalFree", "ptr", p)
  9229. }
  9230.  
  9231. calcIMGdimensions(imgW, imgH, givenW, givenH, ByRef ResizedW, ByRef ResizedH) {
  9232. ; This function calculates from original imgW and imgH
  9233. ; new image dimensions that maintain the aspect ratio
  9234. ; and are within the boundaries of givenW and givenH.
  9235. ;
  9236. ; imgW, imgH - original image width and height [in pixels]
  9237. ; givenW, givenH - the width and height to adapt to [in pixels]
  9238. ; ResizedW, ResizedH - the width and height resulted from adapting imgW, imgH to givenW, givenH
  9239. ; by keeping the aspect ratio
  9240. ; function initially written by SBC; modified by Marius Șucan
  9241.  
  9242. PicRatio := Round(imgW/imgH, 8)
  9243. givenRatio := Round(givenW/givenH, 8)
  9244. If (imgW<=givenW && imgH<=givenH)
  9245. {
  9246. ResizedW := givenW
  9247. ResizedH := Round(ResizedW / PicRatio)
  9248. If (ResizedH>givenH)
  9249. {
  9250. ResizedH := (imgH <= givenH) ? givenH : imgH
  9251. ResizedW := Round(ResizedH * PicRatio)
  9252. }
  9253. } Else If (PicRatio>givenRatio)
  9254. {
  9255. ResizedW := givenW
  9256. ResizedH := Round(ResizedW / PicRatio)
  9257. } Else
  9258. {
  9259. ResizedH := (imgH >= givenH) ? givenH : imgH
  9260. ResizedW := Round(ResizedH * PicRatio)
  9261. }
  9262. If (ResizedW<1)
  9263. ResizedW := 1
  9264. If (ResizedH<1)
  9265. ResizedH := 1
  9266. }
  9267.  
  9268. GetWindowRect(hwnd, ByRef W, ByRef H) {
  9269. ; function by GeekDude: https://gist.github.com/G33kDude/5b7ba418e685e52c3e6507e5c6972959
  9270. ; W10 compatible function to find a window's visible boundaries
  9271. ; modified by Marius Șucanto return an array
  9272. If !hwnd
  9273. Return
  9274.  
  9275. size := VarSetCapacity(rect, 16, 0)
  9276. er := DllCall("dwmapi\DwmGetWindowAttribute"
  9277. , "UPtr", hWnd ; HWND hwnd
  9278. , "UInt", 9 ; DWORD dwAttribute (DWMWA_EXTENDED_FRAME_BOUNDS)
  9279. , "UPtr", &rect ; PVOID pvAttribute
  9280. , "UInt", size ; DWORD cbAttribute
  9281. , "UInt") ; HRESULT
  9282.  
  9283. If er
  9284. DllCall("GetWindowRect", "UPtr", hwnd, "UPtr", &rect, "UInt")
  9285.  
  9286. r := []
  9287. r.x1 := NumGet(rect, 0, "Int"), r.y1 := NumGet(rect, 4, "Int")
  9288. r.x2 := NumGet(rect, 8, "Int"), r.y2 := NumGet(rect, 12, "Int")
  9289. r.w := Abs(max(r.x1, r.x2) - min(r.x1, r.x2))
  9290. r.h := Abs(max(r.y1, r.y2) - min(r.y1, r.y2))
  9291. W := r.w
  9292. H := r.h
  9293. ; ToolTip, % r.w " --- " r.h , , , 2
  9294. Return r
  9295. }
  9296.  
  9297. Gdip_BitmapConvertGray(pBitmap, hue:=0, vibrance:=-40, brightness:=1, contrast:=0, KeepPixelFormat:=0) {
  9298. ; hue, vibrance, contrast and brightness parameters
  9299. ; influence the resulted new grayscale pBitmap.
  9300. ;
  9301. ; KeepPixelFormat can receive a specific PixelFormat.
  9302. ; The function returns a pointer to a new pBitmap.
  9303.  
  9304. If (pBitmap="")
  9305. Return
  9306.  
  9307. Gdip_GetImageDimensions(pBitmap, Width, Height)
  9308. If (KeepPixelFormat=1)
  9309. PixelFormat := Gdip_GetImagePixelFormat(pBitmap, 1)
  9310. If StrLen(KeepPixelFormat)>3
  9311. PixelFormat := KeepPixelFormat
  9312. Else If (KeepPixelFormat=-1)
  9313. PixelFormat := "0xE200B"
  9314.  
  9315. newBitmap := Gdip_CreateBitmap(Width, Height, PixelFormat)
  9316. G := Gdip_GraphicsFromImage(newBitmap, InterpolationMode)
  9317. If (hue!=0 || vibrance!=0)
  9318. {
  9319. nBitmap := Gdip_CloneBitmap(pBitmap)
  9320. pEffect := Gdip_CreateEffect(6, hue, vibrance, 0)
  9321. Gdip_BitmapApplyEffect(nBitmap, pEffect)
  9322. Gdip_DisposeEffect(pEffect)
  9323. }
  9324.  
  9325. matrix := GenerateColorMatrix(2, brightness, contrast)
  9326. fBitmap := StrLen(nBitmap)>2 ? nBitmap : pBitmap
  9327. gdipLastError := Gdip_DrawImage(G, fBitmap, 0, 0, Width, Height, 0, 0, Width, Height, matrix)
  9328. Gdip_DeleteGraphics(G)
  9329. If (nBitmap=fBitmap)
  9330. Gdip_DisposeImage(nBitmap, 1)
  9331.  
  9332. Return newBitmap
  9333. }
  9334.  
  9335. Gdip_BitmapApplyHSL(pBitmap, hue, saturation, lightness) {
  9336. ; hue [-180, 180]
  9337. ; saturation [-100, 100]
  9338. ; light [-100, 100]
  9339. ; if succesful, returns 0
  9340.  
  9341. If (pBitmap="")
  9342. Return -2
  9343.  
  9344. pEffect := Gdip_CreateEffect(6, hue, saturation, lightness)
  9345. If !pEffect
  9346. Return -1
  9347.  
  9348. E := Gdip_BitmapApplyEffect(pBitmap, pEffect)
  9349. Gdip_DisposeEffect(pEffect)
  9350. Return E
  9351. }
  9352.  
  9353. Gdip_BitmapApplyTint(pBitmap, hue, amount) {
  9354. ; hue [-180, 180]
  9355. ; amount [0, 100]
  9356. ; if succesful, returns 0
  9357.  
  9358. If (pBitmap="")
  9359. Return -2
  9360.  
  9361. pEffect := Gdip_CreateEffect(8, hue, amount)
  9362. If !pEffect
  9363. Return -1
  9364.  
  9365. E := Gdip_BitmapApplyEffect(pBitmap, pEffect)
  9366. Gdip_DisposeEffect(pEffect)
  9367. Return E
  9368. }
  9369.  
  9370. Gdip_BitmapApplyBrightnessContrast(pBitmap, brightness, contrast) {
  9371. ; brightness [-255, 255]
  9372. ; contrast [-100, 100]
  9373. ; if succesful, returns 0
  9374.  
  9375. If (pBitmap="")
  9376. Return -2
  9377.  
  9378. pEffect := Gdip_CreateEffect(5, brightness, contrast)
  9379. If !pEffect
  9380. Return -1
  9381.  
  9382. E := Gdip_BitmapApplyEffect(pBitmap, pEffect)
  9383. Gdip_DisposeEffect(pEffect)
  9384. Return E
  9385. }
  9386.  
  9387. Gdip_BitmapSetColorDepth(pBitmap, bitsDepth, useDithering:=1) {
  9388. ; Return 0 = OK - Success
  9389.  
  9390. ditheringMode := (useDithering=1) ? 9 : 1
  9391. If (useDithering=1 && bitsDepth=16)
  9392. ditheringMode := 2
  9393.  
  9394. Colors := 2**bitsDepth
  9395. If bitsDepth Between 2 and 4
  9396. bitsDepth := "40s"
  9397. If bitsDepth Between 5 and 8
  9398. bitsDepth := "80s"
  9399.  
  9400. If (bitsDepth="BW")
  9401. E := Gdip_BitmapConvertFormat(pBitmap, 0x30101, ditheringMode, 2, 2, 2, 2, 0, 0)
  9402. Else If (bitsDepth=1)
  9403. E := Gdip_BitmapConvertFormat(pBitmap, 0x30101, ditheringMode, 1, 2, 1, 2, 0, 0)
  9404. Else If (bitsDepth="40s")
  9405. E := Gdip_BitmapConvertFormat(pBitmap, 0x30402, ditheringMode, 1, Colors, 1, Colors, 0, 0)
  9406. Else If (bitsDepth="80s")
  9407. E := Gdip_BitmapConvertFormat(pBitmap, 0x30803, ditheringMode, 1, Colors, 1, Colors, 0, 0)
  9408. Else If (bitsDepth=16)
  9409. E := Gdip_BitmapConvertFormat(pBitmap, 0x21005, ditheringMode, 1, Colors, 1, Colors, 0, 0)
  9410. Else If (bitsDepth=24)
  9411. E := Gdip_BitmapConvertFormat(pBitmap, 0x21808, 2, 1, 0, 0, 0, 0, 0)
  9412. Else If (bitsDepth=32)
  9413. E := Gdip_BitmapConvertFormat(pBitmap, 0x26200A, 2, 1, 0, 0, 0, 0, 0)
  9414. Else If (bitsDepth=48)
  9415. E := Gdip_BitmapConvertFormat(pBitmap, 0x10300C, 2, 1, 0, 0, 0, 0, 0)
  9416. Else If (bitsDepth=64)
  9417. E := Gdip_BitmapConvertFormat(pBitmap, 0x34400D, 2, 1, 0, 0, 0, 0, 0)
  9418. Else
  9419. E := -1
  9420. Return E
  9421. }
  9422.  
  9423. Gdip_BitmapConvertFormat(pBitmap, PixelFormat, DitherType, DitherPaletteType, PaletteEntries, PaletteType, OptimalColors, UseTransparentColor:=0, AlphaThresholdPercent:=0) {
  9424. ; pBitmap - Handle to a pBitmap object on which the color conversion is applied.
  9425.  
  9426. ; PixelFormat options: see Gdip_GetImagePixelFormat()
  9427. ; Pixel format constant that specifies the new pixel format.
  9428.  
  9429. ; PaletteEntries Number of Entries.
  9430. ; OptimalColors - Integer that specifies the number of colors you want to have in an optimal palette based on a specified pBitmap.
  9431. ; This parameter is relevant if PaletteType parameter is set to PaletteTypeOptimal [1].
  9432. ; UseTransparentColor Boolean value that specifies whether to include the transparent color in the palette.
  9433. ; AlphaThresholdPercent - Real number in the range 0.0 through 100.0 that specifies which pixels in the source bitmap will map to the transparent color in the converted bitmap.
  9434. ;
  9435. ; PaletteType options:
  9436. ; Custom = 0 ; Arbitrary custom palette provided by caller.
  9437. ; Optimal = 1 ; Optimal palette generated using a median-cut algorithm.
  9438. ; FixedBW = 2 ; Black and white palette.
  9439. ;
  9440. ; Symmetric halftone palettes. Each of these halftone palettes will be a superset of the system palette.
  9441. ; e.g. Halftone8 will have its 8-color on-off primaries and the 16 system colors added. With duplicates removed, that leaves 16 colors.
  9442. ; FixedHalftone8 = 3 ; 8-color, on-off primaries
  9443. ; FixedHalftone27 = 4 ; 3 intensity levels of each color
  9444. ; FixedHalftone64 = 5 ; 4 intensity levels of each color
  9445. ; FixedHalftone125 = 6 ; 5 intensity levels of each color
  9446. ; FixedHalftone216 = 7 ; 6 intensity levels of each color
  9447. ;
  9448. ; Assymetric halftone palettes. These are somewhat less useful than the symmetric ones, but are included for completeness.
  9449. ; These do not include all of the system colors.
  9450. ; FixedHalftone252 = 8 ; 6-red, 7-green, 6-blue intensities
  9451. ; FixedHalftone256 = 9 ; 8-red, 8-green, 4-blue intensities
  9452. ;
  9453. ; DitherType options:
  9454. ; None = 0
  9455. ; Solid = 1
  9456. ; - it picks the nearest matching color with no attempt to halftone or dither. May be used on an arbitrary palette.
  9457. ;
  9458. ; Ordered dithers and spiral dithers must be used with a fixed palette.
  9459. ; NOTE: DitherOrdered4x4 is unique in that it may apply to 16bpp conversions also.
  9460. ; Ordered4x4 = 2
  9461. ; Ordered8x8 = 3
  9462. ; Ordered16x16 = 4
  9463. ; Ordered91x91 = 5
  9464. ; Spiral4x4 = 6
  9465. ; Spiral8x8 = 7
  9466. ; DualSpiral4x4 = 8
  9467. ; DualSpiral8x8 = 9
  9468. ; ErrorDiffusion = 10 ; may be used with any palette
  9469. ; Return 0 = OK - Success
  9470.  
  9471. VarSetCapacity(hPalette, 4 * PaletteEntries + 8, 0)
  9472. ; tPalette := DllStructCreate("uint Flags; uint Count; uint ARGB[" & $iEntries & "];")
  9473. NumPut(PaletteType, &hPalette, 0, "uint")
  9474. NumPut(PaletteEntries, &hPalette, 4, "uint")
  9475. NumPut(0, &hPalette, 8, "uint")
  9476.  
  9477. E1 := DllCall("gdiplus\GdipInitializePalette", "UPtr", &hPalette, "uint", PaletteType, "uint", OptimalColors, "Int", UseTransparentColor, "UPtr", pBitmap)
  9478. E2 := DllCall("gdiplus\GdipBitmapConvertFormat", "UPtr", pBitmap, "uint", PixelFormat, "uint", DitherType, "uint", DitherPaletteType, "UPtr", &hPalette, "float", AlphaThresholdPercent)
  9479. E := E1 ? E1 : E2
  9480. Return E
  9481. }
  9482.  
  9483. Gdip_GetImageThumbnail(pBitmap, W, H) {
  9484. ; by jballi, source
  9485. ; https://www.autohotkey.com/boards/viewtopic.php?style=7&t=70508
  9486.  
  9487. gdipLastError := DllCall("gdiplus\GdipGetImageThumbnail"
  9488. ,"UPtr",pBitmap ;-- *image
  9489. ,"UInt",W ;-- thumbWidth
  9490. ,"UInt",H ;-- thumbHeight
  9491. ,"UPtr*",pThumbnail ;-- **thumbImage
  9492. ,"UPtr",0 ;-- callback
  9493. ,"UPtr",0) ;-- callbackData
  9494.  
  9495. Return pThumbnail
  9496. }
  9497.  
  9498. ; =================================================
  9499. ; The following functions were written by Tidbit
  9500. ; handed to me by himself to be included here.
  9501. ; =================================================
  9502.  
  9503. ConvertRGBtoHSL(R, G, B) {
  9504. ; http://www.easyrgb.com/index.php?X=MATH&H=18#text18
  9505. SetFormat, float, 0.5 ; for some reason I need this for some colors to work.
  9506.  
  9507. R := (R / 255)
  9508. G := (G / 255)
  9509. B := (B / 255)
  9510.  
  9511. Min := min(R, G, B)
  9512. Max := max(R, G, B)
  9513. del_Max := Max - Min
  9514.  
  9515. L := (Max + Min) / 2
  9516. if (del_Max = 0)
  9517. {
  9518. H := S := 0
  9519. } else
  9520. {
  9521. if (L < 0.5)
  9522. S := del_Max / (Max + Min)
  9523. else
  9524. S := del_Max / (2 - Max - Min)
  9525.  
  9526. del_R := (((Max - R) / 6) + (del_Max / 2)) / del_Max
  9527. del_G := (((Max - G) / 6) + (del_Max / 2)) / del_Max
  9528. del_B := (((Max - B) / 6) + (del_Max / 2)) / del_Max
  9529.  
  9530. if (R = Max)
  9531. {
  9532. H := del_B - del_G
  9533. } else
  9534. {
  9535. if (G = Max)
  9536. H := (1 / 3) + del_R - del_B
  9537. else if (B = Max)
  9538. H := (2 / 3) + del_G - del_R
  9539. }
  9540. if (H < 0)
  9541. H += 1
  9542. if (H > 1)
  9543. H -= 1
  9544. }
  9545. ; return round(h*360) "," s "," l
  9546. ; return (h*360) "," s "," l
  9547. return [abs(round(h*360, 3)), abs(s), abs(l)]
  9548. }
  9549.  
  9550. ConvertHSLtoRGB(H, S, L) {
  9551. ; http://www.had2know.com/technology/hsl-rgb-color-converter.html
  9552.  
  9553. H := H/360
  9554. if (S == 0)
  9555. {
  9556. R := L*255
  9557. G := L*255
  9558. B := L*255
  9559. } else
  9560. {
  9561. if (L < 0.5)
  9562. var_2 := L * (1 + S)
  9563. else
  9564. var_2 := (L + S) - (S * L)
  9565. var_1 := 2 * L - var_2
  9566.  
  9567. R := 255 * ConvertHueToRGB(var_1, var_2, H + (1 / 3))
  9568. G := 255 * ConvertHueToRGB(var_1, var_2, H)
  9569. B := 255 * ConvertHueToRGB(var_1, var_2, H - (1 / 3))
  9570. }
  9571. ; Return round(R) "," round(G) "," round(B)
  9572. ; Return (R) "," (G) "," (B)
  9573. Return [round(R), round(G), round(B)]
  9574. }
  9575.  
  9576. ConvertHueToRGB(v1, v2, vH) {
  9577. vH := ((vH<0) ? ++vH : vH)
  9578. vH := ((vH>1) ? --vH : vH)
  9579. return ((6 * vH) < 1) ? (v1 + (v2 - v1) * 6 * vH)
  9580. : ((2 * vH) < 1) ? (v2)
  9581. : ((3 * vH) < 2) ? (v1 + (v2 - v1) * ((2 / 3) - vH) * 6)
  9582. : v1
  9583. }
  9584.  
  9585. Gdip_ErrorHandler(errCode, throwErrorMsg, additionalInfo:="") {
  9586. Static errList := {1:"Generic_Error", 2:"Invalid_Parameter"
  9587. , 3:"Out_Of_Memory", 4:"Object_Busy"
  9588. , 5:"Insufficient_Buffer", 6:"Not_Implemented"
  9589. , 7:"Win32_Error", 8:"Wrong_State"
  9590. , 9:"Aborted", 10:"File_Not_Found"
  9591. , 11:"Value_Overflow", 12:"Access_Denied"
  9592. , 13:"Unknown_Image_Format", 14:"Font_Family_Not_Found"
  9593. , 15:"Font_Style_Not_Found", 16:"Not_TrueType_Font"
  9594. , 17:"Unsupported_GdiPlus_Version", 18:"Not_Initialized"
  9595. , 19:"Property_Not_Found", 20:"Property_Not_Supported"
  9596. , 21:"Profile_Not_Found", 100:"Unknown_Wrapper_Error"}
  9597.  
  9598. If !errCode
  9599. Return
  9600.  
  9601. aerrCode := (errCode<0) ? 100 : errCode
  9602. If errList.HasKey(aerrCode)
  9603. GdipErrMsg := "GDI+ ERROR: " errList[aerrCode] " [CODE: " aerrCode "]" additionalInfo
  9604. Else
  9605. GdipErrMsg := "GDI+ UNKNOWN ERROR: " aerrCode additionalInfo
  9606.  
  9607. If (throwErrorMsg=1)
  9608. MsgBox, % GdipErrMsg
  9609.  
  9610. Return GdipErrMsg
  9611. }
  9612.  
  9613. class Gdip_GraphicsPathIterator {
  9614. __New(pPath) {
  9615. ; Create GraphicsPathIterator
  9616. If !pPath
  9617. {
  9618. this.error := 2
  9619. return
  9620. }
  9621.  
  9622. this.error := DllCall("gdiplus\GdipCreatePathIter", "UPtr*", pIterator:=0, "UPtr", pPath)
  9623. If pIterator
  9624. this.ptr := pIterator
  9625. }
  9626.  
  9627. Discard() {
  9628. If (this.ptr)
  9629. {
  9630. DllCall("gdiplus\GdipDeletePathIter", "UPtr", this.ptr)
  9631. this.error := ""
  9632. this.ptr := ""
  9633. }
  9634. }
  9635.  
  9636. HasCurve() {
  9637. ; the function returns 0 when the path contains only polygonal lines; if it contains beziers, it returns 1
  9638. ; on error , the return value is -1
  9639.  
  9640. n := -1
  9641. If (this.ptr)
  9642. this.error := DllCall("gdiplus\GdipPathIterHasCurve", "UPtr", this.ptr, "int*", n)
  9643.  
  9644. Return n
  9645. }
  9646.  
  9647. NextSubpath() {
  9648. ; Get next subpath information
  9649. this.error := DllCall("gdiplus\GdipPathIterNextSubpath"
  9650. , "UPtr", this.ptr
  9651. , "Int*", resultCount:=0
  9652. , "Int*", startIndex:=0
  9653. , "Int*", endIndex:=0
  9654. , "Int*", isClosed:=0)
  9655.  
  9656. return {count: resultCount
  9657. , startIndex: startIndex
  9658. , endIndex: endIndex
  9659. , isClosed: isClosed}
  9660. }
  9661.  
  9662. NextPathType() {
  9663. ; Get next path point type
  9664. this.error := DllCall("gdiplus\GdipPathIterNextPathType"
  9665. , "UPtr", this.ptr
  9666. , "Int*", resultCount:=0
  9667. , "UChar*", pathType:=0
  9668. , "Int*", startIndex:=0
  9669. , "Int*", endIndex:=0)
  9670.  
  9671. return {count: resultCount
  9672. , pathType: pathType
  9673. , startIndex: startIndex
  9674. , endIndex: endIndex}
  9675. }
  9676.  
  9677. NextMarker() {
  9678. ; Get next marker
  9679. this.error := DllCall("gdiplus\GdipPathIterNextMarker"
  9680. , "UPtr", this.ptr
  9681. , "Int*", resultCount:=0
  9682. , "Int*", startIndex:=0
  9683. , "Int*", endIndex:=0)
  9684.  
  9685. return {count: resultCount
  9686. , startIndex: startIndex
  9687. , endIndex: endIndex}
  9688. }
  9689.  
  9690. GetCount() {
  9691. ; Get total number of points
  9692. n := 0
  9693. this.error := DllCall("gdiplus\GdipPathIterGetCount", "UPtr", this.ptr, "Int*", n)
  9694. return n
  9695. }
  9696.  
  9697. GetSubpathCount() {
  9698. ; Get number of subpaths
  9699. n := 0
  9700. this.error := DllCall("gdiplus\GdipPathIterGetSubpathCount", "UPtr", this.ptr, "Int*", n)
  9701. return n
  9702. }
  9703.  
  9704. Rewind() {
  9705. ; Reset iterator position to start
  9706. this.error := DllCall("gdiplus\GdipPathIterRewind", "UPtr", this.ptr)
  9707. Return this.error
  9708. }
  9709.  
  9710. CopyData(ByRef points, ByRef types, startIndex, endIndex) {
  9711. ; Copy path data to arrays
  9712. pointCount := endIndex - startIndex + 1
  9713. VarSetCapacity(pointsBuffer, 8 * pointCount * A_PtrSize)
  9714. VarSetCapacity(typesBuffer, pointCount)
  9715. resultCount := 0
  9716. this.error := DllCall("gdiplus\GdipPathIterCopyData"
  9717. , "UPtr", this.ptr
  9718. , "Int*", resultCount
  9719. , "UPtr", &pointsBuffer
  9720. , "UPtr", &typesBuffer
  9721. , "Int", startIndex
  9722. , "Int", endIndex)
  9723.  
  9724. ; Convert buffer data to arrays
  9725. If !this.error
  9726. {
  9727. points := []
  9728. types := []
  9729. Loop, % resultCount {
  9730. offset := (A_Index-1) * 8
  9731. points.Push(NumGet(pointsBuffer, offset, "Float"))
  9732. points.Push(NumGet(pointsBuffer, offset+4, "Float"))
  9733. types.Push(NumGet(typesBuffer, A_Index-1, "UChar"))
  9734. }
  9735. }
  9736. return resultCount
  9737. }
  9738.  
  9739. GetSubPath(startIndex, endIndex, fillMode:=0) {
  9740. pPath := 0
  9741. pointCount := endIndex - startIndex + 1
  9742. VarSetCapacity(pointsBuffer, 8 * pointCount * A_PtrSize)
  9743. VarSetCapacity(typesBuffer, pointCount)
  9744. resultCount := 0
  9745. this.error := DllCall("gdiplus\GdipPathIterCopyData"
  9746. , "UPtr", this.ptr
  9747. , "Int*", resultCount
  9748. , "UPtr", &pointsBuffer
  9749. , "UPtr", &typesBuffer
  9750. , "Int", startIndex
  9751. , "Int", endIndex)
  9752.  
  9753. If !this.error
  9754. this.error := DllCall("gdiplus\GdipCreatePath2", "UPtr", &pointsBuffer, "UPtr", &typesBuffer, "Int", resultCount, "UInt", fillMode, "UPtr*", pPath)
  9755. return pPath
  9756. }
  9757. }
  9758.  
Add Comment
Please, Sign In to add comment