Fawkes API
Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * segment.cpp - Implementation of segmentation filter 00004 * This filter can be used to draw the segmentation for a 00005 * given object type to the Y-plane of the image 00006 * 00007 * Created: Mon Jun 27 11:37:57 2005 00008 * Copyright 2005-2007 Tim Niemueller [www.niemueller.de] 00009 * 00010 ****************************************************************************/ 00011 00012 /* This program is free software; you can redistribute it and/or modify 00013 * it under the terms of the GNU General Public License as published by 00014 * the Free Software Foundation; either version 2 of the License, or 00015 * (at your option) any later version. A runtime exception applies to 00016 * this software (see LICENSE.GPL_WRE file mentioned below for details). 00017 * 00018 * This program is distributed in the hope that it will be useful, 00019 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00021 * GNU Library General Public License for more details. 00022 * 00023 * Read the full text in the LICENSE.GPL_WRE file in the doc directory. 00024 */ 00025 00026 #include <fvmodels/color/colormodel.h> 00027 #include <fvfilters/segment.h> 00028 00029 #include <fvutils/color/yuv.h> 00030 #include <cstddef> 00031 00032 namespace firevision { 00033 #if 0 /* just to make Emacs auto-indent happy */ 00034 } 00035 #endif 00036 00037 /** @class FilterSegment <fvfilters/segment.h> 00038 * Segmentation filter. 00039 * Visually marks pixels of a given color and makes the segmentation visible. 00040 * The pixels are marked with bright colors. 00041 * @author Tim Niemueller 00042 */ 00043 00044 /** Constructor. 00045 * @param cm color model to use 00046 * @param what what to mark 00047 */ 00048 FilterSegment::FilterSegment(ColorModel *cm, color_t what) 00049 : Filter("FilterSegment") 00050 { 00051 this->cm = cm; 00052 this->what = what; 00053 } 00054 00055 00056 void 00057 FilterSegment::apply() 00058 { 00059 register unsigned int h = 0; 00060 register unsigned int w = 0; 00061 00062 // y-plane 00063 register unsigned char *yp = src[0] + (src_roi[0]->start.y * src_roi[0]->line_step) + (src_roi[0]->start.x * src_roi[0]->pixel_step); 00064 // u-plane 00065 register unsigned char *up = YUV422_PLANAR_U_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 // v-plane 00068 register unsigned char *vp = YUV422_PLANAR_V_PLANE(src[0], src_roi[0]->image_width, src_roi[0]->image_height) 00069 + ((src_roi[0]->start.y * src_roi[0]->line_step) / 2 + (src_roi[0]->start.x * src_roi[0]->pixel_step) / 2); 00070 00071 // destination y-plane 00072 register unsigned char *dyp = dst + (dst_roi->start.y * dst_roi->line_step) + (dst_roi->start.x * dst_roi->pixel_step); 00073 00074 // line starts 00075 unsigned char *lyp = yp; // y-plane 00076 unsigned char *lup = up; // u-plane 00077 unsigned char *lvp = vp; // v-plane 00078 unsigned char *ldyp = dyp; // destination y-plane 00079 00080 for (h = 0; (h < src_roi[0]->height) && (h < dst_roi->height); ++h) { 00081 for (w = 0; (w < src_roi[0]->width) && (w < dst_roi->width); w += 2) { 00082 if ( (cm->determine(*yp++, *up, *vp) == what) ) { 00083 *dyp++ = 255; 00084 } else { 00085 *dyp++ = 0; 00086 } 00087 if ( (cm->determine(*yp++, *up++, *vp++) == what) ) { 00088 *dyp++ = 255; 00089 } else { 00090 *dyp++ = 0; 00091 } 00092 } 00093 lyp += src_roi[0]->line_step; 00094 lup += src_roi[0]->line_step / 2; 00095 lvp += src_roi[0]->line_step / 2; 00096 ldyp += dst_roi->line_step; 00097 yp = lyp; 00098 up = lup; 00099 vp = lvp; 00100 dyp = ldyp; 00101 } 00102 00103 } 00104 00105 } // end namespace firevision