Re: 4x4 matrices in Cairo

Olaf Schmidt <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <[email protected]>
Am 13.11.2013 14:15, schrieb AD:

> Is there a way to use 4x4 matrices in cairo?
> Or alternatively a may to decompose a 4x4 matrix into several 3x3 matrices?
>
> I'm trying to distort an image as in pic attached.

Although direct support would be nice in cairo, for this special
case there's a relative simple "workaround" per "line-wise-drawing"
(separately scaled).

Doesn't look all bad IMO ...
http://www.vbRichClient.com/Downloads/StarWarsScroll.png

...and runs (even with PixMan-rendering) fast enough on Desktop-
Machines (about 50Hz/FPS on a i5 2.8GHz here on Windows).


My Testcode which produced the above image is in VB6 (using a
Cairo-COM-wrapper), but the few lines within the "stripe-loop"
should be easily translatable.

Private Sub Form_Click()
Dim BBSrf As cCairoSurface, SCSrf As cCairoSurface

   Set BBSrf = Cairo.CreateSurface(710, 620)
   Set SCSrf = Cairo.CreateSurface(BBSrf.Width, BBSrf.Height)

   New_c.Timing True

     With BBSrf.CreateContext 'render the Text onto the BackBuf
       .SetSourceColor vbBlack: .Paint 'clear BBSrf with Black

       .SelectFont "Arial Black", 20, RGB(255, 222, 0), True
       .DrawText 0, 50, BBSrf.Width, BBSrf.Height - 50, SB.ToString
     End With

     With SCSrf.CreateContext 'linewise-stretching into SCSrf
       .SetSourceColor vbBlack: .Paint 'clear SCSrf with Black

       Dim i As Double, Fac As Double
       Do While i < SCSrf.Height
         Fac = 0.35 + (i / SCSrf.Height * 0.7) ^ 2
         .Save
            .TranslateDrawings SCSrf.Width / 2 * (1 - Fac), 0
            .ScaleDrawings Fac, Fac

            .SetSourceSurface BBSrf
            .Rectangle 0, i, SCSrf.Width, 4 'StripeHeight of 4
            .Fill
         .Restore
         i = i + 1.5 'a StripeHeight-Shift-Relation of 1.5 / 4 works OK
       Loop

       SCSrf.FastBlur 'a fast Blur (optional, takes about 5msec here)
     End With

   Form.Caption = New_c.Timing 'visualize the timing in the caption

   Cairo.ImageList.AddSurface "Test", SCSrf
   Form.WidgetRoot.ImageKey = "Test"
End Sub


Olaf


-- 
cairo mailing list
[email protected]
http://lists.cairographics.org/mailman/listinfo/cairo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.