segment.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include <models/color/colormodel.h>
00027 #include <filters/segment.h>
00028
00029 #include <fvutils/color/yuv.h>
00030 #include <cstddef>
00031
00032 namespace firevision {
00033 #if 0
00034 }
00035 #endif
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
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
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
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
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
00072 register unsigned char *dyp = dst + (dst_roi->start.y * dst_roi->line_step) + (dst_roi->start.x * dst_roi->pixel_step);
00073
00074
00075 unsigned char *lyp = yp;
00076 unsigned char *lup = up;
00077 unsigned char *lvp = vp;
00078 unsigned char *ldyp = dyp;
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 }