1 /// \file CVImageRGB24.h
2 /// \brief 24-bit RGB image class
3 // Written by Michael Ellison
4 //-------------------------------------------------------------------------
5 //                      CodeVis's Free License
6 //                         www.codevis.com
7 //
8 // Copyright (c) 2003 by Michael Ellison (mike@codevis.com)
9 // All rights reserved.
10 //
11 // You may use this software in source and/or binary form, with or without
12 // modification, for commercial or non-commercial purposes, provided that
13 // you comply with the following conditions:
14 //
15 // * Redistributions of source code must retain the above copyright notice,
16 //   this list of conditions and the following disclaimer.
17 //
18 // * Redistributions of modified source must be clearly marked as modified,
19 //   and due notice must be placed in the modified source indicating the
20 //   type of modification(s) and the name(s) of the person(s) performing
21 //   said modification(s).
22 //
23 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 //
35 //---------------------------------------------------------------------------
36 // Modifications:
37 //
38 //---------------------------------------------------------------------------
39 //
40 /// \class CVImageRGB24 CVImageRGB24.h
41 /// CVImageRGB24 is a 24-bit color image class derived from CVImage
42 /// Pixels are 8-bit per channel unsigned chars,
43 /// and are stored as triplets in R,G,B order.
44 ///
45 /// See CVImage.h for general documentation.
46 ///
47 /// \sa CVImage, CVImageGrey, CVImageRGBFloat
48 ///
49 /// $RCSfile: CVImageRGB24.h,v $
50 /// $Date: 2004/02/08 23:47:39 $
51 /// $Revision: 1.1.1.1 $
52 /// $Author: mikeellison $
53 
54 #ifndef _CVImageRGB24_H_
55 #define _CVImageRGB24_H_
56 
57 #include "CVResImage.h"
58 #include "CVImage.h"
59 
60 #ifdef WIN32
61    #include <windows.h> // For SetFromWin32Bmp
62 #endif
63 
64 class CVImageRGBFloat;
65 
66 class CVImageRGB24 : public CVImage
67 {
68    // Allow CVImage to use our constructor
69    friend CVImage;
70 
71    public:
72       //---------------------------------------------------------------------
73       // Overridden functions
74       //---------------------------------------------------------------------
75       /// GetNumChannels retrieves the number of channels per pixel.
76       /// This is one in greyscale, 3 in RGB, and 4 in RGBA
77       ///
78       /// \return int - number of channels per pixel.
79       /// \sa GetBytesPerPixel()
80       virtual int GetNumChannels() const;
81 
82       /// GetBytesPerPixel retrieves the number of bytes per pixel.
83       /// Note that pixel can be in floating point or integer format, depending
84       /// on the image type.
85       ///
86       /// \return int - bytes per pixel
87       virtual int GetBytesPerPixel() const;
88 
89       /// GetImageType() retrieves the image type.
90       /// See CVIMAGE_TYPE enum.
91       ///
92       /// \return CVIMAGE_TYPE specifying the image's type.
93       virtual CVIMAGE_TYPE   GetImageType   () const;
94 
95       /// GetPNMExtension() retrieves the default file extension for PNM
96       /// file saving. (e.g. ".pgm" for greyscale)
97       ///
98       /// \return const char* - ASCIIZ default file extension,
99       ///                       including preceeding '.'
100       /// \sa Load(), Save()
101       virtual const char *GetPNMExtension() const;
102 
103       /// GetPNMMagicVal() retrieves the magic value for a pnm file
104       /// matching the current image format.
105       ///
106       /// \return char - Magic value for PNM files (e.g. '5' for 'P5' .pgm's)
107       /// \sa Load(), Save()
108       virtual char GetPNMMagicVal() const;
109 
110       /// GetMaxPixelValue() retrieves the maximum value of any pixel in
111       /// the image.
112       ///
113       /// In multichannel images (e.g. RGB triplets), it will
114       /// return the maximum value on any of the channels.
115       ///
116       /// All child classes should implement this.
117       /// \param maxValue - reference to max pixel value, set on return.
118       /// \return CVRES result code
119       /// \sa GetPixel(), SetPixel(), CVImage::GetMaxPixel()
120       virtual CVRES GetMaxPixelValue(float& maxValue) const;
121 
122       /// GetPixel() retrieves the red, green, and blue values for a specified
123       /// pixel as floating points.
124       ///
125       /// This is for convenience and prototyping - for high-speed image
126       /// processing you'll need to work more directly with the image
127       /// buffer.
128       ///
129       /// Within CVImageRGB24, this returns the red, green, and blue values
130       /// all of which will be between 0-255.
131       ///
132       /// \param x - x position within the image of the pixel
133       /// \param y - y position within the image of the pixel
134       /// \param r - receives the red value of the pixel
135       /// \param g - receives the green value of the pixel
136       /// \param b - receives the blue value of the pixel
137       ///
138       /// \return CVRES result code.  CVRES_SUCCESS on success.
139       /// \sa SetPixel()
140       virtual CVRES GetPixel( int      x,
141                               int      y,
142                               float&   r,
143                               float&   g,
144                               float&   b) const;
145 
146       /// SetPixel() sets the red, green, and blue pixel values
147       /// for a pixel
148       ///
149       /// This is for convenience and prototyping - for high-speed image
150       /// processing you'll need to work more directly with the image
151       /// buffer.
152       ///
153       /// Within CVImageRGB24, the values are truncated to be between
154       /// 0 (min) and 255 (max), then set.
155       ///
156       /// \param x - x position within the image of the pixel
157       /// \param y - y position within the image of the pixel
158       /// \param r - receives the red value of the pixel
159       /// \param g - receives the green value of the pixel
160       /// \param b - receives the blue value of the pixel
161       ///
162       /// \return CVRES result code.  CVRES_SUCCESS on success.
163       /// \sa GetPixel()
164       virtual CVRES SetPixel       (   int      x,
165                                        int      y,
166                                        float    r,
167                                        float    g,
168                                        float    b);
169 
170    protected:
171 #ifdef WIN32
172       /// Win32-only function for setting image data from a bitmap.
173       /// WARNING: Currently only supports 24-bit uncompressed RGB bitmaps
174       ///
175       /// Bitmap header and data may be freed after call - we do a deep copy
176       /// of the data we care about.
177       ///
178       /// \param bmih - BITMAPINFOHEADER with format information
179       /// \param data - raw bitmap data matching bmih format.
180       ///
181       /// \return CVRES result code.
182       /// \sa ::CVRES_CORE_ENUM, ::CVRES_IMAGE_ENUM, CVImage::ReleaseImage()
183       virtual CVRES SetFromWin32Bmp(  const BITMAPINFOHEADER* bmih,
184                                       const unsigned char*    data);
185 #endif // WIN32
186 
187       //---------------------------------------------------------------------
188    protected:
189       /// Protected constructor - use CVImage::CreateImage() to construct
190       CVImageRGB24();
191       /// Protected destructor - use CVImage::ReleaseImage() to destroy
192       virtual ~CVImageRGB24();
193 };
194 
195 #endif // _CVImageRGB24_H_
196 
197