Move the sources to trunk
[opencv] / apps / Common / Image.h
1 /*M///////////////////////////////////////////////////////////////////////////////////////\r
2 //\r
3 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.\r
4 //\r
5 //  By downloading, copying, installing or using the software you agree to this license.\r
6 //  If you do not agree to this license, do not download, install,\r
7 //  copy or use the software.\r
8 //\r
9 //\r
10 //                        Intel License Agreement\r
11 //                For Open Source Computer Vision Library\r
12 //\r
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.\r
14 // Third party copyrights are property of their respective owners.\r
15 //\r
16 // Redistribution and use in source and binary forms, with or without modification,\r
17 // are permitted provided that the following conditions are met:\r
18 //\r
19 //   * Redistribution's of source code must retain the above copyright notice,\r
20 //     this list of conditions and the following disclaimer.\r
21 //\r
22 //   * Redistribution's in binary form must reproduce the above copyright notice,\r
23 //     this list of conditions and the following disclaimer in the documentation\r
24 //     and/or other materials provided with the distribution.\r
25 //\r
26 //   * The name of Intel Corporation may not be used to endorse or promote products\r
27 //     derived from this software without specific prior written permission.\r
28 //\r
29 // This software is provided by the copyright holders and contributors "as is" and\r
30 // any express or implied warranties, including, but not limited to, the implied\r
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.\r
32 // In no event shall the Intel Corporation or contributors be liable for any direct,\r
33 // indirect, incidental, special, exemplary, or consequential damages\r
34 // (including, but not limited to, procurement of substitute goods or services;\r
35 // loss of use, data, or profits; or business interruption) however caused\r
36 // and on any theory of liability, whether in contract, strict liability,\r
37 // or tort (including negligence or otherwise) arising in any way out of\r
38 // the use of this software, even if advised of the possibility of such damage.\r
39 //\r
40 //M*/// Image.h: interface for the CImage class.\r
41 //\r
42 //////////////////////////////////////////////////////////////////////\r
43 \r
44 #if !defined(AFX_IMAGE_H__B0C6A376_E412_4ADD_B1EA_7488350A7F5B__INCLUDED_)\r
45 #define AFX_IMAGE_H__B0C6A376_E412_4ADD_B1EA_7488350A7F5B__INCLUDED_\r
46 \r
47 #if _MSC_VER > 1000\r
48 #pragma once\r
49 #endif // _MSC_VER > 1000\r
50 \r
51 #include "ipl.h"\r
52 \r
53 inline int iplWidth( IplImage* img )\r
54 {\r
55     return !img ? 0 : !(img->roi) ? img->width : img->roi->width;\r
56 }\r
57 \r
58 inline int iplHeight( IplImage* img )\r
59 {\r
60     return !img ? 0 : !(img->roi) ? img->height : img->roi->height;\r
61 }\r
62 \r
63 inline IplROI RectToROI( RECT rect )\r
64 {\r
65     IplROI roi;\r
66     roi.coi = 0;\r
67     roi.xOffset = rect.left;\r
68     roi.yOffset = rect.top;\r
69     roi.width = rect.right - rect.left;\r
70     roi.height = rect.bottom - rect.top;\r
71     return roi;\r
72 }\r
73 \r
74 inline RECT NormalizeRect( RECT r )\r
75 {\r
76     if( r.left > r.right )\r
77     {\r
78         int t = r.left;\r
79         r.left = r.right;\r
80         r.right = t;\r
81     }\r
82 \r
83     if( r.top > r.bottom )\r
84     {\r
85         int t = r.top;\r
86         r.top = r.bottom;\r
87         r.bottom = t;\r
88     }\r
89 \r
90     return r;\r
91 }\r
92 \r
93 class CImage  \r
94 {\r
95 public:\r
96     CImage();\r
97     ~CImage();\r
98     \r
99     /* Create image (BGR or grayscale) */\r
100     bool  Create( int w, int h, int bpp );\r
101     \r
102     /* Load image from specified file */\r
103     bool  Load( const char* filename, int desired_color );\r
104 \r
105     /* Load rectangle from the file */\r
106     bool  LoadRect( const char* filename,\r
107                     int desired_color, RECT r );\r
108     \r
109     /* Save entire image to specified file. */\r
110     bool  Save( const char* filename );\r
111     \r
112     /* Get copy of input image ROI */\r
113     void  CopyOf( CImage& image, int desired_color = -1 );\r
114     void  CopyOf( IplImage* img, int desired_color = -1 );\r
115 \r
116     IplImage* GetImage();\r
117     HDC   GetDC();\r
118     void  Destroy(void);\r
119     \r
120     /* width and height of ROI */\r
121     int   Width() { return iplWidth( &m_img ); };\r
122     int   Height() { return iplHeight( &m_img ); };\r
123 \r
124     /* put part of bitmap to specified destination rectangle */\r
125     void  Show( HDC dc, int x, int y, int w, int h, int from_x, int from_y );\r
126     /* draw all bitmap to specified rectangl of DC */\r
127     void  DrawToHDC( HDC hDCDst, RECT* pDstRect );\r
128 \r
129     void  Fill( COLORREF color );\r
130 \r
131 protected:\r
132 \r
133     void      Clear(void);\r
134     \r
135     HDC       m_memDC;\r
136     HGDIOBJ   m_old;\r
137     IplImage  m_img;\r
138 };\r
139 \r
140 bool  LoadGrFmtLib();\r
141 void  FillBitmapInfo( BITMAPINFO* bmi, int width, int height, int bpp );\r
142 \r
143 #endif // !defined(AFX_IMAGE_H__B0C6A376_E412_4ADD_B1EA_7488350A7F5B__INCLUDED_)\r