NXWidgets  1.19
cscaledbitmap.hxx
Go to the documentation of this file.
1 /****************************************************************************
2  * NxWidgets/libnxwidgets/include/cscaledbitmap.hxx
3  *
4  * Copyright (C) 2013-2014 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 #ifndef __INCLUDE_CSCALEDBITMAP_HXX
37 #define __INCLUDE_CSCALEDBITMAP_HXX
38 
39 /****************************************************************************
40  * Included Files
41  ****************************************************************************/
42 
43 #include <nuttx/config.h>
44 
45 #include <stdint.h>
46 #include <stdbool.h>
47 #include <fixedmath.h>
48 #include <debug.h>
49 
50 #include <nuttx/video/rgbcolors.h>
51 #include <nuttx/nx/nxglib.h>
52 
53 #include "nxconfig.hxx"
54 #include "ibitmap.hxx"
55 
56 /****************************************************************************
57  * Pre-Processor Definitions
58  ****************************************************************************/
59 
60 /****************************************************************************
61  * Implementation Classes
62  ****************************************************************************/
63 
64 #if defined(__cplusplus)
65 
66 namespace NXWidgets
67 {
68  /**
69  * Class for scaling layer for any bitmap that inherits from IBitMap
70  */
71 
72  class CScaledBitmap : public IBitmap
73  {
74  protected:
75  FAR IBitmap *m_bitmap; /**< The bitmap that is being scaled */
76  struct nxgl_size_s m_size; /**< Scaled size of the image */
77  FAR uint8_t *m_rowCache[2]; /**< Two cached rows of the image */
78  unsigned int m_row; /**< Row number of the first cached row */
79  b16_t m_xScale; /**< X scale factor */
80  b16_t m_yScale; /**< Y scale factor */
81 
82  /**
83  * Read two rows into the row cache
84  *
85  * @param row - The row number of the first row to cache
86  */
87 
88  bool cacheRows(unsigned int row);
89 
90  /**
91  * Given an two RGB colors and a fractional value, return the scaled
92  * value between the two colors.
93  *
94  * @param incolor1 - The first color to be used
95  * @param incolor2 - The second color to be used
96  * @param fraction - The fractional value
97  * @param outcolor - The returned, scaled color
98  */
99 
100  bool scaleColor(FAR const struct rgbcolor_s &incolor1,
101  FAR const struct rgbcolor_s &incolor2,
102  b16_t fraction, FAR struct rgbcolor_s &outcolor);
103 
104  /**
105  * Given an image row and a non-integer column offset, return the
106  * interpolated RGB color value corresponding to that position
107  *
108  * @param row - The pointer to the row in the row cache to use
109  * @param column - The non-integer column offset
110  * @param outcolor - The returned, interpolated color
111  *
112  */
113 
114  bool rowColor(FAR uint8_t *row, b16_t column,
115  FAR struct rgbcolor_s &outcolor);
116 
117  /**
118  * Copy constructor is protected to prevent usage.
119  */
120 
121  inline CScaledBitmap(const CScaledBitmap &bitmap) { }
122 
123  public:
124 
125  /**
126  * Constructor.
127  *
128  * @param bitmap The bitmap structure being scaled.
129  * @newSize The new, scaled size of the image
130  */
131 
132  CScaledBitmap(IBitmap *bitmap, struct nxgl_size_s &newSize);
133 
134  /**
135  * Destructor.
136  */
137 
138  ~CScaledBitmap(void);
139 
140  /**
141  * Get the bitmap's color format.
142  *
143  * @return The bitmap's color format.
144  */
145 
146  const uint8_t getColorFormat(void) const;
147 
148  /**
149  * Get the bitmap's color format.
150  *
151  * @return The bitmap's pixel depth.
152  */
153 
154  const uint8_t getBitsPerPixel(void) const;
155 
156  /**
157  * Get the bitmap's width (in pixels/columns).
158  *
159  * @return The bitmap's width (in pixels/columns).
160  */
161 
162  const nxgl_coord_t getWidth(void) const;
163 
164  /**
165  * Get the bitmap's height (in rows).
166  *
167  * @return The bitmap's height (in rows).
168  */
169 
170  const nxgl_coord_t getHeight(void) const;
171 
172  /**
173  * Get the bitmap's width (in bytes).
174  *
175  * @return The bitmap's width (in bytes).
176  */
177 
178  const size_t getStride(void) const;
179 
180  /**
181  * Use the colors associated with a selected image.
182  *
183  * @param selected. true: Use colors for a selected widget,
184  * false: Use normal (default) colors.
185  */
186 
187  inline void setSelected(bool selected) {}
188 
189  /**
190  * Get one row from the bit map image.
191  *
192  * @param x The offset into the row to get
193  * @param y The row number to get
194  * @param width The number of pixels to get from the row
195  * @param data The memory location provided by the caller
196  * in which to return the data. This should be at least
197  * (getWidth()*getBitsPerPixl() + 7)/8 bytes in length
198  * and properly aligned for the pixel color format.
199  * @param True if the run was returned successfully.
200  */
201 
202  bool getRun(nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t width,
203  FAR void *data);
204  };
205 }
206 
207 #endif // __cplusplus
208 
209 #endif // __INCLUDE_CSCALEDBITMAP_HXX
bool getRun(nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t width, FAR void *data)
const uint8_t getBitsPerPixel(void) const
bool cacheRows(unsigned int row)
const uint8_t getColorFormat(void) const
FAR uint8_t * m_rowCache[2]
bool rowColor(FAR uint8_t *row, b16_t column, FAR struct rgbcolor_s &outcolor)
CScaledBitmap(const CScaledBitmap &bitmap)
const nxgl_coord_t getWidth(void) const
const size_t getStride(void) const
static const NXWidgets::SRlePaletteBitmapEntry bitmap[]
void setSelected(bool selected)
const nxgl_coord_t getHeight(void) const
bool scaleColor(FAR const struct rgbcolor_s &incolor1, FAR const struct rgbcolor_s &incolor2, b16_t fraction, FAR struct rgbcolor_s &outcolor)
struct nxgl_size_s m_size