blizzard_template.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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, write to the Free Software Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  20. */
  21. #define SKIP_PIXEL(to) to += deststep
  22. #if DEPTH == 8
  23. # define PIXEL_TYPE uint8_t
  24. # define COPY_PIXEL(to, from) *to = from; SKIP_PIXEL(to)
  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) *to = from; SKIP_PIXEL(to)
  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. to[0] = from; to[1] = (from) >> 8; to[2] = (from) >> 16; SKIP_PIXEL(to)
  34. # define COPY_PIXEL1(to, from) \
  35. *to ++ = from; *to ++ = (from) >> 8; *to ++ = (from) >> 16
  36. #elif DEPTH == 32
  37. # define PIXEL_TYPE uint32_t
  38. # define COPY_PIXEL(to, from) *to = from; SKIP_PIXEL(to)
  39. # define COPY_PIXEL1(to, from) *to ++ = from
  40. #else
  41. # error unknown bit depth
  42. #endif
  43. #ifdef WORDS_BIGENDIAN
  44. # define SWAP_WORDS 1
  45. #endif
  46. static void glue(blizzard_draw_line16_, DEPTH)(PIXEL_TYPE *dest,
  47. const uint16_t *src, unsigned int width)
  48. {
  49. #if !defined(SWAP_WORDS) && DEPTH == 16
  50. memcpy(dest, src, width);
  51. #else
  52. uint16_t data;
  53. unsigned int r, g, b;
  54. const uint16_t *end = (const void *) src + width;
  55. while (src < end) {
  56. data = lduw_raw(src ++);
  57. b = (data & 0x1f) << 3;
  58. data >>= 5;
  59. g = (data & 0x3f) << 2;
  60. data >>= 6;
  61. r = (data & 0x1f) << 3;
  62. data >>= 5;
  63. COPY_PIXEL1(dest, glue(rgb_to_pixel, DEPTH)(r, g, b));
  64. }
  65. #endif
  66. }
  67. static void glue(blizzard_draw_line24mode1_, DEPTH)(PIXEL_TYPE *dest,
  68. const uint8_t *src, unsigned int width)
  69. {
  70. /* TODO: check if SDL 24-bit planes are not in the same format and
  71. * if so, use memcpy */
  72. unsigned int r[2], g[2], b[2];
  73. const uint8_t *end = src + width;
  74. while (src < end) {
  75. g[0] = *src ++;
  76. r[0] = *src ++;
  77. r[1] = *src ++;
  78. b[0] = *src ++;
  79. COPY_PIXEL1(dest, glue(rgb_to_pixel, DEPTH)(r[0], g[0], b[0]));
  80. b[1] = *src ++;
  81. g[1] = *src ++;
  82. COPY_PIXEL1(dest, glue(rgb_to_pixel, DEPTH)(r[1], g[1], b[1]));
  83. }
  84. }
  85. static void glue(blizzard_draw_line24mode2_, DEPTH)(PIXEL_TYPE *dest,
  86. const uint8_t *src, unsigned int width)
  87. {
  88. unsigned int r, g, b;
  89. const uint8_t *end = src + width;
  90. while (src < end) {
  91. r = *src ++;
  92. src ++;
  93. b = *src ++;
  94. g = *src ++;
  95. COPY_PIXEL1(dest, glue(rgb_to_pixel, DEPTH)(r, g, b));
  96. }
  97. }
  98. /* No rotation */
  99. static blizzard_fn_t glue(blizzard_draw_fn_, DEPTH)[0x10] = {
  100. NULL,
  101. /* RGB 5:6:5*/
  102. (blizzard_fn_t) glue(blizzard_draw_line16_, DEPTH),
  103. /* RGB 6:6:6 mode 1 */
  104. (blizzard_fn_t) glue(blizzard_draw_line24mode1_, DEPTH),
  105. /* RGB 8:8:8 mode 1 */
  106. (blizzard_fn_t) glue(blizzard_draw_line24mode1_, DEPTH),
  107. NULL, NULL,
  108. /* RGB 6:6:6 mode 2 */
  109. (blizzard_fn_t) glue(blizzard_draw_line24mode2_, DEPTH),
  110. /* RGB 8:8:8 mode 2 */
  111. (blizzard_fn_t) glue(blizzard_draw_line24mode2_, DEPTH),
  112. /* YUV 4:2:2 */
  113. NULL,
  114. /* YUV 4:2:0 */
  115. NULL,
  116. NULL, NULL, NULL, NULL, NULL, NULL,
  117. };
  118. /* 90deg, 180deg and 270deg rotation */
  119. static blizzard_fn_t glue(blizzard_draw_fn_r_, DEPTH)[0x10] = {
  120. /* TODO */
  121. [0 ... 0xf] = NULL,
  122. };
  123. #undef DEPTH
  124. #undef SKIP_PIXEL
  125. #undef COPY_PIXEL
  126. #undef COPY_PIXEL1
  127. #undef PIXEL_TYPE
  128. #undef SWAP_WORDS