2 * Copyright © 2016 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
16 #include <ao_draw_int.h>
18 #define bound(val,max,other) do { \
20 other += (typeof(other)) (-val); \
24 other -= (typeof(other)) (val - max); \
29 #define bound2(a, max_a, b, max_b) do { \
35 ao_copy(struct ao_bitmap *dst,
40 const struct ao_bitmap *src,
45 int16_t dst_x2 = dst_x + width, dst_y2 = dst_y + height;
46 int16_t src_x2 = src_x + width, src_y2 = src_y + height;
48 uint8_t upsidedown = 0;
50 bound2(dst_x, dst->width, src_x, src->width);
51 bound2(dst_x2, dst->width, src_x2, src->width);
52 bound2(dst_y, dst->height, src_y, src->height);
53 bound2(dst_y2, dst->height, src_y2, src->height);
56 reverse = (dst_x > src_x);
57 upsidedown = (dst_y > src_y);
60 ao_damage(dst, dst_x, dst_y, dst_x2, dst_y2);
62 if (dst_x < dst_x2 && dst_y < dst_y2) {
63 ao_blt(src->base + src_y * src->stride,
66 dst->base + dst_y * dst->stride,