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