diff options
author | quou <quou@disroot.org> | 2023-05-06 10:39:19 +1000 |
---|---|---|
committer | quou <quou@disroot.org> | 2023-05-06 10:39:19 +1000 |
commit | 91aef268319a77ee8f5a082ca89264bf2671e212 (patch) | |
tree | 7deb9a4a9e928d4b78f7c3398e7d9c97a4649140 /render.c | |
parent | 2ab411c4b8855d11d48454a93262e8eae3ba7fc7 (diff) |
Map rendering and camera movement.
Diffstat (limited to 'render.c')
-rw-r--r-- | render.c | 119 |
1 files changed, 119 insertions, 0 deletions
@@ -261,3 +261,122 @@ void render_bitmap_col( src += sstride; } } + +void blit( + Bitmap* to, + const Bitmap* from, + int x, + int y, + const Rectangle* rect +) { + int i, j, stride, sstride, n; + Colour* dst; + const Colour* src; + Rectangle sub; + + sub = *rect; + + if (sub.w <= 0) { return; } + if (sub.h <= 0) { return; } + if (sub.w > from->w) { return; } + if (sub.h > from->h) { return; } + + if ((n = -x) > 0) { + sub.w -= n; + sub.x += n; + x += n; + } + + if ((n = -y) > 0) { + sub.h -= n; + sub.y += n; + y += n; + } + + if ((n = x + sub.w - to->w) > 0) { + sub.w -= n; + } + + if ((n = y + sub.h - to->h) > 0) { + sub.h -= n; + } + + if (sub.w <= 0) { return; } + if (sub.h <= 0) { return; } + + dst = to->pixels + (x + y * to->w); + src = from->pixels + (sub.x + sub.y * from->w); + + stride = to->w - sub.w; + sstride = from->w - sub.w; + + for (i = 0; i < sub.h; i++) { + for (j = 0; j < sub.w; j++) { + *dst = blend(*dst, *src); + dst++; + src++; + } + dst += stride; + src += sstride; + } +} + +void blit_col( + Bitmap* to, + const Bitmap* from, + int x, + int y, + const Rectangle* rect, + Colour colour +) { + int i, j, stride, sstride, n; + Colour* dst; + const Colour* src; + Rectangle sub; + + sub = *rect; + + if (sub.w <= 0) { return; } + if (sub.h <= 0) { return; } + if (sub.w > from->w) { return; } + if (sub.h > from->h) { return; } + + if ((n = -x) > 0) { + sub.w -= n; + sub.x += n; + x += n; + } + + if ((n = -y) > 0) { + sub.h -= n; + sub.y += n; + y += n; + } + + if ((n = x + sub.w - to->w) > 0) { + sub.w -= n; + } + + if ((n = y + sub.h - to->h) > 0) { + sub.h -= n; + } + + if (sub.w <= 0) { return; } + if (sub.h <= 0) { return; } + + dst = to->pixels + (x + y * to->w); + src = from->pixels + (sub.x + sub.y * from->w); + + stride = to->w - sub.w; + sstride = from->w - sub.w; + + for (i = 0; i < sub.h; i++) { + for (j = 0; j < sub.w; j++) { + *dst = blend_mod(*dst, *src, colour); + dst++; + src++; + } + dst += stride; + src += sstride; + } +} |