
    ߧeX                       d Z ddlmZ dZddlZddlZddlZddlZddlZi dg ddg ddg d	g d
g dg dg dg dg dg dg dg ddg ddg dg ddgdg i dg dg dg dg dg dg d g d!g d"g d#g d$g d%g d&g d'g d(g d)g d*g g g g g g g g g d+d,gd-d.gg g d/Z	d0d1d2d3d4d5d6d7d8d9	Z
i Zi ZdUd:Zd; Zd< Zd= Zd> Z G d? d@e          ZdA ZdB Zdg fdCZdVdFZdWdGZi fdHZdI ZdDZeZdJ ZdK ZdL Z dM Z!dDZ"eZ#dN Z$dO Z%dXdPZ&dYdQZ'eZ(	 	 	 	 	 	 	 	 dZdRZ)	 	 	 	 	 	 	 	 	 	 d[dSZ*ej+        dT         Z, e             dS )\a1<  Image transformation, compression, and decompression codecs.

Imagecodecs is a Python library that provides block-oriented, in-memory buffer
transformation, compression, and decompression functions for use in Tifffile,
Czifile, Zarr, kerchunk, and other scientific image input/output packages.

Decode and/or encode functions are implemented for Zlib (DEFLATE), GZIP,
ZStandard (ZSTD), Blosc, Brotli, Snappy, LZMA, BZ2, LZ4, LZ4F, LZ4HC, LZW,
LZF, LZFSE, LZHAM, PGLZ (PostgreSQL LZ), RCOMP (Rice), ZFP, AEC, LERC, NPY,
PNG, APNG, GIF, TIFF, WebP, QOI, JPEG 8-bit, JPEG 12-bit, Lossless JPEG
(LJPEG, LJ92, JPEGLL, SOF3), JPEG 2000 (JP2, J2K), JPEG LS, JPEG XL,
JPEG XR (WDP, HD Photo), MOZJPEG, AVIF, HEIF, RGBE (HDR), Jetraw, PackBits,
Packed Integers, Delta, XOR Delta, Floating Point Predictor, Bitorder reversal,
Byteshuffle, Bitshuffle, CMS (color space transformations), and Float24
(24-bit floating point).

:Author: `Christoph Gohlke <https://www.cgohlke.com>`_
:License: BSD 3-Clause
:Version: 2023.1.23
:DOI: 10.5281/zenodo.6915978

Quickstart
----------

Install the imagecodecs package and all dependencies from the
Python Package Index::

    python -m pip install -U imagecodecs[all]

Imagecodecs is also available in other package repositories such as
`Anaconda <https://anaconda.org/conda-forge/imagecodecs>`_,
`MSYS2 <https://packages.msys2.org/base/mingw-w64-python-imagecodecs>`_, and
`MacPorts <https://ports.macports.org/port/py-imagecodecs/summary>`_.

See `Requirements`_ and `Notes`_ for building from source.

See `Examples`_ for using the programming interface.

Source code and support are available on
`GitHub <https://github.com/cgohlke/imagecodecs>`_.

Requirements
------------

This revision was tested with the following requirements and dependencies
(other versions may work):

- `CPython <https://www.python.org>`_ 3.8.10, 3.9.13, 3.10.9, 3.11.1
- `Numpy <https://pypi.org/project/numpy>`_ 1.23.5

Build requirements:

- `Cython <https://github.com/cython/cython>`_ 0.29.33
- `brotli <https://github.com/google/brotli>`_ 1.0.9
- `brunsli <https://github.com/google/brunsli>`_ 0.1
- `bzip2 <https://gitlab.com/bzip2/bzip2>`_ 1.0.8
- `c-blosc <https://github.com/Blosc/c-blosc>`_ 1.21.3
- `c-blosc2 <https://github.com/Blosc/c-blosc2>`_ 2.6.1
- `cfitsio <https://heasarc.gsfc.nasa.gov/fitsio/>`_ 3.49
- `charls <https://github.com/team-charls/charls>`_ 2.4.1
- `giflib <https://sourceforge.net/projects/giflib/>`_ 5.2.1
- `jetraw <https://github.com/Jetraw/Jetraw>`_ 22.02.16.1
- `jxrlib <https://salsa.debian.org/debian-phototools-team/jxrlib>`_ 1.1
- `lcms <https://github.com/mm2/Little-CMS>`_ 2.14
- `lerc <https://github.com/Esri/lerc>`_ 4.0.0
- `libaec <https://gitlab.dkrz.de/k202009/libaec>`_ 1.0.6
- `libavif <https://github.com/AOMediaCodec/libavif>`_ 0.11.1
  (`aom <https://aomedia.googlesource.com/aom>`_ 3.5.0,
  `dav1d <https://github.com/videolan/dav1d>`_ 1.0.0,
  `rav1e <https://github.com/xiph/rav1e>`_ 0.6.3,
  `svt-av1 <https://gitlab.com/AOMediaCodec/SVT-AV1>`_ 1.4.1)
- `libdeflate <https://github.com/ebiggers/libdeflate>`_ 1.16
- `libheif <https://github.com/strukturag/libheif>`_ 1.14.2
  (`libde265 <https://github.com/strukturag/libde265>`_ 1.0.9,
  `x265 <https://bitbucket.org/multicoreware/x265_git/src/master/>`_ 3.5)
- `libjpeg-turbo <https://github.com/libjpeg-turbo/libjpeg-turbo>`_ 2.1.4
- `libjxl <https://github.com/libjxl/libjxl>`_ 0.8.0
- `libpng <https://github.com/glennrp/libpng>`_ 1.6.39
- `libpng-apng <https://sourceforge.net/projects/libpng-apng/>`_ 1.6.39
- `libtiff <https://gitlab.com/libtiff/libtiff>`_ 4.5.0
- `libwebp <https://github.com/webmproject/libwebp>`_ 1.3.0
- `lz4 <https://github.com/lz4/lz4>`_ 1.9.4
- `lzfse <https://github.com/lzfse/lzfse/>`_ 1.0
- `lzham_codec <https://github.com/richgel999/lzham_codec/>`_ 1.0
- `mozjpeg <https://github.com/mozilla/mozjpeg>`_ 4.1.1
- `openjpeg <https://github.com/uclouvain/openjpeg>`_ 2.5.0
- `snappy <https://github.com/google/snappy>`_ 1.1.9
- `xz <https://git.tukaani.org/?p=xz.git>`_ 5.4.1
- `zfp <https://github.com/LLNL/zfp>`_ 1.0.0
- `zlib <https://github.com/madler/zlib>`_ 1.2.13
- `zlib-ng <https://github.com/zlib-ng/zlib-ng>`_ 2.0.6
- `zopfli <https://github.com/google/zopfli>`_ 1.0.3
- `zstd <https://github.com/facebook/zstd>`_ 1.5.2

Vendored requirements:

- `bitshuffle <https://github.com/kiyo-masui/bitshuffle>`_ 0.5.1
- `jpg_0XC3.cpp
  <https://github.com/rordenlab/dcm2niix/blob/master/console/jpg_0XC3.cpp>`_
  modified
- `liblj92
  <https://bitbucket.org/baldand/mlrawviewer/src/master/liblj92/>`_ modified
- `liblzf <http://oldhome.schmorp.de/marc/liblzf.html>`_ 3.6
- `libspng <https://github.com/randy408/libspng>`_ 0.7.3
- `pg_lzcompress.c <https://github.com/postgres/postgres/tree/
  master/src/common/pg_lzcompress.c>`_ modified
- `qoi.h <https://github.com/phoboslab/qoi/>`_ c3dcfe7
- `rgbe.c <https://www.graphics.cornell.edu/~bjw/rgbe/rgbe.c>`_ modified

Test requirements:

- `tifffile <https://pypi.org/project/tifffile>`_ 2023.1.23
- `czifile <https://pypi.org/project/czifile>`_ 2019.7.2
- `zarr <https://github.com/zarr-developers/zarr-python>`_ 2.13.6
- `numcodecs <https://github.com/zarr-developers/numcodecs>`_ 0.11.0
- `bitshuffle <https://github.com/kiyo-masui/bitshuffle>`_ 0.5.1
- `python-blosc <https://github.com/Blosc/python-blosc>`_ 1.11.1
- `python-blosc2 <https://github.com/Blosc/python-blosc2>`_ 2.0.0
- `python-brotli <https://github.com/google/brotli/tree/master/python>`_ 1.0.9
- `python-lz4 <https://github.com/python-lz4/python-lz4>`_ 4.3.2
- `python-lzf <https://github.com/teepark/python-lzf>`_ 0.2.4
- `python-snappy <https://github.com/andrix/python-snappy>`_ 0.6.1
- `python-zstd <https://github.com/sergey-dryabzhinsky/python-zstd>`_ 1.5.2.6
- `pyliblzfse <https://github.com/ydkhatri/pyliblzfse>`_ 0.4.1
- `zopflipy <https://github.com/hattya/zopflipy>`_ 1.8

Revisions
---------

2023.1.23

- Pass 6626 tests.
- Require libjxl 0.8.
- Change mapping of level to distance parameter in jpegxl_encode.
- Add option to specify bitspersample in jpegxl_encode.
- Add option to pass de/linearize tables to LJPEG codec.
- Fix lj92 decoder for SSSS=16 (#59).
- Prefer ljpeg over jpegsof3 codec.
- Add option to specify AVIF encoder codec.
- Support LERC with Zstd or Deflate compression.
- Squeeze chunk arrays by default in numcodecs image compression codecs.

2022.12.24

- Pass 6512 tests.
- Fix PNG codec error handling.
- Fix truncated transferfunctions in cms_profile (#57).
- Fix exceptions not raised in cdef functions not returning Python object.

2022.12.22

- Require libtiff 4.5.
- Require libavif 0.11.
- Change jpegxl_encode level parameter to resemble libjpeg quality (breaking).
- Add LZFSE codec via lzfse library.
- Add LZHAM codec via lzham library.
- Fix AttributeError in cms_profile (#52).
- Support gamma argument in cms_profile (#53).
- Raise limit of TIFF pages to 1048576.
- Use libtiff thread-safe error/warning handlers.
- Add option to specify filters and strategy in png_encode.
- Add option to specify integrity check type in lzma_encode.
- Fix DeprecationWarning with NumPy 1.24.
- Support Python 3.11 and win-arm64.

2022.9.26

- Support JPEG XL multi-channel (planar grayscale only) and multi-frame.
- Require libjxl 0.7.
- Switch to Blosc2 API and require c-blosc 2.4 (breaking).
- Return LogLuv encoded TIFF as float32.
- Add RGBE codec via rgbe.c.

2022.8.8

- Drop support for libjpeg.
- Fix encoding JPEG in RGB color space.
- Require ZFP 1.0.

2022.7.31

- Add option to decode WebP as RGBA.
- Add option to specify WebP compression method.
- Use exact lossless WebP encoding.

2022.7.27

- Add LZW encoder.
- Add QOI codec via qoi.h (#37).
- Add HEIF codec via libheif (source only; #33).
- Add JETRAW codec via Jetraw demo (source only).
- Add ByteShuffle codec, a generic version of FloatPred.
- Replace imcd_floatpred by imcd_byteshuffle (breaking).
- Use bool type in imcd (breaking).

2022.2.22

- Fix jpeg numcodecs with tables (#28).
- Add APNG codec via libpng-apng patch.
- Add lossless and decodingspeed parameters to jpegxl_encode (#30).
- Add option to read JPEG XL animations.
- Add dummy numthreads parameter to codec functions.
- Set default numthreads to 1 (disable multi-threading).
- Drop support for Python 3.7 and numpy < 1.19 (NEP29).

2021.11.20

- ...

Refer to the CHANGES file for older revisions.

Notes
-----

This library is largely a work in progress.

The API is not stable yet and might change between revisions.

Python <= 3.7 is no longer supported. 32-bit versions are deprecated.

Works on little-endian platforms only.

Only ``win_amd64`` wheels include all features.

The ``tiff``, ``packints``, and ``jpegsof3`` codecs are currently decode-only.

The ``heif`` and ``jetraw`` codecs are distributed as source code only due to
license and possible patent usage issues.

The latest `Microsoft Visual C++ Redistributable for Visual Studio 2015-2022
<https://docs.microsoft.com/en-US/cpp/windows/latest-supported-vc-redist>`_
is required on Windows.

Refer to the imagecodecs/licenses folder for 3rd-party library licenses.

This software is based in part on the work of the Independent JPEG Group.

Wheels for macOS may not be available for the latest releases.

Build instructions for manylinux and macOS courtesy of
`Grzegorz Bokota <https://github.com/Czaki/imagecodecs_build>`_.

Update pip and setuptools to the latest version before installing imagecodecs::

    python -m pip install -U pip setuptools wheel Cython

Install the requirements for building imagecodecs from source code on
latest Ubuntu Linux distributions:

    ``sudo apt-get install build-essential python3-dev cython3
    python3-setuptools python3-pip python3-wheel python3-numpy python3-zarr
    python3-pytest python3-blosc python3-brotli python3-snappy python3-lz4
    libz-dev libblosc-dev liblzma-dev liblz4-dev libzstd-dev libpng-dev
    libwebp-dev libbz2-dev libopenjp2-7-dev libjpeg-dev libjxr-dev
    liblcms2-dev libcharls-dev libaec-dev libbrotli-dev libsnappy-dev
    libzopfli-dev libgif-dev libtiff-dev libdeflate-dev libavif-dev
    libheif-dev libcfitsio-dev``

Use the ``--lite`` build option to only build extensions without 3rd-party
dependencies. Use the ``--skip-extension`` build options to skip building
specific extensions, e.g.:

    ``python -m pip install imagecodecs --global-option="build_ext"
    --global-option="--skip-bitshuffle"``

The ``apng``, ``avif``, ``jetraw``, ``jpeg12``, ``jpegls``, ``jpegxl``,
``lerc``, ``lz4f``, ``lzfse``, ``lzham``, ``mozjpeg``, ``zfp``, and ``zlibng``
extensions are disabled by default when building from source.

To modify other build settings such as library names and compiler arguments,
provide a ``imagecodecs_distributor_setup.customize_build`` function, which
is imported and executed during setup. See ``setup.py`` for examples.

Other Python packages and C libraries providing imaging or compression codecs:
`Python zlib <https://docs.python.org/3/library/zlib.html>`_,
`Python bz2 <https://docs.python.org/3/library/bz2.html>`_,
`Python lzma <https://docs.python.org/3/library/lzma.html>`_,
`backports.lzma <https://github.com/peterjc/backports.lzma>`_,
`python-lzo <https://bitbucket.org/james_taylor/python-lzo-static>`_,
`python-lzw <https://github.com/joeatwork/python-lzw>`_,
`python-lerc <https://pypi.org/project/lerc/>`_,
`packbits <https://github.com/psd-tools/packbits>`_,
`isa-l.igzip <https://github.com/intel/isa-l>`_,
`fpzip <https://github.com/seung-lab/fpzip>`_,
`libmng <https://sourceforge.net/projects/libmng/>`_,
`OpenEXR <https://github.com/AcademySoftwareFoundation/openexr>`_
(EXR, PIZ, PXR24, B44, DWA),
`pyJetraw <https://github.com/Jetraw/pyJetraw>`_,
`tinyexr <https://github.com/syoyo/tinyexr>`_,
`pytinyexr <https://github.com/syoyo/pytinyexr>`_,
`pyroexr <https://github.com/dragly/pyroexr>`_,
`libjpeg <https://github.com/thorfdbg/libjpeg>`_ (GPL),
`pylibjpeg <https://github.com/pydicom/pylibjpeg>`_,
`pylibjpeg-libjpeg <https://github.com/pydicom/pylibjpeg-libjpeg>`_ (GPL),
`pylibjpeg-openjpeg <https://github.com/pydicom/pylibjpeg-openjpeg>`_,
`pylibjpeg-rle <https://github.com/pydicom/pylibjpeg-rle>`_,
`glymur <https://github.com/quintusdias/glymur>`_,
`pyheif <https://github.com/carsales/pyheif>`_,
`pyrus-cramjam <https://github.com/milesgranger/pyrus-cramjam>`_,
`PyLZHAM <https://github.com/Galaxy1036/pylzham>`_,
`QuickLZ <http://www.quicklz.com/>`_ (GPL),
`LZO <http://www.oberhumer.com/opensource/lzo/>`_ (GPL),
`nvJPEG <https://developer.nvidia.com/nvjpeg>`_,
`nvJPEG2K <https://developer.nvidia.com/nvjpeg>`_,
`PyTurboJPEG <https://github.com/lilohuang/PyTurboJPEG>`_,
`CCSDS123 <https://github.com/drowzie/CCSDS123-Issue-2>`_,
`LPC-Rice <https://sourceforge.net/projects/lpcrice/>`_,
`CompressionAlgorithms <https://github.com/glampert/compression-algorithms>`_,
`Compressonator <https://github.com/GPUOpen-Tools/Compressonator>`_,
`Wuffs <https://github.com/google/wuffs>`_,
`TinyDNG <https://github.com/syoyo/tinydng>`_,
`MAFISC
<https://wr.informatik.uni-hamburg.de/research/projects/icomex/mafisc>`_.

Examples
--------

Import the JPEG2K codec:

>>> from imagecodecs import (
...     jpeg2k_encode, jpeg2k_decode, jpeg2k_check, jpeg2k_version, JPEG2K
... )

Check that the JPEG2K codec is available in the imagecodecs build:

>>> bool(JPEG2K)
True

Print the version of the JPEG2K codec's underlying OpenJPEG library:

>>> jpeg2k_version()
'openjpeg 2.5.0'

Encode a numpy array in lossless JP2 format:

>>> array = numpy.random.randint(100, 200, (256, 256, 3), numpy.uint8)
>>> encoded = jpeg2k_encode(array, level=0)
>>> bytes(encoded[:12])
b'\x00\x00\x00\x0cjP  \r\n\x87\n'

Check that the encoded bytes likely contain a JPEG 2000 stream:

>>> jpeg2k_check(encoded)
True

Decode the JP2 encoded bytes to a numpy array:

>>> decoded = jpeg2k_decode(encoded)
>>> numpy.array_equal(decoded, array)
True

Decode the JP2 encoded bytes to an existing numpy array:

>>> out = numpy.empty_like(array)
>>> _ = jpeg2k_decode(encoded, out=out)
>>> numpy.array_equal(out, array)
True

Not all codecs are fully implemented, raising exceptions at runtime:

>>> from imagecodecs import tiff_encode
>>> tiff_encode(array)
Traceback (most recent call last):
 ...
NotImplementedError: tiff_encode

Write the numpy array to a JP2 file:

>>> from imagecodecs import imwrite, imread
>>> imwrite('_test.jp2', array)

Read the image from the JP2 file as numpy array:

>>> image = imread('_test.jp2')
>>> numpy.array_equal(image, array)
True

Create a JPEG 2000 compressed Zarr array:

>>> import zarr
>>> import numcodecs
>>> from imagecodecs.numcodecs import Jpeg2k
>>> numcodecs.register_codec(Jpeg2k)
>>> zarr.zeros(
...     (4, 5, 512, 512, 3),
...     chunks=(1, 1, 256, 256, 3),
...     dtype='u1',
...     compressor=Jpeg2k()
... )
<zarr.core.Array (4, 5, 512, 512, 3) uint8>

Access image data in a sequence of JP2 files via tifffile.FileSequence and
dask.array:

>>> import tifffile
>>> import dask.array
>>> def jp2_read(filename):
...     with open(filename, 'rb') as fh:
...         data = fh.read()
...     return jpeg2k_decode(data)
>>> with tifffile.FileSequence(jp2_read, '*.jp2') as ims:
...     with ims.aszarr() as store:
...         dask.array.from_zarr(store)
dask.array<from-zarr, shape=(1, 256, 256, 3)...chunksize=(1, 256, 256, 3)...

View the image in the JP2 file from the command line::

    $ python -m imagecodecs _test.jp2

    )annotationsz	2023.1.23N)versionimreadimwriteimagefileextDelayedImportError)nonenumpyjpegimcd)imcd_versionnumpy_abi_versioncython_version)	bitorderbyteshuffledeltafloat24	floatpredlzwpackbitspackintsxoraecapngavif
bitshufflebloscblosc2brotlibrunslibz2cms)cms_transformcms_profilecms_profile_validatedeflate)deflate_crc32deflate_adler32)r&   gzipgifheifjetrawjetraw_initjpeg2kjpeg8jpeg12jpeglsjpegsof3jpegxljpegxrlercljpeglz4lz4flzflzfselzhamlzmamozjpegpglzqoi
zlib_crc32zlib_adler32zlibng_crc32zlibng_adler32)pngrgbercompsnappyspngtiffwebpzfpzlibzlibngzopflizstdJPEG8jpeg8_checkjpeg8_version
zlib_checkzlib_decodejpeg2k_encodejpeg2k_decodejpegxr_encodejpegxr_decode)	JPEG
jpeg_checkjpeg_versionzopfli_checkzopfli_decode
j2k_encode
j2k_decode
jxr_encode
jxr_decodec                j    | }|<| d| d| d| d|                                  d|                                 f} t          v r!t                                        |           n
|t           <   t                               fdt                    D                         t          |<   dS )z8Register codec in global _API, _ATTRIBUTES, and _CODECS.N_encode_decode_check_versionErrorc                    i | ]}|S  ri   ).0attrmodules     7lib/python3.11/site-packages/imagecodecs/imagecodecs.py
<dictcomp>z_add_codec.<locals>.<dictcomp>;  s    >>>f>>>    )
capitalizeupper_APIextend_ATTRIBUTESupdate_CODECS)rl   codec
attributess   `  rm   
_add_codecry   *  s    }!!((({{}}

 ~~VJ''''!V>>>>f>>>???GENNNro   c                    t                                           D ]l\  } }|                                D ]C}t          |t                    r,|                    |           |D ]}t          | |            nDt          |            mdS )z#Parse _API and register all codecs.N)rr   itemscopy
isinstancetupleremovery   )rl   rx   rk   rw   s       rm   _register_codecsr   ?  s    "jjll  
OO%% 	 	D$&& !!$'''! . .Evu----	 v ro   c                 F    t                      D ]} t          |            dS )z3Add all registered attributes to package namespace.N)__dir____getattr__names    rm   	_load_allr   L  s0    		  D ro   c                 n    t          t          t                    t          t                    z             S )z4Return list of attribute names accessible on module.)sortedlistrt   _COMPATIBILITYri   ro   rm   r   r   R  s%    ${##d>&:&::;;;ro   c                   | }t                               | |           } | t          vrt          d|           t          |          }|dS 	 t	          j        d|z   d          }n%# t          $ r d}Y nt          $ r ddlm} d}Y nw xY wt          |         D ]E}|t           v rt          ||d          }|t          ||          }t          t          ||           Ft          t          |           }| |k    rt          t          ||           |S )zReturn module attribute after loading it from extension.

    Load attribute's extension and add its attributes to the package namespace.

    z&module 'imagecodecs' has no attribute Nz._imagecodecs   )_shared)r   getrt   AttributeError	importlibimport_moduleImportError r   rr   getattr_stubsetattrr   )r   name_module_rl   r   nrk   s          rm   r   r   W  sP    EdD))D;NdNNOOO$Gt(GG      
 	 '] & &vq$''<F##DQ%%%%;%%Du}}UD)))Ks   A$ $B2BBc                  "     e Zd ZdZ fdZ xZS )r   zDelayed ImportError.c                V    d|d}t                                          |           dS )z(Initialize instance from attribute name.zcould not import name z from 'imagecodecs'N)super__init__)selfr   msg	__class__s      rm   r   zDelayedImportError.__init__  s1    BtBBBro   )__name__
__module____qualname____doc__r   __classcell__)r   s   @rm   r   r     s>                ro   r   c                                          d          r fd}n fd}|S                       d          rd }|S                       d          r fd}|S                       d	          r fd
}|S                                  r fd}|S                       d          r G  fddt                    }|S  G  fddt                    }                                 r G d d|          }	|	S  G d d|          }
|
S )zReturn stub function or class.rf   Nc                      dd          dS ),Stub for imagecodecs.codec_version function.Nz n/ari   r   s   rm   stub_versionz_stub.<locals>.stub_version  s    ss)))))ro   c                      dd          dS )r   Nr   z unknownri   r   s   rm   r   z_stub.<locals>.stub_version  s    ss)----ro   re   c                    dS )z*Stub for imagecodecs.codec_check function.Fri   )args    rm   
stub_checkz_stub.<locals>.stub_check  s    5ro   rd   c                 "    t                    )z+Stub for imagecodecs.codec_decode function.r   argskwargsr   s     rm   stub_decodez_stub.<locals>.stub_decode      $T***ro   rc   c                 "    t                    )z+Stub for imagecodecs.codec_encode function.r   r   s     rm   stub_encodez_stub.<locals>.stub_encode  r   ro   c                 "    t                    )z$Stub for imagecodecs.codec_function.r   r   s     rm   stub_functionz_stub.<locals>.stub_function  r   ro   rg   c                      e Zd ZdZ fdZdS )_stub.<locals>.StubErrorz&Stub for imagecodecs.CodecError class.c                "    t                    Nr   )r   r   r   r   s      rm   r   z!_stub.<locals>.StubError.__init__  s    (...ro   N)r   r   r   r   r   r   s   rm   	StubErrorr     s4        88/ / / / / / /ro   r   c                  (    e Zd ZfdZ d ZdS dS )_stub.<locals>.StubTypec                "    t                    r   r   )clsr   r   s     rm   r   z#_stub.<locals>.StubType.__getattr__  s    $T***ro   Nc                    dS )NFri   )r   s    rm   __bool__z _stub.<locals>.StubType.__bool__  s    uro   )r   r   r   r   r   )rl   r   s   rm   StubTyper     sK        	+ 	+ 	+ 	+ 	+ >     >ro   r   c                      e Zd ZdZdS )_stub.<locals>.STUBz%Stub for imagecodecs.CODEC constants.Nr   r   r   r   ri   ro   rm   STUBr     s        7777ro   r   )	metaclassc                      e Zd ZdZdS )_stub.<locals>.Stubz!Stub for imagecodecs.Codec class.Nr   ri   ro   rm   Stubr     s        ////ro   r   )endswithislowerRuntimeErrortypeisupper)r   rl   r   r   r   r   r   r   r   r   r   s   ``         rm   r   r     s)   }}Z   >* * * * * *. . . . . }}X 	 	 	 }}Y 	+ 	+ 	+ 	+ 	+ }}Y 	+ 	+ 	+ 	+ 	+ ||~~ 	+ 	+ 	+ 	+ 	+ }}W 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/        4    ||~~ 	8 	8 	8 	8 	8X 	8 	8 	8 	8 0 0 0 0 0 0 0 0 0 Kro   c                 >    t          d t          D                       S )z&Return sorted list of extension names.c              3     K   | ]}||V  	d S r   ri   )rj   es     rm   	<genexpr>z_extensions.<locals>.<genexpr>  s"      33Q]!]]]]33ro   )r   rr   ri   ro   rm   _extensionsr     s    33T333333ro   c                   |s|                     dt           t                                          t                                          t                                          t                                          f           |                     t          d t          D                                  | 	| t          u rd
                    d |D                       S | t          u rt          d |D                       S t          |          S )z=Return version information about all codecs and dependencies.zimagecodecs c                z    h | ]8}|                     d           r!|dv t          t          |                      9S )rf   )r   r   numpy_versionr   none_version)r   r   r   )rj   vs     rm   	<setcomp>zversion.<locals>.<setcomp>  sb       zz*--   ,GK++--  ro   Nz, c              3  B   K   | ]}|                     d d          V  dS ) -N)replacerj   vers     rm   r   zversion.<locals>.<genexpr>   s0      EE3S#..EEEEEEro   c              3  @   K   | ]}|                     d           V  dS )r   N)splitr   s     rm   r   zversion.<locals>.<genexpr>  s,      99sCIIcNN999999ro   )rs   __version__r   r   r   r   r   r   rt   strjoindictr~   )astype
_versions_s     rm   r   r     s    
,{,,**,,))++--//((**	
 	
 	
 	 (   	
 	
 	
$ ~3yyEE*EEEEEE~~99j999999ro   TFc                   ddl }g |t          | t          t          j        f          rRt          j                            t          j        |                     d         dd                                         }nd}|t                      v rEt                      |         }|dk    r
                    d           n                    |           
                    fddD                        nt          |t          t          f          s|g}|D ]b}t          |t                    r6|                                }t                                          ||          }                    |           cd}d	}	t          | |j                   r| }
|
                                }nt!          | d
          r|                                 }
nt          | t          t          j        f          rt%          t          j        |           d          5 }|r4d}d}	|                     |                                d|j                  }
n|                                }
ddd           n# 1 swxY w Y   n| }
g }d}D ]}t+          |          r|}nj	 t-          t.          |dz             }nP# t0          $ rC}|                    t3          |                                           d|            Y d}~wd}~ww xY w	  ||
fi |}|j        dk    rd}t9          d           nl# t:          $ r Y nGt0          $ r;}|                    |j                                         d|            Y d}~nd}~ww xY w||
                    |           |	r|
                                  |"t9          d!                    |                    |r||fS |S )z+Return image data from file as numpy array.r   Nr   r   )r/   r0   r6   r2   c              3  $   K   | ]
}|v|V  d S r   ri   )rj   ccodecss     rm   r   zimread.<locals>.<genexpr>  s9       
 
. 1 0 3
 
ro   )rI   r   rD   r*   rJ   r/   r0   r6   r.   r1   r4   r3   r   r+   rK   r5   rE   r2   r
   FreadrbT)accessrd   z: objectfailed
)"mmapr}   r   osPathLikepathsplitextfspathlower	_imcodecsrs   appendr   r~   r   tellhasattrr   openfilenoACCESS_READcallabler   r   	Exceptionreprrq   dtype
ValueErrorr   r   seekcloser   )fileobjrw   memmapreturn_codecr   r   extr   offsetr  datafh
exceptionsimagefuncexcr   s                   @rm   r   r     sf   KKKF}gR[122 	'""29W#5#566r:122>DDFFCCC)++KK$EFGGGGe$$$ 
 
 
 

 
 
 	
 	
 	
 	
: %$// 	GE 	 	A!S!! *GGIIKKOOAq))MM!FE'49%% 	&	!	! ||~~	Gc2;/	0	0  ")G$$d++ 	!r !yya8HyIIwwyy	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! JE  E?? 	DD{EI,=>>   !!T%[[%6%6%8%8"A"AC"A"ABBB
	AD((((E{h&& ***E! 	 	 	D 	A 	A 	A!4!4!6!6??#??@@@@@@@@	A IIf 

}:../// d{LsI   AI))I-0I-J,,
K969K44K9=%L$$
M40	M491M//M4c                   |t          | t          t          j        f          rRt          j                            t          j        |                     d                                         dd         }nt          d          t                      
                    ||          }	 t          t          |dz             }n# t          $ r}t          d|          |d}~ww xY wt          |t                    ru|                                }t                      
                    ||          }	 t          t          |dz             }nF# t          $ r}t          d|          |d}~ww xY wt          |          st          d|           ||fi |}t          | d          r|                     |           dS t#          t          |           d          5 }|                    |           ddd           dS # 1 swxY w Y   dS )	z Write numpy array to image file.Nr   r   zno codec specifiedrc   zinvalid codec writewb)r}   r   r   r   r   r   r   r   r
  r   r   r   r   r   r  r  r  r  )r  r  rw   r   r  r  r  s          rm   r   r   w  sY   }gR[122 	3'""29W#5#566r:@@BB122FCC1222S))	BK):;;EE 	B 	B 	B7e7788cA	B 
E3		 	5u--	BK):;;EE 	B 	B 	B7e7788cA	B e__ 53%334445    Dw   d #g,,%% 	HHTNNN	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	sB   (C 
C#CC#2E 
E-E((E-HHHc                    | ski ddddddddd	d
dddddddddddddddddddddd d!d"d#d$d%}|                      d& |                                D                        | S )'z3Return map of image file extensions to codec names.r   )r   r   )r   avifsr    )brnr*   )r*   r+   )r+   heicheifsheicshifr   )jpgr   jpejfifjifr.   )j2kjp2j2cjpcjpxjpfr1   )jlsr3   )jxlr4   )jxrhdpwdpr5   )lerc1lerc2r6   )ljpljpgr6   r
   )npynpzrD   )rD   r?   )r?   rE   )hdrrE   picrI   )tifrI   ptifptifftf8tf2btf)rJ   )rK   )rJ   rK   c              3  .   K   | ]\  }}|D ]}||fV  	d S r   ri   )rj   rw   extsr  s       rm   r   z_imcodecs.<locals>.<genexpr>  sO       
 
(UDd
 
?BS%L
 
 
 
 
 
 
ro   )ru   r{   )_codecs_r   s     rm   r   r     s>    

I
%
 x

 8
  
 9
 @
 h
  h!
" +#
$ &%
& -'
( ^)
* 8+
, 8-
. */
0 I1
2 5
 
 
8 	 
 
,2LLNN
 
 
 	
 	
 	
 Oro   c                 \    t          t                                                                S )zCReturn list of image file extensions handled by imread and imwrite.)r   r   keysri   ro   rm   r   r     s     	  ""###ro   c                     dS )zReturn empty version string.r   ri   ri   ro   rm   r   r     s    2ro   c                    dS )z2Return True if data likely contains Template data.Nri   )r  s    rm   
none_checkrF    s      ro   c                    | S )zDecode NOP.ri   r  r   r   s      rm   none_decoderI        Kro   c                    | S )zEncode NOP.ri   rH  s      rm   none_encoderL    rJ  ro   c                      dt           j         S )zReturn numpy version string.znumpy )r
   r   ri   ro   rm   r   r     s    'E%'''ro   c                    t          j        |           5 }|                    d          } ddd           n# 1 swxY w Y   d}|                     |          p|                     d          o|| v S )z4Return True if data likely contains NPY or NPZ data.@   Ns   NUMPYs   PK)ioBytesIOr   
startswith)r  r  magics      rm   numpy_checkrT    s    	D		 Rwwr{{              E??5!!Odooe&<&<&N$Os   7;;c                8   t          j        |           5 }	 t          j        |fi |}n"# t          $ r}t	          d          |d}~ww xY wt          |d          r'	 |j        |         }n# t          $ r Y nw xY w||         }ddd           n# 1 swxY w Y   |S )zDecode NPY and NPZ.znot a numpy arrayNfiles)rP  rQ  r
   loadr
  r  rV  r  )r  index
numthreadsoutr   r  r  s          rm   numpy_decoder[    s   	D		 
R	;*R**6**CC 	; 	; 	;011s:	;3   		%(   e*C
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 JsT   B*B
A	AA		BA+*B+
A85B7A88BBBc                   t          j                    5 }|rt          j        ||            nt          j        ||            |                    d           |                                }ddd           n# 1 swxY w Y   |S )zEncode NPY and NPZ.r   N)rP  rQ  r
   savez_compressedsaver  r   )r  levelrY  rZ  r  s        rm   numpy_encoder`    s    	  	!"2t,,,,Jr4   



ggii               Js   AA77A;>A;c	           
        ||| z   dz   } |	 t                               | ||||||          S # t          $ r}	t          |	          }
d|
v r&t                               | ||||||          cY d}	~	S d|
v rU	 t                               | ||          cY d}	~	S # t          $ r% t                               | ||          cY cY d}	~	S w xY w|	d}	~	ww xY w	 |dk    r!t                               | ||||||          S |dk    r!t                               | ||||||          S 	 t                               | ||          S # t          $ r  t                               | ||          cY S w xY w# t          $ ro}	t          |	          }
d|
v rU	 t                               | ||          cY d}	~	S # t          $ r% t                               | ||          cY cY d}	~	S w xY w|	d}	~	ww xY w)	z$Decode JPEG 8-bit, 12-bit, and SOF3.Ns   )tables
colorspaceoutcolorspaceshaperY  rZ  zUnsupported JPEG data precisionzSOF type)rY  rZ        )r   jpeg8_decoder  r   jpeg12_decodeljpeg_decodejpegsof3_decode)r  bitspersamplerb  headerrc  rd  re  rY  rZ  r  r   s              rm   jpeg_decodern    sj    }{*#	++%+% ,     	 	 	c((C0C77"00!)"/) 1         S  &33 4         !   &66 7           I3	4)A++%+% ,    B,,%+% -   	++ ,     	 	 	.. /     	    #hh"//ZS 0            "22ZS 3          
 	s    / 
C3C,C2C7BC'C CCCCC&E/ =&E/ %E 'E,)E/ +E,,E/ /
G(9G#F/)G(/'GG#G(GG##G(c                   |rt                               | ||
          S | j        t          j        k    rt           j        }n9| j        t          j        k    rt           j        }nt          d| j                    || |||||||	|
	  	        S )zEncode JPEG 8-bit or 12-bit.)rl  rZ  zinvalid data type )r_  rc  rd  subsamplingoptimize	smoothingrY  rZ  )	r   ljpeg_encoder	  r
   uint8jpeg8_encodeuint16jpeg12_encoder
  )r  r_  rc  rd  rp  rq  rr  losslessrl  rY  rZ  r  s               rm   jpeg_encodery  k  s      
''3 ( 
 
 	
 zU[  '	u|	#	#(:dj::;;;4#
 
 
 
ro   r   )NN)NTFr   )r   NN)NNN)NNNNNNNN)
NNNNNNNNNN)-r   
__future__r   r   r   sysrP  r   r
   rr   r   rt   rv   ry   r   r   r   r   r   r   r   r   r   r   r   r   r   NONEr   	NoneErrorr   rF  rI  rL  NUMPY
NumpyErrorr   rT  r[  r`  	JpegErrorrn  ry  modulesr   ri   ro   rm   <module>r     sD  @Y Yv # " " " " " 				 



 				     K   K    K4 
25K6 B7K8 B9K< "=K> R?K@ bAKB bCKD rEKF 
2GKH 
CCCIKJ HHHKKL 
2MKN BOKP }oQKR bSK KT RUKV bWKX bYKZ [K\ b]K^ b_K` BaKb RcKd 
2eKf BgKh 
2iKj RkKl RmKn BoKp rqKv BwKx 
2yK Kz >*/0SK K K` # "!!!!
 
     *
 
 
  < < <
( ( (V       N N Nb4 4 4
 B " " " "Jn n n nb! ! ! !H  " " " "J$ $ $
 	  
= = =  
  
 	
( ( (
P P P    	 	 	 	 	
 
\ \ \ \B " " " "L k-(       ro   