omap_lcd_template.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. #if DEPTH == 8
  30. # define BPP 1
  31. # define PIXEL_TYPE uint8_t
  32. #elif DEPTH == 15 || DEPTH == 16
  33. # define BPP 2
  34. # define PIXEL_TYPE uint16_t
  35. #elif DEPTH == 32
  36. # define BPP 4
  37. # define PIXEL_TYPE uint32_t
  38. #else
  39. # error unsupport depth
  40. #endif
  41. /*
  42. * 2-bit colour
  43. */
  44. static void glue(draw_line2_, DEPTH)(void *opaque,
  45. uint8_t *d, const uint8_t *s, int width, int deststep)
  46. {
  47. uint16_t *pal = opaque;
  48. uint8_t v, r, g, b;
  49. do {
  50. v = ldub_raw((void *) s);
  51. r = (pal[v & 3] >> 4) & 0xf0;
  52. g = pal[v & 3] & 0xf0;
  53. b = (pal[v & 3] << 4) & 0xf0;
  54. ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
  55. d += BPP;
  56. v >>= 2;
  57. r = (pal[v & 3] >> 4) & 0xf0;
  58. g = pal[v & 3] & 0xf0;
  59. b = (pal[v & 3] << 4) & 0xf0;
  60. ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
  61. d += BPP;
  62. v >>= 2;
  63. r = (pal[v & 3] >> 4) & 0xf0;
  64. g = pal[v & 3] & 0xf0;
  65. b = (pal[v & 3] << 4) & 0xf0;
  66. ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
  67. d += BPP;
  68. v >>= 2;
  69. r = (pal[v & 3] >> 4) & 0xf0;
  70. g = pal[v & 3] & 0xf0;
  71. b = (pal[v & 3] << 4) & 0xf0;
  72. ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
  73. d += BPP;
  74. s ++;
  75. width -= 4;
  76. } while (width > 0);
  77. }
  78. /*
  79. * 4-bit colour
  80. */
  81. static void glue(draw_line4_, DEPTH)(void *opaque,
  82. uint8_t *d, const uint8_t *s, int width, int deststep)
  83. {
  84. uint16_t *pal = opaque;
  85. uint8_t v, r, g, b;
  86. do {
  87. v = ldub_raw((void *) s);
  88. r = (pal[v & 0xf] >> 4) & 0xf0;
  89. g = pal[v & 0xf] & 0xf0;
  90. b = (pal[v & 0xf] << 4) & 0xf0;
  91. ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
  92. d += BPP;
  93. v >>= 4;
  94. r = (pal[v & 0xf] >> 4) & 0xf0;
  95. g = pal[v & 0xf] & 0xf0;
  96. b = (pal[v & 0xf] << 4) & 0xf0;
  97. ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
  98. d += BPP;
  99. s ++;
  100. width -= 2;
  101. } while (width > 0);
  102. }
  103. /*
  104. * 8-bit colour
  105. */
  106. static void glue(draw_line8_, DEPTH)(void *opaque,
  107. uint8_t *d, const uint8_t *s, int width, int deststep)
  108. {
  109. uint16_t *pal = opaque;
  110. uint8_t v, r, g, b;
  111. do {
  112. v = ldub_raw((void *) s);
  113. r = (pal[v] >> 4) & 0xf0;
  114. g = pal[v] & 0xf0;
  115. b = (pal[v] << 4) & 0xf0;
  116. ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
  117. s ++;
  118. d += BPP;
  119. } while (-- width != 0);
  120. }
  121. /*
  122. * 12-bit colour
  123. */
  124. static void glue(draw_line12_, DEPTH)(void *opaque,
  125. uint8_t *d, const uint8_t *s, int width, int deststep)
  126. {
  127. uint16_t v;
  128. uint8_t r, g, b;
  129. do {
  130. v = lduw_raw((void *) s);
  131. r = (v >> 4) & 0xf0;
  132. g = v & 0xf0;
  133. b = (v << 4) & 0xf0;
  134. ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
  135. s += 2;
  136. d += BPP;
  137. } while (-- width != 0);
  138. }
  139. /*
  140. * 16-bit colour
  141. */
  142. static void glue(draw_line16_, DEPTH)(void *opaque,
  143. uint8_t *d, const uint8_t *s, int width, int deststep)
  144. {
  145. #if DEPTH == 16 && defined(HOST_WORDS_BIGENDIAN) == defined(TARGET_WORDS_BIGENDIAN)
  146. memcpy(d, s, width * 2);
  147. #else
  148. uint16_t v;
  149. uint8_t r, g, b;
  150. do {
  151. v = lduw_raw((void *) s);
  152. r = (v >> 8) & 0xf8;
  153. g = (v >> 3) & 0xfc;
  154. b = (v << 3) & 0xf8;
  155. ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
  156. s += 2;
  157. d += BPP;
  158. } while (-- width != 0);
  159. #endif
  160. }
  161. #undef DEPTH
  162. #undef BPP
  163. #undef PIXEL_TYPE