qemu/hw/display/blizzard_template.h
<<
>>
Prefs
   1/*
   2 * QEMU Epson S1D13744/S1D13745 templates
   3 *
   4 * Copyright (C) 2008 Nokia Corporation
   5 * Written by Andrzej Zaborowski <andrew@openedhand.com>
   6 *
   7 * This program is free software; you can redistribute it and/or
   8 * modify it under the terms of the GNU General Public License as
   9 * published by the Free Software Foundation; either version 2 or
  10 * (at your option) version 3 of the License.
  11 *
  12 * This program is distributed in the hope that it will be useful,
  13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15 * GNU General Public License for more details.
  16 *
  17 * You should have received a copy of the GNU General Public License along
  18 * with this program; if not, see <http://www.gnu.org/licenses/>.
  19 */
  20
  21#define SKIP_PIXEL(to)         (to += deststep)
  22#if DEPTH == 8
  23# define PIXEL_TYPE            uint8_t
  24# define COPY_PIXEL(to, from)  do { *to = from; SKIP_PIXEL(to); } while (0)
  25# define COPY_PIXEL1(to, from) (*to++ = from)
  26#elif DEPTH == 15 || DEPTH == 16
  27# define PIXEL_TYPE            uint16_t
  28# define COPY_PIXEL(to, from)  do { *to = from; SKIP_PIXEL(to); } while (0)
  29# define COPY_PIXEL1(to, from) (*to++ = from)
  30#elif DEPTH == 24
  31# define PIXEL_TYPE            uint8_t
  32# define COPY_PIXEL(to, from) \
  33    do {                      \
  34        to[0] = from;         \
  35        to[1] = (from) >> 8;  \
  36        to[2] = (from) >> 16; \
  37        SKIP_PIXEL(to);       \
  38    } while (0)
  39
  40# define COPY_PIXEL1(to, from) \
  41    do {                       \
  42        *to++ = from;          \
  43        *to++ = (from) >> 8;   \
  44        *to++ = (from) >> 16;  \
  45    } while (0)
  46#elif DEPTH == 32
  47# define PIXEL_TYPE            uint32_t
  48# define COPY_PIXEL(to, from)  do { *to = from; SKIP_PIXEL(to); } while (0)
  49# define COPY_PIXEL1(to, from) (*to++ = from)
  50#else
  51# error unknown bit depth
  52#endif
  53
  54#ifdef HOST_WORDS_BIGENDIAN
  55# define SWAP_WORDS     1
  56#endif
  57
  58static void glue(blizzard_draw_line16_, DEPTH)(PIXEL_TYPE *dest,
  59                const uint16_t *src, unsigned int width)
  60{
  61#if !defined(SWAP_WORDS) && DEPTH == 16
  62    memcpy(dest, src, width);
  63#else
  64    uint16_t data;
  65    unsigned int r, g, b;
  66    const uint16_t *end = (const void *) src + width;
  67    while (src < end) {
  68        data = *src ++;
  69        b = (data & 0x1f) << 3;
  70        data >>= 5;
  71        g = (data & 0x3f) << 2;
  72        data >>= 6;
  73        r = (data & 0x1f) << 3;
  74        data >>= 5;
  75        COPY_PIXEL1(dest, glue(rgb_to_pixel, DEPTH)(r, g, b));
  76    }
  77#endif
  78}
  79
  80static void glue(blizzard_draw_line24mode1_, DEPTH)(PIXEL_TYPE *dest,
  81                const uint8_t *src, unsigned int width)
  82{
  83    /* TODO: check if SDL 24-bit planes are not in the same format and
  84     * if so, use memcpy */
  85    unsigned int r[2], g[2], b[2];
  86    const uint8_t *end = src + width;
  87    while (src < end) {
  88        g[0] = *src ++;
  89        r[0] = *src ++;
  90        r[1] = *src ++;
  91        b[0] = *src ++;
  92        COPY_PIXEL1(dest, glue(rgb_to_pixel, DEPTH)(r[0], g[0], b[0]));
  93        b[1] = *src ++;
  94        g[1] = *src ++;
  95        COPY_PIXEL1(dest, glue(rgb_to_pixel, DEPTH)(r[1], g[1], b[1]));
  96    }
  97}
  98
  99static void glue(blizzard_draw_line24mode2_, DEPTH)(PIXEL_TYPE *dest,
 100                const uint8_t *src, unsigned int width)
 101{
 102    unsigned int r, g, b;
 103    const uint8_t *end = src + width;
 104    while (src < end) {
 105        r = *src ++;
 106        src ++;
 107        b = *src ++;
 108        g = *src ++;
 109        COPY_PIXEL1(dest, glue(rgb_to_pixel, DEPTH)(r, g, b));
 110    }
 111}
 112
 113/* No rotation */
 114static blizzard_fn_t glue(blizzard_draw_fn_, DEPTH)[0x10] = {
 115    NULL,
 116    /* RGB 5:6:5*/
 117    (blizzard_fn_t) glue(blizzard_draw_line16_, DEPTH),
 118    /* RGB 6:6:6 mode 1 */
 119    (blizzard_fn_t) glue(blizzard_draw_line24mode1_, DEPTH),
 120    /* RGB 8:8:8 mode 1 */
 121    (blizzard_fn_t) glue(blizzard_draw_line24mode1_, DEPTH),
 122    NULL, NULL,
 123    /* RGB 6:6:6 mode 2 */
 124    (blizzard_fn_t) glue(blizzard_draw_line24mode2_, DEPTH),
 125    /* RGB 8:8:8 mode 2 */
 126    (blizzard_fn_t) glue(blizzard_draw_line24mode2_, DEPTH),
 127    /* YUV 4:2:2 */
 128    NULL,
 129    /* YUV 4:2:0 */
 130    NULL,
 131    NULL, NULL, NULL, NULL, NULL, NULL,
 132};
 133
 134/* 90deg, 180deg and 270deg rotation */
 135static blizzard_fn_t glue(blizzard_draw_fn_r_, DEPTH)[0x10] = {
 136    /* TODO */
 137    [0 ... 0xf] = NULL,
 138};
 139
 140#undef DEPTH
 141#undef SKIP_PIXEL
 142#undef COPY_PIXEL
 143#undef COPY_PIXEL1
 144#undef PIXEL_TYPE
 145
 146#undef SWAP_WORDS
 147