segment_scanline.cpp

00001 
00002 /***************************************************************************
00003  *  segment_scanline.cpp - Implementation of scanline segmentation filter
00004  *                         This filter can be used to draw the segmentation for
00005  *                         all objects into a colored YUV422_PLANAR buffer
00006  *                         but only on the scanline model points
00007  *
00008  *  Created: Thu Jul 14 15:04:23 2005
00009  *  Copyright  2005-2007  Tim Niemueller [www.niemueller.de]
00010  *
00011  ****************************************************************************/
00012 
00013 /*  This program is free software; you can redistribute it and/or modify
00014  *  it under the terms of the GNU General Public License as published by
00015  *  the Free Software Foundation; either version 2 of the License, or
00016  *  (at your option) any later version. A runtime exception applies to
00017  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00018  *
00019  *  This program is distributed in the hope that it will be useful,
00020  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022  *  GNU Library General Public License for more details.
00023  *
00024  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00025  */
00026 
00027 #include <filters/segment_scanline.h>
00028 
00029 #include <models/color/colormodel.h>
00030 #include <models/scanlines/scanlinemodel.h>
00031 
00032 #include <fvutils/color/yuv.h>
00033 #include <cstddef>
00034 
00035 
00036 namespace firevision {
00037 #if 0 /* just to make Emacs auto-indent happy */
00038 }
00039 #endif
00040 
00041 /** @class FilterScanlineSegmentation <filters/segment_scanline.h>
00042  * Segmentation filter.
00043  * Visually marks pixels depending of their classification determined by the
00044  * supplied color model to make the segmentation visible - but only the pixels
00045  * at scanline points.
00046  * The pixels are marked with the color matching the segmentation with an
00047  * appropriate place holder color.
00048  * @author Tim Niemueller
00049  */
00050 
00051 /** Constructor.
00052  * @param cm color model to use
00053  * @param slm scanline model to use
00054  */
00055 FilterScanlineSegmentation::FilterScanlineSegmentation(ColorModel *cm, ScanlineModel *slm)
00056   : Filter("FilterScanlineSegmentation")
00057 {
00058   this->cm = cm;
00059   this->slm = slm;
00060 }
00061 
00062 
00063 void
00064 FilterScanlineSegmentation::apply()
00065 {
00066   unsigned int  x = 0, y = 0;
00067   unsigned char   py = 0, pu = 0, pv = 0;
00068   register unsigned char *dyp, *dup, *dvp;
00069   color_t c;
00070 
00071 
00072   slm->reset();
00073   while (! slm->finished()) {
00074 
00075     x = (*slm)->x;
00076     y = (*slm)->y;
00077 
00078 
00079     // Get source pixel values
00080     YUV422_PLANAR_YUV(src[0], src_roi[0]->image_width, src_roi[0]->image_height, x, y,  py,  pu,  pv);
00081 
00082     // destination y-plane
00083     dyp  = dst + (y * dst_roi->line_step) + (x * dst_roi->pixel_step);
00084     // destination u-plane
00085     dup  = YUV422_PLANAR_U_PLANE(dst, dst_roi->image_width, dst_roi->image_height)
00086                                    + (((y * dst_roi->line_step) + (x * dst_roi->pixel_step)) / 2) ;
00087     // destination v-plane
00088     dvp  = YUV422_PLANAR_V_PLANE(dst, dst_roi->image_width, dst_roi->image_height)
00089                                    + (((y * dst_roi->line_step) + (x * dst_roi->pixel_step)) / 2);
00090 
00091     c = cm->determine(py, pu, pv);
00092 
00093     switch (c) {
00094     case C_ORANGE:
00095       *dyp++ = 128;
00096       *dyp++ = 128;
00097       *dup++ = 0;
00098       *dvp++ = 255;
00099       break;
00100     case C_MAGENTA:
00101       *dyp++ = 128;
00102       *dyp++ = 128;
00103       *dup++ = 128;
00104       *dvp++ = 255;
00105       break;
00106     case C_CYAN:
00107       *dyp++ = 128;
00108       *dyp++ = 128;
00109       *dup++ = 255;
00110       *dvp++ = 0;
00111       break;
00112     case C_BLUE:
00113       *dyp++ = 128;
00114       *dyp++ = 128;
00115       *dup++ = 255;
00116       *dvp++ = 128;
00117       break;
00118     case C_YELLOW:
00119       *dyp++ = 255;
00120       *dyp++ = 255;
00121       *dup++ = 0;
00122       *dvp++ = 128;
00123       break;
00124     case C_GREEN:
00125       *dyp++ = 128;
00126       *dyp++ = 128;
00127       *dup++ = 0;
00128       *dvp++ = 0;
00129       break;
00130     case C_WHITE:
00131       *dyp++ = 255;
00132       *dyp++ = 255;
00133       *dup++ = 128;
00134       *dvp++ = 128;
00135       break;
00136     case C_RED:
00137       *dyp++ = 196;
00138       *dyp++ = 196;
00139       *dup++ = 0;
00140       *dvp++ = 255;
00141       break;
00142     default:
00143       *dyp++ = 0;
00144       *dyp++ = 0;
00145       *dup++ = 128;
00146       *dvp++ = 128;
00147       break;
00148     }
00149     ++(*slm);
00150   }
00151 }
00152 
00153 } // end namespace firevision