crlepalettebitmap.hxx 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /****************************************************************************
  2. * apps/include/graphics/nxwidgets/crlepalettebitmap.hxx
  3. *
  4. * Licensed to the Apache Software Foundation (ASF) under one or more
  5. * contributor license agreements. See the NOTICE file distributed with
  6. * this work for additional information regarding copyright ownership. The
  7. * ASF licenses this file to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance with the
  9. * License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  16. * License for the specific language governing permissions and limitations
  17. * under the License.
  18. *
  19. ****************************************************************************/
  20. #ifndef __APPS_INCLUDE_GRAPHICS_NXWIDGETS_CRLEPALETTBITMAP_HXX
  21. #define __APPS_INCLUDE_GRAPHICS_NXWIDGETS_CRLEPALETTBITMAP_HXX
  22. /****************************************************************************
  23. * Included Files
  24. ****************************************************************************/
  25. #include <nuttx/config.h>
  26. #include <stdint.h>
  27. #include <stdbool.h>
  28. #include <nuttx/nx/nxglib.h>
  29. #include "graphics/nxwidgets/nxconfig.hxx"
  30. #include "graphics/nxwidgets/ibitmap.hxx"
  31. /****************************************************************************
  32. * Pre-Processor Definitions
  33. ****************************************************************************/
  34. /****************************************************************************
  35. * Implementation Classes
  36. ****************************************************************************/
  37. #if defined(__cplusplus)
  38. namespace NXWidgets
  39. {
  40. /**
  41. * One Run-Length Encoded (RLE) value
  42. */
  43. struct SRlePaletteBitmapEntry
  44. {
  45. uint8_t npixels; /**< Number of pixels */
  46. uint8_t lookup; /**< Pixel RGB lookup index */
  47. };
  48. /**
  49. * Run-Length Encoded (RLE), Paletted Bitmap Structure
  50. */
  51. struct SRlePaletteBitmap
  52. {
  53. uint8_t bpp; /**< Bits per pixel */
  54. uint8_t fmt; /**< Color format */
  55. uint8_t nlut; /**< Number of colors in the Look-Up Table (LUT) */
  56. nxgl_coord_t width; /**< Width in pixels */
  57. nxgl_coord_t height; /**< Height in rows */
  58. FAR const void *lut[2]; /**< Pointers to the beginning of the Look-Up Tables (LUTs) */
  59. /**
  60. * The pointer to the beginning of the RLE data
  61. */
  62. FAR const struct SRlePaletteBitmapEntry *data;
  63. };
  64. /**
  65. * Class providing bitmap accessor for a bitmap represented by SRlePaletteBitmap.
  66. */
  67. class CRlePaletteBitmap : public IBitmap
  68. {
  69. protected:
  70. /**
  71. * The bitmap that is being managed
  72. */
  73. FAR const struct SRlePaletteBitmap *m_bitmap; /**< The bitmap that is being managed */
  74. /**
  75. * Accessor state data
  76. */
  77. nxgl_coord_t m_row; /**< Logical row number */
  78. nxgl_coord_t m_col; /**< Logical column number */
  79. uint8_t m_remaining; /**< Number of bytes remaining in current entry */
  80. FAR const void *m_lut; /**< The selected LUT */
  81. FAR const struct SRlePaletteBitmapEntry *m_rle; /**< RLE entry being processed */
  82. /**
  83. * Reset to the beginning of the image
  84. */
  85. void startOfImage(void);
  86. /**
  87. * Advance position data ahead. Called after npixels have
  88. * have been consume.
  89. *
  90. * @param npixels The number of pixels to advance
  91. * @return False if this goes beyond the end of the image
  92. */
  93. bool advancePosition(nxgl_coord_t npixels);
  94. /**
  95. * Seek ahead the specific number of pixels -- discarding
  96. * and advancing.
  97. *
  98. * @param npixels The number of pixels to skip
  99. * @return False if this goes beyond the end of the image
  100. */
  101. bool skipPixels(nxgl_coord_t npixels);
  102. /** Seek to the beginning of the next row
  103. *
  104. * @return False if this was the last row of the image
  105. */
  106. bool nextRow(void);
  107. /** Seek to the beignning specific row
  108. *
  109. * @param row The row number to seek to
  110. * @return False if this goes beyond the end of the image
  111. */
  112. bool seekRow(nxgl_coord_t row);
  113. /** Copy the pixels from the current RLE entry the specified number of times.
  114. *
  115. * @param npixels The number of pixels to copy. Must be less than or equal
  116. * to m_remaining.
  117. * @param data The memory location provided by the caller
  118. * in which to return the data. This should be at least
  119. * (getWidth()*getBitsPerPixl() + 7)/8 bytes in length
  120. * and properly aligned for the pixel color format.
  121. */
  122. void copyColor(nxgl_coord_t npixels, FAR void *data);
  123. /** Copy pixels from the current position
  124. *
  125. * @param npixels The number of pixels to copy
  126. * @param data The memory location provided by the caller
  127. * in which to return the data. This should be at least
  128. * (getWidth()*getBitsPerPixl() + 7)/8 bytes in length
  129. * and properly aligned for the pixel color format.
  130. * @return False if this goes beyond the end of the image
  131. */
  132. bool copyPixels(nxgl_coord_t npixels, FAR void *data);
  133. public:
  134. /**
  135. * Constructor.
  136. *
  137. * @param bitmap The bitmap structure being wrapped.
  138. */
  139. CRlePaletteBitmap(const struct SRlePaletteBitmap *bitmap);
  140. /**
  141. * Destructor.
  142. */
  143. inline ~CRlePaletteBitmap(void) {}
  144. /**
  145. * Get the bitmap's color format.
  146. *
  147. * @return The bitmap's width.
  148. */
  149. const uint8_t getColorFormat(void) const;
  150. /**
  151. * Get the bitmap's color format.
  152. *
  153. * @return The bitmap's color format.
  154. */
  155. const uint8_t getBitsPerPixel(void) const;
  156. /**
  157. * Get the bitmap's width (in pixels/columns).
  158. *
  159. * @return The bitmap's pixel depth.
  160. */
  161. const nxgl_coord_t getWidth(void) const;
  162. /**
  163. * Get the bitmap's height (in rows).
  164. *
  165. * @return The bitmap's height.
  166. */
  167. const nxgl_coord_t getHeight(void) const;
  168. /**
  169. * Get the bitmap's width (in bytes).
  170. *
  171. * @return The bitmap's width.
  172. */
  173. const size_t getStride(void) const;
  174. /**
  175. * Use the colors associated with a selected image.
  176. *
  177. * @param selected. true: Use colors for a selected widget,
  178. * false: Use normal (default) colors.
  179. */
  180. void setSelected(bool selected);
  181. /**
  182. * Get one row from the bit map image using the selected colors.
  183. *
  184. * @param x The offset into the row to get
  185. * @param y The row number to get
  186. * @param width The number of pixels to get from the row
  187. * @param data The memory location provided by the caller
  188. * in which to return the data. This should be at least
  189. * (getWidth()*getBitsPerPixl() + 7)/8 bytes in length
  190. * and properly aligned for the pixel color format.
  191. * @param True if the run was returned successfully.
  192. */
  193. bool getRun(nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t width,
  194. FAR void *data);
  195. };
  196. }
  197. #endif // __cplusplus
  198. #endif // __APPS_INCLUDE_GRAPHICS_NXWIDGETS_CRLEPALETTBITMAP_HXX