From patchwork Thu Oct 10 00:11:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Skakov Pavel X-Patchwork-Id: 15644 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 609B844A130 for ; Thu, 10 Oct 2019 03:11:47 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 40A9568812E; Thu, 10 Oct 2019 03:11:47 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C4DFA687EB8 for ; Thu, 10 Oct 2019 03:11:40 +0300 (EEST) Received: by mail-lf1-f49.google.com with SMTP id w67so2971814lff.4 for ; Wed, 09 Oct 2019 17:11:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:references:message-id:date:user-agent:mime-version :in-reply-to:content-language; bh=ppDKUUiA/B8YLtPHI7+StI3a3047rMRQyJV8VQBtzWs=; b=SZXXos/ThC/So/dEoPI9qiZfzbVJqhUKZLWwXVtklcMWCBptcAHo9Ajck61IWNS0ZI 1m1JF3fxSLm+cdm2W7QBPk+7nlZUVtF2Zo2BVxgXoJlXBRwUD/ascwDJ59dQ0TTSL1PA AV+OFkCTeOaLuoyt5cu3dmHpzUcV0xqPeCujw1toK0wODEsJCrzUHH8PNaFP0LBvhYgf ORYbOBxB4PZ3YtTwHOfC69hVAsrym/8xAG3xWk8PhlvfLSsYxf8FdjXZWss/G/zg/aSd VMvSNvcjZDR9esZ2WX3Y02O1/8jP7p8f8aFFEMJbcuBY2/IzmIbEUxC10GiXddP0Zw3/ EGfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:references:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=ppDKUUiA/B8YLtPHI7+StI3a3047rMRQyJV8VQBtzWs=; b=eMG2BXacvtSNllB+jm6UJlHZ71Gp3bHrGSW0/hnE/dUVCKice5YGikgcslDVWyp8ra zLr0Y81YKn36X0g/iQVPAdlxh3nhqceNP81xt9WfAu+lv7/TqjB69BAgN+Rk2EeqS5ej Q1+p9aRsyuW9LiIBlizHb8Tr5p5euzsMYVwBsylWiOR+PrdqsPLTki0PFkOoDR/d6eoT rlx4PQdQqDQ/bnMPFjpyBuQ4XBAM0hA9vsrfAMFs/LmSwS0/uMhftYduRde4Mvz17GR0 XDAG7zoNgXOmvRtmoMLYXrNQkdKtYSIUzTDASZqtMYnnDRBenf9E0lgjOASHLKDFw3ri 14mQ== X-Gm-Message-State: APjAAAXsGqYqdo3Fdty84GDNHPDMD3MoSfye+8BmXmLBLkdFJYYOaSvJ JnlnXUKGnXHKzduYlp+zC1BmZZnh X-Google-Smtp-Source: APXvYqy86Yu0bXXejv3YgAMZX5BlWInmN19sK0HmZcPe06InGHL7TSMzjOX7SHmZEHc2DdJNf6UhQQ== X-Received: by 2002:ac2:4904:: with SMTP id n4mr3513708lfi.179.1570666299885; Wed, 09 Oct 2019 17:11:39 -0700 (PDT) Received: from [10.1.0.176] ([5.18.248.33]) by smtp.gmail.com with ESMTPSA id f22sm802580lfk.56.2019.10.09.17.11.38 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 Oct 2019 17:11:39 -0700 (PDT) From: Skakov Pavel To: FFmpeg development discussions and patches References: <5bb1e2e7-faf8-7244-b48b-9bc21842b010@gmail.com> Message-ID: <9646f429-96af-2f2e-775c-234c363cc3d7@gmail.com> Date: Thu, 10 Oct 2019 03:11:38 +0300 User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <5bb1e2e7-faf8-7244-b48b-9bc21842b010@gmail.com> Content-Language: en-US Subject: [FFmpeg-devel] [PATCH v2 2/4] avcodec/tiff: add support for 16-bit YUV images 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" Added support for 16-bit per sample YUV formats. This would allow ffmpeg to losslessly save (later) and load subsampled 10/16-bit YUV frames in simple and somewhat standard format. Formats that don't currently have ffmpeg support but would work if such support appears are left commented out (YUV440P16/YUV411P16/YUV410P16). From 529a3e68a74bf7bde67cf9c4defdf4504efbd2ce Mon Sep 17 00:00:00 2001 From: Pavel Skakov Date: Thu, 10 Oct 2019 02:31:20 +0300 Subject: [PATCH 2/4] avcodec/tiff: add support for 16-bit YUV images Signed-off-by: Pavel Skakov --- libavcodec/tiff.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c index 70c49f7d44..eac5113ad7 100644 --- a/libavcodec/tiff.c +++ b/libavcodec/tiff.c @@ -366,6 +366,7 @@ static void unpack_yuv(TiffContext *s, AVFrame *p, uint8_t *pu = &p->data[1][lnum / s->subsampling[1] * p->linesize[1]]; uint8_t *pv = &p->data[2][lnum / s->subsampling[1] * p->linesize[2]]; if (s->width % s->subsampling[0] || s->height % s->subsampling[1]) { + if (s->bpp == 24) { for (i = 0; i < w; i++) { for (j = 0; j < s->subsampling[1]; j++) for (k = 0; k < s->subsampling[0]; k++) @@ -377,7 +378,24 @@ static void unpack_yuv(TiffContext *s, AVFrame *p, *pu++ = *src++; *pv++ = *src++; } + } else { + for (i = 0; i < w; i++) { + for (j = 0; j < s->subsampling[1]; j++) + for (k = 0; k < s->subsampling[0]; k++) + if (j < s->height - lnum && i * s->subsampling[0] + k < s->width) { + p->data[0][(lnum + j) * p->linesize[0] + (i * s->subsampling[0] + k)*2 ] = *src++; + p->data[0][(lnum + j) * p->linesize[0] + (i * s->subsampling[0] + k)*2 + 1] = *src++; + } else { + src += 2; + } + *pu++ = *src++; + *pu++ = *src++; + *pv++ = *src++; + *pv++ = *src++; + } + } }else{ + if (s->bpp == 24) { for (i = 0; i < w; i++) { for (j = 0; j < s->subsampling[1]; j++) for (k = 0; k < s->subsampling[0]; k++) @@ -386,6 +404,19 @@ static void unpack_yuv(TiffContext *s, AVFrame *p, *pu++ = *src++; *pv++ = *src++; } + } else { + for (i = 0; i < w; i++) { + for (j = 0; j < s->subsampling[1]; j++) + for (k = 0; k < s->subsampling[0]; k++) { + p->data[0][(lnum + j) * p->linesize[0] + (i * s->subsampling[0] + k)*2 ] = *src++; + p->data[0][(lnum + j) * p->linesize[0] + (i * s->subsampling[0] + k)*2 + 1] = *src++; + } + *pu++ = *src++; + *pu++ = *src++; + *pv++ = *src++; + *pv++ = *src++; + } + } } } @@ -588,8 +619,9 @@ static int tiff_unpack_strip(TiffContext *s, AVFrame *p, uint8_t *dst, int strid width = (s->width - 1) / s->subsampling[0] + 1; width = width * s->subsampling[0] * s->subsampling[1] + 2*width; + width *= s->bpp/24; av_assert0(width <= bytes_per_row); - av_assert0(s->bpp == 24); + av_assert0(s->bpp == 24 || s->bpp == 48); } if (s->is_bayer) { width = (s->bpp * s->width + 7) >> 3; @@ -1145,7 +1177,26 @@ static int init_image(TiffContext *s, ThreadFrame *frame) } break; case 483: + if (s->photometric == TIFF_PHOTOMETRIC_YCBCR) { + if (s->subsampling[0] == 1 && s->subsampling[1] == 1) { + s->avctx->pix_fmt = s->le ? AV_PIX_FMT_YUV444P16LE : AV_PIX_FMT_YUV444P16BE; + } else if (s->subsampling[0] == 2 && s->subsampling[1] == 1) { + s->avctx->pix_fmt = s->le ? AV_PIX_FMT_YUV422P16LE : AV_PIX_FMT_YUV422P16BE; + } else if (s->subsampling[0] == 2 && s->subsampling[1] == 2) { + s->avctx->pix_fmt = s->le ? AV_PIX_FMT_YUV420P16LE : AV_PIX_FMT_YUV420P16BE; + //} else if (s->subsampling[0] == 1 && s->subsampling[1] == 2) { + // s->avctx->pix_fmt = s->le ? AV_PIX_FMT_YUV440P16LE : AV_PIX_FMT_YUV440P16BE; + //} else if (s->subsampling[0] == 4 && s->subsampling[1] == 1) { + // s->avctx->pix_fmt = s->le ? AV_PIX_FMT_YUV411P16LE : AV_PIX_FMT_YUV411P16BE; + //} else if (s->subsampling[0] == 4 && s->subsampling[1] == 4) { + // s->avctx->pix_fmt = s->le ? AV_PIX_FMT_YUV410P16LE : AV_PIX_FMT_YUV410P16BE; + } else { + av_log(s->avctx, AV_LOG_ERROR, "Unsupported YCbCr subsampling\n"); + return AVERROR_PATCHWELCOME; + } + } else { s->avctx->pix_fmt = s->le ? AV_PIX_FMT_RGB48LE : AV_PIX_FMT_RGB48BE; + } break; case 644: s->avctx->pix_fmt = s->le ? AV_PIX_FMT_RGBA64LE : AV_PIX_FMT_RGBA64BE; -- 2.13.2.windows.1