Re: resize image surface
chris nuernberger <[email protected]>
| Newsgroups | gmane.comp.lib.cairo |
|---|---|
| Message-ID | <CAG=GWvfMrf=-mFO_wtsOkK4XvPAzRrekQ4OQMB3iQ9ry=SkO0Q@mail.gmail.com> |
I don't think that is a very good match really. I need the *results* of the drawing operation to be packed and contiguous in memory because as I stated upload to is sensitive to the total data size and the image data upload functions don't include a stride. This would in theory render correctly (somewhat) but the original image surface would still have its original stride. The subsurfaces are simply a translation layer sitting above the original surface; I need to data format of the original surface to change. I got something working already, it looks like the attached file. I think this works in my case because: 1. I already need all image sizes to be divisible by four (GLES2 limitation). 2. I am only using pango to render to the surface and then copying the result off to somewhere else with glTexImage2D. 3. The damage member is always null so there shouldn't be anything else relying on the damage. At least I got it to work rendering to an RGB image surface which has 4 byte pixels for alignment reasons. It doesn't work (yet) if I switch the image surface to be alpha-only. I use the resulting texture in opengl as a luminance texture so rendering an alpha mask in cairo should be ideal in terms of memory bandwidth and it fits my use case. Chris On Sat, Sep 29, 2012 at 11:37 AM, Kalle Vahlman <[email protected]>wrote: > 2012/9/29 chris nuernberger <[email protected]>: > > I was wondering if there was a way to force cairo to treat a surface as > if > > it had a smaller width than it was originally allocated with instead when > > cairo is rendering? This would solve the problem. > > Sounds like you are looking for subsurfaces: > > > http://cairographics.org/manual/cairo-cairo-surface-t.html#cairo-surface-create-for-rectangle > > (can't help you with using them though, haven't done anything with them > myself) > > -- > Kalle Vahlman, [email protected] > Powered by http://movial.com > Interesting stuff at http://sandbox.movial.com > -- A foolish consistency is the hobgoblin of little minds - Emerson -- cairo mailing list [email protected] http://lists.cairographics.org/mailman/listinfo/cairo
image_resize.c
(text/x-csrc, 1.2 KB)
cairo_public cairo_surface_t *
cairo_image_surface_resize (cairo_surface_t * surface,
int new_width,
int new_height,
int* original_surface_byte_size)
{
//handle the easy case first
pixman_image_t* pixman_image;
cairo_image_surface_t* image_surface = (cairo_image_surface_t*)surface;
int new_byte_size = cairo_format_stride_for_width( image_surface->format, new_width ) * new_height;
if ( new_byte_size > *original_surface_byte_size )
{
cairo_surface_t* new_surface = cairo_image_surface_create( image_surface->format, new_width, new_height );
*original_surface_byte_size = new_byte_size;
cairo_surface_destroy(surface);
return new_surface;
}
pixman_image = image_surface->pixman_image;
pixman_image_set_width( pixman_image, new_width );
pixman_image_set_height( pixman_image, new_height );
image_surface->width = pixman_image_get_width (pixman_image);
image_surface->height = pixman_image_get_height (pixman_image);
image_surface->stride = pixman_image_get_stride (pixman_image);
image_surface->depth = pixman_image_get_depth (pixman_image);
if ( surface->damage )
{
_cairo_damage_destroy( surface->damage );
surface->damage = NULL;
}
return surface;
}