From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id A923E41190 for ; Tue, 15 Feb 2022 09:09:02 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F3D5468B23C; Tue, 15 Feb 2022 11:08:59 +0200 (EET) Received: from mail-yb1-f182.google.com (mail-yb1-f182.google.com [209.85.219.182]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A4D5A68AEB1 for ; Tue, 15 Feb 2022 11:08:52 +0200 (EET) Received: by mail-yb1-f182.google.com with SMTP id bt13so54108368ybb.2 for ; Tue, 15 Feb 2022 01:08:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=fQ8MXoVOvnG+YqNwSFNWFBjv26vE8e2ZorroHDEDMds=; b=nJ4ensNeVPZMs6ejcwll2nyzg2IWfbWIGwDCvAty3fjVhBo9kcfu+e7bpIoYLC+/zd 6GERIPZvlrtkOO8scMat/tXC47OHq5HGFRqcIdU1eSUzpxKf18vpOPlNmPa0418OqyQF GtuYPCpahuhM6O6hj8YU9VzCNAOAFrwaLtslFfB1yZW7jRpLPRimuSLzoqv5Veq4+mK4 7LpV83CBxtqnfA0cmVgL3I4FM4sfuKPPDjjnciRtpjGOOoUs5eQ08+KiaVcMjE7vjbTG CpE1kbHqgsUQUwvufmdRiB1rgSGHyVvDf822l2F81+NXyJxATWd1wrlPp4pbW9ySjcfw pXbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=fQ8MXoVOvnG+YqNwSFNWFBjv26vE8e2ZorroHDEDMds=; b=wxkLEBtyBnBffphIdIgAYiRsSvUCwu4JLrsxCspaNHHaA59XX80hO2nuIvaBDANrna 0UA2TYIKYxrKEpiWYRIwPCXUvl3SyVxz57kYKmQRVLDl2yzYT/+5NYQN0zNbKBdQ8KFN /4G6C+1pp23uco2jNis7ZnkFxXdCHhTdAO42clQsKcPLE4n++ZSr2vrkP15bz5BX6RAc opZF9Som3KeEApgn7NiGHhFHV23VOg6srMb5evjh3Bg5zwa8f0Gs13OcxaK5b+QHL98C EcrqW07sXQZnRrYi7d9XvkufMUZOU9zK7Ep9N5Vmx8GXrdxNqETTwZyaug9ok6RZQSrN 9CMw== X-Gm-Message-State: AOAM533fSeiUuGHwvfmtCYAquWuL8hhn6qU+n3AjE8Qw9Sa+0e8DtrG+ 9q5nlDv/hvZ8Cbvgq8yfaekUYOppSrAlTQ3rImQQ4IFLKbQ= X-Google-Smtp-Source: ABdhPJwc999sQps+CM6VsLUkT7JX7Hf6Axo3tlg8jiZcJTUTqaRIgyxbo9Fm0ftnW3ahk2OPdzXMGg4T5wdgeMGmqug= X-Received: by 2002:a81:7346:: with SMTP id o67mr1354023ywc.124.1644916131017; Tue, 15 Feb 2022 01:08:51 -0800 (PST) MIME-Version: 1.0 References: <20210115045832.76405-1-borbarak@fb.com> <3fa8e9b2-6824-eb3a-2390-22fd024efa9f@mail.de> <164363001951.23111.4989616914372511566@lain.red.khirnov.net> <164491528780.19727.15494655440668021866@lain.red.khirnov.net> In-Reply-To: <164491528780.19727.15494655440668021866@lain.red.khirnov.net> From: Paul B Mahol Date: Tue, 15 Feb 2022 10:10:17 +0100 Message-ID: To: FFmpeg development discussions and patches X-Content-Filtered-By: Mailman/MimeDel 2.1.29 Subject: Re: [FFmpeg-devel] [PATCH] avfilter: Added siti filter X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On Tue, Feb 15, 2022 at 9:55 AM Anton Khirnov wrote: > Quoting Thilo Borgmann (2022-02-12 11:55:39) > > Am 31.01.22 um 12:55 schrieb James Almer: > > +static int config_input(AVFilterLink *inlink) > > +{ > > + // Video input data avilable > > + AVFilterContext *ctx = inlink->dst; > > + SiTiContext *s = ctx->priv; > > + int max_pixsteps[4]; > > + size_t pixel_sz; > > + size_t data_sz; > > + size_t gradient_sz; > > + size_t motion_sz; > > + > > + const AVPixFmtDescriptor *desc = > av_pix_fmt_desc_get(inlink->format); > > + av_image_fill_max_pixsteps(max_pixsteps, NULL, desc); > > + > > + s->pixel_depth = max_pixsteps[0]; > > + s->width = inlink->w; > > + s->height = inlink->h; > > + pixel_sz = s->pixel_depth == 1 ? sizeof(uint8_t) : sizeof(uint16_t); > > + data_sz = s->width * pixel_sz * s->height; > > + > > + s->prev_frame = av_malloc(data_sz); > > + > > + gradient_sz = (s->width - 2) * sizeof(double) * (s->height - 2); > > + s->gradient_matrix = (double*)av_malloc(gradient_sz); > > + > > + motion_sz = s->width * sizeof(double) * s->height; > > + s->motion_matrix = (double*)av_malloc(motion_sz); > > useless casts > > > + > > + if (!s->prev_frame || ! s->gradient_matrix || !s->motion_matrix) { > > + av_freep(&s->prev_frame); > > + av_freep(&s->gradient_matrix); > > + av_freep(&s->motion_matrix); > > You don't need to free them on failure, that will be done in uninit. But > you should free them at the beginning of this function, because > config_input can be called multiple times. > In which scenarios? When its called, uninit is also called before. Was thinking to add better support for frame w/h changes when midstream filtering.... > > > +// Applies sobel convolution > > +static void convolve_sobel(SiTiContext *s, const uint8_t *src, double > *dst, int linesize) > > +{ > > + double x_conv_sum; > > + double y_conv_sum; > > + double gradient; > > + int ki; > > + int kj; > > + int index; > > + uint16_t data; > > + int filter_width = 3; > > + int filter_size = filter_width * filter_width; > > + int stride = linesize / s->pixel_depth; > > + > > + // Dst matrix is smaller than src since we ignore edges that can't > be convolved > > + #define CONVOLVE(bps) \ > > + { \ > > + uint##bps##_t *vsrc = (uint##bps##_t*)src; \ > > + for (int j = 1; j < s->height - 1; j++) { \ > > + for (int i = 1; i < s->width - 1; i++) { \ > > + x_conv_sum = 0.0; \ > > + y_conv_sum = 0.0; \ > > + for (int k = 0; k < filter_size; k++) { \ > > + ki = k % filter_width - 1; \ > > + kj = floor(k / filter_width) - 1; \ > > + index = (j + kj) * stride + (i + ki); \ > > + data = convert_full_range(s, vsrc[index]); \ > > Pass bps as a parameter to convert_full_range() instead of accessing > s->pixel_depth, so the compiler can optimize the branch away. > > > +// Calculate pixel difference between current and previous frame, and > update previous > > +static void calculate_motion(SiTiContext *s, const uint8_t *curr, > > + double *motion_matrix, int linesize) > > +{ > > + int stride = linesize / s->pixel_depth; > > + double motion; > > + int curr_index; > > + int prev_index; > > + uint16_t curr_data; > > + > > + // Previous frame is already converted to full range > > + #define CALCULATE(bps) \ > > + { \ > > + uint##bps##_t *vsrc = (uint##bps##_t*)curr; \ > > + for (int j = 0; j < s->height; j++) { \ > > + for (int i = 0; i < s->width; i++) { \ > > + motion = 0; \ > > + curr_index = j * stride + i; \ > > + prev_index = j * s->width + i; \ > > + curr_data = convert_full_range(s, vsrc[curr_index]); \ > > + if (s->nb_frames > 1) \ > > + motion = curr_data - s->prev_frame[prev_index]; \ > > + s->prev_frame[prev_index] = curr_data; \ > > previous code accessed this as uint8_t or uint16_t based on bps > > -- > Anton Khirnov > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel > > To unsubscribe, visit link above, or email > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". > _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".