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
|
tom@400
|
30 #include <string>
|
tom@400
|
31
|
tomwalters@397
|
32 #include <stdlib.h>
|
tomwalters@397
|
33 #include <stdio.h>
|
tomwalters@397
|
34
|
tomwalters@397
|
35 #include "cairo.h"
|
tomwalters@397
|
36
|
tomwalters@397
|
37 #include "Modules/Output/Graphics/Devices/GraphicsOutputDevice.h"
|
tomwalters@397
|
38
|
tom@399
|
39 namespace aimc {
|
tom@400
|
40 using std::string;
|
tomwalters@397
|
41 /*!
|
tomwalters@397
|
42 * \class GraphicsOutputDeviceCairo "Output/GraphicsOutputDeviceCairo.h"
|
tomwalters@397
|
43 * \brief Output class for output to a graphics file using Cairo
|
tomwalters@397
|
44 *
|
tomwalters@397
|
45 * This class outputs a graphics operation to file. It only supports 2d though,
|
tomwalters@397
|
46 * so the z-component is ignored.
|
tomwalters@397
|
47 */
|
tom@399
|
48 class GraphicsOutputDeviceCairo : public GraphicsOutputDevice {
|
tomwalters@397
|
49 public:
|
tomwalters@411
|
50 GraphicsOutputDeviceCairo(Parameters *parameters);
|
tomwalters@397
|
51 virtual ~GraphicsOutputDeviceCairo();
|
tomwalters@397
|
52
|
tomwalters@398
|
53 /*! \brief Initializes this output device, prepares plotting tools.
|
tomwalters@398
|
54 * \param sDir Directory or filename where to put images, max length is
|
tomwalters@411
|
55 * _MAX_PATH. Must end with slash.
|
tomwalters@398
|
56 * \return true on success, false on failure.
|
tomwalters@398
|
57 *
|
tomwalters@398
|
58 * sDir can be either a filename, in which case the output will be
|
tomwalters@398
|
59 * to that file, or a directory, in which case it will be filled
|
tomwalters@398
|
60 * with 6-digit numbered files. A new file is then created at every
|
tomwalters@398
|
61 * call to gGrab().
|
tomwalters@398
|
62 *
|
tomwalters@398
|
63 * As usual, make sure to call this function before any other. If this
|
tomwalters@398
|
64 * Initialize() failed, you shouldn't try the other functions either.
|
tomwalters@398
|
65 */
|
tomwalters@411
|
66 bool Initialize(string directory);
|
tomwalters@443
|
67 virtual bool Initialize(Parameters *global_parameters);
|
tomwalters@443
|
68
|
tomwalters@397
|
69 void gGrab();
|
tomwalters@397
|
70 void gBeginLineStrip();
|
tomwalters@397
|
71 void gBeginQuadStrip();
|
tomwalters@398
|
72 using GraphicsOutputDevice::gVertex3f; // Because we overload it
|
tomwalters@398
|
73 void gVertex3f(float x, float y, float z);
|
tomwalters@398
|
74 void gColor3f(float r, float g, float b);
|
tomwalters@397
|
75 void gEnd();
|
tomwalters@398
|
76 void gText3f(float x, float y, float z, const char *sStr, bool bRotated = false);
|
tomwalters@398
|
77 void gRelease();
|
tomwalters@398
|
78 unsigned char* GetBuffer();
|
tomwalters@398
|
79 int GetPixelFormat();
|
tomwalters@443
|
80 virtual void Reset(Parameters* global_parameters);
|
tomwalters@397
|
81 protected:
|
tomwalters@397
|
82 /*! \brief Internal initialisation
|
tomwalters@397
|
83 *
|
tomwalters@397
|
84 */
|
tomwalters@443
|
85 void InitialzeInternal();
|
tomwalters@397
|
86
|
tomwalters@398
|
87 /*! \brief Open the file with given index for output
|
tomwalters@398
|
88 * \param index File number to open
|
tomwalters@398
|
89 * \return true on success, false on error
|
tomwalters@398
|
90 *
|
tomwalters@398
|
91 * This opens a file for output and sets up the plotting library.
|
tomwalters@398
|
92 */
|
tomwalters@398
|
93 bool OpenFile(unsigned int index);
|
tomwalters@397
|
94
|
tomwalters@398
|
95 //! \brief Closes a plot output file, if any is open.
|
tomwalters@398
|
96 void CloseFile();
|
tomwalters@397
|
97
|
tomwalters@398
|
98 //! \brief Set to true if the input file can be written to
|
tomwalters@398
|
99 bool m_bOutputFile;
|
tomwalters@398
|
100 //! \brief Output directory
|
tomwalters@411
|
101 string directory_;
|
tomwalters@398
|
102 //! \brief Current file number
|
tomwalters@398
|
103 unsigned int m_iFileNumber;
|
tomwalters@398
|
104 //! \brief true if this is the first vertex after gBegin()
|
tomwalters@398
|
105 bool m_bIsFirstVertex;
|
tomwalters@397
|
106
|
tomwalters@398
|
107 enum VertexType {
|
tomwalters@398
|
108 VertexTypeNone,
|
tomwalters@397
|
109 VertexTypeLine,
|
tomwalters@397
|
110 VertexTypeQuad
|
tomwalters@398
|
111 };
|
tomwalters@398
|
112 //! \brief The current vertex type
|
tomwalters@398
|
113 VertexType m_iVertexType;
|
tomwalters@398
|
114 //! \brief Begin vertex of current quad
|
tomwalters@398
|
115 float m_aPrevX[3], m_aPrevY[3];
|
tomwalters@398
|
116 //! \brief Current number of quad vertices stored
|
tomwalters@398
|
117 unsigned int m_iPrevVertexCount;
|
tomwalters@397
|
118
|
tomwalters@398
|
119 //! \brief Whether to invert the colors or not
|
tomwalters@398
|
120 bool m_bInvertColors;
|
tomwalters@397
|
121
|
tomwalters@397
|
122 //! \brief Cairo Drawing Surface
|
tomwalters@397
|
123 cairo_surface_t *m_cSurface;
|
tomwalters@397
|
124
|
tomwalters@397
|
125 //! \brief Cairo Context
|
tomwalters@398
|
126 cairo_t *m_cCr;
|
tomwalters@397
|
127
|
tomwalters@397
|
128 //! \brief Internal store for the input filename
|
tomwalters@411
|
129 string image_filename_;
|
tomwalters@397
|
130
|
tomwalters@398
|
131 unsigned int m_iWidth;
|
tomwalters@398
|
132 unsigned int m_iHeight;
|
tomwalters@398
|
133 bool m_bUseMemoryBuffer;
|
tomwalters@397
|
134 };
|
tom@399
|
135 } // namespace aimc
|
tomwalters@397
|
136 #endif /* __GRAPHICS_OUTPUT_DEVICE_CAIRO_H__ */
|