namespace DeathSocket open System.IO open ColourServices /// Provides functions which help draw gridded overlays onto images. /// Death Socket, uses System.Drawing's brushes and colours. /// If you are using System.Media brushes and colour, you will need to /// convert them. Death Socket, also, uses SkiaSharp for cross platform /// functionality. If you are using Death Socket on Windows Desktop, use /// functions which do not include "Skia" in their name. If you are using /// Death Socket in a Xamarin/UWP project you should use the SkiaSharp /// functions. module GridPainter = open Validation open ImageServices open System // Not tested let applyGridToImageAsync (spec: ImageSpec) = async { try match spec with | Brush b -> validateIO b.originalPath b.savePath |> ignore drawBrushSpecGrid b | RGBA r -> validateIO r.originalPath r.savePath |> ignore drawRGBAGrid r | Skia s -> validateIO s.originalPath s.savePath |> ignore drawSkiaGrid s | SkiaRGB sR -> validateIO sR.originalPath sR.savePath |> ignore drawSkiaRGBGrid sR with | :? FileNotFoundException as ex -> printfn "File could not be found at %s" ex.Message } // System.Drawing Functions // ======================================================================== /// /// 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. /// Use this function when targeting .Net/Mono). /// /// The width of the image. /// The height of the image. /// The number of rows the grid should have. /// You will probably only need these when dealing with GUI's. let determineHorizontalLines (width: int) (height: int) (rows: int) = createHorizontalLines width height rows /// /// Determines the (Pen) points needed to draw the appropriate number /// of vertical lines (I.E. columns). Each item in the array includes a /// start and end co-ordinate (point) for each line. /// Use this function when targeting Windows Desktop (or Mono). /// /// The width of the image. /// The height of the image. /// The number of columns the grid should have. /// You will probably only need these when dealing with GUI's. 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). /// /// The red value. /// The green value. /// The blue value. /// The alpha value. /// /// Death Socket uses System.Drawing and not System.Media for colours /// and brushes. /// let makeSolidBrushFromRGBA (r: int) (g: int) (b:int) (a: int) = makeBrushFromRGBA r g b a /// /// Creates a System.Drawing SolidBrush from a RGBASpec. /// Use this function when targeting .Net/Mono). /// /// ///The specification which the brush is made from. /// /// /// Death Socket uses System.Drawing and not System.Media for colours /// and brushes. /// let makeSolidBrushFromRGBASpec (spec: RGBASpec) = makeBrushFromRGBASpec spec // SkiaSharp Functions // ======================================================================== /// /// Determines the (SKPoints) points needed to draw the appropriate /// number of horizontal lines (I.E. rows). Each item in the array /// included a start and end co-ordinate (SKPoint) for each line. /// Use this function when targeting Xamarin/UWP/.Net Core (SkiaSharp). /// /// The width of the image. /// The height of the image. /// The number of rows the grid should have. /// This function is part of the SkiaSharp functions provided /// by Death Socket. let determineSKHorizontalLines (width: int) (height: int) (rows: int) = createSKHorizontalLines width height rows /// /// Determines the (SKPoints) points needed to draw the appropriate /// number of vertical lines (I.E. columns). Each item in the array /// included a start and end co-ordinate (SKPoint) for each line. /// Use this function when targeting Xamarin/UWP/.Net Core (SkiaSharp). /// /// The width of the image. /// The height of the image. /// The number of columns the grid should have. /// /// 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 }