Browse Source

add grey scale functionality to RGBASpec image type.

The code can now convert the image into grey scale and add a grid on top of it when using the RGBASpec. The commands in the console program can now pass on the grey scale variable to. The Skia Sharp functions still need this functionality added it.
unstable
Craig Oates 4 years ago
parent
commit
507da455bf
  1. 4
      DeathSocket/GridPainter.fs
  2. 24
      DeathSocket/ImageServices.fs
  3. 8
      DeathSocketCLI/Commands.fs

4
DeathSocket/GridPainter.fs

@ -50,10 +50,10 @@ namespace DeathSocket
| false -> drawRGBAGrid r | false -> drawRGBAGrid r
| Skia s -> | Skia s ->
validateIO s.originalPath s.savePath |> ignore validateIO s.originalPath s.savePath |> ignore
drawSkiaGrid s // greyScale drawSkiaGrid s // greyScale not implemented
| SkiaRGB sR -> | SkiaRGB sR ->
validateIO sR.originalPath sR.savePath |> ignore validateIO sR.originalPath sR.savePath |> ignore
drawSkiaRGBGrid sR // greyScale drawSkiaRGBGrid sR // greyScale not implemented
| _ -> printfn "[DEATH SOCKET INFO] Inappropriate ImageSpec used here. Please use none buffer-based spec's when using this function." | _ -> printfn "[DEATH SOCKET INFO] Inappropriate ImageSpec used here. Please use none buffer-based spec's when using this function."
with with
| :? FileNotFoundException as ex -> | :? FileNotFoundException as ex ->

24
DeathSocket/ImageServices.fs

@ -255,12 +255,30 @@
clone.Save (spec.savePath) clone.Save (spec.savePath)
let drawRGBAGridGrey (spec: RGBASpec) = let drawRGBAGridGrey (spec: RGBASpec) =
// THIS NEEDS REFACTORING TO CONVERT IMAGE TO GREYSCALE. // This part converts the images to greyscale.
use original = Bitmap.FromFile spec.originalPath use original = Bitmap.FromFile spec.originalPath
use temp = new Bitmap (original) use temp = new Bitmap (original)
use clone = use clone = new Bitmap(temp.Width, temp.Height)
temp.Clone (new Rectangle(0, 0, temp.Width, temp.Height), PixelFormat.Format32bppArgb) use g = Graphics.FromImage(clone)
// This can be refactored out into its own function or reachable from
// anywhere in this module. It's used more than once and doesn't use 'use'.
let aM: float32[][] = [|
[| (float32 0.3); (float32 0.3); (float32 0.3); (float32 0.0); (float32 0.0) |];
[| (float32 0.59); (float32 0.59); (float32 0.59); (float32 0.0); (float32 0.0) |];
[| (float32 0.11); (float32 0.11); (float32 0.11); (float32 0.0); (float32 0.0) |];
[| (float32 0.0); (float32 0.0); (float32 0.0); (float32 1.0); (float32 0.0) |];
[| (float32 0.0); (float32 0.0); (float32 0.0); (float32 0.0); (float32 1.0) |];
|]
let colourMatrix = new ColorMatrix(aM) // Maybe put in own function?
use attributes = new ImageAttributes()
attributes.SetColorMatrix(colourMatrix)
g.DrawImage(temp, new Rectangle(0, 0, temp.Width, temp.Height),
0, 0, temp.Width, temp.Height, GraphicsUnit.Pixel, attributes)
use graphics = Graphics.FromImage(clone) use graphics = Graphics.FromImage(clone)
// This part applies the grid.
use pen = new Pen ((makeBrushFromRGBASpec spec), width = spec.penWidth) use pen = new Pen ((makeBrushFromRGBASpec spec), width = spec.penWidth)
graphics.DrawImage (original,new Rectangle(0, 0, clone.Width, clone.Height)) graphics.DrawImage (original,new Rectangle(0, 0, clone.Width, clone.Height))
let horizontalLines = let horizontalLines =

8
DeathSocketCLI/Commands.fs

@ -51,10 +51,10 @@
[<ListCommand>] [<ListCommand>]
[<Parameters [<Parameters
("(image-path: string) (no-of-rows: int) (no-of-columns: int) " + ("(image-path: string) (no-of-rows: int) (no-of-columns: int) " +
"(pen-width: float32) (colour: string) (new-path: string)")>] "(pen-width: float32) (colour: string) (new-path: string) (greyScale: bool)")>]
[<Description "Adds a grid to an image, using the specified parameters, and saves it.">] [<Description "Adds a grid to an image, using the specified parameters, and saves it.">]
[<Usage [<Usage
"add-grid C:/orignal-image.png 10 5 2 red C:/new-image.png">] "add-grid C:/orignal-image.png 10 5 2 red C:/new-image.png true">]
let ``add-grid`` imgPath numRows numColumns pWidth colour newPath greyScale = let ``add-grid`` imgPath numRows numColumns pWidth colour newPath greyScale =
try try
printfn "[INFO.] Adding grid to image..." printfn "[INFO.] Adding grid to image..."
@ -112,13 +112,13 @@
let``add-skia-grid`` imgPath numRows numColumns pWidth colour newPath greyScale= let``add-skia-grid`` imgPath numRows numColumns pWidth colour newPath greyScale=
printfn "[INFO.] Adding SkiaSharp grid to image..." printfn "[INFO.] Adding SkiaSharp grid to image..."
Skia (buildSkiaSpec imgPath numRows numColumns pWidth colour newPath) Skia (buildSkiaSpec imgPath numRows numColumns pWidth colour newPath)
|> applyGridToImageAsync greyScale |> applyGridToImageAsync greyScale // Not implement in this context.
|> Async.Start |> Async.Start
showEndOfCommandMessage showEndOfCommandMessage
let``add-skia-rgb-grid`` imgPath numRows numColumns pWidth r g b newPath greyScale = let``add-skia-rgb-grid`` imgPath numRows numColumns pWidth r g b newPath greyScale =
printfn "[INFO.] Adding SkiaSharp grid to image..." printfn "[INFO.] Adding SkiaSharp grid to image..."
SkiaRGB (buildSkiaRGBSpec imgPath numRows numColumns pWidth r g b newPath) SkiaRGB (buildSkiaRGBSpec imgPath numRows numColumns pWidth r g b newPath)
|> applyGridToImageAsync greyScale |> applyGridToImageAsync greyScale // Not implement in this context.
|> Async.Start |> Async.Start
showEndOfCommandMessage showEndOfCommandMessage
Loading…
Cancel
Save