Fawkes API  Fawkes Development Version
min.cpp
00001 
00002 /***************************************************************************
00003  *  min.cpp - implementation of min intensity filter
00004  *
00005  *  Created: Mon Jun 05 16:57:57 2006
00006  *  Copyright  2005-2007  Tim Niemueller [www.niemueller.de]
00007  *
00008  ****************************************************************************/
00009 
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version. A runtime exception applies to
00014  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00015  *
00016  *  This program 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 Library General Public License for more details.
00020  *
00021  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00022  */
00023 
00024 #include <filters/min.h>
00025 
00026 #include <core/exceptions/software.h>
00027 #include <fvutils/color/yuv.h>
00028 #include <cstddef>
00029 
00030 using namespace fawkes;
00031 
00032 namespace firevision {
00033 #if 0 /* just to make Emacs auto-indent happy */
00034 }
00035 #endif
00036 
00037 /** @class FilterMin <filters/min.h>
00038  * Minimum filter
00039  * @author Tim Niemueller
00040  */
00041 
00042 /** Constructor. */
00043 FilterMin::FilterMin()
00044   : Filter("FilterMin", 2)
00045 {
00046 }
00047 
00048 
00049 void
00050 FilterMin::apply()
00051 {
00052   if ( src[0] == NULL ) throw NullPointerException("FilterInvert: src buffer 0 is NULL");
00053   if ( src[1] == NULL ) throw NullPointerException("FilterInvert: src buffer 1 is NULL");
00054   if ( src_roi[0] == NULL ) throw NullPointerException("FilterInvert: src ROI 0 is NULL");
00055   if ( src_roi[1] == NULL ) throw NullPointerException("FilterInvert: src ROI 1 is NULL");
00056 
00057   register unsigned int h = 0;
00058   register unsigned int w = 0;
00059 
00060   // y-plane
00061   register unsigned char *byp   = src[0] + (src_roi[0]->start.y * src_roi[0]->line_step) + (src_roi[0]->start.x * src_roi[0]->pixel_step);
00062   // u-plane
00063   register unsigned char *bup   = YUV422_PLANAR_U_PLANE(src[0], src_roi[0]->image_width, src_roi[0]->image_height)
00064     + ((src_roi[0]->start.y * src_roi[0]->line_step) / 2 + (src_roi[0]->start.x * src_roi[0]->pixel_step) / 2) ;
00065   // v-plane
00066   register unsigned char *bvp   = YUV422_PLANAR_V_PLANE(src[0], src_roi[0]->image_width, src_roi[0]->image_height)
00067     + ((src_roi[0]->start.y * src_roi[0]->line_step) / 2 + (src_roi[0]->start.x * src_roi[0]->pixel_step) / 2);
00068 
00069 
00070   // y-plane
00071   register unsigned char *fyp   = src[1] + (src_roi[1]->start.y * src_roi[1]->line_step) + (src_roi[1]->start.x * src_roi[1]->pixel_step);
00072   // u-plane
00073   register unsigned char *fup   = YUV422_PLANAR_U_PLANE(src[1], src_roi[1]->image_width, src_roi[1]->image_height)
00074     + ((src_roi[1]->start.y * src_roi[1]->line_step) / 2 + (src_roi[1]->start.x * src_roi[1]->pixel_step) / 2) ;
00075   // v-plane
00076   register unsigned char *fvp   = YUV422_PLANAR_V_PLANE(src[1], src_roi[1]->image_width, src_roi[1]->image_height)
00077     + ((src_roi[1]->start.y * src_roi[1]->line_step) / 2 + (src_roi[1]->start.x * src_roi[1]->pixel_step) / 2);
00078 
00079 
00080   // destination y-plane
00081   register unsigned char *dyp  = dst + (dst_roi->start.y * dst_roi->line_step) + (dst_roi->start.x * dst_roi->pixel_step);
00082   // destination u-plane
00083   register unsigned char *dup   = YUV422_PLANAR_U_PLANE(dst, dst_roi->image_width, dst_roi->image_height)
00084     + ((dst_roi->start.y * dst_roi->line_step) / 2 + (dst_roi->start.x * dst_roi->pixel_step) / 2) ;
00085   // destination v-plane
00086   register unsigned char *dvp   = YUV422_PLANAR_V_PLANE(dst, dst_roi->image_width, dst_roi->image_height)
00087     + ((dst_roi->start.y * dst_roi->line_step) / 2 + (dst_roi->start.x * dst_roi->pixel_step) / 2);
00088   
00089   // line starts
00090   unsigned char *lbyp = byp;   // y-plane
00091   unsigned char *lbup = fup;   // u-plane
00092   unsigned char *lbvp = fvp;   // v-plane
00093   unsigned char *lfyp = fyp;   // y-plane
00094   unsigned char *lfup = fup;   // u-plane
00095   unsigned char *lfvp = fvp;   // v-plane
00096   unsigned char *ldyp = dyp;  // destination y-plane
00097   unsigned char *ldup = dup;  // destination u-plane
00098   unsigned char *ldvp = dvp;  // destination v-plane
00099 
00100   unsigned char u1, u2, v1, v2;
00101 
00102   for (h = 0; (h < src_roi[1]->height) && (h < dst_roi->height); ++h) {
00103     for (w = 0; (w < src_roi[1]->width) && (w < dst_roi->width); w += 2) {
00104       if ( *byp < *fyp ) {
00105         *dyp++ = *byp;
00106         u1 = *bup;
00107         v1 = *bvp;
00108       } else {
00109         *dyp++ = *fyp;
00110         u1 = *fup;
00111         v1 = *fvp;
00112       }
00113       ++byp;
00114       ++fyp;
00115 
00116       if ( *byp < *fyp ) {
00117         *dyp++ = *byp;
00118         u2 = *bup;
00119         v2 = *bvp;
00120       } else {
00121         *dyp++ = *fyp;
00122         u2 = *fup;
00123         v2 = *fvp;
00124       }
00125       ++byp;
00126       ++fyp;
00127 
00128       *dup++ = (u1 + u2) / 2;
00129       *dvp++ = (v1 + v2) / 2;
00130 
00131       ++bup;
00132       ++bvp;
00133       ++fup;
00134       ++fvp;
00135     }
00136 
00137     lbyp   += src_roi[0]->line_step;
00138     lbup   += src_roi[0]->line_step / 2;
00139     lbvp   += src_roi[0]->line_step / 2;
00140     lfyp   += src_roi[1]->line_step;
00141     lfup   += src_roi[1]->line_step / 2;
00142     lfvp   += src_roi[1]->line_step / 2;
00143     ldyp  += dst_roi->line_step;
00144     ldup  += dst_roi->line_step / 2;
00145     ldvp  += dst_roi->line_step / 2;
00146     byp    = lbyp;
00147     bup    = lbup;
00148     bvp    = lbvp;
00149     fyp    = lfyp;
00150     fup    = lfup;
00151     fvp    = lfvp;
00152     dyp    = ldyp;
00153     dup    = ldup;
00154     dvp    = ldvp;
00155   }
00156 
00157 }
00158 
00159 } // end namespace firevision