From patchwork Tue Sep 11 19:49:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 10293 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:12c4:0:0:0:0:0 with SMTP id 65-v6csp4040142jap; Tue, 11 Sep 2018 12:57:15 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYmPh0N0f0CFs3HUHcdjcFDRIXatXQPN1GpDMFOfz0/ln6RnyPnZQYQhyLCzq/JJbl+hKcw X-Received: by 2002:adf:a512:: with SMTP id i18-v6mr19409367wrb.220.1536695835867; Tue, 11 Sep 2018 12:57:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536695835; cv=none; d=google.com; s=arc-20160816; b=fEVTrJqVeHwNnmGIgrkVZO9Hp0JnE9d14UwxCMKjpscjmHZDLpzjro678hqdxm5p6Q GgIoDdDzmiL2p8W4C8yJ+IpkO4YAXAdUCqr/MN/J0uyDsvJjBQ8zd1sw6nTSFk7q9jei ag9XheziRCCcvxwr+5O4HEcyrRFYz3aiqCc9oaWT3G6gv48oH6fV7gmSDkH2ZW3t6Q8b Ugl93U8PppVllsmNc4GPA6dNr7FBhy3sSnriCzsLf9dsMNnkb+yKMjxJREVy2O4yWVmn bTq1izjtXMidzKrPkWBDJMB4DGAQWQKRaGRl1d3GChLPTFandzrzEOGhQyXo14bm9a2k vDpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:dkim-signature :delivered-to; bh=wQsAqUhh3KIJXrOsDfXRAQLzdr+mYxiXv4LLc6+TiQg=; b=wzL++0PB0iSTnkBGJbGtSvfPz+vx7H6YRMeAjdsAPfJv37FlVG1eABe6gHiePx5SOL kLHET29CRMNeTEDV+ZQlukN81NBs8MHVm8AlQzZyD17KvhgawrfvVU5yQoAatF4+jD/L yQ+xpQ7AFNJFZHddl6d1vKYj58HDkzfsFS3WI3BPAkZ3PmAW0mOLs6ukkGsek8oueeFx tVk8AWthAhB7w5k7MhrMzSBROMQ/lL8yBAOeqhBTN6WD7FE8MChwRPozSdP2E8+BfQtO mUOExbkv/AIK8RcoITBbXYgHhVEx/hyS1vjOjeQ9w0UbZZtny7K4tJLOAFnVh/L1YgX8 LB6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=Sp5lbBqE; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id t81-v6si1428777wmf.30.2018.09.11.12.57.15; Tue, 11 Sep 2018 12:57:15 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=Sp5lbBqE; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8C5B868A42C; Tue, 11 Sep 2018 22:57:04 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f68.google.com (mail-ed1-f68.google.com [209.85.208.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B3D83689F67 for ; Tue, 11 Sep 2018 22:56:58 +0300 (EEST) Received: by mail-ed1-f68.google.com with SMTP id j62-v6so20221810edd.7 for ; Tue, 11 Sep 2018 12:57:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=jzJ1fNTSBnnf3KAM++h+jbNx0mH9rLVIIGIu2L5RxYs=; b=Sp5lbBqEk5GGhaZtU+Zz3b7tIpKiXMW9yYFcPFbQGBFnXEJwja/VDGkNllKCtSg3Ly SQ8QjTj5t0PSLj6DmHm7fdqjXJM2CWgRKri1KeYs++YlG8orhxDBiqqvekdd0HYBm00C eWx3z6EJ/kEo0QHYWFhHVEtPGcp2ZVaESPqbFfWxN5VTaQzCWNJ63h8IotvXp5SNM4pN XrT3zziNuCjBAM7syyjA+10YGYOyD3aXxqzvK7lKae00HLpOoXzDO+5MU+T1daCAy5c+ 0+1VHMIbJE5emNbyFy5TnxU+R7c95ah7OGFRlMRxbSndkF24LQ53V2oS+hN2YUePgcq+ hPiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=jzJ1fNTSBnnf3KAM++h+jbNx0mH9rLVIIGIu2L5RxYs=; b=jZW6Xh2SXfC6ckqb4s6E8YXKP+yel3VvoTmPSmpYtX7Y0Ve2sMPae1l21zyQmhV7PM DoXk2u0Kfxkv6GMRa/XOAsrQ46D6CH0MQhymp8CcyUoCvtK3p/KD/d6qGyQ6y65KWFXS EGnKWG2h867H+bTS+iybrMT44hYgPR0DxjBnSdexxUseWSca8p6mJ3kzj1cDXaX65Z5d DaRbn+xeVFIxu6963vw8oiRuzNusw5criLV1lrY0ozXhNGYEQxMXSS3aocHuGSRJQce1 l5g5CrdMf2IlTfj3kCgzl6RifHWFt0GBO/5QZ8t6xHuTnzgTjNN17+oWg3L2QDODaJL7 ShKQ== X-Gm-Message-State: APzg51AkRaO1wbrpXmKx8AgYTjjQhQvdZHJ7lrKNcXFwGpQM+WHby1f4 8tGCLN+S2Mif+vehX9p2jay3XoQi X-Received: by 2002:a50:a9a4:: with SMTP id n33-v6mr30755188edc.208.1536695383611; Tue, 11 Sep 2018 12:49:43 -0700 (PDT) Received: from localhost.localdomain ([94.250.174.60]) by smtp.gmail.com with ESMTPSA id w22-v6sm11683377eda.34.2018.09.11.12.49.41 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Sep 2018 12:49:42 -0700 (PDT) From: Paul B Mahol To: ffmpeg-devel@ffmpeg.org Date: Tue, 11 Sep 2018 21:49:32 +0200 Message-Id: <20180911194933.2374-1-onemda@gmail.com> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH 1/2] avfilter/vf_remap: refactor code X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Paul B Mahol --- libavfilter/vf_remap.c | 242 ++++++++++++++--------------------------- 1 file changed, 84 insertions(+), 158 deletions(-) diff --git a/libavfilter/vf_remap.c b/libavfilter/vf_remap.c index 4f8d57f229..48ec38af7c 100644 --- a/libavfilter/vf_remap.c +++ b/libavfilter/vf_remap.c @@ -126,85 +126,48 @@ fail: * pixels are copied from source to target using : * Target_frame[y][x] = Source_frame[ ymap[y][x] ][ [xmap[y][x] ]; */ -static int remap_planar_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) -{ - const ThreadData *td = (ThreadData*)arg; - const AVFrame *in = td->in; - const AVFrame *xin = td->xin; - const AVFrame *yin = td->yin; - const AVFrame *out = td->out; - - const int slice_start = (out->height * jobnr ) / nb_jobs; - const int slice_end = (out->height * (jobnr+1)) / nb_jobs; - - const int xlinesize = xin->linesize[0] / 2; - const int ylinesize = yin->linesize[0] / 2; - int x , y, plane; - - for (plane = 0; plane < td->nb_planes ; plane++) { - const int dlinesize = out->linesize[plane]; - const uint8_t *src = in->data[plane]; - uint8_t *dst = out->data[plane] + slice_start * dlinesize; - const int slinesize = in->linesize[plane]; - const uint16_t *xmap = (const uint16_t *)xin->data[0] + slice_start * xlinesize; - const uint16_t *ymap = (const uint16_t *)yin->data[0] + slice_start * ylinesize; - - for (y = slice_start; y < slice_end; y++) { - for (x = 0; x < out->width; x++) { - if (ymap[x] < in->height && xmap[x] < in->width) { - dst[x] = src[ymap[x] * slinesize + xmap[x]]; - } else { - dst[x] = 0; - } - } - dst += dlinesize; - xmap += xlinesize; - ymap += ylinesize; - } - } - - return 0; +#define DEFINE_REMAP_PLANAR_FUNC(name, bits, div) \ +static int remap_planar##bits##_##name##_slice(AVFilterContext *ctx, void *arg, \ + int jobnr, int nb_jobs) \ +{ \ + const ThreadData *td = (ThreadData*)arg; \ + const AVFrame *in = td->in; \ + const AVFrame *xin = td->xin; \ + const AVFrame *yin = td->yin; \ + const AVFrame *out = td->out; \ + const int slice_start = (out->height * jobnr ) / nb_jobs; \ + const int slice_end = (out->height * (jobnr+1)) / nb_jobs; \ + const int xlinesize = xin->linesize[0] / 2; \ + const int ylinesize = yin->linesize[0] / 2; \ + int x , y, plane; \ + \ + for (plane = 0; plane < td->nb_planes ; plane++) { \ + const int dlinesize = out->linesize[plane] / div; \ + const uint##bits##_t *src = (const uint##bits##_t *)in->data[plane]; \ + uint##bits##_t *dst = (uint##bits##_t *)out->data[plane] + slice_start * dlinesize; \ + const int slinesize = in->linesize[plane] / div; \ + const uint16_t *xmap = (const uint16_t *)xin->data[0] + slice_start * xlinesize; \ + const uint16_t *ymap = (const uint16_t *)yin->data[0] + slice_start * ylinesize; \ + \ + for (y = slice_start; y < slice_end; y++) { \ + for (x = 0; x < out->width; x++) { \ + if (ymap[x] < in->height && xmap[x] < in->width) { \ + dst[x] = src[ymap[x] * slinesize + xmap[x]]; \ + } else { \ + dst[x] = 0; \ + } \ + } \ + dst += dlinesize; \ + xmap += xlinesize; \ + ymap += ylinesize; \ + } \ + } \ + \ + return 0; \ } -static int remap_planar16_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) -{ - const ThreadData *td = (ThreadData*)arg; - const AVFrame *in = td->in; - const AVFrame *xin = td->xin; - const AVFrame *yin = td->yin; - const AVFrame *out = td->out; - - const int slice_start = (out->height * jobnr ) / nb_jobs; - const int slice_end = (out->height * (jobnr+1)) / nb_jobs; - - const int xlinesize = xin->linesize[0] / 2; - const int ylinesize = yin->linesize[0] / 2; - int x , y, plane; - - for (plane = 0; plane < td->nb_planes ; plane++) { - const int dlinesize = out->linesize[plane] / 2; - const uint16_t *src = (const uint16_t *)in->data[plane]; - uint16_t *dst = (uint16_t *)out->data[plane] + slice_start * dlinesize; - const int slinesize = in->linesize[plane] / 2; - const uint16_t *xmap = (const uint16_t *)xin->data[0] + slice_start * xlinesize; - const uint16_t *ymap = (const uint16_t *)yin->data[0] + slice_start * ylinesize; - - for (y = slice_start; y < slice_end; y++) { - for (x = 0; x < out->width; x++) { - if (ymap[x] < in->height && xmap[x] < in->width) { - dst[x] = src[ymap[x] * slinesize + xmap[x]]; - } else { - dst[x] = 0; - } - } - dst += dlinesize; - xmap += xlinesize; - ymap += ylinesize; - } - } - - return 0; -} +DEFINE_REMAP_PLANAR_FUNC(nearest, 8, 1) +DEFINE_REMAP_PLANAR_FUNC(nearest, 16, 2) /** * remap_packed algorithm expects pixels with both padded bits (step) and @@ -212,85 +175,48 @@ static int remap_planar16_slice(AVFilterContext *ctx, void *arg, int jobnr, int * pixels are copied from source to target using : * Target_frame[y][x] = Source_frame[ ymap[y][x] ][ [xmap[y][x] ]; */ -static int remap_packed_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) -{ - const ThreadData *td = (ThreadData*)arg; - const AVFrame *in = td->in; - const AVFrame *xin = td->xin; - const AVFrame *yin = td->yin; - const AVFrame *out = td->out; - - const int slice_start = (out->height * jobnr ) / nb_jobs; - const int slice_end = (out->height * (jobnr+1)) / nb_jobs; - - const int dlinesize = out->linesize[0]; - const int slinesize = in->linesize[0]; - const int xlinesize = xin->linesize[0] / 2; - const int ylinesize = yin->linesize[0] / 2; - const uint8_t *src = in->data[0]; - uint8_t *dst = out->data[0] + slice_start * dlinesize; - const uint16_t *xmap = (const uint16_t *)xin->data[0] + slice_start * xlinesize; - const uint16_t *ymap = (const uint16_t *)yin->data[0] + slice_start * ylinesize; - const int step = td->step; - int c, x, y; - - for (y = slice_start; y < slice_end; y++) { - for (x = 0; x < out->width; x++) { - for (c = 0; c < td->nb_components; c++) { - if (ymap[x] < in->height && xmap[x] < in->width) { - dst[x * step + c] = src[ymap[x] * slinesize + xmap[x] * step + c]; - } else { - dst[x * step + c] = 0; - } - } - } - dst += dlinesize; - xmap += xlinesize; - ymap += ylinesize; - } - - return 0; +#define DEFINE_REMAP_PACKED_FUNC(name, bits, div) \ +static int remap_packed##bits##_##name##_slice(AVFilterContext *ctx, void *arg, \ + int jobnr, int nb_jobs) \ +{ \ + const ThreadData *td = (ThreadData*)arg; \ + const AVFrame *in = td->in; \ + const AVFrame *xin = td->xin; \ + const AVFrame *yin = td->yin; \ + const AVFrame *out = td->out; \ + const int slice_start = (out->height * jobnr ) / nb_jobs; \ + const int slice_end = (out->height * (jobnr+1)) / nb_jobs; \ + const int dlinesize = out->linesize[0] / div; \ + const int slinesize = in->linesize[0] / div; \ + const int xlinesize = xin->linesize[0] / 2; \ + const int ylinesize = yin->linesize[0] / 2; \ + const uint##bits##_t *src = (const uint##bits##_t *)in->data[0]; \ + uint##bits##_t *dst = (uint##bits##_t *)out->data[0] + slice_start * dlinesize; \ + const uint16_t *xmap = (const uint16_t *)xin->data[0] + slice_start * xlinesize; \ + const uint16_t *ymap = (const uint16_t *)yin->data[0] + slice_start * ylinesize; \ + const int step = td->step / div; \ + int c, x, y; \ + \ + for (y = slice_start; y < slice_end; y++) { \ + for (x = 0; x < out->width; x++) { \ + for (c = 0; c < td->nb_components; c++) { \ + if (ymap[x] < in->height && xmap[x] < in->width) { \ + dst[x * step + c] = src[ymap[x] * slinesize + xmap[x] * step + c]; \ + } else { \ + dst[x * step + c] = 0; \ + } \ + } \ + } \ + dst += dlinesize; \ + xmap += xlinesize; \ + ymap += ylinesize; \ + } \ + \ + return 0; \ } -static int remap_packed16_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) -{ - const ThreadData *td = (ThreadData*)arg; - const AVFrame *in = td->in; - const AVFrame *xin = td->xin; - const AVFrame *yin = td->yin; - const AVFrame *out = td->out; - - const int slice_start = (out->height * jobnr ) / nb_jobs; - const int slice_end = (out->height * (jobnr+1)) / nb_jobs; - - const int dlinesize = out->linesize[0] / 2; - const int slinesize = in->linesize[0] / 2; - const int xlinesize = xin->linesize[0] / 2; - const int ylinesize = yin->linesize[0] / 2; - const uint16_t *src = (const uint16_t *)in->data[0]; - uint16_t *dst = (uint16_t *)out->data[0] + slice_start * dlinesize; - const uint16_t *xmap = (const uint16_t *)xin->data[0] + slice_start * xlinesize; - const uint16_t *ymap = (const uint16_t *)yin->data[0] + slice_start * ylinesize; - const int step = td->step / 2; - int c, x, y; - - for (y = slice_start; y < slice_end; y++) { - for (x = 0; x < out->width; x++) { - for (c = 0; c < td->nb_components; c++) { - if (ymap[x] < in->height && xmap[x] < in->width) { - dst[x * step + c] = src[ymap[x] * slinesize + xmap[x] * step + c]; - } else { - dst[x * step + c] = 0; - } - } - } - dst += dlinesize; - xmap += xlinesize; - ymap += ylinesize; - } - - return 0; -} +DEFINE_REMAP_PACKED_FUNC(nearest, 8, 1) +DEFINE_REMAP_PACKED_FUNC(nearest, 16, 2) static int config_input(AVFilterLink *inlink) { @@ -303,15 +229,15 @@ static int config_input(AVFilterLink *inlink) if (desc->comp[0].depth == 8) { if (s->nb_planes > 1 || s->nb_components == 1) { - s->remap_slice = remap_planar_slice; + s->remap_slice = remap_planar8_nearest_slice; } else { - s->remap_slice = remap_packed_slice; + s->remap_slice = remap_packed8_nearest_slice; } } else { if (s->nb_planes > 1 || s->nb_components == 1) { - s->remap_slice = remap_planar16_slice; + s->remap_slice = remap_planar16_nearest_slice; } else { - s->remap_slice = remap_packed16_slice; + s->remap_slice = remap_packed16_nearest_slice; } }