2
0

omap_lcd_template.h 4.8 KB

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