NXWidgets: cbitmap.cxx Source File

NXWidgets 1.19

cbitmap.cxx
Go to the documentation of this file.
1 /****************************************************************************
2 * NxWidgets/libnxwidgets/src/cbitmap.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 * Portions of this package derive from Woopsi (http://woopsi.org/) and
37 * portions are original efforts. It is difficult to determine at this
38 * point what parts are original efforts and which parts derive from Woopsi.
39 * However, in any event, the work of Antony Dzeryn will be acknowledged
40 * in most NxWidget files. Thanks Antony!
41 *
42 * Copyright (c) 2007-2011, Antony Dzeryn
43 * All rights reserved.
44 *
45 * Redistribution and use in source and binary forms, with or without
46 * modification, are permitted provided that the following conditions are met:
47 *
48 * * Redistributions of source code must retain the above copyright
49 * notice, this list of conditions and the following disclaimer.
50 * * Redistributions in binary form must reproduce the above copyright
51 * notice, this list of conditions and the following disclaimer in the
52 * documentation and/or other materials provided with the distribution.
53 * * Neither the names "Woopsi", "Simian Zombie" nor the
54 * names of its contributors may be used to endorse or promote products
55 * derived from this software without specific prior written permission.
56 *
57 * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY
58 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
59 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
60 * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY
61 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
62 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
63 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
64 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
65 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
66 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
67 *
68 ****************************************************************************/
69
70 /****************************************************************************
71 * Included Files
72 ****************************************************************************/
73
74 #include <nuttx/config.h>
75
76 #include <stdint.h>
77 #include <stdbool.h>
78 #include <cstring>
79
80 #include <nuttx/nx/nxglib.h>
81
82 #include "cbitmap.hxx"
83
84 /****************************************************************************
85 * Pre-Processor Definitions
86 ****************************************************************************/
87
88 /****************************************************************************
89 * Method Implementations
90 ****************************************************************************/
91
92 using namespace NXWidgets;
93
94 /**
95 * Constructor.
96 *
97 * @param bitmap The bitmap structure being wrapped.
98 */
99
100 CBitmap::CBitmap(const struct SBitmap *bitmap) : m_bitmap(bitmap) {}
101
102 /**
103 * Get the bitmap's color format.
104 *
105 * @return The bitmap's width.
106 */
107
108 const uint8_t CBitmap::getColorFormat(void) const
109 {
110 return m_bitmap->fmt;
111 }
112
113 /**
114 * Get the bitmap's color format.
115 *
116 * @return The bitmap's color format.
117 */
118
119 const uint8_t CBitmap::getBitsPerPixel(void) const
120 {
121 return m_bitmap->bpp;
122 }
123
124 /**
125 * Get the bitmap's width (in pixels/columns).
126 *
127 * @return The bitmap's pixel depth.
128 */
129
130 const nxgl_coord_t CBitmap::getWidth(void) const
131 {
132 return m_bitmap->width;
133 }
134
135 /**
136 * Get the bitmap's height (in rows).
137 *
138 * @return The bitmap's height.
139 */
140
141 const nxgl_coord_t CBitmap::getHeight(void) const
142 {
143 return m_bitmap->height;
144 }
145
146 /**
147 * Get the bitmap's width (in bytes).
148 *
149 * @return The bitmap's width.
150 */
151
152 const size_t CBitmap::getStride(void) const
153 {
154 return m_bitmap->stride;
155 }
156
157 /**
158 * Get one row from the bit map image.
159 *
160 * @param x The offset into the row to get
161 * @param y The row number to get
162 * @param width The number of pixels to get from the row
163 * @param data The memory location provided by the caller
164 * in which to return the data. This should be at least
165 * (getWidth()*getBitsPerPixl() + 7)/8 bytes in length
166 * and properly aligned for the pixel color format.
167 * @param True if the run was returned successfully.
168 */
169
170 bool CBitmap::getRun(nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t width,
171 FAR void *data)
172 {
173 // Check ranges. Casts to unsigned int are ugly but permit one-sided comparisons
174
175 if (((unsigned int)x < (unsigned int)m_bitmap->width) &&
176 ((unsigned int)(x + width) <= (unsigned int)m_bitmap->width) &&
177 ((unsigned int)y < (unsigned int)m_bitmap->height))
178 {
179 // Get starting position of the copy (this will only work if bpp
180 // is an even multiple of bytes).
181
182 FAR uint8_t *start = (FAR uint8_t*)m_bitmap->data +
183 y * m_bitmap->stride +
184 ((x * m_bitmap->bpp) >> 3);
185
186 // Get the number of bytes to copy.
187
188 unsigned int length = (width * m_bitmap->bpp) >> 3;
189
190 // And do the copy
191
192 memcpy(data, start, length);
193 return true;
194 }
195
196 return false;
197 }
NXWidgets::CBitmap::getRun
bool getRun(nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t width, FAR void *data)
Definition: cbitmap.cxx:170
NXWidgets::SBitmap::fmt
uint8_t fmt
Definition: cbitmap.hxx:106
NXWidgets::CBitmap::getStride
const size_t getStride(void) const
Definition: cbitmap.cxx:152
NXWidgets::CBitmap::getColorFormat
const uint8_t getColorFormat(void) const
Definition: cbitmap.cxx:108
NXWidgets
Definition: cbgwindow.hxx:65
NXWidgets::CBitmap::getWidth
const nxgl_coord_t getWidth(void) const
Definition: cbitmap.cxx:130
NXWidgets::CBitmap::m_bitmap
const struct SBitmap * m_bitmap
Definition: cbitmap.hxx:120
NXWidgets::SBitmap::bpp
uint8_t bpp
Definition: cbitmap.hxx:105
NXWidgets::CBitmap::getHeight
const nxgl_coord_t getHeight(void) const
Definition: cbitmap.cxx:141
NXWidgets::SBitmap::height
nxgl_coord_t height
Definition: cbitmap.hxx:108
NXWidgets::SBitmap::data
FAR const void * data
Definition: cbitmap.hxx:110
NXWidgets::SBitmap::width
nxgl_coord_t width
Definition: cbitmap.hxx:107
NXWidgets::CBitmap::getBitsPerPixel
const uint8_t getBitsPerPixel(void) const
Definition: cbitmap.cxx:119
cbitmap.hxx
NXWidgets::SBitmap
Definition: cbitmap.hxx:103
NXWidgets::CBitmap::CBitmap
CBitmap(const CBitmap &bitmap)
Definition: cbitmap.hxx:126
bitmap
static const NXWidgets::SRlePaletteBitmapEntry bitmap[]
Definition: glyph_mediaplayer24x24.cxx:85
NXWidgets::SBitmap::stride
uint16_t stride
Definition: cbitmap.hxx:109