LCOV - code coverage report
Current view: top level - include/vcl - graphicfilter.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 5 0.0 %
Date: 2014-04-14 Functions: 0 5 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #ifndef INCLUDED_VCL_GRAPHICFILTER_HXX
      21             : #define INCLUDED_VCL_GRAPHICFILTER_HXX
      22             : 
      23             : #include <tools/gen.hxx>
      24             : #include <tools/stream.hxx>
      25             : #include <tools/urlobj.hxx>
      26             : #include <vcl/dllapi.h>
      27             : #include <vcl/field.hxx>
      28             : #include <vcl/graph.hxx>
      29             : 
      30             : #include <com/sun/star/uno/Sequence.h>
      31             : #include <com/sun/star/beans/PropertyValue.hpp>
      32             : 
      33             : class FilterConfigCache;
      34             : struct WMF_EXTERNALHEADER;
      35             : struct ConvertData;
      36             : 
      37             : #define GRFILTER_OK                 0
      38             : #define GRFILTER_OPENERROR          1
      39             : #define GRFILTER_IOERROR            2
      40             : #define GRFILTER_FORMATERROR        3
      41             : #define GRFILTER_VERSIONERROR       4
      42             : #define GRFILTER_FILTERERROR        5
      43             : #define GRFILTER_ABORT              6
      44             : #define GRFILTER_TOOBIG             7
      45             : 
      46             : #define GRFILTER_OUTHINT_GREY       1
      47             : 
      48             : #define GRFILTER_FORMAT_NOTFOUND    ((sal_uInt16)0xFFFF)
      49             : #define GRFILTER_FORMAT_DONTKNOW    ((sal_uInt16)0xFFFF)
      50             : 
      51             : #define GRFILTER_I_FLAGS_SET_LOGSIZE_FOR_JPEG       00000001
      52             : #define GRFILTER_I_FLAGS_DONT_SET_LOGSIZE_FOR_JPEG  00000002
      53             : #define GRFILTER_I_FLAGS_FOR_PREVIEW                00000004
      54             : #define GRFILTER_I_FLAGS_ALLOW_PARTIAL_STREAMREAD   00000010
      55             : 
      56             : #define IMP_BMP                 "SVBMP"
      57             : #define IMP_MOV                 "SVMOV"
      58             : #define IMP_SVMETAFILE          "SVMETAFILE"
      59             : #define IMP_WMF                 "SVWMF"
      60             : #define IMP_EMF                 "SVEMF"
      61             : #define IMP_SVSGF               "SVSGF"
      62             : #define IMP_SVSGV               "SVSGV"
      63             : #define IMP_GIF                 "SVIGIF"
      64             : #define IMP_PNG                 "SVIPNG"
      65             : #define IMP_JPEG                "SVIJPEG"
      66             : #define IMP_XBM                 "SVIXBM"
      67             : #define IMP_XPM                 "SVIXPM"
      68             : #define IMP_SVG                 "SVISVG"
      69             : #define EXP_BMP                 "SVBMP"
      70             : #define EXP_SVMETAFILE          "SVMETAFILE"
      71             : #define EXP_WMF                 "SVWMF"
      72             : #define EXP_EMF                 "SVEMF"
      73             : #define EXP_JPEG                "SVEJPEG"
      74             : #define EXP_SVG                 "SVESVG"
      75             : #define EXP_PNG                 "SVEPNG"
      76             : 
      77             : #define BMP_SHORTNAME           "BMP"
      78             : #define MOV_SHORTNAME           "MOV"
      79             : #define GIF_SHORTNAME           "GIF"
      80             : #define JPG_SHORTNAME           "JPG"
      81             : #define MET_SHORTNAME           "MET"
      82             : #define PCT_SHORTNAME           "PCT"
      83             : #define PNG_SHORTNAME           "PNG"
      84             : #define SVM_SHORTNAME           "SVM"
      85             : #define TIF_SHORTNAME           "TIF"
      86             : #define WMF_SHORTNAME           "WMF"
      87             : #define EMF_SHORTNAME           "EMF"
      88             : #define SVG_SHORTNAME           "SVG"
      89             : 
      90             : //  Info class for all supported file formats
      91             : 
      92             : #define GFF_NOT ( (sal_uInt16)0x0000 )
      93             : #define GFF_BMP ( (sal_uInt16)0x0001 )
      94             : #define GFF_GIF ( (sal_uInt16)0x0002 )
      95             : #define GFF_JPG ( (sal_uInt16)0x0003 )
      96             : #define GFF_PCD ( (sal_uInt16)0x0004 )
      97             : #define GFF_PCX ( (sal_uInt16)0x0005 )
      98             : #define GFF_PNG ( (sal_uInt16)0x0006 )
      99             : #define GFF_TIF ( (sal_uInt16)0x0007 )
     100             : #define GFF_XBM ( (sal_uInt16)0x0008 )
     101             : #define GFF_XPM ( (sal_uInt16)0x0009 )
     102             : #define GFF_PBM ( (sal_uInt16)0x000a )
     103             : #define GFF_PGM ( (sal_uInt16)0x000b )
     104             : #define GFF_PPM ( (sal_uInt16)0x000c )
     105             : #define GFF_RAS ( (sal_uInt16)0x000d )
     106             : #define GFF_TGA ( (sal_uInt16)0x000e )
     107             : #define GFF_PSD ( (sal_uInt16)0x000f )
     108             : #define GFF_EPS ( (sal_uInt16)0x0010 )
     109             : #define GFF_DXF ( (sal_uInt16)0x00f1 )
     110             : #define GFF_MET ( (sal_uInt16)0x00f2 )
     111             : #define GFF_PCT ( (sal_uInt16)0x00f3 )
     112             : #define GFF_SGF ( (sal_uInt16)0x00f4 )
     113             : #define GFF_SVM ( (sal_uInt16)0x00f5 )
     114             : #define GFF_WMF ( (sal_uInt16)0x00f6 )
     115             : #define GFF_SGV ( (sal_uInt16)0x00f7 )
     116             : #define GFF_EMF ( (sal_uInt16)0x00f8 )
     117             : #define GFF_SVG ( (sal_uInt16)0x00f9 )
     118             : #define GFF_MOV ( (sal_uInt16)0x00fa )
     119             : #define GFF_XXX ( (sal_uInt16)0xffff )
     120             : 
     121             : 
     122             : // - GraphicDescriptor -
     123             : 
     124             : 
     125             : class VCL_DLLPUBLIC GraphicDescriptor
     126             : {
     127             :     SvStream*           pFileStm;
     128             : 
     129             :     OUString            aPathExt;
     130             :     Size                aPixSize;
     131             :     Size                aLogSize;
     132             :     sal_uInt16          nBitsPerPixel;
     133             :     sal_uInt16          nPlanes;
     134             :     sal_uInt16          nFormat;
     135             :     bool            bCompressed;
     136             :     bool            bOwnStream;
     137             : 
     138             :     void                ImpConstruct();
     139             : 
     140             :     bool            ImpDetectBMP( SvStream& rStm, bool bExtendedInfo );
     141             :     bool            ImpDetectGIF( SvStream& rStm, bool bExtendedInfo );
     142             :     bool            ImpDetectJPG( SvStream& rStm, bool bExtendedInfo );
     143             :     bool            ImpDetectPCD( SvStream& rStm, bool bExtendedInfo );
     144             :     bool            ImpDetectPCX( SvStream& rStm, bool bExtendedInfo );
     145             :     bool            ImpDetectPNG( SvStream& rStm, bool bExtendedInfo );
     146             :     bool            ImpDetectTIF( SvStream& rStm, bool bExtendedInfo );
     147             :     bool            ImpDetectXBM( SvStream& rStm, bool bExtendedInfo );
     148             :     bool            ImpDetectXPM( SvStream& rStm, bool bExtendedInfo );
     149             :     bool            ImpDetectPBM( SvStream& rStm, bool bExtendedInfo );
     150             :     bool            ImpDetectPGM( SvStream& rStm, bool bExtendedInfo );
     151             :     bool            ImpDetectPPM( SvStream& rStm, bool bExtendedInfo );
     152             :     bool            ImpDetectRAS( SvStream& rStm, bool bExtendedInfo );
     153             :     bool            ImpDetectTGA( SvStream& rStm, bool bExtendedInfo );
     154             :     bool            ImpDetectPSD( SvStream& rStm, bool bExtendedInfo );
     155             :     bool            ImpDetectEPS( SvStream& rStm, bool bExtendedInfo );
     156             :     bool            ImpDetectDXF( SvStream& rStm, bool bExtendedInfo );
     157             :     bool            ImpDetectMET( SvStream& rStm, bool bExtendedInfo );
     158             :     bool            ImpDetectPCT( SvStream& rStm, bool bExtendedInfo );
     159             :     bool            ImpDetectSGF( SvStream& rStm, bool bExtendedInfo );
     160             :     bool            ImpDetectSVM( SvStream& rStm, bool bExtendedInfo );
     161             :     bool            ImpDetectWMF( SvStream& rStm, bool bExtendedInfo );
     162             :     bool            ImpDetectSGV( SvStream& rStm, bool bExtendedInfo );
     163             :     bool            ImpDetectEMF( SvStream& rStm, bool bExtendedInfo );
     164             :     bool            ImpDetectSVG( SvStream& rStm, bool bExtendedInfo );
     165             :     bool            ImpDetectMOV( SvStream& rStm, bool bExtendedInfo );
     166             :     GraphicDescriptor( const GraphicDescriptor& );
     167             :     GraphicDescriptor& operator=( const GraphicDescriptor& );
     168             : 
     169             : public:
     170             : 
     171             :     /** Ctor to set a filename
     172             : 
     173             :         Detect() must be called to identify the file
     174             :         If the file has no unique header (Mtf's), the format
     175             :         is determined from the extension */
     176             :     GraphicDescriptor( const INetURLObject& rPath );
     177             : 
     178             :     /** Ctor using a stream
     179             : 
     180             :         Detect() must be called to identify the file
     181             :         As some formats (Mtf's) do not have a unique header, it makes sense
     182             :         to supply the file name (incl. ext.), so that the format can be
     183             :         derived from the extension */
     184             :     GraphicDescriptor( SvStream& rInStream, const OUString* pPath = NULL );
     185             : 
     186             :     virtual ~GraphicDescriptor();
     187             : 
     188             :     /** starts the detection
     189             : 
     190             :         if bExtendedInfo == true the file header is used to derive
     191             :         as many properties as possible (size, color, etc.) */
     192             :     virtual bool    Detect( bool bExtendedInfo = false );
     193             : 
     194             :     /** @return the file format, GFF_NOT if no format was recognized */
     195           0 :     sal_uInt16          GetFileFormat() const { return nFormat; }
     196             : 
     197             :     /** @return graphic size in pixels or 0 size */
     198           0 :     const Size&     GetSizePixel() const { return (Size&) aPixSize; }
     199             : 
     200             :     /** @return the logical graphic size in 1/100mm or 0 size */
     201           0 :     const Size&     GetSize_100TH_MM() const { return (Size&) aLogSize; }
     202             : 
     203             :     /** @return bits/pixel or 0 **/
     204           0 :     sal_uInt16          GetBitsPerPixel() const { return nBitsPerPixel; }
     205             : 
     206             :     /** return number of planes or 0 */
     207             :     sal_uInt16          GetPlanes() const { return nPlanes; }
     208             : 
     209             :     /** @return true if the graphic is compressed */
     210             :     bool            IsCompressed() const { return bCompressed; }
     211             : 
     212             :     /** @return filter number that is needed by the GraphFilter to read this format */
     213             :     static OUString GetImportFormatShortName( sal_uInt16 nFormat );
     214             : };
     215             : 
     216             : /** Information about errors during the GraphicFilter operation. */
     217             : struct FilterErrorEx
     218             : {
     219             :     sal_uLong   nFilterError;
     220             :     sal_uLong   nStreamError;
     221             : 
     222           0 :             FilterErrorEx() : nFilterError( 0UL ), nStreamError( 0UL ) {}
     223             : };
     224             : 
     225             : /** Class to import and export graphic formats. */
     226             : class VCL_DLLPUBLIC GraphicFilter
     227             : {
     228             : private:
     229             : 
     230             :     void            ImplInit();
     231             :     sal_uLong           ImplSetError( sal_uLong nError, const SvStream* pStm = NULL );
     232             :     sal_uInt16      ImpTestOrFindFormat( const OUString& rPath, SvStream& rStream, sal_uInt16& rFormat );
     233             : 
     234             :                     DECL_LINK( FilterCallback, ConvertData* pData );
     235             : 
     236             : protected:
     237             : 
     238             :     OUString       aFilterPath;
     239             :     FilterConfigCache*  pConfig;
     240             :     FilterErrorEx*      pErrorEx;
     241             :     bool            bAbort;
     242             :     bool            bUseConfig;
     243             :     long                nExpGraphHint;
     244             : 
     245             : public:
     246             : 
     247             :                     GraphicFilter( bool bUseConfig = true );
     248             :                     ~GraphicFilter();
     249             : 
     250             :     void            SetFilterPath( const OUString& rFilterPath ) { aFilterPath = rFilterPath; };
     251             : 
     252             :     sal_uInt16          GetImportFormatCount();
     253             :     sal_uInt16          GetImportFormatNumber( const OUString& rFormatName );
     254             :     sal_uInt16          GetImportFormatNumberForMediaType( const OUString& rMediaType );
     255             :     sal_uInt16          GetImportFormatNumberForShortName( const OUString& rShortName );
     256             :     sal_uInt16      GetImportFormatNumberForTypeName( const OUString& rType );
     257             :     OUString        GetImportFormatName( sal_uInt16 nFormat );
     258             :     OUString        GetImportFormatTypeName( sal_uInt16 nFormat );
     259             :     OUString        GetImportFormatMediaType( sal_uInt16 nFormat );
     260             :     OUString        GetImportFormatShortName( sal_uInt16 nFormat );
     261             :     OUString        GetImportOSFileType( sal_uInt16 nFormat );
     262             :     OUString        GetImportWildcard( sal_uInt16 nFormat, sal_Int32 nEntry = 0 );
     263             :     bool            IsImportPixelFormat( sal_uInt16 nFormat );
     264             : 
     265             :     sal_uInt16          GetExportFormatCount();
     266             :     sal_uInt16          GetExportFormatNumber( const OUString& rFormatName );
     267             :     sal_uInt16          GetExportFormatNumberForMediaType( const OUString& rShortName );
     268             :     sal_uInt16          GetExportFormatNumberForShortName( const OUString& rShortName );
     269             :     OUString        GetExportInternalFilterName( sal_uInt16 nFormat );
     270             :     sal_uInt16      GetExportFormatNumberForTypeName( const OUString& rType );
     271             :     OUString        GetExportFormatName( sal_uInt16 nFormat );
     272             :     OUString        GetExportFormatTypeName( sal_uInt16 nFormat );
     273             :     OUString        GetExportFormatMediaType( sal_uInt16 nFormat );
     274             :     OUString        GetExportFormatShortName( sal_uInt16 nFormat );
     275             :     OUString        GetExportOSFileType( sal_uInt16 nFormat );
     276             :     OUString        GetExportWildcard( sal_uInt16 nFormat, sal_Int32 nEntry = 0 );
     277             :     bool            IsExportPixelFormat( sal_uInt16 nFormat );
     278             : 
     279             :     sal_uInt16          ExportGraphic( const Graphic& rGraphic, const INetURLObject& rPath,
     280             :                                     sal_uInt16 nFormat = GRFILTER_FORMAT_DONTKNOW,
     281             :                                         const css::uno::Sequence< css::beans::PropertyValue >* pFilterData = NULL );
     282             :     sal_uInt16          ExportGraphic( const Graphic& rGraphic, const OUString& rPath,
     283             :                                     SvStream& rOStm, sal_uInt16 nFormat = GRFILTER_FORMAT_DONTKNOW,
     284             :                                         const css::uno::Sequence< css::beans::PropertyValue >* pFilterData = NULL );
     285             :     long            GetExportGraphicHint() const { return nExpGraphHint; }
     286             : 
     287             :     sal_uInt16          CanImportGraphic( const INetURLObject& rPath,
     288             :                                       sal_uInt16 nFormat = GRFILTER_FORMAT_DONTKNOW,
     289             :                                       sal_uInt16 * pDeterminedFormat = NULL);
     290             : 
     291             :     sal_uInt16          ImportGraphic( Graphic& rGraphic, const INetURLObject& rPath,
     292             :                                    sal_uInt16 nFormat = GRFILTER_FORMAT_DONTKNOW,
     293             :                                    sal_uInt16 * pDeterminedFormat = NULL, sal_uInt32 nImportFlags = 0 );
     294             : 
     295             :     sal_uInt16          CanImportGraphic( const OUString& rPath, SvStream& rStream,
     296             :                                       sal_uInt16 nFormat = GRFILTER_FORMAT_DONTKNOW,
     297             :                                       sal_uInt16 * pDeterminedFormat = NULL);
     298             : 
     299             :     sal_uInt16          ImportGraphic( Graphic& rGraphic, const OUString& rPath,
     300             :                                    SvStream& rStream,
     301             :                                    sal_uInt16 nFormat = GRFILTER_FORMAT_DONTKNOW,
     302             :                                    sal_uInt16 * pDeterminedFormat = NULL, sal_uInt32 nImportFlags = 0,
     303             :                                    WMF_EXTERNALHEADER *pExtHeader = NULL );
     304             : 
     305             :     sal_uInt16          ImportGraphic( Graphic& rGraphic, const OUString& rPath,
     306             :                                    SvStream& rStream,
     307             :                                    sal_uInt16 nFormat,
     308             :                                    sal_uInt16 * pDeterminedFormat, sal_uInt32 nImportFlags,
     309             :                                    com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >* pFilterData,
     310             :                                    WMF_EXTERNALHEADER *pExtHeader = NULL );
     311             : 
     312             :     void            Abort() { bAbort = true; }
     313             : 
     314             :     const FilterErrorEx&    GetLastError() const;
     315             :     void                    ResetLastError();
     316             : 
     317             :     const Link      GetFilterCallback() const;
     318             :     static GraphicFilter& GetGraphicFilter();
     319             :     static int      LoadGraphic( const OUString& rPath, const OUString& rFilter,
     320             :                      Graphic& rGraphic,
     321             :                      GraphicFilter* pFilter = NULL,
     322             :                      sal_uInt16* pDeterminedFormat = NULL );
     323             : };
     324             : 
     325             : #endif // INCLUDED_VCL_GRAPHICFILTER_HXX
     326             : 
     327             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10