[cairo] 4x4 matrices in Cairo

Olaf Schmidt ng at vbRichClient.com
Fri Nov 15 20:21:18 PST 2013


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




More information about the cairo mailing list