21#include <tqdatastream.h>
25#include <tqvaluelist.h>
27#include <kgenericfactory.h>
29#include <KoFilterChain.h>
40const unsigned XcfExport::m_tileWidth = 64;
41const unsigned XcfExport::m_tileHeight = 64;
44typedef KGenericFactory<XcfExport, KoFilter> XcfExportFactory;
45K_EXPORT_COMPONENT_FACTORY( libkarbonxcfexport, XcfExportFactory(
"kofficefilters" ) )
48XcfExport::XcfExport( KoFilter*, const
char*, const TQStringList& )
55KoFilter::ConversionStatus
56XcfExport::convert(
const TQCString& from,
const TQCString& to )
58 if( to !=
"image/x-xcf-gimp" || from !=
"application/x-karbon" )
60 return KoFilter::NotImplemented;
64 KoStoreDevice* storeIn = m_chain->storageFile(
"root", KoStore::Read );
67 return KoFilter::StupidError;
70 TQFile fileOut( m_chain->outputFile() );
72 if( !fileOut.open( IO_WriteOnly ) )
73 return KoFilter::StupidError;
77 domIn.setContent( storeIn );
78 TQDomElement docNode = domIn.documentElement();
80 m_stream =
new TQDataStream( &fileOut );
98XcfExport::visitVDocument( VDocument& document )
101 TQIODevice::Offset current = 0;
102 TQIODevice::Offset start = 0;
103 TQIODevice::Offset end = 0;
106 m_width =
static_cast<unsigned>( document.width() * m_zoomX );
107 m_height =
static_cast<unsigned>( document.height() * m_zoomY );
111 m_stream->writeRawBytes(
"gimp xcf file", 14 );
114 *m_stream << static_cast<TQ_UINT32>( m_width );
117 *m_stream << static_cast<TQ_UINT32>( m_height );
120 *m_stream << static_cast<TQ_UINT32>( 0 );
125 <<
static_cast<TQ_UINT32
>( 0 )
127 <<
static_cast<TQ_UINT32
>( 0 );
131 current = m_stream->device()->at();
134 m_stream->device()->at(
136 current + ( document.layers().count() + 3 + 2 ) * 4 );
140 VLayerListIterator itr( document.layers() );
142 for( ; itr.current(); ++itr )
145 start = m_stream->device()->at();
149 itr.current()->accept( *
this );
153 end = m_stream->device()->at();
156 m_stream->device()->at( current );
162 current = m_stream->device()->at();
165 m_stream->device()->at( end );
170 m_stream->device()->at( current );
173 *m_stream << static_cast<TQ_UINT32>( 0 );
177 m_stream->device()->at( end );
180 *m_stream << static_cast<TQ_UINT32>( 0 );
184XcfExport::visitVLayer( VLayer& layer )
187 *m_stream << static_cast<TQ_UINT32>( m_width );
190 *m_stream << static_cast<TQ_UINT32>( m_height );
193 *m_stream << static_cast<TQ_UINT32>( 1 );
196 *m_stream << layer.name().latin1();
199 *m_stream << static_cast<TQ_UINT32>( 6 );
201 *m_stream << static_cast<TQ_UINT32>( 4 );
203 *m_stream << static_cast<TQ_UINT32>( 255 );
206 *m_stream << static_cast<TQ_UINT32>( 8 );
208 *m_stream << static_cast<TQ_UINT32>( 4 );
210 *m_stream << static_cast<TQ_UINT32>( 1 );
213 *m_stream << static_cast<TQ_UINT32>( 9 );
215 *m_stream << static_cast<TQ_UINT32>( 4 );
217 *m_stream << static_cast<TQ_UINT32>( 0 );
220 *m_stream << static_cast<TQ_UINT32>( 10 );
222 *m_stream << static_cast<TQ_UINT32>( 4 );
224 *m_stream << static_cast<TQ_UINT32>( 0 );
227 *m_stream << static_cast<TQ_UINT32>( 11 );
229 *m_stream << static_cast<TQ_UINT32>( 4 );
231 *m_stream << static_cast<TQ_UINT32>( 0 );
234 *m_stream << static_cast<TQ_UINT32>( 12 );
236 *m_stream << static_cast<TQ_UINT32>( 4 );
238 *m_stream << static_cast<TQ_UINT32>( 0 );
241 *m_stream << static_cast<TQ_UINT32>( 13 );
243 *m_stream << static_cast<TQ_UINT32>( 4 );
245 *m_stream << static_cast<TQ_UINT32>( 0 );
248 *m_stream << static_cast<TQ_UINT32>( 15 );
250 *m_stream << static_cast<TQ_UINT32>( 8 );
252 *m_stream << static_cast<TQ_UINT32>( 0 );
254 *m_stream << static_cast<TQ_UINT32>( 0 );
257 *m_stream << static_cast<TQ_UINT32>( 7 );
259 *m_stream << static_cast<TQ_UINT32>( 4 );
261 *m_stream << static_cast<TQ_UINT32>( 0 );
264 *m_stream << static_cast<TQ_UINT32>( 20 );
266 *m_stream << static_cast<TQ_UINT32>( 4 );
268 *m_stream << static_cast<TQ_UINT32>( 0 );
271 *m_stream << static_cast<TQ_UINT32>( 0 );
273 *m_stream << static_cast<TQ_UINT32>( 0 );
277 TQIODevice::Offset current = 0;
278 TQIODevice::Offset start = 0;
279 TQIODevice::Offset end = 0;
282 current = m_stream->device()->at();
285 m_stream->device()->at( current + 8 );
288 start = m_stream->device()->at();
296 end = m_stream->device()->at();
299 m_stream->device()->at( current );
306 *m_stream << static_cast<TQ_UINT32>( 0 );
310XcfExport::writeHierarchy()
313 TQIODevice::Offset current = 0;
314 TQIODevice::Offset start = 0;
315 TQIODevice::Offset end = 0;
318 *m_stream << m_width;
321 *m_stream << m_height;
324 *m_stream << static_cast<TQ_UINT32>( 3 );
328 int levX = levels( m_width, m_tileWidth );
329 int levY = levels( m_height, m_tileHeight );
330 int levels = TQMAX( levX, levY );
333 int height = m_height;
336 current = m_stream->device()->at();
339 m_stream->device()->at( current + ( levels + 1 ) * 4 );
341 for(
int i = 0; i < levels; ++i )
344 start = m_stream->device()->at();
357 *m_stream << static_cast<TQ_UINT32>( width );
358 *m_stream << static_cast<TQ_UINT32>( height );
359 *m_stream << static_cast<TQ_UINT32>( 0 );
363 end = m_stream->device()->at();
366 m_stream->device()->at( current );
372 current = m_stream->device()->at();
375 m_stream->device()->at( end );
379 m_stream->device()->at( current );
382 *m_stream << static_cast<TQ_UINT32>( 0 );
386XcfExport::writeLevel()
389 TQIODevice::Offset current = 0;
390 TQIODevice::Offset start = 0;
391 TQIODevice::Offset end = 0;
393 *m_stream << static_cast<TQ_UINT32>( m_width );
394 *m_stream << static_cast<TQ_UINT32>( m_height );
396 int rows = ( m_height + m_tileHeight - 1 ) / m_tileHeight;
397 int cols = ( m_width + m_tileWidth - 1 ) / m_tileWidth;
398 int tiles = rows * cols;
401 current = m_stream->device()->at();
404 m_stream->device()->at( current + ( tiles + 1 ) * 4 );
406 for(
int i = 0; i < tiles; ++i )
409 start = m_stream->device()->at();
413 *m_stream << static_cast<TQ_UINT8>( 1 );
414 *m_stream << static_cast<TQ_UINT8>( 1 );
415 *m_stream << static_cast<TQ_UINT8>( 1 );
416 *m_stream << static_cast<TQ_UINT8>( 1 );
417 *m_stream << static_cast<TQ_UINT8>( 1 );
418 *m_stream << static_cast<TQ_UINT8>( 1 );
419 *m_stream << static_cast<TQ_UINT8>( 1 );
420 *m_stream << static_cast<TQ_UINT8>( 1 );
421 *m_stream << static_cast<TQ_UINT8>( 1 );
422 *m_stream << static_cast<TQ_UINT8>( 1 );
423 *m_stream << static_cast<TQ_UINT8>( 1 );
424 *m_stream << static_cast<TQ_UINT8>( 1 );
428 end = m_stream->device()->at();
431 m_stream->device()->at( current );
437 current = m_stream->device()->at();
440 m_stream->device()->at( end );
445XcfExport::levels(
int layerSize,
int tileSize )
449 while( layerSize > tileSize )
458#include "xcfexport.moc"