From 6f90055c214fdd26ef1a7aa9e22fb4f5742a2395 Mon Sep 17 00:00:00 2001 From: Craig Oates Date: Tue, 25 Dec 2018 16:28:33 +0000 Subject: [PATCH 01/31] remove functions marked as obsolete. --- DeathSocket/GridPainter.fs | 114 +------------------------------------ 1 file changed, 1 insertion(+), 113 deletions(-) diff --git a/DeathSocket/GridPainter.fs b/DeathSocket/GridPainter.fs index e961c71..e55197a 100644 --- a/DeathSocket/GridPainter.fs +++ b/DeathSocket/GridPainter.fs @@ -85,64 +85,6 @@ namespace DeathSocket let determineVerticalLines (width: int) (height: int) (columns: int) = createVerticalLines width height columns - /// - /// Uses the information included in spec to create a gridded image. - /// It then asynchronously saves it. Uses .jpg or .png formats only. - /// Use this function when targeting .Net/Mono). - /// - /// - /// The specification used to generate the new gridded image - /// - /// - /// If the file the grid is being applied to cannot be found, - /// a FileNotFoundException will be thrown. - /// - /// - [] - let applyBrushSpecGridAsync (spec: BrushSpec) = - async { - try - validateFilePath spec.originalPath |> ignore - validateSaveFileType spec.savePath |> ignore - drawBrushSpecGrid spec |> ignore - with - | :? FileNotFoundException as ex -> - printfn "File could not be found at %s" ex.Message - } - - /// - /// Uses the information included in spec to create a gridded image. It - /// then asynchronously saves it. Uses .jpg or .png formats only. - /// Use this function when targeting .Net/Mono). - /// - /// - /// The specification used to generate the gridded image. - /// - /// - /// If the file the grid is being applied to cannot be found, - /// a FileNotFoundException will be thrown. - /// - /// - [] - let applyRGBAGridAsync (spec: RGBASpec) = - async { - try - validateFilePath spec.originalPath |> ignore - validateSaveFileType spec.savePath |> ignore - drawRGBAGrid spec - with - | :? FileNotFoundException as ex -> - printfn "File could not be found at %s" ex.Message - } - /// /// Creates a Sytsem.Drawing SolidBrush from the individual RGBA values. /// Use this function when targeting .Net/Mono). @@ -202,58 +144,4 @@ namespace DeathSocket /// This function is part of the SkiaSharp functions provided /// by Death Socket. let determineSKVerticalLines (width: int) (height: int) (columns: int) = - createSKVerticalLines width height columns - - /// - /// Uses the information included in spec to create a gridded image. - /// It then asynchronously saves it. Uses .jpg or .png formats only. - /// Use this function when targeting Xamarin/UWP/.Net Core. - /// - /// - /// Used to note the orignial file's location and the - /// changes the user would like to make to it (including the save - /// location of the modified version). - /// - /// - /// Make sure the image, which is having the overlay added to it, - /// is not in use or needed by another program/process. - /// This is because it is locked whilst in this function. - /// - [] - let applySkiaGridAsync (spec: SkiaSpec) = - async { - try - validateFilePath spec.originalPath |> ignore - validateSaveFileType spec.savePath |> ignore - drawSkiaGrid spec - with - | :? FileNotFoundException as ex -> - printfn "File could not be found at %s" ex.Message - } - - /// - /// Uses the information included in spec to create a gridded image. - /// It then asynchronously saves it. Uses .jpg or .png formats only. - /// Use this function when targeting Xamarin/UWP/.Net Core. - /// - /// - /// Used to note the orignial file's location and the - /// changes the user would like to make to it (including the save - /// location of the modified version). - /// - /// - /// Make sure the image, which is having the overlay added to it, - /// is not in use or needed by another program/process. - /// This is because it is locked whilst in this function. - /// - [] - let applySkiaRGBGridAsync (spec: SkiaRGBSpec) = - async { - try - validateFilePath spec.originalPath |> ignore - validateSaveFileType spec.savePath |> ignore - drawSkiaRGBGrid spec - with - | :? FileNotFoundException as ex -> - printfn "File could not be found at %s" ex.Message - } \ No newline at end of file + createSKVerticalLines width height columns \ No newline at end of file From 941577ec80e4dba2d3a06206c05f2f9af355ace4 Mon Sep 17 00:00:00 2001 From: Craig Oates Date: Sat, 29 Dec 2018 11:45:22 +0000 Subject: [PATCH 02/31] add function to scale (pen) line thickness. --- DeathSocket/GridPainter.fs | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/DeathSocket/GridPainter.fs b/DeathSocket/GridPainter.fs index e55197a..198b44c 100644 --- a/DeathSocket/GridPainter.fs +++ b/DeathSocket/GridPainter.fs @@ -15,7 +15,6 @@ namespace DeathSocket open Validation open ImageServices - open System /// /// Uses the information included in spec to create a gridded image. @@ -30,7 +29,7 @@ namespace DeathSocket /// If the file the grid is being applied to cannot be found, /// a FileNotFoundException will be thrown. /// - /// /// Make sure the image, which is having the overlay added to it, /// is not in use or needed by another program/process. /// This is because it is locked whilst in this function. @@ -54,7 +53,33 @@ namespace DeathSocket with | :? FileNotFoundException as ex -> printfn "File could not be found at %s" ex.Message - } + } + + // 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. + /// + /// + /// The width of the image when previewed (I.E. in a GUI). + /// + /// + /// The width of the actual image. + /// + /// + /// The thickness of the pen used to draw the grid line. + /// + /// + /// You should find you only need this function when dealing with + /// previewing an image in a GUI. Another thing to note is the + /// 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) // System.Drawing Functions // ======================================================================== From f06451572f8d446220d9023a64331cfef5fc64be Mon Sep 17 00:00:00 2001 From: Craig Oates Date: Sat, 29 Dec 2018 13:29:34 +0000 Subject: [PATCH 03/31] 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}. - +