From af5526c6508d8c66b356aa0ce8c6111e95e56883 Mon Sep 17 00:00:00 2001 From: nek0 Date: Sat, 10 Dec 2016 23:49:51 +0100 Subject: [PATCH 1/2] simplifying drawing for performance purposes. Does not yet work --- src/Affection/Draw.hs | 46 +++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/src/Affection/Draw.hs b/src/Affection/Draw.hs index 91d95b1..ba90c64 100644 --- a/src/Affection/Draw.hs +++ b/src/Affection/Draw.hs @@ -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 - 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 + -> 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 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 + ) From 3757622475e2f389dc26cb79e9d5528a5edba9a5 Mon Sep 17 00:00:00 2001 From: nek0 Date: Sun, 11 Dec 2016 01:42:06 +0100 Subject: [PATCH 2/2] works now and is fast --- examples/example01.hs | 2 +- src/Affection/Draw.hs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/example01.hs b/examples/example01.hs index 80fb49e..16d3f2e 100644 --- a/examples/example01.hs +++ b/examples/example01.hs @@ -51,7 +51,7 @@ load _ = do traceM "checkerboard" over <- G.gegl_node_new_child root G.defaultOverOperation traceM "over" - buffer <- G.gegl_buffer_new (G.GeglRectangle 0 0 20 20) =<< + buffer <- G.gegl_buffer_new (G.GeglRectangle 0 0 800 600) =<< B.babl_format (B.PixelFormat B.RGBA B.CFfloat) bufsrc <- G.gegl_node_new_child root $ G.bufferSourceOperation [ G.Property "buffer" $ G.PropertyBuffer buffer diff --git a/src/Affection/Draw.hs b/src/Affection/Draw.hs index ba90c64..1b1c84a 100644 --- a/src/Affection/Draw.hs +++ b/src/Affection/Draw.hs @@ -30,8 +30,8 @@ drawRect buf color (Fill) rect@G.GeglRectangle{..} = 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) + drawRect buf color Fill (G.GeglRectangle (rectangleX + rectangleWidth - size) rectangleY size rectangleHeight) + drawRect buf color Fill (G.GeglRectangle rectangleX (rectangleY + rectangleHeight - size) rectangleWidth size) -- | compute color for a single pixel colorize