Death Socket consists of three projects. They are a .Net Standard 2.0 library, a console program and a Test Centre. The purpose of this repository is to provide a way for people to add grids to images. https://www.craigoates.net/Software/project/13
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

115 lines
3.7 KiB

module DeathSocketCLI.Validation
open DeathSocket
open System.Drawing
open System
open System.IO
open SkiaSharp
(* This function creates a consistent line width amoung different image
sizes. Use this when the user has no means to specify a pen width. *)
let setPenWidth imgWidth imgHeight =
let width = float32 imgWidth
let height = float32 imgHeight
if (width >= height) then
height * (float32 0.002)
else width * (float32 0.002)
// System.Drawing Functions
// ========================================================================
let colourList =
[ "blue", Brushes.AliceBlue
"brown", Brushes.Brown
"black", Brushes.Black
"gray", Brushes.Gray
"grey", Brushes.Gray
"green", Brushes.Green
"purple", Brushes.Purple
"red", Brushes.Red
"white", Brushes.White
"yellow", Brushes.Yellow ]
|> Map.ofList
let isColourValid (colour: string) =
colourList
|> Map.containsKey (colour.ToLower())
let parseColour colour =
match (isColourValid colour) with
| true ->
colourList
|> Map.find (colour.ToLower())
| false ->
invalidArg "Colour"
(String.Concat("The colour specifed is invalid.\n",
"Please use the 'list-colours' command to see what you can use."))
let buildSpec (imgPath) (numRows) (numColumns) (pWidth) (colour) (newPath) : BrushSpec =
{ originalPath = imgPath
savePath = newPath
colour = parseColour colour
penWidth = pWidth
rows = numRows
columns = numColumns }
let buildDefaultSpec imgPath newPath =
use stream = new FileStream (imgPath, FileMode.Open)
use image = Image.FromStream (stream, false, false)
let spec : BrushSpec =
{ originalPath = imgPath
savePath = newPath
colour = Brushes.White
penWidth = setPenWidth (image.Width) (image.Height)
rows = 10
columns = 10 }
spec
// SkiaSharp Functions
// ========================================================================
let skiaColourList =
[ "blue", SKColors.AliceBlue
"brown", SKColors.Brown
"black", SKColors.Black
"gray", SKColors.Gray
"grey", SKColors.Gray
"green", SKColors.Green
"purple", SKColors.Purple
"red", SKColors.Red
"white", SKColors.White
"yellow", SKColors.Yellow ]
|> Map.ofList
let isSkiaColourValid (colour: string) =
skiaColourList
|> Map.containsKey (colour.ToLower())
let parseSkiaColour colour =
match (isSkiaColourValid colour) with
| true ->
skiaColourList
|> Map.find (colour.ToLower())
| false ->
invalidArg "Colour"
(String.Concat("The colour specifed is invalid.\n",
"Please use the 'list-skia-colours' command to see what you can use."))
let buildSkiaSpec imgPath numRows numColumns pWidth colour newPath =
let colour = parseSkiaColour colour
{ originalPath = imgPath
savePath = newPath
skColour = colour
penWidth = pWidth
rows = numRows
columns = numColumns }
let buildSkiaRGBSpec imgPath numRows numColumns pWidth r g b newPath =
{ originalPath = imgPath
savePath = newPath
red = (float32 r)
green = (float32 g)
blue = (float32 b)
penWidth = pWidth
rows = numRows
columns = numColumns }