From patchwork Tue May 2 14:29:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Carl Eugen Hoyos X-Patchwork-Id: 3550 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.3.129 with SMTP id 123csp1915201vsd; Tue, 2 May 2017 07:36:53 -0700 (PDT) X-Received: by 10.28.102.65 with SMTP id a62mr2386829wmc.29.1493735813355; Tue, 02 May 2017 07:36:53 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id i16si2809375wmf.67.2017.05.02.07.36.52; Tue, 02 May 2017 07:36:53 -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; 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=NONE 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 08B666883C1; Tue, 2 May 2017 17:36:46 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-io0-f174.google.com (mail-io0-f174.google.com [209.85.223.174]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 477B1680AB5 for ; Tue, 2 May 2017 17:36:39 +0300 (EEST) Received: by mail-io0-f174.google.com with SMTP id r16so161960966ioi.2 for ; Tue, 02 May 2017 07:36:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=mZxV49fLgo5fZ6ZI6UVi4N6iK927vpzk04GGYBArmJI=; b=g2OEILYDAqo40fyvfSLLXpmgorMz2uROjhk0SnBn/B7h4HPuyoA4Y4ITB2NwsKeCwT edZB9IUgflD2iFyjciPmwK7JYBYgMO0l1FFZ6MIReCbIMli3zCoKt7rwbiLMOuBFwWI7 KUciF8U07XhJKCKPqgg+sHB5OQJaqxQO+LJDUcS9M1z7+ZcifbKk+vG9i1Ii+omiQFbd +iPJunnsu+fpNkeP3Cw+5mOsEzR+PmbEHZWpP+0+QvmYUUkogAkjbTmcnn+Jjo611G9X MnN2Iq+a0wDykw0CbsgGMEC8xt2HFKtH1N0TgsRjxlNHSuRTtYrc60j/RfdTywcWZgz+ fHaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=mZxV49fLgo5fZ6ZI6UVi4N6iK927vpzk04GGYBArmJI=; b=NqA+56TDEuBczX6W4phrCCqzbLKdTB4PRM6BYxhuIhuaI2F8n6Bngc0AhjRsOuD2ie ZvtifRhRuqQFGHeUQpg8xn3afIxfKNISbHenLWfx92bJYzthj1JViJyNHjTpsnb7CE31 zHj8Q4eiiEO+Nij9ltDLvA/xM5KeVCNQYsguju9TWX6HwWlAZKHx4jTIhvq0MeV2Fzvk eOPai5ZpDFhPnpGEm8e2gJ9+L2sHX6+NYbH6JgU6llaiK3oG6tCeTK0p7busxJHPXBYQ uBUSmoNJaoRbImtNdg7bJdrPtbclS9hxtT75hFCcRO0VTBB62wbRDJPrVs/C2tB2HA29 vCBw== X-Gm-Message-State: AN3rC/6+r1Zy2X45CllbEn0OSJpKsqMt+Fl5w0zCzL8oVQnMtliGqBk4 fVBSPEejKYmHrmnhzxMnMCnDt6qNzQ== X-Received: by 10.107.142.201 with SMTP id q192mr29362997iod.138.1493735393496; Tue, 02 May 2017 07:29:53 -0700 (PDT) MIME-Version: 1.0 Received: by 10.79.116.211 with HTTP; Tue, 2 May 2017 07:29:32 -0700 (PDT) In-Reply-To: <20170502142152.GB2162332@phare.normalesup.org> References: <201705021614.58614.cehoyos@ag.or.at> <20170502142152.GB2162332@phare.normalesup.org> From: Carl Eugen Hoyos Date: Tue, 2 May 2017 16:29:32 +0200 Message-ID: To: FFmpeg development discussions and patches Subject: Re: [FFmpeg-devel] [PATCH]lavc/jpeg2000dec: Read resolution box from jp2 files 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" 2017-05-02 16:21 GMT+02:00 Nicolas George : > Le tridi 13 floréal, an CCXXV, Carl Eugen Hoyos a écrit : >> Attached patch allows reading the aspect ratio from jpeg2000 files. >> Kakadu allows to produce samples, the "aspect" is defined as the >> horizontal and vertical resolution as in tiff. > > Did you test what happens with this patch if you try to read two frames > with the same context (for example with the image2 demuxer), the first > frame has a non-square-pixels resolution defined and the second has no > resolution indication at all? > > The correct result would be to have a sample aspect ratio on the first > frame and not on the second. > > But with this code, since the first resolution is stored in the context > and never cleared, it looks like it will be kept for the remaining > images. New, fixed patch attached. (There also was another bug.) Thank you, Carl Eugen From 027d46030354c99ce496d299ff3c95e739ecdda2 Mon Sep 17 00:00:00 2001 From: Carl Eugen Hoyos Date: Tue, 2 May 2017 16:27:47 +0200 Subject: [PATCH] lavc/jpeg2000dec: Read the sample aspect ratio from the jp2 resolution box. --- libavcodec/jpeg2000dec.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c index e9f5f51..17ca257 100644 --- a/libavcodec/jpeg2000dec.c +++ b/libavcodec/jpeg2000dec.c @@ -26,6 +26,7 @@ */ #include +#include #include "libavutil/attributes.h" #include "libavutil/avassert.h" @@ -106,6 +107,7 @@ typedef struct Jpeg2000DecoderContext { int tile_width, tile_height; unsigned numXtiles, numYtiles; int maxtilelen; + AVRational sar; Jpeg2000CodingStyle codsty[4]; Jpeg2000QuantStyle qntsty[4]; @@ -1982,6 +1984,7 @@ static int jp2_find_codestream(Jpeg2000DecoderContext *s) atom2_end = bytestream2_tell(&s->g) + atom2_size - 8; if (atom2_size < 8 || atom2_end > atom_end || atom2_end < atom2_size) break; + atom2_size -= 8; if (atom2 == JP2_CODESTREAM) { return 1; } else if (atom2 == MKBETAG('c','o','l','r') && atom2_size >= 7) { @@ -2043,6 +2046,34 @@ static int jp2_find_codestream(Jpeg2000DecoderContext *s) if (cn < 4 && asoc < 4) s->cdef[cn] = asoc; } + } else if (atom2 == MKBETAG('r','e','s',' ') && atom2_size >= 18) { + int64_t vnum, vden, hnum, hden, vexp, hexp; + uint32_t resx; + bytestream2_skip(&s->g, 4); + resx = bytestream2_get_be32u(&s->g); + if (resx != MKBETAG('r','e','s','c') && resx != MKBETAG('r','e','s','d')) { + bytestream2_seek(&s->g, atom2_end, SEEK_SET); + continue; + } + vnum = bytestream2_get_be16u(&s->g); + vden = bytestream2_get_be16u(&s->g); + hnum = bytestream2_get_be16u(&s->g); + hden = bytestream2_get_be16u(&s->g); + vexp = bytestream2_get_byteu(&s->g); + hexp = bytestream2_get_byteu(&s->g); + if (vexp > hexp) { + vexp -= hexp; + hexp = 0; + } else { + hexp -= vexp; + vexp = 0; + } + if ( INT64_MAX / (hnum * vden) > pow(10, hexp) + && INT64_MAX / (vnum * hden) > pow(10, vexp)) + av_reduce(&s->sar.den, &s->sar.num, + hnum * vden * pow(10, hexp), + vnum * hden * pow(10, vexp), + INT32_MAX); } bytestream2_seek(&s->g, atom2_end, SEEK_SET); } while (atom_end - atom2_end >= 8); @@ -2125,6 +2156,9 @@ static int jpeg2000_decode_frame(AVCodecContext *avctx, void *data, if (s->avctx->pix_fmt == AV_PIX_FMT_PAL8) memcpy(picture->data[1], s->palette, 256 * sizeof(uint32_t)); + if (s->sar.num && s->sar.den) + avctx->sample_aspect_ratio = s->sar; + s->sar.num = s->sar.den = 0; return bytestream2_tell(&s->g); -- 1.7.10.4