From 14bb6012a8c9f48df264ea996f3376e57166201a Mon Sep 17 00:00:00 2001 From: Christoph Gohlke Date: Mon, 3 Jul 2023 09:41:26 -0700 Subject: [PATCH] Update imagecodecs/_heif.pyx --- imagecodecs/_heif.pyx | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) Index: imagecodecs-2023.3.16/imagecodecs/_heif.pyx =================================================================== --- imagecodecs-2023.3.16.orig/imagecodecs/_heif.pyx +++ imagecodecs-2023.3.16/imagecodecs/_heif.pyx @@ -61,9 +61,9 @@ class HEIF: AVC = heif_compression_AVC JPEG = heif_compression_JPEG AV1 = heif_compression_AV1 - # VVC = heif_compression_VVC - # EVC = heif_compression_EVC - # JPEG2000 = heif_compression_JPEG2000 + VVC = heif_compression_VVC + EVC = heif_compression_EVC + JPEG2000 = heif_compression_JPEG2000 class COLORSPACE(enum.IntEnum): """HEIF codec color spaces.""" @@ -145,13 +145,13 @@ def heif_encode( uint16_t* a2ptr = NULL if not ( - src.dtype in (numpy.uint8, numpy.uint16) + src.dtype in {numpy.uint8, numpy.uint16} # and numpy.PyArray_ISCONTIGUOUS(src) - and src.ndim in (2, 3, 4) - and src.shape[0] < 2 ** 32 - and src.shape[1] < 2 ** 32 - and src.shape[src.ndim - 1] < 2 ** 32 - and src.shape[src.ndim - 2] < 2 ** 32 + and src.ndim in {2, 3, 4} + and src.shape[0] < 4294967296 + and src.shape[1] < 4294967296 + and src.shape[src.ndim - 1] < 4294967296 + and src.shape[src.ndim - 2] < 4294967296 ): raise ValueError('invalid data shape, strides, or dtype') @@ -184,14 +184,14 @@ def heif_encode( raise ValueError(f'{src.ndim} dimensions not supported') monochrome = samples < 3 - hasalpha = samples in (2, 4) + hasalpha = samples in {2, 4} if bitspersample is None: depth = 8 if itemsize == 1 else 10 else: depth = bitspersample if ( - depth not in (8, 10, 12) + depth not in {8, 10, 12} or (depth == 8 and itemsize == 2) or (depth > 8 and itemsize == 1) ): @@ -721,12 +721,12 @@ cdef _heif_photometric(photometric): """Return heif_colorspace value from photometric argument.""" if photometric is None: return heif_colorspace_undefined - if photometric in ( + if photometric in { heif_colorspace_undefined, heif_colorspace_YCbCr, heif_colorspace_RGB, heif_colorspace_monochrome, - ): + }: return photometric if isinstance(photometric, str): photometric = photometric.upper() @@ -734,9 +734,9 @@ cdef _heif_photometric(photometric): return heif_colorspace_RGB if photometric[:3] == 'YCBCR': return heif_colorspace_YCbCr - if photometric in ( + if photometric in { 'GRAY', 'BLACKISZERO', 'MINISBLACK', 'WHITEISZERO', 'MINISWHITE' - ): + }: return heif_colorspace_monochrome raise ValueError(f'photometric {photometric!r} not supported') @@ -745,7 +745,7 @@ cdef _heif_compression(compression): """Return heif_compression_format value from compression argument.""" if compression is None: return heif_compression_HEVC - if compression in ( + if compression in { heif_compression_undefined, heif_compression_HEVC, heif_compression_AVC, @@ -754,7 +754,7 @@ cdef _heif_compression(compression): # heif_compression_VVC, # heif_compression_EVC, # heif_compression_JPEG2000, - ): + }: return compression if isinstance(compression, str): compression = compression.upper() @@ -782,7 +782,7 @@ cdef heif_error heif_write_callback( const void* data, size_t size, void* userdata -) nogil: +) noexcept nogil: """heif_writer callback function.""" cdef: output_t* output = userdata