aboutsummaryrefslogtreecommitdiff
path: root/render.c
diff options
context:
space:
mode:
Diffstat (limited to 'render.c')
-rw-r--r--render.c119
1 files changed, 119 insertions, 0 deletions
diff --git a/render.c b/render.c
index b2a59e2..c18d74d 100644
--- a/render.c
+++ b/render.c
@@ -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;
+ }
+}