pl110_template.h 9.3 KB
Newer Older
1
/*
P
pbrook 已提交
2 3 4 5 6
 * Arm PrimeCell PL110 Color LCD Controller
 *
 * Copyright (c) 2005 CodeSourcery, LLC.
 * Written by Paul Brook
 *
M
Matthew Fernandez 已提交
7
 * This code is licensed under the GNU LGPL
P
pbrook 已提交
8 9 10 11 12 13 14 15 16 17
 *
 * Framebuffer format conversion routines.
 */

#ifndef ORDER

#if BITS == 8
#define COPY_PIXEL(to, from) *(to++) = from
#elif BITS == 15 || BITS == 16
#define COPY_PIXEL(to, from) *(uint16_t *)to = from; to += 2;
18
#elif BITS == 24
P
pbrook 已提交
19 20 21 22 23 24 25 26
#define COPY_PIXEL(to, from) \
  *(to++) = from; *(to++) = (from) >> 8; *(to++) = (from) >> 16
#elif BITS == 32
#define COPY_PIXEL(to, from) *(uint32_t *)to = from; to += 4;
#else
#error unknown bit depth
#endif

27 28
#undef RGB
#define BORDER bgr
P
pbrook 已提交
29 30 31 32 33 34
#define ORDER 0
#include "pl110_template.h"
#define ORDER 1
#include "pl110_template.h"
#define ORDER 2
#include "pl110_template.h"
35 36 37 38 39 40 41 42 43 44
#undef BORDER
#define RGB
#define BORDER rgb
#define ORDER 0
#include "pl110_template.h"
#define ORDER 1
#include "pl110_template.h"
#define ORDER 2
#include "pl110_template.h"
#undef BORDER
P
pbrook 已提交
45

46
static drawfn glue(pl110_draw_fn_,BITS)[48] =
P
pbrook 已提交
47
{
48 49 50 51
    glue(pl110_draw_line1_lblp_bgr,BITS),
    glue(pl110_draw_line2_lblp_bgr,BITS),
    glue(pl110_draw_line4_lblp_bgr,BITS),
    glue(pl110_draw_line8_lblp_bgr,BITS),
52
    glue(pl110_draw_line16_555_lblp_bgr,BITS),
53
    glue(pl110_draw_line32_lblp_bgr,BITS),
54 55
    glue(pl110_draw_line16_lblp_bgr,BITS),
    glue(pl110_draw_line12_lblp_bgr,BITS),
56 57 58 59 60

    glue(pl110_draw_line1_bbbp_bgr,BITS),
    glue(pl110_draw_line2_bbbp_bgr,BITS),
    glue(pl110_draw_line4_bbbp_bgr,BITS),
    glue(pl110_draw_line8_bbbp_bgr,BITS),
61
    glue(pl110_draw_line16_555_bbbp_bgr,BITS),
62
    glue(pl110_draw_line32_bbbp_bgr,BITS),
63 64
    glue(pl110_draw_line16_bbbp_bgr,BITS),
    glue(pl110_draw_line12_bbbp_bgr,BITS),
65 66 67 68 69

    glue(pl110_draw_line1_lbbp_bgr,BITS),
    glue(pl110_draw_line2_lbbp_bgr,BITS),
    glue(pl110_draw_line4_lbbp_bgr,BITS),
    glue(pl110_draw_line8_lbbp_bgr,BITS),
70
    glue(pl110_draw_line16_555_lbbp_bgr,BITS),
71
    glue(pl110_draw_line32_lbbp_bgr,BITS),
72 73
    glue(pl110_draw_line16_lbbp_bgr,BITS),
    glue(pl110_draw_line12_lbbp_bgr,BITS),
74 75 76 77 78

    glue(pl110_draw_line1_lblp_rgb,BITS),
    glue(pl110_draw_line2_lblp_rgb,BITS),
    glue(pl110_draw_line4_lblp_rgb,BITS),
    glue(pl110_draw_line8_lblp_rgb,BITS),
79
    glue(pl110_draw_line16_555_lblp_rgb,BITS),
80
    glue(pl110_draw_line32_lblp_rgb,BITS),
81 82
    glue(pl110_draw_line16_lblp_rgb,BITS),
    glue(pl110_draw_line12_lblp_rgb,BITS),
83 84 85 86 87

    glue(pl110_draw_line1_bbbp_rgb,BITS),
    glue(pl110_draw_line2_bbbp_rgb,BITS),
    glue(pl110_draw_line4_bbbp_rgb,BITS),
    glue(pl110_draw_line8_bbbp_rgb,BITS),
88
    glue(pl110_draw_line16_555_bbbp_rgb,BITS),
89
    glue(pl110_draw_line32_bbbp_rgb,BITS),
90 91
    glue(pl110_draw_line16_bbbp_rgb,BITS),
    glue(pl110_draw_line12_bbbp_rgb,BITS),
92 93 94 95 96

    glue(pl110_draw_line1_lbbp_rgb,BITS),
    glue(pl110_draw_line2_lbbp_rgb,BITS),
    glue(pl110_draw_line4_lbbp_rgb,BITS),
    glue(pl110_draw_line8_lbbp_rgb,BITS),
97
    glue(pl110_draw_line16_555_lbbp_rgb,BITS),
98
    glue(pl110_draw_line32_lbbp_rgb,BITS),
99 100
    glue(pl110_draw_line16_lbbp_rgb,BITS),
    glue(pl110_draw_line12_lbbp_rgb,BITS),
P
pbrook 已提交
101 102 103 104 105 106 107 108
};

#undef BITS
#undef COPY_PIXEL

#else

#if ORDER == 0
109
#define NAME glue(glue(lblp_, BORDER), BITS)
110
#ifdef HOST_WORDS_BIGENDIAN
P
pbrook 已提交
111 112 113
#define SWAP_WORDS 1
#endif
#elif ORDER == 1
114
#define NAME glue(glue(bbbp_, BORDER), BITS)
115
#ifndef HOST_WORDS_BIGENDIAN
P
pbrook 已提交
116 117 118 119
#define SWAP_WORDS 1
#endif
#else
#define SWAP_PIXELS 1
120
#define NAME glue(glue(lbbp_, BORDER), BITS)
121
#ifdef HOST_WORDS_BIGENDIAN
P
pbrook 已提交
122 123 124 125 126
#define SWAP_WORDS 1
#endif
#endif

#define FN_2(x, y) FN(x, y) FN(x+1, y)
P
pbrook 已提交
127
#define FN_4(x, y) FN_2(x, y) FN_2(x+2, y)
P
pbrook 已提交
128 129
#define FN_8(y) FN_4(0, y) FN_4(4, y)

130
static void glue(pl110_draw_line1_,NAME)(void *opaque, uint8_t *d, const uint8_t *src, int width, int deststep)
P
pbrook 已提交
131
{
132
    uint32_t *pallette = opaque;
P
pbrook 已提交
133 134 135 136 137 138 139 140
    uint32_t data;
    while (width > 0) {
        data = *(uint32_t *)src;
#ifdef SWAP_PIXELS
#define FN(x, y) COPY_PIXEL(d, pallette[(data >> (y + 7 - (x))) & 1]);
#else
#define FN(x, y) COPY_PIXEL(d, pallette[(data >> ((x) + y)) & 1]);
#endif
P
pbrook 已提交
141
#ifdef SWAP_WORDS
P
pbrook 已提交
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
        FN_8(24)
        FN_8(16)
        FN_8(8)
        FN_8(0)
#else
        FN_8(0)
        FN_8(8)
        FN_8(16)
        FN_8(24)
#endif
#undef FN
        width -= 32;
        src += 4;
    }
}

158
static void glue(pl110_draw_line2_,NAME)(void *opaque, uint8_t *d, const uint8_t *src, int width, int deststep)
P
pbrook 已提交
159
{
160
    uint32_t *pallette = opaque;
P
pbrook 已提交
161 162 163 164 165 166 167 168
    uint32_t data;
    while (width > 0) {
        data = *(uint32_t *)src;
#ifdef SWAP_PIXELS
#define FN(x, y) COPY_PIXEL(d, pallette[(data >> (y + 6 - (x)*2)) & 3]);
#else
#define FN(x, y) COPY_PIXEL(d, pallette[(data >> ((x)*2 + y)) & 3]);
#endif
P
pbrook 已提交
169
#ifdef SWAP_WORDS
P
pbrook 已提交
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
        FN_4(0, 24)
        FN_4(0, 16)
        FN_4(0, 8)
        FN_4(0, 0)
#else
        FN_4(0, 0)
        FN_4(0, 8)
        FN_4(0, 16)
        FN_4(0, 24)
#endif
#undef FN
        width -= 16;
        src += 4;
    }
}

186
static void glue(pl110_draw_line4_,NAME)(void *opaque, uint8_t *d, const uint8_t *src, int width, int deststep)
P
pbrook 已提交
187
{
188
    uint32_t *pallette = opaque;
P
pbrook 已提交
189 190 191 192 193 194 195 196
    uint32_t data;
    while (width > 0) {
        data = *(uint32_t *)src;
#ifdef SWAP_PIXELS
#define FN(x, y) COPY_PIXEL(d, pallette[(data >> (y + 4 - (x)*4)) & 0xf]);
#else
#define FN(x, y) COPY_PIXEL(d, pallette[(data >> ((x)*4 + y)) & 0xf]);
#endif
P
pbrook 已提交
197
#ifdef SWAP_WORDS
P
pbrook 已提交
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
        FN_2(0, 24)
        FN_2(0, 16)
        FN_2(0, 8)
        FN_2(0, 0)
#else
        FN_2(0, 0)
        FN_2(0, 8)
        FN_2(0, 16)
        FN_2(0, 24)
#endif
#undef FN
        width -= 8;
        src += 4;
    }
}

214
static void glue(pl110_draw_line8_,NAME)(void *opaque, uint8_t *d, const uint8_t *src, int width, int deststep)
P
pbrook 已提交
215
{
216
    uint32_t *pallette = opaque;
P
pbrook 已提交
217 218 219 220
    uint32_t data;
    while (width > 0) {
        data = *(uint32_t *)src;
#define FN(x) COPY_PIXEL(d, pallette[(data >> (x)) & 0xff]);
P
pbrook 已提交
221
#ifdef SWAP_WORDS
P
pbrook 已提交
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
        FN(24)
        FN(16)
        FN(8)
        FN(0)
#else
        FN(0)
        FN(8)
        FN(16)
        FN(24)
#endif
#undef FN
        width -= 4;
        src += 4;
    }
}

238
static void glue(pl110_draw_line16_,NAME)(void *opaque, uint8_t *d, const uint8_t *src, int width, int deststep)
P
pbrook 已提交
239 240 241 242 243
{
    uint32_t data;
    unsigned int r, g, b;
    while (width > 0) {
        data = *(uint32_t *)src;
P
pbrook 已提交
244
#ifdef SWAP_WORDS
P
pbrook 已提交
245 246
        data = bswap32(data);
#endif
247 248 249 250 251 252 253
#ifdef RGB
#define LSB r
#define MSB b
#else
#define LSB b
#define MSB r
#endif
P
pbrook 已提交
254
#if 0
255
        LSB = data & 0x1f;
P
pbrook 已提交
256 257 258
        data >>= 5;
        g = data & 0x3f;
        data >>= 6;
259
        MSB = data & 0x1f;
P
pbrook 已提交
260 261
        data >>= 5;
#else
262
        LSB = (data & 0x1f) << 3;
P
pbrook 已提交
263 264 265
        data >>= 5;
        g = (data & 0x3f) << 2;
        data >>= 6;
266
        MSB = (data & 0x1f) << 3;
P
pbrook 已提交
267 268 269
        data >>= 5;
#endif
        COPY_PIXEL(d, glue(rgb_to_pixel,BITS)(r, g, b));
270
        LSB = (data & 0x1f) << 3;
P
pbrook 已提交
271 272 273
        data >>= 5;
        g = (data & 0x3f) << 2;
        data >>= 6;
274
        MSB = (data & 0x1f) << 3;
P
pbrook 已提交
275 276
        data >>= 5;
        COPY_PIXEL(d, glue(rgb_to_pixel,BITS)(r, g, b));
277 278
#undef MSB
#undef LSB
P
pbrook 已提交
279 280 281 282 283
        width -= 2;
        src += 4;
    }
}

284
static void glue(pl110_draw_line32_,NAME)(void *opaque, uint8_t *d, const uint8_t *src, int width, int deststep)
P
pbrook 已提交
285 286 287 288 289
{
    uint32_t data;
    unsigned int r, g, b;
    while (width > 0) {
        data = *(uint32_t *)src;
290 291 292 293 294 295 296
#ifdef RGB
#define LSB r
#define MSB b
#else
#define LSB b
#define MSB r
#endif
297
#ifndef SWAP_WORDS
298
        LSB = data & 0xff;
P
pbrook 已提交
299
        g = (data >> 8) & 0xff;
300
        MSB = (data >> 16) & 0xff;
P
pbrook 已提交
301
#else
302
        LSB = (data >> 24) & 0xff;
P
pbrook 已提交
303
        g = (data >> 16) & 0xff;
304
        MSB = (data >> 8) & 0xff;
P
pbrook 已提交
305 306
#endif
        COPY_PIXEL(d, glue(rgb_to_pixel,BITS)(r, g, b));
307 308
#undef MSB
#undef LSB
P
pbrook 已提交
309 310 311 312 313
        width--;
        src += 4;
    }
}

314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389
static void glue(pl110_draw_line16_555_,NAME)(void *opaque, uint8_t *d, const uint8_t *src, int width, int deststep)
{
    /* RGB 555 plus an intensity bit (which we ignore) */
    uint32_t data;
    unsigned int r, g, b;
    while (width > 0) {
        data = *(uint32_t *)src;
#ifdef SWAP_WORDS
        data = bswap32(data);
#endif
#ifdef RGB
#define LSB r
#define MSB b
#else
#define LSB b
#define MSB r
#endif
        LSB = (data & 0x1f) << 3;
        data >>= 5;
        g = (data & 0x1f) << 3;
        data >>= 5;
        MSB = (data & 0x1f) << 3;
        data >>= 5;
        COPY_PIXEL(d, glue(rgb_to_pixel,BITS)(r, g, b));
        LSB = (data & 0x1f) << 3;
        data >>= 5;
        g = (data & 0x1f) << 3;
        data >>= 5;
        MSB = (data & 0x1f) << 3;
        data >>= 6;
        COPY_PIXEL(d, glue(rgb_to_pixel,BITS)(r, g, b));
#undef MSB
#undef LSB
        width -= 2;
        src += 4;
    }
}

static void glue(pl110_draw_line12_,NAME)(void *opaque, uint8_t *d, const uint8_t *src, int width, int deststep)
{
    /* RGB 444 with 4 bits of zeroes at the top of each halfword */
    uint32_t data;
    unsigned int r, g, b;
    while (width > 0) {
        data = *(uint32_t *)src;
#ifdef SWAP_WORDS
        data = bswap32(data);
#endif
#ifdef RGB
#define LSB r
#define MSB b
#else
#define LSB b
#define MSB r
#endif
        LSB = (data & 0xf) << 4;
        data >>= 4;
        g = (data & 0xf) << 4;
        data >>= 4;
        MSB = (data & 0xf) << 4;
        data >>= 8;
        COPY_PIXEL(d, glue(rgb_to_pixel,BITS)(r, g, b));
        LSB = (data & 0xf) << 4;
        data >>= 4;
        g = (data & 0xf) << 4;
        data >>= 4;
        MSB = (data & 0xf) << 4;
        data >>= 8;
        COPY_PIXEL(d, glue(rgb_to_pixel,BITS)(r, g, b));
#undef MSB
#undef LSB
        width -= 2;
        src += 4;
    }
}

P
pbrook 已提交
390 391 392 393 394 395
#undef SWAP_PIXELS
#undef NAME
#undef SWAP_WORDS
#undef ORDER

#endif