summaryrefslogtreecommitdiffstats
path: root/libass/ass_bitmap.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-01-29 18:11:13 +0100
committerwm4 <wm4@nowhere>2014-02-02 20:02:40 +0100
commitda4af2b6d86491536b0999f5b731c30b13ff0ac9 (patch)
tree9b941ab8dba74b2804993fe1bd7aa2fe9063926d /libass/ass_bitmap.c
parent7514642f2575fd58c4f4809d74a0099f22d256f0 (diff)
downloadlibass-da4af2b6d86491536b0999f5b731c30b13ff0ac9.tar.bz2
libass-da4af2b6d86491536b0999f5b731c30b13ff0ac9.tar.xz
Use a function for aligned memory allocations
...instead of doing this manually.
Diffstat (limited to 'libass/ass_bitmap.c')
-rw-r--r--libass/ass_bitmap.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/libass/ass_bitmap.c b/libass/ass_bitmap.c
index 7689651..9196fae 100644
--- a/libass/ass_bitmap.c
+++ b/libass/ass_bitmap.c
@@ -103,8 +103,9 @@ void resize_tmp(ASS_SynthPriv *priv, int w, int h)
priv->tmp_w *= 2;
while (priv->tmp_h < h)
priv->tmp_h *= 2;
- free(priv->tmp);
- priv->tmp = malloc((priv->tmp_w + 1) * priv->tmp_h * sizeof(unsigned));
+ ass_aligned_free(priv->tmp);
+ priv->tmp =
+ ass_aligned_alloc(32, (priv->tmp_w + 1) * priv->tmp_h * sizeof(unsigned));
}
ASS_SynthPriv *ass_synth_init(double radius)
@@ -116,7 +117,7 @@ ASS_SynthPriv *ass_synth_init(double radius)
void ass_synth_done(ASS_SynthPriv *priv)
{
- free(priv->tmp);
+ ass_aligned_free(priv->tmp);
free(priv->g0);
free(priv->g);
free(priv->gt2);
@@ -127,12 +128,10 @@ Bitmap *alloc_bitmap(int w, int h)
{
Bitmap *bm;
- uintptr_t alignment_offset = (w > 31) ? 31 : ((w > 15) ? 15 : 0);
- unsigned s = (w + alignment_offset) & ~alignment_offset;
+ unsigned align = (w >= 32) ? 32 : ((w >= 16) ? 16 : 1);
+ unsigned s = ass_align(align, w);
bm = malloc(sizeof(Bitmap));
- bm->buffer_ptr = malloc(s * h + alignment_offset + 32);
- bm->buffer = (unsigned char*)
- (((uintptr_t)bm->buffer_ptr + alignment_offset) & ~alignment_offset);
+ bm->buffer = ass_aligned_alloc(align, s * h + 32);
memset(bm->buffer, 0, s * h + 32);
bm->w = w;
bm->h = h;
@@ -144,7 +143,7 @@ Bitmap *alloc_bitmap(int w, int h)
void ass_free_bitmap(Bitmap *bm)
{
if (bm)
- free(bm->buffer_ptr);
+ ass_aligned_free(bm->buffer);
free(bm);
}