From patchwork Sun Dec 2 17:06:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 11253 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 D80FD44DD23 for ; Sun, 2 Dec 2018 19:13:35 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 76EA268A164; Sun, 2 Dec 2018 19:13:36 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 27DB568A151 for ; Sun, 2 Dec 2018 19:13:30 +0200 (EET) Received: by mail-wr1-f50.google.com with SMTP id c14so9791145wrr.0 for ; Sun, 02 Dec 2018 09:13:37 -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=mQzNUR0MBYa7Yki4g7AmNfHi/+5cx0ZFPAl9m/6fr7w=; b=VJsH7nFMvZjFFcJxwlEy0gV3dtxpKBD+arAafl4EsLeItl9vxYOfZ9/TijurwZSo80 vnbxlIC+HXgx5d+8fQqiI+ucs2+7vBYDvt7sMinc5+KIb+8u1Cn0NGaBMHMAOFLLQ/Wt XfTLAlSZ7vw5BaAbL8wNP1zns143fsi1ZQjcax8F0gdwuotI0gfgf8k//bwLZ8P3FdWL v2CvyP/HK0ojwhIlX1mnxHO3nwoCnWIa4oSykBCI4xCjuYtpAPfnDnxu4Ok+jXrwNsMp LnB2n0K1rD1Fsi6TUcpkwVArGVitjdj9/X8zORNSFk+U67ujFUGGQccUBJa8BtMa9kN3 KJWA== 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=mQzNUR0MBYa7Yki4g7AmNfHi/+5cx0ZFPAl9m/6fr7w=; b=YteZEfj1tiZWVF5TIRoF1Ja7Gh+1oeaS/Pg2j6FjWZdA8oUEcZP38qfYqkTiqJ7zvR hjkfoyBk0Rody4NM2OENEfVJh6IG0K8GqBK+2zUqQQGsTo2sBrRkfVBREHvd3J1rIGRt cGr188KdSGZL7c0xy4EX1nmPOMbCJF00kDhRO0aa3WIhgl7JNNPRrFhF4OLhur6DEQLL fwkSPixWDsLvnG7+sncWpyicvB9Wb0wKpkidUQS0LkmLEIWhGfJ2STwX/Kp2M0BPOkuO 8ZVNU0nolWuWyUJlmfyIpubyprL1uCSYQDu8Ta/l3roEZoyNXaXV8x99YqPpshtSQkq5 M95A== X-Gm-Message-State: AA+aEWaFon4ef2oew8oAmvVCYp3pxRbBxFf7Apfc8NflxJHoZgBXs3M2 fOgbMDz0Y2LnNMDZ+QEA4lkziZNk X-Google-Smtp-Source: AFSGD/WyQbcLgv7m47LG52bN88wPNTrltRGgfPFf3cGT9h9/bbioZ8yEjpOHH5WdfIbO1tJRbhjUWw== X-Received: by 2002:a5d:4f10:: with SMTP id c16mr11779283wru.177.1543770428329; Sun, 02 Dec 2018 09:07:08 -0800 (PST) Received: from localhost.localdomain ([94.250.174.60]) by smtp.gmail.com with ESMTPSA id h62sm3907957wmf.11.2018.12.02.09.07.06 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 02 Dec 2018 09:07:07 -0800 (PST) From: Paul B Mahol To: ffmpeg-devel@ffmpeg.org Date: Sun, 2 Dec 2018 18:06:56 +0100 Message-Id: <20181202170656.21203-1-onemda@gmail.com> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH] avcodec/r210: use correct pixel format 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/r210dec.c | 38 ++++++++++++++++++----------------- libavcodec/r210enc.c | 26 +++++++++++++++--------- tests/ref/vsynth/vsynth1-r210 | 6 +++--- tests/ref/vsynth/vsynth2-r210 | 6 +++--- tests/ref/vsynth/vsynth3-r210 | 6 +++--- 5 files changed, 45 insertions(+), 37 deletions(-) diff --git a/libavcodec/r210dec.c b/libavcodec/r210dec.c index dbc94c76bd..22b95e9092 100644 --- a/libavcodec/r210dec.c +++ b/libavcodec/r210dec.c @@ -27,11 +27,7 @@ static av_cold int decode_init(AVCodecContext *avctx) { - if ((avctx->codec_tag & 0xFFFFFF) == MKTAG('r', '1', '0', 0)) { - avctx->pix_fmt = AV_PIX_FMT_BGR48; - } else { - avctx->pix_fmt = AV_PIX_FMT_RGB48; - } + avctx->pix_fmt = AV_PIX_FMT_GBRP10; avctx->bits_per_raw_sample = 10; return 0; @@ -45,7 +41,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, const uint32_t *src = (const uint32_t *)avpkt->data; int aligned_width = FFALIGN(avctx->width, avctx->codec_id == AV_CODEC_ID_R10K ? 1 : 64); - uint8_t *dst_line; + uint8_t *g_line, *b_line, *r_line; int r10 = (avctx->codec_tag & 0xFFFFFF) == MKTAG('r', '1', '0', 0); int le = avctx->codec_tag == MKTAG('R', '1', '0', 'k') && avctx->extradata_size >= 12 && !memcmp(&avctx->extradata[4], "DpxE", 4) && @@ -61,10 +57,14 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, pic->pict_type = AV_PICTURE_TYPE_I; pic->key_frame = 1; - dst_line = pic->data[0]; + g_line = pic->data[0]; + b_line = pic->data[1]; + r_line = pic->data[2]; for (h = 0; h < avctx->height; h++) { - uint16_t *dst = (uint16_t *)dst_line; + uint16_t *dstg = (uint16_t *)g_line; + uint16_t *dstb = (uint16_t *)b_line; + uint16_t *dstr = (uint16_t *)r_line; for (w = 0; w < avctx->width; w++) { uint32_t pixel; uint16_t r, g, b; @@ -74,20 +74,22 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, pixel = av_be2ne32(*src++); } if (avctx->codec_id == AV_CODEC_ID_R210 || r10) { - b = pixel << 6; - g = (pixel >> 4) & 0xffc0; - r = (pixel >> 14) & 0xffc0; + b = pixel & 0x3ff; + g = (pixel >> 10) & 0x3ff; + r = (pixel >> 20) & 0x3ff; } else { - b = (pixel << 4) & 0xffc0; - g = (pixel >> 6) & 0xffc0; - r = (pixel >> 16) & 0xffc0; + b = (pixel >> 2) & 0x3ff; + g = (pixel >> 12) & 0x3ff; + r = (pixel >> 22) & 0x3ff; } - *dst++ = r | (r >> 10); - *dst++ = g | (g >> 10); - *dst++ = b | (b >> 10); + *dstr++ = r; + *dstg++ = g; + *dstb++ = b; } src += aligned_width - avctx->width; - dst_line += pic->linesize[0]; + g_line += pic->linesize[0]; + b_line += pic->linesize[1]; + r_line += pic->linesize[2]; } *got_frame = 1; diff --git a/libavcodec/r210enc.c b/libavcodec/r210enc.c index a55e5434f3..02412f3684 100644 --- a/libavcodec/r210enc.c +++ b/libavcodec/r210enc.c @@ -43,22 +43,26 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, int aligned_width = FFALIGN(avctx->width, avctx->codec_id == AV_CODEC_ID_R10K ? 1 : 64); int pad = (aligned_width - avctx->width) * 4; - uint8_t *src_line; + uint8_t *srcr_line, *srcg_line, *srcb_line; uint8_t *dst; if ((ret = ff_alloc_packet2(avctx, pkt, 4 * aligned_width * avctx->height, 0)) < 0) return ret; - src_line = pic->data[0]; + srcg_line = pic->data[0]; + srcb_line = pic->data[1]; + srcr_line = pic->data[2]; dst = pkt->data; for (i = 0; i < avctx->height; i++) { - uint16_t *src = (uint16_t *)src_line; + uint16_t *srcr = (uint16_t *)srcr_line; + uint16_t *srcg = (uint16_t *)srcg_line; + uint16_t *srcb = (uint16_t *)srcb_line; for (j = 0; j < avctx->width; j++) { uint32_t pixel; - uint16_t r = *src++ >> 6; - uint16_t g = *src++ >> 6; - uint16_t b = *src++ >> 6; + uint16_t r = *srcr++; + uint16_t g = *srcg++; + uint16_t b = *srcb++; if (avctx->codec_id == AV_CODEC_ID_R210) pixel = (r << 20) | (g << 10) | b; else @@ -70,7 +74,9 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, } memset(dst, 0, pad); dst += pad; - src_line += pic->linesize[0]; + srcr_line += pic->linesize[2]; + srcg_line += pic->linesize[0]; + srcb_line += pic->linesize[1]; } pkt->flags |= AV_PKT_FLAG_KEY; @@ -87,7 +93,7 @@ AVCodec ff_r210_encoder = { .id = AV_CODEC_ID_R210, .init = encode_init, .encode2 = encode_frame, - .pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_RGB48, AV_PIX_FMT_NONE }, + .pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_GBRP10, AV_PIX_FMT_NONE }, .capabilities = AV_CODEC_CAP_INTRA_ONLY, }; #endif @@ -99,7 +105,7 @@ AVCodec ff_r10k_encoder = { .id = AV_CODEC_ID_R10K, .init = encode_init, .encode2 = encode_frame, - .pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_RGB48, AV_PIX_FMT_NONE }, + .pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_GBRP10, AV_PIX_FMT_NONE }, .capabilities = AV_CODEC_CAP_INTRA_ONLY, }; #endif @@ -111,7 +117,7 @@ AVCodec ff_avrp_encoder = { .id = AV_CODEC_ID_AVRP, .init = encode_init, .encode2 = encode_frame, - .pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_RGB48, AV_PIX_FMT_NONE }, + .pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_GBRP10, AV_PIX_FMT_NONE }, .capabilities = AV_CODEC_CAP_INTRA_ONLY, }; #endif diff --git a/tests/ref/vsynth/vsynth1-r210 b/tests/ref/vsynth/vsynth1-r210 index 825e1d4789..1103308060 100644 --- a/tests/ref/vsynth/vsynth1-r210 +++ b/tests/ref/vsynth/vsynth1-r210 @@ -1,4 +1,4 @@ -1ea72f280b110ed65fc535c3438d27f9 *tests/data/fate/vsynth1-r210.avi +1a522a30ddd8c2865a731a5659001717 *tests/data/fate/vsynth1-r210.avi 22125252 tests/data/fate/vsynth1-r210.avi -ecaafa9eec11b5e1453a63ed6d194eed *tests/data/fate/vsynth1-r210.out.rawvideo -stddev: 3.23 PSNR: 37.94 MAXDIFF: 48 bytes: 7603200/ 7603200 +b6444935d6c4d8c75fe63d5978f5b457 *tests/data/fate/vsynth1-r210.out.rawvideo +stddev: 3.73 PSNR: 36.68 MAXDIFF: 48 bytes: 7603200/ 7603200 diff --git a/tests/ref/vsynth/vsynth2-r210 b/tests/ref/vsynth/vsynth2-r210 index dc5ff1849c..5efd87d6f5 100644 --- a/tests/ref/vsynth/vsynth2-r210 +++ b/tests/ref/vsynth/vsynth2-r210 @@ -1,4 +1,4 @@ -2f928096d892ce0239832afc369e117c *tests/data/fate/vsynth2-r210.avi +9a27c0c96f9e658d610d2590b61416a1 *tests/data/fate/vsynth2-r210.avi 22125252 tests/data/fate/vsynth2-r210.avi -2ade5f6167d7a4a1589e168ddbbc35d0 *tests/data/fate/vsynth2-r210.out.rawvideo -stddev: 1.17 PSNR: 46.71 MAXDIFF: 15 bytes: 7603200/ 7603200 +d43196c64fd611f6e9c046e0ef3e570e *tests/data/fate/vsynth2-r210.out.rawvideo +stddev: 1.37 PSNR: 45.34 MAXDIFF: 14 bytes: 7603200/ 7603200 diff --git a/tests/ref/vsynth/vsynth3-r210 b/tests/ref/vsynth/vsynth3-r210 index 75c424cf28..253657cd85 100644 --- a/tests/ref/vsynth/vsynth3-r210 +++ b/tests/ref/vsynth/vsynth3-r210 @@ -1,4 +1,4 @@ -229e700e0fab4e81481e99a70e00bec9 *tests/data/fate/vsynth3-r210.avi +fd12f6dde75d0872ccf9012b342208de *tests/data/fate/vsynth3-r210.avi 442052 tests/data/fate/vsynth3-r210.avi -e1d882babc8754f7418aa91ce48f7ab0 *tests/data/fate/vsynth3-r210.out.rawvideo -stddev: 3.48 PSNR: 37.28 MAXDIFF: 42 bytes: 86700/ 86700 +a2c4e460ebede1109bd794b1b7b05a1f *tests/data/fate/vsynth3-r210.out.rawvideo +stddev: 4.10 PSNR: 35.87 MAXDIFF: 48 bytes: 86700/ 86700