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