summaryrefslogtreecommitdiff
path: root/src/base/bitmap.cc
diff options
context:
space:
mode:
authorAndreas Sandberg <andreas.sandberg@arm.com>2015-05-23 13:37:03 +0100
committerAndreas Sandberg <andreas.sandberg@arm.com>2015-05-23 13:37:03 +0100
commitdb5c9a5f9028fd87a74e1750068511bd311435ae (patch)
treed2d2125ce8f717355187c767599945ad354470e9 /src/base/bitmap.cc
parent1985d28ef905753423b3ee407c8bf4ee9165302b (diff)
downloadgem5-db5c9a5f9028fd87a74e1750068511bd311435ae.tar.xz
base: Redesign internal frame buffer handling
Currently, frame buffer handling in gem5 is quite ad hoc. In practice, we pass around naked pointers to raw pixel data and expect consumers to convert frame buffers using the (broken) VideoConverter. This changeset completely redesigns the way we handle frame buffers internally. In summary, it fixes several color conversion bugs, adds support for more color formats (e.g., big endian), and makes the code base easier to follow. In the new world, gem5 always represents pixel data using the Pixel struct when pixels need to be passed between different classes (e.g., a display controller and the VNC server). Producers of entire frames (e.g., display controllers) should use the FrameBuffer class to represent a frame. Frame producers are expected to create one instance of the FrameBuffer class in their constructors and register it with its consumers once. Consumers are expected to check the dimensions of the frame buffer when they consume it. Conversion between the external representation and the internal representation is supported for all common "true color" RGB formats of up to 32-bit color depth. The external pixel representation is expected to be between 1 and 4 bytes in either big endian or little endian. Color channels are assumed to be contiguous ranges of bits within each pixel word. The external pixel value is scaled to an 8-bit internal representation using a floating multiplication to map it to the entire 8-bit range.
Diffstat (limited to 'src/base/bitmap.cc')
-rw-r--r--src/base/bitmap.cc38
1 files changed, 16 insertions, 22 deletions
diff --git a/src/base/bitmap.cc b/src/base/bitmap.cc
index d83a30be3..0052503a4 100644
--- a/src/base/bitmap.cc
+++ b/src/base/bitmap.cc
@@ -47,11 +47,8 @@
#include "base/misc.hh"
// bitmap class ctor
-Bitmap::Bitmap(VideoConvert::Mode mode, uint16_t w, uint16_t h, uint8_t *d)
- : height(h), width(w),
- header(getCompleteHeader()),
- data(d),
- vc(mode, VideoConvert::rgb8888, width, height)
+Bitmap::Bitmap(const FrameBuffer *_fb)
+ : fb(*_fb)
{
}
@@ -62,7 +59,7 @@ Bitmap::~Bitmap()
const Bitmap::CompleteV1Header
Bitmap::getCompleteHeader() const
{
- const uint32_t pixel_array_size(sizeof(PixelType) * width * height);
+ const uint32_t pixel_array_size(sizeof(PixelType) * fb.area());
const uint32_t file_size(sizeof(CompleteV1Header) + pixel_array_size);
const CompleteV1Header header = {
@@ -76,8 +73,8 @@ Bitmap::getCompleteHeader() const
// Info/DIB header
{
sizeof(InfoHeaderV1),
- width,
- height,
+ fb.width(),
+ fb.height(),
1, /* Color planes */
32, /* Bits per pixel */
0, /* No compression */
@@ -93,28 +90,25 @@ Bitmap::getCompleteHeader() const
}
void
-Bitmap::write(std::ostream *bmp) const
+Bitmap::write(std::ostream &bmp) const
{
- assert(data);
+ const CompleteV1Header header(getCompleteHeader());
// 1. write the header
- bmp->write(reinterpret_cast<const char *>(&header), sizeof(header));
+ bmp.write(reinterpret_cast<const char *>(&header), sizeof(header));
// 2. write the bitmap data
- const uint8_t *pixels(vc.convert(data));
-
// BMP start store data left to right starting with the bottom row
// so we need to do some creative flipping
- for (int y = height - 1; y >= 0; y--) {
- for (int x = 0; x < width; x++) {
- bmp->write(
- (const char *)&pixels[sizeof(PixelType) * (y * width + x)],
- sizeof(PixelType));
- }
- }
+ std::vector<PixelType> line_buffer(fb.width());
+ for (int y = 0; y < fb.height(); ++y) {
+ for (unsigned x = 0; x < fb.width(); ++x)
+ line_buffer[x] = fb.pixel(x, fb.height() - y - 1);
- bmp->flush();
+ bmp.write(reinterpret_cast<const char *>(line_buffer.data()),
+ line_buffer.size() * sizeof(line_buffer[0]));
+ }
- delete[] pixels;
+ bmp.flush();
}