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
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 FilterSegment::FilterSegment(ColorModel *cm, color_t what)
00044 : Filter("FilterSegment")
00045 {
00046 this->cm = cm;
00047 this->what = what;
00048 }
00049
00050
00051 void
00052 FilterSegment::apply()
00053 {
00054 register unsigned int h = 0;
00055 register unsigned int w = 0;
00056
00057
00058 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);
00059
00060 register unsigned char *up = YUV422_PLANAR_U_PLANE(src[0], src_roi[0]->image_width, src_roi[0]->image_height)
00061 + ((src_roi[0]->start.y * src_roi[0]->line_step) / 2 + (src_roi[0]->start.x * src_roi[0]->pixel_step) / 2) ;
00062
00063 register unsigned char *vp = YUV422_PLANAR_V_PLANE(src[0], src_roi[0]->image_width, src_roi[0]->image_height)
00064 + ((src_roi[0]->start.y * src_roi[0]->line_step) / 2 + (src_roi[0]->start.x * src_roi[0]->pixel_step) / 2);
00065
00066
00067 register unsigned char *dyp = dst + (dst_roi->start.y * dst_roi->line_step) + (dst_roi->start.x * dst_roi->pixel_step);
00068
00069
00070 unsigned char *lyp = yp;
00071 unsigned char *lup = up;
00072 unsigned char *lvp = vp;
00073 unsigned char *ldyp = dyp;
00074
00075 for (h = 0; (h < src_roi[0]->height) && (h < dst_roi->height); ++h) {
00076 for (w = 0; (w < src_roi[0]->width) && (w < dst_roi->width); w += 2) {
00077 if ( (cm->determine(*yp++, *up, *vp) == what) ) {
00078 *dyp++ = 255;
00079 } else {
00080 *dyp++ = 0;
00081 }
00082 if ( (cm->determine(*yp++, *up++, *vp++) == what) ) {
00083 *dyp++ = 255;
00084 } else {
00085 *dyp++ = 0;
00086 }
00087 }
00088 lyp += src_roi[0]->line_step;
00089 lup += src_roi[0]->line_step / 2;
00090 lvp += src_roi[0]->line_step / 2;
00091 ldyp += dst_roi->line_step;
00092 yp = lyp;
00093 up = lup;
00094 vp = lvp;
00095 dyp = ldyp;
00096 }
00097
00098 }