gem5  v21.1.0.2
pixel.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 ARM Limited
3  * All rights reserved
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions are
16  * met: redistributions of source code must retain the above copyright
17  * notice, this list of conditions and the following disclaimer;
18  * redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in the
20  * documentation and/or other materials provided with the distribution;
21  * neither the name of the copyright holders nor the names of its
22  * contributors may be used to endorse or promote products derived from
23  * this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  */
37 
38 #ifndef __BASE_PIXEL_HH__
39 #define __BASE_PIXEL_HH__
40 
41 #include <cmath>
42 #include <cstdint>
43 #include <string>
44 #include <vector>
45 
46 #include "base/compiler.hh"
47 #include "base/cprintf.hh"
48 #include "base/str.hh"
49 #include "base/types.hh"
50 #include "sim/byteswap.hh"
51 
52 namespace gem5
53 {
54 
58 struct Pixel
59 {
61  : red(0), green(0), blue(0), padding(0) {}
62 
63  Pixel(uint8_t _red, uint8_t _green, uint8_t _blue)
64  : red(_red), green(_green), blue(_blue), padding(0) {}
65 
66  uint8_t red;
67  uint8_t green;
68  uint8_t blue;
69  uint8_t padding;
70 };
71 
72 inline bool
73 operator==(const Pixel &lhs, const Pixel &rhs)
74 {
75  return lhs.red == rhs.red &&
76  lhs.green == rhs.green &&
77  lhs.blue == rhs.blue &&
78  lhs.padding == rhs.padding;
79 }
80 
92 {
93  public:
97  struct Channel
98  {
103  Channel(unsigned offset, unsigned width);
104 
109  uint8_t toPixel(uint32_t word) const {
110  return round(((word >> offset) & mask) * factor);
111  }
112 
117  uint32_t fromPixel(uint8_t ch) const {
118  return (static_cast<uint8_t>(round(ch / factor)) & mask) << offset;
119  }
120 
122  unsigned offset;
124  unsigned mask;
129  float factor;
130  };
131 
132  PixelConverter(unsigned length,
133  unsigned ro, unsigned go, unsigned bo,
134  unsigned rw, unsigned gw, unsigned bw,
135  ByteOrder byte_order = ByteOrder::little);
136 
138  Pixel toPixel(uint32_t word) const {
139  return Pixel(ch_r.toPixel(word),
140  ch_g.toPixel(word),
141  ch_b.toPixel(word));
142  }
143 
145  Pixel toPixel(const uint8_t *rfb) const {
146  return toPixel(readWord(rfb));
147  }
148 
150  uint32_t fromPixel(const Pixel &pixel) const {
151  return ch_r.fromPixel(pixel.red) |
152  ch_g.fromPixel(pixel.green) |
153  ch_b.fromPixel(pixel.blue);
154  }
155 
160  void fromPixel(uint8_t *rfb, const Pixel &pixel) const {
161  writeWord(rfb, fromPixel(pixel));
162  }
163 
174  uint32_t readWord(const uint8_t *p) const;
181  void writeWord(uint8_t *p, uint32_t word) const;
182 
184  unsigned length;
190  unsigned depth;
192  ByteOrder byte_order;
193 
200 
206  static const PixelConverter rgb565_le;
207 
213  static const PixelConverter rgb565_be;
214 };
215 
216 inline bool
217 to_number(const std::string &value, Pixel &retval)
218 {
219  uint32_t num;
220  if (!to_number(value, num))
221  return false;
222 
223  retval = PixelConverter::rgba8888_le.toPixel(num);
224  return true;
225 }
226 
227 inline std::ostream &
228 operator<<(std::ostream &os, const Pixel &pxl)
229 {
230  os << csprintf("%#.08x", PixelConverter::rgba8888_le.fromPixel(pxl));
231  return os;
232 }
233 
234 } // namespace gem5
235 
236 #endif // __BASE_PIXEL_HH__
gem5::operator<<
std::ostream & operator<<(std::ostream &os, const ArmSemihosting::InPlaceArg &ipa)
Definition: semihosting.cc:1045
gem5::PixelConverter::Channel::offset
unsigned offset
Offset in bits.
Definition: pixel.hh:122
gem5::PixelConverter::ch_b
Channel ch_b
Blue channel conversion helper.
Definition: pixel.hh:199
sc_dt::word
unsigned int word
Definition: scfx_mant.hh:96
gem5::PixelConverter::toPixel
Pixel toPixel(const uint8_t *rfb) const
Get a Pixel representation by reading a word from memory.
Definition: pixel.hh:145
gem5::PixelConverter::rgba8888_be
static const PixelConverter rgba8888_be
Predefined 32-bit RGB (red in least significant bits, 8 bits/channel, big endian) conversion helper.
Definition: pixel.hh:210
gem5::PixelConverter::Channel::factor
float factor
Scaling factor when converting to the full range of an 8-bit color channel.
Definition: pixel.hh:129
gem5::PixelConverter::Channel::mask
unsigned mask
Bit mask (after shifting)
Definition: pixel.hh:124
gem5::PixelConverter::fromPixel
uint32_t fromPixel(const Pixel &pixel) const
Convert a Pixel into a color word.
Definition: pixel.hh:150
gem5::to_number
bool to_number(const std::string &value, Pixel &retval)
Definition: pixel.hh:217
gem5::PixelConverter::toPixel
Pixel toPixel(uint32_t word) const
Get the Pixel representation of a color word.
Definition: pixel.hh:138
gem5::csprintf
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:161
gem5::Pixel::padding
uint8_t padding
Definition: pixel.hh:69
gem5::Pixel::Pixel
Pixel(uint8_t _red, uint8_t _green, uint8_t _blue)
Definition: pixel.hh:63
gem5::PixelConverter::rgb565_be
static const PixelConverter rgb565_be
Predefined 16-bit RGB565 (red in least significant bits, big endian) conversion helper.
Definition: pixel.hh:213
str.hh
gem5::PixelConverter::Channel::fromPixel
uint32_t fromPixel(uint8_t ch) const
Convert an 8-bit representation of a color into an external format.
Definition: pixel.hh:117
gem5::PixelConverter::length
unsigned length
Bytes per pixel when stored in memory (including padding)
Definition: pixel.hh:184
gem5::PixelConverter::rgb565_le
static const PixelConverter rgb565_le
Predefined 16-bit RGB565 (red in least significant bits, little endian) conversion helper.
Definition: pixel.hh:206
gem5::Pixel::green
uint8_t green
Definition: pixel.hh:67
gem5::ArmISA::width
Bitfield< 4 > width
Definition: misc_types.hh:71
gem5::PixelConverter::byte_order
ByteOrder byte_order
Byte order when stored to memory.
Definition: pixel.hh:192
gem5::PowerISA::bo
Bitfield< 25, 21 > bo
Definition: types.hh:82
gem5::MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:326
gem5::Pixel::blue
uint8_t blue
Definition: pixel.hh:68
gem5::operator==
bool operator==(const Pixel &lhs, const Pixel &rhs)
Definition: pixel.hh:73
cprintf.hh
compiler.hh
gem5::Pixel
Internal gem5 representation of a Pixel.
Definition: pixel.hh:58
gem5::PixelConverter
Configurable RGB pixel converter.
Definition: pixel.hh:91
gem5::PixelConverter::Channel::Channel
Channel(unsigned offset, unsigned width)
Definition: pixel.cc:68
gem5::PixelConverter::ch_r
Channel ch_r
Red channel conversion helper.
Definition: pixel.hh:195
types.hh
gem5::X86ISA::os
Bitfield< 17 > os
Definition: misc.hh:809
gem5::PixelConverter::depth
unsigned depth
Number of bits used to represent one pixel value (excluding padding).
Definition: pixel.hh:190
gem5::PixelConverter::PixelConverter
PixelConverter(unsigned length, unsigned ro, unsigned go, unsigned bo, unsigned rw, unsigned gw, unsigned bw, ByteOrder byte_order=ByteOrder::little)
Definition: pixel.cc:54
gem5::Pixel::red
uint8_t red
Definition: pixel.hh:66
gem5::PixelConverter::writeWord
void writeWord(uint8_t *p, uint32_t word) const
Write a word of a given length and endianness to memory.
Definition: pixel.cc:92
gem5::ArmISA::rw
Bitfield< 31 > rw
Definition: misc_types.hh:252
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::PixelConverter::Channel::toPixel
uint8_t toPixel(uint32_t word) const
Get the value of a single color channel represented as an 8-bit number.
Definition: pixel.hh:109
gem5::PixelConverter::ch_g
Channel ch_g
Green channel conversion helper.
Definition: pixel.hh:197
gem5::PixelConverter::fromPixel
void fromPixel(uint8_t *rfb, const Pixel &pixel) const
Convert a pixel into a color word and store the resulting word in memory.
Definition: pixel.hh:160
gem5::Pixel::Pixel
Pixel()
Definition: pixel.hh:60
gem5::PixelConverter::readWord
uint32_t readWord(const uint8_t *p) const
Read a word of a given length and endianness from memory.
Definition: pixel.cc:76
byteswap.hh
gem5::PixelConverter::rgba8888_le
static const PixelConverter rgba8888_le
Predefined 32-bit RGB (red in least significant bits, 8 bits/channel, little endian) conversion helpe...
Definition: pixel.hh:203
gem5::PixelConverter::Channel
Color channel conversion and scaling helper class.
Definition: pixel.hh:97

Generated on Tue Sep 21 2021 12:24:57 for gem5 by doxygen 1.8.17