[ VIGRA Homepage | Function Index | Class Index | Namespaces | File List | Main Page ]

vigra/codec.hxx |

    00001 /************************************************************************/
    00002 /*                                                                      */
    00003 /*               Copyright 2001-2002 by Gunnar Kedenburg                */
    00004 /*                                                                      */
    00005 /*    This file is part of the VIGRA computer vision library.           */
    00006 /*    The VIGRA Website is                                              */
    00007 /*        http://hci.iwr.uni-heidelberg.de/vigra/                       */
    00008 /*    Please direct questions, bug reports, and contributions to        */
    00009 /*        ullrich.koethe@iwr.uni-heidelberg.de    or                    */
    00010 /*        vigra@informatik.uni-hamburg.de                               */
    00011 /*                                                                      */
    00012 /*    Permission is hereby granted, free of charge, to any person       */
    00013 /*    obtaining a copy of this software and associated documentation    */
    00014 /*    files (the "Software"), to deal in the Software without           */
    00015 /*    restriction, including without limitation the rights to use,      */
    00016 /*    copy, modify, merge, publish, distribute, sublicense, and/or      */
    00017 /*    sell copies of the Software, and to permit persons to whom the    */
    00018 /*    Software is furnished to do so, subject to the following          */
    00019 /*    conditions:                                                       */
    00020 /*                                                                      */
    00021 /*    The above copyright notice and this permission notice shall be    */
    00022 /*    included in all copies or substantial portions of the             */
    00023 /*    Software.                                                         */
    00024 /*                                                                      */
    00025 /*    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND    */
    00026 /*    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES   */
    00027 /*    OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND          */
    00028 /*    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT       */
    00029 /*    HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,      */
    00030 /*    WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING      */
    00031 /*    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR     */
    00032 /*    OTHER DEALINGS IN THE SOFTWARE.                                   */
    00033 /*                                                                      */
    00034 /************************************************************************/
    00035
    00036 /* Modifications by Pablo d'Angelo
    00037  * updated to vigra 1.4 by Douglas Wilkins
    00038  * as of 18 Febuary 2006:
    00039  *  - Added UINT16 and UINT32 pixel types.
    00040  *  - Added support for obtaining extra bands beyond RGB.
    00041  *  - Added support for a position field that indicates the start of this
    00042  *    image relative to some global origin.
    00043  *  - Added support for x and y resolution fields.
    00044  *  - Added support for ICC Profiles
    00045  */
    00046
    00047 #ifndef VIGRA_CODEC_HXX
    00048 #define VIGRA_CODEC_HXX
    00049
    00050 #include <memory>
    00051 #include <string>
    00052 #include <vector>
    00053
    00054 #include "array_vector.hxx"
    00055 #include "config.hxx"
    00056 #include "diff2d.hxx"
    00057 #include "sized_int.hxx"
    00058
    00059 // possible pixel types:
    00060 // "undefined", "UINT8", "UINT16", "INT16", "UINT32", "INT32", "FLOAT", "DOUBLE"
    00061
    00062 // possible compression types:
    00063 // "undefined", "RLE", "LZW", "LOSSLESS", "JPEG", "DEFLATE"
    00064
    00065 // possible file types:
    00066 // "undefined", "TIFF", "VIFF", "JPEG", "PNG", "PNM", "BMP", "SUN", "XPM"
    00067
    00068 // possible name extensions:
    00069 // "undefined", "tif", "tiff", "jpg", "jpeg", "png", "pnm", "bmp", "sun",
    00070 // "xpm" (also capital forms)
    00071
    00072 namespace vigra
    00073 {
    00074     template <class T>
    00075     struct TypeAsString
    00076     {
    00077         static std::string result() { return "undefined"; }
    00078     };
    00079
    00080     template <>
    00081     struct TypeAsString<Int8>
    00082     {
    00083         static std::string result() { return "INT8"; }
    00084     };
    00085
    00086     template <>
    00087     struct TypeAsString<UInt8>
    00088     {
    00089         static std::string result() { return "UINT8"; }
    00090     };
    00091
    00092     template <>
    00093     struct TypeAsString<Int16>
    00094     {
    00095         static std::string result() { return "INT16"; }
    00096     };
    00097
    00098     template <>
    00099     struct TypeAsString<UInt16>
    00100     {
    00101         static std::string result() { return "UINT16"; }
    00102     };
    00103
    00104     template <>
    00105     struct TypeAsString<Int32>
    00106     {
    00107         static std::string result() { return "INT32"; }
    00108     };
    00109
    00110     template <>
    00111     struct TypeAsString<UInt32>
    00112     {
    00113         static std::string result() { return "UINT32"; }
    00114     };
    00115
    00116     template <>
    00117     struct TypeAsString<float>
    00118     {
    00119         static std::string result() { return "FLOAT"; }
    00120     };
    00121
    00122     template <>
    00123     struct TypeAsString<double>
    00124     {
    00125         static std::string result() { return "DOUBLE"; }
    00126     };
    00127
    00128
    00129     // codec description
    00130     struct CodecDesc
    00131     {
    00132         std::string fileType;
    00133         std::vector<std::string> pixelTypes;
    00134         std::vector<std::string> compressionTypes;
    00135         std::vector<std::vector<char> > magicStrings;
    00136         std::vector<std::string> fileExtensions;
    00137         std::vector<int> bandNumbers;
    00138     };
    00139
    00140     // Decoder and Encoder are virtual types that define a common
    00141     // interface for all image file formats impex supports.
    00142
    00143     struct Decoder
    00144     {
    00145         virtual ~Decoder() {};
    00146         virtual void init( const std::string & ) = 0;
    00147         virtual void close() = 0;
    00148         virtual void abort() = 0;
    00149
    00150         virtual std::string getFileType() const = 0;
    00151         virtual std::string getPixelType() const = 0;
    00152
    00153         virtual unsigned int getWidth() const = 0;
    00154         virtual unsigned int getHeight() const = 0;
    00155         virtual unsigned int getNumBands() const = 0;
    00156         virtual unsigned int getNumExtraBands() const
    00157         {
    00158             return 0;
    00159         }
    00160
    00161         virtual vigra::Diff2D getPosition() const
    00162         {
    00163             return vigra::Diff2D();
    00164         }
    00165
    00166         virtual float getXResolution() const
    00167         {
    00168             return 0.0f;
    00169         }
    00170         virtual float getYResolution() const
    00171         {
    00172             return 0.0f;
    00173         }
    00174
    00175         virtual unsigned int getOffset() const = 0;
    00176
    00177         virtual const void * currentScanlineOfBand( unsigned int ) const = 0;
    00178         virtual void nextScanline() = 0;
    00179
    00180         typedef ArrayVector<unsigned char> ICCProfile;
    00181
    00182         const ICCProfile & getICCProfile() const
    00183         {
    00184             return iccProfile_;
    00185         }
    00186
    00187         ICCProfile iccProfile_;
    00188     };
    00189
    00190     struct Encoder
    00191     {
    00192         virtual ~Encoder() {};
    00193         virtual void init( const std::string & ) = 0;
    00194         virtual void close() = 0;
    00195         virtual void abort() = 0;
    00196
    00197         virtual std::string getFileType() const = 0;
    00198         virtual unsigned int getOffset() const = 0;
    00199
    00200         virtual void setWidth( unsigned int ) = 0;
    00201         virtual void setHeight( unsigned int ) = 0;
    00202         virtual void setNumBands( unsigned int ) = 0;
    00203         virtual void setCompressionType( const std::string &, int = -1 ) = 0;
    00204         virtual void setPixelType( const std::string & ) = 0;
    00205         virtual void finalizeSettings() = 0;
    00206
    00207         virtual void setPosition( const vigra::Diff2D & /*pos*/ )
    00208         {
    00209         }
    00210         virtual void setXResolution( float /*xres*/ )
    00211         {
    00212         }
    00213         virtual void setYResolution( float /*yres*/ )
    00214         {
    00215         }
    00216
    00217         typedef ArrayVector<unsigned char> ICCProfile;
    00218
    00219         virtual void setICCProfile(const ICCProfile & /* data */)
    00220         {
    00221         }
    00222
    00223         virtual void * currentScanlineOfBand( unsigned int ) = 0;
    00224         virtual void nextScanline() = 0;
    00225
    00226         struct TIFFCompressionException {};
    00227     };
    00228
    00229     // codec factory for registration at the codec manager
    00230
    00231     struct CodecFactory
    00232     {
    00233         virtual CodecDesc getCodecDesc() const = 0;
    00234         virtual std::auto_ptr<Decoder> getDecoder() const = 0;
    00235         virtual std::auto_ptr<Encoder> getEncoder() const = 0;
    00236         virtual ~CodecFactory() {};
    00237     };
    00238
    00239     // factory functions to encapsulate the codec managers
    00240     //
    00241     // codecs are selected according to the following order:
    00242     // - (if provided) the FileType
    00243     // - (in case of decoders) the file's magic string
    00244     // - the filename extension
    00245
    00246     VIGRA_EXPORT std::auto_ptr<Decoder>
    00247     getDecoder( const std::string &, const std::string & = "undefined" );
    00248
    00249     VIGRA_EXPORT std::auto_ptr<Encoder>
    00250     getEncoder( const std::string &, const std::string & = "undefined" );
    00251
    00252     VIGRA_EXPORT std::string
    00253     getEncoderType( const std::string &, const std::string & = "undefined" );
    00254
    00255     // functions to query the capabilities of certain codecs
    00256
    00257     VIGRA_EXPORT std::vector<std::string> queryCodecPixelTypes( const std::string & );
    00258
    00259     VIGRA_EXPORT bool negotiatePixelType( std::string const & codecname,
    00260                  std::string const & srcPixeltype, std::string & destPixeltype);
    00261
    00262     VIGRA_EXPORT bool isPixelTypeSupported( const std::string &, const std::string & );
    00263
    00264     VIGRA_EXPORT bool isBandNumberSupported( const std::string &, int bands );
    00265 }
    00266
    00267 #endif // VIGRA_CODEC_HXX

© Ullrich Köthe (ullrich.koethe@iwr.uni-heidelberg.de) Heidelberg Collaboratory for Image Processing, University of Heidelberg, Germany | html generated using doxygen and Python vigra 1.7.1 (3 Dec 2010)