1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 #include <tools/stream.hxx>
23 #include <tools/fract.hxx>
24 #include <vcl/outdev.hxx>
25 #include <vcl/graphicfilter.hxx>
26 #include <unotools/ucbstreamhelper.hxx>
27 #include "graphicfilter_internal.hxx"
31 GraphicDescriptor::GraphicDescriptor( const INetURLObject
& rPath
) :
32 pFileStm( ::utl::UcbStreamHelper::CreateStream( rPath
.GetMainURL( INetURLObject::NO_DECODE
), StreamMode::READ
) ),
33 aPathExt( rPath
.GetFileExtension().toAsciiLowerCase() ),
39 GraphicDescriptor::GraphicDescriptor( SvStream
& rInStream
, const OUString
* pPath
) :
40 pFileStm ( &rInStream
),
47 INetURLObject
aURL( *pPath
);
48 aPathExt
= aURL
.GetFileExtension().toAsciiLowerCase();
52 GraphicDescriptor::~GraphicDescriptor()
58 bool GraphicDescriptor::Detect( bool bExtendedInfo
)
61 if ( pFileStm
&& !pFileStm
->GetError() )
63 SvStream
& rStm
= *pFileStm
;
64 SvStreamEndian nOldFormat
= rStm
.GetEndian();
66 if ( ImpDetectGIF( rStm
, bExtendedInfo
) ) bRet
= true;
67 else if ( ImpDetectJPG( rStm
, bExtendedInfo
) ) bRet
= true;
68 else if ( ImpDetectBMP( rStm
, bExtendedInfo
) ) bRet
= true;
69 else if ( ImpDetectPNG( rStm
, bExtendedInfo
) ) bRet
= true;
70 else if ( ImpDetectTIF( rStm
, bExtendedInfo
) ) bRet
= true;
71 else if ( ImpDetectPCX( rStm
, bExtendedInfo
) ) bRet
= true;
72 else if ( ImpDetectDXF( rStm
, bExtendedInfo
) ) bRet
= true;
73 else if ( ImpDetectMET( rStm
, bExtendedInfo
) ) bRet
= true;
74 else if ( ImpDetectSGF( rStm
, bExtendedInfo
) ) bRet
= true;
75 else if ( ImpDetectSGV( rStm
, bExtendedInfo
) ) bRet
= true;
76 else if ( ImpDetectSVM( rStm
, bExtendedInfo
) ) bRet
= true;
77 else if ( ImpDetectWMF( rStm
, bExtendedInfo
) ) bRet
= true;
78 else if ( ImpDetectEMF( rStm
, bExtendedInfo
) ) bRet
= true;
79 else if ( ImpDetectSVG( rStm
, bExtendedInfo
) ) bRet
= true;
80 else if ( ImpDetectPCT( rStm
, bExtendedInfo
) ) bRet
= true;
81 else if ( ImpDetectXBM( rStm
, bExtendedInfo
) ) bRet
= true;
82 else if ( ImpDetectXPM( rStm
, bExtendedInfo
) ) bRet
= true;
83 else if ( ImpDetectPBM( rStm
, bExtendedInfo
) ) bRet
= true;
84 else if ( ImpDetectPGM( rStm
, bExtendedInfo
) ) bRet
= true;
85 else if ( ImpDetectPPM( rStm
, bExtendedInfo
) ) bRet
= true;
86 else if ( ImpDetectRAS( rStm
, bExtendedInfo
) ) bRet
= true;
87 else if ( ImpDetectTGA( rStm
, bExtendedInfo
) ) bRet
= true;
88 else if ( ImpDetectPSD( rStm
, bExtendedInfo
) ) bRet
= true;
89 else if ( ImpDetectEPS( rStm
, bExtendedInfo
) ) bRet
= true;
90 else if ( ImpDetectPCD( rStm
, bExtendedInfo
) ) bRet
= true;
92 rStm
.SetEndian( nOldFormat
);
97 void GraphicDescriptor::ImpConstruct()
99 nFormat
= GraphicFileFormat::NOT
;
105 bool GraphicDescriptor::ImpDetectBMP( SvStream
& rStm
, bool bExtendedInfo
)
107 sal_uInt16 nTemp16
= 0;
109 sal_Int32 nStmPos
= rStm
.Tell();
111 rStm
.SetEndian( SvStreamEndian::LITTLE
);
112 rStm
.ReadUInt16( nTemp16
);
115 if ( nTemp16
== 0x4142 )
117 rStm
.SeekRel( 0x0c );
118 rStm
.ReadUInt16( nTemp16
);
122 if ( nTemp16
== 0x4d42 )
124 nFormat
= GraphicFileFormat::BMP
;
130 sal_uInt32 nCompression
;
133 rStm
.SeekRel( 0x10 );
136 rStm
.ReadUInt32( nTemp32
);
137 aPixSize
.Width() = nTemp32
;
140 rStm
.ReadUInt32( nTemp32
);
141 aPixSize
.Height() = nTemp32
;
144 rStm
.ReadUInt16( nTemp16
);
148 rStm
.ReadUInt16( nTemp16
);
149 nBitsPerPixel
= nTemp16
;
152 rStm
.ReadUInt32( nTemp32
);
153 bCompressed
= ( ( nCompression
= nTemp32
) > 0 );
157 rStm
.ReadUInt32( nTemp32
);
159 aLogSize
.Width() = ( aPixSize
.Width() * 100000 ) / nTemp32
;
162 rStm
.ReadUInt32( nTemp32
);
164 aLogSize
.Height() = ( aPixSize
.Height() * 100000 ) / nTemp32
;
166 // further validation, check for rational values
167 if ( ( nBitsPerPixel
> 24 ) || ( nCompression
> 3 ) )
169 nFormat
= GraphicFileFormat::NOT
;
174 rStm
.Seek( nStmPos
);
178 bool GraphicDescriptor::ImpDetectGIF( SvStream
& rStm
, bool bExtendedInfo
)
185 sal_Int32 nStmPos
= rStm
.Tell();
186 rStm
.SetEndian( SvStreamEndian::LITTLE
);
187 rStm
.ReadUInt32( n32
);
189 if ( n32
== 0x38464947 )
191 rStm
.ReadUInt16( n16
);
192 if ( ( n16
== 0x6137 ) || ( n16
== 0x6139 ) )
194 nFormat
= GraphicFileFormat::GIF
;
199 sal_uInt16 nTemp16
= 0;
202 rStm
.ReadUInt16( nTemp16
);
203 aPixSize
.Width() = nTemp16
;
206 rStm
.ReadUInt16( nTemp16
);
207 aPixSize
.Height() = nTemp16
;
210 rStm
.ReadUChar( cByte
);
211 nBitsPerPixel
= ( ( cByte
& 112 ) >> 4 ) + 1;
215 rStm
.Seek( nStmPos
);
219 // returns the next jpeg marker, a return value of 0 represents an error
220 sal_uInt8
ImpDetectJPG_GetNextMarker( SvStream
& rStm
)
227 rStm
.ReadUChar( nByte
);
228 if ( rStm
.IsEof() || rStm
.GetError() ) // as 0 is not allowed as marker,
229 return 0; // we can use it as errorcode
231 while ( nByte
!= 0xff );
234 rStm
.ReadUChar( nByte
);
235 if ( rStm
.IsEof() || rStm
.GetError() )
238 while( nByte
== 0xff );
240 while( nByte
== 0 ); // 0xff00 represents 0xff and not a marker,
241 // the marker detection has to be restartet.
245 bool GraphicDescriptor::ImpDetectJPG( SvStream
& rStm
, bool bExtendedInfo
)
247 sal_uInt32 nTemp32
= 0;
250 sal_Int32 nStmPos
= rStm
.Tell();
252 rStm
.SetEndian( SvStreamEndian::BIG
);
253 rStm
.ReadUInt32( nTemp32
);
255 // compare upper 24 bits
256 if( 0xffd8ff00 == ( nTemp32
& 0xffffff00 ) )
258 nFormat
= GraphicFileFormat::JPG
;
265 sal_uInt32
nError( rStm
.GetError() );
267 bool bScanFailure
= false;
268 bool bScanFinished
= false;
270 while( !bScanFailure
&& !bScanFinished
&& !rStm
.IsEof() && !rStm
.GetError() )
272 sal_uInt8 nMarker
= ImpDetectJPG_GetNextMarker( rStm
);
275 // fixed size marker, not having a two byte length parameter
287 case 0xd8 : // SOI (has already been checked, there should not be a second one)
288 case 0x00 : // marker is invalid, we should stop now
293 bScanFinished
= true;
296 // per default we assume marker segments conaining a length parameter
299 sal_uInt16 nLength
= 0;
300 rStm
.ReadUInt16( nLength
);
306 sal_uInt32 nNextMarkerPos
= rStm
.Tell() + nLength
- 2;
309 case 0xe0 : // APP0 Marker
313 sal_Int32 nIdentifier
= 0;
314 rStm
.ReadInt32( nIdentifier
);
315 if ( nIdentifier
== 0x4a464946 ) // JFIF Identifier
317 sal_uInt8 nStringTerminator
= 0;
318 sal_uInt8 nMajorRevision
= 0;
319 sal_uInt8 nMinorRevision
= 0;
320 sal_uInt8 nUnits
= 0;
321 sal_uInt16 nHorizontalResolution
= 0;
322 sal_uInt16 nVerticalResolution
= 0;
323 sal_uInt8 nHorzThumbnailPixelCount
= 0;
324 sal_uInt8 nVertThumbnailPixelCount
= 0;
326 rStm
.ReadUChar( nStringTerminator
)
327 .ReadUChar( nMajorRevision
)
328 .ReadUChar( nMinorRevision
)
330 .ReadUInt16( nHorizontalResolution
)
331 .ReadUInt16( nVerticalResolution
)
332 .ReadUChar( nHorzThumbnailPixelCount
)
333 .ReadUChar( nVertThumbnailPixelCount
);
335 // setting the logical size
336 if ( nUnits
&& nHorizontalResolution
&& nVerticalResolution
)
339 aMap
.SetMapUnit( nUnits
== 1 ? MAP_INCH
: MAP_CM
);
340 aMap
.SetScaleX( Fraction( 1, nHorizontalResolution
) );
341 aMap
.SetScaleY( Fraction( 1, nVerticalResolution
) );
342 aLogSize
= OutputDevice::LogicToLogic( aPixSize
, aMap
, MapMode( MAP_100TH_MM
) );
349 // Start of Frame Markers
364 sal_uInt8 nSamplePrecision
= 0;
365 sal_uInt16 nNumberOfLines
= 0;
366 sal_uInt16 nSamplesPerLine
= 0;
367 sal_uInt8 nNumberOfImageComponents
= 0;
368 sal_uInt8 nComponentsIdentifier
= 0;
369 sal_uInt8 nHorizontalSamplingFactor
= 0;
370 sal_uInt8 nQuantizationTableDestinationSelector
= 0;
371 rStm
.ReadUChar( nSamplePrecision
)
372 .ReadUInt16( nNumberOfLines
)
373 .ReadUInt16( nSamplesPerLine
)
374 .ReadUChar( nNumberOfImageComponents
)
375 .ReadUChar( nComponentsIdentifier
)
376 .ReadUChar( nHorizontalSamplingFactor
)
377 .ReadUChar( nQuantizationTableDestinationSelector
);
378 nHorizontalSamplingFactor
>>= 4;
380 aPixSize
.Height() = nNumberOfLines
;
381 aPixSize
.Width() = nSamplesPerLine
;
382 nBitsPerPixel
= ( nNumberOfImageComponents
== 3 ? 24 : nNumberOfImageComponents
== 1 ? 8 : 0 );
385 bScanFinished
= true;
389 rStm
.Seek( nNextMarkerPos
);
395 rStm
.SetError( nError
);
398 rStm
.Seek( nStmPos
);
402 bool GraphicDescriptor::ImpDetectPCD( SvStream
& rStm
, bool )
406 sal_Int32 nStmPos
= rStm
.Tell();
407 rStm
.SetEndian( SvStreamEndian::LITTLE
);
409 sal_uInt32 nTemp32
= 0;
410 sal_uInt16 nTemp16
= 0;
413 rStm
.SeekRel( 2048 );
414 rStm
.ReadUInt32( nTemp32
);
415 rStm
.ReadUInt16( nTemp16
);
416 rStm
.ReadUChar( cByte
);
418 if ( ( nTemp32
== 0x5f444350 ) &&
419 ( nTemp16
== 0x5049 ) &&
422 nFormat
= GraphicFileFormat::PCD
;
425 rStm
.Seek( nStmPos
);
429 bool GraphicDescriptor::ImpDetectPCX( SvStream
& rStm
, bool bExtendedInfo
)
431 // ! Because 0x0a can be interpreted as LF too ...
432 // we can't be sure that this special sign represent a PCX file only.
433 // Every Ascii file is possible here :-(
434 // We must detect the whole header.
435 bExtendedInfo
= true;
440 sal_Int32 nStmPos
= rStm
.Tell();
441 rStm
.SetEndian( SvStreamEndian::LITTLE
);
442 rStm
.ReadUChar( cByte
);
446 nFormat
= GraphicFileFormat::PCX
;
462 rStm
.ReadUChar( cByte
);
463 bCompressed
= ( cByte
> 0 );
465 bRet
= (cByte
==0 || cByte
==1);
469 rStm
.ReadUChar( cByte
);
470 nBitsPerPixel
= cByte
;
473 rStm
.ReadUInt16( nTemp16
);
475 rStm
.ReadUInt16( nTemp16
);
477 rStm
.ReadUInt16( nTemp16
);
479 rStm
.ReadUInt16( nTemp16
);
482 aPixSize
.Width() = nXmax
- nXmin
+ 1;
483 aPixSize
.Height() = nYmax
- nYmin
+ 1;
486 rStm
.ReadUInt16( nTemp16
);
488 rStm
.ReadUInt16( nTemp16
);
492 MapMode
aMap( MAP_INCH
, Point(),
493 Fraction( 1, nDPIx
), Fraction( 1, nDPIy
) );
494 aLogSize
= OutputDevice::LogicToLogic( aPixSize
, aMap
,
495 MapMode( MAP_100TH_MM
) );
497 // number of color planes
498 cByte
= 5; // Illegal value in case of EOF.
500 rStm
.ReadUChar( cByte
);
508 rStm
.Seek( nStmPos
);
512 bool GraphicDescriptor::ImpDetectPNG( SvStream
& rStm
, bool bExtendedInfo
)
514 sal_uInt32 nTemp32
= 0;
517 sal_Int32 nStmPos
= rStm
.Tell();
518 rStm
.SetEndian( SvStreamEndian::BIG
);
519 rStm
.ReadUInt32( nTemp32
);
521 if ( nTemp32
== 0x89504e47 )
523 rStm
.ReadUInt32( nTemp32
);
524 if ( nTemp32
== 0x0d0a1a0a )
526 nFormat
= GraphicFileFormat::PNG
;
537 rStm
.ReadUInt32( nTemp32
);
538 aPixSize
.Width() = nTemp32
;
541 rStm
.ReadUInt32( nTemp32
);
542 aPixSize
.Height() = nTemp32
;
545 rStm
.ReadUChar( cByte
);
546 nBitsPerPixel
= cByte
;
549 // compression always
553 sal_uInt32 nLen32
= 0;
558 // read up to the pHYs-Chunk or the start of the image
559 rStm
.ReadUInt32( nLen32
);
560 rStm
.ReadUInt32( nTemp32
);
561 while( ( nTemp32
!= 0x70485973 ) && ( nTemp32
!= 0x49444154 )
562 && !rStm
.IsEof() && !rStm
.GetError() )
564 rStm
.SeekRel( 4 + nLen32
);
565 rStm
.ReadUInt32( nLen32
);
566 rStm
.ReadUInt32( nTemp32
);
569 if ( nTemp32
== 0x70485973
570 && !rStm
.IsEof() && !rStm
.GetError() )
575 // horizontal resolution
577 rStm
.ReadUInt32( nTemp32
);
580 // vertical resolution
582 rStm
.ReadUInt32( nTemp32
);
587 rStm
.ReadUChar( cByte
);
592 aLogSize
.Width() = ( aPixSize
.Width() * 100000 ) /
596 aLogSize
.Height() = ( aPixSize
.Height() * 100000 ) /
603 rStm
.Seek( nStmPos
);
607 bool GraphicDescriptor::ImpDetectTIF( SvStream
& rStm
, bool bExtendedInfo
)
610 sal_uInt8 cByte1
= 0;
611 sal_uInt8 cByte2
= 1;
613 sal_Int32 nStmPos
= rStm
.Tell();
614 rStm
.ReadUChar( cByte1
);
615 rStm
.ReadUChar( cByte2
);
616 if ( cByte1
== cByte2
)
618 bool bDetectOk
= false;
620 if ( cByte1
== 0x49 )
622 rStm
.SetEndian( SvStreamEndian::LITTLE
);
625 else if ( cByte1
== 0x4d )
627 rStm
.SetEndian( SvStreamEndian::BIG
);
633 sal_uInt16 nTemp16
= 0;
635 rStm
.ReadUInt16( nTemp16
);
636 if ( nTemp16
== 0x2a )
638 nFormat
= GraphicFileFormat::TIF
;
644 sal_uLong nMax
= DATA_SIZE
- 48;
645 sal_uInt32 nTemp32
= 0;
647 // Offset of the first IFD
648 rStm
.ReadUInt32( nTemp32
);
649 rStm
.SeekRel( ( nCount
= ( nTemp32
+ 2 ) ) - 0x08 );
655 // read tags till we find Tag256 ( Width )
656 // do not read more bytes than DATA_SIZE
657 rStm
.ReadUInt16( nTemp16
);
658 while ( nTemp16
!= 256 )
666 rStm
.ReadUInt16( nTemp16
);
673 rStm
.ReadUInt16( nTemp16
);
677 rStm
.ReadUInt16( nTemp16
);
678 aPixSize
.Width() = nTemp16
;
683 rStm
.ReadUInt32( nTemp32
);
684 aPixSize
.Width() = nTemp32
;
690 rStm
.ReadUInt16( nTemp16
);
694 rStm
.ReadUInt16( nTemp16
);
695 aPixSize
.Height() = nTemp16
;
700 rStm
.ReadUInt32( nTemp32
);
701 aPixSize
.Height() = nTemp32
;
706 rStm
.ReadUInt16( nTemp16
);
707 if ( nTemp16
== 258 )
710 rStm
.ReadUInt16( nTemp16
);
711 nBitsPerPixel
= nTemp16
;
719 rStm
.ReadUInt16( nTemp16
);
720 if ( nTemp16
== 259 )
723 rStm
.ReadUInt16( nTemp16
);
724 bCompressed
= ( nTemp16
> 1 );
736 rStm
.Seek( nStmPos
);
740 bool GraphicDescriptor::ImpDetectXBM( SvStream
&, bool )
742 bool bRet
= aPathExt
.startsWith( "xbm" );
744 nFormat
= GraphicFileFormat::XBM
;
749 bool GraphicDescriptor::ImpDetectXPM( SvStream
&, bool )
751 bool bRet
= aPathExt
.startsWith( "xpm" );
753 nFormat
= GraphicFileFormat::XPM
;
758 bool GraphicDescriptor::ImpDetectPBM( SvStream
& rStm
, bool )
762 // check file extension first, as this trumps the 2 ID bytes
763 if ( aPathExt
.startsWith( "pbm" ) )
767 sal_Int32 nStmPos
= rStm
.Tell();
768 sal_uInt8 nFirst
= 0, nSecond
= 0;
769 rStm
.ReadUChar( nFirst
).ReadUChar( nSecond
);
770 if ( nFirst
== 'P' && ( ( nSecond
== '1' ) || ( nSecond
== '4' ) ) )
772 rStm
.Seek( nStmPos
);
776 nFormat
= GraphicFileFormat::PBM
;
781 bool GraphicDescriptor::ImpDetectPGM( SvStream
& rStm
, bool )
785 if ( aPathExt
.startsWith( "pgm" ) )
789 sal_uInt8 nFirst
= 0, nSecond
= 0;
790 sal_Int32 nStmPos
= rStm
.Tell();
791 rStm
.ReadUChar( nFirst
).ReadUChar( nSecond
);
792 if ( nFirst
== 'P' && ( ( nSecond
== '2' ) || ( nSecond
== '5' ) ) )
794 rStm
.Seek( nStmPos
);
798 nFormat
= GraphicFileFormat::PGM
;
803 bool GraphicDescriptor::ImpDetectPPM( SvStream
& rStm
, bool )
807 if ( aPathExt
.startsWith( "ppm" ) )
811 sal_uInt8 nFirst
= 0, nSecond
= 0;
812 sal_Int32 nStmPos
= rStm
.Tell();
813 rStm
.ReadUChar( nFirst
).ReadUChar( nSecond
);
814 if ( nFirst
== 'P' && ( ( nSecond
== '3' ) || ( nSecond
== '6' ) ) )
816 rStm
.Seek( nStmPos
);
820 nFormat
= GraphicFileFormat::PPM
;
825 bool GraphicDescriptor::ImpDetectRAS( SvStream
& rStm
, bool )
827 sal_uInt32 nMagicNumber
= 0;
829 sal_Int32 nStmPos
= rStm
.Tell();
830 rStm
.SetEndian( SvStreamEndian::BIG
);
831 rStm
.ReadUInt32( nMagicNumber
);
832 if ( nMagicNumber
== 0x59a66a95 )
834 nFormat
= GraphicFileFormat::RAS
;
837 rStm
.Seek( nStmPos
);
841 bool GraphicDescriptor::ImpDetectTGA( SvStream
&, bool )
843 bool bRet
= aPathExt
.startsWith( "tga" );
845 nFormat
= GraphicFileFormat::TGA
;
850 bool GraphicDescriptor::ImpDetectPSD( SvStream
& rStm
, bool bExtendedInfo
)
854 sal_uInt32 nMagicNumber
= 0;
855 sal_Int32 nStmPos
= rStm
.Tell();
856 rStm
.SetEndian( SvStreamEndian::BIG
);
857 rStm
.ReadUInt32( nMagicNumber
);
858 if ( nMagicNumber
== 0x38425053 )
860 sal_uInt16 nVersion
= 0;
861 rStm
.ReadUInt16( nVersion
);
867 sal_uInt16 nChannels
= 0;
868 sal_uInt32 nRows
= 0;
869 sal_uInt32 nColumns
= 0;
870 sal_uInt16 nDepth
= 0;
871 sal_uInt16 nMode
= 0;
872 rStm
.SeekRel( 6 ); // Pad
873 rStm
.ReadUInt16( nChannels
).ReadUInt32( nRows
).ReadUInt32( nColumns
).ReadUInt16( nDepth
).ReadUInt16( nMode
);
874 if ( ( nDepth
== 1 ) || ( nDepth
== 8 ) || ( nDepth
== 16 ) )
876 nBitsPerPixel
= ( nDepth
== 16 ) ? 8 : nDepth
;
884 aPixSize
.Width() = nColumns
;
885 aPixSize
.Height() = nRows
;
898 nFormat
= GraphicFileFormat::PSD
;
899 rStm
.Seek( nStmPos
);
903 bool GraphicDescriptor::ImpDetectEPS( SvStream
& rStm
, bool )
905 // check the EPS preview and the file extension
906 sal_uInt32 nFirstLong
= 0;
907 sal_uInt8 nFirstBytes
[20];
909 memset(nFirstBytes
, 0, sizeof (nFirstBytes
));
911 sal_Int32 nStmPos
= rStm
.Tell();
912 rStm
.SetEndian( SvStreamEndian::BIG
);
913 rStm
.ReadUInt32( nFirstLong
);
915 rStm
.Read( &nFirstBytes
, 20 );
917 if ( ( nFirstLong
== 0xC5D0D3C6 ) || aPathExt
.startsWith( "eps" ) ||
918 ( ImplSearchEntry( nFirstBytes
, reinterpret_cast<sal_uInt8
const *>("%!PS-Adobe"), 10, 10 )
919 && ImplSearchEntry( &nFirstBytes
[15], reinterpret_cast<sal_uInt8
const *>("EPS"), 3, 3 ) ) )
921 nFormat
= GraphicFileFormat::EPS
;
924 rStm
.Seek( nStmPos
);
928 bool GraphicDescriptor::ImpDetectDXF( SvStream
&, bool )
930 bool bRet
= aPathExt
.startsWith( "dxf" );
932 nFormat
= GraphicFileFormat::DXF
;
937 bool GraphicDescriptor::ImpDetectMET( SvStream
&, bool )
939 bool bRet
= aPathExt
.startsWith( "met" );
941 nFormat
= GraphicFileFormat::MET
;
946 bool GraphicDescriptor::ImpDetectPCT( SvStream
& rStm
, bool )
948 bool bRet
= aPathExt
.startsWith( "pct" );
950 nFormat
= GraphicFileFormat::PCT
;
953 sal_Size nStreamPos
= rStm
.Tell();
954 sal_Size nStreamLen
= rStm
.remainingSize();
955 if (isPCT(rStm
, nStreamPos
, nStreamLen
))
958 nFormat
= GraphicFileFormat::PCT
;
960 rStm
.Seek(nStreamPos
);
966 bool GraphicDescriptor::ImpDetectSGF( SvStream
& rStm
, bool )
969 if( aPathExt
.startsWith( "sgf" ) )
973 sal_Int32 nStmPos
= rStm
.Tell();
975 sal_uInt8 nFirst
= 0, nSecond
= 0;
977 rStm
.ReadUChar( nFirst
).ReadUChar( nSecond
);
979 if( nFirst
== 'J' && nSecond
== 'J' )
982 rStm
.Seek( nStmPos
);
986 nFormat
= GraphicFileFormat::SGF
;
991 bool GraphicDescriptor::ImpDetectSGV( SvStream
&, bool )
993 bool bRet
= aPathExt
.startsWith( "sgv" );
995 nFormat
= GraphicFileFormat::SGV
;
1000 bool GraphicDescriptor::ImpDetectSVM( SvStream
& rStm
, bool bExtendedInfo
)
1004 sal_uInt8 cByte
= 0;
1006 sal_Int32 nStmPos
= rStm
.Tell();
1007 rStm
.SetEndian( SvStreamEndian::LITTLE
);
1008 rStm
.ReadUInt32( n32
);
1009 if ( n32
== 0x44475653 )
1012 rStm
.ReadUChar( cByte
);
1013 if ( cByte
== 0x49 )
1015 nFormat
= GraphicFileFormat::SVM
;
1018 if ( bExtendedInfo
)
1023 rStm
.SeekRel( 0x04 );
1027 rStm
.ReadUInt32( nTemp32
);
1028 aLogSize
.Width() = nTemp32
;
1032 rStm
.ReadUInt32( nTemp32
);
1033 aLogSize
.Height() = nTemp32
;
1035 // read MapUnit and determine PrefSize
1037 rStm
.ReadUInt16( nTemp16
);
1038 aLogSize
= OutputDevice::LogicToLogic( aLogSize
,
1039 MapMode( (MapUnit
) nTemp16
),
1040 MapMode( MAP_100TH_MM
) );
1046 rStm
.SeekRel( -4L );
1048 rStm
.ReadUInt32( n32
);
1050 if( n32
== 0x4D4C4356 )
1052 sal_uInt16 nTmp16
= 0;
1054 rStm
.ReadUInt16( nTmp16
);
1056 if( nTmp16
== 0x4654 )
1058 nFormat
= GraphicFileFormat::SVM
;
1065 rStm
.SeekRel( 0x06 );
1066 ReadMapMode( rStm
, aMapMode
);
1067 ReadPair( rStm
, aLogSize
);
1068 aLogSize
= OutputDevice::LogicToLogic( aLogSize
, aMapMode
, MapMode( MAP_100TH_MM
) );
1073 rStm
.Seek( nStmPos
);
1077 bool GraphicDescriptor::ImpDetectWMF( SvStream
&, bool )
1079 bool bRet
= aPathExt
.startsWith( "wmf" );
1081 nFormat
= GraphicFileFormat::WMF
;
1086 bool GraphicDescriptor::ImpDetectEMF( SvStream
&, bool )
1088 bool bRet
= aPathExt
.startsWith( "emf" );
1090 nFormat
= GraphicFileFormat::EMF
;
1095 bool GraphicDescriptor::ImpDetectSVG( SvStream
& /*rStm*/, bool /*bExtendedInfo*/ )
1097 bool bRet
= aPathExt
.startsWith( "svg" );
1099 nFormat
= GraphicFileFormat::SVG
;
1104 OUString
GraphicDescriptor::GetImportFormatShortName( GraphicFileFormat nFormat
)
1106 const char *pKeyName
= 0;
1110 case( GraphicFileFormat::BMP
) : pKeyName
= "bmp"; break;
1111 case( GraphicFileFormat::GIF
) : pKeyName
= "gif"; break;
1112 case( GraphicFileFormat::JPG
) : pKeyName
= "jpg"; break;
1113 case( GraphicFileFormat::PCD
) : pKeyName
= "pcd"; break;
1114 case( GraphicFileFormat::PCX
) : pKeyName
= "pcx"; break;
1115 case( GraphicFileFormat::PNG
) : pKeyName
= "png"; break;
1116 case( GraphicFileFormat::XBM
) : pKeyName
= "xbm"; break;
1117 case( GraphicFileFormat::XPM
) : pKeyName
= "xpm"; break;
1118 case( GraphicFileFormat::PBM
) : pKeyName
= "pbm"; break;
1119 case( GraphicFileFormat::PGM
) : pKeyName
= "pgm"; break;
1120 case( GraphicFileFormat::PPM
) : pKeyName
= "ppm"; break;
1121 case( GraphicFileFormat::RAS
) : pKeyName
= "ras"; break;
1122 case( GraphicFileFormat::TGA
) : pKeyName
= "tga"; break;
1123 case( GraphicFileFormat::PSD
) : pKeyName
= "psd"; break;
1124 case( GraphicFileFormat::EPS
) : pKeyName
= "eps"; break;
1125 case( GraphicFileFormat::TIF
) : pKeyName
= "tif"; break;
1126 case( GraphicFileFormat::DXF
) : pKeyName
= "dxf"; break;
1127 case( GraphicFileFormat::MET
) : pKeyName
= "met"; break;
1128 case( GraphicFileFormat::PCT
) : pKeyName
= "pct"; break;
1129 case( GraphicFileFormat::SGF
) : pKeyName
= "sgf"; break;
1130 case( GraphicFileFormat::SGV
) : pKeyName
= "sgv"; break;
1131 case( GraphicFileFormat::SVM
) : pKeyName
= "svm"; break;
1132 case( GraphicFileFormat::WMF
) : pKeyName
= "wmf"; break;
1133 case( GraphicFileFormat::EMF
) : pKeyName
= "emf"; break;
1134 case( GraphicFileFormat::SVG
) : pKeyName
= "svg"; break;
1135 default: assert(false);
1138 return OUString::createFromAscii(pKeyName
);
1141 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */