tomwalters@116: // Copyright 2007, Thomas Walters tomwalters@116: // tomwalters@116: // AIM-C: A C++ implementation of the Auditory Image Model tomwalters@116: // http://www.acousticscale.org/AIMC tomwalters@116: // tomwalters@116: // Licensed under the Apache License, Version 2.0 (the "License"); tomwalters@116: // you may not use this file except in compliance with the License. tomwalters@116: // You may obtain a copy of the License at tomwalters@116: // tomwalters@116: // http://www.apache.org/licenses/LICENSE-2.0 tomwalters@116: // tomwalters@116: // Unless required by applicable law or agreed to in writing, software tomwalters@116: // distributed under the License is distributed on an "AS IS" BASIS, tomwalters@116: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. tomwalters@116: // See the License for the specific language governing permissions and tomwalters@116: // limitations under the License. tomwalters@116: tomwalters@116: /*! tomwalters@116: * \file tomwalters@116: * \brief Output device for output to a graphics file using cairo tomwalters@116: * tomwalters@116: * \author Tom Walters and Willem van Engen tomwalters@116: * \date created 2007/09/17 tomwalters@116: * \version \$Header: $ tomwalters@116: */ tomwalters@116: tomwalters@116: #ifndef __GRAPHICS_OUTPUT_DEVICE_CAIRO_H__ tomwalters@116: #define __GRAPHICS_OUTPUT_DEVICE_CAIRO_H__ tomwalters@116: tom@119: #include tom@119: tomwalters@116: #include tomwalters@116: #include tomwalters@116: tomwalters@116: #include "cairo.h" tomwalters@116: tomwalters@116: #include "Modules/Output/Graphics/Devices/GraphicsOutputDevice.h" tomwalters@116: tom@118: namespace aimc { tom@119: using std::string; tomwalters@116: /*! tomwalters@116: * \class GraphicsOutputDeviceCairo "Output/GraphicsOutputDeviceCairo.h" tomwalters@116: * \brief Output class for output to a graphics file using Cairo tomwalters@116: * tomwalters@116: * This class outputs a graphics operation to file. It only supports 2d though, tomwalters@116: * so the z-component is ignored. tomwalters@116: */ tom@118: class GraphicsOutputDeviceCairo : public GraphicsOutputDevice { tomwalters@116: public: tomwalters@126: GraphicsOutputDeviceCairo(Parameters *parameters); tomwalters@116: virtual ~GraphicsOutputDeviceCairo(); tomwalters@116: tomwalters@117: /*! \brief Initializes this output device, prepares plotting tools. tomwalters@117: * \param sDir Directory or filename where to put images, max length is tomwalters@126: * _MAX_PATH. Must end with slash. tomwalters@117: * \return true on success, false on failure. tomwalters@117: * tomwalters@117: * sDir can be either a filename, in which case the output will be tomwalters@117: * to that file, or a directory, in which case it will be filled tomwalters@117: * with 6-digit numbered files. A new file is then created at every tomwalters@117: * call to gGrab(). tomwalters@117: * tomwalters@117: * As usual, make sure to call this function before any other. If this tomwalters@117: * Initialize() failed, you shouldn't try the other functions either. tomwalters@117: */ tomwalters@126: bool Initialize(string directory); tomwalters@145: virtual bool Initialize(Parameters *global_parameters); tomwalters@145: tomwalters@116: void gGrab(); tomwalters@116: void gBeginLineStrip(); tomwalters@116: void gBeginQuadStrip(); tomwalters@117: using GraphicsOutputDevice::gVertex3f; // Because we overload it tomwalters@117: void gVertex3f(float x, float y, float z); tomwalters@117: void gColor3f(float r, float g, float b); tomwalters@116: void gEnd(); tomwalters@117: void gText3f(float x, float y, float z, const char *sStr, bool bRotated = false); tomwalters@117: void gRelease(); tomwalters@117: unsigned char* GetBuffer(); tomwalters@117: int GetPixelFormat(); tomwalters@145: virtual void Reset(Parameters* global_parameters); tomwalters@116: protected: tomwalters@116: /*! \brief Internal initialisation tomwalters@116: * tomwalters@116: */ tomwalters@145: void InitialzeInternal(); tomwalters@116: tomwalters@117: /*! \brief Open the file with given index for output tomwalters@117: * \param index File number to open tomwalters@117: * \return true on success, false on error tomwalters@117: * tomwalters@117: * This opens a file for output and sets up the plotting library. tomwalters@117: */ tomwalters@117: bool OpenFile(unsigned int index); tomwalters@116: tomwalters@117: //! \brief Closes a plot output file, if any is open. tomwalters@117: void CloseFile(); tomwalters@116: tomwalters@117: //! \brief Set to true if the input file can be written to tomwalters@117: bool m_bOutputFile; tomwalters@117: //! \brief Output directory tomwalters@126: string directory_; tomwalters@117: //! \brief Current file number tomwalters@117: unsigned int m_iFileNumber; tomwalters@117: //! \brief true if this is the first vertex after gBegin() tomwalters@117: bool m_bIsFirstVertex; tomwalters@116: tomwalters@117: enum VertexType { tomwalters@117: VertexTypeNone, tomwalters@116: VertexTypeLine, tomwalters@116: VertexTypeQuad tomwalters@117: }; tomwalters@117: //! \brief The current vertex type tomwalters@117: VertexType m_iVertexType; tomwalters@117: //! \brief Begin vertex of current quad tomwalters@117: float m_aPrevX[3], m_aPrevY[3]; tomwalters@117: //! \brief Current number of quad vertices stored tomwalters@117: unsigned int m_iPrevVertexCount; tomwalters@116: tomwalters@117: //! \brief Whether to invert the colors or not tomwalters@117: bool m_bInvertColors; tomwalters@116: tomwalters@116: //! \brief Cairo Drawing Surface tomwalters@116: cairo_surface_t *m_cSurface; tomwalters@116: tomwalters@116: //! \brief Cairo Context tomwalters@117: cairo_t *m_cCr; tomwalters@116: tomwalters@116: //! \brief Internal store for the input filename tomwalters@126: string image_filename_; tomwalters@116: tomwalters@117: unsigned int m_iWidth; tomwalters@117: unsigned int m_iHeight; tomwalters@117: bool m_bUseMemoryBuffer; tomwalters@116: }; tom@118: } // namespace aimc tomwalters@116: #endif /* __GRAPHICS_OUTPUT_DEVICE_CAIRO_H__ */