From patchwork Sat Apr 25 17:26:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carl Eugen Hoyos X-Patchwork-Id: 19237 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 2DA2D4494DE for ; Sat, 25 Apr 2020 20:26:29 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EF5A568C48F; Sat, 25 Apr 2020 20:26:28 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-io1-f42.google.com (mail-io1-f42.google.com [209.85.166.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 012F768C407 for ; Sat, 25 Apr 2020 20:26:21 +0300 (EEST) Received: by mail-io1-f42.google.com with SMTP id p10so14120945ioh.7 for ; Sat, 25 Apr 2020 10:26:21 -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=mDLIPOtWscBSvzBGcA+mukL82jyopeuVvjp84xxngXU=; b=HAFYkHzrpBGCQ7c6VmtXPbEa8cl7PqaKJou5XLLgG0eIfWm42ycrO+5q6CABVovSCG zrjHwLrLtoxAwkTWwgFjWjfQb4qoHDWCbcDD84cf/Rn6r3PR9vSrMJYuijHx3OG0JRCO 5EPWib9iuix6ebw9O7Z5zNL93VGJLF0dkOnS3Y3RuG4xqXmekjghjhSn639jX6015GVA W5ZBKhpHi0wcnXmhafzf3VbH71JdPXE5QPx4ZVc3882jjYJumzaFNR46osdfmGgFfTuR f+aMo4cAkyMwscq6uvOhhS/3KMlFlPmx/XC8VyzEBCjqIDy8TLQVkoNqJ8M2Fci7d6JA xNCw== 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=mDLIPOtWscBSvzBGcA+mukL82jyopeuVvjp84xxngXU=; b=UcMiK8uNS0p5RyovoA6T02fW6VINVIKtaMnCeSVQfc7C0uehg5HWBTCP13EX37xgj5 T9JNCtyk769A+7vXsiJlyJLKhoNgpaJTfOBnpHoisn8BccyiF5Nrz50C7/8MsSACmY0Y hecyABg5UCl0IdOeQ9ZxuTKCuYM663upi/yWRFj1bs59778iznZDRLJlY5gB6HLo75BM KJ1oh49LoWLCcftDcmBy+11UJDlpljERaSvORwCzAjaGznb3JiZmXIihNicHTTrFjczD XZMPBNjvfuUi2ceA/zHVEwgiUn52cqWRUR/gzhCEyD2/0aC4LvgQe8OEBnbY6X4jpZ/2 9u3g== X-Gm-Message-State: AGi0PuZQITWR5CpXDLWEkXqfi5RtNyXETy2o5PZHSzz1jrETNAml7lFX SlUjVhhHAXU3BX86IhGv/YkibHHtsBQfsZMPLkbl5nCL1Do= X-Google-Smtp-Source: APiQypI1vClJSqzLfgACjaTA1bQJx4L1LU7EPrP2stFnyVreM0ydrBaieg3qyGmyQXxsVX0ycbqUMbPcd9fH5nMd3xw= X-Received: by 2002:a02:8247:: with SMTP id q7mr12813831jag.68.1587835580108; Sat, 25 Apr 2020 10:26:20 -0700 (PDT) MIME-Version: 1.0 From: Carl Eugen Hoyos Date: Sat, 25 Apr 2020 19:26:08 +0200 Message-ID: To: FFmpeg development discussions and patches Subject: [FFmpeg-devel] [PATCH]lavc/jpeg2000dec: Scale 4-7bit output to 8 bits 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" Hi! Attached patch makes the output of the reference sample p0_03.j2k bit-exact with opj_decompress and kdu_render and more similar to jasper's output. Please comment, Carl Eugen From de80453a8decd95b4a71cea71b20ba0bd74485cb Mon Sep 17 00:00:00 2001 From: Carl Eugen Hoyos Date: Sat, 25 Apr 2020 18:31:22 +0200 Subject: [PATCH] lavc/jpeg2000dec: Scale 4-7 bit output to 8 bits. Makes p0_03.j2k output bitexact with opj_decompress and kdu_render and more similar with the output of jasper. --- libavcodec/jpeg2000dec.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c index 460a4ad95c..8d7c729530 100644 --- a/libavcodec/jpeg2000dec.c +++ b/libavcodec/jpeg2000dec.c @@ -1938,7 +1938,9 @@ static inline void tile_codeblocks(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile int val = lrintf(*datap) + (1 << (cbps - 1)); \ /* DC level shift and clip see ISO 15444-1:2002 G.1.2 */ \ val = av_clip(val, 0, (1 << cbps) - 1); \ - *dst = val << (precision - cbps); \ + *dst = val << ((precision < 8 ? 8 : precision) - cbps); \ + if (precision < 8) \ + *dst |= *dst >> (8 - precision); \ datap++; \ dst += pixelsize; \ } \ @@ -1947,7 +1949,9 @@ static inline void tile_codeblocks(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile int val = *i_datap + (1 << (cbps - 1)); \ /* DC level shift and clip see ISO 15444-1:2002 G.1.2 */ \ val = av_clip(val, 0, (1 << cbps) - 1); \ - *dst = val << (precision - cbps); \ + *dst = val << ((precision < 8 ? 8 : precision) - cbps); \ + if (precision < 8) \ + *dst |= *dst >> (8 - precision); \ i_datap++; \ dst += pixelsize; \ } \ @@ -1989,7 +1993,7 @@ static int jpeg2000_decode_tile(AVCodecContext *avctx, void *td, } if (s->precision <= 8) { - write_frame_8(s, tile, picture, 8); + write_frame_8(s, tile, picture, s->precision); } else { int precision = picture->format == AV_PIX_FMT_XYZ12 || picture->format == AV_PIX_FMT_RGB48 || -- 2.24.1