simplifying drawing for performance purposes.

Does not yet work
This commit is contained in:
nek0 2016-12-10 23:49:51 +01:00
parent 4e20d26c97
commit af5526c650

View file

@ -19,26 +19,19 @@ drawRect
-> G.Color -- ^ Color to draw in
-> DrawType -- ^ Draw type
-> GeglRectangle -- ^ Dimensions of Rectangle
-> Affection a ()
drawRect buf color dt rect@G.GeglRectangle{..} =
liftIO $ G.iterateOver buf rect (B.PixelFormat B.RGBA B.CFdouble) G.GeglAccessReadWrite G.GeglAbyssNone $
(\(G.Pixel px py pc) ->
case dt of
Fill ->
let col = colorize pc color
-> IO ()
drawRect buf color (Fill) rect@G.GeglRectangle{..} =
G.pixelPoke buf rect (B.PixelFormat B.RGBA B.CFdouble) G.GeglAccessReadWrite G.GeglAbyssNone $
(\(x, y) ->
let col = unsafeColorize color
in
G.Pixel px py col
Line width ->
if (px >= rectangleX && px <= (rectangleX + width) ||
px <= (rectangleX + rectangleWidth) && px >= (rectangleX + rectangleWidth - width)) &&
(py >= rectangleY && py <= (rectangleY + width) ||
py <= (rectangleY + rectangleHeight) && py >= (rectangleY + rectangleHeight - width))
then
let col = colorize pc color
in G.Pixel px py col
else
G.Pixel px py pc
G.Pixel x y col
)
drawRect buf color (Line size) rect@G.GeglRectangle{..} = do
drawRect buf color Fill (G.GeglRectangle rectangleX rectangleY rectangleWidth size)
drawRect buf color Fill (G.GeglRectangle rectangleX rectangleY size rectangleHeight)
drawRect buf color Fill (G.GeglRectangle (rectangleWidth - size) rectangleY size rectangleHeight)
drawRect buf color Fill (G.GeglRectangle rectangleX (rectangleHeight - size) rectangleWidth size)
-- | compute color for a single pixel
colorize
@ -69,3 +62,18 @@ colorize (rr, rg, rb, ra) col =
, G.CVdouble $ CDouble $ blu / da
, G.CVdouble $ CDouble $ ca
)
unsafeColorize col =
let
(r, g, b) = case col of
G.RGBA cr cg cb _ -> (cr, cg, cb)
G.RGB cr cg cb -> (cr, cg, cb)
a = case col of
G.RGBA _ _ _ ca -> ca
G.RGB _ _ _ -> 1
in
( G.CVdouble $ CDouble $ r
, G.CVdouble $ CDouble $ g
, G.CVdouble $ CDouble $ b
, G.CVdouble $ CDouble $ a
)