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

brightness_Filter.cpp

Go to the documentation of this file.
00001 /* ---------------------------------------------------------------------------
00002     Phission :
00003         Realtime Vision Processing System
00004 
00005     Copyright (C) 2003-2005 Philip D.S. Thoren (pthoren@cs.uml.edu)
00006     University of Massachusetts at Lowell,
00007     Laboratory for Artificial Intelligence and Robotics
00008 
00009     This file is part of Phission.
00010 
00011     Phission is free software; you can redistribute it and/or modify
00012     it under the terms of the GNU Lesser General Public License as published by
00013     the Free Software Foundation; either version 2 of the License, or
00014     (at your option) any later version.
00015 
00016     Phission is distributed in the hope that it will be useful,
00017     but WITHOUT ANY WARRANTY; without even the implied warranty of
00018     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019     GNU Lesser General Public License for more details.
00020 
00021     You should have received a copy of the GNU Lesser General Public License
00022     along with Phission; if not, write to the Free Software
00023     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00024 
00025  ---------------------------------------------------------------------------*/
00026 #ifdef HAVE_CONFIG_H
00027     #include <phissionconfig.h>
00028 #endif
00029 
00030 #include <phStandard.h>
00031 
00032 #include <brightness_Filter.h>
00033 
00034 #include <phError.h>
00035 #include <phMemory.h>
00036 #include <phPrint.h>
00037 
00038 /* ------------------------------------------------------------------------ */
00039 brightness_Filter::brightness_Filter( int32_t adjustment,
00040                                       int32_t channel ) :
00041         phFilter("brightness_Filter")
00042 {
00043     this->m_format      = phImagePackedFormatMask;
00044     
00045     this->m_adjustment  = adjustment;
00046     this->m_channel     = channel;
00047     this->m_use_param   = 0;
00048     
00049     this->m_adjust_arr      = NULL;
00050     this->m_adjust_nelems   = 0;
00051     this->m_adjust_arr_size = 0;
00052 
00053     this->m_temp_adjust     = NULL;
00054     this->m_temp_adjust_size= 0;
00055 }
00056 
00057 /* ------------------------------------------------------------------------ */
00058 brightness_Filter::brightness_Filter( int32_t *adjustment_array,
00059                                       uint32_t nelems ): 
00060         phFilter("brightness_Filter")
00061 {
00062     phFUNCTION("brightness_Filter::brightness_Filter(int32_t*,uint32_t)")
00063 
00064     this->m_format      = phImagePackedFormatMask;
00065    
00066     rc = this->set( adjustment_array, nelems );
00067     phPRINT_RC(rc,NULL,"this->set()");
00068     
00069     this->m_adjustment  = 0;
00070     this->m_channel     = -1;
00071 
00072     this->m_temp_adjust     = NULL;
00073     this->m_temp_adjust_size= 0;
00074 }
00075 
00076 /* ------------------------------------------------------------------------ */
00077 brightness_Filter::~brightness_Filter()
00078 {
00079     phFUNCTION("brightness_Filter::~brightness_Filter")
00080     int locked = 0;
00081    
00082     phTHIS_LOOSE_LOCK(locked);
00083     
00084     phFree(this->m_adjust_arr);
00085     this->m_adjust_arr_size = 0;
00086     this->m_adjust_nelems   = 0;
00087     this->m_adjust_nelems = 0;
00088 
00089     phTHIS_LOOSE_UNLOCK(locked);
00090 }
00091 
00092 /* ------------------------------------------------------------------------ */
00093 int brightness_Filter::set( int32_t adjustment,
00094                             int32_t channel )
00095 {
00096     phFUNCTION("brightness_Filter::set(int,int)")
00097     int locked = 0;
00098     
00099     phTHIS_LOCK(locked);
00100 
00101     this->m_adjustment  = adjustment;
00102     this->m_channel     = channel;
00103     this->m_use_param   = 0;
00104 
00105     phTHIS_UNLOCK(locked);
00106 
00107     return phSUCCESS;
00108 error:
00109     phTHIS_ERROR_UNLOCK(locked);
00110 
00111     return phFAIL;
00112 }
00113 
00114 /* ------------------------------------------------------------------------ */
00115 int brightness_Filter::set( int32_t *adjustment_array,
00116                             uint32_t nelems )
00117                             
00118 {
00119     phFUNCTION("brightness_Filter::set(int32_t*,uint32_t)")
00120     int         locked  = 0;
00121     
00122     phTHIS_LOCK(locked);
00123 
00124     phDALLOC(this->m_adjust_arr,
00125              this->m_adjust_arr_size,
00126              nelems,
00127              int32_t);
00128     this->m_adjust_nelems   = nelems;
00129     phMemcpy(this->m_adjust_arr,adjustment_array,this->m_adjust_arr_size);
00130 
00131     this->m_use_param       = 1;
00132 
00133     phTHIS_UNLOCK(locked);
00134 
00135     return phSUCCESS;
00136 error:
00137     phTHIS_ERROR_UNLOCK(locked);
00138 
00139     return phFAIL;
00140 }
00141 
00142 /* ------------------------------------------------------------------------ */
00143 phFilter *brightness_Filter::cloneFilter()
00144 {
00145     phFUNCTION("brightness_Filter::cloneFilter")
00146     int         locked = 0;
00147     phFilter   *retval = NULL;
00148 
00149     phTHIS_LOCK(locked);
00150     
00151     if (this->m_use_param == 0)
00152         retval = (phFilter *)new brightness_Filter(this->m_adjustment,
00153                                                    this->m_channel);
00154     else
00155         retval = (phFilter *)new brightness_Filter(this->m_adjust_arr,
00156                                                    this->m_adjust_nelems);
00157     
00158     phTHIS_UNLOCK(locked);
00159 
00160     return retval;
00161 error:
00162     phTHIS_ERROR_UNLOCK(locked);
00163     phDelete(retval);
00164 
00165     return NULL;
00166 
00167 }
00168 
00169 /* ------------------------------------------------------------------------ */
00170 int brightness_Filter::filter()
00171 {
00172     phFUNCTION("brightness_Filter::filter()")
00173 
00174     uint32_t    limit       = 0;
00175     uint32_t    i           = 0;
00176     int32_t     x           = 0;
00177     uint8_t    *imgptr      = NULL;
00178     int32_t     img_step    = 1;
00179     int32_t    *adjust_arr  = NULL;
00180 
00181     if ((this->m_adjustment == 0) && (this->m_use_param == 0)) 
00182     {
00183         return phSUCCESS;
00184     }
00185     else if (((this->m_adjust_arr == NULL) || (this->m_adjust_nelems == 0)) &&
00186              (this->m_use_param == 1))
00187     {
00188         return phSUCCESS;
00189     }
00190     
00191     limit = width * height * depth;
00192 
00193     /* use the adjustment value and put it into the m_temp_adjust array */
00194     if (this->m_use_param == 0)
00195     {
00196         phDALLOC(this->m_temp_adjust,
00197                  this->m_temp_adjust_size,
00198                  depth,
00199                  int32_t);
00200 
00201         /* If the user is only changing one channel */
00202         if ((this->m_channel >= 0) && (this->m_channel < (int32_t)depth))
00203         {
00204             this->m_temp_adjust[this->m_channel] = this->m_adjustment;
00205             img_step = depth;
00206         }
00207         /* Adjust the S & V channel for HSV */
00208         else if (format & phImageHSV24)
00209         {
00210             this->m_temp_adjust[1] /* S */= 
00211                 this->m_temp_adjust[2] /* V */= this->m_adjustment;
00212         }
00213         /* Adjust the L channel for SCT/LAB */
00214         else if (format & phImageSCT24)
00215         {
00216             this->m_temp_adjust[0] = this->m_adjustment;
00217             img_step = depth;
00218         }
00219         /* Adjust all the channels for the RGB color spaces */
00220         else
00221         {
00222             if (format & (phImageRGB24 | 
00223                           phImageRGBA32 | 
00224                           phImageBGRA32 |
00225                           phImageBGR24))
00226             {
00227                 for (i = 0; i < 3; i++ )
00228                     this->m_temp_adjust[i] = this->m_adjustment;
00229             }
00230             else if (format & (phImageABGR32))
00231             {
00232                 for (i = 1; i < depth; i++ )
00233                     this->m_temp_adjust[i] = this->m_adjustment;
00234             }
00235         } 
00236         adjust_arr = this->m_temp_adjust;
00237     }
00238     else
00239     {
00240         adjust_arr = this->m_adjust_arr;
00241     }
00242     
00243     imgptr = Image;
00244 
00245     for (i = 0; i < limit; i++, imgptr++ )
00246     {   
00247         x = *imgptr;
00248         x = x + adjust_arr[i];
00249         if (x > 255)    x = 255;
00250         else if (x < 0) x = 0;
00251         *imgptr = (uint8_t)x;
00252         if (i == depth) i = 0;
00253     }
00254 
00255     return phSUCCESS;
00256 error:
00257     return phFAIL;
00258 }
00259 




Copyright (C) 2002 - 2007 Philip D.S. Thoren ( pthoren@users.sourceforge.net )
University Of Massachusetts at Lowell
Robotics Lab
SourceForge.net Logo

Generated on Sat Jun 16 02:44:09 2007 for phission by  doxygen 1.4.4