2
// Copyright ļæ½ 1997 - 2001, Paul C. Gregory
4
// Contact: pgregory@aqsis.com
6
// This library is free software; you can redistribute it and/or
7
// modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation; either
9
// version 2 of the License, or (at your option) any later version.
11
// This library is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
// General Public License for more details.
16
// You should have received a copy of the GNU General Public
17
// License along with this library; if not, write to the Free Software
18
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
\brief Simple example display device manager.
23
\author Paul C. Gregory (pgregory@aqsis.com)
30
#include "irenderer.h"
31
#include "ddmsimple.h"
32
#include "imagebuffer.h"
36
START_NAMESPACE( Aqsis )
38
/// Required function that implements Class Factory design pattern for DDManager libraries
39
IqDDManager* CreateDisplayDriverManager()
41
return new CqDDManagerSimple;
44
//---------------------------------------------------------------------
45
/** Initialise the device manager.
48
TqInt CqDDManagerSimple::Initialise()
53
TqInt CqDDManagerSimple::Shutdown()
59
TqInt CqDDManagerSimple::AddDisplay( const TqChar* name, const TqChar* type, const TqChar* mode, TqInt modeID, TqInt dataOffset, TqInt dataSize, std::map<std::string, void*> mapOfArguments )
61
m_aDisplayRequests.push_back( SqDDevice( name, type, mode ) );
65
TqInt CqDDManagerSimple::ClearDisplays()
67
m_aDisplayRequests.clear();
71
TqInt CqDDManagerSimple::OpenDisplays()
73
std::vector<SqDDevice>::iterator i;
74
for ( i = m_aDisplayRequests.begin(); i != m_aDisplayRequests.end(); i++ )
76
i->m_XRes = QGetRenderContext() ->pImage() ->iXRes();
77
i->m_YRes = QGetRenderContext() ->pImage() ->iYRes();
79
if ( strstr( i->m_strMode.c_str(), RI_RGB ) != NULL )
81
if ( strstr( i->m_strMode.c_str(), RI_A ) != NULL )
83
if ( strstr( i->m_strMode.c_str(), RI_Z ) != NULL )
85
TqInt SamplesPerElement = mode & ModeRGB ? 3 : 0;
86
SamplesPerElement += mode & ModeA ? 1 : 0;
87
SamplesPerElement = mode & ModeZ ? 1 : SamplesPerElement;
88
i->m_SamplesPerElement = SamplesPerElement;
90
// Create a buffer big enough to hold a row of buckets.
91
i->m_pData = new unsigned char[ i->m_XRes * i->m_YRes * i->m_SamplesPerElement ];
96
TqInt CqDDManagerSimple::CloseDisplays()
98
std::vector<SqDDevice>::iterator i;
100
i = m_aDisplayRequests.begin();
102
for ( ; i != m_aDisplayRequests.end(); i++ )
104
uint16 photometric = PHOTOMETRIC_RGB;
105
uint16 config = PLANARCONFIG_CONTIG;
107
TIFF* pOut = TIFFOpen( i->m_strName.c_str(), "w" );
111
// Write the image to a tiff file.
113
int ExtraSamplesTypes[ 1 ] = {EXTRASAMPLE_ASSOCALPHA};
115
TIFFSetField( pOut, TIFFTAG_IMAGEWIDTH, ( uint32 ) i->m_XRes );
116
TIFFSetField( pOut, TIFFTAG_IMAGELENGTH, ( uint32 ) i->m_YRes );
117
TIFFSetField( pOut, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT );
118
TIFFSetField( pOut, TIFFTAG_SAMPLESPERPIXEL, i->m_SamplesPerElement );
119
TIFFSetField( pOut, TIFFTAG_BITSPERSAMPLE, 8 );
120
TIFFSetField( pOut, TIFFTAG_PLANARCONFIG, config );
121
//TIFFSetField( pOut, TIFFTAG_COMPRESSION, compression );
122
//if ( compression == COMPRESSION_JPEG )
123
//TIFFSetField( pOut, TIFFTAG_JPEGQUALITY, quality );
124
TIFFSetField( pOut, TIFFTAG_PHOTOMETRIC, photometric );
125
TIFFSetField( pOut, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize( pOut, 0 ) );
127
if ( i->m_SamplesPerElement == 4 )
128
TIFFSetField( pOut, TIFFTAG_EXTRASAMPLES, 1, ExtraSamplesTypes );
130
// Set the position tages in case we aer dealing with a cropped image.
131
//TIFFSetField(pOut, TIFFTAG_XPOSITION, (float)CWXMin);
132
//TIFFSetField(pOut, TIFFTAG_YPOSITION, (float)CWYMin);
134
TqInt linelen = i->m_XRes * i->m_SamplesPerElement;
136
for ( row = 0; row < i->m_YRes; row++ )
138
if ( TIFFWriteScanline( pOut, i->m_pData + ( row * linelen ), row, 0 ) < 0 )
149
TqInt CqDDManagerSimple::DisplayBucket( IqBucket* pBucket )
151
std::vector<SqDDevice>::iterator i;
152
for ( i = m_aDisplayRequests.begin(); i != m_aDisplayRequests.end(); i++ )
154
TqInt xmin = pBucket->XOrigin();
155
TqInt ymin = pBucket->YOrigin();
156
TqInt xsize = pBucket->Width();
157
TqInt ysize = pBucket->Height();
159
for ( std::vector<SqDDevice>::iterator i = m_aDisplayRequests.begin(); i != m_aDisplayRequests.end(); i++ )
161
TqInt samples = i->m_SamplesPerElement;
162
TqInt linelen = i->m_XRes * samples;
165
if ( strstr( i->m_strMode.c_str(), RI_RGB ) != NULL )
167
if ( strstr( i->m_strMode.c_str(), RI_A ) != NULL )
169
if ( strstr( i->m_strMode.c_str(), RI_Z ) != NULL )
172
SqImageSample val( QGetRenderContext()->GetOutputDataTotalSize() );
174
for ( y = 0; y < ysize; y++ )
178
for ( x = 0; x < xsize; x++ )
181
TqInt so = ( sy * linelen ) + ( sx * samples );
182
// If outputting a zfile, use the midpoint method.
183
/// \todo Should really be generalising this section to use specif Filter/Expose/Quantize functions.
186
i->m_pData[ so ] = static_cast<unsigned char>( pBucket->Depth( sx, sy ) );
192
CqColor col = pBucket->Color( sx, sy );
193
i->m_pData[ so + 0 ] = static_cast<unsigned char>( col.fRed() );
194
i->m_pData[ so + 1 ] = static_cast<unsigned char>( col.fGreen() );
195
i->m_pData[ so + 2 ] = static_cast<unsigned char>( col.fBlue() );
198
CqColor o = pBucket->Opacity( sx, sy );
199
TqFloat a = ( o.fRed() + o.fGreen() + o.fBlue() ) / 3.0f;
200
i->m_pData[ so + 3 ] = static_cast<unsigned char>( a * pBucket->Coverage( sx, sy ) );
203
else if ( samples == 1 )
205
CqColor o = pBucket->Opacity( sx, sy );
206
TqFloat a = ( o.fRed() + o.fGreen() + o.fBlue() ) / 3.0f;
207
i->m_pData[ so + 0 ] = static_cast<unsigned char>( a * pBucket->Coverage( sx, sy ) );
217
TqBool CqDDManagerSimple::fDisplayNeeds( const TqChar* var )
219
if ( strcmp( var, "rgba" ) == 0 )
221
else if ( strcmp( var, "rgb" ) == 0 )
223
else if ( strcmp( var, "a" ) == 0 )
230
END_NAMESPACE( Aqsis )