From patchwork Mon Mar 1 14:41:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 26047 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 5399844AC8E for ; Mon, 1 Mar 2021 17:11:59 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2F17868A8DF; Mon, 1 Mar 2021 17:11:59 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BBB8268A73D for ; Mon, 1 Mar 2021 17:11:52 +0200 (EET) Received: by mail-wr1-f52.google.com with SMTP id d15so1291161wrv.5 for ; Mon, 01 Mar 2021 07:11:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=UZrYGJlV4QKKN1frCsFFxhN58Vuw71LY12Iz2E+RbYk=; b=ip/vlQx+aubQp165t1exAjMgAWX9f3eZ5lMVE7b+9HGAasXY/ghgqun2jmKUx0MRQv T5zdhZT9jPANoq9EbHsUoLkNpgLBRDTpico1HgMkPcM45Z55OTYE6/M525Oxj4Y+ZYEU yL7UqfKD/Qfq6Mt4459Cz9QwVceIja3sHrqLafMeuxY8BBA0jwPde+GQLa1TtqrlBHqj 4jtXLAC4YUiAl0aEei4wLcGGIY1SAxzFwO41vdX5lJ1EL7CNVFP+fhlFPfRpWgdTxHz9 f6G9mzR7YsxZmmZ6JQFVZAjCjaaeI0oDmNJjAQuYd7pONbr7859IlDF35cQjhqCgCkeg 6XNA== 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=UZrYGJlV4QKKN1frCsFFxhN58Vuw71LY12Iz2E+RbYk=; b=d1iz6QfGdCF5ZZ+V6X4Pqp/+WvuT6PgSsBaUlE1D6BWfFDHo3J3LHxeCDjida4JtuY NqnhfomXu5ICIjknMXlzwoYKHQ5QthZL3KvuAArFxeVROVroH6M0sDbv3eMXvU3hVjAJ xxGbEtmw8nt/lvvXdAZAT1gePu8OHPprNRQae+aSilGtxbNZRSxQZSJ5y38oYTrT+20D EEvqw8jrjF5+vOU01ugN/7pGnvSvaHwcabiREIZOwLmYOrxQTC+zfGiMsSlsH9AwGAU1 j7o7QnRt7d7nDPYQZ5ZnAQKPA1AHz+Da8AjEtwLZYSPi2cximdXEabPGaE1b5BcZRFEW 7zMQ== X-Gm-Message-State: AOAM530S7+d7vv8LiyO/IjEYOuReyleRSjVoN6x3Bal1bX//kOlhy46j YCa6yDaFWqIUxkaBWq71XKsWghO2NHo= X-Google-Smtp-Source: ABdhPJwYw+s6co9j9PnfF6bMEBHr3PpRHe6PeMvMkfdx9re8X48lgtmRRhfw/gn2inEuc87NOhx9vQ== X-Received: by 2002:a17:907:3d8d:: with SMTP id he13mr16403298ejc.448.1614609691656; Mon, 01 Mar 2021 06:41:31 -0800 (PST) Received: from localhost.localdomain ([109.227.52.18]) by smtp.gmail.com with ESMTPSA id b17sm13791111ejj.9.2021.03.01.06.41.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Mar 2021 06:41:31 -0800 (PST) From: Paul B Mahol To: ffmpeg-devel@ffmpeg.org Date: Mon, 1 Mar 2021 15:41:22 +0100 Message-Id: <20210301144122.4731-1-onemda@gmail.com> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH] avcodec/speedhq: fix decoding 422 subsampling when width is not multiple of 16 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/speedhq.c | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/libavcodec/speedhq.c b/libavcodec/speedhq.c index 759fc6dfc5..2a2fc42efa 100644 --- a/libavcodec/speedhq.c +++ b/libavcodec/speedhq.c @@ -283,6 +283,7 @@ static int decode_speedhq_field(const SHQContext *s, const uint8_t *buf, int buf int linesize_cb = frame->linesize[1] * line_stride; int linesize_cr = frame->linesize[2] * line_stride; int linesize_a; + GetBitContext gb; if (s->alpha_type != SHQ_NO_ALPHA) linesize_a = frame->linesize[3] * line_stride; @@ -304,7 +305,6 @@ static int decode_speedhq_field(const SHQContext *s, const uint8_t *buf, int buf } for (slice_number = 0; slice_number < 4; slice_number++) { - GetBitContext gb; uint32_t slice_begin, slice_end; int x, y; @@ -333,7 +333,7 @@ static int decode_speedhq_field(const SHQContext *s, const uint8_t *buf, int buf dest_a = frame->data[3] + frame->linesize[3] * (y + field_number); } - for (x = 0; x < frame->width; x += 16) { + for (x = 0; x < frame->width - 8 * (s->subsampling != SHQ_SUBSAMPLING_444); x += 16) { /* Decode the four luma blocks. */ if ((ret = decode_dct_block(s, &gb, last_dc, 0, dest_y, linesize_y)) < 0) return ret; @@ -402,6 +402,44 @@ static int decode_speedhq_field(const SHQContext *s, const uint8_t *buf, int buf } } + if (s->subsampling == SHQ_SUBSAMPLING_444) + return 0; + + if (!(frame->width & 15)) + return 0; + + for (int y = 0; y < frame->height; y += 16 * line_stride) { + int last_dc[4] = { 1024, 1024, 1024, 1024 }; + uint8_t *dest_y, *dest_cb, *dest_cr; + int x = frame->width - 8; + + dest_y = frame->data[0] + frame->linesize[0] * (y + field_number) + x; + if (s->subsampling == SHQ_SUBSAMPLING_420) { + dest_cb = frame->data[1] + frame->linesize[1] * (y/2 + field_number) + x / 2; + dest_cr = frame->data[2] + frame->linesize[2] * (y/2 + field_number) + x / 2; + } else if (s->subsampling == SHQ_SUBSAMPLING_422) { + dest_cb = frame->data[1] + frame->linesize[1] * (y + field_number) + x / 2; + dest_cr = frame->data[2] + frame->linesize[2] * (y + field_number) + x / 2; + } + + if ((ret = decode_dct_block(s, &gb, last_dc, 0, dest_y, linesize_y)) < 0) + return ret; + if ((ret = decode_dct_block(s, &gb, last_dc, 0, dest_y + 8, linesize_y)) < 0) + return ret; + if ((ret = decode_dct_block(s, &gb, last_dc, 0, dest_y + 8 * linesize_y, linesize_y)) < 0) + return ret; + if ((ret = decode_dct_block(s, &gb, last_dc, 0, dest_y + 8 * linesize_y + 8, linesize_y)) < 0) + return ret; + if ((ret = decode_dct_block(s, &gb, last_dc, 1, dest_cb, linesize_cb)) < 0) + return ret; + if ((ret = decode_dct_block(s, &gb, last_dc, 2, dest_cr, linesize_cr)) < 0) + return ret; + if ((ret = decode_dct_block(s, &gb, last_dc, 1, dest_cb + 8 * linesize_cb, linesize_cb)) < 0) + return ret; + if ((ret = decode_dct_block(s, &gb, last_dc, 2, dest_cr + 8 * linesize_cr, linesize_cr)) < 0) + return ret; + } + return 0; }