2
0

omap_lcd_template.h 4.8 KB

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