Move the sources to trunk
[opencv] / otherlibs / VlGrFmts / grfmt.h
1 /*M///////////////////////////////////////////////////////////////////////////////////////
2 //  
3 //                      INTEL CORPORATION PROPRIETARY INFORMATION              
4 //         This software is supplied under the terms of a license agreement or 
5 //         nondisclosure agreement with Intel Corporation and may not be copied
6 //         or disclosed except in accordance with the terms of that agreement. 
7 //               Copyright (c) 1999 Intel Corporation. All Rights Reserved.    
8 //  
9 //    RCS:
10 //       Source:    grfmt.h$
11 //       $Revision: 1.2 $
12 //      Purpose: 
13 //      Contents:
14 //      Authors: Vadim Pisarevsky
15 //  
16 //M*/
17
18 #pragma once
19
20 #pragma warning( disable: 4514 )
21 #pragma warning( disable: 4711 )
22
23 typedef unsigned char byte;
24
25 // graphics_format_reader interface
26 class  graphics_format_reader
27 {
28 public:
29     
30     graphics_format_reader();
31
32     int           get_signature_length() { return m_sign_len; };
33     const char*   get_description() { return m_description; };
34     int           get_width()  { return m_width; };
35     int           get_height() { return m_height; };
36     
37     virtual bool  check_format( const char* signature );
38     void          set_file( const char* filename );
39
40     virtual int   get_color() = 0;
41     virtual bool  read_header() = 0;
42     virtual bool  read_data( byte* data, int pitch, int color ) = 0;
43     virtual void  close() = 0;
44
45 protected:
46     int          m_width;       // width  of an image ( filled by read_header )
47     int          m_height;      // height of an image ( filled by read_header )
48     int          m_sign_len;    // length of the signature of the format
49     const char*  m_signature;   // signature of the format
50     const char*  m_description; // e.g: Graphics interchange format (*.GIF)
51     char         m_filename[1000];
52 };
53
54
55 typedef struct {} list_position;
56
57 // list of <graphics_format_reader>s
58 class  graphics_format_readers_list
59 {
60 public:
61
62     graphics_format_readers_list();
63     ~graphics_format_readers_list();
64     void                    remove_all_readers();
65     void                    add_reader( graphics_format_reader* reader );
66     int                     readers_count() { return m_cur_readers; };
67     list_position*          get_first_reader_pos();
68     graphics_format_reader* get_next_reader( list_position*& pos );
69     graphics_format_reader* find_reader( const char* filename );
70     int                     get_filters_string( char* buffer, int maxlen );
71
72 protected:
73
74     graphics_format_reader** m_readers;
75     int  m_max_readers;
76     int  m_cur_readers;
77 };
78
79 struct palette_entry 
80 {
81     unsigned char b,g,r,a;
82 };
83
84 #define WRITE_PIX( ptr, clr )     \
85     (((byte*)(ptr))[0] = (clr).b, \
86      ((byte*)(ptr))[1] = (clr).g, \
87      ((byte*)(ptr))[2] = (clr).r)
88
89 #define  descale(x,n)  (((x) + (1 << ((n)-1))) >> (n))
90 #define  saturate(x)   (byte)(((x) & ~255) == 0 ? (x) : ~((x)>>31))
91
92 void  cvt_bgr_to_gray( byte* bgr, byte* gray, int len );
93 void  cvt_palette_to_gray( palette_entry* palette, byte* gray_palette, int entries );