summaryrefslogtreecommitdiff
path: root/src/base/bitmap.hh
diff options
context:
space:
mode:
authorAndreas Sandberg <andreas.sandberg@arm.com>2015-05-23 13:37:01 +0100
committerAndreas Sandberg <andreas.sandberg@arm.com>2015-05-23 13:37:01 +0100
commit1985d28ef905753423b3ee407c8bf4ee9165302b (patch)
tree77a9914fa40545ef33d6b908f7afd3c373b8e763 /src/base/bitmap.hh
parent0479569f6748202f1704d70aad3b03b3d17f6092 (diff)
downloadgem5-1985d28ef905753423b3ee407c8bf4ee9165302b.tar.xz
base: Clean up bitmap generation code
The bitmap generation code is hard to follow and incorrectly uses the size of an enum member to calculate the size of a pixel. This changeset cleans up the code and adds some documentation.
Diffstat (limited to 'src/base/bitmap.hh')
-rw-r--r--src/base/bitmap.hh68
1 files changed, 39 insertions, 29 deletions
diff --git a/src/base/bitmap.hh b/src/base/bitmap.hh
index e9ad15473..b06aff10f 100644
--- a/src/base/bitmap.hh
+++ b/src/base/bitmap.hh
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 ARM Limited
+ * Copyright (c) 2010, 2015 ARM Limited
* All rights reserved
*
* The license below extends only to copyright in the software and shall
@@ -37,12 +37,14 @@
* Authors: William Wang
* Ali Saidi
* Chris Emmons
+ * Andreas Sandberg
*/
#ifndef __BASE_BITMAP_HH__
#define __BASE_BITMAP_HH__
-#include <fstream>
+#include <ostream>
+#include "base/compiler.hh"
#include "base/vnc/convert.hh"
/**
@@ -54,8 +56,10 @@
class Bitmap
{
public:
- /** Create a Bitmap creator that takes data in the given mode & size
- * and outputs to an fstream
+ /**
+ * Create a bitmap that takes data in a given mode & size and
+ * outputs to an ostream.
+ *
* @param mode the type of data that is being provided
* @param h the hight of the image
* @param w the width of the image
@@ -63,52 +67,42 @@ class Bitmap
*/
Bitmap(VideoConvert::Mode mode, uint16_t w, uint16_t h, uint8_t *d);
- /** Destructor */
~Bitmap();
- /** Provide the converter with the data that should be output. It will be
- * converted into rgb8888 and write out when write() is called.
+ /**
+ * Provide the converter with the data that should be output. It
+ * will be converted into rgb8888 and written when write() is
+ * called.
+ *
* @param d the data
*/
void rawData(uint8_t* d) { data = d; }
- /** Write the provided data into the fstream provided
+ /**
+ * Write the frame buffer data into the provided ostream
+ *
* @param bmp stream to write to
*/
void write(std::ostream *bmp) const;
- /** Gets a hash over the bitmap for quick comparisons to other bitmaps.
+ /**
+ * Gets a hash over the bitmap for quick comparisons to other bitmaps.
+ *
* @return hash of the bitmap
*/
uint64_t getHash() const { return vc.getHash(data); }
private:
- VideoConvert::Mode mode;
- uint16_t height;
- uint16_t width;
- uint8_t *data;
-
- VideoConvert vc;
-
- mutable char *headerBuffer;
- static const size_t sizeofHeaderBuffer;
-
- struct Magic
- {
+ struct FileHeader {
unsigned char magic_number[2];
- };
-
- struct Header
- {
uint32_t size;
uint16_t reserved1;
uint16_t reserved2;
uint32_t offset;
- };
+ } M5_ATTR_PACKED;
- struct Info
- {
+ struct InfoHeaderV1 { /* Aka DIB header */
uint32_t Size;
uint32_t Width;
uint32_t Height;
@@ -120,7 +114,23 @@ class Bitmap
uint32_t YPelsPerMeter;
uint32_t ClrUsed;
uint32_t ClrImportant;
- };
+ } M5_ATTR_PACKED;
+
+ struct CompleteV1Header {
+ FileHeader file;
+ InfoHeaderV1 info;
+ } M5_ATTR_PACKED;
+
+ typedef uint32_t PixelType;
+
+ const CompleteV1Header getCompleteHeader() const;
+
+ const uint16_t height;
+ const uint16_t width;
+ const CompleteV1Header header;
+ uint8_t *data;
+
+ VideoConvert vc;
};
#endif // __BASE_BITMAP_HH__