Merge branch 'unsafe_colorize'

This commit is contained in:
nek0 2016-12-11 01:44:01 +01:00
commit 15fdea6949
2 changed files with 27 additions and 17 deletions

View file

@ -51,7 +51,7 @@ load _ = do
traceM "checkerboard" traceM "checkerboard"
over <- G.gegl_node_new_child root G.defaultOverOperation over <- G.gegl_node_new_child root G.defaultOverOperation
traceM "over" 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) B.babl_format (B.PixelFormat B.RGBA B.CFfloat)
bufsrc <- G.gegl_node_new_child root $ G.bufferSourceOperation bufsrc <- G.gegl_node_new_child root $ G.bufferSourceOperation
[ G.Property "buffer" $ G.PropertyBuffer buffer [ G.Property "buffer" $ G.PropertyBuffer buffer

View file

@ -20,23 +20,18 @@ drawRect
-> DrawType -- ^ Draw type -> DrawType -- ^ Draw type
-> GeglRectangle -- ^ Dimensions of Rectangle -> GeglRectangle -- ^ Dimensions of Rectangle
-> IO () -> IO ()
drawRect buf color dt rect@G.GeglRectangle{..} = drawRect buf color (Fill) rect@G.GeglRectangle{..} =
G.iterateOver buf rect (B.PixelFormat B.RGBA B.CFdouble) G.GeglAccessReadWrite G.GeglAbyssNone $ G.pixelPoke buf rect (B.PixelFormat B.RGBA B.CFdouble) G.GeglAccessReadWrite G.GeglAbyssNone $
(\(G.Pixel px py pc) -> (\(x, y) ->
case dt of let col = unsafeColorize color
Fill -> in
let col = colorize pc color G.Pixel x y col
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 (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 -- | compute color for a single pixel
colorize colorize
@ -67,3 +62,18 @@ colorize (rr, rg, rb, ra) col =
, G.CVdouble $ CDouble $ blu / da , G.CVdouble $ CDouble $ blu / da
, G.CVdouble $ CDouble $ ca , 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
)