From 7007ed60db4dfa724f35efaee7408a0656187937 Mon Sep 17 00:00:00 2001 From: Craig Oates Date: Sun, 16 Dec 2018 05:10:39 +0000 Subject: [PATCH] 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