cbitmap.hxx 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /****************************************************************************
  2. * apps/include/graphics/nxwidgets/cbitmap.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. /****************************************************************************
  21. * Portions of this package derive from Woopsi (http://woopsi.org/) and
  22. * portions are original efforts. It is difficult to determine at this
  23. * point what parts are original efforts and which parts derive from Woopsi.
  24. * However, in any event, the work of Antony Dzeryn will be acknowledged
  25. * in all NxWidget files. Thanks Antony!
  26. *
  27. * Copyright (c) 2007-2011, Antony Dzeryn
  28. * All rights reserved.
  29. *
  30. * Redistribution and use in source and binary forms, with or without
  31. * modification, are permitted provided that the following conditions are met:
  32. *
  33. * * Redistributions of source code must retain the above copyright
  34. * notice, this list of conditions and the following disclaimer.
  35. * * Redistributions in binary form must reproduce the above copyright
  36. * notice, this list of conditions and the following disclaimer in the
  37. * documentation and/or other materials provided with the distribution.
  38. * * Neither the names "Woopsi", "Simian Zombie" nor the
  39. * names of its contributors may be used to endorse or promote products
  40. * derived from this software without specific prior written permission.
  41. *
  42. * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY
  43. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  44. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  45. * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY
  46. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  47. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  48. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  49. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  50. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  51. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  52. *
  53. ****************************************************************************/
  54. #ifndef __APPS_INCLUDE_GRAPHICS_NXWIDGETS_CBITMAP_HXX
  55. #define __APPS_INCLUDE_GRAPHICS_NXWIDGETS_CBITMAP_HXX
  56. /****************************************************************************
  57. * Included Files
  58. ****************************************************************************/
  59. #include <nuttx/config.h>
  60. #include <stdint.h>
  61. #include <stdbool.h>
  62. #include <nuttx/nx/nxglib.h>
  63. #include "graphics/nxwidgets/nxconfig.hxx"
  64. #include "graphics/nxwidgets/ibitmap.hxx"
  65. /****************************************************************************
  66. * Pre-Processor Definitions
  67. ****************************************************************************/
  68. /****************************************************************************
  69. * Implementation Classes
  70. ****************************************************************************/
  71. #if defined(__cplusplus)
  72. namespace NXWidgets
  73. {
  74. /**
  75. * Bitmap Structure
  76. */
  77. struct SBitmap
  78. {
  79. uint8_t bpp; /**< Bits per pixel */
  80. uint8_t fmt; /**< Color format */
  81. nxgl_coord_t width; /**< Width in pixels */
  82. nxgl_coord_t height; /**< Height in rows */
  83. uint16_t stride; /**< Width in bytes */
  84. FAR const void *data; /**< Pointer to the beginning of pixel data */
  85. };
  86. /**
  87. * Class providing bitmap accessor for a bitmap represented by SBitmap.
  88. */
  89. class CBitmap : public IBitmap
  90. {
  91. protected:
  92. const struct SBitmap *m_bitmap; /**< The bitmap that is being managed */
  93. /**
  94. * Copy constructor is protected to prevent usage.
  95. */
  96. inline CBitmap(const CBitmap &bitmap) { }
  97. public:
  98. /**
  99. * Constructor.
  100. *
  101. * @param bitmap The bitmap structure being wrapped.
  102. */
  103. CBitmap(const struct SBitmap *bitmap);
  104. /**
  105. * Destructor.
  106. */
  107. inline ~CBitmap(void) {}
  108. /**
  109. * Get the bitmap's color format.
  110. *
  111. * @return The bitmap's width.
  112. */
  113. const uint8_t getColorFormat(void) const;
  114. /**
  115. * Get the bitmap's color format.
  116. *
  117. * @return The bitmap's color format.
  118. */
  119. const uint8_t getBitsPerPixel(void) const;
  120. /**
  121. * Get the bitmap's width (in pixels/columns).
  122. *
  123. * @return The bitmap's pixel depth.
  124. */
  125. const nxgl_coord_t getWidth(void) const;
  126. /**
  127. * Get the bitmap's height (in rows).
  128. *
  129. * @return The bitmap's height.
  130. */
  131. const nxgl_coord_t getHeight(void) const;
  132. /**
  133. * Get the bitmap's width (in bytes).
  134. *
  135. * @return The bitmap's width.
  136. */
  137. const size_t getStride(void) const;
  138. /**
  139. * Use the colors associated with a selected image.
  140. *
  141. * @param selected. true: Use colors for a selected widget,
  142. * false: Use normal (default) colors.
  143. */
  144. inline void setSelected(bool selected) {}
  145. /**
  146. * Get one row from the bit map image.
  147. *
  148. * @param x The offset into the row to get
  149. * @param y The row number to get
  150. * @param width The number of pixels to get from the row
  151. * @param data The memory location provided by the caller
  152. * in which to return the data. This should be at least
  153. * (getWidth()*getBitsPerPixl() + 7)/8 bytes in length
  154. * and properly aligned for the pixel color format.
  155. * @param True if the run was returned successfully.
  156. */
  157. bool getRun(nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t width,
  158. FAR void *data);
  159. };
  160. }
  161. #endif // __cplusplus
  162. #endif // __APPS_INCLUDE_GRAPHICS_NXWIDGETS_CBITMAP_HXX