00001 /* --------------------------------------------------------------------------- 00002 Phission : 00003 Realtime Vision Processing System 00004 00005 Copyright (C) 2003-2006 Philip D.S. Thoren (pthoren@cs.uml.edu) 00006 University of Massachusetts at Lowell, 00007 Laboratory for Artificial Intelligence and Robotics 00008 00009 --------------------------------------------------------------------------- 00010 <Add other copyrights here> 00011 --------------------------------------------------------------------------- 00012 00013 This file is part of Phission. 00014 00015 Phission is free software; you can redistribute it and/or modify 00016 it under the terms of the GNU Lesser General Public License as published by 00017 the Free Software Foundation; either version 2 of the License, or 00018 (at your option) any later version. 00019 00020 Phission is distributed in the hope that it will be useful, 00021 but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 GNU Lesser General Public License for more details. 00024 00025 You should have received a copy of the GNU Lesser General Public License 00026 along with Phission; if not, write to the Free Software 00027 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00028 00029 ---------------------------------------------------------------------------*/ 00030 #ifdef HAVE_CONFIG_H 00031 #include <phissionconfig.h> 00032 #endif 00033 00034 #include <phStandard.h> 00035 00036 #include <grayScale_Filter.h> 00037 00038 #include <phError.h> 00039 #include <phMemory.h> 00040 #include <phPrint.h> 00041 00042 /* ---------------------------------------------------------------------- */ 00043 grayScale_Filter::grayScale_Filter() : 00044 phFilter("grayScale_Filter") 00045 00046 { 00047 /* this->m_format is used to permit only certain image formats 00048 * as input to the filter by OR'ing together the format flags. 00049 * Don't confuse 'm_format' with the 'format' variable! 'format' is the 00050 * ACTUAL input image format stored in the 'Image' variable when 00051 * the 'phFilter::filter' method is called. 00052 */ 00053 this->m_format = (phImageRGB24 | 00054 phImageBGR24 | 00055 phImageRGBA32 | 00056 phImageABGR32 | 00057 phImageGREY8); 00058 00059 } 00060 00061 /* ---------------------------------------------------------------------- */ 00062 grayScale_Filter::~grayScale_Filter() 00063 { 00064 } 00065 00066 /* ------------------------------------------------------------------------ */ 00067 phFilter *grayScale_Filter::cloneFilter() 00068 { 00069 return (phFilter *)new grayScale_Filter(); 00070 } 00071 00072 /* ---------------------------------------------------------------------- */ 00073 int grayScale_Filter::filter() 00074 { 00075 phFUNCTION("grayScale_Filter::filter") 00076 00077 unsigned int x = 0; 00078 unsigned int y = 0; 00079 unsigned int d = 0; 00080 uint32_t value; 00081 00082 /* Begin filter */ 00083 00084 /* Check the input image 'format'; Let an image that is already 00085 * gray scale pass through the filter without any processing. */ 00086 if (format != phImageGREY8) 00087 { 00088 for ( y = 0; y < height; y++ ) 00089 { 00090 for( x = 0; x < width; x++ ) 00091 { 00092 value = 0; 00093 /* Add up the value of the pixels */ 00094 for ( d = 0; d < depth; d++ ) 00095 { 00096 value += (int)Image[(x+y*width)*depth + d]; 00097 } 00098 /* average the values */ 00099 value /= depth; 00100 /* Set the average value into all the pixels: 00101 * 00102 * The equation for going to pixel (x,y) in a linear 00103 * piece of memory that represents an image of 00104 * some (width,height,depth): 00105 * 00106 * index(x,y,width,height,depth) = ((x + (y * width)) * depth) 00107 */ 00108 phMemset(&(Image[(x+(y*width))*depth]), 00109 value, 00110 depth); 00111 /* If RGB is used as input, RGB is also output with all 00112 * per pixel channel values being equal: 00113 * pixel1 [R:0|G:0|B:0], 00114 * pixel2 [R:45|G:45|B:45], 00115 * pixel3 [R:30|G:30|B:30], etc. */ 00116 } 00117 } 00118 } 00119 00120 /* End Filter */ 00121 00122 return phSUCCESS; 00123 } 00124 00125
Copyright (C) 2002 - 2007 |
Philip D.S. Thoren ( pthoren@users.sourceforge.net ) University Of Massachusetts at Lowell Robotics Lab |