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 static inline uint32_t
19 ao_pattern_expand(uint8_t v, uint8_t rot)
24 v = (uint8_t) ao_left(v, 8-rot) | (uint8_t) ao_right(v, rot);
26 return (r << 24) | (r << 16) | (r << 8) | (r);
35 ao_pattern(const struct ao_bitmap *dst,
40 const struct ao_pattern *pattern,
47 int16_t x2 = x + width;
48 int16_t y2 = y + height;
50 ao_clip(x, 0, dst->width);
51 ao_clip(x2, 0, dst->width);
52 ao_clip(y, 0, dst->height);
53 ao_clip(y2, 0, dst->height);
55 if (x < x2 && y < y2) {
56 uint8_t xrot = (x - pat_x) & 7;
57 uint8_t yrot = (y - pat_y) & 7;
61 for (i = 0; i < 8; i++)
62 pat[(i + yrot) & 7] = ao_pattern_expand(pattern->pattern[i], xrot);
63 for (dst_y = y; dst_y < y2; dst_y += 8) {
64 int16_t h = (int16_t) min(y2 - dst_y, 8);
65 for (dst_x = x; dst_x < x2; dst_x += 8) {
66 int16_t w = (int16_t) min(x2 - dst_x, 8);
69 dst->base + dst_y * dst->stride,