1/*M///////////////////////////////////////////////////////////////////////////////////////
2//
3//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4//
5//  By downloading, copying, installing or using the software you agree to this license.
6//  If you do not agree to this license, do not download, install,
7//  copy or use the software.
8//
9//
10//                        Intel License Agreement
11//                For Open Source Computer Vision Library
12//
13// Copyright (C) 2000, Intel Corporation, all rights reserved.
14// Third party copyrights are property of their respective owners.
15//
16// Redistribution and use in source and binary forms, with or without modification,
17// are permitted provided that the following conditions are met:
18//
19//   * Redistribution's of source code must retain the above copyright notice,
20//     this list of conditions and the following disclaimer.
21//
22//   * Redistribution's in binary form must reproduce the above copyright notice,
23//     this list of conditions and the following disclaimer in the documentation
24//     and/or other materials provided with the distribution.
25//
26//   * The name of Intel Corporation may not be used to endorse or promote products
27//     derived from this software without specific prior written permission.
28//
29// This software is provided by the copyright holders and contributors "as is" and
30// any express or implied warranties, including, but not limited to, the implied
31// warranties of merchantability and fitness for a particular purpose are disclaimed.
32// In no event shall the Intel Corporation or contributors be liable for any direct,
33// indirect, incidental, special, exemplary, or consequential damages
34// (including, but not limited to, procurement of substitute goods or services;
35// loss of use, data, or profits; or business interruption) however caused
36// and on any theory of liability, whether in contract, strict liability,
37// or tort (including negligence or otherwise) arising in any way out of
38// the use of this software, even if advised of the possibility of such damage.
39//
40//M*/
41
42#ifndef _GRFMT_BASE_H_
43#define _GRFMT_BASE_H_
44
45#if _MSC_VER >= 1200
46    #pragma warning( disable: 4514 )
47    #pragma warning( disable: 4711 )
48    #pragma warning( disable: 4611 )
49#endif
50
51#include "utils.h"
52#include "bitstrm.h"
53
54#define  RBS_BAD_HEADER     -125  /* invalid image header */
55#define  BAD_HEADER_ERR()   goto bad_header_exit
56
57#ifndef _MAX_PATH
58    #define _MAX_PATH    1024
59#endif
60
61
62///////////////////////////////// base class for readers ////////////////////////
63class   GrFmtReader
64{
65public:
66
67    GrFmtReader( const char* filename );
68    virtual ~GrFmtReader();
69
70    int   GetWidth()  { return m_width; };
71    int   GetHeight() { return m_height; };
72    bool  IsColor()   { return m_iscolor; };
73    int   GetDepth()  { return m_bit_depth; };
74    void  UseNativeDepth( bool yes ) { m_native_depth = yes; };
75    bool  IsFloat()   { return m_isfloat; };
76
77    virtual bool  ReadHeader() = 0;
78    virtual bool  ReadData( uchar* data, int step, int color ) = 0;
79    virtual void  Close();
80
81protected:
82
83    bool    m_iscolor;
84    int     m_width;    // width  of the image ( filled by ReadHeader )
85    int     m_height;   // height of the image ( filled by ReadHeader )
86    int     m_bit_depth;// bit depth per channel (normally 8)
87    char    m_filename[_MAX_PATH]; // filename
88    bool    m_native_depth;// use the native bit depth of the image
89    bool    m_isfloat;  // is image saved as float or double?
90};
91
92
93///////////////////////////// base class for writers ////////////////////////////
94class   GrFmtWriter
95{
96public:
97
98    GrFmtWriter( const char* filename );
99    virtual ~GrFmtWriter() {};
100    virtual bool  IsFormatSupported( int depth );
101    virtual bool  WriteImage( const uchar* data, int step,
102                              int width, int height, int depth, int channels ) = 0;
103protected:
104    char    m_filename[_MAX_PATH]; // filename
105};
106
107
108////////////////////////////// base class for filter factories //////////////////
109class   GrFmtFilterFactory
110{
111public:
112
113    GrFmtFilterFactory();
114    virtual ~GrFmtFilterFactory() {};
115
116    const char*  GetDescription() { return m_description; };
117    int     GetSignatureLength()  { return m_sign_len; };
118	virtual bool CheckFile( const char* filename );
119    virtual bool CheckSignature( const char* signature );
120    virtual bool CheckExtension( const char* filename );
121    virtual GrFmtReader* NewReader( const char* filename ) = 0;
122    virtual GrFmtWriter* NewWriter( const char* filename ) = 0;
123
124protected:
125    const char* m_description;
126           // graphic format description in form:
127           // <Some textual description>( *.<extension1> [; *.<extension2> ...]).
128           // the textual description can not contain symbols '(', ')'
129           // and may be, some others. It is safe to use letters, digits and spaces only.
130           // e.g. "Targa (*.tga)",
131           // or "Portable Graphic Format (*.pbm;*.pgm;*.ppm)"
132
133    int          m_sign_len;    // length of the signature of the format
134    const char*  m_signature;   // signature of the format
135};
136
137
138/////////////////////////// list of graphic format filters ///////////////////////////////
139
140typedef void* ListPosition;
141
142class   GrFmtFactoriesList
143{
144public:
145
146    GrFmtFactoriesList();
147    virtual ~GrFmtFactoriesList();
148    void  RemoveAll();
149    bool  AddFactory( GrFmtFilterFactory* factory );
150    int   FactoriesCount() { return m_curFactories; };
151    ListPosition  GetFirstFactoryPos();
152    GrFmtFilterFactory*  GetNextFactory( ListPosition& pos );
153    virtual GrFmtReader*  FindReader( const char* filename );
154    virtual GrFmtWriter*  FindWriter( const char* filename );
155
156protected:
157
158    GrFmtFilterFactory** m_factories;
159    int  m_maxFactories;
160    int  m_curFactories;
161};
162
163#endif/*_GRFMT_BASE_H_*/
164