From patchwork Mon Mar 19 06:45: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: 8036 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.1.70 with SMTP id c67csp2308019jad; Sun, 18 Mar 2018 23:51:20 -0700 (PDT) X-Google-Smtp-Source: AG47ELsYwDyl6rYGj0BO7dxQaisTJ2uTcVH8houFGyXdM/ibQoBHUOg92ihPwA69QxT/G3TA8jqs X-Received: by 10.223.135.115 with SMTP id 48mr1731678wrz.27.1521442280277; Sun, 18 Mar 2018 23:51:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521442280; cv=none; d=google.com; s=arc-20160816; b=lgVWHcBaxkSUS3De3hdfoHb8FvxUsTGockxcVH2tHo+X5JHnkUMMVuGM+Dc5MGzSUV 6aD7aJ0tYISp0x0h6ODsear9pJDlBji1zR5SadTMJHw7PXtpmGf3i1xSRHW5yc0H/c+b 4AoFLAQ9hWsFfOM6skIiVUtuEFg8b37ek0hD0bUxvVJICNYkCyR8FLJCwk51pkTe/V2d PfdEtVijHb4tNSfCVp+2aI5cqt0BwbB/K466Eg1Abw4nOs6hW/ZLWe9g7neO80CRhMqa hz8NvWZPRxYeDhhQ/db8EaOgc4pUjJjTzGRQBGAwBGaR+Twcq7I/KeyQczS5Z5YYmozC VVpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:to:message-id:date:from:mime-version :dkim-signature:delivered-to:arc-authentication-results; bh=K2ObmY3kpGcTm6nrlybf1Jt9Hgtbk6dmAEp+8broKy0=; b=a9i3K2ad/hEwE5cSIAXcFVwAEMD4q4FUq6cFQgjfG+3CPqT/2epzReSyT3tGM5knxj sCKWnhQhKlV86hWS49oTrA4juKGAxSeIUUNY3gHPJwf6uKKdkgUMwZBUZeY9bNDqS1i0 O5gI5D7I9HFh9l12PYy0IMfuwbogYWaTq3/W5py00rOBhQiIV3DN4mTfbjMa5DYCZblA uO/UEv9dKUOKmMpfKBRcrK1WZiibYeD013wbrZZZ28spiLF7pas05Mokvs9ekL3inmm/ 4Oej6yy/L6hT6n25MiB572OpXiMr/KCQEpJiAaXGdFDfbLJuhQLhEQoHgyF648ug9Eu4 8GsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=VCZPs8ui; 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 z46si9936998wrz.128.2018.03.18.23.51.18; Sun, 18 Mar 2018 23:51:20 -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=VCZPs8ui; 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 C910E687EC9; Mon, 19 Mar 2018 08:51:02 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-it0-f48.google.com (mail-it0-f48.google.com [209.85.214.48]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4737468041E for ; Mon, 19 Mar 2018 08:50:56 +0200 (EET) Received: by mail-it0-f48.google.com with SMTP id j137-v6so1909801ita.1 for ; Sun, 18 Mar 2018 23:51:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=eIjMSJ7U39zFg4cunAvudCT3/PspGraGjRVnx4XdJXM=; b=VCZPs8uisumZVBzlStp42ZsiI4vAayoOW5VjPHPR3+YpRujnr3o9Ui1Fc1Rp8Vhhm2 mHgjIlwRGS3hU7+69iFTeqic00Tp5QggBZJyrJxZEKR6OOhDUBhJT1cWRTSzF9KEY7fW yi9m8/8TT6pe9gj7XXwwXiICKO0u+Qky66Zu4ijQRGKWF+5AnlTL/CKS6QlpTf75RfZU 4ie1RxGszJdjO1i9ZD4sQUp5KU4YDZPotsKMUAWAI94RpSM7GCyXvK7wbGpZV0vaScdv 6+WIPT+kvkTQc/9xCpg2wQL9lzPJs9G82TmsrKeF/4pNviui1qnfae5XP4pxoJq6z3JI Oi6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=eIjMSJ7U39zFg4cunAvudCT3/PspGraGjRVnx4XdJXM=; b=oyA5M4Bc/Rh3qjrwl+DmMkemvGm56ZwfkpPfBrGncXwYMrlLqu0oWXT8t2Kq5GdLFG nEUzH1GnfCboyPryq0Ef099oQp2mSNwlLRxpJR9D4E8cVRnQ9dy/pjKqFJyd5x2jkX4s 0fuVcYDv/UN6WL+Og6rDWSbhIG6ksbzn11FxIJ0AZzYtlM1V64TnTxkELLP0tzabZ68+ kS4pFSPgUkkIavrtwRgSWSLjh1TfqETeHcRt0rH3PNHgEWlfM4hnikvWwfJP9glaBily MYsUX8qyod8s4ASN3qo2xEbHj6kH6rtKWvV7HYQgr7cLijpiXm5e/AlAChhItulriFAO Q6Bw== X-Gm-Message-State: AElRT7Fd2UC/XP967Spl7Bl99qcSFyJgGkwfCwYT9EtAEZdOG4dsdBqN NQcOCEEg4JD0piBNiHJTT0fIKUIlXo+DSpErCZVTlQ== X-Received: by 2002:a24:98d6:: with SMTP id n205-v6mr10992893itd.130.1521441959510; Sun, 18 Mar 2018 23:45:59 -0700 (PDT) MIME-Version: 1.0 Received: by 10.107.8.170 with HTTP; Sun, 18 Mar 2018 23:45:59 -0700 (PDT) From: Gagandeep Singh Date: Mon, 19 Mar 2018 12:15:59 +0530 Message-ID: To: FFmpeg development discussions and patches X-Content-Filtered-By: Mailman/MimeDel 2.1.20 Subject: Re: [FFmpeg-devel] [PATCH] lavc/cfhd: added interlaced frame 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 Sat, Mar 17, 2018 at 5:00 PM, Carl Eugen Hoyos wrote: > 2018-03-17 10:42 GMT+01:00, Gagandeep Singh : > > ticket #5522: interlaced frame required horizontal-temporal inverse > > transform. though the output is not satisfactory yet. > > > diff --git a/libavcodec/cfhd.c b/libavcodec/cfhd.c > > index a064cd1599..b17c7c1dc5 100644 > > --- a/libavcodec/cfhd.c > > +++ b/libavcodec/cfhd.c > > @@ -50,8 +50,11 @@ enum CFHDParam { > > ChannelWidth = 104, > > ChannelHeight = 105, > > PrescaleShift = 109, > > + Progressive = 68, > > I suspect this can be ordered better. > > > }; > > > > + > > + > > Please do not add random cosmetic changes to your patch. > > [...] > > > +static inline void interlaced_vertical_filter(int16_t *output, int16_t > > *low, int16_t *high, > > + int width, int linesize, int plane) > > +{ > > + int i; > > > + int16_t even, odd; > > Could the code be simplified by using an unsigned type? > Why not a standard type? > > > + for (i = 0; i < width; i++) { > > > + > > + > > Maybe you disagree, but these empty lines make > reading the code more difficult imo. > > > + even = (*low - *high)/2; > > + odd = (*low + *high)/2; > > + > > + if (even > 1023) even = 1023; > > + if (even < 0) even = 0; > > + if (odd > 1023) odd = 1023; > > + if (odd < 0) odd = 0; > > FFMIN / FFMAX > > [...] > > > + } > > + else { > > Please merge these lines. > > Thank you, Carl Eugen > libavcodec/cfhd.c | 107 +++++++++++++++++++++++++++++------------------------- 1 file changed, 58 insertions(+), 49 deletions(-) output[i + linesize] = odd; @@ -163,6 +159,23 @@ static inline void interlaced_vertical_filter(int16_t *output, int16_t *low, int 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) { @@ -222,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; @@ -233,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 = @@ -273,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; } @@ -304,8 +316,8 @@ static int cfhd_decode(AVCodecContext *avctx, void *data, int *got_frame, 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", data); - s->progressive = data; + 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; @@ -786,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"); @@ -825,41 +836,39 @@ static int cfhd_decode(AVCodecContext *avctx, void *data, int *got_frame, 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; - } + } 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[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; - } + 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; 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]; - } - } + 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.c b/libavcodec/cfhd.c index b17c7c1dc5..57e0042d01 100644 --- a/libavcodec/cfhd.c +++ b/libavcodec/cfhd.c @@ -46,15 +46,13 @@ enum CFHDParam { SubbandNumber = 48, Quantization = 53, ChannelNumber = 62, + Progressive = 68, BitsPerComponent = 101, ChannelWidth = 104, ChannelHeight = 105, PrescaleShift = 109, - Progressive = 68, }; - - static av_cold int cfhd_init(AVCodecContext *avctx) { CFHDContext *s = avctx->priv_data; @@ -145,17 +143,15 @@ static inline void interlaced_vertical_filter(int16_t *output, int16_t *low, int int width, int linesize, int plane) { int i; - int16_t even, odd; + int even, odd; for (i = 0; i < width; i++) { - - even = (*low - *high)/2; odd = (*low + *high)/2; - if (even > 1023) even = 1023; - if (even < 0) even = 0; - if (odd > 1023) odd = 1023; - if (odd < 0) odd = 0; + even = FFMIN(even, 1023); + even = FFMAX(even, 0); + odd = FFMIN(odd, 1023); + odd = FFMAX(odd, 0); output[i] = even;