diff options
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; + } +} |