Fawkes API Fawkes Development Version

threshold.cpp

00001 
00002 /***************************************************************************
00003  *  threshold.cpp - Implementation for threshold filter, this filter will
00004  *                  luminance values below a given threshold to the given
00005  *                  min_replace value, values above a given max threshold
00006  *                  will be set to the max_replace value
00007  *
00008  *  Created: Tue Jun 07 14:30:10 2005
00009  *  Copyright  2005-2007  Tim Niemueller [www.niemueller.de]
00010  *
00011  ****************************************************************************/
00012 
00013 /*  This program is free software; you can redistribute it and/or modify
00014  *  it under the terms of the GNU General Public License as published by
00015  *  the Free Software Foundation; either version 2 of the License, or
00016  *  (at your option) any later version. A runtime exception applies to
00017  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00018  *
00019  *  This program is distributed in the hope that it will be useful,
00020  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022  *  GNU Library General Public License for more details.
00023  *
00024  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00025  */
00026 
00027 #include <filters/threshold.h>
00028 
00029 #include <core/exception.h>
00030 
00031 #include <cstddef>
00032 #include <ippi.h>
00033 
00034 namespace firevision {
00035 #if 0 /* just to make Emacs auto-indent happy */
00036 }
00037 #endif
00038 
00039 /** @class FilterThreshold <filters/threshold.h>
00040  * Threshold filter
00041  */
00042 
00043 /** Constructor.
00044  * @param min minimum value
00045  * @param min_replace values below min are replaced with this value
00046  * @param max maximum value
00047  * @param max_replace values above max are replaced with this value
00048  */
00049 FilterThreshold::FilterThreshold(unsigned char min, unsigned char min_replace,
00050                                  unsigned char max, unsigned char max_replace)
00051   : Filter("FilterThreshold")
00052 {
00053   this->min = min;
00054   this->max = max;
00055   this->min_replace = min_replace;
00056   this->max_replace = max_replace;
00057 }
00058 
00059 
00060 /** Set new thresholds.
00061  * @param min minimum value
00062  * @param min_replace values below min are replaced with this value
00063  * @param max maximum value
00064  * @param max_replace values above max are replaced with this value
00065  */
00066 void
00067 FilterThreshold::set_thresholds(unsigned char min, unsigned char min_replace,
00068                                 unsigned char max, unsigned char max_replace)
00069 {
00070   this->min = min;
00071   this->max = max;
00072   this->min_replace = min_replace;
00073   this->max_replace = max_replace;
00074 }
00075 
00076 
00077 void
00078 FilterThreshold::apply()
00079 {
00080   IppiSize size;
00081   size.width = src_roi[0]->width;
00082   size.height = src_roi[0]->height;
00083 
00084   IppStatus status;
00085 
00086   if ((dst == NULL) || (dst == src[0])) {
00087     // In-place
00088     status = ippiThreshold_GTVal_8u_C1IR( src[0] + (src_roi[0]->start.y * src_roi[0]->line_step) + (src_roi[0]->start.x * src_roi[0]->pixel_step), src_roi[0]->line_step,
00089                                           size, max, max_replace );
00090     if ( status == ippStsNoErr ) {
00091       status = ippiThreshold_LTVal_8u_C1IR( src[0] + (src_roi[0]->start.y * src_roi[0]->line_step) + (src_roi[0]->start.x * src_roi[0]->pixel_step), src_roi[0]->line_step,
00092                                             size, min, min_replace );
00093     }
00094   } else {
00095     //                                base + number of bytes to line y              + pixel bytes
00096     status = ippiThreshold_GTVal_8u_C1R( src[0] + (src_roi[0]->start.y * src_roi[0]->line_step) + (src_roi[0]->start.x * src_roi[0]->pixel_step), src_roi[0]->line_step,
00097                                          dst + (dst_roi->start.y * dst_roi->line_step) + (dst_roi->start.x * dst_roi->pixel_step), dst_roi->line_step,
00098                                          size, max, max_replace );
00099 
00100     if ( status == ippStsNoErr ) {
00101       status = ippiThreshold_LTVal_8u_C1R( src[0] + (src_roi[0]->start.y * src_roi[0]->line_step) + (src_roi[0]->start.x * src_roi[0]->pixel_step), src_roi[0]->line_step,
00102                                            dst + (dst_roi->start.y * dst_roi->line_step) + (dst_roi->start.x * dst_roi->pixel_step), dst_roi->line_step,
00103                                            size, min, min_replace );
00104     }
00105   }
00106 
00107   if ( status != ippStsNoErr ) {
00108     throw fawkes::Exception("Threshold filter failed with %i\n", status);
00109   }
00110 
00111 }
00112 
00113 } // end namespace firevision
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends