From e67a85a1f98ef0df2f4ccc5616bfd932be19ffe1 Mon Sep 17 00:00:00 2001 From: "OPTIMUS-PRIME\\craig" Date: Mon, 12 Nov 2018 04:22:53 +0000 Subject: [PATCH 01/13] add skia sharp to library and fix references in ScratchPad.fs. --- DeathSocket/DeathSocket.fsproj | 1 + DeathSocket/ScratchPad.fsx | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/DeathSocket/DeathSocket.fsproj b/DeathSocket/DeathSocket.fsproj index 80d6bb6..b152d9f 100644 --- a/DeathSocket/DeathSocket.fsproj +++ b/DeathSocket/DeathSocket.fsproj @@ -29,6 +29,7 @@ New functions have been added so you can now create a SolidBrush using individua + diff --git a/DeathSocket/ScratchPad.fsx b/DeathSocket/ScratchPad.fsx index 13eaa89..9cd1a3f 100644 --- a/DeathSocket/ScratchPad.fsx +++ b/DeathSocket/ScratchPad.fsx @@ -1,5 +1,6 @@ #load "Domain.fs" #load "Validation.fs" +#load "ColourServices.fs" #load "ImageServices.fs" #load "GridPainter.fs" @@ -30,7 +31,7 @@ let verticalLines = createVerticalLines 300 600 10 Death Socket assumes either JPEG or PNG files so use other files at your own risk. Cannot guarantee they will work. Also, either in this spec. can be changed to suit your needs. *) -let spec :ImageSpec = +let spec: BrushSpec = { originalPath = desktop + "/test.jpg" savePath = desktop + "/grid.png" colour = Brushes.Chartreuse @@ -39,4 +40,4 @@ let spec :ImageSpec = columns = 10 } // Run this when you have finished building the spec. -GridPainter.applyGridAsync spec |> Async.RunSynchronously +GridPainter.applyBrushSpecGridAsync spec |> Async.RunSynchronously From ee713b76c0caa69daed74ca8abc183c834fff6e8 Mon Sep 17 00:00:00 2001 From: "OPTIMUS-PRIME\\craig" Date: Mon, 12 Nov 2018 05:19:50 +0000 Subject: [PATCH 02/13] start add code for skia sharp drawing. --- DeathSocket/DeathSocket.fsproj | 2 +- DeathSocket/ImageServices.fs | 12 ++++++++++++ DeathSocket/ScratchPad.fsx | 9 +++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/DeathSocket/DeathSocket.fsproj b/DeathSocket/DeathSocket.fsproj index b152d9f..8300ee4 100644 --- a/DeathSocket/DeathSocket.fsproj +++ b/DeathSocket/DeathSocket.fsproj @@ -30,7 +30,7 @@ New functions have been added so you can now create a SolidBrush using individua - + diff --git a/DeathSocket/ImageServices.fs b/DeathSocket/ImageServices.fs index 8babd60..b5eab84 100644 --- a/DeathSocket/ImageServices.fs +++ b/DeathSocket/ImageServices.fs @@ -4,6 +4,7 @@ open System.Drawing.Imaging open DeathSocket open ColourServices + open SkiaSharp let createHorizontalLines width height rows = let interval = height / rows @@ -52,3 +53,14 @@ for line in horizontalLines do graphics.DrawLines (pen, line) for line in verticalLines do graphics.DrawLines (pen, line) clone.Save (spec.savePath) + + // You are up to here. Need to draw lines and add image. + let drawSkiaGrid () = + let imageInfo = new SKImageInfo (500, 500) + use surface = SKSurface.Create(imageInfo) + let canvas = surface.Canvas + canvas.Clear (SKColors.White) + let horizontalLines = createHorizontalLines 500 1000 6 + let verticalLines = createVerticalLines 500 1000 9 + + 23 \ No newline at end of file diff --git a/DeathSocket/ScratchPad.fsx b/DeathSocket/ScratchPad.fsx index 9cd1a3f..fd88180 100644 --- a/DeathSocket/ScratchPad.fsx +++ b/DeathSocket/ScratchPad.fsx @@ -41,3 +41,12 @@ let spec: BrushSpec = // Run this when you have finished building the spec. GridPainter.applyBrushSpecGridAsync spec |> Async.RunSynchronously + +//***************************************************************************** + +(* Skia Sharp Draft +=============================================================================== +The code below here will eventually be worked into the main codebase or thrown +away. It is here acting as a first draft for integrating the Skia Sharp NuGet +package into Death Socket. *) + From 6baa799ee8f12066cf07a65dbf579cdf9d027124 Mon Sep 17 00:00:00 2001 From: "OPTIMUS-PRIME\\craig" Date: Tue, 13 Nov 2018 01:26:34 +0000 Subject: [PATCH 03/13] add hardcoded but working code for skia sharp. Image is taken from desktop (hard coded) and a grid is added to it and saved back to desktop with new name (all hard coded). This will not work on machines which are not the original one this code was written on. --- DeathSocket/GridPainter.fs | 4 ++- DeathSocket/ImageServices.fs | 54 ++++++++++++++++++++++++---- DeathSocket/ScratchPad.fsx | 6 +++- DeathSocketCLI/Commands.fs | 6 +++- DeathSocketCLI/DeathSocketCLI.fsproj | 14 +++++++- DeathSocketCLI/packages.config | 3 +- 6 files changed, 75 insertions(+), 12 deletions(-) diff --git a/DeathSocket/GridPainter.fs b/DeathSocket/GridPainter.fs index 60dfa1a..0ed5ecd 100644 --- a/DeathSocket/GridPainter.fs +++ b/DeathSocket/GridPainter.fs @@ -113,4 +113,6 @@ namespace DeathSocket /// The number of columns the grid should have. /// You will probably only need these when dealing with GUI's. let determineVerticalLines width height columns = - createVerticalLines width height columns \ No newline at end of file + createVerticalLines width height columns + + let drawskia () = drawSkiaGrid () \ No newline at end of file diff --git a/DeathSocket/ImageServices.fs b/DeathSocket/ImageServices.fs index b5eab84..68235b8 100644 --- a/DeathSocket/ImageServices.fs +++ b/DeathSocket/ImageServices.fs @@ -1,5 +1,6 @@ module internal ImageServices + open System.IO open System.Drawing open System.Drawing.Imaging open DeathSocket @@ -41,11 +42,11 @@ let drawRGBAGrid (spec: RGBASpec) = use original = Bitmap.FromFile spec.originalPath - use temp = new Bitmap(original) - use clone = temp.Clone(new Rectangle(0, 0, temp.Width, temp.Height), PixelFormat.Format32bppArgb) + use temp = new Bitmap (original) + use clone = temp.Clone (new Rectangle(0, 0, temp.Width, temp.Height), PixelFormat.Format32bppArgb) use graphics = Graphics.FromImage(clone) use pen = new Pen ((makeBrushFromRGBASpec spec), width = spec.penWidth) - graphics.DrawImage(original,new Rectangle(0, 0, clone.Width, clone.Height)) + graphics.DrawImage (original,new Rectangle(0, 0, clone.Width, clone.Height)) let horizontalLines = createHorizontalLines (clone.Size.Width) (clone.Size.Height) (spec.rows) let verticalLines = @@ -56,11 +57,50 @@ // You are up to here. Need to draw lines and add image. let drawSkiaGrid () = - let imageInfo = new SKImageInfo (500, 500) + // Set Canvas/Surface + let imageInfo = new SKImageInfo (2592, 1456) use surface = SKSurface.Create(imageInfo) let canvas = surface.Canvas canvas.Clear (SKColors.White) - let horizontalLines = createHorizontalLines 500 1000 6 - let verticalLines = createVerticalLines 500 1000 9 - 23 \ No newline at end of file + // Set SKPaint Objects + use stroke = new SKPaint () + stroke.Style <- SKPaintStyle.Stroke + stroke.StrokeWidth <- float32 3 + stroke.Color <- SKColors.BlueViolet + use imageFill = new SKPaint () + imageFill.Style <- SKPaintStyle.Fill + + // Add Bitmap + //let fileStream = File.Open (@"C:\Users\craig\Desktop\test.jpg", FileMode.Open) + + let byteArray = File.ReadAllBytes(@"C:\Users\craig\Desktop\test.jpg") + use memStream = new MemoryStream(byteArray) + + // this works... + use skStream = new SKManagedStream (memStream) + use bitmap = SKBitmap.Decode (skStream) + use shader = SKShader.CreateBitmap (bitmap, SKShaderTileMode.Mirror, SKShaderTileMode.Mirror) + imageFill.Shader <- shader + canvas.DrawPaint (imageFill) + + // Draw Lines + let horizontalLines = createHorizontalLines 2592 1456 6 + let verticalLines = createVerticalLines 2592 1456 9 + for hLine in horizontalLines do + let x1 = float32 hLine.[0].X + let y1 = float32 hLine.[0].Y + let x2 = float32 hLine.[1].X + let y2 = float32 hLine.[1].Y + canvas.DrawLine (x1, y1, x2, y2, stroke) + for vLine in verticalLines do + let x1 = float32 vLine.[0].X + let y1 = float32 vLine.[0].Y + let x2 = float32 vLine.[1].X + let y2 = float32 vLine.[1].Y + canvas.DrawLine (x1, y1, x2, y2, stroke) + use snapshot = surface.Snapshot () + use data = snapshot.Encode (SKEncodedImageFormat.Png, 100) + use saveStream = File.OpenWrite (@"C:\Users\craig\Desktop\test-complete.jpg") + data.SaveTo (saveStream) + printfn "Skia Sharp image saved." \ No newline at end of file diff --git a/DeathSocket/ScratchPad.fsx b/DeathSocket/ScratchPad.fsx index fd88180..4775c49 100644 --- a/DeathSocket/ScratchPad.fsx +++ b/DeathSocket/ScratchPad.fsx @@ -1,4 +1,7 @@ -#load "Domain.fs" +#r @"C:\Users\craig\.nuget\packages\skiasharp\1.60.3\lib\netstandard1.3\SkiaSharp.dll" +#r @"C:\Users\craig\.nuget\packages\skiasharp\1.60.3\lib\net45\SkiaSharp.dll" + +#load "Domain.fs" #load "Validation.fs" #load "ColourServices.fs" #load "ImageServices.fs" @@ -50,3 +53,4 @@ The code below here will eventually be worked into the main codebase or thrown away. It is here acting as a first draft for integrating the Skia Sharp NuGet package into Death Socket. *) +drawSkiaGrid() \ No newline at end of file diff --git a/DeathSocketCLI/Commands.fs b/DeathSocketCLI/Commands.fs index f70ddad..3e8796d 100644 --- a/DeathSocketCLI/Commands.fs +++ b/DeathSocketCLI/Commands.fs @@ -90,4 +90,8 @@ let ag imgPath numRows numColumns pWidth colour newPath = ``add-grid`` imgPath numRows numColumns pWidth colour newPath - let lc () =``list-colours`` () \ No newline at end of file + let lc () =``list-colours`` () + + let``skia-test`` () = + drawskia () + showEndOfCommandMessage \ No newline at end of file diff --git a/DeathSocketCLI/DeathSocketCLI.fsproj b/DeathSocketCLI/DeathSocketCLI.fsproj index e62a4d0..52310bb 100644 --- a/DeathSocketCLI/DeathSocketCLI.fsproj +++ b/DeathSocketCLI/DeathSocketCLI.fsproj @@ -14,6 +14,8 @@ True DeathSocketCLI ..\DeathSocketCLI\resources.res + + true @@ -63,11 +65,14 @@ ..\packages\FSharp.Core.4.5.2\lib\net45\FSharp.Core.dll + + ..\packages\SkiaSharp.1.60.3\lib\net45\SkiaSharp.dll + - ..\packages\System.Drawing.Common.4.5.0\lib\net461\System.Drawing.Common.dll + ..\packages\System.Drawing.Common.4.5.1\lib\net461\System.Drawing.Common.dll @@ -81,6 +86,13 @@ True + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + +