hv_search.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 #include <filters/hv_search.h>
00026
00027 #include <fvutils/color/yuv.h>
00028
00029 #include <cstddef>
00030 #include <cstring>
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 FilterHVSearch::FilterHVSearch(ColorModel *cm, color_t what)
00047 : Filter("FilterHVSearch")
00048 {
00049 this->cm = cm;
00050 this->what = what;
00051 }
00052
00053
00054 void
00055 FilterHVSearch::apply()
00056 {
00057 register unsigned int h = 0;
00058 register unsigned int w = 0;
00059
00060 unsigned int width = src_roi[0]->width <= dst_roi->width ? src_roi[0]->width : dst_roi->width;
00061
00062
00063 unsigned int top[width];
00064 unsigned int bottom[width];
00065 bool vflag[width];
00066
00067
00068 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);
00069
00070 register unsigned char *up = YUV422_PLANAR_U_PLANE(src[0], src_roi[0]->image_width, src_roi[0]->image_height)
00071 + ((src_roi[0]->start.y * src_roi[0]->line_step) / 2 + (src_roi[0]->start.x * src_roi[0]->pixel_step) / 2) ;
00072
00073 register unsigned char *vp = YUV422_PLANAR_V_PLANE(src[0], src_roi[0]->image_width, src_roi[0]->image_height)
00074 + ((src_roi[0]->start.y * src_roi[0]->line_step) / 2 + (src_roi[0]->start.x * src_roi[0]->pixel_step) / 2);
00075
00076
00077 register unsigned char *dyp = dst + (dst_roi->start.y * dst_roi->line_step) + (dst_roi->start.x * dst_roi->pixel_step);
00078
00079
00080 unsigned char *lyp = yp;
00081 unsigned char *lup = up;
00082 unsigned char *lvp = vp;
00083 unsigned char *ldyp = dyp;
00084
00085
00086 unsigned int left;
00087 unsigned int right;
00088 bool flag;
00089
00090
00091 const unsigned int MIN_INTERIA = 9;
00092 unsigned int num_what;
00093
00094
00095
00096
00097 const unsigned int MAX_SHRINK = 16;
00098 unsigned int max_width = 0;
00099 bool not_reflect = true;
00100
00101 memset(top, 0, width * sizeof(unsigned int));
00102 memset(bottom, 0, width * sizeof(unsigned int));
00103 memset(vflag, 0, width * sizeof(bool));
00104
00105 for (h = 0; (h < src_roi[0]->height) && (h < dst_roi->height); ++h) {
00106 flag = false;
00107 left = right = 0;
00108 num_what = 0;
00109 for (w = 0; (w < src_roi[0]->width) && (w < dst_roi->width); ++w) {
00110 if ( (cm->determine(*yp++, *up, *vp) == what) ) {
00111 right = w;
00112 if (not_reflect) bottom[w] = h;
00113 flag = true;
00114 vflag[w] = true;
00115 ++num_what;
00116 } else {
00117 left = flag?left:w;
00118 if (!vflag[w]) top[w] = h;
00119 }
00120 if ( (cm->determine(*yp++, *up++, *vp++) == what) ) {
00121 right = ++w;
00122 if (not_reflect) bottom[w] = h;
00123 flag = true;
00124 vflag[w] = true;
00125 ++num_what;
00126 } else {
00127 ++w;
00128 left = flag?left:w;
00129 if (!vflag[w]) top[w] = h;
00130 }
00131 }
00132
00133
00134 memset(ldyp, 0, dst_roi->width);
00135
00136 if (num_what * MIN_INTERIA > right - left)
00137 {
00138 if (right - left > max_width)
00139 max_width = right - left;
00140 if (not_reflect)
00141 {
00142 if (right - left < max_width / MAX_SHRINK)
00143 {
00144
00145
00146
00147 not_reflect = false;
00148 }
00149
00150
00151
00152
00153 if (left != 0 && left < dst_roi->width-1)
00154 {
00155 ldyp[left] = 255;
00156
00157 }
00158 if (right != 0 && right < dst_roi->width-1)
00159 {
00160 ldyp[right] = 255;
00161
00162 }
00163 }
00164 }
00165
00166 lyp += src_roi[0]->line_step;
00167 lup += src_roi[0]->line_step / 2;
00168 lvp += src_roi[0]->line_step / 2;
00169 ldyp += dst_roi->line_step;
00170 yp = lyp;
00171 up = lup;
00172 vp = lvp;
00173 dyp = ldyp;
00174 }
00175 for (w = 0; w < dst_roi->width; w++)
00176 {
00177 if (top[w] != 0 && top[w] != dst_roi->height - 1)
00178 *(dst + ((dst_roi->start.y + top[w]) * dst_roi->line_step)
00179 + ((dst_roi->start.x + w) * dst_roi->pixel_step)) = 255;
00180 if (bottom[w] != 0 && bottom[w] != dst_roi->height - 1)
00181 *(dst + ((dst_roi->start.y + bottom[w]) * dst_roi->line_step)
00182 + ((dst_roi->start.x + w) * dst_roi->pixel_step)) = 255;
00183 }
00184 }
00185