From patchwork Wed Feb 14 12:46:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Martinez X-Patchwork-Id: 7598 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.150.1 with SMTP id c1csp728494jai; Wed, 14 Feb 2018 04:47:08 -0800 (PST) X-Google-Smtp-Source: AH8x2241VNxOPoMY0LdL68YWA9/clgD9IUqpWqbWSykfiJCNquTdpyy6HXUHoCh27iuWjJniv+Al X-Received: by 10.223.156.145 with SMTP id d17mr4592805wre.1.1518612427950; Wed, 14 Feb 2018 04:47:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518612427; cv=none; d=google.com; s=arc-20160816; b=moPIUa8W23QVQqaxIgNV8/LU8bMev7ZGY4/ZZ24PFvjvN6XK+GLqY+htP4QooE7Cf9 JddmVT2BXIiqhcZrE9ym0BX95tuKC+qBppLhGtDnz5kS4BwnvWZJHkceuyblZvKIX8C4 aBL9GBzXw8BVjZhe2arRSip0uS/tzgqijNZ57JhwyvXNWwf+8pSpTu6wNrHSZpNj+hqO c3apqRxLuelRu7o2vNLHuYhvIHiR7tg2c6HVa4gEBl3AA8lyAOa7ju4OvOf4FQgtl0fh ZHBgaGvbyWVmq8mE5tHo4A2Bd4kaVibivhPxaVWAngMqhb6XdFBzKbhkJqnKP4O4Lqqj MKBQ== 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:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:delivered-to :arc-authentication-results; bh=BfRCEE6ZcON+juelUpsmt2PJxoyFkIBSkIDOTW3RvTM=; b=baInta3AVkWblp3KEN0N4ayKN1TsWPNG7juwvQOY9TgGFH5d97kEW9S2gQOKcWUQCS ZPMEfV3UHL81JOixeEaM+2UQhDTFswu642kjRZq7k7pAq+PCIIwJ1FW6Bk9Sa4ZCI2ea awDAnxVAXWgXm5+PLo2Fcx2JW45P9LZKCEaY0+KVyXXsUMboR0fa8u4+xElA2ZA4OUjv HNY7ZxbyHwkxk+OjqjCDj2x9ns9DqNOz7qr6zZThgngLOxIk6hduqoZS0fPNL7ZZPku9 FRBQ5PTC2irbiNq8BmUwcA69OCjwDi3KPOw9CVC7R64E758q3BBsuE/AWj83nDydvD8Z vfTg== 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 6si6744575wmb.186.2018.02.14.04.47.07; Wed, 14 Feb 2018 04:47:07 -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 2D5B2689FB2; Wed, 14 Feb 2018 14:46:55 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from 9.mo3.mail-out.ovh.net (9.mo3.mail-out.ovh.net [87.98.184.141]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AE125689F5D for ; Wed, 14 Feb 2018 14:46:48 +0200 (EET) Received: from player693.ha.ovh.net (gw6.ovh.net [213.251.189.206]) by mo3.mail-out.ovh.net (Postfix) with ESMTP id 0BAF4197394 for ; Wed, 14 Feb 2018 13:46:58 +0100 (CET) Received: from [192.168.2.120] (p5DDB67CD.dip0.t-ipconnect.de [93.219.103.205]) (Authenticated sender: zen-lists@mediaarea.net) by player693.ha.ovh.net (Postfix) with ESMTPSA id C50BB44008C for ; Wed, 14 Feb 2018 13:46:58 +0100 (CET) To: ffmpeg-devel@ffmpeg.org References: <1d1e3171-771f-7e1d-0dd6-6bf04430ba5c@mediaarea.net> From: Jerome Martinez Message-ID: <133b22e5-2849-4cde-8da7-8332b4ae8a77@mediaarea.net> Date: Wed, 14 Feb 2018 13:46:59 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <1d1e3171-771f-7e1d-0dd6-6bf04430ba5c@mediaarea.net> Content-Language: en-GB X-Ovh-Tracer-Id: 3441313066859958461 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedtfedrfedtgdeggecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecu Subject: [FFmpeg-devel] [PATCH] avcodec/dpx: Support for RGB 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" On 08/02/2018 11:28, Jerome Martinez wrote: > 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 Looks like the previous version of the patch is not included due to the debate about RGBA. Please consider to include this modified patch, which has the RGBA part commented (I could remove the commented lines if you prefer). From 28316686fed140279494d8c94e4f6bb5707e9ac0 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 12-bit packed decoding Limited to widths multiple of 8 (RGB) due to lack of test files for such corner case This partially fixes ticket #5639 --- libavcodec/dpx.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 66 insertions(+), 3 deletions(-) diff --git a/libavcodec/dpx.c b/libavcodec/dpx.c index 1aa2cbd1c8..7e2a6fb779 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,17 @@ 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];