diff --git a/examples/example01.hs b/examples/example01.hs index 4aba6f3..58f528b 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 a31c96d..1b1c84a 100644 --- a/src/Affection/Draw.hs +++ b/src/Affection/Draw.hs @@ -20,23 +20,18 @@ drawRect -> DrawType -- ^ Draw type -> GeglRectangle -- ^ Dimensions of Rectangle -> IO () -drawRect buf color dt rect@G.GeglRectangle{..} = - 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 size -> - if not ((px >= (rectangleX + size) && px < (rectangleX + rectangleWidth - size)) && - (py >= (rectangleY + size) && py < (rectangleY + rectangleHeight - size))) - then - let col = colorize pc color - in G.Pixel px py col - else - G.Pixel px py pc +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 (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 @@ -67,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 + )