comparison trunk/src/Modules/Output/Graphics/Devices/GraphicsOutputDeviceCairo.h @ 397:7a573750b186

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