diff options
author | Hanspeter Portner <dev@open-music-kontrollers.ch> | 2019-07-18 19:26:26 +0200 |
---|---|---|
committer | Hanspeter Portner <dev@open-music-kontrollers.ch> | 2019-07-18 19:26:26 +0200 |
commit | 6a388b93c2e1da1d724177f8ce9e8cf49524267a (patch) | |
tree | 58ed0537a3e5500ba9116abe9d7629ca2babb27e /test/core.c | |
parent | 5841ebb4dcf412ab2ca6fc6b84020dfbe0abb484 (diff) | |
download | d2tk-6a388b93c2e1da1d724177f8ce9e8cf49524267a.tar.xz |
core: prototype bitmap primitive.
Diffstat (limited to 'test/core.c')
-rw-r--r-- | test/core.c | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/test/core.c b/test/core.c index f2b0b17..7d226f3 100644 --- a/test/core.c +++ b/test/core.c @@ -1141,6 +1141,79 @@ _test_image() #undef IMAGE_PATH #undef IMAGE_ALIGN +#define BITMAP_X 10 +#define BITMAP_Y 20 +#define BITMAP_W 30 +#define BITMAP_H 40 +#define BITMAP_WIDTH 16 +#define BITMAP_HEIGHT 16 +#define BITMAP_ALIGN D2TK_ALIGN_LEFT + +static void +_check_bitmap(const d2tk_com_t *com, const d2tk_clip_t *clip) +{ + assert(clip->x0 == CLIP_X); + assert(clip->y0 == CLIP_Y); + assert(clip->x1 == CLIP_X + CLIP_W); + assert(clip->y1 == CLIP_Y + CLIP_H); + assert(clip->w == CLIP_W); + assert(clip->h == CLIP_H); + + assert(com->size == sizeof(d2tk_body_bitmap_t) + + BITMAP_WIDTH*BITMAP_HEIGHT*sizeof(uint32_t)); + assert(com->instr == D2TK_INSTR_BITMAP); + assert(com->body->bitmap.x == BITMAP_X - CLIP_X); + assert(com->body->bitmap.y == BITMAP_Y - CLIP_Y); + assert(com->body->bitmap.w == BITMAP_W); + assert(com->body->bitmap.h == BITMAP_H); + assert(com->body->bitmap.align == BITMAP_ALIGN); + assert(com->body->bitmap.surf.w == BITMAP_WIDTH); + assert(com->body->bitmap.surf.h == BITMAP_HEIGHT); + for(unsigned i = 0; i < BITMAP_WIDTH*BITMAP_HEIGHT; i++) + { + assert(com->body->bitmap.surf.rgba[i] == 999 - i); + } +} + +static void +_test_bitmap() +{ + d2tk_mock_ctx_t ctx = { + .check = _check_bitmap + }; + + d2tk_core_t *core = d2tk_core_new(&d2tk_mock_driver, &ctx); + assert(core); + + d2tk_core_set_dimensions(core, DIM_W, DIM_H); + + d2tk_core_pre(core); + const ssize_t ref = d2tk_core_bbox_push(core, true, + &D2TK_RECT(CLIP_X, CLIP_Y, CLIP_W, CLIP_H)); + assert(ref >= 0); + + uint32_t surf [BITMAP_WIDTH*BITMAP_HEIGHT]; + for(unsigned i = 0; i < BITMAP_WIDTH*BITMAP_HEIGHT; i++) + { + surf[i] = 999 - i; + } + + d2tk_core_bitmap(core, &D2TK_RECT(BITMAP_X, BITMAP_Y, BITMAP_W, BITMAP_H), + BITMAP_WIDTH, BITMAP_HEIGHT, surf, BITMAP_ALIGN); + + d2tk_core_bbox_pop(core, ref); + d2tk_core_post(core); + d2tk_core_free(core); +} + +#undef BITMAP_X +#undef BITMAP_Y +#undef BITMAP_W +#undef BITMAP_H +#undef BITMAP_WIDTH +#undef BITMAP_HEIGHT +#undef BITMAP_ALIGN + #define STROKE_WIDTH 2 static void @@ -1283,6 +1356,7 @@ main(int argc __attribute__((unused)), char **argv __attribute__((unused))) _test_font_face(); _test_text(); _test_image(); + _test_bitmap(); _test_stroke_width(); _test_triple(); |