annotate src/Modules/Output/Graphics/Devices/GraphicsOutputDeviceCairo.h @ 175:384b794cf81f

- AWS
author tomwalters
date Wed, 11 Aug 2010 09:15:53 +0000
parents 48e5fc566441
children 73c6d61440ad
rev   line source
tomwalters@116 1 // Copyright 2007, Thomas Walters
tomwalters@116 2 //
tomwalters@116 3 // AIM-C: A C++ implementation of the Auditory Image Model
tomwalters@116 4 // http://www.acousticscale.org/AIMC
tomwalters@116 5 //
tomwalters@116 6 // Licensed under the Apache License, Version 2.0 (the "License");
tomwalters@116 7 // you may not use this file except in compliance with the License.
tomwalters@116 8 // You may obtain a copy of the License at
tomwalters@116 9 //
tomwalters@116 10 // http://www.apache.org/licenses/LICENSE-2.0
tomwalters@116 11 //
tomwalters@116 12 // Unless required by applicable law or agreed to in writing, software
tomwalters@116 13 // distributed under the License is distributed on an "AS IS" BASIS,
tomwalters@116 14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
tomwalters@116 15 // See the License for the specific language governing permissions and
tomwalters@116 16 // limitations under the License.
tomwalters@116 17
tomwalters@116 18 /*!
tomwalters@116 19 * \file
tomwalters@116 20 * \brief Output device for output to a graphics file using cairo
tomwalters@116 21 *
tomwalters@116 22 * \author Tom Walters <tom@acousticscale.org> and Willem van Engen <cnbh@willem.engen.nl>
tomwalters@116 23 * \date created 2007/09/17
tomwalters@116 24 * \version \$Header: $
tomwalters@116 25 */
tomwalters@116 26
tomwalters@116 27 #ifndef __GRAPHICS_OUTPUT_DEVICE_CAIRO_H__
tomwalters@116 28 #define __GRAPHICS_OUTPUT_DEVICE_CAIRO_H__
tomwalters@116 29
tom@119 30 #include <string>
tom@119 31
tomwalters@116 32 #include <stdlib.h>
tomwalters@116 33 #include <stdio.h>
tomwalters@116 34
tomwalters@116 35 #include "cairo.h"
tomwalters@116 36
tomwalters@116 37 #include "Modules/Output/Graphics/Devices/GraphicsOutputDevice.h"
tomwalters@116 38
tom@118 39 namespace aimc {
tom@119 40 using std::string;
tomwalters@116 41 /*!
tomwalters@116 42 * \class GraphicsOutputDeviceCairo "Output/GraphicsOutputDeviceCairo.h"
tomwalters@116 43 * \brief Output class for output to a graphics file using Cairo
tomwalters@116 44 *
tomwalters@116 45 * This class outputs a graphics operation to file. It only supports 2d though,
tomwalters@116 46 * so the z-component is ignored.
tomwalters@116 47 */
tom@118 48 class GraphicsOutputDeviceCairo : public GraphicsOutputDevice {
tomwalters@116 49 public:
tomwalters@126 50 GraphicsOutputDeviceCairo(Parameters *parameters);
tomwalters@116 51 virtual ~GraphicsOutputDeviceCairo();
tomwalters@116 52
tomwalters@117 53 /*! \brief Initializes this output device, prepares plotting tools.
tomwalters@117 54 * \param sDir Directory or filename where to put images, max length is
tomwalters@126 55 * _MAX_PATH. Must end with slash.
tomwalters@117 56 * \return true on success, false on failure.
tomwalters@117 57 *
tomwalters@117 58 * sDir can be either a filename, in which case the output will be
tomwalters@117 59 * to that file, or a directory, in which case it will be filled
tomwalters@117 60 * with 6-digit numbered files. A new file is then created at every
tomwalters@117 61 * call to gGrab().
tomwalters@117 62 *
tomwalters@117 63 * As usual, make sure to call this function before any other. If this
tomwalters@117 64 * Initialize() failed, you shouldn't try the other functions either.
tomwalters@117 65 */
tomwalters@126 66 bool Initialize(string directory);
tomwalters@145 67 virtual bool Initialize(Parameters *global_parameters);
tomwalters@145 68
tomwalters@116 69 void gGrab();
tomwalters@116 70 void gBeginLineStrip();
tomwalters@116 71 void gBeginQuadStrip();
tomwalters@117 72 using GraphicsOutputDevice::gVertex3f; // Because we overload it
tomwalters@117 73 void gVertex3f(float x, float y, float z);
tomwalters@117 74 void gColor3f(float r, float g, float b);
tomwalters@116 75 void gEnd();
tomwalters@117 76 void gText3f(float x, float y, float z, const char *sStr, bool bRotated = false);
tomwalters@117 77 void gRelease();
tomwalters@117 78 unsigned char* GetBuffer();
tomwalters@117 79 int GetPixelFormat();
tomwalters@145 80 virtual void Reset(Parameters* global_parameters);
tomwalters@116 81 protected:
tomwalters@116 82 /*! \brief Internal initialisation
tomwalters@116 83 *
tomwalters@116 84 */
tomwalters@145 85 void InitialzeInternal();
tomwalters@116 86
tomwalters@117 87 /*! \brief Open the file with given index for output
tomwalters@117 88 * \param index File number to open
tomwalters@117 89 * \return true on success, false on error
tomwalters@117 90 *
tomwalters@117 91 * This opens a file for output and sets up the plotting library.
tomwalters@117 92 */
tomwalters@117 93 bool OpenFile(unsigned int index);
tomwalters@116 94
tomwalters@117 95 //! \brief Closes a plot output file, if any is open.
tomwalters@117 96 void CloseFile();
tomwalters@116 97
tomwalters@117 98 //! \brief Set to true if the input file can be written to
tomwalters@117 99 bool m_bOutputFile;
tomwalters@117 100 //! \brief Output directory
tomwalters@126 101 string directory_;
tomwalters@117 102 //! \brief Current file number
tomwalters@117 103 unsigned int m_iFileNumber;
tomwalters@117 104 //! \brief true if this is the first vertex after gBegin()
tomwalters@117 105 bool m_bIsFirstVertex;
tomwalters@116 106
tomwalters@117 107 enum VertexType {
tomwalters@117 108 VertexTypeNone,
tomwalters@116 109 VertexTypeLine,
tomwalters@116 110 VertexTypeQuad
tomwalters@117 111 };
tomwalters@117 112 //! \brief The current vertex type
tomwalters@117 113 VertexType m_iVertexType;
tomwalters@117 114 //! \brief Begin vertex of current quad
tomwalters@117 115 float m_aPrevX[3], m_aPrevY[3];
tomwalters@117 116 //! \brief Current number of quad vertices stored
tomwalters@117 117 unsigned int m_iPrevVertexCount;
tomwalters@116 118
tomwalters@117 119 //! \brief Whether to invert the colors or not
tomwalters@117 120 bool m_bInvertColors;
tomwalters@116 121
tomwalters@116 122 //! \brief Cairo Drawing Surface
tomwalters@116 123 cairo_surface_t *m_cSurface;
tomwalters@116 124
tomwalters@116 125 //! \brief Cairo Context
tomwalters@117 126 cairo_t *m_cCr;
tomwalters@116 127
tomwalters@116 128 //! \brief Internal store for the input filename
tomwalters@126 129 string image_filename_;
tomwalters@116 130
tomwalters@117 131 unsigned int m_iWidth;
tomwalters@117 132 unsigned int m_iHeight;
tomwalters@117 133 bool m_bUseMemoryBuffer;
tomwalters@116 134 };
tom@118 135 } // namespace aimc
tomwalters@116 136 #endif /* __GRAPHICS_OUTPUT_DEVICE_CAIRO_H__ */