gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
framebuffer.cc
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  * Authors: Andreas Sandberg
38  */
39 
40 #include "base/framebuffer.hh"
41 
42 #include <zlib.h>
43 
44 #include <cassert>
45 
46 #include "base/bitfield.hh"
47 
48 const PixelConverter PixelConverter::rgba8888_le(4, 0, 8, 16, 8, 8, 8);
49 const PixelConverter PixelConverter::rgba8888_be(4, 0, 8, 16, 8, 8, 8,
51 const PixelConverter PixelConverter::rgb565_le(2, 0, 5, 11, 5, 6, 5);
52 const PixelConverter PixelConverter::rgb565_be(2, 0, 5, 11, 5, 6, 5,
54 
55 const FrameBuffer FrameBuffer::dummy(320, 240);
56 
58  unsigned ro, unsigned go, unsigned bo,
59  unsigned rw, unsigned gw, unsigned bw,
60  ByteOrder _byte_order)
61  : length(_length),
62  depth(rw + gw + bw),
63  byte_order(_byte_order),
64  ch_r(ro, rw),
65  ch_g(go, gw),
66  ch_b(bo, bw)
67 {
68  assert(length > 1);
69 }
70 
71 PixelConverter::Channel::Channel(unsigned _offset, unsigned width)
72  : offset(_offset),
73  mask(::mask(width)),
74  factor(255.0 / mask)
75 {
76 }
77 
78 uint32_t
79 PixelConverter::readWord(const uint8_t *p) const
80 {
81  uint32_t word(0);
82 
84  for (int i = 0; i < length; ++i)
85  word |= p[i] << (8 * i);
86  } else {
87  for (int i = 0; i < length; ++i)
88  word |= p[i] << (8 * (length - i - 1));
89  }
90 
91  return word;
92 }
93 
94 void
95 PixelConverter::writeWord(uint8_t *p, uint32_t word) const
96 {
98  for (int i = 0; i < length; ++i)
99  p[i] = (word >> (8 * i)) & 0xFF;
100  } else {
101  for (int i = 0; i < length; ++i)
102  p[i] = (word >> (8 * (length - i - 1))) & 0xFF;
103  }
104 }
105 
106 
107 
108 
109 FrameBuffer::FrameBuffer(unsigned width, unsigned height)
110  : pixels(width * height),
111  _width(width), _height(height)
112 {
113  clear();
114 }
115 
117  : _width(0), _height(0)
118 {
119 }
120 
122 {
123 }
124 
125 
126 void
128 {
132 }
133 
134 void
136 {
140 }
141 
142 void
143 FrameBuffer::resize(unsigned width, unsigned height)
144 {
145  _width = width;
146  _height = height;
147 
148  pixels.resize(width * height);
149 }
150 
151 void
153 {
154  for (auto &p : pixels)
155  p = pixel;
156 }
157 
158 void
160 {
161  static const Pixel black(0, 0, 0);
162 
163  fill(black);
164 }
165 
166 void
167 FrameBuffer::copyIn(const uint8_t *fb, const PixelConverter &conv)
168 {
169  for (auto &p : pixels) {
170  p = conv.toPixel(fb);
171  fb += conv.length;
172  }
173 }
174 
175 void
176 FrameBuffer::copyOut(uint8_t *fb, const PixelConverter &conv) const
177 {
178  for (auto &p : pixels) {
179  conv.fromPixel(fb, p);
180  fb += conv.length;
181  }
182 }
183 
184 uint64_t
186 {
187  return adler32(0UL,
188  reinterpret_cast<const Bytef *>(pixels.data()),
189  area() * sizeof(Pixel));
190 }
Pixel toPixel(uint32_t word) const
Get the Pixel representation of a color word.
Definition: framebuffer.hh:137
const Pixel & pixel(unsigned x, unsigned y) const
Get a pixel from an (x, y) coordinate.
Definition: framebuffer.hh:336
static const FrameBuffer dummy
Static "dummy" frame buffer.
Definition: framebuffer.hh:368
Internal gem5 representation of a frame buffer.
Definition: framebuffer.hh:244
Bitfield< 7 > i
Definition: miscregs.hh:1378
void resize(unsigned width, unsigned height)
Resize the frame buffer.
Definition: framebuffer.cc:143
uint32_t readWord(const uint8_t *p) const
Read a word of a given length and endianness from memory.
Definition: framebuffer.cc:79
unsigned length
Bytes per pixel when stored in memory (including padding)
Definition: framebuffer.hh:183
void copyIn(const uint8_t *fb, const PixelConverter &conv)
Fill the frame buffer with pixel data from an external buffer of the same width and height as this fr...
Definition: framebuffer.cc:167
void copyOut(uint8_t *fb, const PixelConverter &conv) const
Store the contents of this frame buffer in an external buffer of the same width and height as this fr...
Definition: framebuffer.cc:176
unsigned _width
Width in pixels.
Definition: framebuffer.hh:375
void clear()
Fill the frame buffer with black pixels.
Definition: framebuffer.cc:159
FrameBuffer()
Create an empty (0x0) frame buffer.
Definition: framebuffer.cc:116
std::vector< Pixel > pixels
Frame buffer backing store.
Definition: framebuffer.hh:371
Bitfield< 23, 0 > offset
Definition: types.hh:149
Channel(unsigned offset, unsigned width)
Definition: framebuffer.cc:71
static const PixelConverter rgb565_be
Predefined 16-bit RGB565 (red in least significant bits, big endian) conversion helper.
Definition: framebuffer.hh:212
PixelConverter(unsigned length, unsigned ro, unsigned go, unsigned bo, unsigned rw, unsigned gw, unsigned bw, ByteOrder byte_order=LittleEndianByteOrder)
Definition: framebuffer.cc:57
#define UNSERIALIZE_SCALAR(scalar)
Definition: serialize.hh:145
#define SERIALIZE_CONTAINER(member)
Definition: serialize.hh:164
ByteOrder byte_order
Byte order when stored to memory.
Definition: framebuffer.hh:191
unsigned height() const
Frame buffer height in pixels.
Definition: framebuffer.hh:277
ByteOrder
Definition: types.hh:204
static const PixelConverter rgba8888_le
Predefined 32-bit RGB (red in least significant bits, 8 bits/channel, little endian) conversion helpe...
Definition: framebuffer.hh:202
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: framebuffer.cc:135
#define UNSERIALIZE_CONTAINER(member)
Definition: serialize.hh:167
#define SERIALIZE_SCALAR(scalar)
Definition: serialize.hh:143
static const PixelConverter rgb565_le
Predefined 16-bit RGB565 (red in least significant bits, little endian) conversion helper...
Definition: framebuffer.hh:205
Bitfield< 25, 21 > bo
Definition: types.hh:64
std::ostream CheckpointOut
Definition: serialize.hh:67
unsigned width() const
Frame buffer width in pixels.
Definition: framebuffer.hh:275
Bitfield< 9 > fb
Definition: miscregs.hh:1472
Bitfield< 4 > width
Definition: miscregs.hh:1383
Bitfield< 31 > rw
Definition: miscregs.hh:1449
uint64_t getHash() const
Create a hash of the image that can be used for quick comparisons.
Definition: framebuffer.cc:185
virtual ~FrameBuffer()
Definition: framebuffer.cc:121
void fill(const Pixel &pixel)
Fill the frame buffer with a single pixel value.
Definition: framebuffer.cc:152
Bitfield< 3, 0 > mask
Definition: types.hh:64
uint8_t length
Definition: inet.hh:334
Configurable RGB pixel converter.
Definition: framebuffer.hh:91
Internal gem5 representation of a Pixel.
Definition: framebuffer.hh:58
unsigned _height
Height in pixels.
Definition: framebuffer.hh:377
void writeWord(uint8_t *p, uint32_t word) const
Write a word of a given length and endianness to memory.
Definition: framebuffer.cc:95
Bitfield< 0 > p
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: framebuffer.cc:127
static const PixelConverter rgba8888_be
Predefined 32-bit RGB (red in least significant bits, 8 bits/channel, big endian) conversion helper...
Definition: framebuffer.hh:209
uint32_t fromPixel(const Pixel &pixel) const
Convert a Pixel into a color word.
Definition: framebuffer.hh:149
unsigned area() const
Total number of pixels in frame buffer.
Definition: framebuffer.hh:279

Generated on Fri Jun 9 2017 13:03:40 for gem5 by doxygen 1.8.6