From 7007ed60db4dfa724f35efaee7408a0656187937 Mon Sep 17 00:00:00 2001 From: Craig Oates Date: Sun, 16 Dec 2018 05:10:39 +0000 Subject: [PATCH 01/10] begin initial integration of applyImageToGrid. --- DeathSocket/Domain.fs | 8 +++++++- DeathSocket/GridPainter.fs | 22 +++++++++++++++++++++- DeathSocket/Validation.fs | 6 +++++- DeathSocketCLI/Commands.fs | 17 ++++++++++++++++- 4 files changed, 49 insertions(+), 4 deletions(-) diff --git a/DeathSocket/Domain.fs b/DeathSocket/Domain.fs index 0fd06ba..3980415 100644 --- a/DeathSocket/Domain.fs +++ b/DeathSocket/Domain.fs @@ -94,4 +94,10 @@ /// The number of rows the grid will have. rows: int ///The number of columns the grid will have. - columns: int } \ No newline at end of file + columns: int } + + type ImageSpec = + | BrushSpec of BrushSpec + | RGBASpec of RGBASpec + | SkiaSpec of SkiaSpec + | SkiaRGBSpec of SkiaRGBSpec \ No newline at end of file diff --git a/DeathSocket/GridPainter.fs b/DeathSocket/GridPainter.fs index e12bd8b..40af0b8 100644 --- a/DeathSocket/GridPainter.fs +++ b/DeathSocket/GridPainter.fs @@ -213,4 +213,24 @@ namespace DeathSocket with | :? FileNotFoundException as ex -> printfn "File could not be found at %s" ex.Message - } \ No newline at end of file + } + + let applyImageToGrid (spec: ImageSpec) = + async { + try + match spec with + | BrushSpec b -> + validateIO b.originalPath b.savePath |> ignore + drawBrushSpecGrid b + | RGBASpec r -> + validateIO r.originalPath r.savePath |> ignore + drawRGBAGrid r + | SkiaSpec s -> + validateIO s.originalPath s.savePath |> ignore + drawSkiaGrid s + | SkiaRGBSpec sR -> + validateIO sR.originalPath sR.savePath |> ignore + with + | :? FileNotFoundException as ex -> + printfn "File could not be found at %s" ex.Message + } \ No newline at end of file diff --git a/DeathSocket/Validation.fs b/DeathSocket/Validation.fs index 71128f3..edc208a 100644 --- a/DeathSocket/Validation.fs +++ b/DeathSocket/Validation.fs @@ -13,4 +13,8 @@ | ".JPG" -> () | ".png" -> () | ".PNG" -> () - | _ -> invalidArg "savePath" "The file type must be a .jpg or .png file." \ No newline at end of file + | _ -> invalidArg "savePath" "The file type must be a .jpg or .png file." + + let validateIO iPath oPath = + validateFilePath iPath + validateSaveFileType oPath \ No newline at end of file diff --git a/DeathSocketCLI/Commands.fs b/DeathSocketCLI/Commands.fs index d0fd0ed..8a3df0b 100644 --- a/DeathSocketCLI/Commands.fs +++ b/DeathSocketCLI/Commands.fs @@ -8,6 +8,7 @@ open System.IO open Console.Waterworks open Console.Waterworks.Attributes + open DeathSocket.Domain let showEndOfCommandMessage = "[INFO.] Task completed." @@ -91,7 +92,7 @@ let ag imgPath numRows numColumns pWidth colour newPath = ``add-grid`` imgPath numRows numColumns pWidth colour newPath - let lc () =``list-colours`` () + let lc () = ``list-colours`` () (* SkiaSharp Command-Methods -- NOT FOR MASS CONSUMPTION ======================================================================= @@ -120,4 +121,18 @@ buildSkiaRGBSpec imgPath numRows numColumns pWidth r g b newPath |> applySkiaRGBGridAsync |> Async.Start + showEndOfCommandMessage + + let dutest () = + printf "saving image..." + let b = + BrushSpec (buildDefaultSpec "C:\Users\craig\Desktop\du-test.jpg" "C:\Users\craig\Desktop\du-test-brush.jpg") + // let r = buildRGBASpec... + let s = + SkiaSpec (buildSkiaSpec "C:\Users\craig\Desktop\du-test.jpg" 5 5 (float32 2) "Red" "C:\Users\craig\Desktop\du-test-skia.jpg") + let sR = + SkiaRGBSpec (buildSkiaRGBSpec "C:\Users\craig\Desktop\du-test.jpg" 5 5 (float32 2) 12 56 121 "C:\Users\craig\Desktop\du-test-skia.jpg") + sR + |> applyImageToGrid + |> Async.RunSynchronously showEndOfCommandMessage \ No newline at end of file From 0e88720ae2462055818501cad2824e15551834a1 Mon Sep 17 00:00:00 2001 From: Craig Oates Date: Sun, 16 Dec 2018 05:27:05 +0000 Subject: [PATCH 02/10] refactor add-default command (applyImageToGrid). --- DeathSocket/Domain.fs | 10 ++++++---- DeathSocket/GridPainter.fs | 9 +++++---- DeathSocketCLI/Commands.fs | 11 ++++++----- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/DeathSocket/Domain.fs b/DeathSocket/Domain.fs index 3980415..5bf5a4b 100644 --- a/DeathSocket/Domain.fs +++ b/DeathSocket/Domain.fs @@ -96,8 +96,10 @@ ///The number of columns the grid will have. columns: int } + /// Discriminated Union representing the various specification types + /// Death Socket can use to apply a grid to an image. type ImageSpec = - | BrushSpec of BrushSpec - | RGBASpec of RGBASpec - | SkiaSpec of SkiaSpec - | SkiaRGBSpec of SkiaRGBSpec \ No newline at end of file + | Brush of BrushSpec + | RGBA of RGBASpec + | Skia of SkiaSpec + | SkiaRGB of SkiaRGBSpec \ No newline at end of file diff --git a/DeathSocket/GridPainter.fs b/DeathSocket/GridPainter.fs index 40af0b8..1c7c718 100644 --- a/DeathSocket/GridPainter.fs +++ b/DeathSocket/GridPainter.fs @@ -219,17 +219,18 @@ namespace DeathSocket async { try match spec with - | BrushSpec b -> + | Brush b -> validateIO b.originalPath b.savePath |> ignore drawBrushSpecGrid b - | RGBASpec r -> + | RGBA r -> validateIO r.originalPath r.savePath |> ignore drawRGBAGrid r - | SkiaSpec s -> + | Skia s -> validateIO s.originalPath s.savePath |> ignore drawSkiaGrid s - | SkiaRGBSpec sR -> + | SkiaRGB sR -> validateIO sR.originalPath sR.savePath |> ignore + drawSkiaRGBGrid sR with | :? FileNotFoundException as ex -> printfn "File could not be found at %s" ex.Message diff --git a/DeathSocketCLI/Commands.fs b/DeathSocketCLI/Commands.fs index 8a3df0b..995776e 100644 --- a/DeathSocketCLI/Commands.fs +++ b/DeathSocketCLI/Commands.fs @@ -39,8 +39,9 @@ let ``add-default`` imgPath newPath = try printfn "[INFO.] Adding default grid to image..." - buildDefaultSpec imgPath newPath - |> applyBrushSpecGridAsync + Brush (buildDefaultSpec imgPath newPath) + |> applyImageToGrid + //|> applyBrushSpecGridAsync |> Async.Start showEndOfCommandMessage with @@ -126,12 +127,12 @@ let dutest () = printf "saving image..." let b = - BrushSpec (buildDefaultSpec "C:\Users\craig\Desktop\du-test.jpg" "C:\Users\craig\Desktop\du-test-brush.jpg") + Brush (buildDefaultSpec "C:\Users\craig\Desktop\du-test.jpg" "C:\Users\craig\Desktop\du-test-brush.jpg") // let r = buildRGBASpec... let s = - SkiaSpec (buildSkiaSpec "C:\Users\craig\Desktop\du-test.jpg" 5 5 (float32 2) "Red" "C:\Users\craig\Desktop\du-test-skia.jpg") + Skia (buildSkiaSpec "C:\Users\craig\Desktop\du-test.jpg" 5 5 (float32 2) "Red" "C:\Users\craig\Desktop\du-test-skia.jpg") let sR = - SkiaRGBSpec (buildSkiaRGBSpec "C:\Users\craig\Desktop\du-test.jpg" 5 5 (float32 2) 12 56 121 "C:\Users\craig\Desktop\du-test-skia.jpg") + SkiaRGB (buildSkiaRGBSpec "C:\Users\craig\Desktop\du-test.jpg" 5 5 (float32 2) 12 56 121 "C:\Users\craig\Desktop\du-test-skia.jpg") sR |> applyImageToGrid |> Async.RunSynchronously From 5daf3725b21f2d6ba92295a71f3f194f1d02620e Mon Sep 17 00:00:00 2001 From: Craig Oates Date: Sun, 16 Dec 2018 05:30:18 +0000 Subject: [PATCH 03/10] refactor add-grid command (applyImageToGrid). --- DeathSocketCLI/Commands.fs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/DeathSocketCLI/Commands.fs b/DeathSocketCLI/Commands.fs index 995776e..754728f 100644 --- a/DeathSocketCLI/Commands.fs +++ b/DeathSocketCLI/Commands.fs @@ -59,8 +59,9 @@ let ``add-grid`` imgPath numRows numColumns pWidth colour newPath = try printfn "[INFO.] Adding grid to image..." - buildSpec imgPath numRows numColumns pWidth colour newPath - |> applyBrushSpecGridAsync + Brush (buildSpec imgPath numRows numColumns pWidth colour newPath) + |> applyImageToGrid + //|> applyBrushSpecGridAsync |> Async.Start showEndOfCommandMessage with From d7adc985c999dd9fc2363a144865b129e04b20db Mon Sep 17 00:00:00 2001 From: Craig Oates Date: Sun, 16 Dec 2018 05:32:26 +0000 Subject: [PATCH 04/10] refactor add-skia-grid (applyImageToGrid). --- DeathSocketCLI/Commands.fs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/DeathSocketCLI/Commands.fs b/DeathSocketCLI/Commands.fs index 754728f..e75c16f 100644 --- a/DeathSocketCLI/Commands.fs +++ b/DeathSocketCLI/Commands.fs @@ -113,8 +113,9 @@ let``add-skia-grid`` imgPath numRows numColumns pWidth colour newPath = printfn "[INFO.] Adding SkiaSharp grid to image..." - buildSkiaSpec imgPath numRows numColumns pWidth colour newPath - |> applySkiaGridAsync + Skia (buildSkiaSpec imgPath numRows numColumns pWidth colour newPath) + |> applyImageToGrid + //|> applySkiaGridAsync |> Async.Start showEndOfCommandMessage From 2b1a2c7b29dfa9c87c71f7378252d8cc2f4a3d6d Mon Sep 17 00:00:00 2001 From: Craig Oates Date: Sun, 16 Dec 2018 05:35:25 +0000 Subject: [PATCH 05/10] refactor add-skia-rgb-command (applyImageGrid). --- DeathSocketCLI/Commands.fs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/DeathSocketCLI/Commands.fs b/DeathSocketCLI/Commands.fs index e75c16f..093f8fe 100644 --- a/DeathSocketCLI/Commands.fs +++ b/DeathSocketCLI/Commands.fs @@ -121,8 +121,9 @@ let``add-skia-rgb-grid`` imgPath numRows numColumns pWidth r g b newPath = printfn "[INFO.] Adding SkiaSharp grid to image..." - buildSkiaRGBSpec imgPath numRows numColumns pWidth r g b newPath - |> applySkiaRGBGridAsync + SkiaRGB (buildSkiaRGBSpec imgPath numRows numColumns pWidth r g b newPath) + |> applyImageToGrid + //|> applySkiaRGBGridAsync |> Async.Start showEndOfCommandMessage From 54dabb9c07c226d7014b96ebc2006c06d1472c16 Mon Sep 17 00:00:00 2001 From: Craig Oates Date: Sun, 16 Dec 2018 05:37:19 +0000 Subject: [PATCH 06/10] remove temp. code and comments from Commands.fs. --- DeathSocketCLI/Commands.fs | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/DeathSocketCLI/Commands.fs b/DeathSocketCLI/Commands.fs index 093f8fe..1e61222 100644 --- a/DeathSocketCLI/Commands.fs +++ b/DeathSocketCLI/Commands.fs @@ -41,7 +41,6 @@ printfn "[INFO.] Adding default grid to image..." Brush (buildDefaultSpec imgPath newPath) |> applyImageToGrid - //|> applyBrushSpecGridAsync |> Async.Start showEndOfCommandMessage with @@ -61,7 +60,6 @@ printfn "[INFO.] Adding grid to image..." Brush (buildSpec imgPath numRows numColumns pWidth colour newPath) |> applyImageToGrid - //|> applyBrushSpecGridAsync |> Async.Start showEndOfCommandMessage with @@ -115,7 +113,6 @@ printfn "[INFO.] Adding SkiaSharp grid to image..." Skia (buildSkiaSpec imgPath numRows numColumns pWidth colour newPath) |> applyImageToGrid - //|> applySkiaGridAsync |> Async.Start showEndOfCommandMessage @@ -123,20 +120,5 @@ printfn "[INFO.] Adding SkiaSharp grid to image..." SkiaRGB (buildSkiaRGBSpec imgPath numRows numColumns pWidth r g b newPath) |> applyImageToGrid - //|> applySkiaRGBGridAsync |> Async.Start - showEndOfCommandMessage - - let dutest () = - printf "saving image..." - let b = - Brush (buildDefaultSpec "C:\Users\craig\Desktop\du-test.jpg" "C:\Users\craig\Desktop\du-test-brush.jpg") - // let r = buildRGBASpec... - let s = - Skia (buildSkiaSpec "C:\Users\craig\Desktop\du-test.jpg" 5 5 (float32 2) "Red" "C:\Users\craig\Desktop\du-test-skia.jpg") - let sR = - SkiaRGB (buildSkiaRGBSpec "C:\Users\craig\Desktop\du-test.jpg" 5 5 (float32 2) 12 56 121 "C:\Users\craig\Desktop\du-test-skia.jpg") - sR - |> applyImageToGrid - |> Async.RunSynchronously showEndOfCommandMessage \ No newline at end of file From 8910091adc05e6db92852ee456a174b9a5dd59c2 Mon Sep 17 00:00:00 2001 From: Craig Oates Date: Sun, 16 Dec 2018 05:47:20 +0000 Subject: [PATCH 07/10] mark untested code. --- DeathSocket/GridPainter.fs | 1 + 1 file changed, 1 insertion(+) diff --git a/DeathSocket/GridPainter.fs b/DeathSocket/GridPainter.fs index 1c7c718..f3dd2d3 100644 --- a/DeathSocket/GridPainter.fs +++ b/DeathSocket/GridPainter.fs @@ -215,6 +215,7 @@ namespace DeathSocket printfn "File could not be found at %s" ex.Message } + // Not tested let applyImageToGrid (spec: ImageSpec) = async { try From 392151692f63fd68ba3054d3d3e3c3baa791ea95 Mon Sep 17 00:00:00 2001 From: Craig Oates Date: Sun, 16 Dec 2018 06:38:07 +0000 Subject: [PATCH 08/10] 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 From d91e41bac6d181e03d7f8fba1dac17bc716ec26b Mon Sep 17 00:00:00 2001 From: Craig Oates Date: Sun, 16 Dec 2018 06:48:44 +0000 Subject: [PATCH 09/10] refactor tests to use applyGridToImageAsync function. --- TestCentre/LibraryTests.fs | 67 +++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/TestCentre/LibraryTests.fs b/TestCentre/LibraryTests.fs index 1c8331a..1ee1e20 100644 --- a/TestCentre/LibraryTests.fs +++ b/TestCentre/LibraryTests.fs @@ -102,6 +102,7 @@ open FsCheck.Xunit open DeathSocket open System.Drawing + open DeathSocket open DeathSocket.GridPainter open TestingHelpers open System.IO @@ -116,13 +117,13 @@ resetSavingTestArea () let oPath = generateLoadPath () let sPath = generateSavePath oPath - { originalPath = oPath - savePath = sPath - colour = randomBrush () :?> Brush - penWidth = float32 (newPenWidth()) - rows = 10 - columns = 10 } - |> applyBrushSpecGridAsync + Brush ({ originalPath = oPath + savePath = sPath + colour = randomBrush () :?> Brush + penWidth = float32 (newPenWidth()) + rows = 10 + columns = 10 }) + |> applyGridToImageAsync |> Async.RunSynchronously (File.Exists sPath) = true @@ -131,16 +132,16 @@ resetSavingTestArea () let oPath = generateLoadPath () let sPath = generateSavePath oPath - { originalPath = oPath - savePath = sPath - alpha = float (newRGBANum ()) - red = float (newRGBANum ()) - green = float (newRGBANum ()) - blue = float (newRGBANum ()) - penWidth = float32 (newPenWidth()) - rows = 10 - columns = 10 } - |> applyRGBAGridAsync + RGBA ({ originalPath = oPath + savePath = sPath + alpha = float (newRGBANum ()) + red = float (newRGBANum ()) + green = float (newRGBANum ()) + blue = float (newRGBANum ()) + penWidth = float32 (newPenWidth()) + rows = 10 + columns = 10 }) + |> applyGridToImageAsync |> Async.RunSynchronously (File.Exists sPath) = true @@ -180,13 +181,13 @@ resetSavingTestArea() let oPath = generateLoadPath () let sPath = generateSavePath oPath - { originalPath = oPath - savePath= sPath - skColour = randomSKColour () - penWidth = float32 (newPenWidth()) - rows = newNum () - columns = newNum () } - |> applySkiaGridAsync + Skia ({ originalPath = oPath + savePath= sPath + skColour = randomSKColour () + penWidth = float32 (newPenWidth()) + rows = newNum () + columns = newNum () }) + |> applyGridToImageAsync |> Async.RunSynchronously (File.Exists sPath) = true @@ -195,15 +196,15 @@ resetSavingTestArea() let oPath = generateLoadPath () let sPath = generateSavePath oPath - { originalPath = oPath - savePath= sPath - red = float32 (newRGBANum ()) - green = float32 (newRGBANum ()) - blue = float32 (newRGBANum ()) - penWidth = float32 (newPenWidth()) - rows = newNum () - columns = newNum () } - |> applySkiaRGBGridAsync + SkiaRGB ({ originalPath = oPath + savePath= sPath + red = float32 (newRGBANum ()) + green = float32 (newRGBANum ()) + blue = float32 (newRGBANum ()) + penWidth = float32 (newPenWidth()) + rows = newNum () + columns = newNum () }) + |> applyGridToImageAsync |> Async.RunSynchronously (File.Exists sPath) = true From 72d7fc40aacbe47530dd1a4bb5a1e5c7a1f4c7f4 Mon Sep 17 00:00:00 2001 From: Craig Oates Date: Sun, 23 Dec 2018 18:03:37 +0000 Subject: [PATCH 10/10] add comments and remove unused code. --- DeathSocket/GridPainter.fs | 19 ++++++++++++++++++- DeathSocket/ScratchPad.fsx | 6 +++--- TestCentre/LibraryTests.fs | 1 - 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/DeathSocket/GridPainter.fs b/DeathSocket/GridPainter.fs index 8172dd9..e961c71 100644 --- a/DeathSocket/GridPainter.fs +++ b/DeathSocket/GridPainter.fs @@ -17,7 +17,24 @@ namespace DeathSocket open ImageServices open System - // Not tested + /// + /// Uses the information included in spec to create a gridded image. + /// It then asynchronously saves it. Uses .jpg or .png formats only. + /// + /// + /// The specification used to generate the new gridded image. The + /// ImageSpec is a discriminated union, consisting of a Brush, RGBA, + /// Skia or SkiaRGB spec. + /// + /// + /// If the file the grid is being applied to cannot be found, + /// a FileNotFoundException will be thrown. + /// + /// let applyGridToImageAsync (spec: ImageSpec) = async { try diff --git a/DeathSocket/ScratchPad.fsx b/DeathSocket/ScratchPad.fsx index e14403b..c719984 100644 --- a/DeathSocket/ScratchPad.fsx +++ b/DeathSocket/ScratchPad.fsx @@ -1,6 +1,6 @@ -#r @"C:/Users/craig/.nuget/packages/skiasharp/1.60.3/lib/netstandard1.3/SkiaSharp.dll" +// These two paths need adjusting to match your computer. +#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" @@ -83,4 +83,4 @@ SkiaRGB ({ originalPath = desktop + "/test.jpg" rows = 10 columns = 10}) |> GridPainter.applyGridToImageAsync -|> Async.RunSynchronously \ No newline at end of file +|> Async.Start \ No newline at end of file diff --git a/TestCentre/LibraryTests.fs b/TestCentre/LibraryTests.fs index 1ee1e20..8e37eb1 100644 --- a/TestCentre/LibraryTests.fs +++ b/TestCentre/LibraryTests.fs @@ -102,7 +102,6 @@ open FsCheck.Xunit open DeathSocket open System.Drawing - open DeathSocket open DeathSocket.GridPainter open TestingHelpers open System.IO