From patchwork Wed Aug 3 08:25:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Dufresne via libcamera-devel X-Patchwork-Id: 16924 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 7A37EBE173 for ; Wed, 3 Aug 2022 08:25:59 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E0BD763313; Wed, 3 Aug 2022 10:25:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1659515158; bh=Tau/yevSZXKMouDpmlcLQo4QB3F6TTWc3d7WrY3wpx4=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=IVMfjcMVFHxhFX1XI09LeriZixhUMljvJVerSjgA4AQCUk7EWaOYb3yHOISKHJOFh ct+OkLo1b9u8DdAuYFaYQJAF3b9QxupVzWqImaqQ0GzGZFpBfCVYy11CfXZ56kZifP NWTdyXdduqLTZab0qao3HFye1+Grhdgx+cjzr9LJrSdBLFJdOgBFia7Kliw+cITRyz CEHAETEEUwc23zv84CL5R3JelicUWjKmoSH7akWnWHciKzOhtpx+7YfuMT/ytTBy6Z /YcinN1jcZM7cE0ZOADLFQ9tetalhPFfpUQBrIzoB+maXcI5OXirvXnFoqSnyuIn4K PbUi0RLZgwNZw== Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 18EF6603EF for ; Wed, 3 Aug 2022 10:25:57 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="Mr2B+lPH"; dkim-atps=neutral Received: by mail-wm1-x335.google.com with SMTP id 8-20020a05600c024800b003a2fe343db1so519720wmj.1 for ; Wed, 03 Aug 2022 01:25:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=AGZOioqHnXhWwEKmDTA6/duzrAvvA7O+MuvjuNarU3A=; b=Mr2B+lPH7CsAm3LIWWP9lbBjizUONIJkxkfeUlxyT1SZLBe3mSInoo9xABWkj/36ep gzTO3QwHWksYzLqbfBVvEbcTkm6JLEkHOXGsr/QBRQB7bhXDFXHOeCmwO9gYmFQGTl2J ojbu7zm6Z1mPXoiS8qwBLSTgrg5MSF10o+btJcjGuamvqT4rlwgdN5qU+4EbHzymcNxF zLTABckOcK8/1ZPlXpm4i6zjyhtCR4+Xb01axuV9kxQmmqHEVgFRrlmiLNgLpjajuOzH OT0XH6mqnYIIs88OWf79kNfdqXZaexghD3mu/d9CRAOyxAIVP7OFjzOVMXA0YsYsEu5a VOUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=AGZOioqHnXhWwEKmDTA6/duzrAvvA7O+MuvjuNarU3A=; b=hE/f0qb5n7OHWr81X7th1IBB/fV4neVzVr8cTg6lvDv3dRJ8tZ9v6iwGRRQeXYumgU y0d3QVK57IHT2/MY/5/1T4R4c2IsJBrMn9PXkhSlULPreglIuDHjnPcgEdYXnK0fsORI 0eh0j2mMuU/soEwYiW24LsM/UZMZ1s5GVjIbh2iR5MrJ8jGkxvfKFLfII4EAHlQnphiu JRw22SEY+klhFkEumSf4k9FTJiF5YGI8lsgRFk2ZUDhWTD7nE0Yn6bvv97jr5ZdPrpUX gmtR0N/jY6GbNzvoapKIDuUV2oEMbORmyRscGgR3a/qhcXA2jC0Yrq/sjyVvT6NROqRs le8Q== X-Gm-Message-State: ACgBeo2zJjhSh5gGS2zA6PSvR+vkWjQFgc0XxdhmncTqKO25mKL0fIX7 gCDwAnA1N4VmTweiJEA7O5zH5MOcUClYEw== X-Google-Smtp-Source: AA6agR7xTo4Ri309o/rAKa++Pz4y6T+1ux/WWt+Aw2aRB+am0CMSdDCDZF5Ryyfhu6DiQIaqDfEJQw== X-Received: by 2002:a7b:c3d4:0:b0:3a3:ce7:7894 with SMTP id t20-20020a7bc3d4000000b003a30ce77894mr2048677wmj.134.1659515156385; Wed, 03 Aug 2022 01:25:56 -0700 (PDT) Received: from wv-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id l12-20020a7bc44c000000b003a2e42ae9a4sm1822352wmi.14.2022.08.03.01.25.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Aug 2022 01:25:55 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 3 Aug 2022 09:25:39 +0100 Message-Id: <20220803082539.11172-1-william.vinnicombe@raspberrypi.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3] utils: raspberrypi: ctt: dng_load_image: Work with DNG files from Picamera2 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: William Vinnicombe via libcamera-devel From: Nicolas Dufresne via libcamera-devel Reply-To: william.vinnicombe@raspberrypi.com Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: William Vinnicombe The DNG specification is based on the TIFF file format and recommends storing the raw image data in a SubIFD and the Exif tags in an Exif IFD. Other options are allowed, even if not recommended, such as storing both the raw image data and the Exif data in IFD0, as done by the TIFF/EP specification. libcamera-apps use pyexiv2 to produce DNG files, following the DNG recommendation, while applications based on picamera2 use PiDNG, which adopts the TIFF/EP structure. Why it does so is not currently clear (see https://github.com/schoolpost/PiDNG/issues/65 for discussions on this topic), but as files based on the DNG and TIFF/EP variants exist in the wild, both need to be supported by ctt. Add code to identify which tags are being used, and then load the metadata from the correct tags. Signed-off-by: William Vinnicombe Reviewed-by: David Plowman Reviewed-by: Naushir Patuck Reviewed-by: Laurent Pinchart --- utils/raspberrypi/ctt/ctt_image_load.py | 32 +++++++++++++++++++------ 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/utils/raspberrypi/ctt/ctt_image_load.py b/utils/raspberrypi/ctt/ctt_image_load.py index 934db123..7f8ba72a 100644 --- a/utils/raspberrypi/ctt/ctt_image_load.py +++ b/utils/raspberrypi/ctt/ctt_image_load.py @@ -301,17 +301,35 @@ def dng_load_image(Cam, im_str): metadata.read() Img.ver = 100 # random value - Img.w = metadata['Exif.SubImage1.ImageWidth'].value + """ + The DNG and TIFF/EP specifications use different IFDs to store the raw + image data and the Exif tags. DNG stores them in a SubIFD and in an Exif + IFD respectively (named "SubImage1" and "Photo" by pyexiv2), while + TIFF/EP stores them both in IFD0 (name "Image"). Both are used in "DNG" + files, with libcamera-apps following the DNG recommendation and + applications based on picamera2 following TIFF/EP. + + This code detects which tags are being used, and therefore extracts the + correct values. + """ + try: + Img.w = metadata['Exif.SubImage1.ImageWidth'].value + subimage = "SubImage1" + photo = "Photo" + except KeyError: + Img.w = metadata['Exif.Image.ImageWidth'].value + subimage = "Image" + photo = "Image" Img.pad = 0 - Img.h = metadata['Exif.SubImage1.ImageLength'].value - white = metadata['Exif.SubImage1.WhiteLevel'].value + Img.h = metadata[f'Exif.{subimage}.ImageLength'].value + white = metadata[f'Exif.{subimage}.WhiteLevel'].value Img.sigbits = int(white).bit_length() Img.fmt = (Img.sigbits - 4) // 2 - Img.exposure = int(metadata['Exif.Photo.ExposureTime'].value*1000000) - Img.againQ8 = metadata['Exif.Photo.ISOSpeedRatings'].value*256/100 + Img.exposure = int(metadata[f'Exif.{photo}.ExposureTime'].value*1000000) + Img.againQ8 = metadata[f'Exif.{photo}.ISOSpeedRatings'].value*256/100 Img.againQ8_norm = Img.againQ8 / 256 Img.camName = metadata['Exif.Image.Model'].value - Img.blacklevel = int(metadata['Exif.SubImage1.BlackLevel'].value[0]) + Img.blacklevel = int(metadata[f'Exif.{subimage}.BlackLevel'].value[0]) Img.blacklevel_16 = Img.blacklevel << (16 - Img.sigbits) bayer_case = { '0 1 1 2': (0, (0, 1, 2, 3)), @@ -319,7 +337,7 @@ def dng_load_image(Cam, im_str): '2 1 1 0': (2, (3, 2, 1, 0)), '1 0 2 1': (3, (1, 0, 3, 2)) } - cfa_pattern = metadata['Exif.SubImage1.CFAPattern'].value + cfa_pattern = metadata[f'Exif.{subimage}.CFAPattern'].value Img.pattern = bayer_case[cfa_pattern][0] Img.order = bayer_case[cfa_pattern][1]