Fawkes API  Fawkes Development Version
compare.cpp
00001 
00002 /***************************************************************************
00003  *  compare.cpp - implementation of compare 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/compare.h>
00025 
00026 #include <fvutils/color/yuv.h>
00027 #include <cstddef>
00028 
00029 namespace firevision {
00030 #if 0 /* just to make Emacs auto-indent happy */
00031 }
00032 #endif
00033 
00034 /** Background image. */
00035 const unsigned int FilterCompare::BACKGROUND = 0;
00036 /** Foreground image. */
00037 const unsigned int FilterCompare::FOREGROUND = 1;
00038 
00039 /** @class FilterCompare <filters/compare.h>
00040  * Comparison filter.
00041  */ 
00042 
00043 /** Constructor. */
00044 FilterCompare::FilterCompare()
00045   : Filter("FilterCompare", 2)
00046 {
00047 }
00048 
00049 void
00050 FilterCompare::apply()
00051 {
00052   if ( src[BACKGROUND] == NULL ) return;
00053   if ( src[FOREGROUND] == NULL ) return;
00054   if ( src_roi[BACKGROUND] == NULL ) return;
00055   if ( src_roi[FOREGROUND] == NULL ) return;
00056 
00057   register unsigned int h = 0;
00058   register unsigned int w = 0;
00059 
00060 
00061   // y-plane
00062   register unsigned char *byp   = src[BACKGROUND] + (src_roi[BACKGROUND]->start.y * src_roi[BACKGROUND]->line_step) + (src_roi[BACKGROUND]->start.x * src_roi[BACKGROUND]->pixel_step);
00063 
00064 
00065   // y-plane
00066   register unsigned char *fyp   = src[FOREGROUND] + (src_roi[FOREGROUND]->start.y * src_roi[FOREGROUND]->line_step) + (src_roi[FOREGROUND]->start.x * src_roi[FOREGROUND]->pixel_step);
00067   // u-plane
00068   register unsigned char *fup   = YUV422_PLANAR_U_PLANE(src[FOREGROUND], src_roi[FOREGROUND]->image_width, src_roi[FOREGROUND]->image_height)
00069     + ((src_roi[FOREGROUND]->start.y * src_roi[FOREGROUND]->line_step) / 2 + (src_roi[FOREGROUND]->start.x * src_roi[FOREGROUND]->pixel_step) / 2) ;
00070   // v-plane
00071   register unsigned char *fvp   = YUV422_PLANAR_V_PLANE(src[FOREGROUND], src_roi[FOREGROUND]->image_width, src_roi[FOREGROUND]->image_height)
00072     + ((src_roi[FOREGROUND]->start.y * src_roi[FOREGROUND]->line_step) / 2 + (src_roi[FOREGROUND]->start.x * src_roi[FOREGROUND]->pixel_step) / 2);
00073 
00074 
00075   // destination y-plane
00076   register unsigned char *dyp  = dst + (dst_roi->start.y * dst_roi->line_step) + (dst_roi->start.x * dst_roi->pixel_step);
00077   // destination u-plane
00078   register unsigned char *dup   = YUV422_PLANAR_U_PLANE(dst, dst_roi->image_width, dst_roi->image_height)
00079     + ((dst_roi->start.y * dst_roi->line_step) / 2 + (dst_roi->start.x * dst_roi->pixel_step) / 2) ;
00080   // destination v-plane
00081   register unsigned char *dvp   = YUV422_PLANAR_V_PLANE(dst, dst_roi->image_width, dst_roi->image_height)
00082     + ((dst_roi->start.y * dst_roi->line_step) / 2 + (dst_roi->start.x * dst_roi->pixel_step) / 2);
00083   
00084   // line starts
00085   unsigned char *lbyp = byp;   // y-plane
00086   unsigned char *lfyp = fyp;   // y-plane
00087   unsigned char *lfup = fup;   // u-plane
00088   unsigned char *lfvp = fvp;   // v-plane
00089   unsigned char *ldyp = dyp;  // destination y-plane
00090   unsigned char *ldup = dup;  // destination u-plane
00091   unsigned char *ldvp = dvp;  // destination v-plane
00092 
00093   for (h = 0; (h < src_roi[FOREGROUND]->height) && (h < dst_roi->height); ++h) {
00094     for (w = 0; (w < src_roi[FOREGROUND]->width) && (w < dst_roi->width); w += 2) {
00095       if ( *byp < *fyp ) {
00096         *dyp++ = *byp;
00097       } else {
00098         *dyp++ = *fyp;
00099       }
00100       byp++;
00101       fyp++;
00102 
00103       if ( *byp < *fyp ) {
00104         *dyp++ = *byp;
00105       } else {
00106         *dyp++ = *fyp;
00107       }
00108       byp++;
00109       fyp++;
00110 
00111       *dup++ = *fup++;
00112       *dvp++ = *fvp++;
00113     }
00114 
00115     lbyp   += src_roi[BACKGROUND]->line_step;
00116     lfyp   += src_roi[FOREGROUND]->line_step;
00117     lfup   += src_roi[FOREGROUND]->line_step / 2;
00118     lfvp   += src_roi[FOREGROUND]->line_step / 2;
00119     ldyp  += dst_roi->line_step;
00120     ldup  += dst_roi->line_step / 2;
00121     ldvp  += dst_roi->line_step / 2;
00122     byp    = lbyp;
00123     fyp    = lfyp;
00124     fup    = lfup;
00125     fvp    = lfvp;
00126     dyp    = ldyp;
00127     dup    = ldup;
00128     dvp    = ldvp;
00129   }
00130 
00131 }
00132 
00133 } // end namespace firevision