From 392151692f63fd68ba3054d3d3e3c3baa791ea95 Mon Sep 17 00:00:00 2001 From: Craig Oates Date: Sun, 16 Dec 2018 06:38:07 +0000 Subject: [PATCH] set obsolete attributes and refactor replacement to applyGridToImageAsync. --- DeathSocket/GridPainter.fs | 52 +++++++++++----------- DeathSocket/ScratchPad.fsx | 88 +++++++++++++++++++++++++------------- DeathSocketCLI/Commands.fs | 8 ++-- TestCentre/LibraryTests.fs | 1 - 4 files changed, 91 insertions(+), 58 deletions(-) diff --git a/DeathSocket/GridPainter.fs b/DeathSocket/GridPainter.fs index f3dd2d3..8172dd9 100644 --- a/DeathSocket/GridPainter.fs +++ b/DeathSocket/GridPainter.fs @@ -15,6 +15,29 @@ namespace DeathSocket open Validation open ImageServices + open System + + // Not tested + let applyGridToImageAsync (spec: ImageSpec) = + async { + try + match spec with + | Brush b -> + validateIO b.originalPath b.savePath |> ignore + drawBrushSpecGrid b + | RGBA r -> + validateIO r.originalPath r.savePath |> ignore + drawRGBAGrid r + | Skia s -> + validateIO s.originalPath s.savePath |> ignore + drawSkiaGrid s + | SkiaRGB sR -> + validateIO sR.originalPath sR.savePath |> ignore + drawSkiaRGBGrid sR + with + | :? FileNotFoundException as ex -> + printfn "File could not be found at %s" ex.Message + } // System.Drawing Functions // ======================================================================== @@ -62,6 +85,7 @@ namespace DeathSocket /// is not in use or needed by another program/process. /// This is because it is locked whilst in this function. /// + [] let applyBrushSpecGridAsync (spec: BrushSpec) = async { try @@ -90,6 +114,7 @@ namespace DeathSocket /// is not in use or needed by another program/process. /// This is because it is locked whilst in this function. /// + [] let applyRGBAGridAsync (spec: RGBASpec) = async { try @@ -162,7 +187,6 @@ namespace DeathSocket let determineSKVerticalLines (width: int) (height: int) (columns: int) = createSKVerticalLines width height columns - /// /// Uses the information included in spec to create a gridded image. /// It then asynchronously saves it. Uses .jpg or .png formats only. @@ -178,6 +202,7 @@ namespace DeathSocket /// is not in use or needed by another program/process. /// This is because it is locked whilst in this function. /// + [] let applySkiaGridAsync (spec: SkiaSpec) = async { try @@ -204,6 +229,7 @@ namespace DeathSocket /// is not in use or needed by another program/process. /// This is because it is locked whilst in this function. /// + [] let applySkiaRGBGridAsync (spec: SkiaRGBSpec) = async { try @@ -213,26 +239,4 @@ namespace DeathSocket with | :? FileNotFoundException as ex -> printfn "File could not be found at %s" ex.Message - } - - // Not tested - let applyImageToGrid (spec: ImageSpec) = - async { - try - match spec with - | Brush b -> - validateIO b.originalPath b.savePath |> ignore - drawBrushSpecGrid b - | RGBA r -> - validateIO r.originalPath r.savePath |> ignore - drawRGBAGrid r - | Skia s -> - validateIO s.originalPath s.savePath |> ignore - drawSkiaGrid s - | SkiaRGB sR -> - validateIO sR.originalPath sR.savePath |> ignore - drawSkiaRGBGrid sR - with - | :? FileNotFoundException as ex -> - printfn "File could not be found at %s" ex.Message - } \ No newline at end of file + } \ No newline at end of file diff --git a/DeathSocket/ScratchPad.fsx b/DeathSocket/ScratchPad.fsx index 4775c49..e14403b 100644 --- a/DeathSocket/ScratchPad.fsx +++ b/DeathSocket/ScratchPad.fsx @@ -1,5 +1,6 @@ -#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" +#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" +#r @"C:/Users/craig/.nuget/packages/skiasharp/1.60.3/lib/Xamarin.Mac20/SkiaSharp.dll" #load "Domain.fs" #load "Validation.fs" @@ -12,6 +13,8 @@ open System open DeathSocket open Validation open ImageServices +open SkiaSharp + (* Death Socket Scripts =============================================================================== @@ -21,36 +24,63 @@ a nerw image. *) let desktop = Environment.GetFolderPath (Environment.SpecialFolder.Desktop) -(* You will need to provide the image at the location specified. It will throw -an exception if the file cannnot be found.*) -let validationTest = validateFilePath (desktop + "/test.jpg") +(* You will need to provide the image at the location specified. Both throw an +exception if the file cannot be found or is the wrong extension. Death Socket +only works with JPG and PNG.*) +let IOTest = validateFilePath (desktop + "/test.jpg") +let extentionTest = validateSaveFileType (desktop + "/test.jpg") -(* These are not needed to create an image. There here for you to check the -start and end points of each pen stroke/path. *) +(* These are not needed by you to create an image. They here for you to check +the start and end points of each pen stroke/path. *) let horizontalLines = createHorizontalLines 1000 500 10 let verticalLines = createVerticalLines 300 600 10 +let skHorizontalLines = createSKHorizontalLines 550 520 10 +let skVerticalLines = createSKVerticalLines 120 450 22 (* You will need to provide the image and specify its load/save location. -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: BrushSpec = - { originalPath = desktop + "/test.jpg" - savePath = desktop + "/grid.png" - colour = Brushes.Chartreuse - penWidth = (float32 1) - rows = 10 - columns = 10 } - -// 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. *) +Death Socket assumes either JPEG or PNG files.*) + +// Brush Specification (uses System.Drawing) +Brush ({ originalPath = desktop + "/test.jpg" + savePath = desktop + "/grid.png" + colour = Brushes.Chartreuse + penWidth = (float32 1) + rows = 10 + columns = 10 }) +|> GridPainter.applyGridToImageAsync +|> Async.Start + +// RGBA Specification (uses System.Drawing) +RGBA ({ originalPath = desktop + "/test.jpg" + savePath = desktop + "/grid.png" + alpha = float 1 + red = float 122 + green = float 222 + blue = float 100 + penWidth = (float32 1) + rows = 10 + columns = 10 }) +|> GridPainter.applyGridToImageAsync +|> Async.Start + +// Skia Specification (uses SkiaSharp -- use with Xamarin) +Skia ({ originalPath = desktop + "/test.jpg" + savePath = desktop + "/grid.png" + skColour = SKColors.BlueViolet + penWidth = (float32 1) + rows = 10 + columns = 10}) +|> GridPainter.applyGridToImageAsync +|> Async.Start -drawSkiaGrid() \ No newline at end of file +// SkiaRGB Specification (uses SkiaSharp -- use with Xamarin) +SkiaRGB ({ originalPath = desktop + "/test.jpg" + savePath = desktop + "/grid.png" + red = (float32 102) + green = (float32 124) + blue = (float32 224) + penWidth = (float32 1) + rows = 10 + columns = 10}) +|> GridPainter.applyGridToImageAsync +|> Async.RunSynchronously \ No newline at end of file diff --git a/DeathSocketCLI/Commands.fs b/DeathSocketCLI/Commands.fs index 1e61222..e924dbb 100644 --- a/DeathSocketCLI/Commands.fs +++ b/DeathSocketCLI/Commands.fs @@ -40,7 +40,7 @@ try printfn "[INFO.] Adding default grid to image..." Brush (buildDefaultSpec imgPath newPath) - |> applyImageToGrid + |> applyGridToImageAsync |> Async.Start showEndOfCommandMessage with @@ -59,7 +59,7 @@ try printfn "[INFO.] Adding grid to image..." Brush (buildSpec imgPath numRows numColumns pWidth colour newPath) - |> applyImageToGrid + |> applyGridToImageAsync |> Async.Start showEndOfCommandMessage with @@ -112,13 +112,13 @@ let``add-skia-grid`` imgPath numRows numColumns pWidth colour newPath = printfn "[INFO.] Adding SkiaSharp grid to image..." Skia (buildSkiaSpec imgPath numRows numColumns pWidth colour newPath) - |> applyImageToGrid + |> applyGridToImageAsync |> Async.Start showEndOfCommandMessage let``add-skia-rgb-grid`` imgPath numRows numColumns pWidth r g b newPath = printfn "[INFO.] Adding SkiaSharp grid to image..." SkiaRGB (buildSkiaRGBSpec imgPath numRows numColumns pWidth r g b newPath) - |> applyImageToGrid + |> applyGridToImageAsync |> Async.Start showEndOfCommandMessage \ No newline at end of file diff --git a/TestCentre/LibraryTests.fs b/TestCentre/LibraryTests.fs index 6d7e6dc..1c8331a 100644 --- a/TestCentre/LibraryTests.fs +++ b/TestCentre/LibraryTests.fs @@ -105,7 +105,6 @@ open DeathSocket.GridPainter open TestingHelpers open System.IO - open SkiaSharp (* With regards to the "saving images" tests, you should end up with one image left over in the SavingTestArea folder. Comment out the