Hi,
It seems to be a Rasterific issue because the following program gives the same result:
import Codec.Picture
import Graphics.Rasterific
main :: IO ()
main = do
i <- readPng "tiny-rectangle.png"
case i of
Left err -> error err
Right img -> do
let d = drawImage (convertRGBA8 img) 0.0 (V2 0 0)
let img2 = renderDrawing 4 5 (PixelRGBA8 0 0 0 0) d
writePng "tiny-rectangle-out.png" img2
In Graphics.Rasterific.Immediate.fillWithTexture, if we print "els" (the shape of the image we want to render) we get:
[LinePrim Line (V2 (-0.5) (-0.5)) (V2 3.5 (-0.5)),LinePrim Line (V2 3.5 (-0.5)) (V2 3.5 4.5),LinePrim Line (V2 3.5 4.5) (V2 (-0.5) 4.5),LinePrim Line (V2 (-0.5) 4.5) (V2 (-0.5) (-0.5))]
Notice the (-0.5,-0.5) translation.
It then gets clipped to:
fromList [LinePrim Line (V2 0.0 0.0) (V2 3.5 0.0),LinePrim Line
(V2 3.5 0.0) (V2 3.5 0.0),LinePrim Line (V2 3.5 0.0) (V2 3.5
0.0),LinePrim Line (V2 3.5 0.0) (V2 3.5 0.125),LinePrim Line (V2
3.5 0.125) (V2 3.5 0.75),LinePrim Line (V2 3.5 0.75) (V2 3.5
2.0),LinePrim Line (V2 3.5 2.0) (V2 3.5 4.5),LinePrim Line (V2 3.5
4.5) (V2 1.5 4.5),LinePrim Line (V2 1.5 4.5) (V2 0.5 4.5),LinePrim
Line (V2 0.5 4.5) (V2 0.0 4.5),LinePrim Line (V2 0.0 4.5) (V2 0.0
4.5),LinePrim Line (V2 0.0 4.5) (V2 0.0 0.0)]
The following patch seems to fix the issue:
diff --git src/Graphics/Rasterific.hs src/Graphics/Rasterific.hs
index 088248d..e60e2ac 100644
--- src/Graphics/Rasterific.hs
+++ src/Graphics/Rasterific.hs
@@ -823,8 +823,8 @@ drawImageAtSize img@Image { imageWidth = w,
imageHeight = h } borderSize ip
stroke (borderSize / 2) (JoinMiter 0)
(CapStraight 0, CapStraight 0) rect'
where
- p = ip ^-^ V2 0.5 0.5
- rect = rectangle (V2 0 0) rw rh
+ p = ip ^+^ V2 0.5 0.5
+ rect = rectangle (V2 (-0.5) (-0.5)) rw rh
rect' = rectangle p reqWidth reqHeight
My guess is that "^-^ V2 0.5 0.5" was added to compensate for line sampling (hence rectangle sampling) which adds (0.5,0.5) to every sample coordinate (probably to get at the center of the pixels).
Texture sampling seems to use final image coordinates according
to the comment in Graphics.Rasterific.Texture. So if we only do:
- p = ip ^-^ V2 0.5 0.5
+ p = ip
We get the correct shape:
[LinePrim Line (V2 0.0 0.0) (V2 4.0 0.0),LinePrim Line (V2 4.0 0.0) (V2 4.0 5.0),LinePrim Line (V2 4.0 5.0) (V2 0.0 5.0),LinePrim Line (V2 0.0 5.0) (V2 0.0 0.0)]
But we don't compensate the (0.5,0.5) translation in samples so
the output is still bad. We can do:
- rect = rectangle (V2 0 0) rw rh
+ rect = rectangle (V2 (-0.5) (-0.5)) rw rh
to compensate, but then the coordinates are (-0.5,-0.5) off. So
finally we do:
- p = ip ^-^ V2 0.5 0.5
+ p = ip ^+^ V2 0.5 0.5
I'm not sure if it's the best fix. It's probably worth opening a ticket.
Cheers
Sylvain
--
You received this message because you are subscribed to the Google Groups "diagrams-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to diagrams-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/diagrams-discuss/e15c080c-4a16-4520-99d1-1c9117855e28n%40googlegroups.com.
You received this message because you are subscribed to a topic in the Google Groups "diagrams-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/diagrams-discuss/TRtnvrQaT-k/unsubscribe.
To unsubscribe from this group and all its topics, send an email to diagrams-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/diagrams-discuss/9bd6e150-3384-8e8b-a202-55f65ba31184%40haskus.fr.
Hi Lyle,
I've added a comment in #22: https://github.com/Twinside/Rasterific/issues/22#issuecomment-768922232
Cheers,
Sylvain
To view this discussion on the web visit https://groups.google.com/d/msgid/diagrams-discuss/CAH3XM1nk86e1%2B0Eir6turkq%2BdmNHAL9q3UvgxGcUfN8pZ-fcaQ%40mail.gmail.com.