Browse Source

Merge pull request #7 from CraigOates/0.6

0.6
master
Craig Oates 5 years ago committed by GitHub
parent
commit
c530a10848
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      DeathSocket/Domain.fs
  2. 45
      DeathSocket/GridPainter.fs
  3. 88
      DeathSocket/ScratchPad.fsx
  4. 6
      DeathSocket/Validation.fs
  5. 19
      DeathSocketCLI/Commands.fs
  6. 67
      TestCentre/LibraryTests.fs

10
DeathSocket/Domain.fs

@ -94,4 +94,12 @@
/// The number of rows the grid will have. /// The number of rows the grid will have.
rows: int rows: int
///The number of columns the grid will have. ///The number of columns the grid will have.
columns: int } columns: int }
/// Discriminated Union representing the various specification types
/// Death Socket can use to apply a grid to an image.
type ImageSpec =
| Brush of BrushSpec
| RGBA of RGBASpec
| Skia of SkiaSpec
| SkiaRGB of SkiaRGBSpec

45
DeathSocket/GridPainter.fs

@ -15,6 +15,46 @@ namespace DeathSocket
open Validation open Validation
open ImageServices open ImageServices
open System
/// <summary>
/// Uses the information included in spec to create a gridded image.
/// It then asynchronously saves it. Uses .jpg or .png formats only.
/// </summary>
/// <param name="spec">
/// The specification used to generate the new gridded image. The
/// ImageSpec is a discriminated union, consisting of a Brush, RGBA,
/// Skia or SkiaRGB spec.
/// </param>
/// <exeption cref="System.IO.FileNotFoundException">
/// If the file the grid is being applied to cannot be found,
/// a FileNotFoundException will be thrown.
/// </exception>
/// <remarks
/// Make sure the image, which is having the overlay added to it,
/// is not in use or needed by another program/process.
/// This is because it is locked whilst in this function.
/// </remarks>
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 // System.Drawing Functions
// ======================================================================== // ========================================================================
@ -62,6 +102,7 @@ namespace DeathSocket
/// is not in use or needed by another program/process. /// is not in use or needed by another program/process.
/// This is because it is locked whilst in this function. /// This is because it is locked whilst in this function.
/// </remarks> /// </remarks>
[<Obsolete("Method is deprecated, use applyGridToImage instead.")>]
let applyBrushSpecGridAsync (spec: BrushSpec) = let applyBrushSpecGridAsync (spec: BrushSpec) =
async { async {
try try
@ -90,6 +131,7 @@ namespace DeathSocket
/// is not in use or needed by another program/process. /// is not in use or needed by another program/process.
/// This is because it is locked whilst in this function. /// This is because it is locked whilst in this function.
/// </remarks> /// </remarks>
[<Obsolete("Method is deprecated, use applyGridToImage instead.")>]
let applyRGBAGridAsync (spec: RGBASpec) = let applyRGBAGridAsync (spec: RGBASpec) =
async { async {
try try
@ -162,7 +204,6 @@ namespace DeathSocket
let determineSKVerticalLines (width: int) (height: int) (columns: int) = let determineSKVerticalLines (width: int) (height: int) (columns: int) =
createSKVerticalLines width height columns createSKVerticalLines width height columns
/// <summary> /// <summary>
/// Uses the information included in spec to create a gridded image. /// Uses the information included in spec to create a gridded image.
/// It then asynchronously saves it. Uses .jpg or .png formats only. /// It then asynchronously saves it. Uses .jpg or .png formats only.
@ -178,6 +219,7 @@ namespace DeathSocket
/// is not in use or needed by another program/process. /// is not in use or needed by another program/process.
/// This is because it is locked whilst in this function. /// This is because it is locked whilst in this function.
/// </remarks> /// </remarks>
[<Obsolete("Method is deprecated, use applyGridToImage instead.")>]
let applySkiaGridAsync (spec: SkiaSpec) = let applySkiaGridAsync (spec: SkiaSpec) =
async { async {
try try
@ -204,6 +246,7 @@ namespace DeathSocket
/// is not in use or needed by another program/process. /// is not in use or needed by another program/process.
/// This is because it is locked whilst in this function. /// This is because it is locked whilst in this function.
/// </remarks> /// </remarks>
[<Obsolete("Method is deprecated, use applyGridToImage instead.")>]
let applySkiaRGBGridAsync (spec: SkiaRGBSpec) = let applySkiaRGBGridAsync (spec: SkiaRGBSpec) =
async { async {
try try

88
DeathSocket/ScratchPad.fsx

@ -1,5 +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\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"
#load "Domain.fs" #load "Domain.fs"
#load "Validation.fs" #load "Validation.fs"
@ -12,6 +13,8 @@ open System
open DeathSocket open DeathSocket
open Validation open Validation
open ImageServices open ImageServices
open SkiaSharp
(* Death Socket Scripts (* Death Socket Scripts
=============================================================================== ===============================================================================
@ -21,36 +24,63 @@ a nerw image. *)
let desktop = Environment.GetFolderPath (Environment.SpecialFolder.Desktop) let desktop = Environment.GetFolderPath (Environment.SpecialFolder.Desktop)
(* You will need to provide the image at the location specified. It will throw (* You will need to provide the image at the location specified. Both throw an
an exception if the file cannnot be found.*) exception if the file cannot be found or is the wrong extension. Death Socket
let validationTest = validateFilePath (desktop + "/test.jpg") 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 (* These are not needed by you to create an image. They here for you to check
start and end points of each pen stroke/path. *) the start and end points of each pen stroke/path. *)
let horizontalLines = createHorizontalLines 1000 500 10 let horizontalLines = createHorizontalLines 1000 500 10
let verticalLines = createVerticalLines 300 600 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. (* 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 Death Socket assumes either JPEG or PNG files.*)
risk. Cannot guarantee they will work. Also, either in this spec. can be
changed to suit your needs. *) // Brush Specification (uses System.Drawing)
let spec: BrushSpec = Brush ({ originalPath = desktop + "/test.jpg"
{ originalPath = desktop + "/test.jpg" savePath = desktop + "/grid.png"
savePath = desktop + "/grid.png" colour = Brushes.Chartreuse
colour = Brushes.Chartreuse penWidth = (float32 1)
penWidth = (float32 1) rows = 10
rows = 10 columns = 10 })
columns = 10 } |> GridPainter.applyGridToImageAsync
|> Async.Start
// Run this when you have finished building the spec.
GridPainter.applyBrushSpecGridAsync spec |> Async.RunSynchronously // RGBA Specification (uses System.Drawing)
RGBA ({ originalPath = desktop + "/test.jpg"
//***************************************************************************** savePath = desktop + "/grid.png"
alpha = float 1
(* Skia Sharp Draft red = float 122
=============================================================================== green = float 222
The code below here will eventually be worked into the main codebase or thrown blue = float 100
away. It is here acting as a first draft for integrating the Skia Sharp NuGet penWidth = (float32 1)
package into Death Socket. *) 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() // 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.Start

6
DeathSocket/Validation.fs

@ -13,4 +13,8 @@
| ".JPG" -> () | ".JPG" -> ()
| ".png" -> () | ".png" -> ()
| ".PNG" -> () | ".PNG" -> ()
| _ -> invalidArg "savePath" "The file type must be a .jpg or .png file." | _ -> invalidArg "savePath" "The file type must be a .jpg or .png file."
let validateIO iPath oPath =
validateFilePath iPath
validateSaveFileType oPath

19
DeathSocketCLI/Commands.fs

@ -8,6 +8,7 @@
open System.IO open System.IO
open Console.Waterworks open Console.Waterworks
open Console.Waterworks.Attributes open Console.Waterworks.Attributes
open DeathSocket.Domain
let showEndOfCommandMessage = "[INFO.] Task completed." let showEndOfCommandMessage = "[INFO.] Task completed."
@ -38,8 +39,8 @@
let ``add-default`` imgPath newPath = let ``add-default`` imgPath newPath =
try try
printfn "[INFO.] Adding default grid to image..." printfn "[INFO.] Adding default grid to image..."
buildDefaultSpec imgPath newPath Brush (buildDefaultSpec imgPath newPath)
|> applyBrushSpecGridAsync |> applyGridToImageAsync
|> Async.Start |> Async.Start
showEndOfCommandMessage showEndOfCommandMessage
with with
@ -57,8 +58,8 @@
let ``add-grid`` imgPath numRows numColumns pWidth colour newPath = let ``add-grid`` imgPath numRows numColumns pWidth colour newPath =
try try
printfn "[INFO.] Adding grid to image..." printfn "[INFO.] Adding grid to image..."
buildSpec imgPath numRows numColumns pWidth colour newPath Brush (buildSpec imgPath numRows numColumns pWidth colour newPath)
|> applyBrushSpecGridAsync |> applyGridToImageAsync
|> Async.Start |> Async.Start
showEndOfCommandMessage showEndOfCommandMessage
with with
@ -91,7 +92,7 @@
let ag imgPath numRows numColumns pWidth colour newPath = let ag imgPath numRows numColumns pWidth colour newPath =
``add-grid`` 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 (* SkiaSharp Command-Methods -- NOT FOR MASS CONSUMPTION
======================================================================= =======================================================================
@ -110,14 +111,14 @@
let``add-skia-grid`` imgPath numRows numColumns pWidth colour newPath = let``add-skia-grid`` imgPath numRows numColumns pWidth colour newPath =
printfn "[INFO.] Adding SkiaSharp grid to image..." printfn "[INFO.] Adding SkiaSharp grid to image..."
buildSkiaSpec imgPath numRows numColumns pWidth colour newPath Skia (buildSkiaSpec imgPath numRows numColumns pWidth colour newPath)
|> applySkiaGridAsync |> applyGridToImageAsync
|> Async.Start |> Async.Start
showEndOfCommandMessage showEndOfCommandMessage
let``add-skia-rgb-grid`` imgPath numRows numColumns pWidth r g b newPath = let``add-skia-rgb-grid`` imgPath numRows numColumns pWidth r g b newPath =
printfn "[INFO.] Adding SkiaSharp grid to image..." printfn "[INFO.] Adding SkiaSharp grid to image..."
buildSkiaRGBSpec imgPath numRows numColumns pWidth r g b newPath SkiaRGB (buildSkiaRGBSpec imgPath numRows numColumns pWidth r g b newPath)
|> applySkiaRGBGridAsync |> applyGridToImageAsync
|> Async.Start |> Async.Start
showEndOfCommandMessage showEndOfCommandMessage

67
TestCentre/LibraryTests.fs

@ -105,7 +105,6 @@
open DeathSocket.GridPainter open DeathSocket.GridPainter
open TestingHelpers open TestingHelpers
open System.IO open System.IO
open SkiaSharp
(* With regards to the "saving images" tests, you should end up with (* With regards to the "saving images" tests, you should end up with
one image left over in the SavingTestArea folder. Comment out the one image left over in the SavingTestArea folder. Comment out the
@ -117,13 +116,13 @@
resetSavingTestArea () resetSavingTestArea ()
let oPath = generateLoadPath () let oPath = generateLoadPath ()
let sPath = generateSavePath oPath let sPath = generateSavePath oPath
{ originalPath = oPath Brush ({ originalPath = oPath
savePath = sPath savePath = sPath
colour = randomBrush () :?> Brush colour = randomBrush () :?> Brush
penWidth = float32 (newPenWidth()) penWidth = float32 (newPenWidth())
rows = 10 rows = 10
columns = 10 } columns = 10 })
|> applyBrushSpecGridAsync |> applyGridToImageAsync
|> Async.RunSynchronously |> Async.RunSynchronously
(File.Exists sPath) = true (File.Exists sPath) = true
@ -132,16 +131,16 @@
resetSavingTestArea () resetSavingTestArea ()
let oPath = generateLoadPath () let oPath = generateLoadPath ()
let sPath = generateSavePath oPath let sPath = generateSavePath oPath
{ originalPath = oPath RGBA ({ originalPath = oPath
savePath = sPath savePath = sPath
alpha = float (newRGBANum ()) alpha = float (newRGBANum ())
red = float (newRGBANum ()) red = float (newRGBANum ())
green = float (newRGBANum ()) green = float (newRGBANum ())
blue = float (newRGBANum ()) blue = float (newRGBANum ())
penWidth = float32 (newPenWidth()) penWidth = float32 (newPenWidth())
rows = 10 rows = 10
columns = 10 } columns = 10 })
|> applyRGBAGridAsync |> applyGridToImageAsync
|> Async.RunSynchronously |> Async.RunSynchronously
(File.Exists sPath) = true (File.Exists sPath) = true
@ -181,13 +180,13 @@
resetSavingTestArea() resetSavingTestArea()
let oPath = generateLoadPath () let oPath = generateLoadPath ()
let sPath = generateSavePath oPath let sPath = generateSavePath oPath
{ originalPath = oPath Skia ({ originalPath = oPath
savePath= sPath savePath= sPath
skColour = randomSKColour () skColour = randomSKColour ()
penWidth = float32 (newPenWidth()) penWidth = float32 (newPenWidth())
rows = newNum () rows = newNum ()
columns = newNum () } columns = newNum () })
|> applySkiaGridAsync |> applyGridToImageAsync
|> Async.RunSynchronously |> Async.RunSynchronously
(File.Exists sPath) = true (File.Exists sPath) = true
@ -196,15 +195,15 @@
resetSavingTestArea() resetSavingTestArea()
let oPath = generateLoadPath () let oPath = generateLoadPath ()
let sPath = generateSavePath oPath let sPath = generateSavePath oPath
{ originalPath = oPath SkiaRGB ({ originalPath = oPath
savePath= sPath savePath= sPath
red = float32 (newRGBANum ()) red = float32 (newRGBANum ())
green = float32 (newRGBANum ()) green = float32 (newRGBANum ())
blue = float32 (newRGBANum ()) blue = float32 (newRGBANum ())
penWidth = float32 (newPenWidth()) penWidth = float32 (newPenWidth())
rows = newNum () rows = newNum ()
columns = newNum () } columns = newNum () })
|> applySkiaRGBGridAsync |> applyGridToImageAsync
|> Async.RunSynchronously |> Async.RunSynchronously
(File.Exists sPath) = true (File.Exists sPath) = true

Loading…
Cancel
Save