Bitmap *alloc_bitmap(int w, int h) { Bitmap *bm; unsigned align = (w >= 32) ? 32 : ((w >= 16) ? 16 : 1); unsigned s = ass_align(align, w); bm = malloc(sizeof(Bitmap)); bm->buffer = ass_aligned_alloc(align, s * h + 32); memset(bm->buffer, 0, s * h + 32); bm->w = w; bm->h = h; bm->stride = s; bm->left = bm->top = 0; return bm; }
static Bitmap *alloc_bitmap_raw(int w, int h) { Bitmap *bm; unsigned align = (w >= 32) ? 32 : ((w >= 16) ? 16 : 1); size_t s = ass_align(align, w); // Too often we use ints as offset for bitmaps => use INT_MAX. if (s > (INT_MAX - 32) / FFMAX(h, 1)) return NULL; bm = malloc(sizeof(Bitmap)); if (!bm) return NULL; bm->buffer = ass_aligned_alloc(align, s * h + 32); if (!bm->buffer) { free(bm); return NULL; } bm->w = w; bm->h = h; bm->stride = s; bm->left = bm->top = 0; return bm; }