NXWidgets: crlepalettebitmap.hxx Source File

NXWidgets 1.19

crlepalettebitmap.hxx
Go to the documentation of this file.
1 /****************************************************************************
2 * NxWidgets/libnxwidgets/include/crlepalettebitmap.hxx
3 *
4 * Copyright (C) 2012 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, NxWidgets, nor the names of its contributors
18 * me be 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
37 #ifndef __INCLUDE_CRLEPALETTBITMAP_HXX
38 #define __INCLUDE_CRLEPALETTBITMAP_HXX
39
40 /****************************************************************************
41 * Included Files
42 ****************************************************************************/
43
44 #include <nuttx/config.h>
45
46 #include <stdint.h>
47 #include <stdbool.h>
48
49 #include <nuttx/nx/nxglib.h>
50
51 #include "nxconfig.hxx"
52 #include "ibitmap.hxx"
53
54 /****************************************************************************
55 * Pre-Processor Definitions
56 ****************************************************************************/
57
58 /****************************************************************************
59 * Implementation Classes
60 ****************************************************************************/
61
62 #if defined(__cplusplus)
63
64 namespace NXWidgets
65 {
66 /**
67 * One Run-Length Encoded (RLE) value
68 */
69
70 struct SRlePaletteBitmapEntry
71 {
72 uint8_t npixels; /**< Number of pixels */
73 uint8_t lookup; /**< Pixel RGB lookup index */
74 };
75
76 /**
77 * Run-Length Encoded (RLE), Paletted Bitmap Structure
78 */
79
80 struct SRlePaletteBitmap
81 {
82 uint8_t bpp; /**< Bits per pixel */
83 uint8_t fmt; /**< Color format */
84 uint8_t nlut; /**< Number of colors in the Look-Up Table (LUT) */
85 nxgl_coord_t width; /**< Width in pixels */
86 nxgl_coord_t height; /**< Height in rows */
87 FAR const void *lut[2]; /**< Pointers to the beginning of the Look-Up Tables (LUTs) */
88
89 /**
90 * The pointer to the beginning of the RLE data
91 */
92
93 FAR const struct SRlePaletteBitmapEntry *data;
94 };
95
96 /**
97 * Class providing bitmap accessor for a bitmap represented by SRlePaletteBitmap.
98 */
99
100 class CRlePaletteBitmap : public IBitmap
101 {
102 protected:
103 /**
104 * The bitmap that is being managed
105 */
106
107 FAR const struct SRlePaletteBitmap *m_bitmap; /**< The bitmap that is being managed */
108
109 /**
110 * Accessor state data
111 */
112
113 nxgl_coord_t m_row; /**< Logical row number */
114 nxgl_coord_t m_col; /**< Logical column number */
115 uint8_t m_remaining; /**< Number of bytes remaining in current entry */
116 FAR const void *m_lut; /**< The selected LUT */
117 FAR const struct SRlePaletteBitmapEntry *m_rle; /**< RLE entry being processed */
118
119 /**
120 * Reset to the beginning of the image
121 */
122
123 void startOfImage(void);
124
125 /**
126 * Advance position data ahead. Called after npixels have
127 * have been consume.
128 *
129 * @param npixels The number of pixels to advance
130 * @return False if this goes beyond the end of the image
131 */
132
133 bool advancePosition(nxgl_coord_t npixels);
134
135 /**
136 * Seek ahead the specific number of pixels -- discarding
137 * and advancing.
138 *
139 * @param npixels The number of pixels to skip
140 * @return False if this goes beyond the end of the image
141 */
142
143 bool skipPixels(nxgl_coord_t npixels);
144
145 /** Seek to the beginning of the next row
146 *
147 * @return False if this was the last row of the image
148 */
149
150 bool nextRow(void);
151
152 /** Seek to the beignning specific row
153 *
154 * @param row The row number to seek to
155 * @return False if this goes beyond the end of the image
156 */
157
158 bool seekRow(nxgl_coord_t row);
159
160 /** Copy the pixels from the current RLE entry the specified number of times.
161 *
162 * @param npixels The number of pixels to copy. Must be less than or equal
163 * to m_remaining.
164 * @param data The memory location provided by the caller
165 * in which to return the data. This should be at least
166 * (getWidth()*getBitsPerPixl() + 7)/8 bytes in length
167 * and properly aligned for the pixel color format.
168 */
169
170 void copyColor(nxgl_coord_t npixels, FAR void *data);
171
172 /** Copy pixels from the current position
173 *
174 * @param npixels The number of pixels to copy
175 * @param data The memory location provided by the caller
176 * in which to return the data. This should be at least
177 * (getWidth()*getBitsPerPixl() + 7)/8 bytes in length
178 * and properly aligned for the pixel color format.
179 * @return False if this goes beyond the end of the image
180 */
181
182 bool copyPixels(nxgl_coord_t npixels, FAR void *data);
183
184 public:
185
186 /**
187 * Constructor.
188 *
189 * @param bitmap The bitmap structure being wrapped.
190 */
191
192 CRlePaletteBitmap(const struct SRlePaletteBitmap *bitmap);
193
194 /**
195 * Destructor.
196 */
197
198 inline ~CRlePaletteBitmap(void) {}
199
200 /**
201 * Get the bitmap's color format.
202 *
203 * @return The bitmap's width.
204 */
205
206 const uint8_t getColorFormat(void) const;
207
208 /**
209 * Get the bitmap's color format.
210 *
211 * @return The bitmap's color format.
212 */
213
214 const uint8_t getBitsPerPixel(void) const;
215
216 /**
217 * Get the bitmap's width (in pixels/columns).
218 *
219 * @return The bitmap's pixel depth.
220 */
221
222 const nxgl_coord_t getWidth(void) const;
223
224 /**
225 * Get the bitmap's height (in rows).
226 *
227 * @return The bitmap's height.
228 */
229
230 const nxgl_coord_t getHeight(void) const;
231
232 /**
233 * Get the bitmap's width (in bytes).
234 *
235 * @return The bitmap's width.
236 */
237
238 const size_t getStride(void) const;
239
240 /**
241 * Use the colors associated with a selected image.
242 *
243 * @param selected. true: Use colors for a selected widget,
244 * false: Use normal (default) colors.
245 */
246
247 void setSelected(bool selected);
248
249 /**
250 * Get one row from the bit map image using the selected colors.
251 *
252 * @param x The offset into the row to get
253 * @param y The row number to get
254 * @param width The number of pixels to get from the row
255 * @param data The memory location provided by the caller
256 * in which to return the data. This should be at least
257 * (getWidth()*getBitsPerPixl() + 7)/8 bytes in length
258 * and properly aligned for the pixel color format.
259 * @param True if the run was returned successfully.
260 */
261
262 bool getRun(nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t width,
263 FAR void *data);
264 };
265 }
266
267 #endif // __cplusplus
268
269 #endif // __INCLUDE_CRLEPALETTBITMAP_HXX
NXWidgets::SRlePaletteBitmap::bpp
uint8_t bpp
Definition: crlepalettebitmap.hxx:82
NXWidgets::CRlePaletteBitmap::m_remaining
uint8_t m_remaining
Definition: crlepalettebitmap.hxx:115
ibitmap.hxx
NXWidgets::SRlePaletteBitmapEntry
Definition: crlepalettebitmap.hxx:70
NXWidgets::CRlePaletteBitmap::m_row
nxgl_coord_t m_row
Definition: crlepalettebitmap.hxx:113
NXWidgets::CRlePaletteBitmap::m_lut
FAR const void * m_lut
Definition: crlepalettebitmap.hxx:116
NXWidgets::SRlePaletteBitmapEntry::npixels
uint8_t npixels
Definition: crlepalettebitmap.hxx:72
NXWidgets::CRlePaletteBitmap
Definition: crlepalettebitmap.hxx:100
NXWidgets::SRlePaletteBitmapEntry::lookup
uint8_t lookup
Definition: crlepalettebitmap.hxx:73
NXWidgets::CRlePaletteBitmap::m_bitmap
FAR const struct SRlePaletteBitmap * m_bitmap
Definition: crlepalettebitmap.hxx:107
NXWidgets::SRlePaletteBitmap::width
nxgl_coord_t width
Definition: crlepalettebitmap.hxx:85
NXWidgets::CRlePaletteBitmap::m_rle
FAR const struct SRlePaletteBitmapEntry * m_rle
Definition: crlepalettebitmap.hxx:117
NXWidgets::SRlePaletteBitmap::nlut
uint8_t nlut
Definition: crlepalettebitmap.hxx:84
NXWidgets
Definition: cbgwindow.hxx:65
NXWidgets::SRlePaletteBitmap::fmt
uint8_t fmt
Definition: crlepalettebitmap.hxx:83
NXWidgets::SRlePaletteBitmap::data
FAR const struct SRlePaletteBitmapEntry * data
Definition: crlepalettebitmap.hxx:93
nxconfig.hxx
NXWidgets::SRlePaletteBitmap::height
nxgl_coord_t height
Definition: crlepalettebitmap.hxx:86
NXWidgets::CRlePaletteBitmap::m_col
nxgl_coord_t m_col
Definition: crlepalettebitmap.hxx:114
NXWidgets::CRlePaletteBitmap::~CRlePaletteBitmap
~CRlePaletteBitmap(void)
Definition: crlepalettebitmap.hxx:198
NXWidgets::SRlePaletteBitmap
Definition: crlepalettebitmap.hxx:80
bitmap
static const NXWidgets::SRlePaletteBitmapEntry bitmap[]
Definition: glyph_mediaplayer24x24.cxx:85
NXWidgets::IBitmap
Definition: ibitmap.hxx:103