pngwriter.hh revision 12230
16019Shines@cs.fsu.edu/* 27093Sgblack@eecs.umich.edu * Copyright (c) 2017 ARM Limited 37093Sgblack@eecs.umich.edu * All rights reserved 47093Sgblack@eecs.umich.edu * 57093Sgblack@eecs.umich.edu * The license below extends only to copyright in the software and shall 67093Sgblack@eecs.umich.edu * not be construed as granting a license to any other intellectual 77093Sgblack@eecs.umich.edu * property including but not limited to intellectual property relating 87093Sgblack@eecs.umich.edu * to a hardware implementation of the functionality of the software 97093Sgblack@eecs.umich.edu * licensed hereunder. You may use the software subject to the license 107093Sgblack@eecs.umich.edu * terms below provided that you ensure that this notice is replicated 117093Sgblack@eecs.umich.edu * unmodified and in its entirety in all distributions of the software, 127093Sgblack@eecs.umich.edu * modified or unmodified, in source code or in binary form. 137093Sgblack@eecs.umich.edu * 146019Shines@cs.fsu.edu * Redistribution and use in source and binary forms, with or without 156019Shines@cs.fsu.edu * modification, are permitted provided that the following conditions are 166019Shines@cs.fsu.edu * met: redistributions of source code must retain the above copyright 176019Shines@cs.fsu.edu * notice, this list of conditions and the following disclaimer; 186019Shines@cs.fsu.edu * redistributions in binary form must reproduce the above copyright 196019Shines@cs.fsu.edu * notice, this list of conditions and the following disclaimer in the 206019Shines@cs.fsu.edu * documentation and/or other materials provided with the distribution; 216019Shines@cs.fsu.edu * neither the name of the copyright holders nor the names of its 226019Shines@cs.fsu.edu * contributors may be used to endorse or promote products derived from 236019Shines@cs.fsu.edu * this software without specific prior written permission. 246019Shines@cs.fsu.edu * 256019Shines@cs.fsu.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 266019Shines@cs.fsu.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 276019Shines@cs.fsu.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 286019Shines@cs.fsu.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 296019Shines@cs.fsu.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 306019Shines@cs.fsu.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 316019Shines@cs.fsu.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 326019Shines@cs.fsu.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 336019Shines@cs.fsu.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 346019Shines@cs.fsu.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 356019Shines@cs.fsu.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 366019Shines@cs.fsu.edu * 376019Shines@cs.fsu.edu * Authors: Giacomo Travaglini 386019Shines@cs.fsu.edu */ 396019Shines@cs.fsu.edu 407399SAli.Saidi@ARM.com/** 417399SAli.Saidi@ARM.com * @file Declaration of a class that writes a frame buffer to a png 426019Shines@cs.fsu.edu */ 436019Shines@cs.fsu.edu 446019Shines@cs.fsu.edu#ifndef __BASE_PNG_HH__ 456019Shines@cs.fsu.edu#define __BASE_PNG_HH__ 466019Shines@cs.fsu.edu 476019Shines@cs.fsu.edu#include "base/compiler.hh" 486116Snate@binkert.org#include "base/framebuffer.hh" 496019Shines@cs.fsu.edu#include "base/imgwriter.hh" 506019Shines@cs.fsu.edu 516019Shines@cs.fsu.edu/** Image writer implementing support for PNG */ 526019Shines@cs.fsu.educlass PngWriter : public ImgWriter 536019Shines@cs.fsu.edu{ 546019Shines@cs.fsu.edu public: 556019Shines@cs.fsu.edu /** 568232Snate@binkert.org * Create a png that takes data in a given mode & size and 578232Snate@binkert.org * outputs to an ostream. 588232Snate@binkert.org */ 596116Snate@binkert.org PngWriter(const FrameBuffer *_fb) 606116Snate@binkert.org : ImgWriter(_fb) 616019Shines@cs.fsu.edu {} 626019Shines@cs.fsu.edu 637406SAli.Saidi@ARM.com ~PngWriter() {}; 647406SAli.Saidi@ARM.com 657406SAli.Saidi@ARM.com /** 667406SAli.Saidi@ARM.com * Return Image format as a string 676019Shines@cs.fsu.edu * 686019Shines@cs.fsu.edu * @return img extension (e.g. .png for Png) 696019Shines@cs.fsu.edu */ 706019Shines@cs.fsu.edu const char* getImgExtension() const override 717697SAli.Saidi@ARM.com { return _imgExtension; } 727404SAli.Saidi@ARM.com 737404SAli.Saidi@ARM.com /** 747404SAli.Saidi@ARM.com * Write the frame buffer data into the provided ostream 757749SAli.Saidi@ARM.com * 766019Shines@cs.fsu.edu * @param png stream to write to 777404SAli.Saidi@ARM.com */ 787404SAli.Saidi@ARM.com void write(std::ostream &png) const override; 797399SAli.Saidi@ARM.com private: 807406SAli.Saidi@ARM.com /** Png Pixel type: not containing padding */ 817404SAli.Saidi@ARM.com struct PngPixel24 { 827406SAli.Saidi@ARM.com PngPixel24 &operator=(const Pixel &rhs) { 836019Shines@cs.fsu.edu red = rhs.red; 846019Shines@cs.fsu.edu green = rhs.green; 856019Shines@cs.fsu.edu blue = rhs.blue; 866019Shines@cs.fsu.edu 876019Shines@cs.fsu.edu return *this; 886019Shines@cs.fsu.edu } 896019Shines@cs.fsu.edu uint8_t red; 906019Shines@cs.fsu.edu uint8_t green; 917694SAli.Saidi@ARM.com uint8_t blue; 927694SAli.Saidi@ARM.com } M5_ATTR_PACKED; 937694SAli.Saidi@ARM.com 947749SAli.Saidi@ARM.com /** 957749SAli.Saidi@ARM.com * Handle to resources used by libpng: 967749SAli.Saidi@ARM.com * - png_struct: Structure holding write informations 977694SAli.Saidi@ARM.com * - png_info : Structure holding image informations 987694SAli.Saidi@ARM.com * 997694SAli.Saidi@ARM.com * The class is automatically taking care of struct 1007694SAli.Saidi@ARM.com * allocation/deallocation 1017694SAli.Saidi@ARM.com */ 1027694SAli.Saidi@ARM.com struct PngStructHandle; 1037404SAli.Saidi@ARM.com 1047694SAli.Saidi@ARM.com typedef PngPixel24 PixelType; 1056019Shines@cs.fsu.edu 1067404SAli.Saidi@ARM.com static const char* _imgExtension; 1077404SAli.Saidi@ARM.com}; 1087404SAli.Saidi@ARM.com 1097697SAli.Saidi@ARM.com#endif // __BASE_PNG_HH__ 1107404SAli.Saidi@ARM.com