The Machine Perception Toolbox

[Introduction]- [News]- [Download]- [Screenshots]- [Manual (pdf)]- [Forums]- [API Reference]- [Repository ]

 

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

color.h

Go to the documentation of this file.
00001 /*
00002  * color.h
00003  *
00004  * Copyright (c) 2003 Machine Perception Laboratory
00005  * University of California San Diego.
00006  * Please read the disclaimer and notes about redistribution
00007  * at the end of this file.
00008  *
00009  * Authors: Josh Susskind
00010  */
00011 #ifndef _MPCOLOR_MPUTIL__
00012 #define _MPCOLOR_MPUTIL__
00013 #ifdef WIN32
00014 #include <windows.h>
00015 #endif
00016 #include "../common.h"
00017 #include "ffimage.h"
00018 
00019 // ================================================================
00020 
00021 enum RGBCOLOR {RGBRED=0, RGBGREEN, RGBBLUE, RGBWHITE, RGBTURQ, RGBPURPLE, RGBYELLOW};
00022 
00023 // ================================================================
00024 
00025 class MPColorTools {
00026 private:
00027         float m_low;
00028         float m_high;
00029 public:
00030         MPColorTools (float low = 0.00, float high = 1.00) {
00031          m_low = low;
00032          m_high = high; 
00033         };
00034         bool RGBtoHSV (const unsigned char *pix, float &h, float &s, float &v);
00035         static void hilitePixel(void *pix, const int &type);
00036 
00038 
00039         inline RGBTRIPLE setRGBColor(RGBTRIPLE &x, const int color, double fadeAmount = 1.0) const{     
00040                 switch (color) {
00041                 case RGBRED:
00042                         x.rgbtRed = (unsigned char) (fadeAmount*255.0 + (1.0-fadeAmount)*(double) x.rgbtRed);   
00043                         x.rgbtBlue = (unsigned char) ((1.0-fadeAmount)*(double) x.rgbtBlue);     
00044                         x.rgbtGreen = (unsigned char) ((1.0-fadeAmount)*(double) x.rgbtGreen);
00045                         return x;
00046                         break;
00047                 case RGBBLUE:
00048                         x.rgbtRed = (unsigned char) ((1.0-fadeAmount)*(double) x.rgbtRed);      
00049                         x.rgbtBlue = (unsigned char) (fadeAmount*255.0 + (1.0-fadeAmount)*(double) x.rgbtBlue);  
00050                         x.rgbtGreen = (unsigned char) ((1.0-fadeAmount)*(double) x.rgbtGreen);
00051                         return x;
00052                         break;
00053                 case RGBGREEN:
00054                         x.rgbtRed = (unsigned char) ((1.0-fadeAmount)*(double) x.rgbtRed);      
00055                         x.rgbtBlue = (unsigned char) ((1.0-fadeAmount)*(double) x.rgbtBlue);     
00056                         x.rgbtGreen = (unsigned char) (fadeAmount*255.0 + (1.0-fadeAmount)*(double) x.rgbtGreen);
00057                         return x;
00058                         break;
00059                 case RGBWHITE:
00060                         x.rgbtRed = (unsigned char) (fadeAmount*255.0 + (1.0-fadeAmount)*(double) x.rgbtRed);   
00061                         x.rgbtBlue = (unsigned char) (fadeAmount*255.0 + (1.0-fadeAmount)*(double) x.rgbtBlue);  
00062                         x.rgbtGreen = (unsigned char) (fadeAmount*255.0 + (1.0-fadeAmount)*(double) x.rgbtGreen);
00063                         return x;
00064                         break;
00065                 case RGBTURQ:
00066                         x.rgbtRed = (unsigned char) ((1.0-fadeAmount)*(double) x.rgbtRed);      
00067                         x.rgbtBlue = (unsigned char) (fadeAmount*255.0 + (1.0-fadeAmount)*(double) x.rgbtBlue);  
00068                         x.rgbtGreen = (unsigned char) (fadeAmount*255.0 + (1.0-fadeAmount)*(double) x.rgbtGreen);
00069                         return x;
00070                         break;
00071                 case RGBPURPLE:
00072                         x.rgbtRed = (unsigned char) (fadeAmount*255.0 + (1.0-fadeAmount)*(double) x.rgbtRed);   
00073                         x.rgbtBlue = (unsigned char) (fadeAmount*255.0 + (1.0-fadeAmount)*(double) x.rgbtBlue);  
00074                         x.rgbtGreen = (unsigned char) ((1.0-fadeAmount)*(double) x.rgbtGreen);
00075                         return x;
00076                         break;
00077                 case RGBYELLOW:
00078                         x.rgbtRed = (unsigned char) (fadeAmount*255.0 + (1.0-fadeAmount)*(double) x.rgbtRed);   
00079                         x.rgbtBlue = (unsigned char) ((1.0-fadeAmount)*(double) x.rgbtBlue);     
00080                         x.rgbtGreen = (unsigned char) (fadeAmount*255.0 + (1.0-fadeAmount)*(double) x.rgbtGreen);
00081                         return x;
00082                         break;
00083                 }
00084                 return x;
00085         }
00086 
00088 
00089         inline void DrawRGBBox(FFImage<RGBTRIPLE> &rgbimage, int x, int y, int xSize, int ySize, RGBCOLOR color, double alpha = 1) {
00090                 
00091                 
00092                 int leftX, rightX, topY, bottomY, i;
00093                 RGBTRIPLE *ptr1, *ptr2;
00094                 leftX = max(x, 0);
00095                 rightX = min(x + xSize, rgbimage.width-1);
00096                 if(rgbimage.isFlipped()) {
00097                         topY = min(y + ySize, rgbimage.height-1);
00098                         bottomY = max(y, 0);
00099                 }
00100                 topY = max(y, 0);
00101                 bottomY = min(y + ySize, rgbimage.height-1);
00102                 ptr1 = rgbimage.array + leftX + rgbimage.width*((rgbimage.height-1) - topY);
00103                 ptr2 = rgbimage.array + leftX + rgbimage.width*((rgbimage.height-1) - bottomY);
00104                 for(i = leftX; i <= rightX; ++i, *ptr1++, *ptr2++){
00105                         setRGBColor(*ptr1, color, alpha);
00106                         setRGBColor(*ptr2, color, alpha);
00107                 }
00108                 ptr1 = rgbimage.array + leftX + rgbimage.width*((rgbimage.height-1) - bottomY);
00109                 ptr2 = rgbimage.array + rightX + rgbimage.width*((rgbimage.height-1) - bottomY);
00110                 for(i = topY; i < bottomY; ++i){
00111                         setRGBColor(*ptr1, color, alpha);
00112                         setRGBColor(*ptr2, color, alpha);
00113                         ptr1+=rgbimage.width; ptr2+=rgbimage.width;
00114                 }
00115         }
00116 
00118 
00119 };
00120 
00121 // ================================================================
00122 
00123 #endif //_MPCOLOR_MPUTIL__
00124 
00125 
00126 /*
00127  * 
00128  * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
00129  * 
00130  *    1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
00131  *    2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
00132  *    3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
00133  * 
00134  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00135  * 
00136  */

Generated on Mon Nov 8 17:07:31 2004 for MPT by  doxygen 1.3.9.1