update dev300-m58
[ooovba.git] / svtools / source / filter.vcl / filter / filter2.cxx
blob6fa57e149e8d82dacf9d1b42e5482afba1d42109
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: filter2.cxx,v $
10 * $Revision: 1.20 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
34 #include <string.h>
35 #include <stdio.h>
36 #include <tools/stream.hxx>
37 #include <tools/debug.hxx>
38 #include <vcl/outdev.hxx>
39 #include <tools/config.hxx>
40 #include <svtools/filter.hxx>
41 #include "FilterConfigCache.hxx"
42 #include <unotools/ucbstreamhelper.hxx>
44 #define DATA_SIZE 640
46 BYTE* ImplSearchEntry( BYTE* , BYTE* , ULONG , ULONG );
49 /*************************************************************************
53 \************************************************************************/
55 GraphicDescriptor::GraphicDescriptor( const String* pPath ) :
56 pFileStm ( NULL )
58 ImpConstruct();
60 if ( pPath )
62 INetURLObject aURL( *pPath, INET_PROT_FILE );
63 aPathExt = aURL.GetFileExtension().toAsciiLowerCase();
65 bLinked = TRUE;
66 bLinkChanged = FALSE;
67 bWideSearch = FALSE;
71 /*************************************************************************
75 \************************************************************************/
77 GraphicDescriptor::GraphicDescriptor( const INetURLObject& rPath ) :
78 pFileStm( ::utl::UcbStreamHelper::CreateStream( rPath.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ ) ),
79 aPathExt( rPath.GetFileExtension().toAsciiLowerCase() )
81 if ( pFileStm )
83 nStmPos = 0;
84 pFileStm->Seek( nStmPos );
85 bDataReady = TRUE;
88 ImpConstruct();
90 if ( pFileStm && !pFileStm->GetError() )
91 bDataReady = TRUE;
94 /*************************************************************************
98 \************************************************************************/
100 GraphicDescriptor::GraphicDescriptor( SvStream& rInStream, const String* pPath) :
101 pFileStm ( NULL )
103 ImpConstruct();
105 if ( pPath )
107 INetURLObject aURL( *pPath );
108 aPathExt = aURL.GetFileExtension().toAsciiLowerCase();
110 nStmPos = rInStream.Tell();
111 pBaseStm = &rInStream;
112 bBaseStm = TRUE;
114 if ( !pBaseStm->GetError() )
115 bDataReady = TRUE;
119 /*************************************************************************
123 \************************************************************************/
125 GraphicDescriptor::~GraphicDescriptor()
127 delete pFileStm;
131 /*************************************************************************
135 \************************************************************************/
137 BOOL GraphicDescriptor::Detect( BOOL bExtendedInfo )
139 BOOL bRet = FALSE;
141 // Link-Status ueberpruefen
142 if ( bLinked && bLinkChanged )
144 DBG_ASSERT( aReqLink.IsSet(), "Wo ist der RequestHandler???" );
145 pMemStm = (SvStream*) aReqLink.Call( this );
146 if ( pMemStm )
148 nStmPos = pMemStm->Tell();
149 bDataReady = TRUE;
153 if ( bDataReady )
155 SvStream& rStm = GetSearchStream();
156 UINT16 nOldFormat = rStm.GetNumberFormatInt();
158 if ( ImpDetectGIF( rStm, bExtendedInfo ) ) bRet = TRUE;
159 else if ( ImpDetectJPG( rStm, bExtendedInfo ) ) bRet = TRUE;
160 else if ( ImpDetectBMP( rStm, bExtendedInfo ) ) bRet = TRUE;
161 else if ( ImpDetectPNG( rStm, bExtendedInfo ) ) bRet = TRUE;
162 else if ( ImpDetectTIF( rStm, bExtendedInfo ) ) bRet = TRUE;
163 else if ( ImpDetectPCX( rStm, bExtendedInfo ) ) bRet = TRUE;
164 else if ( ImpDetectDXF( rStm, bExtendedInfo ) ) bRet = TRUE;
165 else if ( ImpDetectMET( rStm, bExtendedInfo ) ) bRet = TRUE;
166 else if ( ImpDetectSGF( rStm, bExtendedInfo ) ) bRet = TRUE;
167 else if ( ImpDetectSGV( rStm, bExtendedInfo ) ) bRet = TRUE;
168 else if ( ImpDetectSVM( rStm, bExtendedInfo ) ) bRet = TRUE;
169 else if ( ImpDetectWMF( rStm, bExtendedInfo ) ) bRet = TRUE;
170 else if ( ImpDetectEMF( rStm, bExtendedInfo ) ) bRet = TRUE;
171 else if ( ImpDetectPCT( rStm, bExtendedInfo ) ) bRet = TRUE;
172 else if ( ImpDetectXBM( rStm, bExtendedInfo ) ) bRet = TRUE;
173 else if ( ImpDetectXPM( rStm, bExtendedInfo ) ) bRet = TRUE;
174 else if ( ImpDetectPBM( rStm, bExtendedInfo ) ) bRet = TRUE;
175 else if ( ImpDetectPGM( rStm, bExtendedInfo ) ) bRet = TRUE;
176 else if ( ImpDetectPPM( rStm, bExtendedInfo ) ) bRet = TRUE;
177 else if ( ImpDetectRAS( rStm, bExtendedInfo ) ) bRet = TRUE;
178 else if ( ImpDetectTGA( rStm, bExtendedInfo ) ) bRet = TRUE;
179 else if ( ImpDetectPSD( rStm, bExtendedInfo ) ) bRet = TRUE;
180 else if ( ImpDetectEPS( rStm, bExtendedInfo ) ) bRet = TRUE;
182 // diese Formate lassen sich nur bei WideSearch im gesamten
183 // Stream ermitteln
184 else if ( bWideSearch )
186 if ( ImpDetectPCD( rStm, bExtendedInfo ) )
187 bRet = TRUE;
190 rStm.SetNumberFormatInt( nOldFormat );
191 rStm.Seek( nStmPos );
194 return bRet;
198 /*************************************************************************
202 \************************************************************************/
204 BOOL GraphicDescriptor::IsDataReady() const
206 return bDataReady;
210 /*************************************************************************
214 \************************************************************************/
216 BOOL GraphicDescriptor::IsWideSearch() const
218 return bWideSearch;
222 /*************************************************************************
226 \************************************************************************/
228 SvStream& GraphicDescriptor::GetSearchStream() const
230 DBG_ASSERT( bDataReady, "Was laeuft hier falsch???" );
232 if ( bLinked )
233 return *pMemStm;
234 else if ( bBaseStm )
235 return *pBaseStm;
236 else
237 return *pFileStm;
241 /*************************************************************************
245 \************************************************************************/
247 void GraphicDescriptor::SetRequestHdl( const Link& rRequestLink )
249 aReqLink = rRequestLink;
250 bLinkChanged = TRUE;
254 /*************************************************************************
258 \************************************************************************/
260 ULONG GraphicDescriptor::GetRequestedByteCount() const
262 return DATA_SIZE;
266 /******************************************************************************/
267 /* IMP-Methoden */
268 /* */
271 /*************************************************************************
275 \************************************************************************/
277 void GraphicDescriptor::ImpConstruct()
279 if ( !pFileStm )
280 pFileStm = new SvStream();
281 nFormat = GFF_NOT;
282 nBitsPerPixel = 0;
283 nPlanes = 0;
284 bCompressed = FALSE;
285 bDataReady = FALSE;
286 bLinked = FALSE;
287 bWideSearch = TRUE;
288 bBaseStm = FALSE;
289 pMemStm = NULL;
293 /*************************************************************************
297 \************************************************************************/
299 BOOL GraphicDescriptor::ImpDetectBMP( SvStream& rStm, BOOL bExtendedInfo )
301 UINT16 nTemp16;
302 BOOL bRet = FALSE;
304 rStm.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN );
305 rStm.Seek( nStmPos );
307 rStm >> nTemp16;
309 // OS/2-BitmapArray
310 if ( nTemp16 == 0x4142 )
312 rStm.SeekRel( 0x0c );
313 rStm >> nTemp16;
316 // Bitmap
317 if ( nTemp16 == 0x4d42 )
319 nFormat = GFF_BMP;
320 bRet = TRUE;
322 if ( bExtendedInfo )
324 UINT32 nTemp32;
325 UINT32 nCompression;
327 // bis zur ersten Information
328 rStm.SeekRel( 0x10 );
330 // PixelBreite auslesen
331 rStm >> nTemp32;
332 aPixSize.Width() = nTemp32;
334 // PixelHoehe auslesen
335 rStm >> nTemp32;
336 aPixSize.Height() = nTemp32;
338 // Planes auslesen
339 rStm >> nTemp16;
340 nPlanes = nTemp16;
342 // BitCount auslesen
343 rStm >> nTemp16;
344 nBitsPerPixel = nTemp16;
346 // Compression auslesen
347 rStm >> nTemp32;
348 bCompressed = ( ( nCompression = nTemp32 ) > 0 );
350 // logische Breite
351 rStm.SeekRel( 4 );
352 rStm >> nTemp32;
353 if ( nTemp32 )
354 aLogSize.Width() = ( aPixSize.Width() * 100000 ) / nTemp32;
356 // logische Hoehe
357 rStm >> nTemp32;
358 if ( nTemp32 )
359 aLogSize.Height() = ( aPixSize.Height() * 100000 ) / nTemp32;
361 // Wir wollen noch etwas feiner differenzieren und
362 // auf sinnvolle Werte ueberpruefen ( Bug-Id #29001 )
363 if ( ( nBitsPerPixel > 24 ) || ( nCompression > 3 ) )
365 nFormat = GFF_NOT;
366 bRet = FALSE;
371 return bRet;
375 /*************************************************************************
379 \************************************************************************/
381 BOOL GraphicDescriptor::ImpDetectGIF( SvStream& rStm, BOOL bExtendedInfo )
383 UINT32 n32;
384 UINT16 n16;
385 BOOL bRet = FALSE;
386 BYTE cByte;
388 rStm.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN );
389 rStm.Seek( nStmPos );
391 rStm >> n32;
392 if ( n32 == 0x38464947 )
394 rStm >> n16;
395 if ( ( n16 == 0x6137 ) || ( n16 == 0x6139 ) )
397 nFormat = GFF_GIF;
398 bRet = TRUE;
400 if ( bExtendedInfo )
402 UINT16 nTemp16;
404 // PixelBreite auslesen
405 rStm >> nTemp16;
406 aPixSize.Width() = nTemp16;
408 // PixelHoehe auslesen
409 rStm >> nTemp16;
410 aPixSize.Height() = nTemp16;
412 // Bits/Pixel auslesen
413 rStm >> cByte;
414 nBitsPerPixel = ( ( cByte & 112 ) >> 4 ) + 1;
419 return bRet;
423 /*************************************************************************
427 \************************************************************************/
429 BOOL GraphicDescriptor::ImpDetectJPG( SvStream& rStm, BOOL bExtendedInfo )
431 UINT32 nTemp32;
432 BOOL bRet = FALSE;
433 BYTE cByte = 0;
434 BOOL bM_COM;
436 rStm.SetNumberFormatInt( NUMBERFORMAT_INT_BIGENDIAN );
437 rStm.Seek( nStmPos );
439 rStm >> nTemp32;
441 // compare upper 28 bits
442 if( 0xffd8ff00 == ( nTemp32 & 0xffffff00 ) )
444 nFormat = GFF_JPG;
445 return TRUE;
448 bM_COM = ( nTemp32 == 0xffd8fffe );
449 if ( ( nTemp32 == 0xffd8ffe0 ) || bM_COM )
451 if( !bM_COM )
453 rStm.SeekRel( 2 );
454 rStm >> nTemp32;
457 if( bM_COM || ( nTemp32 == 0x4a464946 ) )
459 nFormat = GFF_JPG;
460 bRet = TRUE;
462 if( bExtendedInfo )
464 MapMode aMap;
465 UINT16 nTemp16;
466 ULONG nCount = 9;
467 ULONG nMax;
468 ULONG nResX;
469 ULONG nResY;
470 BYTE cUnit;
472 // Groesse des verbleibenden Puffers ermitteln
473 if ( bLinked )
474 nMax = ( (SvMemoryStream&) rStm ).GetSize() - 16;
475 else
476 nMax = DATA_SIZE - 16;
478 // max. 8K
479 nMax = Min( nMax, (ULONG) 8192 );
481 // Res-Unit ermitteln
482 rStm.SeekRel( 3 );
483 rStm >> cUnit;
485 // ResX ermitteln
486 rStm >> nTemp16;
487 nResX = nTemp16;
489 // ResY ermitteln
490 rStm >> nTemp16;
491 nResY = nTemp16;
493 // SOF0/1-Marker finden, aber dabei
494 // nicht mehr als DATA_SIZE Pixel lesen, falls
495 // kein WideSearch
498 while ( ( cByte != 0xff ) &&
499 ( bWideSearch || ( nCount++ < nMax ) ) )
501 rStm >> cByte;
504 while ( ( cByte == 0xff ) &&
505 ( bWideSearch || ( nCount++ < nMax ) ) )
507 rStm >> cByte;
510 while ( ( cByte != 0xc0 ) &&
511 ( cByte != 0xc1 ) &&
512 ( bWideSearch || ( nCount < nMax ) ) );
514 // wir haben den SOF0/1-Marker
515 if ( ( cByte == 0xc0 ) || ( cByte == 0xc1 ) )
517 // Hoehe einlesen
518 rStm.SeekRel( 3 );
519 rStm >> nTemp16;
520 aPixSize.Height() = nTemp16;
522 // Breite einlesen
523 rStm >> nTemp16;
524 aPixSize.Width() = nTemp16;
526 // Bit/Pixel einlesen
527 rStm >> cByte;
528 nBitsPerPixel = ( cByte == 3 ? 24 : cByte == 1 ? 8 : 0 );
530 // logische Groesse setzen
531 if ( cUnit && nResX && nResY )
533 aMap.SetMapUnit( cUnit == 1 ? MAP_INCH : MAP_CM );
534 aMap.SetScaleX( Fraction( 1, nResX ) );
535 aMap.SetScaleY( Fraction( 1, nResY ) );
536 aLogSize = OutputDevice::LogicToLogic( aPixSize, aMap,
537 MapMode( MAP_100TH_MM ) );
540 // Planes immer 1
541 nPlanes = 1;
547 return bRet;
551 /*************************************************************************
555 \************************************************************************/
557 BOOL GraphicDescriptor::ImpDetectPCD( SvStream& rStm, BOOL )
559 BOOL bRet = FALSE;
561 rStm.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN );
562 rStm.Seek( nStmPos );
564 if ( bWideSearch )
566 UINT32 nTemp32;
567 UINT16 nTemp16;
568 BYTE cByte;
570 rStm.SeekRel( 2048 );
571 rStm >> nTemp32;
572 rStm >> nTemp16;
573 rStm >> cByte;
575 if ( ( nTemp32 == 0x5f444350 ) &&
576 ( nTemp16 == 0x5049 ) &&
577 ( cByte == 0x49 ) )
579 nFormat = GFF_PCD;
580 bRet = TRUE;
583 else
585 bRet = aPathExt.CompareToAscii( "pcd", 3 ) == COMPARE_EQUAL;
586 if ( bRet )
588 nFormat = GFF_PCD;
592 return bRet;
596 /*************************************************************************
600 \************************************************************************/
602 BOOL GraphicDescriptor::ImpDetectPCX( SvStream& rStm, BOOL bExtendedInfo )
604 // ! Because 0x0a can be interpreted as LF too ...
605 // we cant be shure that this special sign represent a PCX file only.
606 // Every Ascii file is possible here :-(
607 // We must detect the whole header.
608 bExtendedInfo = TRUE;
610 BOOL bRet = FALSE;
611 BYTE cByte;
613 rStm.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN );
614 rStm.Seek( nStmPos );
616 rStm >> cByte;
617 if ( cByte == 0x0a )
619 nFormat = GFF_PCX;
620 bRet = TRUE;
622 if ( bExtendedInfo )
624 UINT16 nTemp16;
625 USHORT nXmin;
626 USHORT nXmax;
627 USHORT nYmin;
628 USHORT nYmax;
629 USHORT nDPIx;
630 USHORT nDPIy;
633 rStm.SeekRel( 1 );
635 // Kompression lesen
636 rStm >> cByte;
637 bCompressed = ( cByte > 0 );
639 bRet = (cByte==0 || cByte ==1);
641 // Bits/Pixel lesen
642 rStm >> cByte;
643 nBitsPerPixel = cByte;
645 // Bildabmessungen
646 rStm >> nTemp16;
647 nXmin = nTemp16;
648 rStm >> nTemp16;
649 nYmin = nTemp16;
650 rStm >> nTemp16;
651 nXmax = nTemp16;
652 rStm >> nTemp16;
653 nYmax = nTemp16;
655 aPixSize.Width() = nXmax - nXmin + 1;
656 aPixSize.Height() = nYmax - nYmin + 1;
658 // Aufloesung
659 rStm >> nTemp16;
660 nDPIx = nTemp16;
661 rStm >> nTemp16;
662 nDPIy = nTemp16;
664 // logische Groesse setzen
665 MapMode aMap( MAP_INCH, Point(),
666 Fraction( 1, nDPIx ), Fraction( 1, nDPIy ) );
667 aLogSize = OutputDevice::LogicToLogic( aPixSize, aMap,
668 MapMode( MAP_100TH_MM ) );
671 // Anzahl Farbebenen
672 rStm.SeekRel( 49 );
673 rStm >> cByte;
674 nPlanes = cByte;
676 bRet = (nPlanes<=4);
680 return bRet;
684 /*************************************************************************
688 \************************************************************************/
690 BOOL GraphicDescriptor::ImpDetectPNG( SvStream& rStm, BOOL bExtendedInfo )
692 UINT32 nTemp32;
693 BOOL bRet = FALSE;
695 rStm.SetNumberFormatInt( NUMBERFORMAT_INT_BIGENDIAN );
696 rStm.Seek( nStmPos );
698 rStm >> nTemp32;
699 if ( nTemp32 == 0x89504e47 )
701 rStm >> nTemp32;
702 if ( nTemp32 == 0x0d0a1a0a )
704 nFormat = GFF_PNG;
705 bRet = TRUE;
707 if ( bExtendedInfo )
709 BYTE cByte;
711 // IHDR-Chunk
712 rStm.SeekRel( 8 );
714 // Breite einlesen
715 rStm >> nTemp32;
716 aPixSize.Width() = nTemp32;
718 // Hoehe einlesen
719 rStm >> nTemp32;
720 aPixSize.Height() = nTemp32;
722 // Bits/Pixel einlesen
723 rStm >> cByte;
724 nBitsPerPixel = cByte;
726 // Planes immer 1;
727 // Kompression immer
728 nPlanes = 1;
729 bCompressed = TRUE;
731 if ( bWideSearch )
733 UINT32 nLen32;
735 rStm.SeekRel( 8 );
737 // so lange ueberlesen, bis wir den pHYs-Chunk haben oder
738 // den Anfang der Bilddaten
739 rStm >> nLen32;
740 rStm >> nTemp32;
741 while( ( nTemp32 != 0x70485973 ) && ( nTemp32 != 0x49444154 ) )
743 rStm.SeekRel( 4 + nLen32 );
744 rStm >> nLen32;
745 rStm >> nTemp32;
748 if ( nTemp32 == 0x70485973 )
750 ULONG nXRes;
751 ULONG nYRes;
753 // horizontale Aufloesung
754 rStm >> nTemp32;
755 nXRes = nTemp32;
757 // vertikale Aufloesung
758 rStm >> nTemp32;
759 nYRes = nTemp32;
761 // Unit einlesen
762 rStm >> cByte;
764 if ( cByte )
766 if ( nXRes )
767 aLogSize.Width() = ( aPixSize.Width() * 100000 ) /
768 nTemp32;
770 if ( nYRes )
771 aLogSize.Height() = ( aPixSize.Height() * 100000 ) /
772 nTemp32;
780 return bRet;
784 /*************************************************************************
788 \************************************************************************/
790 BOOL GraphicDescriptor::ImpDetectTIF( SvStream& rStm, BOOL bExtendedInfo )
792 BOOL bDetectOk = FALSE;
793 BOOL bRet = FALSE;
794 BYTE cByte1;
795 BYTE cByte2;
797 rStm.Seek( nStmPos );
798 rStm >> cByte1;
799 rStm >> cByte2;
800 if ( cByte1 == cByte2 )
802 if ( cByte1 == 0x49 )
804 rStm.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN );
805 bDetectOk = TRUE;
807 else if ( cByte1 == 0x4d )
809 rStm.SetNumberFormatInt( NUMBERFORMAT_INT_BIGENDIAN );
810 bDetectOk = TRUE;
813 if ( bDetectOk )
815 UINT16 nTemp16;
817 rStm >> nTemp16;
818 if ( nTemp16 == 0x2a )
820 nFormat = GFF_TIF;
821 bRet = TRUE;
823 if ( bExtendedInfo )
825 ULONG nCount;
826 ULONG nMax = DATA_SIZE - 48;
827 UINT32 nTemp32;
828 BOOL bOk = FALSE;
830 // Offset des ersten IFD einlesen
831 rStm >> nTemp32;
832 rStm.SeekRel( ( nCount = ( nTemp32 + 2 ) ) - 0x08 );
834 if ( bWideSearch || ( nCount < nMax ) )
836 // Tag's lesen, bis wir auf Tag256 ( Width ) treffen
837 // nicht mehr Bytes als DATA_SIZE lesen
838 rStm >> nTemp16;
839 while ( nTemp16 != 256 )
841 bOk = bWideSearch || ( nCount < nMax );
842 if ( !bOk )
844 break;
846 rStm.SeekRel( 10 );
847 rStm >> nTemp16;
848 nCount += 12;
851 if ( bOk )
853 // Breite lesen
854 rStm >> nTemp16;
855 rStm.SeekRel( 4 );
856 if ( nTemp16 == 3 )
858 rStm >> nTemp16;
859 aPixSize.Width() = nTemp16;
860 rStm.SeekRel( 2 );
862 else
864 rStm >> nTemp32;
865 aPixSize.Width() = nTemp32;
867 nCount += 12;
869 // Hoehe lesen
870 rStm.SeekRel( 2 );
871 rStm >> nTemp16;
872 rStm.SeekRel( 4 );
873 if ( nTemp16 == 3 )
875 rStm >> nTemp16;
876 aPixSize.Height() = nTemp16;
877 rStm.SeekRel( 2 );
879 else
881 rStm >> nTemp32;
882 aPixSize.Height() = nTemp32;
884 nCount += 12;
886 // ggf. Bits/Pixel lesen
887 rStm >> nTemp16;
888 if ( nTemp16 == 258 )
890 rStm.SeekRel( 6 );
891 rStm >> nTemp16;
892 nBitsPerPixel = nTemp16;
893 rStm.SeekRel( 2 );
894 nCount += 12;
896 else
897 rStm.SeekRel( -2 );
899 // ggf. Compression lesen
900 rStm >> nTemp16;
901 if ( nTemp16 == 259 )
903 rStm.SeekRel( 6 );
904 rStm >> nTemp16;
905 bCompressed = ( nTemp16 > 1 );
906 rStm.SeekRel( 2 );
907 nCount += 12;
909 else
910 rStm.SeekRel( -2 );
918 return bRet;
922 /*************************************************************************
926 \************************************************************************/
928 BOOL GraphicDescriptor::ImpDetectXBM( SvStream&, BOOL )
930 BOOL bRet = aPathExt.CompareToAscii( "xbm", 3 ) == COMPARE_EQUAL;
931 if (bRet)
932 nFormat = GFF_XBM;
934 return bRet;
938 /*************************************************************************
942 \************************************************************************/
944 BOOL GraphicDescriptor::ImpDetectXPM( SvStream&, BOOL )
946 BOOL bRet = aPathExt.CompareToAscii( "xpm", 3 ) == COMPARE_EQUAL;
947 if (bRet)
948 nFormat = GFF_XPM;
950 return bRet;
953 /*************************************************************************
957 \************************************************************************/
959 BOOL GraphicDescriptor::ImpDetectPBM( SvStream& rStm, BOOL )
961 BOOL bRet = FALSE;
963 // erst auf Datei Extension pruefen, da diese aussagekraeftiger ist
964 // als die 2 ID Bytes
966 if ( aPathExt.CompareToAscii( "pbm", 3 ) == COMPARE_EQUAL )
967 bRet = TRUE;
968 else
970 BYTE nFirst, nSecond;
971 rStm.Seek( nStmPos );
972 rStm >> nFirst >> nSecond;
973 if ( nFirst == 'P' && ( ( nSecond == '1' ) || ( nSecond == '4' ) ) )
974 bRet = TRUE;
977 if ( bRet )
978 nFormat = GFF_PBM;
980 return bRet;
983 /*************************************************************************
987 \************************************************************************/
989 BOOL GraphicDescriptor::ImpDetectPGM( SvStream& rStm, BOOL )
991 BOOL bRet = FALSE;
993 if ( aPathExt.CompareToAscii( "pgm", 3 ) == COMPARE_EQUAL )
994 bRet = TRUE;
995 else
997 BYTE nFirst, nSecond;
998 rStm.Seek( nStmPos );
999 rStm >> nFirst >> nSecond;
1000 if ( nFirst == 'P' && ( ( nSecond == '2' ) || ( nSecond == '5' ) ) )
1001 bRet = TRUE;
1004 if ( bRet )
1005 nFormat = GFF_PGM;
1007 return bRet;
1010 /*************************************************************************
1014 \************************************************************************/
1016 BOOL GraphicDescriptor::ImpDetectPPM( SvStream& rStm, BOOL )
1018 BOOL bRet = FALSE;
1020 if ( aPathExt.CompareToAscii( "ppm", 3 ) == COMPARE_EQUAL )
1021 bRet = TRUE;
1022 else
1024 BYTE nFirst, nSecond;
1025 rStm.Seek( nStmPos );
1026 rStm >> nFirst >> nSecond;
1027 if ( nFirst == 'P' && ( ( nSecond == '3' ) || ( nSecond == '6' ) ) )
1028 bRet = TRUE;
1031 if ( bRet )
1032 nFormat = GFF_PPM;
1034 return bRet;
1037 /*************************************************************************
1041 \************************************************************************/
1043 BOOL GraphicDescriptor::ImpDetectRAS( SvStream& rStm, BOOL )
1045 UINT32 nMagicNumber;
1046 rStm.Seek( nStmPos );
1047 rStm.SetNumberFormatInt( NUMBERFORMAT_INT_BIGENDIAN );
1048 rStm >> nMagicNumber;
1049 if ( nMagicNumber == 0x59a66a95 )
1051 nFormat = GFF_RAS;
1052 return TRUE;
1054 else
1055 return FALSE;
1058 /*************************************************************************
1062 \************************************************************************/
1064 BOOL GraphicDescriptor::ImpDetectTGA( SvStream&, BOOL )
1066 BOOL bRet = aPathExt.CompareToAscii( "tga", 3 ) == COMPARE_EQUAL;
1067 if (bRet)
1068 nFormat = GFF_TGA;
1070 return bRet;
1073 /*************************************************************************
1077 \************************************************************************/
1079 BOOL GraphicDescriptor::ImpDetectPSD( SvStream& rStm, BOOL bExtendedInfo )
1081 BOOL bRet = FALSE;
1083 UINT32 nMagicNumber;
1084 rStm.Seek( nStmPos );
1085 rStm.SetNumberFormatInt( NUMBERFORMAT_INT_BIGENDIAN );
1086 rStm >> nMagicNumber;
1087 if ( nMagicNumber == 0x38425053 )
1089 UINT16 nVersion;
1090 rStm >> nVersion;
1091 if ( nVersion == 1 )
1093 bRet = TRUE;
1094 if ( bExtendedInfo )
1096 UINT16 nChannels;
1097 UINT32 nRows;
1098 UINT32 nColumns;
1099 UINT16 nDepth;
1100 UINT16 nMode;
1101 rStm.SeekRel( 6 ); // Pad
1102 rStm >> nChannels >> nRows >> nColumns >> nDepth >> nMode;
1103 if ( ( nDepth == 1 ) || ( nDepth == 8 ) || ( nDepth == 16 ) )
1105 nBitsPerPixel = ( nDepth == 16 ) ? 8 : nDepth;
1106 switch ( nChannels )
1108 case 4 :
1109 case 3 :
1110 nBitsPerPixel = 24;
1111 case 2 :
1112 case 1 :
1113 aPixSize.Width() = nColumns;
1114 aPixSize.Height() = nRows;
1115 break;
1116 default:
1117 bRet = FALSE;
1120 else
1121 bRet = FALSE;
1126 if ( bRet )
1127 nFormat = GFF_PSD;
1128 return bRet;
1131 /*************************************************************************
1135 \************************************************************************/
1137 BOOL GraphicDescriptor::ImpDetectEPS( SvStream& rStm, BOOL )
1139 // es wird die EPS mit Vorschaubild Variante und die Extensionuebereinstimmung
1140 // geprueft
1142 sal_uInt32 nFirstLong;
1143 sal_uInt8 nFirstBytes[20];
1145 rStm.Seek( nStmPos );
1146 rStm.SetNumberFormatInt( NUMBERFORMAT_INT_BIGENDIAN );
1147 rStm >> nFirstLong;
1148 rStm.SeekRel( -4 );
1149 rStm.Read( &nFirstBytes, 20 );
1151 if ( ( nFirstLong == 0xC5D0D3C6 ) || ( aPathExt.CompareToAscii( "eps", 3 ) == COMPARE_EQUAL ) ||
1152 ( ImplSearchEntry( nFirstBytes, (sal_uInt8*)"%!PS-Adobe", 10, 10 )
1153 && ImplSearchEntry( &nFirstBytes[15], (sal_uInt8*)"EPS", 3, 3 ) ) )
1155 nFormat = GFF_EPS;
1156 return TRUE;
1158 else
1159 return FALSE;
1162 /*************************************************************************
1166 \************************************************************************/
1168 BOOL GraphicDescriptor::ImpDetectDXF( SvStream&, BOOL )
1170 BOOL bRet = aPathExt.CompareToAscii( "dxf", 3 ) == COMPARE_EQUAL;
1171 if (bRet)
1172 nFormat = GFF_DXF;
1174 return bRet;
1177 /*************************************************************************
1181 \************************************************************************/
1183 BOOL GraphicDescriptor::ImpDetectMET( SvStream&, BOOL )
1185 BOOL bRet = aPathExt.CompareToAscii( "met", 3 ) == COMPARE_EQUAL;
1186 if (bRet)
1187 nFormat = GFF_MET;
1189 return bRet;
1193 /*************************************************************************
1197 \************************************************************************/
1199 BOOL GraphicDescriptor::ImpDetectPCT( SvStream& rStm, BOOL )
1201 BOOL bRet = aPathExt.CompareToAscii( "pct", 3 ) == COMPARE_EQUAL;
1202 if (bRet)
1203 nFormat = GFF_PCT;
1204 else
1206 BYTE sBuf[4];
1208 rStm.Seek( nStmPos + 522 );
1209 rStm.Read( sBuf, 3 );
1211 if( !rStm.GetError() )
1213 if ( ( sBuf[0] == 0x00 ) && ( sBuf[1] == 0x11 ) &&
1214 ( ( sBuf[2] == 0x01 ) || ( sBuf[2] == 0x02 ) ) )
1216 bRet = TRUE;
1217 nFormat = GFF_PCT;
1222 return bRet;
1226 /*************************************************************************
1230 \************************************************************************/
1232 BOOL GraphicDescriptor::ImpDetectSGF( SvStream& rStm, BOOL )
1234 BOOL bRet = FALSE;
1236 if( aPathExt.CompareToAscii( "sgf", 3 ) == COMPARE_EQUAL )
1237 bRet = TRUE;
1238 else
1240 BYTE nFirst, nSecond;
1242 rStm.Seek( nStmPos );
1243 rStm >> nFirst >> nSecond;
1245 if( nFirst == 'J' && nSecond == 'J' )
1246 bRet = TRUE;
1249 if( bRet )
1250 nFormat = GFF_SGF;
1252 return bRet;
1256 /*************************************************************************
1260 \************************************************************************/
1262 BOOL GraphicDescriptor::ImpDetectSGV( SvStream&, BOOL )
1264 BOOL bRet = aPathExt.CompareToAscii( "sgv", 3 ) == COMPARE_EQUAL;
1265 if (bRet)
1266 nFormat = GFF_SGV;
1268 return bRet;
1272 /*************************************************************************
1276 \************************************************************************/
1278 BOOL GraphicDescriptor::ImpDetectSVM( SvStream& rStm, BOOL bExtendedInfo )
1280 UINT32 n32;
1281 BOOL bRet = FALSE;
1282 BYTE cByte;
1284 rStm.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN );
1285 rStm.Seek( nStmPos );
1287 rStm >> n32;
1288 if ( n32 == 0x44475653 )
1290 rStm >> cByte;
1291 if ( cByte == 0x49 )
1293 nFormat = GFF_SVM;
1294 bRet = TRUE;
1296 if ( bExtendedInfo )
1298 UINT32 nTemp32;
1299 UINT16 nTemp16;
1301 rStm.SeekRel( 0x04 );
1303 // Breite auslesen
1304 rStm >> nTemp32;
1305 aLogSize.Width() = nTemp32;
1307 // Hoehe auslesen
1308 rStm >> nTemp32;
1309 aLogSize.Height() = nTemp32;
1311 // Map-Unit auslesen und PrefSize ermitteln
1312 rStm >> nTemp16;
1313 aLogSize = OutputDevice::LogicToLogic( aLogSize,
1314 MapMode( (MapUnit) nTemp16 ),
1315 MapMode( MAP_100TH_MM ) );
1319 else
1321 rStm.SeekRel( -4L );
1322 rStm >> n32;
1324 if( n32 == 0x4D4C4356 )
1326 UINT16 nTmp16;
1328 rStm >> nTmp16;
1330 if( nTmp16 == 0x4654 )
1332 nFormat = GFF_SVM;
1333 bRet = TRUE;
1335 if( bExtendedInfo )
1337 MapMode aMapMode;
1339 rStm.SeekRel( 0x06 );
1340 rStm >> aMapMode;
1341 rStm >> aLogSize;
1342 aLogSize = OutputDevice::LogicToLogic( aLogSize, aMapMode, MapMode( MAP_100TH_MM ) );
1348 return bRet;
1352 /*************************************************************************
1356 \************************************************************************/
1358 BOOL GraphicDescriptor::ImpDetectWMF( SvStream&, BOOL )
1360 BOOL bRet = aPathExt.CompareToAscii( "wmf",3 ) == COMPARE_EQUAL;
1361 if (bRet)
1362 nFormat = GFF_WMF;
1364 return bRet;
1367 /*************************************************************************
1371 \************************************************************************/
1373 BOOL GraphicDescriptor::ImpDetectEMF( SvStream&, BOOL )
1375 BOOL bRet = aPathExt.CompareToAscii( "emf", 3 ) == COMPARE_EQUAL;
1376 if (bRet)
1377 nFormat = GFF_EMF;
1379 return bRet;
1382 /*************************************************************************
1386 \************************************************************************/
1388 String GraphicDescriptor::GetImportFormatShortName( sal_uInt16 nFormat )
1390 ByteString aKeyName;
1392 switch( nFormat )
1394 case( GFF_BMP ) : aKeyName = "bmp"; break;
1395 case( GFF_GIF ) : aKeyName = "gif"; break;
1396 case( GFF_JPG ) : aKeyName = "jpg"; break;
1397 case( GFF_PCD ) : aKeyName = "pcd"; break;
1398 case( GFF_PCX ) : aKeyName = "pcx"; break;
1399 case( GFF_PNG ) : aKeyName = "png"; break;
1400 case( GFF_XBM ) : aKeyName = "xbm"; break;
1401 case( GFF_XPM ) : aKeyName = "xpm"; break;
1402 case( GFF_PBM ) : aKeyName = "pbm"; break;
1403 case( GFF_PGM ) : aKeyName = "pgm"; break;
1404 case( GFF_PPM ) : aKeyName = "ppm"; break;
1405 case( GFF_RAS ) : aKeyName = "ras"; break;
1406 case( GFF_TGA ) : aKeyName = "tga"; break;
1407 case( GFF_PSD ) : aKeyName = "psd"; break;
1408 case( GFF_EPS ) : aKeyName = "eps"; break;
1409 case( GFF_TIF ) : aKeyName = "tif"; break;
1410 case( GFF_DXF ) : aKeyName = "dxf"; break;
1411 case( GFF_MET ) : aKeyName = "met"; break;
1412 case( GFF_PCT ) : aKeyName = "pct"; break;
1413 case( GFF_SGF ) : aKeyName = "sgf"; break;
1414 case( GFF_SGV ) : aKeyName = "sgv"; break;
1415 case( GFF_SVM ) : aKeyName = "svm"; break;
1416 case( GFF_WMF ) : aKeyName = "wmf"; break;
1417 case( GFF_EMF ) : aKeyName = "emf"; break;
1420 return String( aKeyName, RTL_TEXTENCODING_ASCII_US );