base: Introducing utility for writing raw data in png format

Originally it was possible to use a Bitmap writer class for dumping a
framebuffer snapshot in a .bmp file. This patch enables you to choose
another format.  In particular it implements the writing of PNG Images
using libpng library.  The latter has to be already installed in your
machine, otherwise gem5 will default to the Bitmap format.  This
configurable writer has been introduced in the VNC frame dumping mechanism,
which is storing changed frame buffers from the VNC server

Change-Id: Id7e5763c82235f1ce90381c8486b85a7cce734ce
Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com>
Reviewed-on: https://gem5-review.googlesource.com/5181
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
Maintainer: Andreas Sandberg <andreas.sandberg@arm.com>
This commit is contained in:
Giacomo Travaglini
2017-09-28 13:01:08 +01:00
parent 1025ef1598
commit 12fb1ca0b5
16 changed files with 575 additions and 43 deletions

View File

@@ -1,6 +1,6 @@
# -*- mode:python -*-
# Copyright (c) 2013, 2015, 2016 ARM Limited
# Copyright (c) 2013, 2015-2017 ARM Limited
# All rights reserved.
#
# The license below extends only to copyright in the software and shall
@@ -1134,6 +1134,14 @@ if not have_fenv:
print "Warning: Header file <fenv.h> not found."
print " This host has no IEEE FP rounding mode control."
# Check for <png.h> (libpng library needed if wanting to dump
# frame buffer image in png format)
have_png = conf.CheckHeader('png.h', '<>')
if not have_png:
print "Warning: Header file <png.h> not found."
print " This host has no libpng library."
print " Disabling support for PNG framebuffers."
# Check if we should enable KVM-based hardware virtualization. The API
# we rely on exists since version 2.6.36 of the kernel, but somehow
# the KVM_API_VERSION does not reflect the change. We test for one of
@@ -1278,8 +1286,11 @@ sticky_vars.AddVariables(
False),
BoolVariable('USE_POSIX_CLOCK', 'Use POSIX Clocks', have_posix_clock),
BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv),
BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', False),
BoolVariable('USE_KVM', 'Enable hardware virtualized (KVM) CPU models', have_kvm),
BoolVariable('USE_PNG', 'Enable support for PNG images', have_png),
BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability',
False),
BoolVariable('USE_KVM', 'Enable hardware virtualized (KVM) CPU models',
have_kvm),
BoolVariable('USE_TUNTAP',
'Enable using a tap device to bridge to the host network',
have_tuntap),
@@ -1293,7 +1304,8 @@ sticky_vars.AddVariables(
# These variables get exported to #defines in config/*.hh (see src/SConscript).
export_vars += ['USE_FENV', 'SS_COMPATIBLE_FP', 'TARGET_ISA', 'TARGET_GPU_ISA',
'CP_ANNOTATE', 'USE_POSIX_CLOCK', 'USE_KVM', 'USE_TUNTAP',
'PROTOCOL', 'HAVE_PROTOBUF', 'HAVE_PERF_ATTR_EXCLUDE_HOST']
'PROTOCOL', 'HAVE_PROTOBUF', 'HAVE_PERF_ATTR_EXCLUDE_HOST',
'USE_PNG']
###################################################
#
@@ -1486,6 +1498,14 @@ for variant_path in variant_paths:
print "Warning: No IEEE FP rounding mode control in", variant_dir + "."
print " FP results may deviate slightly from other platforms."
if not have_png and env['USE_PNG']:
print "Warning: <png.h> not available; " \
"forcing USE_PNG to False in", variant_dir + "."
env['USE_PNG'] = False
if env['USE_PNG']:
env.Append(LIBS=['png'])
if env['EFENCE']:
env.Append(LIBS=['efence'])

43
src/base/Graphics.py Normal file
View File

@@ -0,0 +1,43 @@
# Copyright (c) 2017 ARM Limited
# All rights reserved
#
# The license below extends only to copyright in the software and shall
# not be construed as granting a license to any other intellectual
# property including but not limited to intellectual property relating
# to a hardware implementation of the functionality of the software
# licensed hereunder. You may use the software subject to the license
# terms below provided that you ensure that this notice is replicated
# unmodified and in its entirety in all distributions of the software,
# modified or unmodified, in source code or in binary form.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met: redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer;
# redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution;
# neither the name of the copyright holders nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Authors: Giacomo Travaglini
from m5.SimObject import SimObject
from m5.params import *
# Image Formats:
# Auto option will let gem5 to choose the image format it prefers.
class ImageFormat(Enum): vals = ['Auto', 'Bitmap', 'Png']

View File

@@ -33,15 +33,19 @@ Import('*')
if env['CP_ANNOTATE']:
SimObject('CPA.py')
Source('cp_annotate.cc')
SimObject('Graphics.py')
Source('atomicio.cc')
Source('bitfield.cc')
Source('bigint.cc')
Source('bitmap.cc')
Source('imgwriter.cc')
Source('bmpwriter.cc')
Source('callback.cc')
Source('cprintf.cc')
Source('debug.cc')
if env['USE_FENV']:
Source('fenv.c')
if env['USE_PNG']:
Source('pngwriter.cc')
Source('framebuffer.cc')
Source('hostinfo.cc')
Source('inet.cc')

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2015 ARM Limited
* Copyright (c) 2010, 2015, 2017 ARM Limited
* All rights reserved
*
* The license below extends only to copyright in the software and shall
@@ -40,24 +40,22 @@
* Andreas Sandberg
*/
#include "base/bitmap.hh"
#include "base/bmpwriter.hh"
#include <cassert>
#include "base/misc.hh"
const char* BmpWriter::_imgExtension = "bmp";
// bitmap class ctor
Bitmap::Bitmap(const FrameBuffer *_fb)
: fb(*_fb)
BmpWriter::BmpWriter(const FrameBuffer *_fb)
: ImgWriter(_fb)
{
}
Bitmap::~Bitmap()
{
}
const Bitmap::CompleteV1Header
Bitmap::getCompleteHeader() const
const BmpWriter::CompleteV1Header
BmpWriter::getCompleteHeader() const
{
const uint32_t pixel_array_size(sizeof(PixelType) * fb.area());
const uint32_t file_size(sizeof(CompleteV1Header) + pixel_array_size);
@@ -90,7 +88,7 @@ Bitmap::getCompleteHeader() const
}
void
Bitmap::write(std::ostream &bmp) const
BmpWriter::write(std::ostream &bmp) const
{
const CompleteV1Header header(getCompleteHeader());
@@ -112,3 +110,4 @@ Bitmap::write(std::ostream &bmp) const
bmp.flush();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2015 ARM Limited
* Copyright (c) 2010, 2015, 2017 ARM Limited
* All rights reserved
*
* The license below extends only to copyright in the software and shall
@@ -46,31 +46,38 @@
#include "base/compiler.hh"
#include "base/framebuffer.hh"
#include "base/imgwriter.hh"
/**
* @file Declaration of a class that writes a frame buffer to a bitmap
*/
// write frame buffer into a bitmap picture
class Bitmap
class BmpWriter : public ImgWriter
{
public:
/**
* Create a bitmap that takes data in a given mode & size and
* outputs to an ostream.
*/
Bitmap(const FrameBuffer *fb);
BmpWriter(const FrameBuffer *fb);
~Bitmap();
~BmpWriter() {};
/*
* Return Image format as a string
*
* @return img extension (e.g. bmp for Bitmap)
*/
const char* getImgExtension() const override
{ return _imgExtension; }
/**
* Write the frame buffer data into the provided ostream
*
* @param bmp stream to write to
*/
void write(std::ostream &bmp) const;
void write(std::ostream &bmp) const override;
private:
struct FileHeader {
@@ -117,10 +124,11 @@ class Bitmap
typedef BmpPixel32 PixelType;
const CompleteV1Header getCompleteHeader() const;
static const char* _imgExtension;
const FrameBuffer &fb;
const CompleteV1Header getCompleteHeader() const;
};
#endif // __BASE_BITMAP_HH__

72
src/base/imgwriter.cc Normal file
View File

@@ -0,0 +1,72 @@
/*
* Copyright (c) 2017 ARM Limited
* All rights reserved
*
* The license below extends only to copyright in the software and shall
* not be construed as granting a license to any other intellectual
* property including but not limited to intellectual property relating
* to a hardware implementation of the functionality of the software
* licensed hereunder. You may use the software subject to the license
* terms below provided that you ensure that this notice is replicated
* unmodified and in its entirety in all distributions of the software,
* modified or unmodified, in source code or in binary form.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met: redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer;
* redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution;
* neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Authors: Giacomo Travaglini
*/
#include "base/imgwriter.hh"
#include "base/bmpwriter.hh"
#include "base/misc.hh"
#include "config/use_png.hh"
#if USE_PNG
#include "base/pngwriter.hh"
#endif
std::unique_ptr<ImgWriter>
createImgWriter(Enums::ImageFormat type, const FrameBuffer *fb)
{
switch (type) {
case Enums::Auto:
// The Auto option allows gem5 to choose automatically the
// writer type, and it will choose for the best fit in
// performance.
// gem5 will try PNG first, and it will fallback to BMP if not
// available.
/* FALLTHROUGH */
#if USE_PNG
case Enums::Png:
return std::unique_ptr<PngWriter>(new PngWriter(fb));
#endif
case Enums::Bitmap:
return std::unique_ptr<BmpWriter>(new BmpWriter(fb));
default:
warn("Invalid Image Type specified, defaulting to Bitmap\n");
return std::unique_ptr<BmpWriter>(new BmpWriter(fb));
}
}

91
src/base/imgwriter.hh Normal file
View File

@@ -0,0 +1,91 @@
/*
* Copyright (c) 2017 ARM Limited
* All rights reserved
*
* The license below extends only to copyright in the software and shall
* not be construed as granting a license to any other intellectual
* property including but not limited to intellectual property relating
* to a hardware implementation of the functionality of the software
* licensed hereunder. You may use the software subject to the license
* terms below provided that you ensure that this notice is replicated
* unmodified and in its entirety in all distributions of the software,
* modified or unmodified, in source code or in binary form.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met: redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer;
* redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution;
* neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Authors: Giacomo Travaglini
*/
#ifndef __BASE_IMGWRITER_HH__
#define __BASE_IMGWRITER_HH__
#include <ostream>
#include "base/compiler.hh"
#include "base/framebuffer.hh"
#include "enums/ImageFormat.hh"
// write frame buffer to an image
class ImgWriter
{
public:
ImgWriter(const FrameBuffer *_fb)
: fb(*_fb)
{}
virtual ~ImgWriter() {};
/**
* Write the frame buffer data into the provided ostream
*
* @param out output stream to write to
*/
virtual void write(std::ostream &out) const = 0;
/*
* Return Image format as a string
*
* @return img extension (e.g. bmp for Bitmap)
*/
virtual const char* getImgExtension() const = 0;
protected:
const FrameBuffer &fb;
};
/**
* Factory Function which allocates a ImgWriter object and returns
* a smart pointer to it. The dynamic type of the object being pointed
* depends upon the enum type passed as a first parameter.
* If the enum contains an invalid value, the function will produce a warning
* and will default to Bitamp.
*
* @param type Image writer type (e.g. Bitamp, Png)
* @param fb Pointer to a FrameBuffer object
* This contains the raw data which will be stored as an image
* when calling the appropriate object method
* @return smart pointer to the allocated Image Writer
*/
std::unique_ptr<ImgWriter>
createImgWriter(Enums::ImageFormat type, const FrameBuffer *fb);
#endif //__BASE_IMGWRITER_HH__

175
src/base/pngwriter.cc Normal file
View File

@@ -0,0 +1,175 @@
/*
* Copyright (c) 2017 ARM Limited
* All rights reserved
*
* The license below extends only to copyright in the software and shall
* not be construed as granting a license to any other intellectual
* property including but not limited to intellectual property relating
* to a hardware implementation of the functionality of the software
* licensed hereunder. You may use the software subject to the license
* terms below provided that you ensure that this notice is replicated
* unmodified and in its entirety in all distributions of the software,
* modified or unmodified, in source code or in binary form.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met: redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer;
* redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution;
* neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Authors: Giacomo Travaglini
*/
/**
* @file Definition of a class that writes a frame buffer to a png
*/
#include "base/pngwriter.hh"
extern "C"
{
#include <png.h>
}
#include <cstdio>
#include <cstdlib>
#include "base/misc.hh"
const char* PngWriter::_imgExtension = "png";
/**
* Write callback to use with libpng APIs
*
* @param pngPtr pointer to the png_struct structure
* @param data pointer to the data being written
* @param length number of bytes being written
*/
static void
writePng(png_structp pngPtr, png_bytep data, png_size_t length)
{
// Here we get our IO pointer back from the write struct
// and we cast it into a ostream* type.
std::ostream* strmPtr = reinterpret_cast<std::ostream*>(
png_get_io_ptr(pngPtr)
);
// Write length bytes to data
strmPtr->write(reinterpret_cast<const char *>(data), length);
}
struct PngWriter::PngStructHandle {
private:
// Make PngStructHandle uncopyable
PngStructHandle(const PngStructHandle&) = delete;
PngStructHandle& operator=(const PngStructHandle&) = delete;
public:
PngStructHandle() :
pngWriteP(NULL), pngInfoP(NULL)
{
// Creating write structure
pngWriteP = png_create_write_struct(
PNG_LIBPNG_VER_STRING, NULL, NULL, NULL
);
if (pngWriteP) {
// Creating info structure
pngInfoP = png_create_info_struct(pngWriteP);
}
}
~PngStructHandle()
{
if (pngWriteP) {
png_destroy_write_struct(&pngWriteP, &pngInfoP);
}
}
/** Pointer to PNG Write struct */
png_structp pngWriteP;
/** Pointer to PNG Info struct */
png_infop pngInfoP;
};
void
PngWriter::write(std::ostream &png) const
{
// Height of the frame buffer
unsigned height = fb.height();
unsigned width = fb.width();
// Do not write if frame buffer is empty
if (!fb.area()) {
png.flush();
return;
}
// Initialize Png structures
PngStructHandle handle;
// Png info/write pointers.
png_structp pngPtr = handle.pngWriteP;
png_infop infoPtr = handle.pngInfoP;
if (!pngPtr) {
warn("Frame buffer dump aborted: Unable to create"
"Png Write Struct\n");
return;
}
if (!infoPtr) {
warn("Frame buffer dump aborted: Unable to create"
"Png Info Struct\n");
return;
}
// We cannot use default libpng write function since it requires
// a file pointer (FILE*), whereas we want to use the ostream.
// The following function replaces the write function with a custom
// one provided by us (writePng)
png_set_write_fn(pngPtr, (png_voidp)&png, writePng, NULL);
png_set_IHDR(pngPtr, infoPtr, width, height, 8,
PNG_COLOR_TYPE_RGB,
PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_DEFAULT,
PNG_FILTER_TYPE_DEFAULT);
png_write_info(pngPtr, infoPtr);
// libpng requires an array of pointers to the frame buffer's rows.
std::vector<PixelType> rowPacked(width);
for (unsigned y=0; y < height; ++y) {
for (unsigned x=0; x < height; ++x) {
rowPacked[x] = fb.pixel(x, y);
}
png_write_row(pngPtr,
reinterpret_cast<png_bytep>(rowPacked.data())
);
}
// End of write
png_write_end(pngPtr, NULL);
}

109
src/base/pngwriter.hh Normal file
View File

@@ -0,0 +1,109 @@
/*
* Copyright (c) 2017 ARM Limited
* All rights reserved
*
* The license below extends only to copyright in the software and shall
* not be construed as granting a license to any other intellectual
* property including but not limited to intellectual property relating
* to a hardware implementation of the functionality of the software
* licensed hereunder. You may use the software subject to the license
* terms below provided that you ensure that this notice is replicated
* unmodified and in its entirety in all distributions of the software,
* modified or unmodified, in source code or in binary form.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met: redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer;
* redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution;
* neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Authors: Giacomo Travaglini
*/
/**
* @file Declaration of a class that writes a frame buffer to a png
*/
#ifndef __BASE_PNG_HH__
#define __BASE_PNG_HH__
#include "base/compiler.hh"
#include "base/framebuffer.hh"
#include "base/imgwriter.hh"
/** Image writer implementing support for PNG */
class PngWriter : public ImgWriter
{
public:
/**
* Create a png that takes data in a given mode & size and
* outputs to an ostream.
*/
PngWriter(const FrameBuffer *_fb)
: ImgWriter(_fb)
{}
~PngWriter() {};
/**
* Return Image format as a string
*
* @return img extension (e.g. .png for Png)
*/
const char* getImgExtension() const override
{ return _imgExtension; }
/**
* Write the frame buffer data into the provided ostream
*
* @param png stream to write to
*/
void write(std::ostream &png) const override;
private:
/** Png Pixel type: not containing padding */
struct PngPixel24 {
PngPixel24 &operator=(const Pixel &rhs) {
red = rhs.red;
green = rhs.green;
blue = rhs.blue;
return *this;
}
uint8_t red;
uint8_t green;
uint8_t blue;
} M5_ATTR_PACKED;
/**
* Handle to resources used by libpng:
* - png_struct: Structure holding write informations
* - png_info : Structure holding image informations
*
* The class is automatically taking care of struct
* allocation/deallocation
*/
struct PngStructHandle;
typedef PngPixel24 PixelType;
static const char* _imgExtension;
};
#endif // __BASE_PNG_HH__

View File

@@ -37,11 +37,16 @@
from m5.SimObject import SimObject
from m5.params import *
from Graphics import *
class VncInput(SimObject):
type = 'VncInput'
cxx_header = "base/vnc/vncinput.hh"
frame_capture = Param.Bool(False, "capture changed frames to files")
img_format = Param.ImageFormat(
"Bitmap", "Format of the dumped Framebuffer"
)
class VncServer(VncInput):
type = 'VncServer'

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2015 ARM Limited
* Copyright (c) 2010, 2015, 2017 ARM Limited
* All rights reserved
*
* The license below extends only to copyright in the software and shall
@@ -48,6 +48,7 @@
#include "base/misc.hh"
#include "base/output.hh"
#include "base/trace.hh"
#include "debug/VNC.hh"
@@ -58,7 +59,8 @@ VncInput::VncInput(const Params *p)
fb(&FrameBuffer::dummy),
_videoWidth(fb->width()), _videoHeight(fb->height()),
captureEnabled(p->frame_capture),
captureCurrentFrame(0), captureLastHash(0)
captureCurrentFrame(0), captureLastHash(0),
imgFormat(p->img_format)
{
if (captureEnabled) {
// remove existing frame output directory if it exists, then create a
@@ -78,9 +80,11 @@ VncInput::setFrameBuffer(const FrameBuffer *rfb)
fb = rfb;
// create bitmap of the frame with new attributes
if (captureEnabled)
captureBitmap.reset(new Bitmap(rfb));
// Create the Image Writer object in charge of dumping
// the frame buffer raw data into a file in a specific format.
if (captureEnabled) {
captureImage = createImgWriter(imgFormat, rfb);
}
// Setting a new frame buffer means that we need to send an update
// to the client. Mark the internal buffers as dirty to do so.
@@ -110,7 +114,7 @@ VncInput::setDirty()
void
VncInput::captureFrameBuffer()
{
assert(captureBitmap);
assert(captureImage);
// skip identical frames
uint64_t new_hash = fb->getHash();
@@ -120,13 +124,14 @@ VncInput::captureFrameBuffer()
// get the filename for the current frame
char frameFilenameBuffer[64];
snprintf(frameFilenameBuffer, 64, "fb.%06d.%lld.bmp.gz",
captureCurrentFrame, static_cast<long long int>(curTick()));
snprintf(frameFilenameBuffer, 64, "fb.%06d.%lld.%s.gz",
captureCurrentFrame, static_cast<long long int>(curTick()),
captureImage->getImgExtension());
const string frameFilename(frameFilenameBuffer);
// create the compressed framebuffer file
OutputStream *fb_out(captureOutputDirectory->create(frameFilename, true));
captureBitmap->write(*fb_out->stream());
captureImage->write(*fb_out->stream());
captureOutputDirectory->close(fb_out);
++captureCurrentFrame;

View File

@@ -48,7 +48,7 @@
#include <iostream>
#include <memory>
#include "base/bitmap.hh"
#include "base/imgwriter.hh"
#include "params/VncInput.hh"
#include "sim/sim_object.hh"
@@ -226,8 +226,11 @@ class VncInput : public SimObject
/** Computed hash of the last captured frame */
uint64_t captureLastHash;
/** Cached bitmap object for writing out frame buffers to file */
std::unique_ptr<Bitmap> captureBitmap;
/** Cached ImgWriter object for writing out frame buffers to file */
std::unique_ptr<ImgWriter> captureImage;
/** image format */
Enums::ImageFormat imgFormat;
/** Captures the current frame buffer to a file */
void captureFrameBuffer();

View File

@@ -64,7 +64,6 @@
#include <cstdio>
#include "base/atomicio.hh"
#include "base/bitmap.hh"
#include "base/misc.hh"
#include "base/output.hh"
#include "base/socket.hh"

View File

@@ -48,7 +48,6 @@
#include <iostream>
#include "base/vnc/vncinput.hh"
#include "base/bitmap.hh"
#include "base/circlebuf.hh"
#include "base/pollevent.hh"
#include "base/socket.hh"

View File

@@ -79,7 +79,7 @@
#include <fstream>
#include <memory>
#include "base/bitmap.hh"
#include "base/bmpwriter.hh"
#include "base/framebuffer.hh"
#include "base/output.hh"
#include "dev/arm/amba_device.hh"
@@ -350,7 +350,7 @@ class HDLcd: public AmbaDmaDevice
EventFunctionWrapper virtRefreshEvent;
/** Helper to write out bitmaps */
Bitmap bmp;
BmpWriter bmp;
/** Picture of what the current frame buffer looks like */
OutputStream *pic;

View File

@@ -49,7 +49,7 @@
#include <fstream>
#include <memory>
#include "base/bitmap.hh"
#include "base/bmpwriter.hh"
#include "base/framebuffer.hh"
#include "base/output.hh"
#include "dev/arm/amba_device.hh"
@@ -266,7 +266,7 @@ class Pl111: public AmbaDmaDevice
VncInput *vnc;
/** Helper to write out bitmaps */
Bitmap bmp;
BmpWriter bmp;
/** Picture of what the current frame buffer looks like */
OutputStream *pic;