Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/scripts/build-windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
22 changes: 20 additions & 2 deletions rawpy/_rawpy.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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 *)

Expand Down Expand Up @@ -61,13 +64,18 @@ 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
ushort top_margin, left_margin
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]
Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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:
"""
Expand Down
32 changes: 32 additions & 0 deletions test/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading