[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-kimageshop
Subject:    Re: Mirroring of the canvas
From:       Dmitry Kazakov <dimula73 () gmail ! com>
Date:       2010-03-24 21:16:30
Message-ID: ae32c1ef1003241416r38b7b185m5705edc07efdd803 () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


We have four coordinate systems:
1) image
2) viewport - scaled image coordinates (takes into account zoom-level and
image resolution)
3) widget ~ viewport transalted on "origin"
4) canvas ~ widget translated on "offset"

I'm very unsure about 3 and 4. What do they do actually? And why can't we
join both translations?

As for mirroring, i think all the translation between 1<->2 should be moved
into KisCanvas2, then you need to change only two functions and a flip flag
to get mirroring.

On Wed, Mar 24, 2010 at 10:30 PM, LukasT.dev@gmail.com <lukast.dev@gmail.com
> wrote:

> Hello,
>
> I'm trying to implement the mirroring of the canvas. It is a feature where
> we
> mirror the projection of the canvas instead of the mirroring the device
> when
> you want to see mirrored image of your paint. Similar feature is in
> mypaint.
>
> I started with mirroring the events. There are some coordinate systems in
> canvas. First one is widget space, it is possition of the input device in
> widget pixels. Then there is document space, so when you paint, the event
> from
> the widget is converted by few function calls to document coordinates.
>
> First the coordinates are translated by scrolling offset (when you move
> with
> slider in bigger zoom ) and by document origin (it is the distance from the
> canvas top left corner to image top left corner). Then the coordinates
> are transformed to document coordinates with zoom.
>
> I mirror the coordinates on document level, that means that when you draw
> stroke, the document is updated in the mirrored part. Document adds the
> "dirty
> rects on document level" so the projection is computed properly because so
> far
> projection does not know about mirroring.
>
> Next step was to mirror the canvas. I mirrored the projection by QPainter
> as Cyrille suggested using transformation like scale(-1,1) and
> translate(width,0)
>
> Now the problems started to show  up. The projection with mirrored canvas
> is
> not updated properly. So I started to investigate.
> In KisCanvas2::updateCanvasProjection I tried to mirror the vRect
> rectangle.
> The rc rectangle update the projection and the vRect is responsible to for
> proper updates calls.
>
> So far I have these problems:
> the canvas is not updated properly, I mirrored the vRect like this
> vRect = QRect(image()->width() - vRect.x()
> vRect.width(),vRect.top(),vRect.width(), vRect.height());
>
> but that is not correct. The canvas is erased in QRect
> KisPrescaledProjection::preScale(const QRect & rc)
>
>
> If I call just update(), when the whole canvas is updated, it is correct.
> What I miss there?
>
> Question: how to solve it? I don't know much about projection even I spent
> a
> lot of time looking at the code. Dmitry, what do you think I need to do?
> Is it correct to mirror the QPainter or should we mirror on the projection
> level? If so, what has to be mirrored?
>
> Another problem. When we zoom and scroll vertically, part of the image is
> erased. It seems that when we mirror the image, the hidden part because
> actually visible and in the projection it is represented by transparent
> pixel.
> Is that what is happening? Any hints where and how to fix it?
>
> Here is the patch I have for now
> http://valdyas.org/~lukast/mirroring.patch<http://valdyas.org/%7Elukast/mirroring.patch>
> _______________________________________________
> kimageshop mailing list
> kimageshop@kde.org
> https://mail.kde.org/mailman/listinfo/kimageshop
>



-- 
Dmitry Kazakov

[Attachment #5 (text/html)]

We have four coordinate systems:<br>1) image<br>2) viewport - scaled image \
coordinates (takes into account zoom-level and image resolution)<br>3) widget ~ \
viewport transalted on &quot;origin&quot;<br>4) canvas ~ widget translated on \
&quot;offset&quot;<br> <br>I&#39;m very unsure about 3 and 4. What do they do \
actually? And why can&#39;t we join both translations?<br><br>As for mirroring, i \
think all the translation between 1&lt;-&gt;2 should be moved into KisCanvas2, then \
you need to change only two functions and a flip flag to get mirroring.<br> <br><div \
class="gmail_quote">On Wed, Mar 24, 2010 at 10:30 PM, <a \
href="mailto:LukasT.dev@gmail.com">LukasT.dev@gmail.com</a> <span dir="ltr">&lt;<a \
href="mailto:lukast.dev@gmail.com">lukast.dev@gmail.com</a>&gt;</span> wrote:<br> \
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); \
margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hello,<br> <br>
I&#39;m trying to implement the mirroring of the canvas. It is a feature where we<br>
mirror the projection of the canvas instead of the mirroring the device when<br>
you want to see mirrored image of your paint. Similar feature is in mypaint.<br>
<br>
I started with mirroring the events. There are some coordinate systems in<br>
canvas. First one is widget space, it is possition of the input device in<br>
widget pixels. Then there is document space, so when you paint, the event from<br>
the widget is converted by few function calls to document coordinates.<br>
<br>
First the coordinates are translated by scrolling offset (when you move with<br>
slider in bigger zoom ) and by document origin (it is the distance from the<br>
canvas top left corner to image top left corner). Then the coordinates<br>
are transformed to document coordinates with zoom.<br>
<br>
I mirror the coordinates on document level, that means that when you draw<br>
stroke, the document is updated in the mirrored part. Document adds the \
&quot;dirty<br> rects on document level&quot; so the projection is computed properly \
because so far<br> projection does not know about mirroring.<br>
<br>
Next step was to mirror the canvas. I mirrored the projection by QPainter<br>
as Cyrille suggested using transformation like scale(-1,1) and<br>
translate(width,0)<br>
<br>
Now the problems started to show   up. The projection with mirrored canvas is<br>
not updated properly. So I started to investigate.<br>
In KisCanvas2::updateCanvasProjection I tried to mirror the vRect rectangle.<br>
The rc rectangle update the projection and the vRect is responsible to for<br>
proper updates calls.<br>
<br>
So far I have these problems:<br>
the canvas is not updated properly, I mirrored the vRect like this<br>
vRect = QRect(image()-&gt;width() - vRect.x()<br>
vRect.width(),vRect.top(),vRect.width(), vRect.height());<br>
<br>
but that is not correct. The canvas is erased in QRect<br>
KisPrescaledProjection::preScale(const QRect &amp; rc)<br>
<br>
<br>
If I call just update(), when the whole canvas is updated, it is correct.<br>
What I miss there?<br>
<br>
Question: how to solve it? I don&#39;t know much about projection even I spent a<br>
lot of time looking at the code. Dmitry, what do you think I need to do?<br>
Is it correct to mirror the QPainter or should we mirror on the projection<br>
level? If so, what has to be mirrored?<br>
<br>
Another problem. When we zoom and scroll vertically, part of the image is<br>
erased. It seems that when we mirror the image, the hidden part because<br>
actually visible and in the projection it is represented by transparent pixel.<br>
Is that what is happening? Any hints where and how to fix it?<br>
<br>
Here is the patch I have for now<br>
<a href="http://valdyas.org/%7Elukast/mirroring.patch" \
target="_blank">http://valdyas.org/~lukast/mirroring.patch</a><br> \
_______________________________________________<br> kimageshop mailing list<br>
<a href="mailto:kimageshop@kde.org">kimageshop@kde.org</a><br>
<a href="https://mail.kde.org/mailman/listinfo/kimageshop" \
target="_blank">https://mail.kde.org/mailman/listinfo/kimageshop</a><br> \
</blockquote></div><br><br clear="all"><br>-- <br>Dmitry Kazakov<br>



_______________________________________________
kimageshop mailing list
kimageshop@kde.org
https://mail.kde.org/mailman/listinfo/kimageshop


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic