
    Dh                     6   d dl Z d dlZd dlZd dlmZmZmZmZmZmZm	Z	m
Z
mZmZ d Zd Zd Zd Zd Zd Zd	 Zd
d
ddddddddddZ ed ej-                         D              Zddddddddddd
Zd Z G d  d!e      Z G d" d#ej8                  e$      Zd#gZy)%    N)
ffiglib_libvips_libError	_to_bytes
_to_string_to_string_copyGValueat_least_libvips
Introspectc                     t        | t        j                        xs- t        | t              xr t        | t        j
                         S N)
isinstancenumbersNumberlistpyvipsImage)values    o/var/www/fastuser/data/www/generator.snapmosaic.io/flask_app/venv/lib/python3.12/site-packages/pyvips/vimage.py	_is_pixelr      s<    ugnn- -t$ ,ufll+*,.    c                     t        | t              sy| D ]0  }t        |t              s yt        |      t        | d         k7  s0 y y)NFr   T)r   r   len)arrayxs     r   _is_2Dr      sG    eT" !T"q6Sq]"	 r   c                 \    t        |t              rt        t        | |            S  | |      S r   )r   r   map)funcr   s     r   _smapr!   #   s&    !TCaL!!Awr   c                     t        |      r%t        j                  j                  |dz   | ||      S t        j                  j                  || ||      S )N_const)r   r   	Operationcall)imageotherbase	operations       r   
_call_enumr*   *   sH    $$TH_eYNN$$T5%CCr   c                    |j                   }|j                   dk7  r|j                   dk7  r|j                  dz  dk7  rt        d      |j                   dk7  r |j                   dk7  r|j                  d      }|j                   dk(  rd}nd}|j	                  ||j                  dz        } | |      }|dk7  r9|dk7  r4|j                   dk(  rd}nd}|j	                  ||j                  dz        }|S )	zRun a complex function on a non-complex image.

    The image needs to be complex, or have an even number of bands. The input
    can be int, the output is always float or double.
    complex	dpcomplex   r   znot an even number of bandsfloatdouble)formatbands)r1   r2   r   castcopy)fnr&   original_format
new_formats       r   
_run_cmplxr8   1   s     llO||y U\\[%@;;?a566<<7"u||x'?JJw'E<<8#$J"J

*EKK!O
DuIE)#;(F<<;&!J J

*EKK!O
DLr   c                 t    	 t         j                  j                  |       fd}|S # t        $ r d Y w xY w)Nc                     | _         | S r   )__doc__)r    	docstrings    r   _docz_add_doc.<locals>._doc[   s     r   )r   r$   generate_docstringr   )namer=   r<   s     @r   _add_docr@   U   s@    $$77=	 K  	s   ) 77c                       fd}|S )Nc                     | _         | S r   )__deprecated__)r    notes    r   _depz_deprecated.<locals>._depd   s    "r    )rD   rE   s   ` r   _deprecatedrG   c   s     Kr   ucharcharushortshortuintintr/   r,   r0   r-   )|b1z|u1z|i1z<u2z<i2z<u4z<i4z<f4z<c8z<f8z<c16c              #   *   K   | ]  \  }}||f  y wr   rF   ).0kvs      r   	<genexpr>rS   z   s     FDAq!QFs   BcHhIifd)
rH   rI   rJ   rK   rL   rM   r/   r0   r,   r-   c                 6   |t         vrt        d|       t        | t              r| dk  rt        d      d}|dk(  r| dv rd}|S | dv rd	}|S |d
k(  r	| dk(  rd}|S |dk(  r| dv rd}|S | dv rd}|S |dk(  r	| dk(  rd}|S |dv r| dv rd}|S | dv rd}|S |dv rd}|S )a[  Return a best-guess interpretation string based on bands and libvips
    format.

    Args:
        bands (int): Number of bands in the image.
        format (str): libvips format string.

    Returns:
        str: the best-guess libvips interpretation string.

    This function is a helper for :class:`.Image` creation from arrays when the
    user specifies 'auto' for `interpretation`.

    The heuristic used here can be defined in the following table::

        | bands | format    | interpretation | reason       |
        | ----- | --------- | -------------- | ------------ |
        | 1     | uchar     | b-w            | L            |
        | 2     | uchar     | b-w            | LA           |
        | 3     | uchar     | rgb            | RGB          |
        | 4     | uchar     | rgb            | RGBA         |
        | 5+    | uchar     | multiband      | spectral     |
        | 1     | char      | matrix         | conv. kernel |
        | 2+    | char      | multiband      |              |
        | 1     | ushort    | grey16         | L            |
        | 2     | ushort    | grey16         | LA           |
        | 3     | ushort    | rgb16          | RGB          |
        | 4     | ushort    | rgb16          | RGBA         |
        | 5+    | ushort    | multiband      | spectral     |
        | any   | short     | multiband      |              |
        | 1     | float     | b-w            | L            |
        | 2     | float     | b-w            | LA           |
        | 3     | float     | scrgb          | RGB          |
        | 4     | float     | scrgb          | RGBA         |
        | 5+    | float     | multiband      | spectral     |
        | 1     | double    | b-w            | L            |
        | 2     | double    | b-w            | LA           |
        | 3     | double    | scrgb          | RGB          |
        | 4     | double    | scrgb          | RGBA         |
        | 5+    | double    | multiband      | spectral     |
        | any   | complex   | fourier        | FFT          |
        | any   | dpcomplex | fourier        | FFT          |

    zUnknown format:    z+Number of bands must be a positive integer.	multibandrH   )r]   r.   zb-w)      rgbrI   matrixrJ   grey16rgb16rK   )r/   r0   scrgbr,   r-   fourier)FORMAT_TO_TYPESTR
ValueErrorr   rM   )r2   r1   interps      r   _guess_interpretationrk      s(   \ &&+F8455eS!UQYFGG FF?F, M+ f_F( M' 
6	A:F" M! 
8	F?F M f_F M 
7	A:F M 
&	&F?F M f_F M 
+	+Mr   c                       e Zd Zd Zy)	ImageTypec                     	 t        j                         t	              fd       }|S # t        $ r t        w xY w)Nc                  J    t        j                  j                  g| i |S r   r   r$   r%   )argskwargsr?   s     r   call_functionz,ImageType.__getattr__.<locals>.call_function   s$    ##((????r   )r   getr   AttributeErrorr@   )clsr?   rs   s    ` r   __getattr__zImageType.__getattr__   sO    	!NN4  
$	@ 
	@   	! ! 	!s   - =N)__name__
__module____qualname__rw   rF   r   r   rm   rm      s    r   rm   c                       e Zd ZdZdZed        Z fdZed        Zed        Z	edd       Z
edd       Zed	        Zed
        Zed        Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z fdZ fdZd Zd Zd Zd Zd Z ddZ!ddZ"d Z# fd Z$ e%d!      d"        Z& e%d#      d$        Z' e%d%      d&        Z( e%d'      d(        Z)d) Z*d* Z+d+ Z,d, Z-d- Z.d. Z/d/ Z0d0 Z1d1 Z2d2 Z3d3 Z4d4 Z5d5 Z6d6 Z7d7 Z8d8 Z9d9 Z:d: Z;d; Z<d< Z=d= Z>d> Z?d? Z@d@ ZAdA ZBdB ZCdC ZDdD ZEdE ZFdF ZGdG ZHdH ZIdI ZJdJ ZKdK ZLdL ZMdM ZNdN ZOdO ZPdP ZQdQ ZRdR ZSdS ZTdT ZUdU ZVdV ZWdW ZXdX ZYdY ZZdZ Z[d[ Z\d\ Z]d] Z^d^ Z_d_ Z`d` Zada Zbdb Zcdc Zddd Zede Zfdf Zgdg Zhdh Zidi Zjdj Zkdk Zldl Zmdm Zndn Zodo Zpdp Zqdq Zrdr Zsds Ztdt Zudu Zvdv Zwdw Zxdx Zydy Zzdz Z{d{ Z|d| Z}d} Z~ ed~      d        Zd Z xZS )r   zWrap a VipsImage object.

    )_referencesc                     t        |t              r|S t        |      rt        j                  |      S | j	                  |      S r   )r   r   r   new_from_arraynew_from_image)selfr   s     r   	_imageizezImage._imageize   s<     eU#LE]''..&&u--r   c                 :    g | _         t        t        |   |       y r   )r|   superr   __init__)r   pointer	__class__s     r   r   zImage.__init__  s     eT#G,r   c                 `   t        |       } t        j                  |       }t        |      }t        j                  |       }t        |      }t        j
                  |       }|t        j                  k(  rt        d|        t        |      }t        j                  j                  ||fd|i|S )a  Load an image from a file.

        This method can load images in any format supported by vips. The
        filename can include load options, for example::

            image = pyvips.Image.new_from_file('fred.jpg[shrink=2]')

        You can also supply options as keyword arguments, for example::

            image = pyvips.Image.new_from_file('fred.jpg', shrink=2)

        The full set of options available depend upon the load operation that
        will be executed. Try something like::

            $ vips jpegload

        at the command-line to see a summary of the available options for the
        JPEG loader.

        Loading is fast: only enough of the image is loaded to be able to fill
        out the header. Pixels will only be decompressed when they are needed.

        Args:
            vips_filename (str): The disc file to load the image from, with
                optional appended arguments.

        All loaders support at least the following options:

        Keyword args:
            memory (bool): If set True, load the image via memory rather than
                via a temporary disc file. See :meth:`.new_temp_file` for
                notes on where temporary files are created. Small images are
                loaded via memory by default, use ``VIPS_DISC_THRESHOLD`` to
                set the definition of small.
            access (Access): Hint the expected access pattern for the image.
            fail (bool): If set True, the loader will fail with an error on
                the first serious error in the file. By default, libvips
                will attempt to read everything it can from a damaged image.

        Returns:
            A new :class:`.Image`.

        Raises:
            :class:`.Error`

        zunable to load from file string_options)r   r   vips_filename_get_filenamer	   vips_filename_get_optionsvips_foreign_find_loadr   NULLr   r   r   r$   r%   )vips_filenamerr   r   filenameoptionsr?   s         r   new_from_filezImage.new_from_file  s    ` "-055mD"7+44]C!'*11-@chh3M?CDD'"$$T8 G4;G?EG 	Gr   c                     t        j                  | t        |             }|t        j                  k(  rt        d      t        |      }t        j                  j                  || fd|i|S )a  Load a formatted image from memory.

        This behaves exactly as :meth:`new_from_file`, but the image is
        loaded from the memory object rather than from a file. The memory
        object can be anything that supports the Python buffer protocol.

        Args:
            data (array, bytearray, bytes, buffer): The memory object to
                load the image from.
            options (str): Load options as a string. Use ``""`` for no options.

        All loaders support at least the following options:

        Keyword args:
            access (Access): Hint the expected access pattern for the image.
            fail (bool): If set True, the loader will fail with an error on the
                first serious error in the image. By default, libvips will
                attempt to read everything it can from a damaged image.

        Returns:
            A new :class:`Image`.

        Raises:
            :class:`.Error`

        zunable to load from bufferr   )
r   vips_foreign_find_load_bufferr   r   r   r   r   r   r$   r%   )datar   rr   r   r?   s        r   new_from_bufferzImage.new_from_bufferL  sm    8 88s4yIchh455'"$$T4 G4;G?EG 	Gr   c                 
   t        |       s| g} t        |       }t        | d         }||z  }t        j                  d|      }t	        d|      D ]$  }t	        d|      D ]  }| |   |   ||||z  z   <    & t        j                  ||||      }	|	t        j                  k(  rt        d      t        j                  |	      }
|
j                  t        j                  d|       |
j                  t        j                  d|       |
S )a  Create an image from a list or list of lists.

        A new one-band image with :class:`BandFormat` ``'double'`` pixels is
        created from the array. These image are useful with the libvips
        convolution operator :meth:`Image.conv`.

        Args:
            array (list[list[float]]): Create the image from these values.
                1D arrays become a single row of pixels.
            scale (float): Default to 1.0. What to divide each pixel by after
                convolution.  Useful for integer convolution masks.
            offset (float): Default to 0.0. What to subtract from each pixel
                after convolution.  Useful for integer convolution masks.

        Returns:
            A new :class:`Image`.

        Raises:
            :class:`.Error`

        r   zdouble[]z unable to make image from matrixscaleoffset)r   r   r   newranger    vips_image_new_matrix_from_arrayr   r   r   r   set_typer
   gdouble_type)r   r   r   heightwidthnayr   vir&   s              r   new_from_listzImage.new_from_listp  s    . e}GEUE!HFNGGJ"q&! 	/A1e_ /#(8A;!a%i- /	/ 66ufaK>:;;R v**GU;v**Hf=r   c                 `   t        |t              r| j                  |||      S t        |d      rI|j                  }|d   }|d   }t        |      }|j                  dd      }	|dkD  rt        d      |t        vrt        d| d	      |d
k(  rd}
d}d}n'|dk(  r
|d
   }
d}d}n|dk(  r|\  }}
d}n|dk(  r|\  }}
}t        |   }|	t        |d      r|j                  }nEt        |d      r|j                         }n(t        |d      r|j                         }nt        d      | j                  |
|      }|dk(  r|j                  dd
      }|#|dk(  rt        ||      }|j!                  |      }|S t        |d      r| j#                  |j%                               S t        d      )a  Create a new Image from a list or an array-like object.

        Array-like objects are those which define `__array_interface__` or
        `__array__`. For details about the array interface, see `The Array
        Interface
        <https://numpy.org/doc/stable/reference/arrays.interface.html>`_.

        If `__array_interface__` is not available, `__array__` is used as a
        fallback.

        The behavior for input objects with different dimensions is summarized
        as::

            | array ndim | array shape | Image w | Image h | Image bands |
            |------------|-------------|---------|---------|-------------|
            | 0          | ()          | 1       | 1       | 1           |
            | 1          | (W,)        | W       | 1       | 1           |
            | 2          | (H, W)      | W       | H       | 1           |
            | 3          | (H, W, C)   | W       | H       | C           |


        Args:
            obj (list or object width `__array_interface__` or `__array__`):
                The object to convert to an image.

                If the input object is a list, `Image.new_from_list` is used
                with the given `scale` and `offset`

                If the input object is an array-like object, a new image is
                created from the object's data and shape.  The memory is shared
                except in the following cases:

                - The object's memory is not contiguous.  In this case, a copy
                  is made by attempting to call the object's `tobytes()` method
                  or its `tostring()` method.

                - The object is an array of bools, in which case it is
                  converted to a pyvips uchar image with True values becoming
                  255 and False values becoming 0.

            scale (float): Default to 1.0. **Ignored for non-list inputs**.
                What to divide each pixel by after convolution.  Useful for
                integer convolution masks.
            offset (float): Default to 0.0.  **Ignored for non-list inputs**.
                What to subtract from each pixel after convolution.  Useful for
                integer convolution masks.
            interpretation (str, optional): **Ignored for list inputs** The
                libvips interpretation of the array. If None, the
                interpretation defaults to the pyvips one for
                `Image.new_from_memory`.

                If 'auto', a heuristic is used to determine a best-guess
                interpretation as defined in the `_guess_interpretation`
                function.

                Must be one of None, 'auto', 'error', 'multiband', 'b-w',
                'histogram', 'xyz', 'lab', 'cmyk', 'labq', 'rgb', 'cmc', 'lch',
                'labs', 'srgb', 'yxy', 'fourier', 'rgb16', 'grey16', 'matrix',
                'scrgb', or 'hsv'

        Returns:
            The new image.

        See Also:
            :func:`_guess_interpretation`
        __array_interface__shapetypestrstridesNr_   z array has more than 3 dimensionszconversion from z not supportedr   r]   r.   r   tobytestostringz#object has no .tobytes or .tostringrN      auto)interpretation	__array__z0does not define __array_interface__ or __array__)r   r   r   hasattrr   r   rt   ri   TYPESTR_TO_FORMATr   r   r   	TypeErrornew_from_memory
ifthenelserk   r4   r~   r   )rv   objr   r   r   r   r   r   ndimr   r   r   r2   r1   r   ims                   r   r~   zImage.new_from_array  s   H c4 $$S%883-.''AgJE	lGu:D eeIt,Gax !CDD// #3G9N!KLLqya %',$u&w/F73#7xx 3	*;;=DS*-<<>D#$IJJ$$B %]]3*)!V+%:5&%INWWNW;IS+&%%cmmo66 + , ,r   c                    t        j                  t         j                  |      }t        j                  |       }t        | d      r| j                  n
t        |       }t        j                  ||||||      }|t        j                  k(  rt        d      t        j                  |      }	|	j                  j                  |        |	S )aC  Wrap an image around a memory array.

        Wraps an Image around an area of memory containing a C-style array. For
        example, if the ``data`` memory array contains four bytes with the
        values 1, 2, 3, 4, you can make a one-band, 2x2 uchar image from
        it like this::

            image = Image.new_from_memory(data, 2, 2, 1, 'uchar')

        A reference is kept to the data object, so it will not be
        garbage-collected until the returned image is garbage-collected.

        This method is useful for efficiently transferring images from PIL or
        NumPy into libvips.

        See :meth:`.write_to_memory` for the opposite operation.

        Use :meth:`.copy` to set other image attributes.

        Args:
            data (bytes): A memoryview or buffer object.
            width (int): Image width in pixels.
            height (int): Image height in pixels.
            bands (int): Number of bands.
            format (BandFormat): Band format.

        Returns:
            A new :class:`Image`.

        Raises:
            :class:`.Error`

        nbytesz unable to make image from memory)r
   to_enumformat_typer   from_bufferr   r   r   r   vips_image_new_from_memoryr   r   r   r   r|   append)
r   r   r   r2   r1   format_valuer   r   r   r&   s
             r   r   zImage.new_from_memory(  s    F ~~f&8&8&A//$' 'h 7SY0017161=? >:;;R 
 	  &r   c                    t        j                  | j                        }|t        j                  k(  rt        d      t        |      }t        j                  j                  || fd|i|}|j                  j                  |        |S )a4  Load a formatted image from a source.

        This behaves exactly as :meth:`new_from_file`, but the image is
        loaded from the source rather than from a file.

        Args:
            source (Source): The source to load the image from.
            options (str): Load options as a string. Use ``""`` for no options.

        All loaders support at least the following options:

        Keyword args:
            access (Access): Hint the expected access pattern for the image.
            fail (bool): If set True, the loader will fail with an error on the
                first serious error in the image. By default, libvips will
                attempt to read everything it can from a damaged image.

        Returns:
            A new :class:`Image`.

        Raises:
            :class:`.Error`

        zunable to load from sourcer   )r   vips_foreign_find_load_sourcer   r   r   r   r   r   r$   r%   r|   r   )sourcer   rr   r   r?   r&   s         r   new_from_sourcezImage.new_from_source^  s    4 88Hchh455'"  %%dF H5<H@FH 	  (r   c                     t        j                  t        |             }|t        j                  k(  rt        d      t        j                  |      S )a  Make a new temporary image.

        Returns an image backed by a temporary file. When written to with
        :func:`Image.write`, a temporary file will be created on disc in the
        specified format. When the image is closed, the file will be deleted
        automatically.

        The file is created in the temporary directory. This is set with
        the environment variable ``TMPDIR``. If this is not set, then on
        Unix systems, vips will default to ``/tmp``. On Windows, vips uses
        ``GetTempPath()`` to find the temporary directory.

        vips uses ``g_mkstemp()`` to make the temporary filename. They
        generally look something like ``"vips-12-EJKJFGH.v"``.

        Args:
            format (str): The format for the temp file, for example
                ``"%s.v"`` for a vips format file. The ``%s`` is
                substituted by the file path.

        Returns:
            A new :class:`Image`.

        Raises:
            :class:`.Error`

        zunable to make temp file)r   vips_image_new_temp_filer   r   r   r   r   r   )r1   r   s     r   new_temp_filezImage.new_temp_file  s?    : ..y/@A>233||Br   c                 N   t         j                  dd      |z   j                  | j                        }|j	                  dd| j
                  | j                  d      }|j                  | j                  | j                  | j                  | j                  | j                        }|S )a  Make a new image from an existing one.

        A new image is created which has the same size, format, interpretation
        and resolution as ``self``, but with every pixel set to ``value``.

        Args:
            value (float, list[float]): The value for the pixels. Use a
                single number to make a one-band image; use an array constant
                to make a many-band image.

        Returns:
            A new :class:`Image`.

        Raises:
            :class:`.Error`

        r]   r   r4   )extend)r   xresyresxoffsetyoffset)r   blackr3   r1   embedr   r   r4   r   r   r   r   r   )r   r   pixelr&   s       r   r   zImage.new_from_image  s    $ Q"U*00=Aq$**dkk#)  +

$*=*= $		 $		#'<<#'<<	  1 r   c                     t        j                  | j                        }|t        j                  k(  rt        d      t        j                  |      S )a,  Copy an image to memory.

        A large area of memory is allocated, the image is rendered to that
        memory area, and a new image is returned which wraps that large memory
        area.

        Returns:
            A new :class:`Image`.

        Raises:
            :class:`.Error`

        zunable to copy to memory)r   vips_image_copy_memoryr   r   r   r   r   r   )r   r   s     r   copy_memoryzImage.copy_memory  s>     ,,T\\:>233||Br   c                 b   t        |      }t        j                  |      }t        |      }t        j                  |      }t        |      }t        j
                  |      }|t        j                  k(  rt        d|       t        |      }t        j                  j                  || |fd|i|S )a  Write an image to a file on disc.

        This method can save images in any format supported by vips. The format
        is selected from the filename suffix. The filename can include embedded
        save options, see :func:`Image.new_from_file`.

        For example::

            image.write_to_file('fred.jpg[Q=95]')

        You can also supply options as keyword arguments, for example::

            image.write_to_file('fred.jpg', Q=95)

        The full set of options available depend upon the load operation that
        will be executed. Try something like::

            $ vips jpegsave

        at the command-line to see a summary of the available options for the
        JPEG saver.

        Args:
            vips_filename (str): The disc file to save the image to, with
                optional appended arguments.

        Other arguments depend upon the save operation.

        Returns:
            None

        Raises:
            :class:`.Error`

        zunable to write to file r   )r   r   r   r	   r   vips_foreign_find_saver   r   r   r   r   r$   r%   )r   r   rr   r   r   r   r?   s          r   write_to_filezImage.write_to_file  s    H "-055mD"7+44]C!'*11-@chh2=/BCC'"$$T4 G4;G?EG 	Gr   c                 (   t        |      }t        j                  |      }t        j                  |t
        j                        }t        j                  |      }t        |      }t        j                  }t        dd      r=t        j                          t        j                  |      }t        j                          |t        j                  k7  r`t        |      }t        j                   j#                         }t        j$                  j&                  || |fd|i| |j)                  d      }|S t        j*                  |      }|t        j                  k(  rt-        d      t        |      }t        j$                  j&                  || fd|i|}|S )a  Write an image to memory.

        This method can save images in any format supported by vips. The format
        is selected from the suffix in the format string. This can include
        embedded save options, see :func:`Image.write_to_file`.

        For example::

            data = image.write_to_buffer('.jpg[Q=95]')

        You can also supply options as keyword arguments, for example::

            data = image.write_to_buffer('.jpg', Q=95)

        The full set of options available depend upon the load operation that
        will be executed. Try something like::

            $ vips jpegsave_buffer

        at the command-line to see a summary of the available options for the
        JPEG saver.

        Args:
            format_string (str): The suffix, plus any string-form arguments.

        Other arguments depend upon the save operation.

        Returns:
            A byte string.

        Raises:
            :class:`.Error`

           	   r   blobzunable to write to buffer)r   r   r   r   gcr   g_freer   r	   r   r   vips_error_freezevips_foreign_find_save_targetvips_error_thawr   r   Targetnew_to_memoryr$   r%   rt   vips_foreign_find_save_bufferr   )	r   format_stringrr   r   r   r   r?   targetbuffers	            r   write_to_bufferzImage.write_to_buffer  sZ   F "-066}E66(HOO444]C!'*((Aq!&&(<<XFG$$&chhg&D]]002F!!$f D18D<BDZZ'F  <<XFG#(("788g&D%%**4 M:AMEKMF r   c                    t        |      }t        j                  |      }t        |      }t        j                  |      }|t
        j                  k(  rt        d      t        |      }t        j                  j                  || |fd|i|S )a  Write an image to a target.

        This method will write the image to the target in the format
        specified in the suffix in the format string. This can include
        embedded save options, see :func:`Image.write_to_file`.

        For example::

            image.write_to_target(target, '.jpg[Q=95]')

        You can also supply options as keyword arguments, for example::

            image.write_to_target(target, '.jpg', Q=95)

        The full set of options available depend upon the save operation that
        will be executed. Try something like::

            $ vips jpegsave_target

        at the command-line to see a summary of the available options for the
        JPEG saver.

        Args:
            target (Target): The target to write the image to
            format_string (str): The suffix, plus any string-form arguments.

        Other arguments depend upon the save operation.

        Returns:
            None

        Raises:
            :class:`.Error`

        zunable to write to targetr   )r   r   r   r	   r   r   r   r   r   r   r$   r%   )r   r   r   rr   r   r   r?   s          r   write_to_targetzImage.write_to_targetR  s    H "-044]C!'*88Gchh344'"$$T4 G4;G?EG 	Gr   c                 "   t        j                  d      }t        j                  | j                  |      }|t         j
                  k(  rt        d      t        j                  |t        j                        }t        j                  ||d         S )a	  Write the image to a large memory array.

        A large area of memory is allocated, the image is rendered to that
        memory array, and the array is returned as a buffer.

        For example, if you have a 2x2 uchar image containing the bytes 1, 2,
        3, 4, read left-to-right, top-to-bottom, then::

            buf = image.write_to_memory()

        will return a four byte buffer containing the values 1, 2, 3, 4.

        Returns:
            buffer

        Raises:
            :class:`.Error`

        zsize_t *zunable to write to memoryr   )r   r   r   vips_image_write_to_memoryr   r   r   r   r   r   r   )r   psizer   s      r   write_to_memoryzImage.write_to_memory  si    ( 
#55dllEJchh344&&(//2zz'58,,r   c                 x    t        j                  | j                  |j                        }|dk7  rt        d      y)a]  Write an image to another image.

        This function writes ``self`` to another image. Use something like
        :func:`Image.new_temp_file` to make an image that can be written to.

        Args:
            other (Image): The :class:`Image` to write to,

        Returns:
            None

        Raises:
            :class:`.Error`

        r   zunable to write to imageN)r   vips_image_writer   r   )r   r'   results      r   writezImage.write  s6      **4<<GQ;233 r   c                 B    t        j                  | j                         y)a  Drop caches on an image, and any downstream images.

        This method drops all pixel caches on an image and on all downstream
        images. Any operations which depend on this image, directly or
        indirectly, are also dropped from the libvips operation cache.

        This method can be useful if you wrap a libvips image around an area
        of memory with :meth:`.new_from_memory` and then change some bytes
        without libvips knowing.

        Returns:
            None

        N)r   vips_image_invalidate_allr   r   s    r   
invalidatezImage.invalidate  s     	**4<<8r   c                 D    t        j                  | j                  |       y)zEnable progress reporting on an image.

        When progress reporting is enabled, evaluation of the most downstream
        image from this image will report progress using the ::preeval, ::eval,
        and ::posteval signals.

        N)r   vips_image_set_progressr   )r   progresss     r   set_progresszImage.set_progress  s     	((x@r   c                 D    t        j                  | j                  |       y)zKill processing of an image.

        Use this to kill evaluation of an image. You can call it from one of
        the progress signals, for example. See :meth:`.set_progress`.

        N)r   vips_image_set_killr   )r   kills     r   set_killzImage.set_kill  s     	$$T\\48r   c                     t        dd      st        t        |   |      }|dk7  r|S t	        j
                  | j                  t        |            S )aV  Get the GType of an item of metadata.

        Fetch the GType of a piece of metadata, or 0 if the named item does not
        exist. See :class:`GValue`.

        Args:
            name (str): The name of the piece of metadata to get the type of.

        Returns:
            The ``GType``, or 0.

        Raises:
            None

        r      r   )r   r   r   
get_typeofr   vips_image_get_typeofr   r   )r   r?   gtyper   s      r   r   zImage.get_typeof  sG    $  1%%1$7Ez--dllIdOLLr   c                 4   t        dd      s+t        t        |   |      }|dk7  rt        t        |   |      S t               }t        j                  | j                  t        |      |j                        }|dk7  rt        d|       |j	                         S )a  Get an item of metadata.

        Fetches an item of metadata as a Python value. For example::

            orientation = image.get('orientation')

        would fetch the image orientation.

        Args:
            name (str): The name of the piece of metadata to get.

        Returns:
            The metadata item as a Python value.

        Raises:
            :class:`.Error`

        r   r   r   zunable to get )r   r   r   r   rt   r
   r   vips_image_getr   r   r   )r   r?   r   gvr   r   s        r   rt   z	Image.get  s    *  1%%1$7EzUD-d33X((y)+5Q;./00vvxr   c                 `   g }t        dd      rt        j                  | j                        }d}||   t        j
                  k7  rSt        ||         }|j                  |       t        j                  ||          |dz  }||   t        j
                  k7  rSt        j                  |       |S )zcGet a list of all the metadata fields on an image.

        Returns:
            [string]

        r   r   r   r]   )
r   r   vips_image_get_fieldsr   r   r   r   r   r   r   )r   namesr   rY   r?   s        r   
get_fieldszImage.get_fields  s     Aq!224<<@EA(chh&!%(+T"a)Q	 (chh&
 OOE"r   c                     t               }|j                  |       |j                  |       t        j                  | j
                  t        |      |j
                         y)a  Set the type and value of an item of metadata.

        Sets the type and value of an item of metadata. Any old item of the
        same name is removed. See :class:`GValue` for types.

        Args:
            gtype (int): The GType of the metadata item to create.
            name (str): The name of the piece of metadata to create.
            value (mixed): The value to set as a Python value. It is
                converted to the ``gtype``, if possible.

        Returns:
            None

        Raises:
            None

        N)r
   r   setr   vips_image_setr   r   )r   r   r?   r   r  s        r   r   zImage.set_type)  s@    & X
E
uiorzzJr   c                 t    | j                  |      }|dk(  rt        d| d      | j                  |||       y)a  Set the value of an item of metadata.

        Sets the value of an item of metadata. The metadata item must already
        exist.

        Args:
            name (str): The name of the piece of metadata to set the value of.
            value (mixed): The value to set as a Python value. It is
                converted to the type of the metadata item, if possible.

        Returns:
            None

        Raises:
            :class:`.Error`

        r   zmetadata item z2 does not exist - use set_type() to create and setN)r   r   r   )r   r?   r   r   s       r   r  z	Image.setA  sF    $ %A:. /< < = =eT5)r   c                 Z    t        j                  | j                  t        |            dk7  S )zRemove an item of metadata.

        The named metadata item is removed.

        Args:
            name (str): The name of the piece of metadata to remove.

        Returns:
            None

        Raises:
            None

        r   )r   vips_image_remover   r   r   r?   s     r   removezImage.removeY  s$     ))$,,	$HAMMr   c                    | j                   dk(  st        d      | j                  dv }|s| j                  nd| j                  z  }| t        | j                      }| j                         }t        j                  ||      D cg c]  }t        |       }}|r9|D cg c],  }t        d|d      D cg c]  }||   d||dz      z  z    c}. }}}|S c c}w c c}w c c}}w )znReturn a single-band image as a list of lists.

        Returns:
            list of lists of values

        r]   z.tolist only implemented for single-band imagesrf   r.   r   y              ?)
r2   NotImplementedErrorr1   r   FORMAT_TO_PYFORMATr   structiter_unpackr   r   )	r   
is_complexrow_elsrowfmtbufrowlstrrY   s	            r   tolistzImage.tolistj  s     zzQ% '; < < [[$<<
$.$**A

N9/<=>""$$*$6$6vs$CDStCyDD! /4Aw.BCAaD2a!f9$C !C ! 
 E D !s   C C 4CC C c                    ddl }|j                  | j                         t        | j                           j                  | j                  | j                  | j                        }| j                  dk(  rB|j                  d      }| j                  dk(  r!| j                  dk(  r|j                  d      }||j                  |      }|S )a  Conversion to a NumPy array.

        Args:
            dtype (str or numpy dtype, optional) The dtype to use for the
                numpy array. If None, the default dtype of the image is used
                as defined the global `FORMAT_TO_TYPESTR` dictionary.

        Returns:
            numpy.ndarray: The array representation of the image.
                * Single-band images lose their channel axis.
                * Single-pixel single-band images are converted to a 0D array.

        See https://numpy.org/devdocs/user/basics.dispatch.html for more
        details.

        This enables a :class:`Image` to be used where a numpy array is
        expected, including in plotting and conversion to other array
        container types (pytorch, JAX, dask, etc.), for example.

        `numpy` is a runtime dependency of this function.

        See Also `Image.new_from_array` for the inverse operation. #TODO
        r   Ndtyper]   )axis)r   r]   )numpy
frombufferr   rh   r1   reshaper   r   r2   squeezeastype)r   r  nparrs       r   r   zImage.__array__  s    0 	 MM$..0 1$++ >  @WT[[$**djj9 	 ::?++2+&CzzQ4;;!#3kkvk.**U#C
r   c                 &    | j                  |      S )a  Convenience function to allow numpy conversion to be at the end
        of a method chain.

        This mimics the behavior of pytorch: ``arr = im.op1().op2().numpy()``

        numpy is a runtime dependency of this function.

        Args:
            dtype (str or numpy dtype): The dtype to use for the numpy array.
                If None, the default dtype of the image is used.

        Returns:
            numpy.ndarray: The image as a numpy array.

        See Also:

            - :meth:`.__array__`
            - `FORMAT_TO_TYPESTR`: Global dictionary mapping libvips format
              strings to numpy dtype strings.
        r  )r   )r   r  s     r   r!  zImage.numpy  s    * ~~E~**r   c                 8   | j                   dk(  rH| j                  dk  r9| j                  dk  r*| j                  dk(  r| j	                         }t        |      S d| j                   d| j                   d| j                   d| j                   d| j                    d	S )
Nrb      r]   z<pyvips.Image r    z, z bands, >)r   r   r   r2   r  reprr1   )r   r   s     r   __repr__zImage.__repr__  s    8+

Rb 

aKKME;$TZZL$++a}Bzzl(4+>+>*?qB Cr   c                     dk(  r& j                  d      dk7  r j                  d      S ydk(  r& j                  d      dk7  r j                  d      S yt        t                 dk7  rt        t                 S 	 t	        j                         t               fd       }|S # t
        $ r t        w xY w)a}  Divert unknown names to libvips.

        Unknown attributes are first looked up in the image properties as
        accessors, for example::

            width = image.width

        and then in the libvips operation table, where they become method
        calls, for example::

            new_image = image.invert()

        Use :func:`get` to fetch image metadata.

        A ``__getattr__`` on the metatype lets you call static members in the
        same way.

        Args:
            name (str): The name of the piece of metadata to get.

        Returns:
            Mixed.

        Raises:
            :class:`.Error`

        r   r         ?r           c                  L    t        j                  j                  g| i |S r   rp   )rq   rr   r?   r   s     r   rs   z(Image.__getattr__.<locals>.call_function*  s&    ##((tEdEfEEr   )r   rt   r   r   r   r   ru   r@   )r   r?   rs   r   s   `` r   rw   zImage.__getattr__  s    > 7?w'1,xx((8x(A-xx)) (.!3)$//	!NN4  
$	F 
	F   	! ! 	!s   B/ /B?zuse Image.get() insteadc                 $    | j                  |      S r   )rt   r  s     r   	get_valuezImage.get_value2  s    xx~r   zuse Image.set() insteadc                 (    | j                  ||       y r   )r  )r   r?   r   s      r   	set_valuezImage.set_value6  s    ur   zuse Image.scale insteadc                     | j                   S r   )r   r   s    r   	get_scalezImage.get_scale:  s    zzr   zuse Image.offset insteadc                     | j                   S r   )r   r   s    r   
get_offsetzImage.get_offset>  s    {{r   c                     | S r   rF   r   s    r   	__enter__zImage.__enter__D      r   c                      y r   rF   )r   typer   	tracebacks       r   __exit__zImage.__exit__G  s    r   c                 :   t        |t              rt        | j                        |   }d}nct        |t              rCt        | j                        |   }t        |      dk(  rt        d      |d   }t        |      }nt        |t              r|st        d      t        d |D              st        d |D              st        d      t        |d   t              rit        |      | j                  k7  rt        d      t        |      D cg c]
  \  }}|s	| }}}t        |      }|dk(  rt        d	      |dk(  rN|d   }nHt        | j                        }|D cg c]  }||   	 }}t        |      }|dk(  r|d   }nt        d
      |dk(  r| j                        S t        |t              r"|j                  dk(  r| j                  |      S D cg c]  }| j                  |       }}|d   j                  |dd       S c c}}w c c}w c c}w )ag  Overload [] to pull out band elements from an image.

        The following arguments types are accepted:

        * int::

            green = rgb_image[1]

          Will make a new one-band image from band 1 (the middle band).

        * slice::

            last_two = rgb_image[1:]
            last_band = rgb_image[-1]
            middle_few = multiband[1:-2]
            reversed  = multiband[::-1]
            every_other = multiband[::2]
            other_every_other = multiband[1::2]

        * list of int::

            # list of integers
            desired_bands = [1, 2, 2, -1]
            four_band = multiband[desired_bands]

        * list of bool::

            wanted_bands = [True, False, True, True, False]
            three_band = five_band[wanted_bands]

        In the case of integer or slice arguments, the semantics of slicing
        exactly match those of slicing `range(self.bands)`.

        In the case of list arguments, the semantics match those of numpy's
        extended slicing syntax. Thus, lists of booleans must have as many
        elements as there are bands in the image.

        r]   r   zempty slicez
empty listc              3   @   K   | ]  }t        |      t        k(    y wr   )r?  rM   rP   r   s     r   rS   z$Image.__getitem__.<locals>.<genexpr>  s     41Q34   c              3   @   K   | ]  }t        |      t        k(    y wr   )r?  boolrD  s     r   rS   z$Image.__getitem__.<locals>.<genexpr>  s     5AQ45rE  z)list must contain only ints or only boolsz,boolean index must have same length as bandszempty boolean indexz>argument must be an int, slice, list of ints, or list of bools)r   N)r   rM   r   r2   slicer   
IndexErrorr   allrG  	enumerateextract_bandstepbandjoin)r   argrY   r   band_seqr   	all_bandsr2   s           r   __getitem__zImage.__getitem__J  s   N c3djj!#&AAU#TZZ(-H8}! //AHAT" .. 444555 !LMM#a&$'s8tzz)$ &7 8 8 +4C.>$!QAA>>M6$%:;;6 A!$**-	256QIaL66M6 A > ? ? 6$$Q''U#A$$Q!$,, 4<<aT&&q)<E<8$$U12Y//7 ? 7" =s   
HH!HHc                 &    | j                  ||      S )a  Fetch a pixel value.

        Args:
            x (int): The x coordinate to fetch.
            y (int): The y coordinate to fetch.

        Returns:
            Pixel as an array of floating point numbers.

        Raises:
            :class:`.Error`

        )getpoint)r   r   r   s      r   __call__zImage.__call__  s     }}Q""r   c                 |    t        |t        j                        r| j                  |      S | j	                  d|      S )Nr]   )r   r   r   addlinearr   r'   s     r   __add__zImage.__add__  s/    eV\\*88E?";;q%((r   c                 $    | j                  |      S r   )rZ  rY  s     r   __radd__zImage.__radd__      ||E""r   c                     t        |t        j                        r| j                  |      S | j	                  dt        d |            S )Nr]   c                     d| z  S Nr  rF   r   s    r   <lambda>zImage.__sub__.<locals>.<lambda>  s
    "q& r   )r   r   r   subtractrX  r!   rY  s     r   __sub__zImage.__sub__  s8    eV\\*=='';;q%(8%"@AAr   c                 &    | j                  d|      S r`  )rX  rY  s     r   __rsub__zImage.__rsub__  s    {{2u%%r   c                 h    t        |t              r| j                  |      S | j                  |d      S )Nr   )r   r   multiplyrX  rY  s     r   __mul__zImage.__mul__  s,    eU#=='';;ua((r   c                 $    | j                  |      S r   )ri  rY  s     r   __rmul__zImage.__rmul__  r]  r   c                     t        |t        j                        r| j                  |      S | j	                  t        d |      d      S )Nc                     d| z  S Nr0  rF   ra  s    r   rb  zImage.__div__.<locals>.<lambda>  
    sQw r   r   )r   r   r   dividerX  r!   rY  s     r   __div__zImage.__div__  s8    eV\\*;;u%%;;u%6>BBr   c                     | dz  |z  S r`  rF   rY  s     r   __rdiv__zImage.__rdiv__  s    
e##r   c                 $    | j                  |      S r   )rq  rY  s     r   __truediv__zImage.__truediv__  r]  r   c                 $    | j                  |      S r   )rs  rY  s     r   __rtruediv__zImage.__rtruediv__  s    }}U##r   c                     t        |t        j                        r| j                  |      j	                         S | j                  t        d |      d      j	                         S )Nc                     d| z  S rn  rF   ra  s    r   rb  z$Image.__floordiv__.<locals>.<lambda>  ro  r   r   )r   r   r   rp  floorrX  r!   rY  s     r   __floordiv__zImage.__floordiv__  sJ    eV\\*;;u%++--;;u%6>BHHJJr   c                 .    | dz  |z  j                         S r`  )rz  rY  s     r   __rfloordiv__zImage.__rfloordiv__  s    u$++--r   c                 z    t        |t        j                        r| j                  |      S | j	                  |      S r   )r   r   r   	remainderremainder_constrY  s     r   __mod__zImage.__mod__  s0    eV\\*>>%((''..r   c                     t        | |dd      S )Nmath2powr*   rY  s     r   __pow__zImage.__pow__      $w66r   c                     t        | |dd      S )Nr  wopr  rY  s     r   __rpow__zImage.__rpow__  r  r   c                 "    | j                         S r   )absr   s    r   __abs__zImage.__abs__  s    xxzr   c                     t        | |dd      S )Nbooleanlshiftr  rY  s     r   
__lshift__zImage.__lshift__      $y(;;r   c                     t        | |dd      S )Nr  rshiftr  rY  s     r   
__rshift__zImage.__rshift__  r  r   c                     t        | |dd      S )Nr  andr  rY  s     r   __and__zImage.__and__      $y%88r   c                 $    | j                  |      S r   )r  rY  s     r   __rand__zImage.__rand__  r]  r   c                     t        | |dd      S )Nr  orr  rY  s     r   __or__zImage.__or__  s    $y$77r   c                 $    | j                  |      S r   )r  rY  s     r   __ror__zImage.__ror__  s    {{5!!r   c                     t        | |dd      S )Nr  eorr  rY  s     r   __xor__zImage.__xor__  r  r   c                 $    | j                  |      S r   )r  rY  s     r   __rxor__zImage.__rxor__  r]  r   c                     d| z  S r`  rF   r   s    r   __neg__zImage.__neg__  s    Dyr   c                     | S r   rF   r   s    r   __pos__zImage.__pos__  r=  r   c                     | dz  S r`  rF   r   s    r   
__invert__zImage.__invert__  s    byr   c                     t        | |dd      S )N
relationalmorer  rY  s     r   __gt__zImage.__gt__       $|V<<r   c                     t        | |dd      S )Nr  moreeqr  rY  s     r   __ge__zImage.__ge__#      $|X>>r   c                     t        | |dd      S )Nr  lessr  rY  s     r   __lt__zImage.__lt__&  r  r   c                     t        | |dd      S )Nr  lesseqr  rY  s     r   __le__zImage.__le__)  r  r   c                 $    |yt        | |dd      S )NFr  equalr  rY  s     r   __eq__zImage.__eq__,  s    =$|W==r   c                 $    |yt        | |dd      S )NTr  noteqr  rY  s     r   __ne__zImage.__ne__3  s    =$|W==r   c                 $    | j                  d      S )z@Return the largest integral value not greater than the argument.rz  roundr   s    r   rz  zImage.floor:  s    zz'""r   c                 $    | j                  d      S )z>Return the smallest integral value not less than the argument.ceilr  r   s    r   r  z
Image.ceil>      zz&!!r   c                 $    | j                  d      S )z"Return the nearest integral value.rintr  r   s    r   r  z
Image.rintB  r  r   c                 $    | j                  d      S )zAND image bands together.r  bandboolr   s    r   bandandzImage.bandandF      }}U##r   c                 $    | j                  d      S )zOR image bands together.r  r  r   s    r   bandorzImage.bandorJ  s    }}T""r   c                 $    | j                  d      S )zEOR image bands together.r  r  r   s    r   bandeorzImage.bandeorN  r  r   c                 ,    | D cg c]  }| c}S c c}w )z-Split an n-band image into n separate images.rF   )r   r   s     r   	bandsplitzImage.bandsplitR  s     a   s   	c                     t        |t              s|g}|s| S t        d |D        d      }|| j                  |      S t        j
                  j                  d| g|z         S )z-Append a set of images or constants bandwise.c              3   T   K   | ]   }t        |t        j                        s| " y wr   )r   r   r   rD  s     r   rS   z!Image.bandjoin.<locals>.<genexpr>`  s'      A",Q"?  As   &(NrN  )r   r   nextbandjoin_constr   r$   r%   )r   r'   
non_numbers      r   rN  zImage.bandjoinV  sr    %&GE K  Ae A 
 &&u--##((dVe^DDr   c                     t        | |dd      S )Nr  atan2r  rY  s     r   r  zImage.atan2i  s    $w88r   c                     t        dd      rt        j                  | j                        S | j	                  d      dk7  r| j                  d      S dS )a  Get the number of pages in an image file, or 1.

        This is the number of pages in the file the image was loaded from, not
        the number of pages in the image.

        To get the number of pages in an image, divide the image height by
        the page height.
        r   zn-pagesr   r]   )r   r   vips_image_get_n_pagesr   r   rt   r   s    r   get_n_pageszImage.get_n_pagesl  sQ     Aq!224<<@@ ??9-2 88I& :89:r   c                 $   t        dd      rt        j                  | j                        S | j	                  d      dk7  r| j                  d      }n| j                  }|dkD  r#|| j                  k  r| j                  |z  dk(  r|S | j                  S )z=Get the page height in a many-page image, or height.
        r   page-heightr   )r   r   vips_image_get_page_heightr   r   rt   r   )r   page_heights     r   get_page_heightzImage.get_page_height{  s     Aq!66t||DD}-2"hh}5"kkQt{{*KK+-2""{{"r   c           	          | j                         }t        d| j                  |      D cg c]   }| j                  d|| j                  |      " c}S c c}w )z@Split an N-page image into a list of N separate images.
        r   )r  r   r   cropr   )r   r  r   s      r   	pagesplitzImage.pagesplit  sR     **,q$++{;= 		!Q

K8 = 	= =s   %Ac                     t        |t              s|g}dt        |      z   }t        j	                  | g|z   d      }|j                         }|j                  t        j                  d|j                  |z         |S )z}Join a set of pages vertically to make a multipage image.

        Also sets the page-height property on the result.
        r]   )acrossr  )
r   r   r   r   	arrayjoinr4   r   r
   	gint_typer   )r   r'   n_pagesr&   s       r   pagejoinzImage.pagejoin  si    
 %&GEc%j.q9

v''w8NOr   c                    t        |t              s|g}t        |t              s|g}|D cg c]&  }t        j                  t        j                  |      ( }}t        j                  j                  d| g|z   |fi |S c c}w )z.Composite a set of images with a set of modes.	composite)r   r   r
   r   blend_mode_typer   r$   r%   )r   r'   moderr   r   s        r   r  zImage.composite  s    %&GE$%6D DHHav55q9HH$$[4&5.$ /'-/ 	/ Is   +A>c                 r    t        |t              s|g}t        j                  j                  d| g|z   fi |S )z&Band-wise rank filter a set of images.bandrank)r   r   r   r$   r%   )r   r'   rr   s      r   r  zImage.bandrank  s7    %&GE$$Z$%J6JJr   c                 L    | j                  dd      \  }}|d   }|d   }|||fS )z,Return the coordinates of the image maximum.Tr   r   r   r   )maxr   rR   optsr   r   s        r   maxposzImage.maxpos  5    ((TT(*4II!Qwr   c                 L    | j                  dd      \  }}|d   }|d   }|||fS )z,Return the coordinates of the image minimum.Tr  r   r   )minr  s        r   minposzImage.minpos  r  r   c                 $    | j                  d      S )z(Return the real part of a complex image.real
complexgetr   s    r   r  z
Image.real      v&&r   c                 $    | j                  d      S )z-Return the imaginary part of a complex image.imagr  r   s    r   r  z
Image.imag  r   r   c                     t        d |       S )z/Return an image converted to polar coordinates.c                 $    | j                  d      S )Npolarr,   ra  s    r   rb  zImage.polar.<locals>.<lambda>  s    AIIg$6 r   r8   r   s    r   r  zImage.polar  s    6==r   c                     t        d |       S )z5Return an image converted to rectangular coordinates.c                 $    | j                  d      S )Nrectr  ra  s    r   rb  zImage.rect.<locals>.<lambda>  s    AIIf$5 r   r  r   s    r   r
  z
Image.rect  s    5t<<r   c                 $    | j                  d      S )z)Return the complex conjugate of an image.conjr  r   s    r   r  z
Image.conj  s    ||F##r   c                 $    | j                  d      S )z'Return the sine of an image in degrees.sinmathr   s    r   r  z	Image.sin      yyr   c                 $    | j                  d      S )z)Return the cosine of an image in degrees.cosr  r   s    r   r  z	Image.cos  r  r   c                 $    | j                  d      S )z*Return the tangent of an image in degrees.tanr  r   s    r   r  z	Image.tan  r  r   c                 $    | j                  d      S )z/Return the inverse sine of an image in degrees.asinr  r   s    r   r  z
Image.asin      yy  r   c                 $    | j                  d      S )z1Return the inverse cosine of an image in degrees.acosr  r   s    r   r  z
Image.acos  r  r   c                 $    | j                  d      S )z2Return the inverse tangent of an image in degrees.atanr  r   s    r   r  z
Image.atan  r  r   c                 $    | j                  d      S )z2Return the hyperbolic sine of an image in radians.sinhr  r   s    r   r  z
Image.sinh  r  r   c                 $    | j                  d      S )z4Return the hyperbolic cosine of an image in radians.coshr  r   s    r   r   z
Image.cosh  r  r   c                 $    | j                  d      S )z5Return the hyperbolic tangent of an image in radians.tanhr  r   s    r   r"  z
Image.tanh  r  r   c                 $    | j                  d      S )z:Return the inverse hyperbolic sine of an image in radians.asinhr  r   s    r   r$  zImage.asinh      yy!!r   c                 $    | j                  d      S )z<Return the inverse hyperbolic cosine of an image in radians.acoshr  r   s    r   r'  zImage.acosh  r%  r   c                 $    | j                  d      S )z=Return the inverse hyperbolic tangent of an image in radians.atanhr  r   s    r   r)  zImage.atanh  r%  r   c                 $    | j                  d      S )z#Return the natural log of an image.logr  r   s    r   r+  z	Image.log  r  r   c                 $    | j                  d      S )z#Return the log base 10 of an image.log10r  r   s    r   r-  zImage.log10  r%  r   c                 $    | j                  d      S )zReturn e ** pixel.expr  r   s    r   r/  z	Image.exp  r  r   c                 $    | j                  d      S )zReturn 10 ** pixel.exp10r  r   s    r   r1  zImage.exp10  r%  r   c                 &    | j                  |d      S )z!Erode with a structuring element.erodemorphr   masks     r   r3  zImage.erode  s    zz$((r   c                 &    | j                  |d      S )z"Dilate with a structuring element.dilater4  r6  s     r   r9  zImage.dilate  s    zz$))r   c                 4    | j                  ||||z  dz        S )zsize x size median filter.r.   )rank)r   sizes     r   medianzImage.median#  s    yytdTkQ%677r   c                 $    | j                  d      S )zFlip horizontally.
horizontalflipr   s    r   fliphorzImage.fliphor'  s    yy&&r   c                 $    | j                  d      S )zFlip vertically.verticalr@  r   s    r   flipverzImage.flipver+  s    yy$$r   c                 $    | j                  d      S )zRotate 90 degrees clockwise.d90rotr   s    r   rot90zImage.rot90/  s    xxr   c                 $    | j                  d      S )zRotate 180 degrees.d180rH  r   s    r   rot180zImage.rot1803      xxr   c                 $    | j                  d      S )zRotate 270 degrees clockwise.d270rH  r   s    r   rot270zImage.rot2707  rN  r   c                 @    t        j                  | j                        S )z'True if the image has an alpha channel.)r   vips_image_hasalphar   r   s    r   hasalphazImage.hasalpha;  s    ++DLL99r   c                     | j                   dk(  s| j                   dk(  rd}n| j                   dk(  rd}nd}| j                  |      S )zAdd an alpha channel.rc   rd   i  re   r0  r   )r   rN  )r   	max_alphas     r   addalphazImage.addalpha?  sI    (*d.A.AW.LI  G+II}}Y''r   r   c                 T   ||| fD ]  }t        |t        j                        s n t        |t        j                        st        j                  |      }t        |t        j                        st        j                  |      }t        j                  j
                  d| ||fi |S )Nr   )r   r   r   r   r$   r%   )r   in1in2rr   match_images        r   r   zImage.ifthenelseK  s    d+ 	K+v||4	 #v||,//+s3C#v||,//+s3C$$\4cLVLLr   c                 D    t        j                  j                  d| fi |S )a  Scale an image to 0 - 255.

        This is the libvips ``scale`` operation, renamed to avoid a clash with
        the ``scale`` for convolution masks.

        Keyword args:
            exp (float): Exponent for log scale.
            log (bool): Switch to turn on log scaling.

        Returns:
            A new :class:`Image`.

        Raises:
            :class:`.Error`

        r   rp   )r   rr   s     r   
scaleimagezImage.scaleimageX  s"    " $$Wd=f==r   )r0  r1  )r0  r1  Nr   )rx   ry   rz   r;   	__slots__staticmethodr   r   r   r   r   classmethodr~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rt   r  r   r  r  r  r   r!  r.  rw   rG   r4  r6  r8  r:  r<  rA  rR  rU  rZ  r\  rd  rf  ri  rk  rq  rs  ru  rw  r{  r}  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rz  r  r  r  r  r  r  rN  r  r  r  r  r  r  r  r  r  r  r  r  r
  r  r  r  r  r  r  r  r  r   r"  r$  r'  r)  r+  r-  r/  r1  r3  r9  r=  rB  rE  rJ  rM  rQ  rT  rW  r@   r   r]  __classcell__)r   s   @r   r   r      sq    !I . .- <G <G| !G !GF * *X H, H,T 3 3j & &P      D: ,1Gf@D/Gb-84(9"A9M2 D*K0*0N"n+Z+.C<@ *+ , *+ , *+ , +, -
\0~#$)#B&)#
C$#$K./77<<9#8"9#=?=?>>#""$#$!E&9:#$= /K''>=$   !!!!!!""" " ")*8'%  :( l
M 
M>r   r   )	metaclass)r   r  r   r   r   r   r   r   r   r	   r
   r   r   r   r   r!   r*   r8   r@   rG   r   dictitemsrh   r  rk   r?  rm   
VipsObjectr   __all__rF   r   r   <module>rg     s      F F F
.
 D H
 $#"$#"!#%$(
*  F,=,C,C,EFF   #! #"! " #!$#&	( Nd (z>F z>z3 )r   