From patchwork Fri Feb 9 11:10:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Martinez X-Patchwork-Id: 7534 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.150.1 with SMTP id c1csp638665jai; Fri, 9 Feb 2018 03:10:58 -0800 (PST) X-Google-Smtp-Source: AH8x226NkPORJhRod/igZWliQzvz3BLt0CVwHTUe3akPWUx8IMX/YawbOAMoZEK9mlEPvpaSnJsv X-Received: by 10.223.177.201 with SMTP id r9mr1149052wra.164.1518174658322; Fri, 09 Feb 2018 03:10:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518174658; cv=none; d=google.com; s=arc-20160816; b=YLArqFK4ReXbhAfvjyTAOP7fFvBp9QzUEG580FGy9Wy+eTJeYREQ2cE0Qr6KtZFatX 6A4hHTPwa8jPeDP/ObZq1B5kLkh5wCz8phusmYescK0V+8c/d/g2MCgXoYJ21lspaWwC TY9CO5cxIudOW5nZLRvIeoxiNDzcYUX26KYSEla2mP3alAN9bHZkktHG6h5pnQ4oP9CG NmhMXuvBopkIleqf1jG6jsSQVb08PxptmA9mKnRyNTN4d2NA6MqRW9aFj/G3uNsUkobl 1S5f9yefSo2S1bnGy0RjCrDDGEvX+tcTTj+8iVyUjiKN2lvJOo3b1NdjFbJK0PnKLKp/ xufw== 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=YkRItbTe5IDaE39i4IhzXoH9hMlHhZnoeUZk3GTOPjs=; b=KT52keUhk20pB6hOt2M4Q7HO0OPG8/sYVWM6BQk1oC3lS5yRZmp8dJ4do2qao+cwq2 c3opVTAPKsMog8QHUqRA5Vlt4yJh51ivbiNwY3RSgUCOOT+/KMn4LDUCxDAT1thTJLSm k14dK0B04KmMwZEFOzh1TNRSlo4MmhDO2UIuEvzvIkMdMXkKfxQQ/w0iKRlPgOxbAlgi ejQk79eXv6SpKb9wY8j4PZXXQ+7CcGHv7chSc+E2DXb3zxcka/S/JLpc7JClCqNaX+L0 /0Y915S2WBCpyj+/AZWXtZZEtBANjQeSPG44QLiKbgGRSo6fVXMVzAVmczUN1p9xaRfX 6ZAA== 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 e37si1602284wre.471.2018.02.09.03.10.57; Fri, 09 Feb 2018 03:10:58 -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 70571689953; Fri, 9 Feb 2018 13:10:46 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from 11.mo4.mail-out.ovh.net (11.mo4.mail-out.ovh.net [46.105.34.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B931668086F for ; Fri, 9 Feb 2018 13:10:40 +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 A2B08148AAE for ; Fri, 9 Feb 2018 12:10:49 +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 531656400B5 for ; Fri, 9 Feb 2018 12:10:49 +0100 (CET) To: ffmpeg-devel@ffmpeg.org References: <1d1e3171-771f-7e1d-0dd6-6bf04430ba5c@mediaarea.net> <2dd4a28d-ad31-f6d3-8849-d68d6eef4a77@mediaarea.net> From: Jerome Martinez Message-ID: <6eaaed88-607c-abc4-ba73-5414f931f7dc@mediaarea.net> Date: Fri, 9 Feb 2018 12:10:52 +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: Content-Language: en-GB X-Ovh-Tracer-Id: 9347502503729303741 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedtfedrvddtgddviecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecu Subject: Re: [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" On 09/02/2018 11:32, Carl Eugen Hoyos wrote: > [...] please mention ticket #5639 in the commit message. I should definitely have indicated this source instead of my copy, my mistake. Commit message extended with it. FYI I am running tests on several DPX flavors (to FFV1 and back to DPX, checking that framemd5 is same in order to be sure the lossless compression is really lossless), including the ones in this ticket, I'll post a message in this ticket when I finish and all files are well supported in FFmpeg. On 09/02/2018 11:39, Carl Eugen Hoyos wrote: > > Sorry, I thought you had access to such a sample and we would > just have to test it, no? I use to stay on a technical side, if the DPX header says alpha I map to alpha (no way to differentiate from an illegitimate content, technically speaking), whatever are the hacks used by users (my goal is to store content with FFV1 in order to save disk space then convert back to DPX when needed, so such hack are the user problem and are not visible by FFmpeg). Sometimes I have contact with the source provider, sometimes not. I think some of the files I get are hacked with infrared instead of alpha, if you are interested in a sample file with infrared-hacked content for sure I'll ask if it is the case for some files I have. But not blocking for the patch IMO (especially because the files I am thinking to are not 12-bit) > > One more minor issue: >> + } >> + else { > This is getting very common now (do you know why?), Different projects, different C style standards, so sometimes some mistakes when people work on several projects. (here, it was due to automatic edition from a code editor having a different standard by default, and I missed it when I reviewed the style) > please fix it. Fixed, updated patch attached. From 986379350bc788701e39e2d6f9fce55b61b5fbb8 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 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..7535de6c23 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];