nxglib_fillrun.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /****************************************************************************
  2. * graphics/nxglib/nxsglib_fullrun.h
  3. *
  4. * Copyright (C) 2010 Gregory Nutt. All rights reserved.
  5. * Author: Gregory Nutt <gnutt@nuttx.org>
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in
  15. * the documentation and/or other materials provided with the
  16. * distribution.
  17. * 3. Neither the name NuttX nor the names of its contributors may be
  18. * used to endorse or promote products derived from this software
  19. * without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  27. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  28. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  29. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  31. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  32. * POSSIBILITY OF SUCH DAMAGE.
  33. *
  34. ****************************************************************************/
  35. #ifndef __GRAPHICS_NXGLIB_NXGLIB_FILLRUN_H
  36. #define __GRAPHICS_NXGLIB_NXGLIB_FILLRUN_H
  37. /****************************************************************************
  38. * Included Files
  39. ****************************************************************************/
  40. #include <nuttx/config.h>
  41. #include <stdint.h>
  42. #include <string.h>
  43. /****************************************************************************
  44. * Pre-Processor Definitions
  45. ****************************************************************************/
  46. #if NXGLIB_BITSPERPIXEL < 16
  47. # define NXGLIB_RUNTYPE uint8_t
  48. #elif NXGLIB_BITSPERPIXEL == 16
  49. # define NXGLIB_RUNTYPE uint16_t
  50. #else
  51. # define NXGLIB_RUNTYPE uint32_t
  52. #endif
  53. /****************************************************************************
  54. * Private Types
  55. ****************************************************************************/
  56. /****************************************************************************
  57. * Private Data
  58. ****************************************************************************/
  59. #if NXGLIB_BITSPERPIXEL == 2
  60. static uint8_t g_wide_2bpp[4] = { 0x00, 0x55, 0xaa, 0xff };
  61. #endif
  62. /****************************************************************************
  63. * Public Data
  64. ****************************************************************************/
  65. /****************************************************************************
  66. * Private Functions
  67. ****************************************************************************/
  68. /****************************************************************************
  69. * Public Functions
  70. ****************************************************************************/
  71. /****************************************************************************
  72. * Name: nxgl_fillrun_*bpp
  73. *
  74. * Description:
  75. * fill a run with the specified color.
  76. *
  77. ****************************************************************************/
  78. #if NXGLIB_BITSPERPIXEL == 1
  79. static inline void nxgl_fillrun_1bpp(FAR uint8_t *run, nxgl_mxpixel_t color,
  80. size_t npixels)
  81. {
  82. /* Get the number of bytes to fill */
  83. unsigned int nbytes = (npixels + 7) >> 3;
  84. /* Get the value of the byte to fill */
  85. uint8_t wide = (color & 1) != 0 ? 0xff : 0x00;
  86. /* Fill the run with the color (it is okay to run a fractional byte over
  87. * the end)
  88. */
  89. memset(run, wide, nbytes);
  90. }
  91. #elif NXGLIB_BITSPERPIXEL == 2
  92. static inline void nxgl_fillrun_2bpp(FAR uint8_t *run, nxgl_mxpixel_t color,
  93. size_t npixels)
  94. {
  95. /* Get the number of bytes to fill */
  96. unsigned int nbytes = (npixels + 3) >> 2;
  97. /* Get the value of the byte to fill */
  98. uint8_t wide = g_wide_2bpp[color & 3];
  99. /* Fill the run with the color (it is okay to run a fractional byte over
  100. * the end)
  101. */
  102. memset(run, wide, nbytes);
  103. }
  104. #elif NXGLIB_BITSPERPIXEL == 4
  105. static inline void nxgl_fillrun_4bpp(FAR uint8_t *run, nxgl_mxpixel_t color,
  106. size_t npixels)
  107. {
  108. /* Get the number of bytes to fill */
  109. unsigned int nbytes = (npixels + 1) >> 1;
  110. /* Get the value of the byte to fill */
  111. uint8_t narrow = (uint8_t)color & 0x0f;
  112. uint8_t wide = narrow | (narrow << 4);
  113. /* Fill the run with the color (it is okay to run a fractional byte over
  114. * the end)
  115. */
  116. memset(run, wide, nbytes);
  117. }
  118. #elif NXGLIB_BITSPERPIXEL == 8
  119. static inline void nxgl_fillrun_8bpp(FAR uint8_t *run, nxgl_mxpixel_t color,
  120. size_t npixels)
  121. {
  122. /* Fill the run with the color (it is okay to run a fractional byte overy the end */
  123. memset(run, color, npixels);
  124. }
  125. #elif NXGLIB_BITSPERPIXEL == 16
  126. static inline void nxgl_fillrun_16bpp(FAR uint16_t *run, nxgl_mxpixel_t color,
  127. size_t npixels)
  128. {
  129. /* Fill the run with the color (it is okay to run a fractional byte overy the end */
  130. while (npixels-- > 0)
  131. {
  132. *run++ = (uint16_t)color;
  133. }
  134. }
  135. #elif NXGLIB_BITSPERPIXEL == 24
  136. static inline void nxgl_fillrun_24bpp(FAR uint32_t *run, nxgl_mxpixel_t color, size_t npixels)
  137. {
  138. /* Fill the run with the color (it is okay to run a fractional byte overy the end */
  139. #warning "Assuming 24-bit color is not packed"
  140. while (npixels-- > 0)
  141. {
  142. *run++ = (uint32_t)color;
  143. }
  144. }
  145. #elif NXGLIB_BITSPERPIXEL == 32
  146. static inline void nxgl_fillrun_32bpp(FAR uint32_t *run, nxgl_mxpixel_t color, size_t npixels)
  147. {
  148. /* Fill the run with the color (it is okay to run a fractional byte overy the end */
  149. while (npixels-- > 0)
  150. {
  151. *run++ = (uint32_t)color;
  152. }
  153. }
  154. #else
  155. # error "Unsupported value of NXGLIB_BITSPERPIXEL"
  156. #endif
  157. #endif /* __GRAPHICS_NXGLIB_NXGLIB_FILLRUN_H */