From patchwork Sun Mar 12 11:40:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 2901 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.50.79 with SMTP id y76csp778711vsy; Sun, 12 Mar 2017 04:47:08 -0700 (PDT) X-Received: by 10.223.176.217 with SMTP id j25mr25352668wra.8.1489319228054; Sun, 12 Mar 2017 04:47:08 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id u189si6780539wmg.112.2017.03.12.04.47.07; Sun, 12 Mar 2017 04:47:08 -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; 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=NONE 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 0D24A689B24; Sun, 12 Mar 2017 13:46:50 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr0-f195.google.com (mail-wr0-f195.google.com [209.85.128.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 32A67689B0D for ; Sun, 12 Mar 2017 13:46:44 +0200 (EET) Received: by mail-wr0-f195.google.com with SMTP id g10so16791391wrg.0 for ; Sun, 12 Mar 2017 04:46:59 -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=YiSehGEIbyefDRvbiDio87Hp7Dao+8v/Y+NeYGCLXVs=; b=AZb7K/sQldgbYD8xdyqUPgCfnhsC0DcqcAj1d/BsRjI+KLqF3HRWobq0iy8RjTGjhu Ns+Sh6hEQNSzt2vcI1Y13mKC7z3CwgWTzXqXVtWUkUSGd4SLB42XOENbgmvfbKv/BwJl R5rmQ8i+nHJXxYV9fcBEbGqwgfjKqPL0UWn+TZX6T3PycGe2xd3Oh1kWhlu/ddRHSgOv 7E0Ah/ZjCnriPdbiTqnnSVepiyKK6bDfyBPhGmbRX+fiZUoOqGrmEGzAByH2M+00C62v hwIUrMR7IUZlDhFmCGnmRQxNBoBnZbaf0cK6GoOoBoLGny1hHKngnFtnMl4TuKUD+FSO 9qeQ== 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=YiSehGEIbyefDRvbiDio87Hp7Dao+8v/Y+NeYGCLXVs=; b=OG/zGJDmC2JM1uJImogOD6rUlpppp6K+dZ71gAXPqAy3EUk+j4BTuPnsXkq6PJZxve lhSwSNCaT+kZoVIKA2R7qLKDimqUejJ4flhAjzr3m8W21ld/jJqqjqbk5CRkL9itBm6H I9XxlJIEluWyMspFz6XpkQP98VoIo9FXOboK3oyM/xvH/oGQQs9xKnJrzvmlknbs3s74 7XLLwVHiTQj17d4a7VlqQeMBRD+Pfj2/7AUKTFMJmkj1oI9yoazIG39jI1u+Qvmp2QkU B564Oj0ih6u/iFcy++a7o5QG3j8fRro3wq6i9na/o5g5RVmBNfHndACVa58sSR/s0kVO iCRA== X-Gm-Message-State: AMke39mUDIgrO7Tjfwbw13mcVvHHZxmCfBjpzWgYJFdrpF3yl6w5xy3w9tNbRvHeg8nZ/A== X-Received: by 10.223.155.17 with SMTP id b17mr22632342wrc.181.1489318852550; Sun, 12 Mar 2017 04:40:52 -0700 (PDT) Received: from localhost.localdomain ([94.250.174.60]) by smtp.gmail.com with ESMTPSA id j26sm20824254wrb.69.2017.03.12.04.40.50 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 12 Mar 2017 04:40:50 -0700 (PDT) From: Paul B Mahol To: ffmpeg-devel@ffmpeg.org Date: Sun, 12 Mar 2017 12:40:39 +0100 Message-Id: <20170312114040.25287-1-onemda@gmail.com> X-Mailer: git-send-email 2.9.3 Subject: [FFmpeg-devel] [PATCH 1/2] avcodec/scpr: avoid negative linesize 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 --- libavcodec/scpr.c | 89 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 48 insertions(+), 41 deletions(-) diff --git a/libavcodec/scpr.c b/libavcodec/scpr.c index 465926a..a37e99a 100644 --- a/libavcodec/scpr.c +++ b/libavcodec/scpr.c @@ -290,6 +290,14 @@ static int decode_unit(SCPRContext *s, PixelModel *pixel, unsigned step, unsigne return 0; } +static int vflip(int pos, int h, int linesize) +{ + int y = pos / linesize; + int x = pos % linesize; + + return (h - y) * linesize + x; +} + static int decompress_i(AVCodecContext *avctx, uint32_t *dst, int linesize) { SCPRContext *s = avctx->priv_data; @@ -299,6 +307,7 @@ static int decompress_i(AVCodecContext *avctx, uint32_t *dst, int linesize) unsigned backstep = linesize - avctx->width; const int cxshift = s->cxshift; unsigned lx, ly, ptype; + const int hy = avctx->height - 1; reinit_tables(s); bytestream2_skip(gb, 2); @@ -331,7 +340,7 @@ static int decompress_i(AVCodecContext *avctx, uint32_t *dst, int linesize) clr = (b << 16) + (g << 8) + r; k += run; while (run-- > 0) { - dst[y * linesize + x] = clr; + dst[vflip(y * linesize + x, hy, linesize)] = clr; lx = x; ly = y; x++; @@ -379,7 +388,7 @@ static int decompress_i(AVCodecContext *avctx, uint32_t *dst, int linesize) if (y >= avctx->height) return AVERROR_INVALIDDATA; - dst[y * linesize + x] = clr; + dst[vflip(y * linesize + x, hy, linesize)] = clr; lx = x; ly = y; x++; @@ -394,7 +403,7 @@ static int decompress_i(AVCodecContext *avctx, uint32_t *dst, int linesize) if (y >= avctx->height) return AVERROR_INVALIDDATA; - dst[y * linesize + x] = dst[ly * linesize + lx]; + dst[vflip(y * linesize + x, hy, linesize)] = dst[vflip(ly * linesize + lx, hy, linesize)]; lx = x; ly = y; x++; @@ -403,15 +412,15 @@ static int decompress_i(AVCodecContext *avctx, uint32_t *dst, int linesize) y++; } } - clr = dst[ly * linesize + lx]; + clr = dst[vflip(ly * linesize + lx, hy, linesize)]; break; case 2: while (run-- > 0) { if (y < 1 || y >= avctx->height) return AVERROR_INVALIDDATA; - clr = dst[y * linesize + x + off + 1]; - dst[y * linesize + x] = clr; + clr = dst[vflip(y * linesize + x + off + 1, hy, linesize)]; + dst[vflip(y * linesize + x, hy, linesize)] = clr; lx = x; ly = y; x++; @@ -435,17 +444,17 @@ static int decompress_i(AVCodecContext *avctx, uint32_t *dst, int linesize) z = 0; } - r = odst[(ly * linesize + lx) * 4] + - odst[((y * linesize + x) + off - z) * 4 + 4] - - odst[((y * linesize + x) + off - z) * 4]; - g = odst[(ly * linesize + lx) * 4 + 1] + - odst[((y * linesize + x) + off - z) * 4 + 5] - - odst[((y * linesize + x) + off - z) * 4 + 1]; - b = odst[(ly * linesize + lx) * 4 + 2] + - odst[((y * linesize + x) + off - z) * 4 + 6] - - odst[((y * linesize + x) + off - z) * 4 + 2]; + r = odst[vflip((ly * linesize + lx) * 4, hy, linesize * 4)] + + odst[vflip(((y * linesize + x) + off - z) * 4 + 4, hy, linesize * 4)] - + odst[vflip(((y * linesize + x) + off - z) * 4, hy, linesize * 4)]; + g = odst[vflip((ly * linesize + lx) * 4 + 1, hy, linesize * 4)] + + odst[vflip(((y * linesize + x) + off - z) * 4 + 5, hy, linesize * 4)] - + odst[vflip(((y * linesize + x) + off - z) * 4 + 1, hy, linesize * 4)]; + b = odst[vflip((ly * linesize + lx) * 4 + 2, hy, linesize * 4)] + + odst[vflip(((y * linesize + x) + off - z) * 4 + 6, hy, linesize * 4)] - + odst[vflip(((y * linesize + x) + off - z) * 4 + 2, hy, linesize * 4)]; clr = ((b & 0xFF) << 16) + ((g & 0xFF) << 8) + (r & 0xFF); - dst[y * linesize + x] = clr; + dst[vflip(y * linesize + x, hy, linesize)] = clr; lx = x; ly = y; x++; @@ -467,8 +476,8 @@ static int decompress_i(AVCodecContext *avctx, uint32_t *dst, int linesize) z = 0; } - clr = dst[y * linesize + x + off - z]; - dst[y * linesize + x] = clr; + clr = dst[vflip(y * linesize + x + off - z, hy, linesize)]; + dst[vflip(y * linesize + x, hy, linesize)] = clr; lx = x; ly = y; x++; @@ -501,6 +510,7 @@ static int decompress_p(AVCodecContext *avctx, int ret, temp, min, max, x, y, cx = 0, cx1 = 0; int backstep = linesize - avctx->width; const int cxshift = s->cxshift; + const int hy = avctx->height - 1; if (bytestream2_get_byte(gb) == 0) return 0; @@ -567,7 +577,7 @@ static int decompress_p(AVCodecContext *avctx, for (i = 0; i < sy2 - sy1 && (by + sy1 + i) < avctx->height && (by + mvy + sy1 + i) < avctx->height; i++) { for (j = 0; j < sx2 - sx1 && (bx + sx1 + j) < avctx->width && (bx + mvx + sx1 + j) < avctx->width; j++) { - dst[(by + i + sy1) * linesize + bx + sx1 + j] = prev[(by + mvy + sy1 + i) * plinesize + bx + sx1 + mvx + j]; + dst[vflip((by + i + sy1) * linesize + bx + sx1 + j, hy, linesize)] = prev[vflip((by + mvy + sy1 + i) * plinesize + bx + sx1 + mvx + j, hy, linesize)]; } } } else { @@ -607,7 +617,7 @@ static int decompress_p(AVCodecContext *avctx, if (by >= avctx->height) return AVERROR_INVALIDDATA; - dst[by * linesize + bx] = clr; + dst[vflip(by * linesize + bx, hy, linesize)] = clr; bx++; if (bx >= x * 16 + sx2 || bx >= avctx->width) { bx = x * 16 + sx1; @@ -628,8 +638,8 @@ static int decompress_p(AVCodecContext *avctx, if (by >= avctx->height) return AVERROR_INVALIDDATA; - clr = dst[by * linesize + bx - 1 - z]; - dst[by * linesize + bx] = clr; + clr = dst[vflip(by * linesize + bx - 1 - z, hy, linesize)]; + dst[vflip(by * linesize + bx, hy, linesize)] = clr; bx++; if (bx >= x * 16 + sx2 || bx >= avctx->width) { bx = x * 16 + sx1; @@ -642,8 +652,8 @@ static int decompress_p(AVCodecContext *avctx, if (by < 1 || by >= avctx->height) return AVERROR_INVALIDDATA; - clr = dst[(by - 1) * linesize + bx]; - dst[by * linesize + bx] = clr; + clr = dst[vflip((by - 1) * linesize + bx, hy, linesize)]; + dst[vflip(by * linesize + bx, hy, linesize)] = clr; bx++; if (bx >= x * 16 + sx2 || bx >= avctx->width) { bx = x * 16 + sx1; @@ -656,8 +666,8 @@ static int decompress_p(AVCodecContext *avctx, if (by >= avctx->height) return AVERROR_INVALIDDATA; - clr = prev[by * plinesize + bx]; - dst[by * linesize + bx] = clr; + clr = prev[vflip(by * plinesize + bx, hy, plinesize)]; + dst[vflip(by * linesize + bx, hy, linesize)] = clr; bx++; if (bx >= x * 16 + sx2 || bx >= avctx->width) { bx = x * 16 + sx1; @@ -678,17 +688,17 @@ static int decompress_p(AVCodecContext *avctx, z = 0; } - r = odst[((by - 1) * linesize + bx) * 4] + - odst[(by * linesize + bx - 1 - z) * 4] - - odst[((by - 1) * linesize + bx - 1 - z) * 4]; - g = odst[((by - 1) * linesize + bx) * 4 + 1] + - odst[(by * linesize + bx - 1 - z) * 4 + 1] - - odst[((by - 1) * linesize + bx - 1 - z) * 4 + 1]; - b = odst[((by - 1) * linesize + bx) * 4 + 2] + - odst[(by * linesize + bx - 1 - z) * 4 + 2] - - odst[((by - 1) * linesize + bx - 1 - z) * 4 + 2]; + r = odst[vflip(((by - 1) * linesize + bx) * 4, hy, linesize * 4)] + + odst[vflip((by * linesize + bx - 1 - z) * 4, hy, linesize * 4)] - + odst[vflip(((by - 1) * linesize + bx - 1 - z) * 4, hy, linesize * 4)]; + g = odst[vflip(((by - 1) * linesize + bx) * 4 + 1, hy, linesize * 4)] + + odst[vflip((by * linesize + bx - 1 - z) * 4 + 1, hy, linesize * 4)] - + odst[vflip(((by - 1) * linesize + bx - 1 - z) * 4 + 1, hy, linesize * 4)]; + b = odst[vflip(((by - 1) * linesize + bx) * 4 + 2, hy, linesize * 4)] + + odst[vflip((by * linesize + bx - 1 - z) * 4 + 2, hy, linesize * 4)] - + odst[vflip(((by - 1) * linesize + bx - 1 - z) * 4 + 2, hy, linesize * 4)]; clr = ((b & 0xFF) << 16) + ((g & 0xFF) << 8) + (r & 0xFF); - dst[by * linesize + bx] = clr; + dst[vflip(by * linesize + bx, hy, linesize)] = clr; bx++; if (bx >= x * 16 + sx2 || bx >= avctx->width) { bx = x * 16 + sx1; @@ -707,8 +717,8 @@ static int decompress_p(AVCodecContext *avctx, z = 0; } - clr = dst[(by - 1) * linesize + bx - 1 - z]; - dst[by * linesize + bx] = clr; + clr = dst[vflip((by - 1) * linesize + bx - 1 - z, hy, linesize)]; + dst[vflip(by * linesize + bx, hy, linesize)] = clr; bx++; if (bx >= x * 16 + sx2 || bx >= avctx->width) { bx = x * 16 + sx1; @@ -830,9 +840,6 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, FFSWAP(AVFrame *, s->current_frame, s->last_frame); - frame->data[0] += frame->linesize[0] * (avctx->height - 1); - frame->linesize[0] *= -1; - *got_frame = 1; return avpkt->size;