diff options
author | Grigori Goronzy <greg@blackbox> | 2009-07-21 03:06:05 +0200 |
---|---|---|
committer | Grigori Goronzy <greg@blackbox> | 2009-07-21 03:09:13 +0200 |
commit | a7b40ce5a9d84182b40392665d3a11a69be90ebf (patch) | |
tree | a27f02735c4d0e33ad39c85d5066fa2ec395ab3e /libass/ass_render.c | |
parent | f7f50dfb6335b3d2c1f1fa85a1e496ed2abf6d27 (diff) | |
download | libass-a7b40ce5a9d84182b40392665d3a11a69be90ebf.tar.bz2 libass-a7b40ce5a9d84182b40392665d3a11a69be90ebf.tar.xz |
Factor out bitmap buffer copy
For clarity, factor out bitmap copying into a function. Do not pad the
bitmap with stride in the last row; this can not by guaranteed anyway.
Add a comment about this peculiarity to the API documentation in ass.h
Idea by Evgeniy Stepanov.
Diffstat (limited to 'libass/ass_render.c')
-rw-r--r-- | libass/ass_render.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/libass/ass_render.c b/libass/ass_render.c index f6234828..23c93fba 100644 --- a/libass/ass_render.c +++ b/libass/ass_render.c @@ -611,6 +611,20 @@ static ass_image_t **render_glyph(ass_renderer_t *render_priv, } /** + * \brief Replace the bitmap buffer in ass_image_t with a copy + * \param img ass_image_t to operate on + * \return pointer to old bitmap buffer + */ +static unsigned char *clone_bitmap_buffer(ass_image_t *img) +{ + unsigned char *old_bitmap = img->bitmap; + int size = img->stride * (img->h - 1) + img->w; + img->bitmap = malloc(size); + memcpy(img->bitmap, old_bitmap, size); + return old_bitmap; +} + +/** * \brief Calculate overlapping area of two consecutive bitmaps and in case they * overlap, composite them together * Mainly useful for translucent glyphs and especially borders, to avoid the @@ -680,12 +694,8 @@ render_overlap(ass_renderer_t *render_priv, ass_image_t **last_tail, return; } // Allocate new bitmaps and copy over data - a = (*last_tail)->bitmap; - b = (*tail)->bitmap; - (*last_tail)->bitmap = malloc(as * ah); - (*tail)->bitmap = malloc(bs * bh); - memcpy((*last_tail)->bitmap, a, as * ah); - memcpy((*tail)->bitmap, b, bs * bh); + a = clone_bitmap_buffer(*last_tail); + b = clone_bitmap_buffer(*tail); // Composite overlapping area for (y = 0; y < h; y++) |