annotate trunk/src/Modules/Output/Graphics/Devices/GraphicsOutputDeviceCairo.h @ 399:7bfed53caacf

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