From patchwork Thu Feb 8 10:28:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Martinez X-Patchwork-Id: 7528 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.150.1 with SMTP id c1csp1686941jai; Thu, 8 Feb 2018 02:28:51 -0800 (PST) X-Google-Smtp-Source: AH8x224qJdu45StaYEf1czWIjjRNBteT+t071bch7wyDyVcNaOtXU/vZ3RAwPW74a+3ysqYkvIca X-Received: by 10.223.139.214 with SMTP id w22mr245875wra.186.1518085731151; Thu, 08 Feb 2018 02:28:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518085731; cv=none; d=google.com; s=arc-20160816; b=QOaKcFhGoXHt9nXVrYFHZFWBV+NpRrAzcp9eOdVUa7zxR6neF+0+IlyUp3b852Ci3D qNvgpY37QdG2Ff/IJgSgvhWYMnw0KrZfzxP6WA+Y1v+LbBsPxmVlj3ZYw6ryUlIzvFN4 AykTi1jAZPVivFAwjIFmqv5qPDTEBYfCUKblFdNN8/j+wpUzQhKjl0ytuoo9jNPM7ZQq ofQAfjAiHdBMLdT5rTUfhQJOApUFBi5xU2v/z6tSg7P9DSvblrzbRX/I4vPwuwO5p3ro BchQq+I3fEhwmjKCyTD+umF78XZpQ5B2o68WgtGE/xeHxkHtUB8ynaKtaMYJCVHa2iJp fYmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject :content-language:mime-version:user-agent:date:message-id:to:from :delivered-to:arc-authentication-results; bh=dgpHhYwNi+PEyogrisqCF8tj7QjO2WsC52gpv04nL9g=; b=sMOldV3lDAig8bpiCDdp2Tdsi03uJwC2UNrU1vKgxoAxkLUtzGGjgQiMQl1iBXxXlL GIetWKJrD8k3+mo7Wuf4FNxBmPR28xGQmgZ0w1rgeaOtKj2wR5d1wIG0DVLg5WZ9Awpa i6mz61mk4Il4eg88jMNKpnF0EicZM47I3ixXz5dbb/e6d9tjkAWyklpORKkYKJ9lLFiS vVvc1VdBf28nyIetYqnbrHWr+WLVGkCXzp5502tZMox2qcBPdWH+OYsohDwqMeq576vd QPZmsgksIN3VW2FeDFDY/JcaWpxY89r8VqYN4my01S6JVd2rsHwi4Anb8caquYLQiNpu cYCQ== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id l20si722816wre.478.2018.02.08.02.28.50; Thu, 08 Feb 2018 02:28:51 -0800 (PST) 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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EB36B689767; Thu, 8 Feb 2018 12:28:39 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from 16.mo4.mail-out.ovh.net (16.mo4.mail-out.ovh.net [188.165.55.104]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5166B680B81 for ; Thu, 8 Feb 2018 12:28:34 +0200 (EET) Received: from player759.ha.ovh.net (b9.ovh.net [213.186.33.59]) by mo4.mail-out.ovh.net (Postfix) with ESMTP id 70CC914A86C for ; Thu, 8 Feb 2018 11:28:42 +0100 (CET) Received: from [192.168.2.120] (p5DDB56EF.dip0.t-ipconnect.de [93.219.86.239]) (Authenticated sender: zen-lists@mediaarea.net) by player759.ha.ovh.net (Postfix) with ESMTPSA id 41ABD6400BA for ; Thu, 8 Feb 2018 11:28:42 +0100 (CET) From: Jerome Martinez To: FFmpeg development discussions and patches Message-ID: <1d1e3171-771f-7e1d-0dd6-6bf04430ba5c@mediaarea.net> Date: Thu, 8 Feb 2018 11:28:44 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 Content-Language: en-GB X-Ovh-Tracer-Id: 2763521324588142781 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedtfedrudekgdduhecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd Subject: [FFmpeg-devel] [PATCH] avcodec/dpx: Support for RGB and RGBA 12-bit packed decoding 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Currently RGB and RGBA 12-bit are supported by DPX decoder only if component values are padded (packing "Filled to 32-bit words, method A"). This patch adds decoding of RGB and RGBA 12-bit with no padding (packing "Packed into 32-bit words"). As I have no file with line boundaries not aligned on 32-bit, I can not have good tests about the stride computing (so code about non aligned boundaries is theory) so I preferred to limit risks by decoding only if line boundaries are aligned on 32-bit words: - 8 pixels for RGB (8 pixels x 3 components x 12 bits = 288 bits = 9 x 32-bit words) - 2 pixels for RGBA (2 pixels x 4 components x 12 bits = 3 x 32-bit words) I think Little Endian parsing is fine thanks to the generic code about Big vs Little endian but I have no Little Endian test file so I also limited the decoding to Big Endian files. Would be happy to check with cases I was not able to check if someone provides files. I kept "Packing to 16bit required\n" message but interested in any suggestion about a better wording due to exceptions. My test files: https://github.com/MediaArea/RAWcooked-RegressionTestingFiles/tree/master/Formats/DPX/Flavors/RGB_12_Packed_BE Regression tests done on 12-bit content "Filled to 32-bit words, method A" in: https://samples.ffmpeg.org/image-samples/dpx_samples.zip From bf95371e3964e198e22dc545fc75706dedf9029b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Martinez?= Date: Thu, 8 Feb 2018 09:22:08 +0100 Subject: [PATCH] avcodec/dpx: Support for RGB and RGBA 12-bit packed decoding Limited to widths multiple of 8 (RGB) and 2 (RGBA) due to lack of test files for such corner case --- libavcodec/dpx.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 67 insertions(+), 3 deletions(-) diff --git a/libavcodec/dpx.c b/libavcodec/dpx.c index 1aa2cbd1c8..aaacd243c9 100644 --- a/libavcodec/dpx.c +++ b/libavcodec/dpx.c @@ -65,6 +65,38 @@ static uint16_t read10in32(const uint8_t **ptr, uint32_t * lbuf, return *lbuf & 0x3FF; } +static uint16_t read12in32(const uint8_t **ptr, uint32_t * lbuf, + int * n_datum, int is_big) +{ + if (*n_datum) + (*n_datum)--; + else { + *lbuf = read32(ptr, is_big); + *n_datum = 7; + } + + switch (*n_datum){ + case 7: return *lbuf & 0xFFF; + case 6: return (*lbuf >> 12) & 0xFFF; + case 5: { + uint32_t c = *lbuf >> 24; + *lbuf = read32(ptr, is_big); + c |= *lbuf << 8; + return c & 0xFFF; + } + case 4: return (*lbuf >> 4) & 0xFFF; + case 3: return (*lbuf >> 16) & 0xFFF; + case 2: { + uint32_t c = *lbuf >> 28; + *lbuf = read32(ptr, is_big); + c |= *lbuf << 4; + return c & 0xFFF; + } + case 1: return (*lbuf >> 8) & 0xFFF; + default: return *lbuf >> 20; + } +} + static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, @@ -201,10 +233,29 @@ static int decode_frame(AVCodecContext *avctx, break; case 12: if (!packing) { - av_log(avctx, AV_LOG_ERROR, "Packing to 16bit required\n"); - return -1; + int tested = 0; + if (endian && descriptor == 50 && (avctx->width%8) == 0) // Little endian and widths not a multiple of 8 need tests + tested = 1; + if (endian && descriptor == 51 && (avctx->width%2) == 0) // Little endian and widths not a multiple of 2 need tests + tested = 1; + if (!tested) { + av_log(avctx, AV_LOG_ERROR, "Packing to 16bit required\n"); + return -1; + } + } + stride = avctx->width * elements; + if (packing) + stride *= 2; + else { + stride *= 3; // 12 bits are 1.5 byte so multiplied by 3 then divided by 2 + if (stride % 8) { + // Align to 32-bit boundaries (not tested) + stride /= 8; + stride++; + stride *= 8; + } + stride /= 2; } - stride = 2 * avctx->width * elements; break; case 16: stride = 2 * avctx->width * elements; @@ -349,6 +400,7 @@ static int decode_frame(AVCodecContext *avctx, (uint16_t*)ptr[2], (uint16_t*)ptr[3]}; for (y = 0; y < avctx->width; y++) { + if (packing) { if (elements >= 3) *dst[2]++ = read16(&buf, endian) >> 4; *dst[0] = read16(&buf, endian) >> 4; @@ -357,6 +409,18 @@ static int decode_frame(AVCodecContext *avctx, *dst[1]++ = read16(&buf, endian) >> 4; if (elements == 4) *dst[3]++ = read16(&buf, endian) >> 4; + } + else { + *dst[2]++ = read12in32(&buf, &rgbBuffer, + &n_datum, endian); + *dst[0]++ = read12in32(&buf, &rgbBuffer, + &n_datum, endian); + *dst[1]++ = read12in32(&buf, &rgbBuffer, + &n_datum, endian); + if (elements == 4) + *dst[3]++ = read12in32(&buf, &rgbBuffer, + &n_datum, endian); + } } for (i = 0; i < elements; i++) ptr[i] += p->linesize[i];