1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
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.
10 // Intel License Agreement
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
19 // * Redistribution's of source code must retain the above copyright notice,
20 // this list of conditions and the following disclaimer.
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.
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.
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.
42 #ifndef _GRFMT_BASE_H_
43 #define _GRFMT_BASE_H_
46 #pragma warning( disable: 4514 )
47 #pragma warning( disable: 4711 )
48 #pragma warning( disable: 4611 )
54 #define RBS_BAD_HEADER -125 /* invalid image header */
55 #define BAD_HEADER_ERR() goto bad_header_exit
58 #define _MAX_PATH 1024
62 ///////////////////////////////// base class for readers ////////////////////////
67 GrFmtReader( const char* filename );
68 virtual ~GrFmtReader();
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; };
77 virtual bool ReadHeader() = 0;
78 virtual bool ReadData( uchar* data, int step, int color ) = 0;
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?
93 ///////////////////////////// base class for writers ////////////////////////////
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;
104 char m_filename[_MAX_PATH]; // filename
108 ////////////////////////////// base class for filter factories //////////////////
109 class GrFmtFilterFactory
113 GrFmtFilterFactory();
114 virtual ~GrFmtFilterFactory() {};
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;
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)"
133 int m_sign_len; // length of the signature of the format
134 const char* m_signature; // signature of the format
138 /////////////////////////// list of graphic format filters ///////////////////////////////
140 typedef void* ListPosition;
142 class GrFmtFactoriesList
146 GrFmtFactoriesList();
147 virtual ~GrFmtFactoriesList();
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 );
158 GrFmtFilterFactory** m_factories;
163 #endif/*_GRFMT_BASE_H_*/