Browse Source

add initial bits of code for expanding the amount of spec's.

Begin adding code to use the new specifications.
master
Craig Oates 6 years ago
parent
commit
c89dab50dd
  1. 14
      DeathSocket/ColourServices.fs
  2. 1
      DeathSocket/DeathSocket.fsproj
  3. 39
      DeathSocket/Domain.fs
  4. 19
      DeathSocket/GridPainter.fs
  5. 43
      DeathSocket/ImageServices.fs
  6. 4
      DeathSocket/ScratchPad.fsx
  7. 4
      DeathSocketCLI/AssemblyInfo.fs
  8. 2
      TestCentre/LibraryTests.fs

14
DeathSocket/ColourServices.fs

@ -0,0 +1,14 @@
module ColourServices
open System.Drawing
open DeathSocket.Domain
// not tested
let convertRGBAToBrush (spec: RGBASpec) =
let a = int spec.alpha
let r = int spec.red
let g = int spec.green
let b = int spec.blue
let colour = Color.FromArgb (a, r, g, b)
new SolidBrush(colour)

1
DeathSocket/DeathSocket.fsproj

@ -7,6 +7,7 @@
<ItemGroup>
<Compile Include="Domain.fs" />
<Compile Include="Validation.fs" />
<Compile Include="ColourServices.fs" />
<Compile Include="ImageServices.fs" />
<Compile Include="GridPainter.fs" />
<None Include="ScratchPad.fsx" />

39
DeathSocket/Domain.fs

@ -21,4 +21,43 @@
/// The number of rows the grid will have.
rows: int
///The number of columns the grid will have.
columns: int }
/// <summary>
/// The specification which uses System.Drawing brush to draw a grid.
/// </summary>
// REPLACING IMAGESPEC
type BrushSpec =
{ /// The original path of the image which the grid is being added to.
originalPath: string
/// The location of the new gridded image.
savePath: string
/// The (System.Drawing) brush used to draw the grid. This determines the colour.
colour: Brush
/// The thickness of the line on the grid.
penWidth: float32
/// The number of rows the grid will have.
rows: int
///The number of columns the grid will have.
columns: int }
type RGBASpec =
{ originalPath: string
savePath: string
alpha: float
red: float
green: float
blue: float
penWidth: float32
rows: int
columns: int }
type CMYKSpec =
{ originalPath: string
savePath: string
cyan: float
magenta: float
yellow: float
key: float32
rows: int
columns: int }

19
DeathSocket/GridPainter.fs

@ -28,7 +28,8 @@ 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 =
let applyGridAsync (spec: ImageSpec) =
// The spec is to be changed to Brush Spec.
async {
try
validateFilePath spec.originalPath |> ignore
@ -39,6 +40,20 @@ namespace DeathSocket
printfn "File could not be found at %s" ex.Message
}
// Not tested.
let applyRGBAGridAsync (spec: RGBASpec) =
async {
try
validateFilePath spec.originalPath |> ignore
validatFileType spec.savePath |> ignore
drawRGBAGrid spec
with
| :? FileNotFoundException as ex ->
printfn "File could not be found at %s" ex.Message
}
// let applyCMYKGridAsync -- to be added at a later date.
/// <summary>
/// Determines the (Pen) points needed to draw the appropriate number of horizontal lines (I.E. rows).
/// Each item in the array includes a start and end co-ordinate (point) for each line.
@ -48,6 +63,7 @@ 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>
@ -59,4 +75,5 @@ 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

43
DeathSocket/ImageServices.fs

@ -3,20 +3,25 @@
open System.Drawing
open System.Drawing.Imaging
open DeathSocket
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) ->
[| Point ((interval * point), 0)
Point ((interval * point), height)|]|]
let drawGrid spec =
// 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)
@ -30,4 +35,38 @@
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)
clone.Save (spec.savePath)
// not tested but same as Draw Grid -- this is its replacement
let drawBrushSpecGrid (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
let drawRGBAGrid (spec: RGBASpec) =
// 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 ((convertRGBAToBrush spec), 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)

4
DeathSocket/ScratchPad.fsx

@ -30,7 +30,7 @@ let verticalLines = createVerticalLines 300 600 10
Death Socket assumes either JPEG or PNG files so use other files at your own
risk. Cannot guarantee they will work. Also, either in this spec. can be
changed to suit your needs. *)
let spec =
let spec :ImageSpec =
{ originalPath = desktop + "/test.jpg"
savePath = desktop + "/grid.png"
colour = Brushes.Chartreuse
@ -39,4 +39,4 @@ let spec =
columns = 10 }
// Run this when you have finished building the spec.
GridPainter.applyGrid spec |> Async.RunSynchronously
GridPainter.applyGridAsync spec |> Async.RunSynchronously

4
DeathSocketCLI/AssemblyInfo.fs

@ -38,8 +38,8 @@ open System.Runtime.InteropServices
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [<assembly: AssemblyVersion("1.0.*")>]
[<assembly: AssemblyVersion("0.3.0.0")>]
[<assembly: AssemblyFileVersion("0.3.0.0")>]
[<assembly: AssemblyVersion("0.4.0.0")>]
[<assembly: AssemblyFileVersion("0.4.0.0")>]
do
()

2
TestCentre/LibraryTests.fs

@ -86,7 +86,7 @@
resetSavingTestArea ()
let oPath = generateLoadPath ()
let sPath = generateSavePath oPath
let spec =
let (spec: ImageSpec) =
{ originalPath = oPath
savePath = sPath
colour = randomBrush () :?> Brush

Loading…
Cancel
Save