Advertisement
pastamaker

circle v1.1

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