max.cpp

00001 
00002 /***************************************************************************
00003  *  max.cpp - implementation of max intensity filter
00004  *
00005  *  Created: Sat Jun 10 16:43:41 2006 (FIFA WM 2006, England vs. Paraguay)
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/max.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 FilterMax <filters/max.h>
00038  * Maximum filter.
00039  * @author Tim Niemueller
00040  */
00041 
00042 /** Constructor. */
00043 FilterMax::FilterMax()
00044   : Filter("FilterMax", 2)
00045 {
00046 }
00047 
00048 void
00049 FilterMax::apply()
00050 {
00051   if ( src[0] == NULL ) throw NullPointerException("FilterInvert: src buffer 0 is NULL");
00052   if ( src[1] == NULL ) throw NullPointerException("FilterInvert: src buffer 1 is NULL");
00053   if ( src_roi[0] == NULL ) throw NullPointerException("FilterInvert: src ROI 0 is NULL");
00054   if ( src_roi[1] == NULL ) throw NullPointerException("FilterInvert: src ROI 1 is NULL");
00055 
00056   register unsigned int h = 0;
00057   register unsigned int w = 0;
00058 
00059   // y-plane
00060   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);
00061   // u-plane
00062   register unsigned char *bup   = YUV422_PLANAR_U_PLANE(src[0], src_roi[0]->image_width, src_roi[0]->image_height)
00063     + ((src_roi[0]->start.y * src_roi[0]->line_step) / 2 + (src_roi[0]->start.x * src_roi[0]->pixel_step) / 2) ;
00064   // v-plane
00065   register unsigned char *bvp   = YUV422_PLANAR_V_PLANE(src[0], src_roi[0]->image_width, src_roi[0]->image_height)
00066     + ((src_roi[0]->start.y * src_roi[0]->line_step) / 2 + (src_roi[0]->start.x * src_roi[0]->pixel_step) / 2);
00067 
00068 
00069   // y-plane
00070   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);
00071   // u-plane
00072   register unsigned char *fup   = YUV422_PLANAR_U_PLANE(src[1], src_roi[1]->image_width, src_roi[1]->image_height)
00073     + ((src_roi[1]->start.y * src_roi[1]->line_step) / 2 + (src_roi[1]->start.x * src_roi[1]->pixel_step) / 2) ;
00074   // v-plane
00075   register unsigned char *fvp   = YUV422_PLANAR_V_PLANE(src[1], src_roi[1]->image_width, src_roi[1]->image_height)
00076     + ((src_roi[1]->start.y * src_roi[1]->line_step) / 2 + (src_roi[1]->start.x * src_roi[1]->pixel_step) / 2);
00077 
00078 
00079   // destination y-plane
00080   register unsigned char *dyp  = dst + (dst_roi->start.y * dst_roi->line_step) + (dst_roi->start.x * dst_roi->pixel_step);
00081   // destination u-plane
00082   register unsigned char *dup   = YUV422_PLANAR_U_PLANE(dst, dst_roi->image_width, dst_roi->image_height)
00083     + ((dst_roi->start.y * dst_roi->line_step) / 2 + (dst_roi->start.x * dst_roi->pixel_step) / 2) ;
00084   // destination v-plane
00085   register unsigned char *dvp   = YUV422_PLANAR_V_PLANE(dst, dst_roi->image_width, dst_roi->image_height)
00086     + ((dst_roi->start.y * dst_roi->line_step) / 2 + (dst_roi->start.x * dst_roi->pixel_step) / 2);
00087   
00088   // line starts
00089   unsigned char *lbyp = byp;   // y-plane
00090   unsigned char *lbup = fup;   // u-plane
00091   unsigned char *lbvp = fvp;   // v-plane
00092   unsigned char *lfyp = fyp;   // y-plane
00093   unsigned char *lfup = fup;   // u-plane
00094   unsigned char *lfvp = fvp;   // v-plane
00095   unsigned char *ldyp = dyp;  // destination y-plane
00096   unsigned char *ldup = dup;  // destination u-plane
00097   unsigned char *ldvp = dvp;  // destination v-plane
00098 
00099   unsigned char u1, u2, v1, v2;
00100 
00101   for (h = 0; (h < src_roi[1]->height) && (h < dst_roi->height); ++h) {
00102     for (w = 0; (w < src_roi[1]->width) && (w < dst_roi->width); w += 2) {
00103       if ( *byp > *fyp ) {
00104         *dyp++ = *byp;
00105         u1 = *bup;
00106         v1 = *bvp;
00107       } else {
00108         *dyp++ = *fyp;
00109         u1 = *fup;
00110         v1 = *fvp;
00111       }
00112       ++byp;
00113       ++fyp;
00114 
00115       if ( *byp > *fyp ) {
00116         *dyp++ = *byp;
00117         u2 = *bup;
00118         v2 = *bvp;
00119       } else {
00120         *dyp++ = *fyp;
00121         u2 = *fup;
00122         v2 = *fvp;
00123       }
00124       ++byp;
00125       ++fyp;
00126 
00127       *dup++ = (u1 + u2) / 2;
00128       *dvp++ = (v1 + v2) / 2;
00129 
00130       ++bup;
00131       ++bvp;
00132       ++fup;
00133       ++fvp;
00134     }
00135 
00136     lbyp   += src_roi[0]->line_step;
00137     lbup   += src_roi[0]->line_step / 2;
00138     lbvp   += src_roi[0]->line_step / 2;
00139     lfyp   += src_roi[1]->line_step;
00140     lfup   += src_roi[1]->line_step / 2;
00141     lfvp   += src_roi[1]->line_step / 2;
00142     ldyp  += dst_roi->line_step;
00143     ldup  += dst_roi->line_step / 2;
00144     ldvp  += dst_roi->line_step / 2;
00145     byp    = lbyp;
00146     bup    = lbup;
00147     bvp    = lbvp;
00148     fyp    = lfyp;
00149     fup    = lfup;
00150     fvp    = lfvp;
00151     dyp    = ldyp;
00152     dup    = ldup;
00153     dvp    = ldvp;
00154   }
00155 
00156 }
00157 
00158 } // end namespace firevision

Generated on 1 Mar 2011 for Fawkes API by  doxygen 1.6.1