From 61692c0a25625de81600ca5f4bd92643c77b007f Mon Sep 17 00:00:00 2001 From: jtomori Date: Wed, 12 Feb 2025 12:56:54 +0100 Subject: [PATCH 1/3] Expose LibRaw's raw_inset_crops in rawpy's ImageSizes --- rawpy/_rawpy.pyx | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/rawpy/_rawpy.pyx b/rawpy/_rawpy.pyx index 3da8f85..118922f 100644 --- a/rawpy/_rawpy.pyx +++ b/rawpy/_rawpy.pyx @@ -20,6 +20,9 @@ import sys import warnings from enum import Enum +cdef extern from "limits.h": + cdef unsigned short USHRT_MAX + cdef extern from "Python.h": wchar_t* PyUnicode_AsWideCharString(object, Py_ssize_t *) @@ -61,6 +64,10 @@ cdef extern from "libraw.h": LIBRAW_IMAGE_JPEG LIBRAW_IMAGE_BITMAP + ctypedef struct libraw_raw_inset_crop_t: + ushort cleft, ctop + ushort cwidth, cheight + ctypedef struct libraw_image_sizes_t: ushort raw_height, raw_width ushort height, width @@ -68,6 +75,7 @@ cdef extern from "libraw.h": ushort iheight, iwidth double pixel_aspect int flip + libraw_raw_inset_crop_t[2] raw_inset_crops ctypedef struct libraw_colordata_t: float cam_mul[4] @@ -249,7 +257,9 @@ ImageSizes = namedtuple('ImageSizes', ['raw_height', 'raw_width', 'height', 'width', 'top_margin', 'left_margin', 'iheight', 'iwidth', - 'pixel_aspect', 'flip']) + 'pixel_aspect', 'flip', + 'crop_left_margin', 'crop_top_margin', 'crop_width', 'crop_height' + ]) class RawType(Enum): """ @@ -568,11 +578,19 @@ cdef class RawPy: def __get__(self): self.ensure_unpack() cdef libraw_image_sizes_t* s = &self.p.imgdata.sizes + + # LibRaw returns 65535 for cleft and ctop in some files - probably those that do not specify them + cdef bint has_cleft = s.raw_inset_crops[0].cleft != USHRT_MAX + cdef bint has_ctop = s.raw_inset_crops[0].ctop != USHRT_MAX + return ImageSizes(raw_height=s.raw_height, raw_width=s.raw_width, height=s.height, width=s.width, top_margin=s.top_margin, left_margin=s.left_margin, iheight=s.iheight, iwidth=s.iwidth, - pixel_aspect=s.pixel_aspect, flip=s.flip) + pixel_aspect=s.pixel_aspect, flip=s.flip, + crop_left_margin=s.raw_inset_crops[0].cleft if has_cleft else 0, + crop_top_margin=s.raw_inset_crops[0].ctop if has_ctop else 0, + crop_width=s.raw_inset_crops[0].cwidth, crop_height=s.raw_inset_crops[0].cheight) property num_colors: """ From 7af1aed54a21c6f09b54298275e1190e570fc474 Mon Sep 17 00:00:00 2001 From: jtomori Date: Wed, 12 Feb 2025 12:57:33 +0100 Subject: [PATCH 2/3] Add tests for crop sizes --- test/test_basic.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/test/test_basic.py b/test/test_basic.py index b870922..8595a46 100644 --- a/test/test_basic.py +++ b/test/test_basic.py @@ -228,6 +228,38 @@ def testVisibleSize(): assert_equal(h, s.height) assert_equal(w, s.width) +def testCropSizeNikon(): + with rawpy.imread(rawTestPath) as raw: + s = raw.sizes + assert_equal(s.crop_left_margin, 0) + assert_equal(s.crop_top_margin, 0) + assert_equal(s.crop_width, 0) + assert_equal(s.crop_height, 0) + +def testCropSizeCanon(): + with rawpy.imread(raw3TestPath) as raw: + s = raw.sizes + assert_equal(s.crop_left_margin, 168) + assert_equal(s.crop_top_margin, 56) + assert_equal(s.crop_width, 5616) + assert_equal(s.crop_height, 3744) + +def testCropSizeSigma(): + with rawpy.imread(raw4TestPath) as raw: + s = raw.sizes + assert_equal(s.crop_left_margin, 0) + assert_equal(s.crop_top_margin, 0) + assert_equal(s.crop_width, 0) + assert_equal(s.crop_height, 0) + +def testCropSizeKodak(): + with rawpy.imread(raw6TestPath) as raw: + s = raw.sizes + assert_equal(s.crop_left_margin, 0) + assert_equal(s.crop_top_margin, 0) + assert_equal(s.crop_width, 0) + assert_equal(s.crop_height, 0) + def testHalfSizeParameter(): raw = rawpy.imread(rawTestPath) s = raw.sizes From 4d09e7850881efa4497f68929cc826428c3162ed Mon Sep 17 00:00:00 2001 From: jtomori Date: Mon, 17 Feb 2025 20:12:37 +0100 Subject: [PATCH 3/3] Update vcpkg to fix failing windows CI builds --- .github/scripts/build-windows.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/build-windows.ps1 b/.github/scripts/build-windows.ps1 index 7a60a4b..102c718 100644 --- a/.github/scripts/build-windows.ps1 +++ b/.github/scripts/build-windows.ps1 @@ -119,7 +119,7 @@ Get-ChildItem env: # Install vcpkg and build dependencies if (!(Test-Path ./vcpkg)) { - exec { git clone https://github.com/microsoft/vcpkg -b 2023.11.20 --depth 1} + exec { git clone https://github.com/microsoft/vcpkg -b 2025.01.13 --depth 1} exec { ./vcpkg/bootstrap-vcpkg } } exec { ./vcpkg/vcpkg install zlib libjpeg-turbo[jpeg8] jasper lcms --triplet=x64-windows-static --recurse }