From f06451572f8d446220d9023a64331cfef5fc64be Mon Sep 17 00:00:00 2001 From: Craig Oates Date: Sat, 29 Dec 2018 13:29:34 +0000 Subject: [PATCH] update NuGets and add initial code for 0.7 features. --- DeathSocket/DeathSocket.fsproj | 2 +- DeathSocket/Domain.fs | 10 +++++++++- DeathSocket/GridPainter.fs | 30 ++++++++++++++++++---------- DeathSocket/ImageServices.fs | 12 ++++++++++- DeathSocket/ScratchPad.fsx | 26 ++++++++++++++++++------ DeathSocketCLI/DeathSocketCLI.fsproj | 6 +++--- DeathSocketCLI/packages.config | 2 +- TestCentre/LibraryTests.fs | 6 +++--- TestCentre/TestCentre.fsproj | 6 +++--- TestCentre/packages.config | 2 +- 10 files changed, 72 insertions(+), 30 deletions(-) diff --git a/DeathSocket/DeathSocket.fsproj b/DeathSocket/DeathSocket.fsproj index ab27a1b..5004753 100644 --- a/DeathSocket/DeathSocket.fsproj +++ b/DeathSocket/DeathSocket.fsproj @@ -30,7 +30,7 @@ - + diff --git a/DeathSocket/Domain.fs b/DeathSocket/Domain.fs index 5bf5a4b..5d93eef 100644 --- a/DeathSocket/Domain.fs +++ b/DeathSocket/Domain.fs @@ -6,6 +6,7 @@ open System.Drawing open SkiaSharp + open System.Threading /// The specification used to note the orignial file's location and the /// changes the user would like to make to it. (including the save @@ -102,4 +103,11 @@ | Brush of BrushSpec | RGBA of RGBASpec | Skia of SkiaSpec - | SkiaRGB of SkiaRGBSpec \ No newline at end of file + | SkiaRGB of SkiaRGBSpec + + /// Discriminated Union representing the graphics libraries used by + /// Desth Socket. Useful for selecting which one you want to use. + /// System.Drawing for using Windows/Mono and SkiaSharp for Xamarin. + type ImageType = + | SkiaSharp of string + | SystemDrawing of string \ No newline at end of file diff --git a/DeathSocket/GridPainter.fs b/DeathSocket/GridPainter.fs index 198b44c..205ba7f 100644 --- a/DeathSocket/GridPainter.fs +++ b/DeathSocket/GridPainter.fs @@ -58,16 +58,16 @@ namespace DeathSocket // NOT TESTED /// - /// Takes an image and determines the current scale it is viewed at - /// (E.G. scaled preview in image viewer). The (pen) line thickness is - /// then updated to match this preview scale and can be used when - /// drawing a grid line on the scaled preview of the image. + /// Determines the current scale an image is viewed at (E.G. scaled + /// preview in image viewer). The (pen) line thickness is then updated + /// to match this preview scale and can be used when drawing a grid + /// line on the scaled preview of the image. /// - /// - /// The width of the image when previewed (I.E. in a GUI). + /// + /// The width or height of the image when previewed (I.E. in a GUI). /// - /// - /// The width of the actual image. + /// + /// The width or height of the actual image. /// /// /// The thickness of the pen used to draw the grid line. @@ -78,8 +78,18 @@ namespace DeathSocket /// SkiaSharp based functions already scale the grid lines for you. So, /// you should not need to use this function when using them. /// - let scaleLineThickness (previewWidth: double) (actualWidth: double) (lineThickness: double) = - lineThickness / (previewWidth / actualWidth) + let scaleLineThickness (previewDimension: double) (actualDimension: double) (lineThickness: double) = + lineThickness / (previewDimension / actualDimension) + + // NOT TESTED. + let determineDimension imageType = + match imageType with + | SkiaSharp s -> + validateIO s |> ignore + determineSkiaDimensions s + | SystemDrawing d -> + validateIO d |> ignore + determineSystemDrawingDimensions d // System.Drawing Functions // ======================================================================== diff --git a/DeathSocket/ImageServices.fs b/DeathSocket/ImageServices.fs index c68b950..12cba6b 100644 --- a/DeathSocket/ImageServices.fs +++ b/DeathSocket/ImageServices.fs @@ -21,7 +21,13 @@ [| for point in 1 .. (columns - 1) -> [| SKPoint ((interval * (float32 point)), (float32 0)) SKPoint ((interval * (float32 point)), (float32 height))|]|] - + + let determineSkiaDimensions filePath = + use fileStream = File.Open (filePath, FileMode.Open) + use skStream = new SKManagedStream (fileStream) + use bitmap = SKBitmap.Decode (skStream) + (bitmap.Width, bitmap.Height) + let drawSkiaGrid (spec: SkiaSpec) = use fileStream = File.Open (spec.originalPath, FileMode.Open) use skStream = new SKManagedStream (fileStream) @@ -114,6 +120,10 @@ [| Point ((interval * point), 0) Point ((interval * point), height)|]|] + let determineSystemDrawingDimensions filePath = + use bitmap = Bitmap.FromFile filePath + (bitmap.Width, bitmap.Height) + (* Note on Use of Temp. File in Functions which Add A Grid Overlay =========================================================================== The temp. file is used in the functions below are there to convert images diff --git a/DeathSocket/ScratchPad.fsx b/DeathSocket/ScratchPad.fsx index c719984..d14be3c 100644 --- a/DeathSocket/ScratchPad.fsx +++ b/DeathSocket/ScratchPad.fsx @@ -1,6 +1,7 @@ // These two paths need adjusting to match your computer. -#r @"C:/Users/craig/.nuget/packages/skiasharp/1.60.3/lib/netstandard1.3/SkiaSharp.dll" -#r @"C:/Users/craig/.nuget/packages/skiasharp/1.60.3/lib/net45/SkiaSharp.dll" +#r @"C:/Users/craig/.nuget/packages/skiasharp/1.68.0/lib/netstandard1.3/SkiaSharp.dll" +// Currently not working... +// #r @"C:/Users/craig/.nuget/packages/skiasharp/1.68.0/runtimes/win10-x86/nativeassets/uap10.0/libSkiaSharp.dll" #load "Domain.fs" #load "Validation.fs" @@ -8,19 +9,19 @@ #load "ImageServices.fs" #load "GridPainter.fs" -open System.Drawing open System -open DeathSocket +open System.Drawing +open SkiaSharp open Validation open ImageServices -open SkiaSharp +open DeathSocket (* Death Socket Scripts =============================================================================== The code in here can be use to create a gridded image without running the CLI. You can, also, run checks to see what Death Socket is doing when creating -a nerw image. *) +a new image. *) let desktop = Environment.GetFolderPath (Environment.SpecialFolder.Desktop) @@ -40,6 +41,19 @@ let skVerticalLines = createSKVerticalLines 120 450 22 (* You will need to provide the image and specify its load/save location. Death Socket assumes either JPEG or PNG files.*) +// Not working at time of writing see "#r" comment (lines 3 and 4) +let skiaSharpDimensions = + determineSkiaDimensions (desktop + "/test.jpg") + +let systemDrawingDimensions = + determineSystemDrawingDimensions (desktop + "/test.jpg") + +let width = double (fst systemDrawingDimensions) // skiaSharpDimensions +let height = double (snd systemDrawingDimensions) // skiaSharpDimensions + +// Change the line thickness (the last parameter) to whatever you want. +let scaledPen = GridPainter.scaleLineThickness width height 8.0 + // Brush Specification (uses System.Drawing) Brush ({ originalPath = desktop + "/test.jpg" savePath = desktop + "/grid.png" diff --git a/DeathSocketCLI/DeathSocketCLI.fsproj b/DeathSocketCLI/DeathSocketCLI.fsproj index cf3d00a..5bd45b7 100644 --- a/DeathSocketCLI/DeathSocketCLI.fsproj +++ b/DeathSocketCLI/DeathSocketCLI.fsproj @@ -66,7 +66,7 @@ - ..\packages\SkiaSharp.1.60.3\lib\net45\SkiaSharp.dll + ..\packages\SkiaSharp.1.68.0\lib\net45\SkiaSharp.dll @@ -86,12 +86,12 @@ True - + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - +