Browse Source

refactor ImageSpec to BrushSpec.

Comment-out code which uses the ImageSpec and mark code as obsolete when still active.
master
Craig Oates 6 years ago
parent
commit
23e3408b06
  1. 2
      DeathSocket/Domain.fs
  2. 8
      DeathSocket/GridPainter.fs
  3. 32
      DeathSocket/ImageServices.fs
  4. 4
      DeathSocketCLI/Commands.fs
  5. 4
      TestCentre/LibraryTests.fs

2
DeathSocket/Domain.fs

@ -5,10 +5,12 @@
module Domain =
open System.Drawing
open System
/// <summary>
/// The specification used by Death Socket when adding a grid to an image.
/// </summary>
[<Obsolete "Please use the BrushSpec type.">]
type ImageSpec =
{ /// The original path of the image which the grid is being added to.
originalPath: string

8
DeathSocket/GridPainter.fs

@ -14,7 +14,7 @@ namespace DeathSocket
/// Uses the information included in spec and creates a gridded image.
/// It then asynchronously saves it.
/// Please stick to .bmp, .jpg or .png files.
/// The others (image) file types have not been tested.
/// The other (image) file types have not been tested.
/// </summary>
/// <param name="spec">
/// The specification used to generate the new gridded image
@ -28,13 +28,13 @@ namespace DeathSocket
/// is not in use or needed by another program/process.
/// This is because it is locked whilst in this function.
/// </remarks>
let applyGridAsync (spec: ImageSpec) =
let applyBrushSpecGridAsync (spec: BrushSpec) =
// The spec is to be changed to Brush Spec.
async {
try
validateFilePath spec.originalPath |> ignore
validatFileType spec.savePath |> ignore
drawGrid spec |> ignore
drawBrushSpecGrid spec |> ignore
with
| :? FileNotFoundException as ex ->
printfn "File could not be found at %s" ex.Message
@ -63,7 +63,6 @@ namespace DeathSocket
/// <param name="rows">The number of rows the grid should have.</param>
/// <remarks>You will probably only need these when dealing with GUI's.</remarks>
let determineHorizontalLines width height rows =
// To Be moved to its own service and made public. No wrapper needed.
createHorizontalLines width height rows
/// <summary>
@ -75,5 +74,4 @@ namespace DeathSocket
/// <param name="columns">The number of columns the grid should have.</param>
/// <remarks>You will probably only need these when dealing with GUI's.</remarks>
let determineVerticalLines width height columns =
// To Be moved to its own service and made public. No wrapper needed.
createVerticalLines width height columns

32
DeathSocket/ImageServices.fs

@ -6,14 +6,12 @@
open Validation
open ColourServices
// To Be moved to its own service and made public. No wrapper needed.
let createHorizontalLines width height rows =
let interval = height / rows
[| for point in 1 .. (rows - 1) ->
[|Point (0, (interval * point))
Point (width, (interval * point) )|]|]
// To Be moved to its own service and made public. No wrapper needed.
let createVerticalLines width height columns =
let interval = width / columns
[| for point in 1 .. (columns - 1) ->
@ -21,21 +19,21 @@
Point ((interval * point), height)|]|]
// To be deleted -- replaced with brush spec.
let drawGrid (spec: ImageSpec) =
// The temp. file is used as a way to convert images with indexed pixels.
use original = Bitmap.FromFile spec.originalPath
use temp = new Bitmap(original)
use clone = temp.Clone(new Rectangle(0, 0, temp.Width, temp.Height), PixelFormat.Format32bppArgb)
use graphics = Graphics.FromImage(clone)
use pen = new Pen (spec.colour, width = spec.penWidth)
graphics.DrawImage(original,new Rectangle(0, 0, clone.Width, clone.Height))
let horizontalLines =
createHorizontalLines (clone.Size.Width) (clone.Size.Height) (spec.rows)
let verticalLines =
createVerticalLines (clone.Size.Width) (clone.Size.Height) (spec.columns)
for line in horizontalLines do graphics.DrawLines (pen, line)
for line in verticalLines do graphics.DrawLines (pen, line)
clone.Save (spec.savePath)
//let drawGrid (spec: BrushSpec) =
// // The temp. file is used as a way to convert images with indexed pixels.
// use original = Bitmap.FromFile spec.originalPath
// use temp = new Bitmap(original)
// use clone = temp.Clone(new Rectangle(0, 0, temp.Width, temp.Height), PixelFormat.Format32bppArgb)
// use graphics = Graphics.FromImage(clone)
// use pen = new Pen (spec.colour, width = spec.penWidth)
// graphics.DrawImage(original,new Rectangle(0, 0, clone.Width, clone.Height))
// let horizontalLines =
// createHorizontalLines (clone.Size.Width) (clone.Size.Height) (spec.rows)
// let verticalLines =
// createVerticalLines (clone.Size.Width) (clone.Size.Height) (spec.columns)
// for line in horizontalLines do graphics.DrawLines (pen, line)
// for line in verticalLines do graphics.DrawLines (pen, line)
// clone.Save (spec.savePath)
// not tested but same as Draw Grid -- this is its replacement
let drawBrushSpecGrid (spec: BrushSpec) =

4
DeathSocketCLI/Commands.fs

@ -38,7 +38,7 @@
try
printfn "[INFO.] Adding default grid to image..."
buildDefaultSpec imgPath newPath
|> applyGridAsync
|> applyBrushSpecGridAsync
|> Async.Start
showEndOfCommandMessage
with
@ -57,7 +57,7 @@
try
printfn "[INFO.] Adding grid to image..."
buildSpec imgPath numRows numColumns pWidth colour newPath
|> applyGridAsync
|> applyBrushSpecGridAsync
|> Async.Start
showEndOfCommandMessage
with

4
TestCentre/LibraryTests.fs

@ -86,14 +86,14 @@
resetSavingTestArea ()
let oPath = generateLoadPath ()
let sPath = generateSavePath oPath
let (spec: ImageSpec) =
let (spec: BrushSpec) =
{ originalPath = oPath
savePath = sPath
colour = randomBrush () :?> Brush
penWidth = float32 1
rows = 10
columns = 10 }
applyGridAsync spec
applyBrushSpecGridAsync spec
|> Async.RunSynchronously
(File.Exists sPath) = true

Loading…
Cancel
Save