From c58b8f0df4b96de505821a4d80fe92721bf4af8f Mon Sep 17 00:00:00 2001 From: Craig Oates Date: Sat, 20 Oct 2018 11:26:16 +0100 Subject: [PATCH] rename colour service functions and begin writing RGBa convertion test. --- DeathSocket/ColourServices.fs | 15 ++++++++++----- DeathSocket/GridPainter.fs | 8 ++++++++ DeathSocket/ImageServices.fs | 2 +- TestCentre/LibraryTests.fs | 16 +++++++++++++--- 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/DeathSocket/ColourServices.fs b/DeathSocket/ColourServices.fs index 606ca0f..3e29ee6 100644 --- a/DeathSocket/ColourServices.fs +++ b/DeathSocket/ColourServices.fs @@ -1,14 +1,19 @@ -module ColourServices +module internal ColourServices -open System.Drawing -open DeathSocket.Domain + open System.Drawing + open DeathSocket.Domain // not tested - let convertRGBAToBrush (spec: RGBASpec) = + let makeBrushFromRGBASpec (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) + new SolidBrush (colour) + + // not tested + let makeBrushFromRGBA r g b a = + let colour = Color.FromArgb (a, r, g, b) + new SolidBrush (colour) diff --git a/DeathSocket/GridPainter.fs b/DeathSocket/GridPainter.fs index f540b30..d5e097e 100644 --- a/DeathSocket/GridPainter.fs +++ b/DeathSocket/GridPainter.fs @@ -1,6 +1,7 @@ namespace DeathSocket open System.IO + open ColourServices /// Provides functions which help draw gridded overlays onto images. /// Grid Painter, and all of Death Socket, uses the System.Drawing brushes/colours. @@ -54,6 +55,13 @@ namespace DeathSocket // let applyCMYKGridAsync -- to be added at a later date. + // not tested. + let makeSolidBrushFromRGBA r g b a = makeBrushFromRGBA r g b a + + // not tested or completed. + let makeSolidBrushFromCMYK c m y k = + "" + /// /// 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. diff --git a/DeathSocket/ImageServices.fs b/DeathSocket/ImageServices.fs index 05e0d3c..398321a 100644 --- a/DeathSocket/ImageServices.fs +++ b/DeathSocket/ImageServices.fs @@ -58,7 +58,7 @@ 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) + use pen = new Pen ((makeBrushFromRGBASpec 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) diff --git a/TestCentre/LibraryTests.fs b/TestCentre/LibraryTests.fs index d2638ef..152758a 100644 --- a/TestCentre/LibraryTests.fs +++ b/TestCentre/LibraryTests.fs @@ -23,7 +23,6 @@ let rand = Random () - (* These are duplicates from ConsoleTests.fs (both of them). See point about helpers. Tests for checking these locations can be found in ConsoleTests.fs. *) @@ -46,6 +45,8 @@ Intended for horizontal and vertical line tests. *) let newNum () = rand.Next(1, 1000) + let newRGBANum () = rand.Next (255) + let imagesInLoadingTestArea = Directory.GetFileSystemEntries (loadLocation, "*.png") @@ -97,6 +98,15 @@ |> Async.RunSynchronously (File.Exists sPath) = true + [] + // need to write a test which tests the colour is the same once coverted. + let ``Can make a solid brush from RGBA values`` () = + let brush = + makeSolidBrushFromRGBA (newRGBANum ()) (newRGBANum ()) (newRGBANum ()) (newRGBANum ()) + let b = brush :? SolidBrush + b = true + + [] let ``Can return a collection of points which represent a grids horizontal lines`` () = let result = determineHorizontalLines (newNum()) (newNum()) (newNum()) @@ -115,7 +125,7 @@ open System open System.IO - (* This test is a precaution (a test for the tests if you will...). + (* This test is a pre-test test (a test for the tests if you will...). It is here to make sure the property test has what it needs to run. If the property test fails, here is a good place to start. See script.fs (in Test Centre) for information on populating the @@ -126,7 +136,7 @@ let imagesAreThere = if length < 100 then false else true Assert.True imagesAreThere - (* This test is a precaution. If the property tests fails, here is a + (* This test is a pre-test test. If the property tests fails, here is a good place to start. The easiest way to get this test to pass is to create a folder called "SavingTestArea" in this projects folder (at the root). You can, also, see script.fs (in Test Centre) for