balrog | c3d2689 | 2007-07-29 17:57:26 +0000 | [diff] [blame] | 1 | /* |
| 2 | * QEMU OMAP LCD Emulator templates |
| 3 | * |
| 4 | * Copyright (c) 2006 Andrzej Zaborowski <balrog@zabor.org> |
| 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions |
| 8 | * are met: |
| 9 | * |
| 10 | * 1. Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * 2. Redistributions in binary form must reproduce the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer in |
| 14 | * the documentation and/or other materials provided with the |
| 15 | * distribution. |
| 16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' |
| 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 19 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
| 20 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR |
| 21 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 22 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 23 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 24 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 25 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | */ |
| 29 | |
Pooja Dhannawat | ea644cf | 2016-05-12 13:22:24 +0100 | [diff] [blame] | 30 | #if DEPTH == 32 |
balrog | c3d2689 | 2007-07-29 17:57:26 +0000 | [diff] [blame] | 31 | # define BPP 4 |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 32 | # define PIXEL_TYPE uint32_t |
balrog | c3d2689 | 2007-07-29 17:57:26 +0000 | [diff] [blame] | 33 | #else |
| 34 | # error unsupport depth |
| 35 | #endif |
| 36 | |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 37 | /* |
balrog | c3d2689 | 2007-07-29 17:57:26 +0000 | [diff] [blame] | 38 | * 2-bit colour |
| 39 | */ |
pbrook | 714fa30 | 2009-04-01 12:27:59 +0000 | [diff] [blame] | 40 | static void glue(draw_line2_, DEPTH)(void *opaque, |
| 41 | uint8_t *d, const uint8_t *s, int width, int deststep) |
balrog | c3d2689 | 2007-07-29 17:57:26 +0000 | [diff] [blame] | 42 | { |
pbrook | 714fa30 | 2009-04-01 12:27:59 +0000 | [diff] [blame] | 43 | uint16_t *pal = opaque; |
balrog | c3d2689 | 2007-07-29 17:57:26 +0000 | [diff] [blame] | 44 | uint8_t v, r, g, b; |
| 45 | |
| 46 | do { |
Paolo Bonzini | 0983979 | 2014-03-28 18:43:14 +0100 | [diff] [blame] | 47 | v = ldub_p((void *) s); |
balrog | c3d2689 | 2007-07-29 17:57:26 +0000 | [diff] [blame] | 48 | r = (pal[v & 3] >> 4) & 0xf0; |
| 49 | g = pal[v & 3] & 0xf0; |
| 50 | b = (pal[v & 3] << 4) & 0xf0; |
| 51 | ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b); |
| 52 | d += BPP; |
| 53 | v >>= 2; |
| 54 | r = (pal[v & 3] >> 4) & 0xf0; |
| 55 | g = pal[v & 3] & 0xf0; |
| 56 | b = (pal[v & 3] << 4) & 0xf0; |
| 57 | ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b); |
| 58 | d += BPP; |
| 59 | v >>= 2; |
| 60 | r = (pal[v & 3] >> 4) & 0xf0; |
| 61 | g = pal[v & 3] & 0xf0; |
| 62 | b = (pal[v & 3] << 4) & 0xf0; |
| 63 | ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b); |
| 64 | d += BPP; |
| 65 | v >>= 2; |
| 66 | r = (pal[v & 3] >> 4) & 0xf0; |
| 67 | g = pal[v & 3] & 0xf0; |
| 68 | b = (pal[v & 3] << 4) & 0xf0; |
| 69 | ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b); |
| 70 | d += BPP; |
| 71 | s ++; |
| 72 | width -= 4; |
| 73 | } while (width > 0); |
| 74 | } |
| 75 | |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 76 | /* |
balrog | c3d2689 | 2007-07-29 17:57:26 +0000 | [diff] [blame] | 77 | * 4-bit colour |
| 78 | */ |
pbrook | 714fa30 | 2009-04-01 12:27:59 +0000 | [diff] [blame] | 79 | static void glue(draw_line4_, DEPTH)(void *opaque, |
| 80 | uint8_t *d, const uint8_t *s, int width, int deststep) |
balrog | c3d2689 | 2007-07-29 17:57:26 +0000 | [diff] [blame] | 81 | { |
pbrook | 714fa30 | 2009-04-01 12:27:59 +0000 | [diff] [blame] | 82 | uint16_t *pal = opaque; |
balrog | c3d2689 | 2007-07-29 17:57:26 +0000 | [diff] [blame] | 83 | uint8_t v, r, g, b; |
| 84 | |
| 85 | do { |
Paolo Bonzini | 0983979 | 2014-03-28 18:43:14 +0100 | [diff] [blame] | 86 | v = ldub_p((void *) s); |
balrog | c3d2689 | 2007-07-29 17:57:26 +0000 | [diff] [blame] | 87 | r = (pal[v & 0xf] >> 4) & 0xf0; |
| 88 | g = pal[v & 0xf] & 0xf0; |
| 89 | b = (pal[v & 0xf] << 4) & 0xf0; |
| 90 | ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b); |
| 91 | d += BPP; |
| 92 | v >>= 4; |
| 93 | r = (pal[v & 0xf] >> 4) & 0xf0; |
| 94 | g = pal[v & 0xf] & 0xf0; |
| 95 | b = (pal[v & 0xf] << 4) & 0xf0; |
| 96 | ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b); |
| 97 | d += BPP; |
| 98 | s ++; |
| 99 | width -= 2; |
| 100 | } while (width > 0); |
| 101 | } |
| 102 | |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 103 | /* |
balrog | c3d2689 | 2007-07-29 17:57:26 +0000 | [diff] [blame] | 104 | * 8-bit colour |
| 105 | */ |
pbrook | 714fa30 | 2009-04-01 12:27:59 +0000 | [diff] [blame] | 106 | static void glue(draw_line8_, DEPTH)(void *opaque, |
| 107 | uint8_t *d, const uint8_t *s, int width, int deststep) |
balrog | c3d2689 | 2007-07-29 17:57:26 +0000 | [diff] [blame] | 108 | { |
pbrook | 714fa30 | 2009-04-01 12:27:59 +0000 | [diff] [blame] | 109 | uint16_t *pal = opaque; |
balrog | c3d2689 | 2007-07-29 17:57:26 +0000 | [diff] [blame] | 110 | uint8_t v, r, g, b; |
| 111 | |
| 112 | do { |
Paolo Bonzini | 0983979 | 2014-03-28 18:43:14 +0100 | [diff] [blame] | 113 | v = ldub_p((void *) s); |
balrog | c3d2689 | 2007-07-29 17:57:26 +0000 | [diff] [blame] | 114 | r = (pal[v] >> 4) & 0xf0; |
| 115 | g = pal[v] & 0xf0; |
| 116 | b = (pal[v] << 4) & 0xf0; |
| 117 | ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b); |
| 118 | s ++; |
| 119 | d += BPP; |
| 120 | } while (-- width != 0); |
| 121 | } |
| 122 | |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 123 | /* |
balrog | c3d2689 | 2007-07-29 17:57:26 +0000 | [diff] [blame] | 124 | * 12-bit colour |
| 125 | */ |
pbrook | 714fa30 | 2009-04-01 12:27:59 +0000 | [diff] [blame] | 126 | static void glue(draw_line12_, DEPTH)(void *opaque, |
| 127 | uint8_t *d, const uint8_t *s, int width, int deststep) |
balrog | c3d2689 | 2007-07-29 17:57:26 +0000 | [diff] [blame] | 128 | { |
| 129 | uint16_t v; |
| 130 | uint8_t r, g, b; |
| 131 | |
| 132 | do { |
Paolo Bonzini | 58f6d82 | 2015-12-17 13:37:13 +0000 | [diff] [blame] | 133 | v = lduw_le_p((void *) s); |
balrog | c3d2689 | 2007-07-29 17:57:26 +0000 | [diff] [blame] | 134 | r = (v >> 4) & 0xf0; |
| 135 | g = v & 0xf0; |
| 136 | b = (v << 4) & 0xf0; |
| 137 | ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b); |
| 138 | s += 2; |
| 139 | d += BPP; |
| 140 | } while (-- width != 0); |
| 141 | } |
| 142 | |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 143 | /* |
balrog | c3d2689 | 2007-07-29 17:57:26 +0000 | [diff] [blame] | 144 | * 16-bit colour |
| 145 | */ |
pbrook | 714fa30 | 2009-04-01 12:27:59 +0000 | [diff] [blame] | 146 | static void glue(draw_line16_, DEPTH)(void *opaque, |
| 147 | uint8_t *d, const uint8_t *s, int width, int deststep) |
balrog | c3d2689 | 2007-07-29 17:57:26 +0000 | [diff] [blame] | 148 | { |
Pooja Dhannawat | ea644cf | 2016-05-12 13:22:24 +0100 | [diff] [blame] | 149 | #if defined(HOST_WORDS_BIGENDIAN) == defined(TARGET_WORDS_BIGENDIAN) |
balrog | c3d2689 | 2007-07-29 17:57:26 +0000 | [diff] [blame] | 150 | memcpy(d, s, width * 2); |
| 151 | #else |
| 152 | uint16_t v; |
| 153 | uint8_t r, g, b; |
| 154 | |
| 155 | do { |
Paolo Bonzini | 58f6d82 | 2015-12-17 13:37:13 +0000 | [diff] [blame] | 156 | v = lduw_le_p((void *) s); |
balrog | c3d2689 | 2007-07-29 17:57:26 +0000 | [diff] [blame] | 157 | r = (v >> 8) & 0xf8; |
| 158 | g = (v >> 3) & 0xfc; |
| 159 | b = (v << 3) & 0xf8; |
| 160 | ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b); |
| 161 | s += 2; |
| 162 | d += BPP; |
| 163 | } while (-- width != 0); |
| 164 | #endif |
| 165 | } |
| 166 | |
| 167 | #undef DEPTH |
| 168 | #undef BPP |
| 169 | #undef PIXEL_TYPE |