nxglib_fillrectangle.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /****************************************************************************
  2. * graphics/nxglib/fb/nxglib_fillrectangle.c
  3. *
  4. * Copyright (C) 2008-2011 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. /****************************************************************************
  36. * Included Files
  37. ****************************************************************************/
  38. #include <nuttx/config.h>
  39. #include <stdint.h>
  40. #include <nuttx/video/fb.h>
  41. #include <nuttx/nx/nxglib.h>
  42. #include "nxglib_bitblit.h"
  43. /****************************************************************************
  44. * Pre-processor Definitions
  45. ****************************************************************************/
  46. #ifndef NXGLIB_SUFFIX
  47. # error "NXGLIB_SUFFIX must be defined before including this header file"
  48. #endif
  49. /****************************************************************************
  50. * Public Functions
  51. ****************************************************************************/
  52. /****************************************************************************
  53. * Name: nxgl_fillrectangle_*bpp
  54. *
  55. * Descripton:
  56. * Fill a rectangle region in the framebuffer memory with a fixed color
  57. *
  58. ****************************************************************************/
  59. void NXGL_FUNCNAME(nxgl_fillrectangle, NXGLIB_SUFFIX)
  60. (FAR struct fb_planeinfo_s *pinfo,
  61. FAR const struct nxgl_rect_s *rect,
  62. NXGL_PIXEL_T color)
  63. {
  64. FAR uint8_t *line;
  65. unsigned int width;
  66. unsigned int stride;
  67. int rows;
  68. #if NXGLIB_BITSPERPIXEL < 8
  69. FAR uint8_t *dest;
  70. uint8_t mpixel = NXGL_MULTIPIXEL(color);
  71. uint8_t leadmask;
  72. uint8_t tailmask;
  73. uint8_t mask;
  74. int lnlen;
  75. #endif
  76. /* Get the width of the framebuffer in bytes */
  77. stride = pinfo->stride;
  78. /* Get the dimensions of the rectange to fill in pixels */
  79. width = rect->pt2.x - rect->pt1.x + 1;
  80. rows = rect->pt2.y - rect->pt1.y + 1;
  81. /* Get the address of the first byte in the first line to write */
  82. line = pinfo->fbmem + rect->pt1.y * stride + NXGL_SCALEX(rect->pt1.x);
  83. #if NXGLIB_BITSPERPIXEL < 8
  84. # ifdef CONFIG_NX_PACKEDMSFIRST
  85. /* Get the mask for pixels that are ordered so that they pack from the
  86. * MS byte down.
  87. */
  88. leadmask = (uint8_t)(0xff >> (8 - NXGL_REMAINDERX(rect->pt1.x)));
  89. tailmask = (uint8_t)(0xff << (8 - NXGL_REMAINDERX(rect->pt2.x-1)));
  90. # else
  91. /* Get the mask for pixels that are ordered so that they pack from the
  92. * LS byte up.
  93. */
  94. leadmask = (uint8_t)(0xff << (8 - NXGL_REMAINDERX(rect->pt1.x)));
  95. tailmask = (uint8_t)(0xff >> (8 - NXGL_REMAINDERX(rect->pt1.x-1)));
  96. # endif
  97. #endif
  98. /* Then fill the rectangle line-by-line */
  99. while (rows-- > 0)
  100. {
  101. #if NXGLIB_BITSPERPIXEL < 8
  102. /* Handle masking of the fractional initial byte */
  103. mask = leadmask;
  104. dest = line;
  105. lnlen = width;
  106. if (lnlen > 1 && mask)
  107. {
  108. dest[0] = (dest[0] & ~mask) | (mpixel & mask);
  109. mask = 0xff;
  110. dest++;
  111. lnlen--;
  112. }
  113. /* Handle masking of the fractional final byte */
  114. mask &= tailmask;
  115. if (lnlen > 0 && mask)
  116. {
  117. dest[lnlen-1] = (dest[lnlen-1] & ~mask) | (mpixel & mask);
  118. lnlen--;
  119. }
  120. /* Handle all of the unmasked bytes in-between */
  121. if (lnlen > 0)
  122. {
  123. NXGL_MEMSET(dest, (NXGL_PIXEL_T)color, lnlen);
  124. }
  125. #else
  126. /* Draw the entire raster line */
  127. NXGL_MEMSET(line, (NXGL_PIXEL_T)color, width);
  128. #endif
  129. line += stride;
  130. }
  131. }