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 /** @class FilterScanlineSegmentation <filters/segment_scanline.h>
00037  * Segmentation filter.
00038  * Visually marks pixels depending of their classification determined by the
00039  * supplied color model to make the segmentation visible - but only the pixels
00040  * at scanline points.
00041  * The pixels are marked with the color matching the segmentation with an
00042  * appropriate place holder color.
00043  * @author Tim Niemueller
00044  */
00045 
00046 /** Constructor.
00047  * @param cm color model to use
00048  * @param slm scanline model to use
00049  */
00050 FilterScanlineSegmentation::FilterScanlineSegmentation(ColorModel *cm, ScanlineModel *slm)
00051   : Filter("FilterScanlineSegmentation")
00052 {
00053   this->cm = cm;
00054   this->slm = slm;
00055 }
00056
00057
00058 void
00059 FilterScanlineSegmentation::apply()
00060 {
00061   unsigned int  x = 0, y = 0;
00062   unsigned char   py = 0, pu = 0, pv = 0;
00063   register unsigned char *dyp, *dup, *dvp;
00064   color_t c;
00065
00066
00067   slm->reset();
00068   while (! slm->finished()) {
00069
00070     x = (*slm)->x;
00071     y = (*slm)->y;
00072
00073
00074     // Get source pixel values
00075     YUV422_PLANAR_YUV(src[0], src_roi[0]->image_width, src_roi[0]->image_height, x, y,  py,  pu,  pv);
00076
00077     // destination y-plane
00078     dyp  = dst + (y * dst_roi->line_step) + (x * dst_roi->pixel_step);
00079     // destination u-plane
00080     dup  = YUV422_PLANAR_U_PLANE(dst, dst_roi->image_width, dst_roi->image_height)
00081                                    + (((y * dst_roi->line_step) + (x * dst_roi->pixel_step)) / 2) ;
00082     // destination v-plane
00083     dvp  = YUV422_PLANAR_V_PLANE(dst, dst_roi->image_width, dst_roi->image_height)
00084                                    + (((y * dst_roi->line_step) + (x * dst_roi->pixel_step)) / 2);
00085
00086     c = cm->determine(py, pu, pv);
00087
00088     switch (c) {
00089     case C_ORANGE:
00090       *dyp++ = 128;
00091       *dyp++ = 128;
00092       *dup++ = 0;
00093       *dvp++ = 255;
00094       break;
00095     case C_MAGENTA:
00096       *dyp++ = 128;
00097       *dyp++ = 128;
00098       *dup++ = 128;
00099       *dvp++ = 255;
00100       break;
00101     case C_CYAN:
00102       *dyp++ = 128;
00103       *dyp++ = 128;
00104       *dup++ = 255;
00105       *dvp++ = 0;
00106       break;
00107     case C_BLUE:
00108       *dyp++ = 128;
00109       *dyp++ = 128;
00110       *dup++ = 255;
00111       *dvp++ = 128;
00112       break;
00113     case C_YELLOW:
00114       *dyp++ = 255;
00115       *dyp++ = 255;
00116       *dup++ = 0;
00117       *dvp++ = 128;
00118       break;
00119     case C_GREEN:
00120       *dyp++ = 128;
00121       *dyp++ = 128;
00122       *dup++ = 0;
00123       *dvp++ = 0;
00124       break;
00125     case C_WHITE:
00126       *dyp++ = 255;
00127       *dyp++ = 255;
00128       *dup++ = 128;
00129       *dvp++ = 128;
00130       break;
00131     case C_RED:
00132       *dyp++ = 196;
00133       *dyp++ = 196;
00134       *dup++ = 0;
00135       *dvp++ = 255;
00136       break;
00137     default:
00138       *dyp++ = 0;
00139       *dyp++ = 0;
00140       *dup++ = 128;
00141       *dvp++ = 128;
00142       break;
00143     }
00144     ++(*slm);
00145   }
00146 }