5 #include "libmythbase/mythconfig.h"
9 #include "libavcodec/avcodec.h"
26 int excluderow,
int excludecol,
int excludewidth,
int excludeheight)
35 const size_t srcwidth = src->linesize[0];
37 memset(sgm, 0, srcwidth * srcheight *
sizeof(*sgm));
38 int rr2 = srcheight - 1;
39 int cc2 = srcwidth - 1;
40 for (
int rr = 0; rr < rr2; rr++)
42 for (
int cc = 0;
cc < cc2;
cc++)
45 excludewidth, excludeheight))
47 uchar *rr0 = &src->data[0][(rr * srcwidth) +
cc];
48 uchar *rr1 = &src->data[0][((rr + 1) * srcwidth) +
cc];
49 int dx = rr1[1] - rr0[0];
50 int dy = rr1[0] - rr0[1];
51 sgm[(rr * srcwidth) +
cc] = dx * dx + dy * dy;
60 sgm_init(
unsigned int *sgm,
const AVFrame *src,
int srcheight)
68 return *(
unsigned int*)aa - *(
unsigned int*)bb;
73 int extratop,
int extraright,
74 [[maybe_unused]]
int extrabottom,
76 const unsigned int *sgm,
unsigned int *sgmsorted,
int percentile,
77 int excluderow,
int excludecol,
int excludewidth,
int excludeheight)
87 static constexpr
int kMinThresholdPct = 95;
89 const int dstwidth = dst->linesize[0];
90 const int padded_width = extraleft + dstwidth + extraright;
99 for (
int rr = 0; rr < dstheight; rr++)
101 for (
int cc = 0;
cc < dstwidth;
cc++)
104 excludewidth, excludeheight))
106 sgmsorted[nn++] = sgm[((extratop + rr) * padded_width) +
112 int dstnn = dstwidth * dstheight;
115 (min(max(0, excluderow + excludeheight), dstheight) -
116 min(max(0, excluderow), dstheight)) *
117 (min(max(0, excludecol + excludewidth), dstwidth) -
118 min(max(0, excludecol), dstwidth)));
120 memset(dst->data[0], 0, dstnn *
sizeof(*dst->data[0]));
130 int ii = percentile * nn / 100;
131 uint thresholdval = sgmsorted[ii];
138 for ( ; first > 0 && sgmsorted[first] == thresholdval; first--) ;
139 if (sgmsorted[first] != thresholdval)
141 if (first * 100 / nn < kMinThresholdPct)
145 for ( ; last < last2 && sgmsorted[last] == thresholdval;
147 if (sgmsorted[last] != thresholdval)
150 uint newthresholdval = sgmsorted[std::min(last + 1, nn - 1)];
151 if (thresholdval == newthresholdval)
157 thresholdval = newthresholdval;
161 for (
int rr = 0; rr < dstheight; rr++)
163 for (
int cc = 0;
cc < dstwidth;
cc++)
166 excludewidth, excludeheight) &&
167 sgm[((extratop + rr) * padded_width) + extraleft +
cc] >=
169 dst->data[0][(rr * dstwidth) +
cc] = UCHAR_MAX;
176 int edge_mark_uniform(
AVFrame *dst,
int dstheight,
int extramargin,
177 const unsigned int *sgm,
unsigned int *sgmsorted,
181 extramargin, extramargin, extramargin, extramargin,
182 sgm, sgmsorted, percentile, 0, 0, 0, 0);
187 const unsigned int *sgm,
unsigned int *sgmsorted,
int percentile,
188 int excluderow,
int excludecol,
int excludewidth,
int excludeheight)
191 extramargin, extramargin, extramargin, extramargin,
192 sgm, sgmsorted, percentile,
193 excluderow, excludecol, excludewidth, excludeheight);
200 [[maybe_unused]]
int col,
201 [[maybe_unused]]
int width,
202 [[maybe_unused]]
int height)