Fawkes API Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * segment_color.cpp - Implementation of color segmentation filter 00004 * This filter can be used to draw the segmentation for 00005 * all objects into a colored YUV422_PLANAR buffer 00006 * 00007 * Created: Mon Jul 04 16:18:15 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 <filters/segment_color.h> 00027 00028 #include <models/color/colormodel.h> 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 FilterColorSegmentation <filters/segment_color.h> 00038 * Segmentation filter. 00039 * Visually marks pixels depending of their classification determined by the 00040 * supplied color model to make the segmentation visible. 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 */ 00049 FilterColorSegmentation::FilterColorSegmentation(ColorModel *cm) 00050 : Filter("FilterColorSegmentation") 00051 { 00052 this->cm = cm; 00053 } 00054 00055 00056 void 00057 FilterColorSegmentation::apply() 00058 { 00059 register unsigned int h = 0; 00060 register unsigned int w = 0; 00061 00062 // source 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 // source 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 // source 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 // destination u-plane 00074 register unsigned char *dup = YUV422_PLANAR_U_PLANE(dst, dst_roi->image_width, dst_roi->image_height) 00075 + ((dst_roi->start.y * dst_roi->line_step) / 2 + (dst_roi->start.x * dst_roi->pixel_step) / 2) ; 00076 // destination v-plane 00077 register unsigned char *dvp = YUV422_PLANAR_V_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 00080 // line starts 00081 unsigned char *lyp = yp; // source y-plane 00082 unsigned char *lup = up; // source u-plane 00083 unsigned char *lvp = vp; // source v-plane 00084 unsigned char *ldyp = dyp; // destination y-plane 00085 unsigned char *ldup = dup; // destination y-plane 00086 unsigned char *ldvp = dvp; // destination y-plane 00087 00088 color_t c1; 00089 // Unused for now: color_t c2; 00090 00091 for (h = 0; (h < src_roi[0]->height) && (h < dst_roi->height); ++h) { 00092 for (w = 0; (w < src_roi[0]->width) && (w < dst_roi->width); w += 2) { 00093 c1 = cm->determine(*yp++, *up++, *vp++); 00094 yp++; 00095 //c2 = cm->determine(*yp++, *up++, *vp++); 00096 00097 switch (c1) { 00098 case C_ORANGE: 00099 *dyp++ = 128; 00100 *dyp++ = 128; 00101 *dup++ = 0; 00102 *dvp++ = 255; 00103 break; 00104 case C_MAGENTA: 00105 *dyp++ = 128; 00106 *dyp++ = 128; 00107 *dup++ = 128; 00108 *dvp++ = 255; 00109 break; 00110 case C_CYAN: 00111 *dyp++ = 128; 00112 *dyp++ = 128; 00113 *dup++ = 255; 00114 *dvp++ = 0; 00115 break; 00116 case C_BLUE: 00117 *dyp++ = 128; 00118 *dyp++ = 128; 00119 *dup++ = 255; 00120 *dvp++ = 128; 00121 break; 00122 case C_YELLOW: 00123 *dyp++ = 255; 00124 *dyp++ = 255; 00125 *dup++ = 0; 00126 *dvp++ = 128; 00127 break; 00128 case C_GREEN: 00129 *dyp++ = 128; 00130 *dyp++ = 128; 00131 *dup++ = 0; 00132 *dvp++ = 0; 00133 break; 00134 case C_WHITE: 00135 *dyp++ = 255; 00136 *dyp++ = 255; 00137 *dup++ = 128; 00138 *dvp++ = 128; 00139 break; 00140 case C_RED: 00141 *dyp++ = 196; 00142 *dyp++ = 196; 00143 *dup++ = 0; 00144 *dvp++ = 255; 00145 break; 00146 default: 00147 *dyp++ = 0; 00148 *dyp++ = 0; 00149 *dup++ = 128; 00150 *dvp++ = 128; 00151 break; 00152 } 00153 } 00154 lyp += src_roi[0]->line_step; 00155 lup += src_roi[0]->line_step / 2; 00156 lvp += src_roi[0]->line_step / 2; 00157 ldyp += dst_roi->line_step; 00158 ldup += dst_roi->line_step / 2; 00159 ldvp += dst_roi->line_step / 2; 00160 yp = lyp; 00161 up = lup; 00162 vp = lvp; 00163 dyp = ldyp; 00164 dup = ldup; 00165 dvp = ldvp; 00166 } 00167 00168 } 00169 00170 } // end namespace firevision