module DeathSocket.Validation
open DeathSocket
open System.Drawing
open System
open System.IO
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 setPenWidth imgWidth imgHeight =
let width = float32 imgWidth
let height = float32 imgHeight
if (width >= height) then
height * (float32 0 .002 )
else width * (float32 0 .002 )
let buildSpec imgPath numRows numColumns pWidth colour newPath =
{ originalPath = imgPath
savePath = newPath
colour = parseColour colour
penWidth = pWidth
rows = numRows
columns = numColumns }
let buildDefaultSpec imgPath newPath =
let stream = new FileStream (imgPath, FileMode.Open)
let image = Image.FromStream (stream, false, false)
let spec =
{ originalPath = imgPath
savePath = newPath
colour = Brushes.White
penWidth = setPenWidth (image.Width) (image.Height)
rows = 10
columns = 10 }
stream.Dispose ()
image.Dispose ()
spec