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