From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 74534441C1 for ; Tue, 1 Nov 2022 02:16:21 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 15A6C68BE56; Tue, 1 Nov 2022 04:16:18 +0200 (EET) Received: from mail-ed1-f50.google.com (mail-ed1-f50.google.com [209.85.208.50]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C5EBF68BD7E for ; Tue, 1 Nov 2022 04:16:11 +0200 (EET) Received: by mail-ed1-f50.google.com with SMTP id a5so19940591edb.11 for ; Mon, 31 Oct 2022 19:16:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=55j/Z0jmPoQ3Jp7+17QcwyceAEgs0Ppm5FWGnfJX8mw=; b=CquHaJD+igDTzVC4R++EDK4h6fxTA2Au30mD6zsPuJeemFYKTcIU0V78gZ5c0TwHHV zjjmhRYlcgAscmK7yz7TdotKohLlVcoerXGhCMci52NU4I+uX+EcgQO2XOuJ9S+ln8s2 OfJ7UZ/WFI5LX6qFrOL37YLec3l85lIILF3PQySSqKy8GpjZyt+L+zGDVKTDN0ayzG17 5zWVs7EJ4pkeQBI4JPczR25bLQ8MVeUGAFAwm2Q7RvpCj/vF1HiCubXc2NoHB5LqoIT/ WSu6lSit5Fl9IW+R+UE7ifdx21ZGOqu8GRJJvkepOkF613QqTbK4Af4y/RPD0f0R0xq1 mTmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=55j/Z0jmPoQ3Jp7+17QcwyceAEgs0Ppm5FWGnfJX8mw=; b=7nlpkkKf4yqYyWTCLMChPXFnBVzQqmyj6ndSuip1CtduKa3uX5TGYKjqLQvrKMK0Pw P0QuyFwhHKIUgfpKFuBQcCOPM6VAddNDBJXrqhAZ4Hj6XcasbbZqC9CM/jjihSlw3mze 4SZR17SU8jWZqQu6a8QBpWQ474sANJ9wOD7GcsfWvNDU2m3ahrZUyL6E48GU3pHAMjbR RSxXpanaVRLnobwVD4zSDCwCiWbYtGV+SboTJgNsNCJzXAt2XOQ94IH7X5RKtYgBRu14 7Ss3IK/bkx4vJ3R72Hj3MXX4tg0z/Lx0TMZYfOaaYV4xiktvykAj0w8mdntvI3EtsXRT 7KxA== X-Gm-Message-State: ACrzQf3vkxd9dSVmjUexrFLSUhu1pDzngL8DkJ6BWRbHlI6YCS5twpmD 4m+4NwaCZ9pL5br9JHzrJRInD94WeoYeBypU6l5zpyM6 X-Google-Smtp-Source: AMsMyM59dnPa7gz2VCSGKgGpg3kOf+QGRqVZa/MhMPDaBukSk95P9p0ABW0whiONV0Xg4StqAawByvzef0c6IO7ulWg= X-Received: by 2002:a05:6402:2a03:b0:463:11e7:cd5f with SMTP id ey3-20020a0564022a0300b0046311e7cd5fmr13520819edb.274.1667268971221; Mon, 31 Oct 2022 19:16:11 -0700 (PDT) MIME-Version: 1.0 References: <166721993346.12287.10742392140936295449@lain.khirnov.net> In-Reply-To: <166721993346.12287.10742392140936295449@lain.khirnov.net> From: Carl Eugen Hoyos Date: Tue, 1 Nov 2022 03:08:36 +0100 Message-ID: To: FFmpeg development discussions and patches Subject: Re: [FFmpeg-devel] [RFC]lavc/tiff: Support dng cropping X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Am Mo., 31. Okt. 2022 um 13:39 Uhr schrieb Anton Khirnov : > > Quoting Carl Eugen Hoyos (2022-10-23 20:46:57) > > Am So., 23. Okt. 2022 um 16:35 Uhr schrieb Carl Eugen Hoyos > > : > > > > > > Hi! > > > > > > I tried to implement dng cropping, it unfortunately can only work with > > > -flags +unaligned, is there an alternative to simply print a warning > > > if the flag was not supplied? > > > > New patch with more parentheses attached. > > > > Please comment, Carl Eugen > > > > From 1bfe065564604659b7703e75b1bb750c031fdc81 Mon Sep 17 00:00:00 2001 > > From: Carl Eugen Hoyos > > Date: Sun, 23 Oct 2022 16:31:53 +0200 > > Subject: [PATCH] lavc/tiff: Support dng cropping, > > A FATE test would be nice. The samples are big but will look into this once the patch is ok. > > needs -flags +unaligned > > AFAICT this is not entirely correct. Applying left cropping in > libavcodec might need AV_CODEC_FLAG_UNALIGNED, but not always. Of course, but evidence indicates that in nearly all cases, it is needed. > Users may also set apply_cropping=0 and apply cropping themselves. It should be possible to check this. > The decoder should not care about it in any case, since it's handled in > the generic code. Could you elaborate? The reason I added this check (and I would love to see that it is not necessary) is that there is no (working) generic code afaict and that decoding just breaks without a useful hint if the check is removed. > > Fixes samples mentioned in ticket #4364. > > --- > > libavcodec/tiff.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++ > > libavcodec/tiff.h | 3 ++ > > 2 files changed, 86 insertions(+) > > > > diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c > > index fd9db18c0b..33edff8213 100644 > > --- a/libavcodec/tiff.c > > +++ b/libavcodec/tiff.c > > @@ -1492,6 +1492,89 @@ static int tiff_decode_tag(TiffContext *s, AVFrame *frame) > > case DNG_WHITE_LEVEL: > > s->white_level = value; > > break; > > + case DNG_CROP_ORIGIN: > > + if (count != 2 || type != TIFF_SHORT && type != TIFF_LONG && type != TIFF_RATIONAL) { > > This condition could definitely use more parentheses. Same in two checks > below. Sorry, I disagree. > > + av_log(s->avctx, AV_LOG_WARNING, "Invalid crop origin (count: %d, type: %d)\n", count, type); > > + break; > > + } > > + if (type == TIFF_RATIONAL) { > > + unsigned denum1, denum2; > > + value = ff_tget(&s->gb, TIFF_LONG, s->le); > > + denum1 = ff_tget(&s->gb, TIFF_LONG, s->le); > > + value2 = ff_tget(&s->gb, TIFF_LONG, s->le); > > + denum2 = ff_tget(&s->gb, TIFF_LONG, s->le); > > + if (denum1 != 1 || denum2 != 1) { > > + av_log(s->avctx, AV_LOG_WARNING, "Unsupported crop origin\n"); > > + break; > > + } > > + } else { > > + value = ff_tget(&s->gb, type, s->le); > > + value2 = ff_tget(&s->gb, type, s->le); > > + } > > This entire block is duplicated for DNG_CROP_ORIGIN and DNG_CROP_SIZE, > you could split it into a function. Will do, but I expect this to look ugly. > > + av_log(s->avctx, AV_LOG_DEBUG, "dng crop origin: %d/%d\n", value, value2); > > + if (value >= s->width || value2 >= s->height) { > > + av_log(s->avctx, AV_LOG_WARNING, "Invalid crop origin (%d/%d)\n", value, value2); > > + break; > > + } > > + if ((value || value2) && !(s->avctx->flags & AV_CODEC_FLAG_UNALIGNED)) { > > + av_log(s->avctx, AV_LOG_WARNING,"Correct DNG cropping needs -flags +unaligned\n"); > > + } else { > > + frame->crop_left = value; > > + frame->crop_top = value2; > > + } > > + break; > > + case DNG_CROP_SIZE: > > + if (count != 2 || type != TIFF_SHORT && type != TIFF_LONG && type != TIFF_RATIONAL) { > > + av_log(s->avctx, AV_LOG_WARNING, "Invalid crop size (count: %d, type: %d)\n", count, type); > > + break; > > + } > > + if (type == TIFF_RATIONAL) { > > + unsigned denum1, denum2; > > + value = ff_tget(&s->gb, TIFF_LONG, s->le); > > + denum1 = ff_tget(&s->gb, TIFF_LONG, s->le); > > + value2 = ff_tget(&s->gb, TIFF_LONG, s->le); > > + denum2 = ff_tget(&s->gb, TIFF_LONG, s->le); > > + if (denum1 != 1 || denum2 != 1) { > > + av_log(s->avctx, AV_LOG_WARNING, "Unsupported crop size\n"); > > + break; > > + } > > + } else { > > + value = ff_tget(&s->gb, type, s->le); > > + value2 = ff_tget(&s->gb, type, s->le); > > + } > > + av_log(s->avctx, AV_LOG_DEBUG, "dng crop size %d x %d\n", value, value2); > > + if (value + frame->crop_left >= s->width || value2 + frame->crop_top >= s->height) { > > value/value2 can be arbitrary 32bit integers, so the addition can > overflow. Move crop_left/top to the other side of the comparison, since > they are known to be smaller than width/height. Analogously for > DNG_ACTIVE_AREA. Definitely, will do. Thank you, Carl Eugen _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".