summaryrefslogtreecommitdiff
path: root/hw/milkymist-vgafb_template.h
blob: 69af9ef3f693d3898f9a55645b1787052adcb6f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
 *  QEMU model of the Milkymist VGA framebuffer.
 *
 *  Copyright (c) 2010 Michael Walle <michael@walle.cc>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
 *
 */

#if BITS == 8
#define COPY_PIXEL(to, r, g, b)                    \
    do {                                           \
        *to = rgb_to_pixel8(r, g, b);              \
        to += 1;                                   \
    } while (0)
#elif BITS == 15
#define COPY_PIXEL(to, r, g, b)                    \
    do {                                           \
        *(uint16_t *)to = rgb_to_pixel15(r, g, b); \
        to += 2;                                   \
    } while (0)
#elif BITS == 16
#define COPY_PIXEL(to, r, g, b)                    \
    do {                                           \
        *(uint16_t *)to = rgb_to_pixel16(r, g, b); \
        to += 2;                                   \
    } while (0)
#elif BITS == 24
#define COPY_PIXEL(to, r, g, b)                    \
    do {                                           \
        uint32 tmp = rgb_to_pixel24(r, g, b);      \
        *(to++) =         tmp & 0xff;              \
        *(to++) =  (tmp >> 8) & 0xff;              \
        *(to++) = (tmp >> 16) & 0xff;              \
    } while (0)
#elif BITS == 32
#define COPY_PIXEL(to, r, g, b)                    \
    do {                                           \
        *(uint32_t *)to = rgb_to_pixel32(r, g, b); \
        to += 4;                                   \
    } while (0)
#else
#error unknown bit depth
#endif

static void glue(draw_line_, BITS)(void *opaque, uint8_t *d, const uint8_t *s,
        int width, int deststep)
{
    uint16_t rgb565;
    uint8_t r, g, b;

    while (width--) {
        rgb565 = lduw_raw(s);
        r = ((rgb565 >> 11) & 0x1f) << 3;
        g = ((rgb565 >>  5) & 0x3f) << 2;
        b = ((rgb565 >>  0) & 0x1f) << 3;
        COPY_PIXEL(d, r, g, b);
        s += 2;
    }
}

#undef BITS
#undef COPY_PIXEL