[cairo] CAIRO_FORMAT_A8 / stride

Nikolaj Thygesen nikolaj.thygesen at hotmail.com
Sun Jul 2 13:45:29 PDT 2006


    My problem is that f.x. in the actual test example below, the char-array 
- "existing_image_buffer" - has an "odd" width/stride (== 202), and the 
rendered text is skewed, but if I make WIDTH == 200 f.x. everything works 
fine. In my tests I create an initial background pattern manually, so I can 
tell that the buffer is rendered correctly. I also tried drawing a rectangle 
over the letters, and even this is rendered skewed, so I consider Pango to 
be innocent. I'm not worried about speed, as right there I have all the time 
in the world, but I just don't want to create a second copy of a potentially 
quite large buffer with a proper stride (multiple of 4).

    br - Nikolaj Thygesen

        #define WIDTH 202
        #define HEIGHT 200

	cairo_surface_t *surface = cairo_image_surface_create_for_data
                                            (existing_image_buffer,
                                             CAIRO_FORMAT_A8,
                                             WIDTH,
                                             HEIGHT,
                                             WIDTH);
	cairo_t *cairo = cairo_create(surface);
	PangoLayout *layout = pango_cairo_create_layout(cairo);

	PangoFontDescription *desc = pango_font_description_from_string("Serif Bold 
18");
	pango_layout_set_font_description(layout, desc);
	pango_layout_set_text(layout, "DiamondBOX", sizeof("DiamondBOX") - 1);
	cairo_move_to(cairo, 0, 0);
	pango_cairo_show_layout(cairo, layout);
        <... now render buffer to window...>



>From: Owen Taylor <otaylor at redhat.com>
>To: Nikolaj Thygesen <nikolaj.thygesen at hotmail.com>
>CC: cairo at cairographics.org
>Subject: Re: [cairo] CAIRO_FORMAT_A8 / stride
>Date: Sun, 02 Jul 2006 13:26:57 -0400
>
>On Sun, 2006-07-02 at 20:07 +0000, Nikolaj Thygesen wrote:
> >     The thing is that I'm using an existing buffer for the data part, so 
>I
> > don't always know whether stride is divisible by four, and the size of 
>the
> > buffers may be substantial, so I'd hate to create temporary copies.
> >     Suppose I created my own "local_image_surface" by cloning the 
>official
> > "cairo_image_surface.c", and implemented what I need. Would other parts 
>of
> > Cairo still readjust my "odd" stride, or could I get away with it?? I 
>have
> > looked around at the Cairo sources but find very few references to 
>stride.
>
>I don't quite understand what your problem is ... as far as I know,
>Cairo will work fine with non-word-aligned rowstrides, though it
>may be less efficient.
>
>Do you have a example where cairo_image_surface_create_for_data()
>doesn't work in that case?
>
>(If there are problems they are in the underlying pixman library not
>cairo_image_surface.c)
>
>I suspect you'd be surprised by how little overhead copying the data
>would be .. memcpy is *fast* on modern machines, but I'd expect things
>to just work.
>						Owen
>


><< signature.asc >>

_________________________________________________________________
Opret en personlig blog og del dine billeder på MSN Spaces:  
http://spaces.msn.com/



More information about the cairo mailing list