From 9aea847f5891214f456cc9d6e173d7fbb1a30c0a Mon Sep 17 00:00:00 2001 From: Chris Emmons Date: Thu, 1 Dec 2011 00:15:26 -0800 Subject: VNC: Add support for capturing frame buffer to file each time it is changed. When a change in the frame buffer from the VNC server is detected, the new frame is stored out to the m5out/frames_*/ directory. Specifiy the flag "--frame-capture" when running configs/example/fs.py to enable this behavior. --HG-- extra : rebase_source : d4e08e83f4fa6ff79f3dc9c433fc1f0487e057fc --- src/base/bitmap.cc | 44 +++++++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 11 deletions(-) (limited to 'src/base/bitmap.cc') diff --git a/src/base/bitmap.cc b/src/base/bitmap.cc index 0d2a9302b..08425d74f 100644 --- a/src/base/bitmap.cc +++ b/src/base/bitmap.cc @@ -36,6 +36,7 @@ * * Authors: William Wang * Ali Saidi + * Chris Emmons */ #include @@ -43,29 +44,50 @@ #include "base/bitmap.hh" #include "base/misc.hh" +const size_t Bitmap::sizeofHeaderBuffer = sizeof(Magic) + sizeof(Header) + + sizeof(Info); + // bitmap class ctor Bitmap::Bitmap(VideoConvert::Mode _mode, uint16_t w, uint16_t h, uint8_t *d) : mode(_mode), height(h), width(w), data(d), - vc(mode, VideoConvert::rgb8888, width, height) + vc(mode, VideoConvert::rgb8888, width, height), headerBuffer(0) { } +Bitmap::~Bitmap() { + if (headerBuffer) + delete [] headerBuffer; +} + void -Bitmap::write(std::ostream *bmp) +Bitmap::write(std::ostream *bmp) const { assert(data); - // For further information see: http://en.wikipedia.org/wiki/BMP_file_format - Magic magic = {{'B','M'}}; - Header header = {sizeof(VideoConvert::Rgb8888) * width * height , 0, 0, 54}; - Info info = {sizeof(Info), width, height, 1, - sizeof(VideoConvert::Rgb8888) * 8, 0, - sizeof(VideoConvert::Rgb8888) * width * height, 1, 1, 0, 0}; + // header is always the same for a bitmap object; compute the info once per + // bitmap object + if (!headerBuffer) { + // For further information see: + // http://en.wikipedia.org/wiki/BMP_file_format + Magic magic = {{'B','M'}}; + Header header = {sizeof(VideoConvert::Rgb8888) * width * height, + 0, 0, 54}; + Info info = {sizeof(Info), width, height, 1, + sizeof(VideoConvert::Rgb8888) * 8, 0, + sizeof(VideoConvert::Rgb8888) * width * height, 1, 1, 0, 0}; + + char *p = headerBuffer = new char[sizeofHeaderBuffer]; + memcpy(p, &magic, sizeof(Magic)); + p += sizeof(Magic); + memcpy(p, &header, sizeof(Header)); + p += sizeof(Header); + memcpy(p, &info, sizeof(Info)); + } - bmp->write(reinterpret_cast(&magic), sizeof(magic)); - bmp->write(reinterpret_cast(&header), sizeof(header)); - bmp->write(reinterpret_cast(&info), sizeof(info)); + // 1. write the header + bmp->write(headerBuffer, sizeofHeaderBuffer); + // 2. write the bitmap data uint8_t *tmp = vc.convert(data); uint32_t *tmp32 = (uint32_t*)tmp; -- cgit v1.2.3