From patchwork Mon Mar 19 09:47:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gagandeep Singh X-Patchwork-Id: 8037 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.1.70 with SMTP id c67csp2444739jad; Mon, 19 Mar 2018 02:55:35 -0700 (PDT) X-Google-Smtp-Source: AG47ELtXrq91whFeDCCDszTId9Qo5rr5xkJ/2OH6ChNfkm3P2sMfljfk0pVwoy1ayvcy9WZYW8my X-Received: by 10.223.210.73 with SMTP id o9mr9541785wri.248.1521453335195; Mon, 19 Mar 2018 02:55:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521453335; cv=none; d=google.com; s=arc-20160816; b=0WoYRg2DGwo7T1QgkVCUvHkQ6pneZwLpRz5oGsWK1hYUMvSg4RVUvjQfd8Z6uSSIeb g/FOfveo3+bzUEjPcUR6PUCufypQYdGoDeXbx8C3Qy7RwtFZlAjMRwgRzCmRzk+oCOyJ dgj74NCp6b1zbm1ux/6DvU3iodMFe3UYFSzTNPwL4ODdBJjjQ2S8tIddirRWKU1H/k2i qWj49mElvURm600vZPpOW0oIJaKxCbr76I7Cq0+RJteDJabpdcpF0PcjhT3Npjc7k/+0 ajQiiJlTzGD44zPWI43yn2ko6DkSx5ZNHHTnEoqtngyiz32WjGG2WW8l7sfvlmj8Bj/R bxOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:dkim-signature :delivered-to:arc-authentication-results; bh=x/g3MYw9sxToGE7BHGQZ6vLFpbIJts3/QIe6bK0J/6s=; b=m2J0LLRN2TsFv8nnu0Hspz+HNJGc93yWrHllf7ucK1yDZivPzgPzwXj0ikDUN+qC/H gK2QEnhs5LN0FoHP1KkH2xsL8ZLdhMUd6kYJWWkw7XRZM1FBYrghymNDHwPLSIY7pdi7 /dauUZxkWgoS7vjCoLUt5KBi6ZLFef14zFlcGFTYOn6hN19YilRnmtLclxE3wObCWk1m bP9Su/90HcwNnK6/ed8IW9uQ1vCy3Q7ESs1VjcccjqxRAfqvbRYr7QYerIdyaUz0WD1L /tyMo3+5DA80Y4V/IIb7hum7G0yx3zJ1au5Vr+0VlEjXhi7jwV/AsspEC2+1dbOb99Ps SVUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=fJinbjIC; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id v26si8072586wmc.83.2018.03.19.02.55.34; Mon, 19 Mar 2018 02:55:35 -0700 (PDT) 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; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=fJinbjIC; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E9D5C689C73; Mon, 19 Mar 2018 11:55:18 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-io0-f194.google.com (mail-io0-f194.google.com [209.85.223.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9AEAB680872 for ; Mon, 19 Mar 2018 11:55:11 +0200 (EET) Received: by mail-io0-f194.google.com with SMTP id r18so1222228ioa.1 for ; Mon, 19 Mar 2018 02:55:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=3GFtkyALUqjt5SQRiy7bV40wQj3j8XKlB/YFYLtBf+A=; b=fJinbjICanvgB5Q6NHwhS8WDGJNDTy6ez6hQEZixYOyIHbERA3n+Jeq7ycWNslTASk tDx2MLvkXREznXoEJ7v74OYXxpxLCIweiG8j5Itp2bk/7fHY+ivZz8dYgIvNPcrCWyBt dEUEm2d6CCqKYzNiUb8n4oB5d4UfuuX62OX6WJOePIkcRDtAEcxz8HwID3wN48bjjRHh SDRvX2vsSsM7y8xs2XiXsMSacc389sm8FXHB1sgZS+b7PhmxqXTax/vnEF5uHs2xubzN nZB78HgA3UWmefd5kJMZZP0QB7dP6Fk8014jVwYivgtO48ccISh1Qa4xtcoyVRAXFeRH 7D0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=3GFtkyALUqjt5SQRiy7bV40wQj3j8XKlB/YFYLtBf+A=; b=PLcYwWY93n7AZBXiimme/tdHwnKiio23qC5I3h4JjyyMjHOG5PLHFtQ54ml9p6JySB dF2PJiDBnfuwUGnbW7GDrTqZaApshl4hox4BUEnAhKn957ts4nv9eHgyKqZTbYmXJu6Q dt61psHJo6HzMpBuIKThBXcAU346kvqoEafBE4WjqF7+E5tsGTGLC9gOKXDyWmzSsUOd mknDHXYdDeQlVCxlw2wxgqc2I6XQsSC0CTUlhyzBEMqNi5KHh9VaTp4oG3OopTO/hMVv /vBJqrfPFRoGgN7mToqDeswfhbXuMrFpCoCIOhICsdbXIjXIV//5dAH4AgsPcG7nRz43 TQUg== X-Gm-Message-State: AElRT7F9hCU/RRLM51KrUUq4MmrauYOE/hGnCddYv334i0YZorD4IIwL EYdAKLWzbw8jFOhdk4JAVu30Z9JW X-Received: by 10.107.39.138 with SMTP id n132mr11427501ion.91.1521452921657; Mon, 19 Mar 2018 02:48:41 -0700 (PDT) Received: from localhost.localdomain ([2402:8100:20bf:93e5:6025:c00b:53d9:25f4]) by smtp.googlemail.com with ESMTPSA id n21sm8148451ioc.70.2018.03.19.02.48.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Mar 2018 02:48:41 -0700 (PDT) From: Gagandeep Singh To: ffmpeg-devel@ffmpeg.org Date: Mon, 19 Mar 2018 15:17:59 +0530 Message-Id: <20180319094759.31835-1-deepgagan231197@gmail.com> X-Mailer: git-send-email 2.14.1 Subject: [FFmpeg-devel] [FFmpeg][PATCH] lavc/cfhd: introduced interlaced using temporal horizontal transform 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 Cc: Gagandeep Singh MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" interlaced files require horizontal-temporal transform that has been added. Output is not satisfactory yet! --- libavcodec/cfhd.c | 137 +++++++++++++++++++++++++++++++++++++++++------------- libavcodec/cfhd.h | 3 +- 2 files changed, 107 insertions(+), 33 deletions(-) diff --git a/libavcodec/cfhd.c b/libavcodec/cfhd.c index a064cd1599..da0f0fadf6 100644 --- a/libavcodec/cfhd.c +++ b/libavcodec/cfhd.c @@ -46,6 +46,7 @@ enum CFHDParam { SubbandNumber = 48, Quantization = 53, ChannelNumber = 62, + Progressive = 68, BitsPerComponent = 101, ChannelWidth = 104, ChannelHeight = 105, @@ -83,6 +84,7 @@ static void init_frame_defaults(CFHDContext *s) s->wavelet_depth = 3; s->pshift = 1; s->codebook = 0; + s->progressive = 0; init_plane_defaults(s); } @@ -137,6 +139,43 @@ static inline void filter(int16_t *output, ptrdiff_t out_stride, } } +static inline void interlaced_vertical_filter(int16_t *output, int16_t *low, int16_t *high, + int width, int linesize, int plane) +{ + int i; + int even, odd; + for (i = 0; i < width; i++) { + even = (*low - *high)/2; + odd = (*low + *high)/2; + + even = FFMIN(even, 1023); + even = FFMAX(even, 0); + odd = FFMIN(odd, 1023); + odd = FFMAX(odd, 0); + + output[i] = even; + output[i + linesize] = odd; + low++; + high++; + } +} + +static inline void horiz_haar_filter(int16_t *output, int16_t *low, int16_t *high, + int width) +{ + int i; + int even, odd; + for (i = 0; i < width; i+=2) { + even = (*low - *high); + odd = (*low + *high); + + output[i] = even; + output[i + 1] =odd; + low++; + high++; + } +} + static void horiz_filter(int16_t *output, int16_t *low, int16_t *high, int width) { @@ -196,7 +235,8 @@ static int alloc_buffers(AVCodecContext *avctx) int width = i ? avctx->width >> chroma_x_shift : avctx->width; int height = i ? avctx->height >> chroma_y_shift : avctx->height; ptrdiff_t stride = FFALIGN(width / 8, 8) * 8; - if (chroma_y_shift) height = FFALIGN(height / 8, 2) * 8; + if (chroma_y_shift) + height = FFALIGN(height / 8, 2) * 8; s->plane[i].width = width; s->plane[i].height = height; s->plane[i].stride = stride; @@ -207,7 +247,6 @@ static int alloc_buffers(AVCodecContext *avctx) h4 = h8 * 2; w2 = w4 * 2; h2 = h4 * 2; - s->plane[i].idwt_buf = av_mallocz_array(height * stride, sizeof(*s->plane[i].idwt_buf)); s->plane[i].idwt_tmp = @@ -247,7 +286,6 @@ static int alloc_buffers(AVCodecContext *avctx) s->a_height = s->coded_height; s->a_width = s->coded_width; s->a_format = s->coded_format; - return 0; } @@ -277,6 +315,9 @@ static int cfhd_decode(AVCodecContext *avctx, void *data, int *got_frame, uint16_t data = bytestream2_get_be16(&gb); if (abs_tag8 >= 0x60 && abs_tag8 <= 0x6f) { av_log(avctx, AV_LOG_DEBUG, "large len %x\n", ((tagu & 0xff) << 16) | data); + } else if (tag == Progressive) { + av_log(avctx, AV_LOG_DEBUG, "Progressive? %"PRIu16"\n", 0x0001 & data); + s->progressive = 0x0001 & data; } else if (tag == ImageWidth) { av_log(avctx, AV_LOG_DEBUG, "Width %"PRIu16"\n", data); s->coded_width = data; @@ -757,7 +798,6 @@ static int cfhd_decode(AVCodecContext *avctx, void *data, int *got_frame, lowpass_height = s->plane[plane].band[2][1].height; lowpass_width = s->plane[plane].band[2][1].width; highpass_stride = s->plane[plane].band[2][1].stride; - if (lowpass_height > s->plane[plane].band[2][1].a_height || lowpass_width > s->plane[plane].band[2][1].a_width || !highpass_stride || s->plane[plane].band[2][1].width > s->plane[plane].band[2][1].a_width) { av_log(avctx, AV_LOG_ERROR, "Invalid plane dimensions\n"); @@ -766,36 +806,69 @@ static int cfhd_decode(AVCodecContext *avctx, void *data, int *got_frame, } av_log(avctx, AV_LOG_DEBUG, "Level 3 plane %i %i %i %i\n", plane, lowpass_height, lowpass_width, highpass_stride); + if (s->progressive) { + low = s->plane[plane].subband[0]; + high = s->plane[plane].subband[8]; + output = s->plane[plane].l_h[6]; + for (i = 0; i < lowpass_width; i++) { + vert_filter(output, lowpass_width, low, lowpass_width, high, highpass_stride, lowpass_height); + low++; + high++; + output++; + } + + low = s->plane[plane].subband[7]; + high = s->plane[plane].subband[9]; + output = s->plane[plane].l_h[7]; + for (i = 0; i < lowpass_width; i++) { + vert_filter(output, lowpass_width, low, highpass_stride, high, highpass_stride, lowpass_height); + low++; + high++; + output++; + } + + dst = (int16_t *)pic->data[act_plane]; + low = s->plane[plane].l_h[6]; + high = s->plane[plane].l_h[7]; + for (i = 0; i < lowpass_height * 2; i++) { + horiz_filter_clip(dst, low, high, lowpass_width, s->bpc); + low += lowpass_width; + high += lowpass_width; + dst += pic->linesize[act_plane] / 2; + } + } else { + av_log(avctx, AV_LOG_DEBUG, "interlaced frame ? %d", pic->interlaced_frame); + pic->interlaced_frame = 1; + low = s->plane[plane].subband[0]; + high = s->plane[plane].subband[7]; + output = s->plane[plane].l_h[6]; + for (i = 0; i < lowpass_height; i++) { + horiz_filter(output, low, high, lowpass_width); + low += lowpass_width; + high += lowpass_width; + output += lowpass_width * 2; + } - low = s->plane[plane].subband[0]; - high = s->plane[plane].subband[8]; - output = s->plane[plane].l_h[6]; - for (i = 0; i < lowpass_width; i++) { - vert_filter(output, lowpass_width, low, lowpass_width, high, highpass_stride, lowpass_height); - low++; - high++; - output++; - } - - low = s->plane[plane].subband[7]; - high = s->plane[plane].subband[9]; - output = s->plane[plane].l_h[7]; - for (i = 0; i < lowpass_width; i++) { - vert_filter(output, lowpass_width, low, highpass_stride, high, highpass_stride, lowpass_height); - low++; - high++; - output++; - } + low = s->plane[plane].subband[8]; + high = s->plane[plane].subband[9]; + output = s->plane[plane].l_h[7]; + for (i = 0; i < lowpass_height; i++) { + horiz_filter(output, low, high, lowpass_width); + low += lowpass_width; + high += lowpass_width; + output += lowpass_width * 2; + } - dst = (int16_t *)pic->data[act_plane]; - low = s->plane[plane].l_h[6]; - high = s->plane[plane].l_h[7]; - for (i = 0; i < lowpass_height * 2; i++) { - horiz_filter_clip(dst, low, high, lowpass_width, s->bpc); - low += lowpass_width; - high += lowpass_width; - dst += pic->linesize[act_plane] / 2; - } + dst = (int16_t *)pic->data[act_plane]; + low = s->plane[plane].l_h[6]; + high = s->plane[plane].l_h[7]; + for (i = 0; i < lowpass_height; i++) { + interlaced_vertical_filter(dst, low, high, lowpass_width * 2, pic->linesize[act_plane]/2, act_plane); + low += lowpass_width * 2; + high += lowpass_width * 2; + dst += pic->linesize[act_plane]; + } + } } diff --git a/libavcodec/cfhd.h b/libavcodec/cfhd.h index 2573e750a6..b17a88d07a 100644 --- a/libavcodec/cfhd.h +++ b/libavcodec/cfhd.h @@ -87,7 +87,8 @@ typedef struct CFHDContext { int a_width; int a_height; int a_format; - + int progressive; + int bpc; // bits per channel/component int channel_cnt; int subband_cnt;