97 #define OFFSET(x) offsetof(RemovelogoContext, x) 
   98 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM 
  117 #define apply_mask_fudge_factor(x) (((x) >> 2) + x) 
  134                                           int w, 
int h, 
int min_val,
 
  141     int current_pass = 0;
 
  144     for (y = 0; y < h; y++)
 
  145         for (x = 0; x < w; x++)
 
  146             data[y*linesize + x] = data[y*linesize + x] > min_val;
 
  156         int has_anything_changed = 0;
 
  160         for (y = 1; y < h-1; y++) {
 
  161             current_pixel = current_pixel0;
 
  162             for (x = 1; x < w-1; x++) {
 
  174                 if ( *current_pixel      >= current_pass &&
 
  175                     *(current_pixel + 1) >= current_pass &&
 
  176                     *(current_pixel - 1) >= current_pass &&
 
  177                     *(current_pixel + w) >= current_pass &&
 
  178                     *(current_pixel - w) >= current_pass) {
 
  183                     has_anything_changed = 1;
 
  187             current_pixel0 += linesize;
 
  189         if (!has_anything_changed)
 
  195     for (y = 1; y < h - 1; y++)
 
  196         for (x = 1; x < w - 1; x++)
 
  214                      const char *filename, 
void *log_ctx)
 
  218     uint8_t *src_data[4], *gray_data[4];
 
  219     int src_linesize[4], gray_linesize[4];
 
  222     if ((ret = 
ff_load_image(src_data, src_linesize, w, h, &pix_fmt, filename, log_ctx)) < 0)
 
  227                               src_data, src_linesize, *w, *h, pix_fmt,
 
  255                                      uint8_t *dst_data, 
int dst_linesize,
 
  256                                      int src_w, 
int src_h,
 
  263     for (y = 0; y < src_h/2; y++) {
 
  264         for (x = 0; x < src_w/2; x++) {
 
  267             dst_data[(y * dst_linesize) + x] =
 
  268                 src_data[((y << 1) * src_linesize) + (x << 1)] ||
 
  269                 src_data[((y << 1) * src_linesize) + (x << 1) + 1] ||
 
  270                 src_data[(((y << 1) + 1) * src_linesize) + (x << 1)] ||
 
  271                 src_data[(((y << 1) + 1) * src_linesize) + (x << 1) + 1];
 
  272             dst_data[(y * dst_linesize) + x] = 
FFMIN(1, dst_data[(y * dst_linesize) + x]);
 
  277                                   src_w/2, src_h/2, 0, max_mask_size);
 
  286     int full_max_mask_size, half_max_mask_size;
 
  300                                   16, &full_max_mask_size);
 
  307                              w, h, &half_max_mask_size);
 
  320         mask[
a] = (
int **)
av_malloc(
sizeof(
int *) * ((a * 2) + 1));
 
  323         for (b = -a; b <= 
a; b++) {
 
  324             mask[
a][b + 
a] = (
int *)
av_malloc(
sizeof(
int) * ((a * 2) + 1));
 
  327             for (c = -a; c <= 
a; c++) {
 
  328                 if ((b * b) + (c * c) <= (a * a)) 
 
  329                     mask[
a][b + 
a][c + 
a] = 1;
 
  331                     mask[
a][b + 
a][c + 
a] = 0;
 
  342 #define SHOW_LOGO_INFO(mask_type)                                       \ 
  343     av_log(ctx, AV_LOG_VERBOSE, #mask_type " x1:%d x2:%d y1:%d y2:%d max_mask_size:%d\n", \ 
  344            removelogo->mask_type##_mask_bbox.x1, removelogo->mask_type##_mask_bbox.x2, \ 
  345            removelogo->mask_type##_mask_bbox.y1, removelogo->mask_type##_mask_bbox.y2, \ 
  346            mask_type##_max_mask_size); 
  358     if (inlink->
w != removelogo->
mask_w || inlink->
h != removelogo->
mask_h) {
 
  360                "Mask image size %dx%d does not match with the input video size %dx%d\n",
 
  383                                const uint8_t *mask_data, 
int mask_linesize,
 
  384                                uint8_t       *image_data, 
int image_linesize,
 
  385                                int w, 
int h, 
int x, 
int y)
 
  390     int start_posx, start_posy, end_posx, end_posy;
 
  392     unsigned int accumulator = 0, divisor = 0;
 
  394     const uint8_t *image_read_position;
 
  396     const uint8_t *mask_read_position;
 
  399     mask_size  = mask_data[y * mask_linesize + x];
 
  400     start_posx = 
FFMAX(0, x - mask_size);
 
  401     start_posy = 
FFMAX(0, y - mask_size);
 
  402     end_posx   = 
FFMIN(w - 1, x + mask_size);
 
  403     end_posy   = 
FFMIN(h - 1, y + mask_size);
 
  405     image_read_position = image_data + image_linesize * start_posy + start_posx;
 
  406     mask_read_position  = mask_data  + mask_linesize  * start_posy + start_posx;
 
  408     for (j = start_posy; j <= end_posy; j++) {
 
  409         for (i = start_posx; i <= end_posx; i++) {
 
  412             if (!(*mask_read_position) && mask[mask_size][i - start_posx][j - start_posy]) {
 
  413                 accumulator += *image_read_position;
 
  417             image_read_position++;
 
  418             mask_read_position++;
 
  421         image_read_position += (image_linesize - ((end_posx + 1) - start_posx));
 
  422         mask_read_position  += (mask_linesize - ((end_posx + 1) - start_posx));
 
  428     return divisor == 0 ? 255:
 
  429         (accumulator + (divisor / 2)) / divisor;  
 
  456                        const uint8_t *src_data,  
int src_linesize,
 
  457                              uint8_t *dst_data,  
int dst_linesize,
 
  458                        const uint8_t *mask_data, 
int mask_linesize,
 
  459                        int w, 
int h, 
int direct,
 
  469     for (y = bbox->
y1; y <= bbox->y2; y++) {
 
  470         src_line = src_data + src_linesize * 
y;
 
  471         dst_line = dst_data + dst_linesize * 
y;
 
  473         for (x = bbox->
x1; x <= bbox->x2; x++) {
 
  474              if (mask_data[y * mask_linesize + x]) {
 
  477                                           mask_data, mask_linesize,
 
  478                                           dst_data, dst_linesize,
 
  483                     dst_line[x] = src_line[x];
 
  498         outpicref = inpicref;
 
  538     if (removelogo->
mask) {
 
  542             for (b = -a; b <= 
a; b++) {
 
  572     .
name          = 
"removelogo",
 
  578     .
inputs        = removelogo_inputs,
 
  580     .priv_class    = &removelogo_class,