| @@ -279,44 +279,44 @@ static void generate_half_size_image(const uint8_t *src_data, int src_linesize, | |||||
| static av_cold int init(AVFilterContext *ctx) | static av_cold int init(AVFilterContext *ctx) | ||||
| { | { | ||||
| RemovelogoContext *removelogo = ctx->priv; | |||||
| RemovelogoContext *s = ctx->priv; | |||||
| int ***mask; | int ***mask; | ||||
| int ret = 0; | int ret = 0; | ||||
| int a, b, c, w, h; | int a, b, c, w, h; | ||||
| int full_max_mask_size, half_max_mask_size; | int full_max_mask_size, half_max_mask_size; | ||||
| if (!removelogo->filename) { | |||||
| if (!s->filename) { | |||||
| av_log(ctx, AV_LOG_ERROR, "The bitmap file name is mandatory\n"); | av_log(ctx, AV_LOG_ERROR, "The bitmap file name is mandatory\n"); | ||||
| return AVERROR(EINVAL); | return AVERROR(EINVAL); | ||||
| } | } | ||||
| /* Load our mask image. */ | /* Load our mask image. */ | ||||
| if ((ret = load_mask(&removelogo->full_mask_data, &w, &h, removelogo->filename, ctx)) < 0) | |||||
| if ((ret = load_mask(&s->full_mask_data, &w, &h, s->filename, ctx)) < 0) | |||||
| return ret; | return ret; | ||||
| removelogo->mask_w = w; | |||||
| removelogo->mask_h = h; | |||||
| s->mask_w = w; | |||||
| s->mask_h = h; | |||||
| convert_mask_to_strength_mask(removelogo->full_mask_data, w, w, h, | |||||
| convert_mask_to_strength_mask(s->full_mask_data, w, w, h, | |||||
| 16, &full_max_mask_size); | 16, &full_max_mask_size); | ||||
| /* Create the scaled down mask image for the chroma planes. */ | /* Create the scaled down mask image for the chroma planes. */ | ||||
| if (!(removelogo->half_mask_data = av_mallocz(w/2 * h/2))) | |||||
| if (!(s->half_mask_data = av_mallocz(w/2 * h/2))) | |||||
| return AVERROR(ENOMEM); | return AVERROR(ENOMEM); | ||||
| generate_half_size_image(removelogo->full_mask_data, w, | |||||
| removelogo->half_mask_data, w/2, | |||||
| generate_half_size_image(s->full_mask_data, w, | |||||
| s->half_mask_data, w/2, | |||||
| w, h, &half_max_mask_size); | w, h, &half_max_mask_size); | ||||
| removelogo->max_mask_size = FFMAX(full_max_mask_size, half_max_mask_size); | |||||
| s->max_mask_size = FFMAX(full_max_mask_size, half_max_mask_size); | |||||
| /* Create a circular mask for each size up to max_mask_size. When | /* Create a circular mask for each size up to max_mask_size. When | ||||
| the filter is applied, the mask size is determined on a pixel | the filter is applied, the mask size is determined on a pixel | ||||
| by pixel basis, with pixels nearer the edge of the logo getting | by pixel basis, with pixels nearer the edge of the logo getting | ||||
| smaller mask sizes. */ | smaller mask sizes. */ | ||||
| mask = (int ***)av_malloc(sizeof(int **) * (removelogo->max_mask_size + 1)); | |||||
| mask = (int ***)av_malloc(sizeof(int **) * (s->max_mask_size + 1)); | |||||
| if (!mask) | if (!mask) | ||||
| return AVERROR(ENOMEM); | return AVERROR(ENOMEM); | ||||
| for (a = 0; a <= removelogo->max_mask_size; a++) { | |||||
| for (a = 0; a <= s->max_mask_size; a++) { | |||||
| mask[a] = (int **)av_malloc(sizeof(int *) * ((a * 2) + 1)); | mask[a] = (int **)av_malloc(sizeof(int *) * ((a * 2) + 1)); | ||||
| if (!mask[a]) | if (!mask[a]) | ||||
| return AVERROR(ENOMEM); | return AVERROR(ENOMEM); | ||||
| @@ -332,17 +332,17 @@ static av_cold int init(AVFilterContext *ctx) | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| removelogo->mask = mask; | |||||
| s->mask = mask; | |||||
| /* Calculate our bounding rectangles, which determine in what | /* Calculate our bounding rectangles, which determine in what | ||||
| * region the logo resides for faster processing. */ | * region the logo resides for faster processing. */ | ||||
| ff_calculate_bounding_box(&removelogo->full_mask_bbox, removelogo->full_mask_data, w, w, h, 0); | |||||
| ff_calculate_bounding_box(&removelogo->half_mask_bbox, removelogo->half_mask_data, w/2, w/2, h/2, 0); | |||||
| ff_calculate_bounding_box(&s->full_mask_bbox, s->full_mask_data, w, w, h, 0); | |||||
| ff_calculate_bounding_box(&s->half_mask_bbox, s->half_mask_data, w/2, w/2, h/2, 0); | |||||
| #define SHOW_LOGO_INFO(mask_type) \ | #define SHOW_LOGO_INFO(mask_type) \ | ||||
| av_log(ctx, AV_LOG_VERBOSE, #mask_type " x1:%d x2:%d y1:%d y2:%d max_mask_size:%d\n", \ | av_log(ctx, AV_LOG_VERBOSE, #mask_type " x1:%d x2:%d y1:%d y2:%d max_mask_size:%d\n", \ | ||||
| removelogo->mask_type##_mask_bbox.x1, removelogo->mask_type##_mask_bbox.x2, \ | |||||
| removelogo->mask_type##_mask_bbox.y1, removelogo->mask_type##_mask_bbox.y2, \ | |||||
| s->mask_type##_mask_bbox.x1, s->mask_type##_mask_bbox.x2, \ | |||||
| s->mask_type##_mask_bbox.y1, s->mask_type##_mask_bbox.y2, \ | |||||
| mask_type##_max_mask_size); | mask_type##_max_mask_size); | ||||
| SHOW_LOGO_INFO(full); | SHOW_LOGO_INFO(full); | ||||
| SHOW_LOGO_INFO(half); | SHOW_LOGO_INFO(half); | ||||
| @@ -353,12 +353,12 @@ static av_cold int init(AVFilterContext *ctx) | |||||
| static int config_props_input(AVFilterLink *inlink) | static int config_props_input(AVFilterLink *inlink) | ||||
| { | { | ||||
| AVFilterContext *ctx = inlink->dst; | AVFilterContext *ctx = inlink->dst; | ||||
| RemovelogoContext *removelogo = ctx->priv; | |||||
| RemovelogoContext *s = ctx->priv; | |||||
| if (inlink->w != removelogo->mask_w || inlink->h != removelogo->mask_h) { | |||||
| if (inlink->w != s->mask_w || inlink->h != s->mask_h) { | |||||
| av_log(ctx, AV_LOG_INFO, | av_log(ctx, AV_LOG_INFO, | ||||
| "Mask image size %dx%d does not match with the input video size %dx%d\n", | "Mask image size %dx%d does not match with the input video size %dx%d\n", | ||||
| removelogo->mask_w, removelogo->mask_h, inlink->w, inlink->h); | |||||
| s->mask_w, s->mask_h, inlink->w, inlink->h); | |||||
| return AVERROR(EINVAL); | return AVERROR(EINVAL); | ||||
| } | } | ||||
| @@ -488,7 +488,7 @@ static void blur_image(int ***mask, | |||||
| static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref) | static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref) | ||||
| { | { | ||||
| RemovelogoContext *removelogo = inlink->dst->priv; | |||||
| RemovelogoContext *s = inlink->dst->priv; | |||||
| AVFilterLink *outlink = inlink->dst->outputs[0]; | AVFilterLink *outlink = inlink->dst->outputs[0]; | ||||
| AVFrame *outpicref; | AVFrame *outpicref; | ||||
| int direct = 0; | int direct = 0; | ||||
| @@ -505,21 +505,21 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref) | |||||
| av_frame_copy_props(outpicref, inpicref); | av_frame_copy_props(outpicref, inpicref); | ||||
| } | } | ||||
| blur_image(removelogo->mask, | |||||
| blur_image(s->mask, | |||||
| inpicref ->data[0], inpicref ->linesize[0], | inpicref ->data[0], inpicref ->linesize[0], | ||||
| outpicref->data[0], outpicref->linesize[0], | outpicref->data[0], outpicref->linesize[0], | ||||
| removelogo->full_mask_data, inlink->w, | |||||
| inlink->w, inlink->h, direct, &removelogo->full_mask_bbox); | |||||
| blur_image(removelogo->mask, | |||||
| s->full_mask_data, inlink->w, | |||||
| inlink->w, inlink->h, direct, &s->full_mask_bbox); | |||||
| blur_image(s->mask, | |||||
| inpicref ->data[1], inpicref ->linesize[1], | inpicref ->data[1], inpicref ->linesize[1], | ||||
| outpicref->data[1], outpicref->linesize[1], | outpicref->data[1], outpicref->linesize[1], | ||||
| removelogo->half_mask_data, inlink->w/2, | |||||
| inlink->w/2, inlink->h/2, direct, &removelogo->half_mask_bbox); | |||||
| blur_image(removelogo->mask, | |||||
| s->half_mask_data, inlink->w/2, | |||||
| inlink->w/2, inlink->h/2, direct, &s->half_mask_bbox); | |||||
| blur_image(s->mask, | |||||
| inpicref ->data[2], inpicref ->linesize[2], | inpicref ->data[2], inpicref ->linesize[2], | ||||
| outpicref->data[2], outpicref->linesize[2], | outpicref->data[2], outpicref->linesize[2], | ||||
| removelogo->half_mask_data, inlink->w/2, | |||||
| inlink->w/2, inlink->h/2, direct, &removelogo->half_mask_bbox); | |||||
| s->half_mask_data, inlink->w/2, | |||||
| inlink->w/2, inlink->h/2, direct, &s->half_mask_bbox); | |||||
| if (!direct) | if (!direct) | ||||
| av_frame_free(&inpicref); | av_frame_free(&inpicref); | ||||
| @@ -529,23 +529,23 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref) | |||||
| static av_cold void uninit(AVFilterContext *ctx) | static av_cold void uninit(AVFilterContext *ctx) | ||||
| { | { | ||||
| RemovelogoContext *removelogo = ctx->priv; | |||||
| RemovelogoContext *s = ctx->priv; | |||||
| int a, b; | int a, b; | ||||
| av_freep(&removelogo->full_mask_data); | |||||
| av_freep(&removelogo->half_mask_data); | |||||
| av_freep(&s->full_mask_data); | |||||
| av_freep(&s->half_mask_data); | |||||
| if (removelogo->mask) { | |||||
| if (s->mask) { | |||||
| /* Loop through each mask. */ | /* Loop through each mask. */ | ||||
| for (a = 0; a <= removelogo->max_mask_size; a++) { | |||||
| for (a = 0; a <= s->max_mask_size; a++) { | |||||
| /* Loop through each scanline in a mask. */ | /* Loop through each scanline in a mask. */ | ||||
| for (b = -a; b <= a; b++) { | for (b = -a; b <= a; b++) { | ||||
| av_free(removelogo->mask[a][b + a]); /* Free a scanline. */ | |||||
| av_free(s->mask[a][b + a]); /* Free a scanline. */ | |||||
| } | } | ||||
| av_free(removelogo->mask[a]); | |||||
| av_free(s->mask[a]); | |||||
| } | } | ||||
| /* Free the array of pointers pointing to the masks. */ | /* Free the array of pointers pointing to the masks. */ | ||||
| av_freep(&removelogo->mask); | |||||
| av_freep(&s->mask); | |||||
| } | } | ||||
| } | } | ||||