@ -13,24 +13,23 @@ namespace DeathSocket
/// f u n c t i o n s .
module GridPainter =
open V a l i d a t i o n
open V a l i d a t i o n S e r v i c e s
open I m a g e P r e p
open I m a g e S e r v i c e s
open S y s t e m
open S k i a S h a r p
/// < s u m m a r y >
/// Uses the information included in spec to create a gridded i m a g e .
/// It then asynchronously saves it. Uses . jpg or . png formats o n l y .
/// Please note: Any buffer-based spec's (E.G. SkiaBufferSpec) will b e
/// ignored by this f u n c t i o n .
/// < / s u m m a r y >
/// <param n a m e = " s p e c " >
/// The specification used to generate the new gridded image. T h e
/// ImageSpec is a discriminated union, consisting of a Brush, R G B A ,
/// Skia or SkiaRGB s p e c .
/// < / p a r a m >
/// <exeption c r e f = " S y s t e m . I O . F i l e N o t F o u n d E x c e p t i o n " >
/// If the file the grid is being applied to cannot be f o u n d ,
/// a FileNotFoundException will be t h r o w n .
/// < / e x c e p t i o n >
/// < r e m a r k s
/// < r e m a r k s >
/// Make sure the image, which is having the overlay added to i t ,
/// is not in use or needed by another p r o g r a m / p r o c e s s .
/// This is because it is locked whilst in this f u n c t i o n .
@ -51,13 +50,70 @@ namespace DeathSocket
| SkiaRGB sR - >
validateIO sR.originalPath sR.savePath |> i g n o r e
drawSkiaRGBGrid s R
| _ -> printfn "[DEATH SOCKET INFO] Inappropriate ImageSpec used here. Please use none buffer-based spec's when using this f u n c t i o n . "
w i t h
| :? FileNotFoundException as ex - >
printfn "File could not be found at %s" e x . M e s s a g e
}
}
// System.Drawing F u n c t i o n s
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
// NOT T E S T E D .
/// < s u m m a r y >
/// Determines the current scale an image is viewed at (E.G. s c a l e d
/// preview in image viewer). The (pen) line thickness is then u p d a t e d
/// to match this preview scale and can be used when drawing a g r i d
/// line on the scaled preview of the i m a g e .
/// < / s u m m a r y >
/// <param n a m e = " p r e v i e w D i m e n s i o n " >
/// The width or height of the image when previewed (I.E. in a G U I ) .
/// < / p a r a m >
/// <param n a m e = " a c t u a l D i m e n s i o n " >
/// The width or height of the actual i m a g e .
/// < / p a r a m >
/// <param n a m e = " l i n e T h i c k n e s s " >
/// The thickness of the pen used to draw the grid l i n e .
/// < / p a r a m >
/// < r e m a r k s >
/// You should find you only need this function when dealing w i t h
/// previewing an image in a GUI. Another thing to note is t h e
/// SkiaSharp based functions already scale the grid lines for you. S o ,
/// you should not need to use this function when using t h e m .
/// < / r e m a r k s >
let scaleLineThickness (previewDimensions: int * int) (actualDimensions: int * int) (lineThickness: double) =
validateDimensions previewDimensions |> i g n o r e
validateDimensions actualDimensions |> i g n o r e
validateLineThickness |> i g n o r e
adjustLineThickness previewDimensions actualDimensions l i n e T h i c k n e s s
/// < s u m m a r y >
/// Reads an (jpg or png) image and return its width and height as a
/// tuple, (width * h i g h t ) .
/// < / s u m m a r y >
/// <param n a m e = " i m a g e T y p e " >
/// The name of the graphics library used to read and determine t h e
/// images d i m e n s i o n s .
/// < / p a r a m >
/// < r e m a r k s >
/// The image type is determined by the graphics library used. It i s
/// called "ImageType" and not "GraphicsLibUsed" because the i m a g e / f i l e
/// information is the thing this function cares about most of all. H o w
/// it is read and what library it uses it s e c o n d a r y .
/ / / < / r e m a r k s >
let determineImageDimensions (imgType: ImageType) =
t r y
match imgType w i t h
| SkiaSharp s - >
validateFilePath s |> i g n o r e
determineSkiaDimensions s
| SystemDrawing d - >
validateFilePath d |> i g n o r e
determineSystemDrawingDimensions d
w i t h
| :? FileNotFoundException as ex ->
printfn "%s" e x . M e s s a g e
reraise ( )
(* System.Drawing F u n c t i o n s
==================================================================== * )
/// < s u m m a r y >
/// Determines the (Pen) points needed to draw the appropriate n u m b e r
@ -68,7 +124,9 @@ namespace DeathSocket
/// <param name="width">The width of the i m a g e . < / p a r a m >
/// <param name="height">The height of the i m a g e . < / p a r a m >
/// <param name="rows">The number of rows the grid should h a v e . < / p a r a m >
/// <remarks>You will probably only need these when dealing with G U I ' s . < / r e m a r k s >
/// < r e m a r k s >
/// You will probably only need these when dealing with G U I ' s .
/// < / r e m a r k s >
let determineHorizontalLines (width: int) (height: int) (rows: int) =
createHorizontalLines width height r o w s
@ -80,68 +138,14 @@ namespace DeathSocket
/// < / s u m m a r y >
/// <param name="width">The width of the i m a g e . < / p a r a m >
/// <param name="height">The height of the i m a g e . < / p a r a m >
/// <param name="columns">The number of columns the grid should h a v e . < / p a r a m >
/// <remarks>You will probably only need these when dealing with G U I ' s . < / r e m a r k s >
let determineVerticalLines (width: int) (height: int) (columns: int) =
createVerticalLines width height c o l u m n s
/// < s u m m a r y >
/// Uses the information included in spec to create a gridded i m a g e .
/// It then asynchronously saves it. Uses . jpg or . png formats o n l y .
/// Use this function when targeting . N e t / M o n o ) .
/// < / s u m m a r y >
/// <param n a m e = " s p e c " >
/// The specification used to generate the new gridded i m a g e
/// < / p a r a m >
/// <exeption c r e f = " S y s t e m . I O . F i l e N o t F o u n d E x c e p t i o n " >
/// If the file the grid is being applied to cannot be f o u n d ,
/// a FileNotFoundException will be t h r o w n .
/// < / e x c e p t i o n >
/// < r e m a r k s
/// Make sure the image, which is having the overlay added to i t ,
/// is not in use or needed by another p r o g r a m / p r o c e s s .
/// This is because it is locked whilst in this f u n c t i o n .
/// < / r e m a r k s >
[<Obsolete("Method is deprecated, use applyGridToImage i n s t e a d . " ) > ]
let applyBrushSpecGridAsync (spec: BrushSpec) =
async {
t r y
validateFilePath spec.originalPath |> i g n o r e
validateSaveFileType spec.savePath |> i g n o r e
drawBrushSpecGrid spec |> i g n o r e
w i t h
| :? FileNotFoundException as ex - >
printfn "File could not be found at %s" e x . M e s s a g e
}
/// < s u m m a r y >
/// Uses the information included in spec to create a gridded image. I t
/// then asynchronously saves it. Uses . jpg or . png formats o n l y .
/// Use this function when targeting . N e t / M o n o ) .
/// < / s u m m a r y >
/// <param n a m e = " s p e c " >
/// The specification used to generate the gridded i m a g e .
/// <param n a m e = " c o l u m n s " >
/// The number of columns the grid should h a v e .
/// < / p a r a m >
/// <exeption c r e f = " S y s t e m . I O . F i l e N o t F o u n d E x c e p t i o n " >
/// If the file the grid is being applied to cannot be f o u n d ,
/// a FileNotFoundException will be t h r o w n .
/// < / e x c e p t i o n >
/// < r e m a r k s
/// Make sure the image, which is having the overlay added to i t ,
/// is not in use or needed by another p r o g r a m / p r o c e s s .
/// This is because it is locked whilst in this f u n c t i o n .
/// < r e m a r k s >
/// You will probably only need these when dealing with G U I ' s .
/// < / r e m a r k s >
[<Obsolete("Method is deprecated, use applyGridToImage i n s t e a d . " ) > ]
let applyRGBAGridAsync (spec: RGBASpec) =
async {
t r y
validateFilePath spec.originalPath |> i g n o r e
validateSaveFileType spec.savePath |> i g n o r e
drawRGBAGrid s p e c
w i t h
| :? FileNotFoundException as ex - >
printfn "File could not be found at %s" e x . M e s s a g e
}
let determineVerticalLines (width: int) (height: int) (columns: int) =
createVerticalLines width height c o l u m n s
/// < s u m m a r y >
/// Creates a Sytsem.Drawing SolidBrush from the individual RGBA v a l u e s .
@ -163,8 +167,8 @@ namespace DeathSocket
/// Use this function when targeting . N e t / M o n o ) .
/// < / s u m m a r y >
/// <param n a m e = " s p e c " >
///The specification which the brush is made f r o m .
/ / / < / p a r a m >
/// The specification which the brush is made f r o m .
/// < / p a r a m >
/// < r e m a r k s >
/// Death Socket uses System.Drawing and not System.Media for c o l o u r s
/// and b r u s h e s .
@ -172,8 +176,44 @@ namespace DeathSocket
let makeSolidBrushFromRGBASpec (spec: RGBASpec) =
makeBrushFromRGBASpec s p e c
// SkiaSharp F u n c t i o n s
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
(* SkiaSharp F u n c t i o n s
==================================================================== * )
/// < s u m m a r y >
/// Uses the information included in spec to create a SKData b u f f e r .
/// The buffer will contain a gridded image which you can then use i n
/// any way you see fit. Accepted image formats are limited to . j p g
/// and . png. Please note: Any non buffer-based spec's (E.G. S k i a S p e c )
/// will be ignored by this f u n c t i o n .
/// < / s u m m a r y >
/// <param n a m e = " s p e c " >
/// The specification used to generate the new SKData buffer. T h e
/// ImageSpec is a discriminated union, consisting of a SkiaBuffer a n d
/// a SkiaRGBBuffer s p e c .
/// < / p a r a m >
/// < r e m a r k s >
/// Make sure the image, which is used to create the SKData b u f f e r ,
/// is not in use or needed by another p r o g r a m / p r o c e s s .
/// This is because it is locked whilst in this f u n c t i o n .
/// < / r e m a r k s >
let createSKDataAsync (spec: ImageSpec) =
async {
t r y
match spec w i t h
| SkiaBuffer s - >
validateFilePath s.filePath |> i g n o r e
return createSkiaBuffer s
| SkiaRGBBuffer sR - >
validateFilePath sR.filePath |> i g n o r e
return createSkiaRGBBuffer s R
| _ ->
printfn "[DEATH SOCKET INFO] Inappropriate ImageSpec used here. Please use buffer-based spec's when using this function. Returning an empty SKData o b j e c t . "
return S K D a t a . E m p t y
w i t h
| :? FileNotFoundException as ex - >
printfn "%s" ex.Message |> i g n o r e
return S K D a t a . E m p t y
}
/// < s u m m a r y >
/// Determines the (SKPoints) points needed to draw the a p p r o p r i a t e
@ -184,8 +224,10 @@ namespace DeathSocket
/// <param name="width">The width of the i m a g e . < / p a r a m >
/// <param name="height">The height of the i m a g e . < / p a r a m >
/// <param name="rows">The number of rows the grid should h a v e . < / p a r a m >
/// <remarks>This function is part of the SkiaSharp functions p r o v i d e d
/// by Death S o c k e t . < / r e m a r k s >
/// < r e m a r k s >
/// This function is part of the SkiaSharp functions p r o v i d e d
/// by Death S o c k e t .
/// < / r e m a r k s >
let determineSKHorizontalLines (width: int) (height: int) (rows: int) =
createSKHorizontalLines width height r o w s
@ -199,61 +241,9 @@ namespace DeathSocket
/// <param name="height">The height of the i m a g e . < / p a r a m >
/// <param name="columns">The number of columns the grid should h a v e .
/// < / p a r a m >
/// <remarks>This function is part of the SkiaSharp functions p r o v i d e d
/// by Death S o c k e t . < / r e m a r k s >
let determineSKVerticalLines (width: int) (height: int) (columns: int) =
createSKVerticalLines width height c o l u m n s
/// < s u m m a r y >
/// Uses the information included in spec to create a gridded i m a g e .
/// It then asynchronously saves it. Uses . jpg or . png formats o n l y .
/// Use this function when targeting Xamarin/UWP/.Net C o r e .
/// < / s u m m a r y >
/// <param n a m e = " s p e c " >
/// Used to note the orignial file's location and t h e
/// changes the user would like to make to it (including the s a v e
/// location of the modified v e r s i o n ) .
/// < / p a r a m >
/// < r e m a r k s >
/// Make sure the image, which is having the overlay added to i t ,
/// is not in use or needed by another p r o g r a m / p r o c e s s .
/// This is because it is locked whilst in this f u n c t i o n .
/// < / r e m a r k s >
[<Obsolete("Method is deprecated, use applyGridToImage i n s t e a d . " ) > ]
let applySkiaGridAsync (spec: SkiaSpec) =
async {
t r y
validateFilePath spec.originalPath |> i g n o r e
validateSaveFileType spec.savePath |> i g n o r e
drawSkiaGrid s p e c
w i t h
| :? FileNotFoundException as ex - >
printfn "File could not be found at %s" e x . M e s s a g e
}
/// < s u m m a r y >
/// Uses the information included in spec to create a gridded i m a g e .
/// It then asynchronously saves it. Uses . jpg or . png formats o n l y .
/// Use this function when targeting Xamarin/UWP/.Net C o r e .
/// < / s u m m a r y >
/// <param n a m e = " s p e c " >
/// Used to note the orignial file's location and t h e
/// changes the user would like to make to it (including the s a v e
/// location of the modified v e r s i o n ) .
/// < / p a r a m >
/// < r e m a r k s >
/// Make sure the image, which is having the overlay added to i t ,
/// is not in use or needed by another p r o g r a m / p r o c e s s .
/// This is because it is locked whilst in this f u n c t i o n .
/// This function is part of the SkiaSharp functions provided by D e a t h
/// S o c k e t .
/// < / r e m a r k s >
[<Obsolete("Method is deprecated, use applyGridToImage i n s t e a d . " ) > ]
let applySkiaRGBGridAsync (spec: SkiaRGBSpec) =
async {
t r y
validateFilePath spec.originalPath |> i g n o r e
validateSaveFileType spec.savePath |> i g n o r e
drawSkiaRGBGrid s p e c
w i t h
| :? FileNotFoundException as ex - >
printfn "File could not be found at %s" e x . M e s s a g e
}
let determineSKVerticalLines (width: int) (height: int) (columns: int) =
createSKVerticalLines width height c o l u m n s