Advertisement
pastamaker

CONVEX CURVE

Jun 29th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
  2. ; #Warn  ; Enable warnings to assist with detecting common errors.
  3. SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
  4. SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
  5.  
  6. CoordMode,mouse,screen
  7.  
  8.  
  9. ;~ #Include,<hellbents_gdip>
  10.  
  11.  SetBatchLines,-1
  12.  
  13.  #MaxHotkeysPerInterval,10000000000
  14.  
  15.  popUp:=Layered_Window_SetUp(4,0,0,A_ScreenWidth,A_ScreenHeight,1,"Alwaysontop")
  16.  
  17. pointsmass:=[]
  18. pBrush:=new_brush("000000")
  19. backBrush:=new_brush("a00000","90")
  20. point:={x:500,y:350}
  21. loop {
  22.    
  23.     points:=""
  24.     howmany := pointsmass.length() - 1
  25.     Loop % HOWmany {
  26.         points.= pointsmass[a_index].x  " , "  pointsmass[a_index].y " || "
  27.    
  28.     }
  29.     points.= pointsmass[pointsmass.length()].x  " , "  pointsmass[pointsmass.length()].y  
  30.    
  31.     gosub justDraw
  32.     if(getkeystate("capslock","T"))
  33.         break
  34.     if(GetKeyState("lbutton")){
  35.         MouseGetPos,x,y
  36.         a:={x:x,y:y}
  37.        
  38.         PointsMass.insert(a.clone())
  39.        
  40.         loop {
  41.             if(getkeystate("lbutton") = 0)
  42.                 break
  43.         }
  44.        
  45.     }
  46. }
  47.  
  48. howmany := pointsmass.length() - 1
  49. massLines:=[]
  50. loop % howmany {
  51.     x1:=PointsMass[A_Index].x
  52.     y1:=PointsMass[A_Index].y
  53.     x2:=PointsMass[A_Index+1].x
  54.     y2:=PointsMass[A_Index+1].y
  55.    
  56.    
  57.    
  58.     mass:={x1:x1,x2:x2,y2:y2,y1:y1}
  59.     massLines.insert(mass.clone())
  60. }
  61.  
  62. last := pointsmass.length()
  63. x1:=PointsMass[last].x
  64. y1:=PointsMass[last].y
  65. x2:=PointsMass[1].x
  66. y2:=PointsMass[1].y
  67.  
  68. mass:={x1:x1,x2:x2,y2:y2,y1:y1}
  69. massLines.insert(mass.clone())
  70.  
  71.  
  72.  
  73. massValue:=[]
  74.  
  75. howmany := pointsmass.length()
  76. ;~ *******************
  77.  
  78. ;~ *******************
  79. loop % howmany {
  80.     line:=massLines[a_index]
  81.     massValue.insert(getValue(line,point))
  82.    
  83.    
  84.    
  85.    
  86. }
  87.  
  88.  
  89.  
  90. SetTimer,gameLoop,10
  91. return
  92.  
  93. justDraw:
  94. Gdip_GraphicsClear(popUp.g)
  95.  
  96. Gdip_FillRectangle(popup.g,backBrush,0,0,popup.w,popup.h)
  97.  
  98. Gdip_FillPolygon(popup.g, pBrush, Points, 0)
  99. fill_boxx(popup.g,"000000",POINT.x -5,point.y -5,10,10)
  100.  
  101.  
  102.  
  103. UpdateLayeredWindow(popUp.hwnd, popUp.hdc, popUp.x, popUp.y, popUp.w, popUp.h)
  104. return
  105. gameLoop:
  106.  
  107. gosub checkOutside
  108.  
  109. Gdip_GraphicsClear(popUp.g)
  110.  
  111. Gdip_FillRectangle(popup.g,backBrush,0,0,popup.w,popup.h)
  112.  
  113. Gdip_FillPolygon(popup.g, pBrush, Points, 0)
  114.  
  115.  
  116.  
  117.  
  118. UpdateLayeredWindow(popUp.hwnd, popUp.hdc, popUp.x, popUp.y, popUp.w, popUp.h)
  119. return
  120.  
  121.  
  122. checkOutside:
  123. MouseGetPos,x,y
  124. point:={x:x,y:y}
  125. out:=0
  126.  
  127. howmany := pointsmass.length()
  128. loop % howmany {
  129.     line:=massLines[a_index]
  130.     Value:=getValue(line,point)
  131.     if(massValue[a_index] <> Value){
  132.         out:=1
  133.         break
  134.     }
  135.    
  136.    
  137.    
  138.    
  139. }
  140. ToolTip,% "out : " out
  141. return
  142.  
  143.  
  144.    
  145. getValue(line,point){
  146.     x:=point.x,y:=point.y
  147.     x1:=line.x1,y1:=line.y1,x2:=line.x2,y2:=line.y2
  148.     if(x1 = x2){
  149.         if(x > x1)
  150.             return 1
  151.         else if(x <= x1)
  152.             return -1
  153.     }
  154.     else if (x1 <> x2){
  155.         val:= y - (y1 + ((y2-y1)/(x2-x1) )*(x-x1))
  156.         if(val = 0)
  157.             return -1
  158.         return val/abs(val)
  159.     }
  160.    
  161.    
  162.    
  163.    
  164.    
  165. }
  166.  
  167.  
  168.  
  169. getAngle(dx,dy){
  170.     r:=Sqrt(dx**2 + dy**2)
  171.     if(dx>=0)
  172.         angle:= asinG(dy/r)
  173.     else if(dy>=0)
  174.         angle:= acosG(dx/r)
  175.     else if(dx < 0 && dy < 0)
  176.         angle:= 180 + asing(abs(dy/r))
  177.     if(angle < 0)
  178.         angle+=360
  179.     return angle
  180. }
  181.  
  182.  
  183. x::
  184. gosub getOutOfHere
  185. return
  186.  
  187. getOutOfHere:
  188. ExitApp
  189. Layered_Window_ShutDown(popUp)
  190. return
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.  
  208. ;STUFF  Hellbent HAS  added
  209. ;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  210. ;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  211. ;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  212.  
  213. Layered_Window_SetUp(Smoothing,Window_X,Window_Y,Window_W,Window_H,Window_Name:=1,Window_Options:="")
  214.     {
  215.         Layered:={}
  216.         Layered.W:=Window_W
  217.         Layered.H:=Window_H
  218.         Layered.X:=Window_X
  219.         Layered.Y:=Window_Y
  220.         Layered.Name:=Window_Name
  221.         Layered.Options:=Window_Options
  222.         Layered.Token:=Gdip_Startup()
  223.         Create_Layered_GUI(Layered)
  224.         Layered.hwnd:=winExist()
  225.         Layered.hbm := CreateDIBSection(Window_W,Window_H)
  226.         Layered.hdc := CreateCompatibleDC()
  227.         Layered.obm := SelectObject(Layered.hdc,Layered.hbm)
  228.         Layered.G := Gdip_GraphicsFromHDC(Layered.hdc)
  229.         Gdip_SetSmoothingMode(Layered.G,Smoothing)
  230.         return Layered
  231.     }
  232.  
  233. Create_Layered_GUI(Layered)
  234.     {
  235.         Gui,% Layered.Name ": +E0x80000 +LastFound " Layered.Options
  236.         Gui,% Layered.Name ":Show",% "x" Layered.X " y" Layered.Y " w" Layered.W " h" Layered.H " NA"
  237.     }
  238.    
  239. Layered_Window_ShutDown(This)
  240.     {
  241.         SelectObject(This.hdc,This.obm)
  242.         DeleteObject(This.hbm)
  243.         DeleteDC(This.hdc)
  244.         gdip_deleteGraphics(This.g)
  245.         Gdip_Shutdown(This.Token)
  246.     }
  247.  
  248. Gdip_RotateBitmap(pBitmap, Angle, Dispose=1) { ; returns rotated bitmap. By Learning one.
  249. Gdip_GetImageDimensions(pBitmap, Width, Height)
  250. Gdip_GetRotatedDimensions(Width, Height, Angle, RWidth, RHeight)
  251. Gdip_GetRotatedTranslation(Width, Height, Angle, xTranslation, yTranslation)
  252.  
  253. pBitmap2 := Gdip_CreateBitmap(RWidth, RHeight)
  254. G2 := Gdip_GraphicsFromImage(pBitmap2), Gdip_SetSmoothingMode(G2, 4), Gdip_SetInterpolationMode(G2, 7)
  255. Gdip_TranslateWorldTransform(G2, xTranslation, yTranslation)
  256. Gdip_RotateWorldTransform(G2, Angle)
  257. Gdip_DrawImage(G2, pBitmap, 0, 0, Width, Height)
  258.  
  259. Gdip_ResetWorldTransform(G2)
  260. Gdip_DeleteGraphics(G2)
  261. if Dispose
  262. Gdip_DisposeImage(pBitmap)
  263. return pBitmap2
  264. }
  265.  
  266. New_Brush(colour:="000000",Alpha:="FF")
  267.     {
  268.         static Hellbent_Brush:=[]
  269.         new_colour := "0x" Alpha colour
  270.         Hellbent_Brush[Hellbent_Brush.Length()+1]:=Gdip_BrushCreateSolid(new_colour)
  271.         return Hellbent_Brush[Hellbent_Brush.Length()]
  272.     }
  273.    
  274.    
  275. New_Pen(colour:="000000",Alpha:="FF",Width:= 5)
  276.     {
  277.         static Hellbent_Pen:=[]
  278.         new_colour := "0x" Alpha colour
  279.         Hellbent_Pen[Hellbent_Pen.Length()+1]:=Gdip_CreatePen(New_Colour,Width)
  280.         return Hellbent_Pen[Hellbent_Pen.Length()]
  281.     }  
  282.    
  283. Fill_Box(pGraphics,pBrush,x,y,w,h) 
  284.     {
  285.         ;~ Gdip_FillRectangle(G, Brush, x, y, w, h)
  286.         Ptr := A_PtrSize ? "UPtr" : "UInt"
  287.    
  288.         return DllCall("gdiplus\GdipFillRectangle"
  289.                     , Ptr, pGraphics
  290.                     , Ptr, pBrush
  291.                     , "float", x
  292.                     , "float", y
  293.                     , "float", w
  294.                     , "float", h)
  295.     }
  296. Fill_Boxx(pGraphics,colour,x,y,w,h){
  297.     pBrush:=new_brush(colour)
  298. Fill_Box(pGraphics,pBrush,x,y,w,h) 
  299. }
  300. ;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  301. ;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  302. ;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  303.  
  304. atang(tann){
  305.     angle:=ATan(tann)
  306.     angle:=angle/(3.14159265359/180)
  307.     return angle
  308. }
  309. tang(angle){
  310.     return tan(angle*(3.14159265359/180))
  311. }
  312.  
  313.  
  314.  
  315.  
  316.  
  317. turn_bitmap(byref xbitmap,xturn){
  318. xWidth := Gdip_GetImageWidth(xbitmap)
  319. xHeight := Gdip_GetImageHeight(xbitmap)
  320.  
  321.  
  322. Gdip_GetRotatedDimensions(xWidth, xHeight, xturn, xRWidth, xRHeight)
  323. ;~ MsgBox,% "Rwidth: " RWidth "`nrheight: " rheight
  324.  
  325. ; xTranslation and yTranslation now contain the distance to shift the image by
  326. Gdip_GetRotatedTranslation(xWidth, xHeight, xturn, xxTranslation, xyTranslation)
  327. ;~ MsgBox,% "xTranslation: " xTranslation "`nyTranslation: " yTranslation
  328. xpBitmap := Gdip_CreateBitmap(xRWidth, xRHeight)                       ; Create a new bitmap
  329. xg := Gdip_GraphicsFromImage(xpBitmap)                                ; Get a pointer to the graphics of the bitmap
  330. Gdip_SetSmoothingMode(xg, 4)
  331.  
  332. Gdip_SetInterpolationMode(xg, 7)
  333. Gdip_TranslateWorldTransform(xg, xxTranslation, xyTranslation)
  334. Gdip_RotateWorldTransform(xg, xturn)
  335.  
  336.  
  337. Gdip_DrawImage(xg, xbitmap, 0,0, xWidth, xHeight)  
  338. Gdip_ResetWorldTransform(xg)
  339.  
  340. xbitmap:=xpbitmap
  341. }
  342.  
  343. turn_in_graphics(byref xg,xx,xy,xturn,xbitmap){
  344.    
  345.     turn_bitmap(xbitmap,xturn)
  346.     xWidth := Gdip_GetImageWidth(xbitmap)
  347. xHeight := Gdip_GetImageHeight(xbitmap)
  348.     Gdip_DrawImage(xG, xBitmap, xx-xWidth/2, xy-xheight/2, xWidth, xHeight)
  349.    
  350. }
  351. fill_ellipse(g,colour,x1,y1,w,h){
  352.         pBrush:=new_brush(colour)
  353.     Gdip_FillEllipse(g, pBrush, x1, y1, w, h)
  354.  
  355. }
  356.  
  357. sinG(x){
  358. return sin(x*3.14159265359/180)
  359. }
  360. asinG(sinn){
  361.     angle:=Asin(sinn)
  362.     angle:=angle/(3.14159265359/180)
  363.     return angle
  364. }
  365.  
  366.  
  367. acosG(coss){
  368.     angle:=Acos(coss)
  369.     angle:=angle/(3.14159265359/180)
  370.     return angle
  371. }
  372.  
  373.  
  374.  
  375. cosG(x){
  376. return cos(x*3.14159265359/180)
  377. }
  378. /*
  379. two new functions and an opportunity to change
  380.  
  381. GDIP_SCALE(Map,SCALE)
  382. ; map you want to get a changed copy that is scale times less than
  383. original one
  384. fileScale(sFile,newName,SCALE)
  385. ;saves a changed( scale times less copy) of image from sfile Path
  386. to newname Path
  387. */
  388. GDIP_SCALE(Map,SCALE){
  389. Gdip_GetImageDimensions(MAP,  wOrig,  hOrig)
  390. newSize:={w:wOrig//SCALE,h:hOrig//SCALE}
  391.  
  392. newMap := Gdip_CreateBitmap(newSize.w, newSize.h)                    
  393. newMapG := Gdip_GraphicsFromImage(newMap)                              
  394. Gdip_SetSmoothingMode(newMapG, 4)
  395. Gdip_DrawImage(newMapG, map, 0, 0 ,newSize.w,newSize.h,0,0,wOrig,hOrig)
  396. return newMap
  397.    
  398.    
  399. }
  400.  
  401. fileScale(sFile,newName,SCALE){
  402.     map:=Gdip_CreateBitmapFromFile(sfile)
  403.     newmap:=GDIP_SCALE(Map,SCALE)
  404.     Gdip_SaveBitmapToFile(newmap, newname)
  405. }
  406.  
  407.  
  408.  
  409.         ;~ split(string){
  410.     ;~ string := StrSplit(string, A_Space)  
  411.     ;~ t:=1
  412.     ;~ while ( string.length() >= t) {
  413.         ;~ if(string[t]<>"")
  414.             ;~ t++
  415.         ;~ else
  416.             ;~ string.Remove(t)
  417.     ;~ }
  418.     ;~ return string
  419. ;~ }
  420.  
  421.  
  422.  
  423.  
  424.  
  425.  
  426.  
  427.  
  428. ; Gdip standard library v1.45 by tic (Tariq Porter) 07/09/11
  429. ; Modifed by Rseding91 using fincs 64 bit compatible Gdip library 5/1/2013
  430. ; Supports: Basic, _L ANSi, _L Unicode x86 and _L Unicode x64
  431. ;
  432. ; Updated 2/20/2014 - fixed Gdip_CreateRegion() and Gdip_GetClipRegion() on AHK Unicode x86
  433. ; Updated 5/13/2013 - fixed Gdip_SetBitmapToClipboard() on AHK Unicode x64
  434. ;
  435. ;#####################################################################################
  436. ;#####################################################################################
  437. ; STATUS ENUMERATION
  438. ; Return values for functions specified to have status enumerated return type
  439. ;#####################################################################################
  440. ;
  441. ; Ok =                      = 0
  442. ; GenericError              = 1
  443. ; InvalidParameter          = 2
  444. ; OutOfMemory               = 3
  445. ; ObjectBusy                = 4
  446. ; InsufficientBuffer        = 5
  447. ; NotImplemented            = 6
  448. ; Win32Error                = 7
  449. ; WrongState                = 8
  450. ; Aborted                   = 9
  451. ; FileNotFound              = 10
  452. ; ValueOverflow             = 11
  453. ; AccessDenied              = 12
  454. ; UnknownImageFormat        = 13
  455. ; FontFamilyNotFound        = 14
  456. ; FontStyleNotFound         = 15
  457. ; NotTrueTypeFont           = 16
  458. ; UnsupportedGdiplusVersion = 17
  459. ; GdiplusNotInitialized     = 18
  460. ; PropertyNotFound          = 19
  461. ; PropertyNotSupported      = 20
  462. ; ProfileNotFound           = 21
  463. ;
  464. ;#####################################################################################
  465. ;#####################################################################################
  466. ; FUNCTIONS
  467. ;#####################################################################################
  468. ;
  469. ; UpdateLayeredWindow(hwnd, hdc, x="", y="", w="", h="", Alpha=255)
  470. ; BitBlt(ddc, dx, dy, dw, dh, sdc, sx, sy, Raster="")
  471. ; StretchBlt(dDC, dx, dy, dw, dh, sDC, sx, sy, sw, sh, Raster="")
  472. ; SetImage(hwnd, hBitmap)
  473. ; Gdip_BitmapFromScreen(Screen=0, Raster="")
  474. ; CreateRectF(ByRef RectF, x, y, w, h)
  475. ; CreateSizeF(ByRef SizeF, w, h)
  476. ; CreateDIBSection
  477. ;
  478. ;#####################################################################################
  479.  
  480. ; Function:                 UpdateLayeredWindow
  481. ; Description:              Updates a layered window with the handle to the DC of a gdi bitmap
  482. ;
  483. ; hwnd                      Handle of the layered window to update
  484. ; hdc                       Handle to the DC of the GDI bitmap to update the window with
  485. ; Layeredx                  x position to place the window
  486. ; Layeredy                  y position to place the window
  487. ; Layeredw                  Width of the window
  488. ; Layeredh                  Height of the window
  489. ; Alpha                     Default = 255 : The transparency (0-255) to set the window transparency
  490. ;
  491. ; return                    If the function succeeds, the return value is nonzero
  492. ;
  493. ; notes                     If x or y omitted, then layered window will use its current coordinates
  494. ;                           If w or h omitted then current width and height will be used
  495.  
  496. UpdateLayeredWindow(hwnd, hdc, x="", y="", w="", h="", Alpha=255)
  497. {
  498.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  499.    
  500.     if ((x != "") && (y != ""))
  501.         VarSetCapacity(pt, 8), NumPut(x, pt, 0, "UInt"), NumPut(y, pt, 4, "UInt")
  502.  
  503.     if (w = "") ||(h = "")
  504.         WinGetPos,,, w, h, ahk_id %hwnd%
  505.    
  506.     return DllCall("UpdateLayeredWindow"
  507.                     , Ptr, hwnd
  508.                     , Ptr, 0
  509.                     , Ptr, ((x = "") && (y = "")) ? 0 : &pt
  510.                     , "int64*", w|h<<32
  511.                     , Ptr, hdc
  512.                     , "int64*", 0
  513.                     , "uint", 0
  514.                     , "UInt*", Alpha<<16|1<<24
  515.                     , "uint", 2)
  516. }
  517.  
  518. ;#####################################################################################
  519.  
  520. ; Function              BitBlt
  521. ; Description           The BitBlt function performs a bit-block transfer of the color data corresponding to a rectangle
  522. ;                       of pixels from the specified source device context into a destination device context.
  523. ;
  524. ; dDC                   handle to destination DC
  525. ; dx                    x-coord of destination upper-left corner
  526. ; dy                    y-coord of destination upper-left corner
  527. ; dw                    width of the area to copy
  528. ; dh                    height of the area to copy
  529. ; sDC                   handle to source DC
  530. ; sx                    x-coordinate of source upper-left corner
  531. ; sy                    y-coordinate of source upper-left corner
  532. ; Raster                raster operation code
  533. ;
  534. ; return                If the function succeeds, the return value is nonzero
  535. ;
  536. ; notes                 If no raster operation is specified, then SRCCOPY is used, which copies the source directly to the destination rectangle
  537. ;
  538. ; BLACKNESS             = 0x00000042
  539. ; NOTSRCERASE           = 0x001100A6
  540. ; NOTSRCCOPY            = 0x00330008
  541. ; SRCERASE              = 0x00440328
  542. ; DSTINVERT             = 0x00550009
  543. ; PATINVERT             = 0x005A0049
  544. ; SRCINVERT             = 0x00660046
  545. ; SRCAND                = 0x008800C6
  546. ; MERGEPAINT            = 0x00BB0226
  547. ; MERGECOPY             = 0x00C000CA
  548. ; SRCCOPY               = 0x00CC0020
  549. ; SRCPAINT              = 0x00EE0086
  550. ; PATCOPY               = 0x00F00021
  551. ; PATPAINT              = 0x00FB0A09
  552. ; WHITENESS             = 0x00FF0062
  553. ; CAPTUREBLT            = 0x40000000
  554. ; NOMIRRORBITMAP        = 0x80000000
  555.  
  556. BitBlt(ddc, dx, dy, dw, dh, sdc, sx, sy, Raster="")
  557. {
  558.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  559.    
  560.     return DllCall("gdi32\BitBlt"
  561.                     , Ptr, dDC
  562.                     , "int", dx
  563.                     , "int", dy
  564.                     , "int", dw
  565.                     , "int", dh
  566.                     , Ptr, sDC
  567.                     , "int", sx
  568.                     , "int", sy
  569.                     , "uint", Raster ? Raster : 0x00CC0020)
  570. }
  571.  
  572. ;#####################################################################################
  573.  
  574. ; Function              StretchBlt
  575. ; Description           The StretchBlt function copies a bitmap from a source rectangle into a destination rectangle,
  576. ;                       stretching or compressing the bitmap to fit the dimensions of the destination rectangle, if necessary.
  577. ;                       The system stretches or compresses the bitmap according to the stretching mode currently set in the destination device context.
  578. ;
  579. ; ddc                   handle to destination DC
  580. ; dx                    x-coord of destination upper-left corner
  581. ; dy                    y-coord of destination upper-left corner
  582. ; dw                    width of destination rectangle
  583. ; dh                    height of destination rectangle
  584. ; sdc                   handle to source DC
  585. ; sx                    x-coordinate of source upper-left corner
  586. ; sy                    y-coordinate of source upper-left corner
  587. ; sw                    width of source rectangle
  588. ; sh                    height of source rectangle
  589. ; Raster                raster operation code
  590. ;
  591. ; return                If the function succeeds, the return value is nonzero
  592. ;
  593. ; notes                 If no raster operation is specified, then SRCCOPY is used. It uses the same raster operations as BitBlt    
  594.  
  595. StretchBlt(ddc, dx, dy, dw, dh, sdc, sx, sy, sw, sh, Raster="")
  596. {
  597.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  598.    
  599.     return DllCall("gdi32\StretchBlt"
  600.                     , Ptr, ddc
  601.                     , "int", dx
  602.                     , "int", dy
  603.                     , "int", dw
  604.                     , "int", dh
  605.                     , Ptr, sdc
  606.                     , "int", sx
  607.                     , "int", sy
  608.                     , "int", sw
  609.                     , "int", sh
  610.                     , "uint", Raster ? Raster : 0x00CC0020)
  611. }
  612.  
  613. ;#####################################################################################
  614.  
  615. ; Function              SetStretchBltMode
  616. ; Description           The SetStretchBltMode function sets the bitmap stretching mode in the specified device context
  617. ;
  618. ; hdc                   handle to the DC
  619. ; iStretchMode          The stretching mode, describing how the target will be stretched
  620. ;
  621. ; return                If the function succeeds, the return value is the previous stretching mode. If it fails it will return 0
  622. ;
  623. ; STRETCH_ANDSCANS      = 0x01
  624. ; STRETCH_ORSCANS       = 0x02
  625. ; STRETCH_DELETESCANS   = 0x03
  626. ; STRETCH_HALFTONE      = 0x04
  627.  
  628. SetStretchBltMode(hdc, iStretchMode=4)
  629. {
  630.     return DllCall("gdi32\SetStretchBltMode"
  631.                     , A_PtrSize ? "UPtr" : "UInt", hdc
  632.                     , "int", iStretchMode)
  633. }
  634.  
  635. ;#####################################################################################
  636.  
  637. ; Function              SetImage
  638. ; Description           Associates a new image with a static control
  639. ;
  640. ; hwnd                  handle of the control to update
  641. ; hBitmap               a gdi bitmap to associate the static control with
  642. ;
  643. ; return                If the function succeeds, the return value is nonzero
  644.  
  645. SetImage(hwnd, hBitmap)
  646. {
  647.     SendMessage, 0x172, 0x0, hBitmap,, ahk_id %hwnd%
  648.     E := ErrorLevel
  649.     DeleteObject(E)
  650.     return E
  651. }
  652.  
  653. ;#####################################################################################
  654.  
  655. ; Function              SetSysColorToControl
  656. ; Description           Sets a solid colour to a control
  657. ;
  658. ; hwnd                  handle of the control to update
  659. ; SysColor              A system colour to set to the control
  660. ;
  661. ; return                If the function succeeds, the return value is zero
  662. ;
  663. ; notes                 A control must have the 0xE style set to it so it is recognised as a bitmap
  664. ;                       By default SysColor=15 is used which is COLOR_3DFACE. This is the standard background for a control
  665. ;
  666. ; COLOR_3DDKSHADOW              = 21
  667. ; COLOR_3DFACE                  = 15
  668. ; COLOR_3DHIGHLIGHT             = 20
  669. ; COLOR_3DHILIGHT               = 20
  670. ; COLOR_3DLIGHT                 = 22
  671. ; COLOR_3DSHADOW                = 16
  672. ; COLOR_ACTIVEBORDER            = 10
  673. ; COLOR_ACTIVECAPTION           = 2
  674. ; COLOR_APPWORKSPACE            = 12
  675. ; COLOR_BACKGROUND              = 1
  676. ; COLOR_BTNFACE                 = 15
  677. ; COLOR_BTNHIGHLIGHT            = 20
  678. ; COLOR_BTNHILIGHT              = 20
  679. ; COLOR_BTNSHADOW               = 16
  680. ; COLOR_BTNTEXT                 = 18
  681. ; COLOR_CAPTIONTEXT             = 9
  682. ; COLOR_DESKTOP                 = 1
  683. ; COLOR_GRADIENTACTIVECAPTION   = 27
  684. ; COLOR_GRADIENTINACTIVECAPTION = 28
  685. ; COLOR_GRAYTEXT                = 17
  686. ; COLOR_HIGHLIGHT               = 13
  687. ; COLOR_HIGHLIGHTTEXT           = 14
  688. ; COLOR_HOTLIGHT                = 26
  689. ; COLOR_INACTIVEBORDER          = 11
  690. ; COLOR_INACTIVECAPTION         = 3
  691. ; COLOR_INACTIVECAPTIONTEXT     = 19
  692. ; COLOR_INFOBK                  = 24
  693. ; COLOR_INFOTEXT                = 23
  694. ; COLOR_MENU                    = 4
  695. ; COLOR_MENUHILIGHT             = 29
  696. ; COLOR_MENUBAR                 = 30
  697. ; COLOR_MENUTEXT                = 7
  698. ; COLOR_SCROLLBAR               = 0
  699. ; COLOR_WINDOW                  = 5
  700. ; COLOR_WINDOWFRAME             = 6
  701. ; COLOR_WINDOWTEXT              = 8
  702.  
  703. SetSysColorToControl(hwnd, SysColor=15)
  704. {
  705.    WinGetPos,,, w, h, ahk_id %hwnd%
  706.    bc := DllCall("GetSysColor", "Int", SysColor, "UInt")
  707.    pBrushClear := Gdip_BrushCreateSolid(0xff000000 | (bc >> 16 | bc & 0xff00 | (bc & 0xff) << 16))
  708.    pBitmap := Gdip_CreateBitmap(w, h), G := Gdip_GraphicsFromImage(pBitmap)
  709.    Gdip_FillRectangle(G, pBrushClear, 0, 0, w, h)
  710.    hBitmap := Gdip_CreateHBITMAPFromBitmap(pBitmap)
  711.    SetImage(hwnd, hBitmap)
  712.    Gdip_DeleteBrush(pBrushClear)
  713.    Gdip_DeleteGraphics(G), Gdip_DisposeImage(pBitmap), DeleteObject(hBitmap)
  714.    return 0
  715. }
  716.  
  717. ;#####################################################################################
  718.  
  719. ; Function              Gdip_BitmapFromScreen
  720. ; Description           Gets a gdi+ bitmap from the screen
  721. ;
  722. ; Screen                0 = All screens
  723. ;                       Any numerical value = Just that screen
  724. ;                       x|y|w|h = Take specific coordinates with a width and height
  725. ; Raster                raster operation code
  726. ;
  727. ; return                If the function succeeds, the return value is a pointer to a gdi+ bitmap
  728. ;                       -1:     one or more of x,y,w,h not passed properly
  729. ;
  730. ; notes                 If no raster operation is specified, then SRCCOPY is used to the returned bitmap
  731.  
  732. Gdip_BitmapFromScreen(Screen=0, Raster="")
  733. {
  734.     if (Screen = 0)
  735.     {
  736.         Sysget, x, 76
  737.         Sysget, y, 77  
  738.         Sysget, w, 78
  739.         Sysget, h, 79
  740.     }
  741.     else if (SubStr(Screen, 1, 5) = "hwnd:")
  742.     {
  743.         Screen := SubStr(Screen, 6)
  744.         if !WinExist( "ahk_id " Screen)
  745.             return -2
  746.         WinGetPos,,, w, h, ahk_id %Screen%
  747.         x := y := 0
  748.         hhdc := GetDCEx(Screen, 3)
  749.     }
  750.     else if (Screen&1 != "")
  751.     {
  752.         Sysget, M, Monitor, %Screen%
  753.         x := MLeft, y := MTop, w := MRight-MLeft, h := MBottom-MTop
  754.     }
  755.     else
  756.     {
  757.         StringSplit, S, Screen, |
  758.         x := S1, y := S2, w := S3, h := S4
  759.     }
  760.  
  761.     if (x = "") || (y = "") || (w = "") || (h = "")
  762.         return -1
  763.  
  764.     chdc := CreateCompatibleDC(), hbm := CreateDIBSection(w, h, chdc), obm := SelectObject(chdc, hbm), hhdc := hhdc ? hhdc : GetDC()
  765.     BitBlt(chdc, 0, 0, w, h, hhdc, x, y, Raster)
  766.     ReleaseDC(hhdc)
  767.    
  768.     pBitmap := Gdip_CreateBitmapFromHBITMAP(hbm)
  769.     SelectObject(chdc, obm), DeleteObject(hbm), DeleteDC(hhdc), DeleteDC(chdc)
  770.     return pBitmap
  771. }
  772.  
  773. ;#####################################################################################
  774.  
  775. ; Function              Gdip_BitmapFromHWND
  776. ; Description           Uses PrintWindow to get a handle to the specified window and return a bitmap from it
  777. ;
  778. ; hwnd                  handle to the window to get a bitmap from
  779. ;
  780. ; return                If the function succeeds, the return value is a pointer to a gdi+ bitmap
  781. ;
  782. ; notes                 Window must not be not minimised in order to get a handle to it's client area
  783.  
  784. Gdip_BitmapFromHWND(hwnd)
  785. {
  786.     WinGetPos,,, Width, Height, ahk_id %hwnd%
  787.     hbm := CreateDIBSection(Width, Height), hdc := CreateCompatibleDC(), obm := SelectObject(hdc, hbm)
  788.     PrintWindow(hwnd, hdc)
  789.     pBitmap := Gdip_CreateBitmapFromHBITMAP(hbm)
  790.     SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc)
  791.     return pBitmap
  792. }
  793.  
  794. ;#####################################################################################
  795.  
  796. ; Function              CreateRectF
  797. ; Description           Creates a RectF object, containing a the coordinates and dimensions of a rectangle
  798. ;
  799. ; RectF                 Name to call the RectF object
  800. ; x                     x-coordinate of the upper left corner of the rectangle
  801. ; y                     y-coordinate of the upper left corner of the rectangle
  802. ; w                     Width of the rectangle
  803. ; h                     Height of the rectangle
  804. ;
  805. ; return                No return value
  806.  
  807. CreateRectF(ByRef RectF, x, y, w, h)
  808. {
  809.    VarSetCapacity(RectF, 16)
  810.    NumPut(x, RectF, 0, "float"), NumPut(y, RectF, 4, "float"), NumPut(w, RectF, 8, "float"), NumPut(h, RectF, 12, "float")
  811. }
  812.  
  813. ;#####################################################################################
  814.  
  815. ; Function              CreateRect
  816. ; Description           Creates a Rect object, containing a the coordinates and dimensions of a rectangle
  817. ;
  818. ; RectF                 Name to call the RectF object
  819. ; x                     x-coordinate of the upper left corner of the rectangle
  820. ; y                     y-coordinate of the upper left corner of the rectangle
  821. ; w                     Width of the rectangle
  822. ; h                     Height of the rectangle
  823. ;
  824. ; return                No return value
  825.  
  826. CreateRect(ByRef Rect, x, y, w, h)
  827. {
  828.     VarSetCapacity(Rect, 16)
  829.     NumPut(x, Rect, 0, "uint"), NumPut(y, Rect, 4, "uint"), NumPut(w, Rect, 8, "uint"), NumPut(h, Rect, 12, "uint")
  830. }
  831. ;#####################################################################################
  832.  
  833. ; Function              CreateSizeF
  834. ; Description           Creates a SizeF object, containing an 2 values
  835. ;
  836. ; SizeF                 Name to call the SizeF object
  837. ; w                     w-value for the SizeF object
  838. ; h                     h-value for the SizeF object
  839. ;
  840. ; return                No Return value
  841.  
  842. CreateSizeF(ByRef SizeF, w, h)
  843. {
  844.    VarSetCapacity(SizeF, 8)
  845.    NumPut(w, SizeF, 0, "float"), NumPut(h, SizeF, 4, "float")    
  846. }
  847. ;#####################################################################################
  848.  
  849. ; Function              CreatePointF
  850. ; Description           Creates a SizeF object, containing an 2 values
  851. ;
  852. ; SizeF                 Name to call the SizeF object
  853. ; w                     w-value for the SizeF object
  854. ; h                     h-value for the SizeF object
  855. ;
  856. ; return                No Return value
  857.  
  858. CreatePointF(ByRef PointF, x, y)
  859. {
  860.    VarSetCapacity(PointF, 8)
  861.    NumPut(x, PointF, 0, "float"), NumPut(y, PointF, 4, "float")    
  862. }
  863. ;#####################################################################################
  864.  
  865. ; Function              CreateDIBSection
  866. ; Description           The CreateDIBSection function creates a DIB (Device Independent Bitmap) that applications can write to directly
  867. ;
  868. ; w                     width of the bitmap to create
  869. ; h                     height of the bitmap to create
  870. ; hdc                   a handle to the device context to use the palette from
  871. ; bpp                   bits per pixel (32 = ARGB)
  872. ; ppvBits               A pointer to a variable that receives a pointer to the location of the DIB bit values
  873. ;
  874. ; return                returns a DIB. A gdi bitmap
  875. ;
  876. ; notes                 ppvBits will receive the location of the pixels in the DIB
  877.  
  878. CreateDIBSection(w, h, hdc="", bpp=32, ByRef ppvBits=0)
  879. {
  880.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  881.    
  882.     hdc2 := hdc ? hdc : GetDC()
  883.     VarSetCapacity(bi, 40, 0)
  884.    
  885.     NumPut(w, bi, 4, "uint")
  886.     , NumPut(h, bi, 8, "uint")
  887.     , NumPut(40, bi, 0, "uint")
  888.     , NumPut(1, bi, 12, "ushort")
  889.     , NumPut(0, bi, 16, "uInt")
  890.     , NumPut(bpp, bi, 14, "ushort")
  891.    
  892.     hbm := DllCall("CreateDIBSection"
  893.                     , Ptr, hdc2
  894.                     , Ptr, &bi
  895.                     , "uint", 0
  896.                     , A_PtrSize ? "UPtr*" : "uint*", ppvBits
  897.                     , Ptr, 0
  898.                     , "uint", 0, Ptr)
  899.  
  900.     if !hdc
  901.         ReleaseDC(hdc2)
  902.     return hbm
  903. }
  904.  
  905. ;#####################################################################################
  906.  
  907. ; Function              PrintWindow
  908. ; Description           The PrintWindow function copies a visual window into the specified device context (DC), typically a printer DC
  909. ;
  910. ; hwnd                  A handle to the window that will be copied
  911. ; hdc                   A handle to the device context
  912. ; Flags                 Drawing options
  913. ;
  914. ; return                If the function succeeds, it returns a nonzero value
  915. ;
  916. ; PW_CLIENTONLY         = 1
  917.  
  918. PrintWindow(hwnd, hdc, Flags=0)
  919. {
  920.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  921.    
  922.     return DllCall("PrintWindow", Ptr, hwnd, Ptr, hdc, "uint", Flags)
  923. }
  924.  
  925. ;#####################################################################################
  926.  
  927. ; Function              DestroyIcon
  928. ; Description           Destroys an icon and frees any memory the icon occupied
  929. ;
  930. ; hIcon                 Handle to the icon to be destroyed. The icon must not be in use
  931. ;
  932. ; return                If the function succeeds, the return value is nonzero
  933.  
  934. DestroyIcon(hIcon)
  935. {
  936.     return DllCall("DestroyIcon", A_PtrSize ? "UPtr" : "UInt", hIcon)
  937. }
  938.  
  939. ;#####################################################################################
  940.  
  941. PaintDesktop(hdc)
  942. {
  943.     return DllCall("PaintDesktop", A_PtrSize ? "UPtr" : "UInt", hdc)
  944. }
  945.  
  946. ;#####################################################################################
  947.  
  948. CreateCompatibleBitmap(hdc, w, h)
  949. {
  950.     return DllCall("gdi32\CreateCompatibleBitmap", A_PtrSize ? "UPtr" : "UInt", hdc, "int", w, "int", h)
  951. }
  952.  
  953. ;#####################################################################################
  954.  
  955. ; Function              CreateCompatibleDC
  956. ; Description           This function creates a memory device context (DC) compatible with the specified device
  957. ;
  958. ; hdc                   Handle to an existing device context                   
  959. ;
  960. ; return                returns the handle to a device context or 0 on failure
  961. ;
  962. ; notes                 If this handle is 0 (by default), the function creates a memory device context compatible with the application's current screen
  963.  
  964. CreateCompatibleDC(hdc=0)
  965. {
  966.    return DllCall("CreateCompatibleDC", A_PtrSize ? "UPtr" : "UInt", hdc)
  967. }
  968.  
  969. ;#####################################################################################
  970.  
  971. ; Function              SelectObject
  972. ; Description           The SelectObject function selects an object into the specified device context (DC). The new object replaces the previous object of the same type
  973. ;
  974. ; hdc                   Handle to a DC
  975. ; hgdiobj               A handle to the object to be selected into the DC
  976. ;
  977. ; return                If the selected object is not a region and the function succeeds, the return value is a handle to the object being replaced
  978. ;
  979. ; notes                 The specified object must have been created by using one of the following functions
  980. ;                       Bitmap - CreateBitmap, CreateBitmapIndirect, CreateCompatibleBitmap, CreateDIBitmap, CreateDIBSection (A single bitmap cannot be selected into more than one DC at the same time)
  981. ;                       Brush - CreateBrushIndirect, CreateDIBPatternBrush, CreateDIBPatternBrushPt, CreateHatchBrush, CreatePatternBrush, CreateSolidBrush
  982. ;                       Font - CreateFont, CreateFontIndirect
  983. ;                       Pen - CreatePen, CreatePenIndirect
  984. ;                       Region - CombineRgn, CreateEllipticRgn, CreateEllipticRgnIndirect, CreatePolygonRgn, CreateRectRgn, CreateRectRgnIndirect
  985. ;
  986. ; notes                 If the selected object is a region and the function succeeds, the return value is one of the following value
  987. ;
  988. ; SIMPLEREGION          = 2 Region consists of a single rectangle
  989. ; COMPLEXREGION         = 3 Region consists of more than one rectangle
  990. ; NULLREGION            = 1 Region is empty
  991.  
  992. SelectObject(hdc, hgdiobj)
  993. {
  994.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  995.    
  996.     return DllCall("SelectObject", Ptr, hdc, Ptr, hgdiobj)
  997. }
  998.  
  999. ;#####################################################################################
  1000.  
  1001. ; Function              DeleteObject
  1002. ; Description           This function deletes a logical pen, brush, font, bitmap, region, or palette, freeing all system resources associated with the object
  1003. ;                       After the object is deleted, the specified handle is no longer valid
  1004. ;
  1005. ; hObject               Handle to a logical pen, brush, font, bitmap, region, or palette to delete
  1006. ;
  1007. ; return                Nonzero indicates success. Zero indicates that the specified handle is not valid or that the handle is currently selected into a device context
  1008.  
  1009. DeleteObject(hObject)
  1010. {
  1011.    return DllCall("DeleteObject", A_PtrSize ? "UPtr" : "UInt", hObject)
  1012. }
  1013.  
  1014. ;#####################################################################################
  1015.  
  1016. ; Function              GetDC
  1017. ; Description           This function retrieves a handle to a display device context (DC) for the client area of the specified window.
  1018. ;                       The display device context can be used in subsequent graphics display interface (GDI) functions to draw in the client area of the window.
  1019. ;
  1020. ; 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                  
  1021. ;
  1022. ; return                The handle the device context for the specified window's client area indicates success. NULL indicates failure
  1023.  
  1024. GetDC(hwnd=0)
  1025. {
  1026.     return DllCall("GetDC", A_PtrSize ? "UPtr" : "UInt", hwnd)
  1027. }
  1028.  
  1029. ;#####################################################################################
  1030.  
  1031. ; DCX_CACHE = 0x2
  1032. ; DCX_CLIPCHILDREN = 0x8
  1033. ; DCX_CLIPSIBLINGS = 0x10
  1034. ; DCX_EXCLUDERGN = 0x40
  1035. ; DCX_EXCLUDEUPDATE = 0x100
  1036. ; DCX_INTERSECTRGN = 0x80
  1037. ; DCX_INTERSECTUPDATE = 0x200
  1038. ; DCX_LOCKWINDOWUPDATE = 0x400
  1039. ; DCX_NORECOMPUTE = 0x100000
  1040. ; DCX_NORESETATTRS = 0x4
  1041. ; DCX_PARENTCLIP = 0x20
  1042. ; DCX_VALIDATE = 0x200000
  1043. ; DCX_WINDOW = 0x1
  1044.  
  1045. GetDCEx(hwnd, flags=0, hrgnClip=0)
  1046. {
  1047.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1048.    
  1049.     return DllCall("GetDCEx", Ptr, hwnd, Ptr, hrgnClip, "int", flags)
  1050. }
  1051.  
  1052. ;#####################################################################################
  1053.  
  1054. ; Function              ReleaseDC
  1055. ; 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
  1056. ;
  1057. ; hdc                   Handle to the device context to be released
  1058. ; hwnd                  Handle to the window whose device context is to be released
  1059. ;
  1060. ; return                1 = released
  1061. ;                       0 = not released
  1062. ;
  1063. ; 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
  1064. ;                       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.
  1065.  
  1066. ReleaseDC(hdc, hwnd=0)
  1067. {
  1068.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1069.    
  1070.     return DllCall("ReleaseDC", Ptr, hwnd, Ptr, hdc)
  1071. }
  1072.  
  1073. ;#####################################################################################
  1074.  
  1075. ; Function              DeleteDC
  1076. ; Description           The DeleteDC function deletes the specified device context (DC)
  1077. ;
  1078. ; hdc                   A handle to the device context
  1079. ;
  1080. ; return                If the function succeeds, the return value is nonzero
  1081. ;
  1082. ; 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
  1083.  
  1084. DeleteDC(hdc)
  1085. {
  1086.    return DllCall("DeleteDC", A_PtrSize ? "UPtr" : "UInt", hdc)
  1087. }
  1088. ;#####################################################################################
  1089.  
  1090. ; Function              Gdip_LibraryVersion
  1091. ; Description           Get the current library version
  1092. ;
  1093. ; return                the library version
  1094. ;
  1095. ; notes                 This is useful for non compiled programs to ensure that a person doesn't run an old version when testing your scripts
  1096.  
  1097. Gdip_LibraryVersion()
  1098. {
  1099.     return 1.45
  1100. }
  1101.  
  1102. ;#####################################################################################
  1103.  
  1104. ; Function              Gdip_LibrarySubVersion
  1105. ; Description           Get the current library sub version
  1106. ;
  1107. ; return                the library sub version
  1108. ;
  1109. ; notes                 This is the sub-version currently maintained by Rseding91
  1110. Gdip_LibrarySubVersion()
  1111. {
  1112.     return 1.47
  1113. }
  1114.  
  1115. ;#####################################################################################
  1116.  
  1117. ; Function:             Gdip_BitmapFromBRA
  1118. ; Description:          Gets a pointer to a gdi+ bitmap from a BRA file
  1119. ;
  1120. ; BRAFromMemIn          The variable for a BRA file read to memory
  1121. ; File                  The name of the file, or its number that you would like (This depends on alternate parameter)
  1122. ; Alternate             Changes whether the File parameter is the file name or its number
  1123. ;
  1124. ; return                If the function succeeds, the return value is a pointer to a gdi+ bitmap
  1125. ;                       -1 = The BRA variable is empty
  1126. ;                       -2 = The BRA has an incorrect header
  1127. ;                       -3 = The BRA has information missing
  1128. ;                       -4 = Could not find file inside the BRA
  1129.  
  1130. Gdip_BitmapFromBRA(ByRef BRAFromMemIn, File, Alternate=0)
  1131. {
  1132.     Static FName = "ObjRelease"
  1133.    
  1134.     if !BRAFromMemIn
  1135.         return -1
  1136.     Loop, Parse, BRAFromMemIn, `n
  1137.     {
  1138.         if (A_Index = 1)
  1139.         {
  1140.             StringSplit, Header, A_LoopField, |
  1141.             if (Header0 != 4 || Header2 != "BRA!")
  1142.                 return -2
  1143.         }
  1144.         else if (A_Index = 2)
  1145.         {
  1146.             StringSplit, Info, A_LoopField, |
  1147.             if (Info0 != 3)
  1148.                 return -3
  1149.         }
  1150.         else
  1151.             break
  1152.     }
  1153.     if !Alternate
  1154.         StringReplace, File, File, \, \\, All
  1155.     RegExMatch(BRAFromMemIn, "mi`n)^" (Alternate ? File "\|.+?\|(\d+)\|(\d+)" : "\d+\|" File "\|(\d+)\|(\d+)") "$", FileInfo)
  1156.     if !FileInfo
  1157.         return -4
  1158.    
  1159.     hData := DllCall("GlobalAlloc", "uint", 2, Ptr, FileInfo2, Ptr)
  1160.     pData := DllCall("GlobalLock", Ptr, hData, Ptr)
  1161.     DllCall("RtlMoveMemory", Ptr, pData, Ptr, &BRAFromMemIn+Info2+FileInfo1, Ptr, FileInfo2)
  1162.     DllCall("GlobalUnlock", Ptr, hData)
  1163.     DllCall("ole32\CreateStreamOnHGlobal", Ptr, hData, "int", 1, A_PtrSize ? "UPtr*" : "UInt*", pStream)
  1164.     DllCall("gdiplus\GdipCreateBitmapFromStream", Ptr, pStream, A_PtrSize ? "UPtr*" : "UInt*", pBitmap)
  1165.     If (A_PtrSize)
  1166.         %FName%(pStream)
  1167.     Else
  1168.         DllCall(NumGet(NumGet(1*pStream)+8), "uint", pStream)
  1169.     return pBitmap
  1170. }
  1171.  
  1172. ;#####################################################################################
  1173.  
  1174. ; Function              Gdip_DrawRectangle
  1175. ; Description           This function uses a pen to draw the outline of a rectangle into the Graphics of a bitmap
  1176. ;
  1177. ; pGraphics             Pointer to the Graphics of a bitmap
  1178. ; pPen                  Pointer to a pen
  1179. ; x                     x-coordinate of the top left of the rectangle
  1180. ; y                     y-coordinate of the top left of the rectangle
  1181. ; w                     width of the rectanlge
  1182. ; h                     height of the rectangle
  1183. ;
  1184. ; return                status enumeration. 0 = success
  1185. ;
  1186. ; 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
  1187.  
  1188. Gdip_DrawRectangle(pGraphics, pPen, x, y, w, h)
  1189. {
  1190.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1191.    
  1192.     return DllCall("gdiplus\GdipDrawRectangle", Ptr, pGraphics, Ptr, pPen, "float", x, "float", y, "float", w, "float", h)
  1193. }
  1194.  
  1195. ;#####################################################################################
  1196.  
  1197. ; Function              Gdip_DrawRoundedRectangle
  1198. ; Description           This function uses a pen to draw the outline of a rounded rectangle into the Graphics of a bitmap
  1199. ;
  1200. ; pGraphics             Pointer to the Graphics of a bitmap
  1201. ; pPen                  Pointer to a pen
  1202. ; x                     x-coordinate of the top left of the rounded rectangle
  1203. ; y                     y-coordinate of the top left of the rounded rectangle
  1204. ; w                     width of the rectanlge
  1205. ; h                     height of the rectangle
  1206. ; r                     radius of the rounded corners
  1207. ;
  1208. ; return                status enumeration. 0 = success
  1209. ;
  1210. ; 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
  1211.  
  1212. Gdip_DrawRoundedRectangle(pGraphics, pPen, x, y, w, h, r)
  1213. {
  1214.     Gdip_SetClipRect(pGraphics, x-r, y-r, 2*r, 2*r, 4)
  1215.     Gdip_SetClipRect(pGraphics, x+w-r, y-r, 2*r, 2*r, 4)
  1216.     Gdip_SetClipRect(pGraphics, x-r, y+h-r, 2*r, 2*r, 4)
  1217.     Gdip_SetClipRect(pGraphics, x+w-r, y+h-r, 2*r, 2*r, 4)
  1218.     E := Gdip_DrawRectangle(pGraphics, pPen, x, y, w, h)
  1219.     Gdip_ResetClip(pGraphics)
  1220.     Gdip_SetClipRect(pGraphics, x-(2*r), y+r, w+(4*r), h-(2*r), 4)
  1221.     Gdip_SetClipRect(pGraphics, x+r, y-(2*r), w-(2*r), h+(4*r), 4)
  1222.     Gdip_DrawEllipse(pGraphics, pPen, x, y, 2*r, 2*r)
  1223.     Gdip_DrawEllipse(pGraphics, pPen, x+w-(2*r), y, 2*r, 2*r)
  1224.     Gdip_DrawEllipse(pGraphics, pPen, x, y+h-(2*r), 2*r, 2*r)
  1225.     Gdip_DrawEllipse(pGraphics, pPen, x+w-(2*r), y+h-(2*r), 2*r, 2*r)
  1226.     Gdip_ResetClip(pGraphics)
  1227.     return E
  1228. }
  1229.  
  1230. ;#####################################################################################
  1231.  
  1232. ; Function              Gdip_DrawEllipse
  1233. ; Description           This function uses a pen to draw the outline of an ellipse into the Graphics of a bitmap
  1234. ;
  1235. ; pGraphics             Pointer to the Graphics of a bitmap
  1236. ; pPen                  Pointer to a pen
  1237. ; x                     x-coordinate of the top left of the rectangle the ellipse will be drawn into
  1238. ; y                     y-coordinate of the top left of the rectangle the ellipse will be drawn into
  1239. ; w                     width of the ellipse
  1240. ; h                     height of the ellipse
  1241. ;
  1242. ; return                status enumeration. 0 = success
  1243. ;
  1244. ; 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
  1245.  
  1246. Gdip_DrawEllipse(pGraphics, pPen, x, y, w, h)
  1247. {
  1248.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1249.    
  1250.     return DllCall("gdiplus\GdipDrawEllipse", Ptr, pGraphics, Ptr, pPen, "float", x, "float", y, "float", w, "float", h)
  1251. }
  1252.  
  1253. ;#####################################################################################
  1254.  
  1255. ; Function              Gdip_DrawBezier
  1256. ; Description           This function uses a pen to draw the outline of a bezier (a weighted curve) into the Graphics of a bitmap
  1257. ;
  1258. ; pGraphics             Pointer to the Graphics of a bitmap
  1259. ; pPen                  Pointer to a pen
  1260. ; x1                    x-coordinate of the start of the bezier
  1261. ; y1                    y-coordinate of the start of the bezier
  1262. ; x2                    x-coordinate of the first arc of the bezier
  1263. ; y2                    y-coordinate of the first arc of the bezier
  1264. ; x3                    x-coordinate of the second arc of the bezier
  1265. ; y3                    y-coordinate of the second arc of the bezier
  1266. ; x4                    x-coordinate of the end of the bezier
  1267. ; y4                    y-coordinate of the end of the bezier
  1268. ;
  1269. ; return                status enumeration. 0 = success
  1270. ;
  1271. ; 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
  1272.  
  1273. Gdip_DrawBezier(pGraphics, pPen, x1, y1, x2, y2, x3, y3, x4, y4)
  1274. {
  1275.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1276.    
  1277.     return DllCall("gdiplus\GdipDrawBezier"
  1278.                     , Ptr, pgraphics
  1279.                     , Ptr, pPen
  1280.                     , "float", x1
  1281.                     , "float", y1
  1282.                     , "float", x2
  1283.                     , "float", y2
  1284.                     , "float", x3
  1285.                     , "float", y3
  1286.                     , "float", x4
  1287.                     , "float", y4)
  1288. }
  1289.  
  1290. ;#####################################################################################
  1291.  
  1292. ; Function              Gdip_DrawArc
  1293. ; Description           This function uses a pen to draw the outline of an arc into the Graphics of a bitmap
  1294. ;
  1295. ; pGraphics             Pointer to the Graphics of a bitmap
  1296. ; pPen                  Pointer to a pen
  1297. ; x                     x-coordinate of the start of the arc
  1298. ; y                     y-coordinate of the start of the arc
  1299. ; w                     width of the arc
  1300. ; h                     height of the arc
  1301. ; StartAngle            specifies the angle between the x-axis and the starting point of the arc
  1302. ; SweepAngle            specifies the angle between the starting and ending points of the arc
  1303. ;
  1304. ; return                status enumeration. 0 = success
  1305. ;
  1306. ; 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
  1307.  
  1308. Gdip_DrawArc(pGraphics, pPen, x, y, w, h, StartAngle, SweepAngle)
  1309. {
  1310.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1311.    
  1312.     return DllCall("gdiplus\GdipDrawArc"
  1313.                     , Ptr, pGraphics
  1314.                     , Ptr, pPen
  1315.                     , "float", x
  1316.                     , "float", y
  1317.                     , "float", w
  1318.                     , "float", h
  1319.                     , "float", StartAngle
  1320.                     , "float", SweepAngle)
  1321. }
  1322.  
  1323. ;#####################################################################################
  1324.  
  1325. ; Function              Gdip_DrawPie
  1326. ; Description           This function uses a pen to draw the outline of a pie into the Graphics of a bitmap
  1327. ;
  1328. ; pGraphics             Pointer to the Graphics of a bitmap
  1329. ; pPen                  Pointer to a pen
  1330. ; x                     x-coordinate of the start of the pie
  1331. ; y                     y-coordinate of the start of the pie
  1332. ; w                     width of the pie
  1333. ; h                     height of the pie
  1334. ; StartAngle            specifies the angle between the x-axis and the starting point of the pie
  1335. ; SweepAngle            specifies the angle between the starting and ending points of the pie
  1336. ;
  1337. ; return                status enumeration. 0 = success
  1338. ;
  1339. ; 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
  1340.  
  1341. Gdip_DrawPie(pGraphics, pPen, x, y, w, h, StartAngle, SweepAngle)
  1342. {
  1343.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1344.    
  1345.     return DllCall("gdiplus\GdipDrawPie", Ptr, pGraphics, Ptr, pPen, "float", x, "float", y, "float", w, "float", h, "float", StartAngle, "float", SweepAngle)
  1346. }
  1347.  
  1348. ;#####################################################################################
  1349.  
  1350. ; Function              Gdip_DrawLine
  1351. ; Description           This function uses a pen to draw a line into the Graphics of a bitmap
  1352. ;
  1353. ; pGraphics             Pointer to the Graphics of a bitmap
  1354. ; pPen                  Pointer to a pen
  1355. ; x1                    x-coordinate of the start of the line
  1356. ; y1                    y-coordinate of the start of the line
  1357. ; x2                    x-coordinate of the end of the line
  1358. ; y2                    y-coordinate of the end of the line
  1359. ;
  1360. ; return                status enumeration. 0 = success    
  1361.  
  1362. Gdip_DrawLine(pGraphics, pPen, x1, y1, x2, y2)
  1363. {
  1364.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1365.    
  1366.     return DllCall("gdiplus\GdipDrawLine"
  1367.                     , Ptr, pGraphics
  1368.                     , Ptr, pPen
  1369.                     , "float", x1
  1370.                     , "float", y1
  1371.                     , "float", x2
  1372.                     , "float", y2)
  1373. }
  1374.  
  1375. ;#####################################################################################
  1376.  
  1377. ; Function              Gdip_DrawLines
  1378. ; Description           This function uses a pen to draw a series of joined lines into the Graphics of a bitmap
  1379. ;
  1380. ; pGraphics             Pointer to the Graphics of a bitmap
  1381. ; pPen                  Pointer to a pen
  1382. ; Points                the coordinates of all the points passed as x1,y1|x2,y2|x3,y3.....
  1383. ;
  1384. ; return                status enumeration. 0 = success            
  1385.  
  1386. Gdip_DrawLines(pGraphics, pPen, Points)
  1387. {
  1388.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1389.     StringSplit, Points, Points, |
  1390.     VarSetCapacity(PointF, 8*Points0)  
  1391.     Loop, %Points0%
  1392.     {
  1393.         StringSplit, Coord, Points%A_Index%, `,
  1394.         NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float")
  1395.     }
  1396.     return DllCall("gdiplus\GdipDrawLines", Ptr, pGraphics, Ptr, pPen, Ptr, &PointF, "int", Points0)
  1397. }
  1398.  
  1399. ;#####################################################################################
  1400.  
  1401. ; Function              Gdip_FillRectangle
  1402. ; Description           This function uses a brush to fill a rectangle in the Graphics of a bitmap
  1403. ;
  1404. ; pGraphics             Pointer to the Graphics of a bitmap
  1405. ; pBrush                Pointer to a brush
  1406. ; x                     x-coordinate of the top left of the rectangle
  1407. ; y                     y-coordinate of the top left of the rectangle
  1408. ; w                     width of the rectanlge
  1409. ; h                     height of the rectangle
  1410. ;
  1411. ; return                status enumeration. 0 = success
  1412.  
  1413. Gdip_FillRectangle(pGraphics, pBrush, x, y, w, h)
  1414. {
  1415.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1416.    
  1417.     return DllCall("gdiplus\GdipFillRectangle"
  1418.                     , Ptr, pGraphics
  1419.                     , Ptr, pBrush
  1420.                     , "float", x
  1421.                     , "float", y
  1422.                     , "float", w
  1423.                     , "float", h)
  1424. }
  1425.  
  1426. ;#####################################################################################
  1427.  
  1428. ; Function              Gdip_FillRoundedRectangle
  1429. ; Description           This function uses a brush to fill a rounded rectangle in the Graphics of a bitmap
  1430. ;
  1431. ; pGraphics             Pointer to the Graphics of a bitmap
  1432. ; pBrush                Pointer to a brush
  1433. ; x                     x-coordinate of the top left of the rounded rectangle
  1434. ; y                     y-coordinate of the top left of the rounded rectangle
  1435. ; w                     width of the rectanlge
  1436. ; h                     height of the rectangle
  1437. ; r                     radius of the rounded corners
  1438. ;
  1439. ; return                status enumeration. 0 = success
  1440.  
  1441. Gdip_FillRoundedRectangle(pGraphics, pBrush, x, y, w, h, r)
  1442. {
  1443.     Region := Gdip_GetClipRegion(pGraphics)
  1444.     Gdip_SetClipRect(pGraphics, x-r, y-r, 2*r, 2*r, 4)
  1445.     Gdip_SetClipRect(pGraphics, x+w-r, y-r, 2*r, 2*r, 4)
  1446.     Gdip_SetClipRect(pGraphics, x-r, y+h-r, 2*r, 2*r, 4)
  1447.     Gdip_SetClipRect(pGraphics, x+w-r, y+h-r, 2*r, 2*r, 4)
  1448.     E := Gdip_FillRectangle(pGraphics, pBrush, x, y, w, h)
  1449.     Gdip_SetClipRegion(pGraphics, Region, 0)
  1450.     Gdip_SetClipRect(pGraphics, x-(2*r), y+r, w+(4*r), h-(2*r), 4)
  1451.     Gdip_SetClipRect(pGraphics, x+r, y-(2*r), w-(2*r), h+(4*r), 4)
  1452.     Gdip_FillEllipse(pGraphics, pBrush, x, y, 2*r, 2*r)
  1453.     Gdip_FillEllipse(pGraphics, pBrush, x+w-(2*r), y, 2*r, 2*r)
  1454.     Gdip_FillEllipse(pGraphics, pBrush, x, y+h-(2*r), 2*r, 2*r)
  1455.     Gdip_FillEllipse(pGraphics, pBrush, x+w-(2*r), y+h-(2*r), 2*r, 2*r)
  1456.     Gdip_SetClipRegion(pGraphics, Region, 0)
  1457.     Gdip_DeleteRegion(Region)
  1458.     return E
  1459. }
  1460.  
  1461. ;#####################################################################################
  1462.  
  1463. ; Function              Gdip_FillPolygon
  1464. ; Description           This function uses a brush to fill a polygon in the Graphics of a bitmap
  1465. ;
  1466. ; pGraphics             Pointer to the Graphics of a bitmap
  1467. ; pBrush                Pointer to a brush
  1468. ; Points                the coordinates of all the points passed as x1,y1|x2,y2|x3,y3.....
  1469. ;
  1470. ; return                status enumeration. 0 = success
  1471. ;
  1472. ; notes                 Alternate will fill the polygon as a whole, wheras winding will fill each new "segment"
  1473. ; Alternate             = 0
  1474. ; Winding               = 1
  1475.  
  1476. Gdip_FillPolygon(pGraphics, pBrush, Points, FillMode=0)
  1477. {
  1478.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1479.    
  1480.     StringSplit, Points, Points, |
  1481.     VarSetCapacity(PointF, 8*Points0)  
  1482.     Loop, %Points0%
  1483.     {
  1484.         StringSplit, Coord, Points%A_Index%, `,
  1485.         NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float")
  1486.     }  
  1487.     return DllCall("gdiplus\GdipFillPolygon", Ptr, pGraphics, Ptr, pBrush, Ptr, &PointF, "int", Points0, "int", FillMode)
  1488. }
  1489.  
  1490. ;#####################################################################################
  1491.  
  1492. ; Function              Gdip_FillPie
  1493. ; Description           This function uses a brush to fill a pie in the Graphics of a bitmap
  1494. ;
  1495. ; pGraphics             Pointer to the Graphics of a bitmap
  1496. ; pBrush                Pointer to a brush
  1497. ; x                     x-coordinate of the top left of the pie
  1498. ; y                     y-coordinate of the top left of the pie
  1499. ; w                     width of the pie
  1500. ; h                     height of the pie
  1501. ; StartAngle            specifies the angle between the x-axis and the starting point of the pie
  1502. ; SweepAngle            specifies the angle between the starting and ending points of the pie
  1503. ;
  1504. ; return                status enumeration. 0 = success
  1505.  
  1506. Gdip_FillPie(pGraphics, pBrush, x, y, w, h, StartAngle, SweepAngle)
  1507. {
  1508.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1509.    
  1510.     return DllCall("gdiplus\GdipFillPie"
  1511.                     , Ptr, pGraphics
  1512.                     , Ptr, pBrush
  1513.                     , "float", x
  1514.                     , "float", y
  1515.                     , "float", w
  1516.                     , "float", h
  1517.                     , "float", StartAngle
  1518.                     , "float", SweepAngle)
  1519. }
  1520.  
  1521. ;#####################################################################################
  1522.  
  1523. ; Function              Gdip_FillEllipse
  1524. ; Description           This function uses a brush to fill an ellipse in the Graphics of a bitmap
  1525. ;
  1526. ; pGraphics             Pointer to the Graphics of a bitmap
  1527. ; pBrush                Pointer to a brush
  1528. ; x                     x-coordinate of the top left of the ellipse
  1529. ; y                     y-coordinate of the top left of the ellipse
  1530. ; w                     width of the ellipse
  1531. ; h                     height of the ellipse
  1532. ;
  1533. ; return                status enumeration. 0 = success
  1534.  
  1535. Gdip_FillEllipse(pGraphics, pBrush, x, y, w, h)
  1536. {
  1537.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1538.    
  1539.     return DllCall("gdiplus\GdipFillEllipse", Ptr, pGraphics, Ptr, pBrush, "float", x, "float", y, "float", w, "float", h)
  1540. }
  1541.  
  1542. ;#####################################################################################
  1543.  
  1544. ; Function              Gdip_FillRegion
  1545. ; Description           This function uses a brush to fill a region in the Graphics of a bitmap
  1546. ;
  1547. ; pGraphics             Pointer to the Graphics of a bitmap
  1548. ; pBrush                Pointer to a brush
  1549. ; Region                Pointer to a Region
  1550. ;
  1551. ; return                status enumeration. 0 = success
  1552. ;
  1553. ; notes                 You can create a region Gdip_CreateRegion() and then add to this
  1554.  
  1555. Gdip_FillRegion(pGraphics, pBrush, Region)
  1556. {
  1557.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1558.    
  1559.     return DllCall("gdiplus\GdipFillRegion", Ptr, pGraphics, Ptr, pBrush, Ptr, Region)
  1560. }
  1561.  
  1562. ;#####################################################################################
  1563.  
  1564. ; Function              Gdip_FillPath
  1565. ; Description           This function uses a brush to fill a path in the Graphics of a bitmap
  1566. ;
  1567. ; pGraphics             Pointer to the Graphics of a bitmap
  1568. ; pBrush                Pointer to a brush
  1569. ; Region                Pointer to a Path
  1570. ;
  1571. ; return                status enumeration. 0 = success
  1572.  
  1573. Gdip_FillPath(pGraphics, pBrush, Path)
  1574. {
  1575.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1576.    
  1577.     return DllCall("gdiplus\GdipFillPath", Ptr, pGraphics, Ptr, pBrush, Ptr, Path)
  1578. }
  1579.  
  1580. ;#####################################################################################
  1581.  
  1582. ; Function              Gdip_DrawImagePointsRect
  1583. ; Description           This function draws a bitmap into the Graphics of another bitmap and skews it
  1584. ;
  1585. ; pGraphics             Pointer to the Graphics of a bitmap
  1586. ; pBitmap               Pointer to a bitmap to be drawn
  1587. ; Points                Points passed as x1,y1|x2,y2|x3,y3 (3 points: top left, top right, bottom left) describing the drawing of the bitmap
  1588. ; sx                    x-coordinate of source upper-left corner
  1589. ; sy                    y-coordinate of source upper-left corner
  1590. ; sw                    width of source rectangle
  1591. ; sh                    height of source rectangle
  1592. ; Matrix                a matrix used to alter image attributes when drawing
  1593. ;
  1594. ; return                status enumeration. 0 = success
  1595. ;
  1596. ; notes                 if sx,sy,sw,sh are missed then the entire source bitmap will be used
  1597. ;                       Matrix can be omitted to just draw with no alteration to ARGB
  1598. ;                       Matrix may be passed as a digit from 0 - 1 to change just transparency
  1599. ;                       Matrix can be passed as a matrix with any delimiter
  1600.  
  1601. Gdip_DrawImagePointsRect(pGraphics, pBitmap, Points, sx="", sy="", sw="", sh="", Matrix=1)
  1602. {
  1603.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1604.    
  1605.     StringSplit, Points, Points, |
  1606.     VarSetCapacity(PointF, 8*Points0)  
  1607.     Loop, %Points0%
  1608.     {
  1609.         StringSplit, Coord, Points%A_Index%, `,
  1610.         NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float")
  1611.     }
  1612.  
  1613.     if (Matrix&1 = "")
  1614.         ImageAttr := Gdip_SetImageAttributesColorMatrix(Matrix)
  1615.     else if (Matrix != 1)
  1616.         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")
  1617.        
  1618.     if (sx = "" && sy = "" && sw = "" && sh = "")
  1619.     {
  1620.         sx := 0, sy := 0
  1621.         sw := Gdip_GetImageWidth(pBitmap)
  1622.         sh := Gdip_GetImageHeight(pBitmap)
  1623.     }
  1624.  
  1625.     E := DllCall("gdiplus\GdipDrawImagePointsRect"
  1626.                 , Ptr, pGraphics
  1627.                 , Ptr, pBitmap
  1628.                 , Ptr, &PointF
  1629.                 , "int", Points0
  1630.                 , "float", sx
  1631.                 , "float", sy
  1632.                 , "float", sw
  1633.                 , "float", sh
  1634.                 , "int", 2
  1635.                 , Ptr, ImageAttr
  1636.                 , Ptr, 0
  1637.                 , Ptr, 0)
  1638.     if ImageAttr
  1639.         Gdip_DisposeImageAttributes(ImageAttr)
  1640.     return E
  1641. }
  1642.  
  1643. ;#####################################################################################
  1644.  
  1645. ; Function              Gdip_DrawImage
  1646. ; Description           This function draws a bitmap into the Graphics of another bitmap
  1647. ;
  1648. ; pGraphics             Pointer to the Graphics of a bitmap
  1649. ; pBitmap               Pointer to a bitmap to be drawn
  1650. ; dx                    x-coord of destination upper-left corner
  1651. ; dy                    y-coord of destination upper-left corner
  1652. ; dw                    width of destination image
  1653. ; dh                    height of destination image
  1654. ; sx                    x-coordinate of source upper-left corner
  1655. ; sy                    y-coordinate of source upper-left corner
  1656. ; sw                    width of source image
  1657. ; sh                    height of source image
  1658. ; Matrix                a matrix used to alter image attributes when drawing
  1659. ;
  1660. ; return                status enumeration. 0 = success
  1661. ;
  1662. ; notes                 if sx,sy,sw,sh are missed then the entire source bitmap will be used
  1663. ;                       Gdip_DrawImage performs faster
  1664. ;                       Matrix can be omitted to just draw with no alteration to ARGB
  1665. ;                       Matrix may be passed as a digit from 0 - 1 to change just transparency
  1666. ;                       Matrix can be passed as a matrix with any delimiter. For example:
  1667. ;                       MatrixBright=
  1668. ;                       (
  1669. ;                       1.5     |0      |0      |0      |0
  1670. ;                       0       |1.5    |0      |0      |0
  1671. ;                       0       |0      |1.5    |0      |0
  1672. ;                       0       |0      |0      |1      |0
  1673. ;                       0.05    |0.05   |0.05   |0      |1
  1674. ;                       )
  1675. ;
  1676. ; 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
  1677. ;                       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
  1678. ;                       MatrixNegative = -1|0|0|0|0|0|-1|0|0|0|0|0|-1|0|0|0|0|0|1|0|0|0|0|0|1
  1679.  
  1680. Gdip_DrawImage(pGraphics, pBitmap, dx="", dy="", dw="", dh="", sx="", sy="", sw="", sh="", Matrix=1)
  1681. {
  1682.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1683.    
  1684.     if (Matrix&1 = "")
  1685.         ImageAttr := Gdip_SetImageAttributesColorMatrix(Matrix)
  1686.     else if (Matrix != 1)
  1687.         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")
  1688.  
  1689.     if (sx = "" && sy = "" && sw = "" && sh = "")
  1690.     {
  1691.         if (dx = "" && dy = "" && dw = "" && dh = "")
  1692.         {
  1693.             sx := dx := 0, sy := dy := 0
  1694.             sw := dw := Gdip_GetImageWidth(pBitmap)
  1695.             sh := dh := Gdip_GetImageHeight(pBitmap)
  1696.         }
  1697.         else
  1698.         {
  1699.             sx := sy := 0
  1700.             sw := Gdip_GetImageWidth(pBitmap)
  1701.             sh := Gdip_GetImageHeight(pBitmap)
  1702.         }
  1703.     }
  1704.  
  1705.     E := DllCall("gdiplus\GdipDrawImageRectRect"
  1706.                 , Ptr, pGraphics
  1707.                 , Ptr, pBitmap
  1708.                 , "float", dx
  1709.                 , "float", dy
  1710.                 , "float", dw
  1711.                 , "float", dh
  1712.                 , "float", sx
  1713.                 , "float", sy
  1714.                 , "float", sw
  1715.                 , "float", sh
  1716.                 , "int", 2
  1717.                 , Ptr, ImageAttr
  1718.                 , Ptr, 0
  1719.                 , Ptr, 0)
  1720.     if ImageAttr
  1721.         Gdip_DisposeImageAttributes(ImageAttr)
  1722.     return E
  1723. }
  1724.  
  1725. ;#####################################################################################
  1726.  
  1727. ; Function              Gdip_SetImageAttributesColorMatrix
  1728. ; Description           This function creates an image matrix ready for drawing
  1729. ;
  1730. ; Matrix                a matrix used to alter image attributes when drawing
  1731. ;                       passed with any delimeter
  1732. ;
  1733. ; return                returns an image matrix on sucess or 0 if it fails
  1734. ;
  1735. ; 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
  1736. ;                       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
  1737. ;                       MatrixNegative = -1|0|0|0|0|0|-1|0|0|0|0|0|-1|0|0|0|0|0|1|0|0|0|0|0|1
  1738.  
  1739. Gdip_SetImageAttributesColorMatrix(Matrix)
  1740. {
  1741.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1742.    
  1743.     VarSetCapacity(ColourMatrix, 100, 0)
  1744.     Matrix := RegExReplace(RegExReplace(Matrix, "^[^\d-\.]+([\d\.])", "$1", "", 1), "[^\d-\.]+", "|")
  1745.     StringSplit, Matrix, Matrix, |
  1746.     Loop, 25
  1747.     {
  1748.         Matrix := (Matrix%A_Index% != "") ? Matrix%A_Index% : Mod(A_Index-1, 6) ? 0 : 1
  1749.         NumPut(Matrix, ColourMatrix, (A_Index-1)*4, "float")
  1750.     }
  1751.     DllCall("gdiplus\GdipCreateImageAttributes", A_PtrSize ? "UPtr*" : "uint*", ImageAttr)
  1752.     DllCall("gdiplus\GdipSetImageAttributesColorMatrix", Ptr, ImageAttr, "int", 1, "int", 1, Ptr, &ColourMatrix, Ptr, 0, "int", 0)
  1753.     return ImageAttr
  1754. }
  1755.  
  1756. ;#####################################################################################
  1757.  
  1758. ; Function              Gdip_GraphicsFromImage
  1759. ; Description           This function gets the graphics for a bitmap used for drawing functions
  1760. ;
  1761. ; pBitmap               Pointer to a bitmap to get the pointer to its graphics
  1762. ;
  1763. ; return                returns a pointer to the graphics of a bitmap
  1764. ;
  1765. ; notes                 a bitmap can be drawn into the graphics of another bitmap
  1766.  
  1767. Gdip_GraphicsFromImage(pBitmap)
  1768. {
  1769.     DllCall("gdiplus\GdipGetImageGraphicsContext", A_PtrSize ? "UPtr" : "UInt", pBitmap, A_PtrSize ? "UPtr*" : "UInt*", pGraphics)
  1770.     return pGraphics
  1771. }
  1772.  
  1773. ;#####################################################################################
  1774.  
  1775. ; Function              Gdip_GraphicsFromHDC
  1776. ; Description           This function gets the graphics from the handle to a device context
  1777. ;
  1778. ; hdc                   This is the handle to the device context
  1779. ;
  1780. ; return                returns a pointer to the graphics of a bitmap
  1781. ;
  1782. ; notes                 You can draw a bitmap into the graphics of another bitmap
  1783.  
  1784. Gdip_GraphicsFromHDC(hdc)
  1785. {
  1786.     DllCall("gdiplus\GdipCreateFromHDC", A_PtrSize ? "UPtr" : "UInt", hdc, A_PtrSize ? "UPtr*" : "UInt*", pGraphics)
  1787.     return pGraphics
  1788. }
  1789.  
  1790. ;#####################################################################################
  1791.  
  1792. ; Function              Gdip_GetDC
  1793. ; Description           This function gets the device context of the passed Graphics
  1794. ;
  1795. ; hdc                   This is the handle to the device context
  1796. ;
  1797. ; return                returns the device context for the graphics of a bitmap
  1798.  
  1799. Gdip_GetDC(pGraphics)
  1800. {
  1801.     DllCall("gdiplus\GdipGetDC", A_PtrSize ? "UPtr" : "UInt", pGraphics, A_PtrSize ? "UPtr*" : "UInt*", hdc)
  1802.     return hdc
  1803. }
  1804.  
  1805. ;#####################################################################################
  1806.  
  1807. ; Function              Gdip_ReleaseDC
  1808. ; Description           This function releases a device context from use for further use
  1809. ;
  1810. ; pGraphics             Pointer to the graphics of a bitmap
  1811. ; hdc                   This is the handle to the device context
  1812. ;
  1813. ; return                status enumeration. 0 = success
  1814.  
  1815. Gdip_ReleaseDC(pGraphics, hdc)
  1816. {
  1817.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1818.    
  1819.     return DllCall("gdiplus\GdipReleaseDC", Ptr, pGraphics, Ptr, hdc)
  1820. }
  1821.  
  1822. ;#####################################################################################
  1823.  
  1824. ; Function              Gdip_GraphicsClear
  1825. ; Description           Clears the graphics of a bitmap ready for further drawing
  1826. ;
  1827. ; pGraphics             Pointer to the graphics of a bitmap
  1828. ; ARGB                  The colour to clear the graphics to
  1829. ;
  1830. ; return                status enumeration. 0 = success
  1831. ;
  1832. ; notes                 By default this will make the background invisible
  1833. ;                       Using clipping regions you can clear a particular area on the graphics rather than clearing the entire graphics
  1834.  
  1835. Gdip_GraphicsClear(pGraphics, ARGB=0x00ffffff)
  1836. {
  1837.     return DllCall("gdiplus\GdipGraphicsClear", A_PtrSize ? "UPtr" : "UInt", pGraphics, "int", ARGB)
  1838. }
  1839.  
  1840. ;#####################################################################################
  1841.  
  1842. ; Function              Gdip_BlurBitmap
  1843. ; Description           Gives a pointer to a blurred bitmap from a pointer to a bitmap
  1844. ;
  1845. ; pBitmap               Pointer to a bitmap to be blurred
  1846. ; Blur                  The Amount to blur a bitmap by from 1 (least blur) to 100 (most blur)
  1847. ;
  1848. ; return                If the function succeeds, the return value is a pointer to the new blurred bitmap
  1849. ;                       -1 = The blur parameter is outside the range 1-100
  1850. ;
  1851. ; notes                 This function will not dispose of the original bitmap
  1852.  
  1853. Gdip_BlurBitmap(pBitmap, Blur)
  1854. {
  1855.     if (Blur > 100) || (Blur < 1)
  1856.         return -1  
  1857.    
  1858.     sWidth := Gdip_GetImageWidth(pBitmap), sHeight := Gdip_GetImageHeight(pBitmap)
  1859.     dWidth := sWidth//Blur, dHeight := sHeight//Blur
  1860.  
  1861.     pBitmap1 := Gdip_CreateBitmap(dWidth, dHeight)
  1862.     G1 := Gdip_GraphicsFromImage(pBitmap1)
  1863.     Gdip_SetInterpolationMode(G1, 7)
  1864.     Gdip_DrawImage(G1, pBitmap, 0, 0, dWidth, dHeight, 0, 0, sWidth, sHeight)
  1865.  
  1866.     Gdip_DeleteGraphics(G1)
  1867.  
  1868.     pBitmap2 := Gdip_CreateBitmap(sWidth, sHeight)
  1869.     G2 := Gdip_GraphicsFromImage(pBitmap2)
  1870.     Gdip_SetInterpolationMode(G2, 7)
  1871.     Gdip_DrawImage(G2, pBitmap1, 0, 0, sWidth, sHeight, 0, 0, dWidth, dHeight)
  1872.  
  1873.     Gdip_DeleteGraphics(G2)
  1874.     Gdip_DisposeImage(pBitmap1)
  1875.     return pBitmap2
  1876. }
  1877.  
  1878. ;#####################################################################################
  1879.  
  1880. ; Function:             Gdip_SaveBitmapToFile
  1881. ; Description:          Saves a bitmap to a file in any supported format onto disk
  1882. ;  
  1883. ; pBitmap               Pointer to a bitmap
  1884. ; sOutput               The name of the file that the bitmap will be saved to. Supported extensions are: .BMP,.DIB,.RLE,.JPG,.JPEG,.JPE,.JFIF,.GIF,.TIF,.TIFF,.PNG
  1885. ; Quality               If saving as jpg (.JPG,.JPEG,.JPE,.JFIF) then quality can be 1-100 with default at maximum quality
  1886. ;
  1887. ; return                If the function succeeds, the return value is zero, otherwise:
  1888. ;                       -1 = Extension supplied is not a supported file format
  1889. ;                       -2 = Could not get a list of encoders on system
  1890. ;                       -3 = Could not find matching encoder for specified file format
  1891. ;                       -4 = Could not get WideChar name of output file
  1892. ;                       -5 = Could not save file to disk
  1893. ;
  1894. ; notes                 This function will use the extension supplied from the sOutput parameter to determine the output format
  1895.  
  1896. Gdip_SaveBitmapToFile(pBitmap, sOutput, Quality=75)
  1897. {
  1898.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1899.    
  1900.     SplitPath, sOutput,,, Extension
  1901.     if Extension not in BMP,DIB,RLE,JPG,JPEG,JPE,JFIF,GIF,TIF,TIFF,PNG
  1902.         return -1
  1903.     Extension := "." Extension
  1904.  
  1905.     DllCall("gdiplus\GdipGetImageEncodersSize", "uint*", nCount, "uint*", nSize)
  1906.     VarSetCapacity(ci, nSize)
  1907.     DllCall("gdiplus\GdipGetImageEncoders", "uint", nCount, "uint", nSize, Ptr, &ci)
  1908.     if !(nCount && nSize)
  1909.         return -2
  1910.    
  1911.     If (A_IsUnicode){
  1912.         StrGet_Name := "StrGet"
  1913.         Loop, %nCount%
  1914.         {
  1915.             sString := %StrGet_Name%(NumGet(ci, (idx := (48+7*A_PtrSize)*(A_Index-1))+32+3*A_PtrSize), "UTF-16")
  1916.             if !InStr(sString, "*" Extension)
  1917.                 continue
  1918.            
  1919.             pCodec := &ci+idx
  1920.             break
  1921.         }
  1922.     } else {
  1923.         Loop, %nCount%
  1924.         {
  1925.             Location := NumGet(ci, 76*(A_Index-1)+44)
  1926.             nSize := DllCall("WideCharToMultiByte", "uint", 0, "uint", 0, "uint", Location, "int", -1, "uint", 0, "int",  0, "uint", 0, "uint", 0)
  1927.             VarSetCapacity(sString, nSize)
  1928.             DllCall("WideCharToMultiByte", "uint", 0, "uint", 0, "uint", Location, "int", -1, "str", sString, "int", nSize, "uint", 0, "uint", 0)
  1929.             if !InStr(sString, "*" Extension)
  1930.                 continue
  1931.            
  1932.             pCodec := &ci+76*(A_Index-1)
  1933.             break
  1934.         }
  1935.     }
  1936.    
  1937.     if !pCodec
  1938.         return -3
  1939.  
  1940.     if (Quality != 75)
  1941.     {
  1942.         Quality := (Quality < 0) ? 0 : (Quality > 100) ? 100 : Quality
  1943.         if Extension in .JPG,.JPEG,.JPE,.JFIF
  1944.         {
  1945.             DllCall("gdiplus\GdipGetEncoderParameterListSize", Ptr, pBitmap, Ptr, pCodec, "uint*", nSize)
  1946.             VarSetCapacity(EncoderParameters, nSize, 0)
  1947.             DllCall("gdiplus\GdipGetEncoderParameterList", Ptr, pBitmap, Ptr, pCodec, "uint", nSize, Ptr, &EncoderParameters)
  1948.             Loop, % NumGet(EncoderParameters, "UInt")      ;%
  1949.             {
  1950.                 elem := (24+(A_PtrSize ? A_PtrSize : 4))*(A_Index-1) + 4 + (pad := A_PtrSize = 8 ? 4 : 0)
  1951.                 if (NumGet(EncoderParameters, elem+16, "UInt") = 1) && (NumGet(EncoderParameters, elem+20, "UInt") = 6)
  1952.                 {
  1953.                     p := elem+&EncoderParameters-pad-4
  1954.                     NumPut(Quality, NumGet(NumPut(4, NumPut(1, p+0)+20, "UInt")), "UInt")
  1955.                     break
  1956.                 }
  1957.             }      
  1958.         }
  1959.     }
  1960.  
  1961.     if (!A_IsUnicode)
  1962.     {
  1963.         nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sOutput, "int", -1, Ptr, 0, "int", 0)
  1964.         VarSetCapacity(wOutput, nSize*2)
  1965.         DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sOutput, "int", -1, Ptr, &wOutput, "int", nSize)
  1966.         VarSetCapacity(wOutput, -1)
  1967.         if !VarSetCapacity(wOutput)
  1968.             return -4
  1969.         E := DllCall("gdiplus\GdipSaveImageToFile", Ptr, pBitmap, Ptr, &wOutput, Ptr, pCodec, "uint", p ? p : 0)
  1970.     }
  1971.     else
  1972.         E := DllCall("gdiplus\GdipSaveImageToFile", Ptr, pBitmap, Ptr, &sOutput, Ptr, pCodec, "uint", p ? p : 0)
  1973.     return E ? -5 : 0
  1974. }
  1975.  
  1976. ;#####################################################################################
  1977.  
  1978. ; Function              Gdip_GetPixel
  1979. ; Description           Gets the ARGB of a pixel in a bitmap
  1980. ;
  1981. ; pBitmap               Pointer to a bitmap
  1982. ; x                     x-coordinate of the pixel
  1983. ; y                     y-coordinate of the pixel
  1984. ;
  1985. ; return                Returns the ARGB value of the pixel
  1986.  
  1987. Gdip_GetPixel(pBitmap, x, y)
  1988. {
  1989.     DllCall("gdiplus\GdipBitmapGetPixel", A_PtrSize ? "UPtr" : "UInt", pBitmap, "int", x, "int", y, "uint*", ARGB)
  1990.     return ARGB
  1991. }
  1992.  
  1993. ;#####################################################################################
  1994.  
  1995. ; Function              Gdip_SetPixel
  1996. ; Description           Sets the ARGB of a pixel in a bitmap
  1997. ;
  1998. ; pBitmap               Pointer to a bitmap
  1999. ; x                     x-coordinate of the pixel
  2000. ; y                     y-coordinate of the pixel
  2001. ;
  2002. ; return                status enumeration. 0 = success
  2003.  
  2004. Gdip_SetPixel(pBitmap, x, y, ARGB)
  2005. {
  2006.    return DllCall("gdiplus\GdipBitmapSetPixel", A_PtrSize ? "UPtr" : "UInt", pBitmap, "int", x, "int", y, "int", ARGB)
  2007. }
  2008.  
  2009. ;#####################################################################################
  2010.  
  2011. ; Function              Gdip_GetImageWidth
  2012. ; Description           Gives the width of a bitmap
  2013. ;
  2014. ; pBitmap               Pointer to a bitmap
  2015. ;
  2016. ; return                Returns the width in pixels of the supplied bitmap
  2017.  
  2018. Gdip_GetImageWidth(pBitmap)
  2019. {
  2020.    DllCall("gdiplus\GdipGetImageWidth", A_PtrSize ? "UPtr" : "UInt", pBitmap, "uint*", Width)
  2021.    return Width
  2022. }
  2023.  
  2024. ;#####################################################################################
  2025.  
  2026. ; Function              Gdip_GetImageHeight
  2027. ; Description           Gives the height of a bitmap
  2028. ;
  2029. ; pBitmap               Pointer to a bitmap
  2030. ;
  2031. ; return                Returns the height in pixels of the supplied bitmap
  2032.  
  2033. Gdip_GetImageHeight(pBitmap)
  2034. {
  2035.    DllCall("gdiplus\GdipGetImageHeight", A_PtrSize ? "UPtr" : "UInt", pBitmap, "uint*", Height)
  2036.    return Height
  2037. }
  2038.  
  2039. ;#####################################################################################
  2040.  
  2041. ; Function              Gdip_GetDimensions
  2042. ; Description           Gives the width and height of a bitmap
  2043. ;
  2044. ; pBitmap               Pointer to a bitmap
  2045. ; Width                 ByRef variable. This variable will be set to the width of the bitmap
  2046. ; Height                ByRef variable. This variable will be set to the height of the bitmap
  2047. ;
  2048. ; return                No return value
  2049. ;                       Gdip_GetDimensions(pBitmap, ThisWidth, ThisHeight) will set ThisWidth to the width and ThisHeight to the height
  2050.  
  2051. Gdip_GetImageDimensions(pBitmap, ByRef Width, ByRef Height)
  2052. {
  2053.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2054.     DllCall("gdiplus\GdipGetImageWidth", Ptr, pBitmap, "uint*", Width)
  2055.     DllCall("gdiplus\GdipGetImageHeight", Ptr, pBitmap, "uint*", Height)
  2056. }
  2057.  
  2058. ;#####################################################################################
  2059.  
  2060. Gdip_GetDimensions(pBitmap, ByRef Width, ByRef Height)
  2061. {
  2062.     Gdip_GetImageDimensions(pBitmap, Width, Height)
  2063. }
  2064.  
  2065. ;#####################################################################################
  2066.  
  2067. Gdip_GetImagePixelFormat(pBitmap)
  2068. {
  2069.     DllCall("gdiplus\GdipGetImagePixelFormat", A_PtrSize ? "UPtr" : "UInt", pBitmap, A_PtrSize ? "UPtr*" : "UInt*", Format)
  2070.     return Format
  2071. }
  2072.  
  2073. ;#####################################################################################
  2074.  
  2075. ; Function              Gdip_GetDpiX
  2076. ; Description           Gives the horizontal dots per inch of the graphics of a bitmap
  2077. ;
  2078. ; pBitmap               Pointer to a bitmap
  2079. ; Width                 ByRef variable. This variable will be set to the width of the bitmap
  2080. ; Height                ByRef variable. This variable will be set to the height of the bitmap
  2081. ;
  2082. ; return                No return value
  2083. ;                       Gdip_GetDimensions(pBitmap, ThisWidth, ThisHeight) will set ThisWidth to the width and ThisHeight to the height
  2084.  
  2085. Gdip_GetDpiX(pGraphics)
  2086. {
  2087.     DllCall("gdiplus\GdipGetDpiX", A_PtrSize ? "UPtr" : "uint", pGraphics, "float*", dpix)
  2088.     return Round(dpix)
  2089. }
  2090.  
  2091. ;#####################################################################################
  2092.  
  2093. Gdip_GetDpiY(pGraphics)
  2094. {
  2095.     DllCall("gdiplus\GdipGetDpiY", A_PtrSize ? "UPtr" : "uint", pGraphics, "float*", dpiy)
  2096.     return Round(dpiy)
  2097. }
  2098.  
  2099. ;#####################################################################################
  2100.  
  2101. Gdip_GetImageHorizontalResolution(pBitmap)
  2102. {
  2103.     DllCall("gdiplus\GdipGetImageHorizontalResolution", A_PtrSize ? "UPtr" : "uint", pBitmap, "float*", dpix)
  2104.     return Round(dpix)
  2105. }
  2106.  
  2107. ;#####################################################################################
  2108.  
  2109. Gdip_GetImageVerticalResolution(pBitmap)
  2110. {
  2111.     DllCall("gdiplus\GdipGetImageVerticalResolution", A_PtrSize ? "UPtr" : "uint", pBitmap, "float*", dpiy)
  2112.     return Round(dpiy)
  2113. }
  2114.  
  2115. ;#####################################################################################
  2116.  
  2117. Gdip_BitmapSetResolution(pBitmap, dpix, dpiy)
  2118. {
  2119.     return DllCall("gdiplus\GdipBitmapSetResolution", A_PtrSize ? "UPtr" : "uint", pBitmap, "float", dpix, "float", dpiy)
  2120. }
  2121.  
  2122. ;#####################################################################################
  2123.  
  2124. Gdip_CreateBitmapFromFile(sFile, IconNumber=1, IconSize="")
  2125. {
  2126.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2127.     , PtrA := A_PtrSize ? "UPtr*" : "UInt*"
  2128.    
  2129.     SplitPath, sFile,,, ext
  2130.     if ext in exe,dll
  2131.     {
  2132.         Sizes := IconSize ? IconSize : 256 "|" 128 "|" 64 "|" 48 "|" 32 "|" 16
  2133.         BufSize := 16 + (2*(A_PtrSize ? A_PtrSize : 4))
  2134.        
  2135.         VarSetCapacity(buf, BufSize, 0)
  2136.         Loop, Parse, Sizes, |
  2137.         {
  2138.             DllCall("PrivateExtractIcons", "str", sFile, "int", IconNumber-1, "int", A_LoopField, "int", A_LoopField, PtrA, hIcon, PtrA, 0, "uint", 1, "uint", 0)
  2139.            
  2140.             if !hIcon
  2141.                 continue
  2142.  
  2143.             if !DllCall("GetIconInfo", Ptr, hIcon, Ptr, &buf)
  2144.             {
  2145.                 DestroyIcon(hIcon)
  2146.                 continue
  2147.             }
  2148.            
  2149.             hbmMask  := NumGet(buf, 12 + ((A_PtrSize ? A_PtrSize : 4) - 4))
  2150.             hbmColor := NumGet(buf, 12 + ((A_PtrSize ? A_PtrSize : 4) - 4) + (A_PtrSize ? A_PtrSize : 4))
  2151.             if !(hbmColor && DllCall("GetObject", Ptr, hbmColor, "int", BufSize, Ptr, &buf))
  2152.             {
  2153.                 DestroyIcon(hIcon)
  2154.                 continue
  2155.             }
  2156.             break
  2157.         }
  2158.         if !hIcon
  2159.             return -1
  2160.  
  2161.         Width := NumGet(buf, 4, "int"), Height := NumGet(buf, 8, "int")
  2162.         hbm := CreateDIBSection(Width, -Height), hdc := CreateCompatibleDC(), obm := SelectObject(hdc, hbm)
  2163.         if !DllCall("DrawIconEx", Ptr, hdc, "int", 0, "int", 0, Ptr, hIcon, "uint", Width, "uint", Height, "uint", 0, Ptr, 0, "uint", 3)
  2164.         {
  2165.             DestroyIcon(hIcon)
  2166.             return -2
  2167.         }
  2168.        
  2169.         VarSetCapacity(dib, 104)
  2170.         DllCall("GetObject", Ptr, hbm, "int", A_PtrSize = 8 ? 104 : 84, Ptr, &dib) ; sizeof(DIBSECTION) = 76+2*(A_PtrSize=8?4:0)+2*A_PtrSize
  2171.         Stride := NumGet(dib, 12, "Int"), Bits := NumGet(dib, 20 + (A_PtrSize = 8 ? 4 : 0)) ; padding
  2172.         DllCall("gdiplus\GdipCreateBitmapFromScan0", "int", Width, "int", Height, "int", Stride, "int", 0x26200A, Ptr, Bits, PtrA, pBitmapOld)
  2173.         pBitmap := Gdip_CreateBitmap(Width, Height)
  2174.         G := Gdip_GraphicsFromImage(pBitmap)
  2175.         , Gdip_DrawImage(G, pBitmapOld, 0, 0, Width, Height, 0, 0, Width, Height)
  2176.         SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc)
  2177.         Gdip_DeleteGraphics(G), Gdip_DisposeImage(pBitmapOld)
  2178.         DestroyIcon(hIcon)
  2179.     }
  2180.     else
  2181.     {
  2182.         if (!A_IsUnicode)
  2183.         {
  2184.             VarSetCapacity(wFile, 1024)
  2185.             DllCall("kernel32\MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sFile, "int", -1, Ptr, &wFile, "int", 512)
  2186.             DllCall("gdiplus\GdipCreateBitmapFromFile", Ptr, &wFile, PtrA, pBitmap)
  2187.         }
  2188.         else
  2189.             DllCall("gdiplus\GdipCreateBitmapFromFile", Ptr, &sFile, PtrA, pBitmap)
  2190.     }
  2191.    
  2192.     return pBitmap
  2193. }
  2194.  
  2195. ;#####################################################################################
  2196.  
  2197. Gdip_CreateBitmapFromHBITMAP(hBitmap, Palette=0)
  2198. {
  2199.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2200.    
  2201.     DllCall("gdiplus\GdipCreateBitmapFromHBITMAP", Ptr, hBitmap, Ptr, Palette, A_PtrSize ? "UPtr*" : "uint*", pBitmap)
  2202.     return pBitmap
  2203. }
  2204.  
  2205. ;#####################################################################################
  2206.  
  2207. Gdip_CreateHBITMAPFromBitmap(pBitmap, Background=0xffffffff)
  2208. {
  2209.     DllCall("gdiplus\GdipCreateHBITMAPFromBitmap", A_PtrSize ? "UPtr" : "UInt", pBitmap, A_PtrSize ? "UPtr*" : "uint*", hbm, "int", Background)
  2210.     return hbm
  2211. }
  2212.  
  2213. ;#####################################################################################
  2214.  
  2215. Gdip_CreateBitmapFromHICON(hIcon)
  2216. {
  2217.     DllCall("gdiplus\GdipCreateBitmapFromHICON", A_PtrSize ? "UPtr" : "UInt", hIcon, A_PtrSize ? "UPtr*" : "uint*", pBitmap)
  2218.     return pBitmap
  2219. }
  2220.  
  2221. ;#####################################################################################
  2222.  
  2223. Gdip_CreateHICONFromBitmap(pBitmap)
  2224. {
  2225.     DllCall("gdiplus\GdipCreateHICONFromBitmap", A_PtrSize ? "UPtr" : "UInt", pBitmap, A_PtrSize ? "UPtr*" : "uint*", hIcon)
  2226.     return hIcon
  2227. }
  2228.  
  2229. ;#####################################################################################
  2230.  
  2231. Gdip_CreateBitmap(Width, Height, Format=0x26200A)
  2232. {
  2233.     DllCall("gdiplus\GdipCreateBitmapFromScan0", "int", Width, "int", Height, "int", 0, "int", Format, A_PtrSize ? "UPtr" : "UInt", 0, A_PtrSize ? "UPtr*" : "uint*", pBitmap)
  2234.     Return pBitmap
  2235. }
  2236.  
  2237. ;#####################################################################################
  2238.  
  2239. Gdip_CreateBitmapFromClipboard()
  2240. {
  2241.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2242.    
  2243.     if !DllCall("OpenClipboard", Ptr, 0)
  2244.         return -1
  2245.     if !DllCall("IsClipboardFormatAvailable", "uint", 8)
  2246.         return -2
  2247.     if !hBitmap := DllCall("GetClipboardData", "uint", 2, Ptr)
  2248.         return -3
  2249.     if !pBitmap := Gdip_CreateBitmapFromHBITMAP(hBitmap)
  2250.         return -4
  2251.     if !DllCall("CloseClipboard")
  2252.         return -5
  2253.     DeleteObject(hBitmap)
  2254.     return pBitmap
  2255. }
  2256.  
  2257. ;#####################################################################################
  2258.  
  2259. Gdip_SetBitmapToClipboard(pBitmap)
  2260. {
  2261.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2262.     off1 := A_PtrSize = 8 ? 52 : 44, off2 := A_PtrSize = 8 ? 32 : 24
  2263.     hBitmap := Gdip_CreateHBITMAPFromBitmap(pBitmap)
  2264.     DllCall("GetObject", Ptr, hBitmap, "int", VarSetCapacity(oi, A_PtrSize = 8 ? 104 : 84, 0), Ptr, &oi)
  2265.     hdib := DllCall("GlobalAlloc", "uint", 2, Ptr, 40+NumGet(oi, off1, "UInt"), Ptr)
  2266.     pdib := DllCall("GlobalLock", Ptr, hdib, Ptr)
  2267.     DllCall("RtlMoveMemory", Ptr, pdib, Ptr, &oi+off2, Ptr, 40)
  2268.     DllCall("RtlMoveMemory", Ptr, pdib+40, Ptr, NumGet(oi, off2 - (A_PtrSize ? A_PtrSize : 4), Ptr), Ptr, NumGet(oi, off1, "UInt"))
  2269.     DllCall("GlobalUnlock", Ptr, hdib)
  2270.     DllCall("DeleteObject", Ptr, hBitmap)
  2271.     DllCall("OpenClipboard", Ptr, 0)
  2272.     DllCall("EmptyClipboard")
  2273.     DllCall("SetClipboardData", "uint", 8, Ptr, hdib)
  2274.     DllCall("CloseClipboard")
  2275. }
  2276.  
  2277. ;#####################################################################################
  2278.  
  2279. Gdip_CloneBitmapArea(pBitmap, x, y, w, h, Format=0x26200A)
  2280. {
  2281.     DllCall("gdiplus\GdipCloneBitmapArea"
  2282.                     , "float", x
  2283.                     , "float", y
  2284.                     , "float", w
  2285.                     , "float", h
  2286.                     , "int", Format
  2287.                     , A_PtrSize ? "UPtr" : "UInt", pBitmap
  2288.                     , A_PtrSize ? "UPtr*" : "UInt*", pBitmapDest)
  2289.     return pBitmapDest
  2290. }
  2291.  
  2292. ;#####################################################################################
  2293. ; Create resources
  2294. ;#####################################################################################
  2295.  
  2296. Gdip_CreatePen(ARGB, w)
  2297. {
  2298.    DllCall("gdiplus\GdipCreatePen1", "UInt", ARGB, "float", w, "int", 2, A_PtrSize ? "UPtr*" : "UInt*", pPen)
  2299.    return pPen
  2300. }
  2301.  
  2302. ;#####################################################################################
  2303.  
  2304. Gdip_CreatePenFromBrush(pBrush, w)
  2305. {
  2306.     DllCall("gdiplus\GdipCreatePen2", A_PtrSize ? "UPtr" : "UInt", pBrush, "float", w, "int", 2, A_PtrSize ? "UPtr*" : "UInt*", pPen)
  2307.     return pPen
  2308. }
  2309.  
  2310. ;#####################################################################################
  2311.  
  2312. Gdip_BrushCreateSolid(ARGB=0xff000000)
  2313. {
  2314.     DllCall("gdiplus\GdipCreateSolidFill", "UInt", ARGB, A_PtrSize ? "UPtr*" : "UInt*", pBrush)
  2315.     return pBrush
  2316. }
  2317.  
  2318. ;#####################################################################################
  2319.  
  2320. ; HatchStyleHorizontal = 0
  2321. ; HatchStyleVertical = 1
  2322. ; HatchStyleForwardDiagonal = 2
  2323. ; HatchStyleBackwardDiagonal = 3
  2324. ; HatchStyleCross = 4
  2325. ; HatchStyleDiagonalCross = 5
  2326. ; HatchStyle05Percent = 6
  2327. ; HatchStyle10Percent = 7
  2328. ; HatchStyle20Percent = 8
  2329. ; HatchStyle25Percent = 9
  2330. ; HatchStyle30Percent = 10
  2331. ; HatchStyle40Percent = 11
  2332. ; HatchStyle50Percent = 12
  2333. ; HatchStyle60Percent = 13
  2334. ; HatchStyle70Percent = 14
  2335. ; HatchStyle75Percent = 15
  2336. ; HatchStyle80Percent = 16
  2337. ; HatchStyle90Percent = 17
  2338. ; HatchStyleLightDownwardDiagonal = 18
  2339. ; HatchStyleLightUpwardDiagonal = 19
  2340. ; HatchStyleDarkDownwardDiagonal = 20
  2341. ; HatchStyleDarkUpwardDiagonal = 21
  2342. ; HatchStyleWideDownwardDiagonal = 22
  2343. ; HatchStyleWideUpwardDiagonal = 23
  2344. ; HatchStyleLightVertical = 24
  2345. ; HatchStyleLightHorizontal = 25
  2346. ; HatchStyleNarrowVertical = 26
  2347. ; HatchStyleNarrowHorizontal = 27
  2348. ; HatchStyleDarkVertical = 28
  2349. ; HatchStyleDarkHorizontal = 29
  2350. ; HatchStyleDashedDownwardDiagonal = 30
  2351. ; HatchStyleDashedUpwardDiagonal = 31
  2352. ; HatchStyleDashedHorizontal = 32
  2353. ; HatchStyleDashedVertical = 33
  2354. ; HatchStyleSmallConfetti = 34
  2355. ; HatchStyleLargeConfetti = 35
  2356. ; HatchStyleZigZag = 36
  2357. ; HatchStyleWave = 37
  2358. ; HatchStyleDiagonalBrick = 38
  2359. ; HatchStyleHorizontalBrick = 39
  2360. ; HatchStyleWeave = 40
  2361. ; HatchStylePlaid = 41
  2362. ; HatchStyleDivot = 42
  2363. ; HatchStyleDottedGrid = 43
  2364. ; HatchStyleDottedDiamond = 44
  2365. ; HatchStyleShingle = 45
  2366. ; HatchStyleTrellis = 46
  2367. ; HatchStyleSphere = 47
  2368. ; HatchStyleSmallGrid = 48
  2369. ; HatchStyleSmallCheckerBoard = 49
  2370. ; HatchStyleLargeCheckerBoard = 50
  2371. ; HatchStyleOutlinedDiamond = 51
  2372. ; HatchStyleSolidDiamond = 52
  2373. ; HatchStyleTotal = 53
  2374. Gdip_BrushCreateHatch(ARGBfront, ARGBback, HatchStyle=0)
  2375. {
  2376.     DllCall("gdiplus\GdipCreateHatchBrush", "int", HatchStyle, "UInt", ARGBfront, "UInt", ARGBback, A_PtrSize ? "UPtr*" : "UInt*", pBrush)
  2377.     return pBrush
  2378. }
  2379.  
  2380. ;#####################################################################################
  2381.  
  2382. Gdip_CreateTextureBrush(pBitmap, WrapMode=1, x=0, y=0, w="", h="")
  2383. {
  2384.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2385.     , PtrA := A_PtrSize ? "UPtr*" : "UInt*"
  2386.    
  2387.     if !(w && h)
  2388.         DllCall("gdiplus\GdipCreateTexture", Ptr, pBitmap, "int", WrapMode, PtrA, pBrush)
  2389.     else
  2390.         DllCall("gdiplus\GdipCreateTexture2", Ptr, pBitmap, "int", WrapMode, "float", x, "float", y, "float", w, "float", h, PtrA, pBrush)
  2391.     return pBrush
  2392. }
  2393.  
  2394. ;#####################################################################################
  2395.  
  2396. ; WrapModeTile = 0
  2397. ; WrapModeTileFlipX = 1
  2398. ; WrapModeTileFlipY = 2
  2399. ; WrapModeTileFlipXY = 3
  2400. ; WrapModeClamp = 4
  2401. Gdip_CreateLineBrush(x1, y1, x2, y2, ARGB1, ARGB2, WrapMode=1)
  2402. {
  2403.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2404.    
  2405.     CreatePointF(PointF1, x1, y1), CreatePointF(PointF2, x2, y2)
  2406.     DllCall("gdiplus\GdipCreateLineBrush", Ptr, &PointF1, Ptr, &PointF2, "Uint", ARGB1, "Uint", ARGB2, "int", WrapMode, A_PtrSize ? "UPtr*" : "UInt*", LGpBrush)
  2407.     return LGpBrush
  2408. }
  2409.  
  2410. ;#####################################################################################
  2411.  
  2412. ; LinearGradientModeHorizontal = 0
  2413. ; LinearGradientModeVertical = 1
  2414. ; LinearGradientModeForwardDiagonal = 2
  2415. ; LinearGradientModeBackwardDiagonal = 3
  2416. Gdip_CreateLineBrushFromRect(x, y, w, h, ARGB1, ARGB2, LinearGradientMode=1, WrapMode=1)
  2417. {
  2418.     CreateRectF(RectF, x, y, w, h)
  2419.     DllCall("gdiplus\GdipCreateLineBrushFromRect", A_PtrSize ? "UPtr" : "UInt", &RectF, "int", ARGB1, "int", ARGB2, "int", LinearGradientMode, "int", WrapMode, A_PtrSize ? "UPtr*" : "UInt*", LGpBrush)
  2420.     return LGpBrush
  2421. }
  2422.  
  2423. ;#####################################################################################
  2424.  
  2425. Gdip_CloneBrush(pBrush)
  2426. {
  2427.     DllCall("gdiplus\GdipCloneBrush", A_PtrSize ? "UPtr" : "UInt", pBrush, A_PtrSize ? "UPtr*" : "UInt*", pBrushClone)
  2428.     return pBrushClone
  2429. }
  2430.  
  2431. ;#####################################################################################
  2432. ; Delete resources
  2433. ;#####################################################################################
  2434.  
  2435. Gdip_DeletePen(pPen)
  2436. {
  2437.    return DllCall("gdiplus\GdipDeletePen", A_PtrSize ? "UPtr" : "UInt", pPen)
  2438. }
  2439.  
  2440. ;#####################################################################################
  2441.  
  2442. Gdip_DeleteBrush(pBrush)
  2443. {
  2444.    return DllCall("gdiplus\GdipDeleteBrush", A_PtrSize ? "UPtr" : "UInt", pBrush)
  2445. }
  2446.  
  2447. ;#####################################################################################
  2448.  
  2449. Gdip_DisposeImage(pBitmap)
  2450. {
  2451.    return DllCall("gdiplus\GdipDisposeImage", A_PtrSize ? "UPtr" : "UInt", pBitmap)
  2452. }
  2453.  
  2454. ;#####################################################################################
  2455.  
  2456. Gdip_DeleteGraphics(pGraphics)
  2457. {
  2458.    return DllCall("gdiplus\GdipDeleteGraphics", A_PtrSize ? "UPtr" : "UInt", pGraphics)
  2459. }
  2460.  
  2461. ;#####################################################################################
  2462.  
  2463. Gdip_DisposeImageAttributes(ImageAttr)
  2464. {
  2465.     return DllCall("gdiplus\GdipDisposeImageAttributes", A_PtrSize ? "UPtr" : "UInt", ImageAttr)
  2466. }
  2467.  
  2468. ;#####################################################################################
  2469.  
  2470. Gdip_DeleteFont(hFont)
  2471. {
  2472.    return DllCall("gdiplus\GdipDeleteFont", A_PtrSize ? "UPtr" : "UInt", hFont)
  2473. }
  2474.  
  2475. ;#####################################################################################
  2476.  
  2477. Gdip_DeleteStringFormat(hFormat)
  2478. {
  2479.    return DllCall("gdiplus\GdipDeleteStringFormat", A_PtrSize ? "UPtr" : "UInt", hFormat)
  2480. }
  2481.  
  2482. ;#####################################################################################
  2483.  
  2484. Gdip_DeleteFontFamily(hFamily)
  2485. {
  2486.    return DllCall("gdiplus\GdipDeleteFontFamily", A_PtrSize ? "UPtr" : "UInt", hFamily)
  2487. }
  2488.  
  2489. ;#####################################################################################
  2490.  
  2491. Gdip_DeleteMatrix(Matrix)
  2492. {
  2493.    return DllCall("gdiplus\GdipDeleteMatrix", A_PtrSize ? "UPtr" : "UInt", Matrix)
  2494. }
  2495.  
  2496. ;#####################################################################################
  2497. ; Text functions
  2498. ;#####################################################################################
  2499.  
  2500. Gdip_TextToGraphics(pGraphics, Text, Options, Font="Arial", Width="", Height="", Measure=0)
  2501. {
  2502.     IWidth := Width, IHeight:= Height
  2503.    
  2504.     RegExMatch(Options, "i)X([\-\d\.]+)(p*)", xpos)
  2505.     RegExMatch(Options, "i)Y([\-\d\.]+)(p*)", ypos)
  2506.     RegExMatch(Options, "i)W([\-\d\.]+)(p*)", Width)
  2507.     RegExMatch(Options, "i)H([\-\d\.]+)(p*)", Height)
  2508.     RegExMatch(Options, "i)C(?!(entre|enter))([a-f\d]+)", Colour)
  2509.     RegExMatch(Options, "i)Top|Up|Bottom|Down|vCentre|vCenter", vPos)
  2510.     RegExMatch(Options, "i)NoWrap", NoWrap)
  2511.     RegExMatch(Options, "i)R(\d)", Rendering)
  2512.     RegExMatch(Options, "i)S(\d+)(p*)", Size)
  2513.  
  2514.     if !Gdip_DeleteBrush(Gdip_CloneBrush(Colour2))
  2515.         PassBrush := 1, pBrush := Colour2
  2516.    
  2517.     if !(IWidth && IHeight) && (xpos2 || ypos2 || Width2 || Height2 || Size2)
  2518.         return -1
  2519.  
  2520.     Style := 0, Styles := "Regular|Bold|Italic|BoldItalic|Underline|Strikeout"
  2521.     Loop, Parse, Styles, |
  2522.     {
  2523.         if RegExMatch(Options, "\b" A_loopField)
  2524.         Style |= (A_LoopField != "StrikeOut") ? (A_Index-1) : 8
  2525.     }
  2526.  
  2527.     Align := 0, Alignments := "Near|Left|Centre|Center|Far|Right"
  2528.     Loop, Parse, Alignments, |
  2529.     {
  2530.         if RegExMatch(Options, "\b" A_loopField)
  2531.             Align |= A_Index//2.1      ; 0|0|1|1|2|2
  2532.     }
  2533.  
  2534.     xpos := (xpos1 != "") ? xpos2 ? IWidth*(xpos1/100) : xpos1 : 0
  2535.     ypos := (ypos1 != "") ? ypos2 ? IHeight*(ypos1/100) : ypos1 : 0
  2536.     Width := Width1 ? Width2 ? IWidth*(Width1/100) : Width1 : IWidth
  2537.     Height := Height1 ? Height2 ? IHeight*(Height1/100) : Height1 : IHeight
  2538.     if !PassBrush
  2539.         Colour := "0x" (Colour2 ? Colour2 : "ff000000")
  2540.     Rendering := ((Rendering1 >= 0) && (Rendering1 <= 5)) ? Rendering1 : 4
  2541.     Size := (Size1 > 0) ? Size2 ? IHeight*(Size1/100) : Size1 : 12
  2542.  
  2543.     hFamily := Gdip_FontFamilyCreate(Font)
  2544.     hFont := Gdip_FontCreate(hFamily, Size, Style)
  2545.     FormatStyle := NoWrap ? 0x4000 | 0x1000 : 0x4000
  2546.     hFormat := Gdip_StringFormatCreate(FormatStyle)
  2547.     pBrush := PassBrush ? pBrush : Gdip_BrushCreateSolid(Colour)
  2548.     if !(hFamily && hFont && hFormat && pBrush && pGraphics)
  2549.         return !pGraphics ? -2 : !hFamily ? -3 : !hFont ? -4 : !hFormat ? -5 : !pBrush ? -6 : 0
  2550.    
  2551.     CreateRectF(RC, xpos, ypos, Width, Height)
  2552.     Gdip_SetStringFormatAlign(hFormat, Align)
  2553.     Gdip_SetTextRenderingHint(pGraphics, Rendering)
  2554.     ReturnRC := Gdip_MeasureString(pGraphics, Text, hFont, hFormat, RC)
  2555.  
  2556.     if vPos
  2557.     {
  2558.         StringSplit, ReturnRC, ReturnRC, |
  2559.        
  2560.         if (vPos = "vCentre") || (vPos = "vCenter")
  2561.             ypos += (Height-ReturnRC4)//2
  2562.         else if (vPos = "Top") || (vPos = "Up")
  2563.             ypos := 0
  2564.         else if (vPos = "Bottom") || (vPos = "Down")
  2565.             ypos := Height-ReturnRC4
  2566.        
  2567.         CreateRectF(RC, xpos, ypos, Width, ReturnRC4)
  2568.         ReturnRC := Gdip_MeasureString(pGraphics, Text, hFont, hFormat, RC)
  2569.     }
  2570.  
  2571.     if !Measure
  2572.         E := Gdip_DrawString(pGraphics, Text, hFont, hFormat, pBrush, RC)
  2573.  
  2574.     if !PassBrush
  2575.         Gdip_DeleteBrush(pBrush)
  2576.     Gdip_DeleteStringFormat(hFormat)  
  2577.     Gdip_DeleteFont(hFont)
  2578.     Gdip_DeleteFontFamily(hFamily)
  2579.     return E ? E : ReturnRC
  2580. }
  2581.  
  2582. ;#####################################################################################
  2583.  
  2584. Gdip_DrawString(pGraphics, sString, hFont, hFormat, pBrush, ByRef RectF)
  2585. {
  2586.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2587.    
  2588.     if (!A_IsUnicode)
  2589.     {
  2590.         nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sString, "int", -1, Ptr, 0, "int", 0)
  2591.         VarSetCapacity(wString, nSize*2)
  2592.         DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sString, "int", -1, Ptr, &wString, "int", nSize)
  2593.     }
  2594.    
  2595.     return DllCall("gdiplus\GdipDrawString"
  2596.                     , Ptr, pGraphics
  2597.                     , Ptr, A_IsUnicode ? &sString : &wString
  2598.                     , "int", -1
  2599.                     , Ptr, hFont
  2600.                     , Ptr, &RectF
  2601.                     , Ptr, hFormat
  2602.                     , Ptr, pBrush)
  2603. }
  2604.  
  2605. ;#####################################################################################
  2606.  
  2607. Gdip_MeasureString(pGraphics, sString, hFont, hFormat, ByRef RectF)
  2608. {
  2609.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2610.    
  2611.     VarSetCapacity(RC, 16)
  2612.     if !A_IsUnicode
  2613.     {
  2614.         nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sString, "int", -1, "uint", 0, "int", 0)
  2615.         VarSetCapacity(wString, nSize*2)  
  2616.         DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sString, "int", -1, Ptr, &wString, "int", nSize)
  2617.     }
  2618.    
  2619.     DllCall("gdiplus\GdipMeasureString"
  2620.                     , Ptr, pGraphics
  2621.                     , Ptr, A_IsUnicode ? &sString : &wString
  2622.                     , "int", -1
  2623.                     , Ptr, hFont
  2624.                     , Ptr, &RectF
  2625.                     , Ptr, hFormat
  2626.                     , Ptr, &RC
  2627.                     , "uint*", Chars
  2628.                     , "uint*", Lines)
  2629.    
  2630.     return &RC ? NumGet(RC, 0, "float") "|" NumGet(RC, 4, "float") "|" NumGet(RC, 8, "float") "|" NumGet(RC, 12, "float") "|" Chars "|" Lines : 0
  2631. }
  2632.  
  2633. ; Near = 0
  2634. ; Center = 1
  2635. ; Far = 2
  2636. Gdip_SetStringFormatAlign(hFormat, Align)
  2637. {
  2638.    return DllCall("gdiplus\GdipSetStringFormatAlign", A_PtrSize ? "UPtr" : "UInt", hFormat, "int", Align)
  2639. }
  2640.  
  2641. ; StringFormatFlagsDirectionRightToLeft    = 0x00000001
  2642. ; StringFormatFlagsDirectionVertical       = 0x00000002
  2643. ; StringFormatFlagsNoFitBlackBox           = 0x00000004
  2644. ; StringFormatFlagsDisplayFormatControl    = 0x00000020
  2645. ; StringFormatFlagsNoFontFallback          = 0x00000400
  2646. ; StringFormatFlagsMeasureTrailingSpaces   = 0x00000800
  2647. ; StringFormatFlagsNoWrap                  = 0x00001000
  2648. ; StringFormatFlagsLineLimit               = 0x00002000
  2649. ; StringFormatFlagsNoClip                  = 0x00004000
  2650. Gdip_StringFormatCreate(Format=0, Lang=0)
  2651. {
  2652.    DllCall("gdiplus\GdipCreateStringFormat", "int", Format, "int", Lang, A_PtrSize ? "UPtr*" : "UInt*", hFormat)
  2653.    return hFormat
  2654. }
  2655.  
  2656. ; Regular = 0
  2657. ; Bold = 1
  2658. ; Italic = 2
  2659. ; BoldItalic = 3
  2660. ; Underline = 4
  2661. ; Strikeout = 8
  2662. Gdip_FontCreate(hFamily, Size, Style=0)
  2663. {
  2664.    DllCall("gdiplus\GdipCreateFont", A_PtrSize ? "UPtr" : "UInt", hFamily, "float", Size, "int", Style, "int", 0, A_PtrSize ? "UPtr*" : "UInt*", hFont)
  2665.    return hFont
  2666. }
  2667.  
  2668. Gdip_FontFamilyCreate(Font)
  2669. {
  2670.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2671.    
  2672.     if (!A_IsUnicode)
  2673.     {
  2674.         nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &Font, "int", -1, "uint", 0, "int", 0)
  2675.         VarSetCapacity(wFont, nSize*2)
  2676.         DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &Font, "int", -1, Ptr, &wFont, "int", nSize)
  2677.     }
  2678.    
  2679.     DllCall("gdiplus\GdipCreateFontFamilyFromName"
  2680.                     , Ptr, A_IsUnicode ? &Font : &wFont
  2681.                     , "uint", 0
  2682.                     , A_PtrSize ? "UPtr*" : "UInt*", hFamily)
  2683.    
  2684.     return hFamily
  2685. }
  2686.  
  2687. ;#####################################################################################
  2688. ; Matrix functions
  2689. ;#####################################################################################
  2690.  
  2691. Gdip_CreateAffineMatrix(m11, m12, m21, m22, x, y)
  2692. {
  2693.    DllCall("gdiplus\GdipCreateMatrix2", "float", m11, "float", m12, "float", m21, "float", m22, "float", x, "float", y, A_PtrSize ? "UPtr*" : "UInt*", Matrix)
  2694.    return Matrix
  2695. }
  2696.  
  2697. Gdip_CreateMatrix()
  2698. {
  2699.    DllCall("gdiplus\GdipCreateMatrix", A_PtrSize ? "UPtr*" : "UInt*", Matrix)
  2700.    return Matrix
  2701. }
  2702.  
  2703. ;#####################################################################################
  2704. ; GraphicsPath functions
  2705. ;#####################################################################################
  2706.  
  2707. ; Alternate = 0
  2708. ; Winding = 1
  2709. Gdip_CreatePath(BrushMode=0)
  2710. {
  2711.     DllCall("gdiplus\GdipCreatePath", "int", BrushMode, A_PtrSize ? "UPtr*" : "UInt*", Path)
  2712.     return Path
  2713. }
  2714.  
  2715. Gdip_AddPathEllipse(Path, x, y, w, h)
  2716. {
  2717.     return DllCall("gdiplus\GdipAddPathEllipse", A_PtrSize ? "UPtr" : "UInt", Path, "float", x, "float", y, "float", w, "float", h)
  2718. }
  2719.  
  2720. Gdip_AddPathPolygon(Path, Points)
  2721. {
  2722.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2723.    
  2724.     StringSplit, Points, Points, |
  2725.     VarSetCapacity(PointF, 8*Points0)  
  2726.     Loop, %Points0%
  2727.     {
  2728.         StringSplit, Coord, Points%A_Index%, `,
  2729.         NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float")
  2730.     }  
  2731.  
  2732.     return DllCall("gdiplus\GdipAddPathPolygon", Ptr, Path, Ptr, &PointF, "int", Points0)
  2733. }
  2734.  
  2735. Gdip_DeletePath(Path)
  2736. {
  2737.     return DllCall("gdiplus\GdipDeletePath", A_PtrSize ? "UPtr" : "UInt", Path)
  2738. }
  2739.  
  2740. ;#####################################################################################
  2741. ; Quality functions
  2742. ;#####################################################################################
  2743.  
  2744. ; SystemDefault = 0
  2745. ; SingleBitPerPixelGridFit = 1
  2746. ; SingleBitPerPixel = 2
  2747. ; AntiAliasGridFit = 3
  2748. ; AntiAlias = 4
  2749. Gdip_SetTextRenderingHint(pGraphics, RenderingHint)
  2750. {
  2751.     return DllCall("gdiplus\GdipSetTextRenderingHint", A_PtrSize ? "UPtr" : "UInt", pGraphics, "int", RenderingHint)
  2752. }
  2753.  
  2754. ; Default = 0
  2755. ; LowQuality = 1
  2756. ; HighQuality = 2
  2757. ; Bilinear = 3
  2758. ; Bicubic = 4
  2759. ; NearestNeighbor = 5
  2760. ; HighQualityBilinear = 6
  2761. ; HighQualityBicubic = 7
  2762. Gdip_SetInterpolationMode(pGraphics, InterpolationMode)
  2763. {
  2764.    return DllCall("gdiplus\GdipSetInterpolationMode", A_PtrSize ? "UPtr" : "UInt", pGraphics, "int", InterpolationMode)
  2765. }
  2766.  
  2767. ; Default = 0
  2768. ; HighSpeed = 1
  2769. ; HighQuality = 2
  2770. ; None = 3
  2771. ; AntiAlias = 4
  2772. Gdip_SetSmoothingMode(pGraphics, SmoothingMode)
  2773. {
  2774.    return DllCall("gdiplus\GdipSetSmoothingMode", A_PtrSize ? "UPtr" : "UInt", pGraphics, "int", SmoothingMode)
  2775. }
  2776.  
  2777. ; CompositingModeSourceOver = 0 (blended)
  2778. ; CompositingModeSourceCopy = 1 (overwrite)
  2779. Gdip_SetCompositingMode(pGraphics, CompositingMode=0)
  2780. {
  2781.    return DllCall("gdiplus\GdipSetCompositingMode", A_PtrSize ? "UPtr" : "UInt", pGraphics, "int", CompositingMode)
  2782. }
  2783.  
  2784. ;#####################################################################################
  2785. ; Extra functions
  2786. ;#####################################################################################
  2787.  
  2788. Gdip_Startup()
  2789. {
  2790.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2791.    
  2792.     if !DllCall("GetModuleHandle", "str", "gdiplus", Ptr)
  2793.         DllCall("LoadLibrary", "str", "gdiplus")
  2794.     VarSetCapacity(si, A_PtrSize = 8 ? 24 : 16, 0), si := Chr(1)
  2795.     DllCall("gdiplus\GdiplusStartup", A_PtrSize ? "UPtr*" : "uint*", pToken, Ptr, &si, Ptr, 0)
  2796.     return pToken
  2797. }
  2798.  
  2799. Gdip_Shutdown(pToken)
  2800. {
  2801.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2802.    
  2803.     DllCall("gdiplus\GdiplusShutdown", Ptr, pToken)
  2804.     if hModule := DllCall("GetModuleHandle", "str", "gdiplus", Ptr)
  2805.         DllCall("FreeLibrary", Ptr, hModule)
  2806.     return 0
  2807. }
  2808.  
  2809. ; Prepend = 0; The new operation is applied before the old operation.
  2810. ; Append = 1; The new operation is applied after the old operation.
  2811. Gdip_RotateWorldTransform(pGraphics, Angle, MatrixOrder=0)
  2812. {
  2813.     return DllCall("gdiplus\GdipRotateWorldTransform", A_PtrSize ? "UPtr" : "UInt", pGraphics, "float", Angle, "int", MatrixOrder)
  2814. }
  2815.  
  2816. Gdip_ScaleWorldTransform(pGraphics, x, y, MatrixOrder=0)
  2817. {
  2818.     return DllCall("gdiplus\GdipScaleWorldTransform", A_PtrSize ? "UPtr" : "UInt", pGraphics, "float", x, "float", y, "int", MatrixOrder)
  2819. }
  2820.  
  2821. Gdip_TranslateWorldTransform(pGraphics, x, y, MatrixOrder=0)
  2822. {
  2823.     return DllCall("gdiplus\GdipTranslateWorldTransform", A_PtrSize ? "UPtr" : "UInt", pGraphics, "float", x, "float", y, "int", MatrixOrder)
  2824. }
  2825.  
  2826. Gdip_ResetWorldTransform(pGraphics)
  2827. {
  2828.     return DllCall("gdiplus\GdipResetWorldTransform", A_PtrSize ? "UPtr" : "UInt", pGraphics)
  2829. }
  2830.  
  2831. Gdip_GetRotatedTranslation(Width, Height, Angle, ByRef xTranslation, ByRef yTranslation)
  2832. {
  2833.     pi := 3.14159, TAngle := Angle*(pi/180)
  2834.  
  2835.     Bound := (Angle >= 0) ? Mod(Angle, 360) : 360-Mod(-Angle, -360)
  2836.     if ((Bound >= 0) && (Bound <= 90))
  2837.         xTranslation := Height*Sin(TAngle), yTranslation := 0
  2838.     else if ((Bound > 90) && (Bound <= 180))
  2839.         xTranslation := (Height*Sin(TAngle))-(Width*Cos(TAngle)), yTranslation := -Height*Cos(TAngle)
  2840.     else if ((Bound > 180) && (Bound <= 270))
  2841.         xTranslation := -(Width*Cos(TAngle)), yTranslation := -(Height*Cos(TAngle))-(Width*Sin(TAngle))
  2842.     else if ((Bound > 270) && (Bound <= 360))
  2843.         xTranslation := 0, yTranslation := -Width*Sin(TAngle)
  2844. }
  2845.  
  2846. Gdip_GetRotatedDimensions(Width, Height, Angle, ByRef RWidth, ByRef RHeight)
  2847. {
  2848.     pi := 3.14159, TAngle := Angle*(pi/180)
  2849.     if !(Width && Height)
  2850.         return -1
  2851.     RWidth := Ceil(Abs(Width*Cos(TAngle))+Abs(Height*Sin(TAngle)))
  2852.     RHeight := Ceil(Abs(Width*Sin(TAngle))+Abs(Height*Cos(Tangle)))
  2853. }
  2854.  
  2855. ; RotateNoneFlipNone   = 0
  2856. ; Rotate90FlipNone     = 1
  2857. ; Rotate180FlipNone    = 2
  2858. ; Rotate270FlipNone    = 3
  2859. ; RotateNoneFlipX      = 4
  2860. ; Rotate90FlipX        = 5
  2861. ; Rotate180FlipX       = 6
  2862. ; Rotate270FlipX       = 7
  2863. ; RotateNoneFlipY      = Rotate180FlipX
  2864. ; Rotate90FlipY        = Rotate270FlipX
  2865. ; Rotate180FlipY       = RotateNoneFlipX
  2866. ; Rotate270FlipY       = Rotate90FlipX
  2867. ; RotateNoneFlipXY     = Rotate180FlipNone
  2868. ; Rotate90FlipXY       = Rotate270FlipNone
  2869. ; Rotate180FlipXY      = RotateNoneFlipNone
  2870. ; Rotate270FlipXY      = Rotate90FlipNone
  2871.  
  2872. Gdip_ImageRotateFlip(pBitmap, RotateFlipType=1)
  2873. {
  2874.     return DllCall("gdiplus\GdipImageRotateFlip", A_PtrSize ? "UPtr" : "UInt", pBitmap, "int", RotateFlipType)
  2875. }
  2876.  
  2877. ; Replace = 0
  2878. ; Intersect = 1
  2879. ; Union = 2
  2880. ; Xor = 3
  2881. ; Exclude = 4
  2882. ; Complement = 5
  2883. Gdip_SetClipRect(pGraphics, x, y, w, h, CombineMode=0)
  2884. {
  2885.    return DllCall("gdiplus\GdipSetClipRect",  A_PtrSize ? "UPtr" : "UInt", pGraphics, "float", x, "float", y, "float", w, "float", h, "int", CombineMode)
  2886. }
  2887.  
  2888. Gdip_SetClipPath(pGraphics, Path, CombineMode=0)
  2889. {
  2890.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2891.     return DllCall("gdiplus\GdipSetClipPath", Ptr, pGraphics, Ptr, Path, "int", CombineMode)
  2892. }
  2893.  
  2894. Gdip_ResetClip(pGraphics)
  2895. {
  2896.    return DllCall("gdiplus\GdipResetClip", A_PtrSize ? "UPtr" : "UInt", pGraphics)
  2897. }
  2898.  
  2899. Gdip_GetClipRegion(pGraphics)
  2900. {
  2901.     Region := Gdip_CreateRegion()
  2902.     DllCall("gdiplus\GdipGetClip", A_PtrSize ? "UPtr" : "UInt", pGraphics, "UInt*", Region)
  2903.     return Region
  2904. }
  2905.  
  2906. Gdip_SetClipRegion(pGraphics, Region, CombineMode=0)
  2907. {
  2908.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2909.    
  2910.     return DllCall("gdiplus\GdipSetClipRegion", Ptr, pGraphics, Ptr, Region, "int", CombineMode)
  2911. }
  2912.  
  2913. Gdip_CreateRegion()
  2914. {
  2915.     DllCall("gdiplus\GdipCreateRegion", "UInt*", Region)
  2916.     return Region
  2917. }
  2918.  
  2919. Gdip_DeleteRegion(Region)
  2920. {
  2921.     return DllCall("gdiplus\GdipDeleteRegion", A_PtrSize ? "UPtr" : "UInt", Region)
  2922. }
  2923.  
  2924. ;#####################################################################################
  2925. ; BitmapLockBits
  2926. ;#####################################################################################
  2927.  
  2928. Gdip_LockBits(pBitmap, x, y, w, h, ByRef Stride, ByRef Scan0, ByRef BitmapData, LockMode = 3, PixelFormat = 0x26200a)
  2929. {
  2930.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2931.    
  2932.     CreateRect(Rect, x, y, w, h)
  2933.     VarSetCapacity(BitmapData, 16+2*(A_PtrSize ? A_PtrSize : 4), 0)
  2934.     E := DllCall("Gdiplus\GdipBitmapLockBits", Ptr, pBitmap, Ptr, &Rect, "uint", LockMode, "int", PixelFormat, Ptr, &BitmapData)
  2935.     Stride := NumGet(BitmapData, 8, "Int")
  2936.     Scan0 := NumGet(BitmapData, 16, Ptr)
  2937.     return E
  2938. }
  2939.  
  2940. ;#####################################################################################
  2941.  
  2942. Gdip_UnlockBits(pBitmap, ByRef BitmapData)
  2943. {
  2944.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2945.    
  2946.     return DllCall("Gdiplus\GdipBitmapUnlockBits", Ptr, pBitmap, Ptr, &BitmapData)
  2947. }
  2948.  
  2949. ;#####################################################################################
  2950.  
  2951. Gdip_SetLockBitPixel(ARGB, Scan0, x, y, Stride)
  2952. {
  2953.     Numput(ARGB, Scan0+0, (x*4)+(y*Stride), "UInt")
  2954. }
  2955.  
  2956. ;#####################################################################################
  2957.  
  2958. Gdip_GetLockBitPixel(Scan0, x, y, Stride)
  2959. {
  2960.     return NumGet(Scan0+0, (x*4)+(y*Stride), "UInt")
  2961. }
  2962.  
  2963. ;#####################################################################################
  2964.  
  2965. Gdip_PixelateBitmap(pBitmap, ByRef pBitmapOut, BlockSize)
  2966. {
  2967.     static PixelateBitmap
  2968.    
  2969.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2970.    
  2971.     if (!PixelateBitmap)
  2972.     {
  2973.         if A_PtrSize != 8 ; x86 machine code
  2974.         MCode_PixelateBitmap =
  2975.         (LTrim Join
  2976.         558BEC83EC3C8B4514538B5D1C99F7FB56578BC88955EC894DD885C90F8E830200008B451099F7FB8365DC008365E000894DC88955F08945E833FF897DD4
  2977.         397DE80F8E160100008BCB0FAFCB894DCC33C08945F88945FC89451C8945143BD87E608B45088D50028BC82BCA8BF02BF2418945F48B45E02955F4894DC4
  2978.         8D0CB80FAFCB03CA895DD08BD1895DE40FB64416030145140FB60201451C8B45C40FB604100145FC8B45F40FB604020145F883C204FF4DE475D6034D18FF
  2979.         4DD075C98B4DCC8B451499F7F98945148B451C99F7F989451C8B45FC99F7F98945FC8B45F899F7F98945F885DB7E648B450C8D50028BC82BCA83C103894D
  2980.         C48BC82BCA41894DF48B4DD48945E48B45E02955E48D0C880FAFCB03CA895DD08BD18BF38A45148B7DC48804178A451C8B7DF488028A45FC8804178A45F8
  2981.         8B7DE488043A83C2044E75DA034D18FF4DD075CE8B4DCC8B7DD447897DD43B7DE80F8CF2FEFFFF837DF0000F842C01000033C08945F88945FC89451C8945
  2982.         148945E43BD87E65837DF0007E578B4DDC034DE48B75E80FAF4D180FAFF38B45088D500203CA8D0CB18BF08BF88945F48B45F02BF22BFA2955F48945CC0F
  2983.         B6440E030145140FB60101451C0FB6440F010145FC8B45F40FB604010145F883C104FF4DCC75D8FF45E4395DE47C9B8B4DF00FAFCB85C9740B8B451499F7
  2984.         F9894514EB048365140033F63BCE740B8B451C99F7F989451CEB0389751C3BCE740B8B45FC99F7F98945FCEB038975FC3BCE740B8B45F899F7F98945F8EB
  2985.         038975F88975E43BDE7E5A837DF0007E4C8B4DDC034DE48B75E80FAF4D180FAFF38B450C8D500203CA8D0CB18BF08BF82BF22BFA2BC28B55F08955CC8A55
  2986.         1488540E038A551C88118A55FC88540F018A55F888140183C104FF4DCC75DFFF45E4395DE47CA68B45180145E0015DDCFF4DC80F8594FDFFFF8B451099F7
  2987.         FB8955F08945E885C00F8E450100008B45EC0FAFC38365DC008945D48B45E88945CC33C08945F88945FC89451C8945148945103945EC7E6085DB7E518B4D
  2988.         D88B45080FAFCB034D108D50020FAF4D18034DDC8BF08BF88945F403CA2BF22BFA2955F4895DC80FB6440E030145140FB60101451C0FB6440F010145FC8B
  2989.         45F40FB604080145F883C104FF4DC875D8FF45108B45103B45EC7CA08B4DD485C9740B8B451499F7F9894514EB048365140033F63BCE740B8B451C99F7F9
  2990.         89451CEB0389751C3BCE740B8B45FC99F7F98945FCEB038975FC3BCE740B8B45F899F7F98945F8EB038975F88975103975EC7E5585DB7E468B4DD88B450C
  2991.         0FAFCB034D108D50020FAF4D18034DDC8BF08BF803CA2BF22BFA2BC2895DC88A551488540E038A551C88118A55FC88540F018A55F888140183C104FF4DC8
  2992.         75DFFF45108B45103B45EC7CAB8BC3C1E0020145DCFF4DCC0F85CEFEFFFF8B4DEC33C08945F88945FC89451C8945148945103BC87E6C3945F07E5C8B4DD8
  2993.         8B75E80FAFCB034D100FAFF30FAF4D188B45088D500203CA8D0CB18BF08BF88945F48B45F02BF22BFA2955F48945C80FB6440E030145140FB60101451C0F
  2994.         B6440F010145FC8B45F40FB604010145F883C104FF4DC875D833C0FF45108B4DEC394D107C940FAF4DF03BC874068B451499F7F933F68945143BCE740B8B
  2995.         451C99F7F989451CEB0389751C3BCE740B8B45FC99F7F98945FCEB038975FC3BCE740B8B45F899F7F98945F8EB038975F88975083975EC7E63EB0233F639
  2996.         75F07E4F8B4DD88B75E80FAFCB034D080FAFF30FAF4D188B450C8D500203CA8D0CB18BF08BF82BF22BFA2BC28B55F08955108A551488540E038A551C8811
  2997.         8A55FC88540F018A55F888140883C104FF4D1075DFFF45088B45083B45EC7C9F5F5E33C05BC9C21800
  2998.         )
  2999.         else ; x64 machine code
  3000.         MCode_PixelateBitmap =
  3001.         (LTrim Join
  3002.         4489442418488954241048894C24085355565741544155415641574883EC28418BC1448B8C24980000004C8BDA99488BD941F7F9448BD0448BFA8954240C
  3003.         448994248800000085C00F8E9D020000418BC04533E4458BF299448924244C8954241041F7F933C9898C24980000008BEA89542404448BE889442408EB05
  3004.         4C8B5C24784585ED0F8E1A010000458BF1418BFD48897C2418450FAFF14533D233F633ED4533E44533ED4585C97E5B4C63BC2490000000418D040A410FAF
  3005.         C148984C8D441802498BD9498BD04D8BD90FB642010FB64AFF4403E80FB60203E90FB64AFE4883C2044403E003F149FFCB75DE4D03C748FFCB75D0488B7C
  3006.         24188B8C24980000004C8B5C2478418BC59941F7FE448BE8418BC49941F7FE448BE08BC59941F7FE8BE88BC69941F7FE8BF04585C97E4048639C24900000
  3007.         004103CA4D8BC1410FAFC94863C94A8D541902488BCA498BC144886901448821408869FF408871FE4883C10448FFC875E84803D349FFC875DA8B8C249800
  3008.         0000488B5C24704C8B5C24784183C20448FFCF48897C24180F850AFFFFFF8B6C2404448B2424448B6C24084C8B74241085ED0F840A01000033FF33DB4533
  3009.         DB4533D24533C04585C97E53488B74247085ED7E42438D0C04418BC50FAF8C2490000000410FAFC18D04814863C8488D5431028BCD0FB642014403D00FB6
  3010.         024883C2044403D80FB642FB03D80FB642FA03F848FFC975DE41FFC0453BC17CB28BCD410FAFC985C9740A418BC299F7F98BF0EB0233F685C9740B418BC3
  3011.         99F7F9448BD8EB034533DB85C9740A8BC399F7F9448BD0EB034533D285C9740A8BC799F7F9448BC0EB034533C033D24585C97E4D4C8B74247885ED7E3841
  3012.         8D0C14418BC50FAF8C2490000000410FAFC18D04814863C84A8D4431028BCD40887001448818448850FF448840FE4883C00448FFC975E8FFC2413BD17CBD
  3013.         4C8B7424108B8C2498000000038C2490000000488B5C24704503E149FFCE44892424898C24980000004C897424100F859EFDFFFF448B7C240C448B842480
  3014.         000000418BC09941F7F98BE8448BEA89942498000000896C240C85C00F8E3B010000448BAC2488000000418BCF448BF5410FAFC9898C248000000033FF33
  3015.         ED33F64533DB4533D24533C04585FF7E524585C97E40418BC5410FAFC14103C00FAF84249000000003C74898488D541802498BD90FB642014403D00FB602
  3016.         4883C2044403D80FB642FB03F00FB642FA03E848FFCB75DE488B5C247041FFC0453BC77CAE85C9740B418BC299F7F9448BE0EB034533E485C9740A418BC3
  3017.         99F7F98BD8EB0233DB85C9740A8BC699F7F9448BD8EB034533DB85C9740A8BC599F7F9448BD0EB034533D24533C04585FF7E4E488B4C24784585C97E3541
  3018.         8BC5410FAFC14103C00FAF84249000000003C74898488D540802498BC144886201881A44885AFF448852FE4883C20448FFC875E941FFC0453BC77CBE8B8C
  3019.         2480000000488B5C2470418BC1C1E00203F849FFCE0F85ECFEFFFF448BAC24980000008B6C240C448BA4248800000033FF33DB4533DB4533D24533C04585
  3020.         FF7E5A488B7424704585ED7E48418BCC8BC5410FAFC94103C80FAF8C2490000000410FAFC18D04814863C8488D543102418BCD0FB642014403D00FB60248
  3021.         83C2044403D80FB642FB03D80FB642FA03F848FFC975DE41FFC0453BC77CAB418BCF410FAFCD85C9740A418BC299F7F98BF0EB0233F685C9740B418BC399
  3022.         F7F9448BD8EB034533DB85C9740A8BC399F7F9448BD0EB034533D285C9740A8BC799F7F9448BC0EB034533C033D24585FF7E4E4585ED7E42418BCC8BC541
  3023.         0FAFC903CA0FAF8C2490000000410FAFC18D04814863C8488B442478488D440102418BCD40887001448818448850FF448840FE4883C00448FFC975E8FFC2
  3024.         413BD77CB233C04883C428415F415E415D415C5F5E5D5BC3
  3025.         )
  3026.        
  3027.         VarSetCapacity(PixelateBitmap, StrLen(MCode_PixelateBitmap)//2)
  3028.         Loop % StrLen(MCode_PixelateBitmap)//2      ;%
  3029.             NumPut("0x" SubStr(MCode_PixelateBitmap, (2*A_Index)-1, 2), PixelateBitmap, A_Index-1, "UChar")
  3030.         DllCall("VirtualProtect", Ptr, &PixelateBitmap, Ptr, VarSetCapacity(PixelateBitmap), "uint", 0x40, A_PtrSize ? "UPtr*" : "UInt*", 0)
  3031.     }
  3032.  
  3033.     Gdip_GetImageDimensions(pBitmap, Width, Height)
  3034.    
  3035.     if (Width != Gdip_GetImageWidth(pBitmapOut) || Height != Gdip_GetImageHeight(pBitmapOut))
  3036.         return -1
  3037.     if (BlockSize > Width || BlockSize > Height)
  3038.         return -2
  3039.  
  3040.     E1 := Gdip_LockBits(pBitmap, 0, 0, Width, Height, Stride1, Scan01, BitmapData1)
  3041.     E2 := Gdip_LockBits(pBitmapOut, 0, 0, Width, Height, Stride2, Scan02, BitmapData2)
  3042.     if (E1 || E2)
  3043.         return -3
  3044.  
  3045.     E := DllCall(&PixelateBitmap, Ptr, Scan01, Ptr, Scan02, "int", Width, "int", Height, "int", Stride1, "int", BlockSize)
  3046.    
  3047.     Gdip_UnlockBits(pBitmap, BitmapData1), Gdip_UnlockBits(pBitmapOut, BitmapData2)
  3048.     return 0
  3049. }
  3050.  
  3051. ;#####################################################################################
  3052.  
  3053. Gdip_ToARGB(A, R, G, B)
  3054. {
  3055.     return (A << 24) | (R << 16) | (G << 8) | B
  3056. }
  3057.  
  3058. ;#####################################################################################
  3059.  
  3060. Gdip_FromARGB(ARGB, ByRef A, ByRef R, ByRef G, ByRef B)
  3061. {
  3062.     A := (0xff000000 & ARGB) >> 24
  3063.     R := (0x00ff0000 & ARGB) >> 16
  3064.     G := (0x0000ff00 & ARGB) >> 8
  3065.     B := 0x000000ff & ARGB
  3066. }
  3067.  
  3068. ;#####################################################################################
  3069.  
  3070. Gdip_AFromARGB(ARGB)
  3071. {
  3072.     return (0xff000000 & ARGB) >> 24
  3073. }
  3074.  
  3075. ;#####################################################################################
  3076.  
  3077. Gdip_RFromARGB(ARGB)
  3078. {
  3079.     return (0x00ff0000 & ARGB) >> 16
  3080. }
  3081.  
  3082. ;#####################################################################################
  3083.  
  3084. Gdip_GFromARGB(ARGB)
  3085. {
  3086.     return (0x0000ff00 & ARGB) >> 8
  3087. }
  3088.  
  3089. ;#####################################################################################
  3090.  
  3091. Gdip_BFromARGB(ARGB)
  3092. {
  3093.     return 0x000000ff & ARGB
  3094. }
  3095.  
  3096. ;#####################################################################################
  3097.  
  3098. StrGetB(Address, Length=-1, Encoding=0)
  3099. {
  3100.     ; Flexible parameter handling:
  3101.     if Length is not integer
  3102.     Encoding := Length,  Length := -1
  3103.  
  3104.     ; Check for obvious errors.
  3105.     if (Address+0 < 1024)
  3106.         return
  3107.  
  3108.     ; Ensure 'Encoding' contains a numeric identifier.
  3109.     if Encoding = UTF-16
  3110.         Encoding = 1200
  3111.     else if Encoding = UTF-8
  3112.         Encoding = 65001
  3113.     else if SubStr(Encoding,1,2)="CP"
  3114.         Encoding := SubStr(Encoding,3)
  3115.  
  3116.     if !Encoding ; "" or 0
  3117.     {
  3118.         ; No conversion necessary, but we might not want the whole string.
  3119.         if (Length == -1)
  3120.             Length := DllCall("lstrlen", "uint", Address)
  3121.         VarSetCapacity(String, Length)
  3122.         DllCall("lstrcpyn", "str", String, "uint", Address, "int", Length + 1)
  3123.     }
  3124.     else if Encoding = 1200 ; UTF-16
  3125.     {
  3126.         char_count := DllCall("WideCharToMultiByte", "uint", 0, "uint", 0x400, "uint", Address, "int", Length, "uint", 0, "uint", 0, "uint", 0, "uint", 0)
  3127.         VarSetCapacity(String, char_count)
  3128.         DllCall("WideCharToMultiByte", "uint", 0, "uint", 0x400, "uint", Address, "int", Length, "str", String, "int", char_count, "uint", 0, "uint", 0)
  3129.     }
  3130.     else if Encoding is integer
  3131.     {
  3132.         ; Convert from target encoding to UTF-16 then to the active code page.
  3133.         char_count := DllCall("MultiByteToWideChar", "uint", Encoding, "uint", 0, "uint", Address, "int", Length, "uint", 0, "int", 0)
  3134.         VarSetCapacity(String, char_count * 2)
  3135.         char_count := DllCall("MultiByteToWideChar", "uint", Encoding, "uint", 0, "uint", Address, "int", Length, "uint", &String, "int", char_count * 2)
  3136.         String := StrGetB(&String, char_count, 1200)
  3137.     }
  3138.    
  3139.     return String
  3140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement