a
    s=icW  ã                   @   s>   d dl Zd dlmZ ddlmZ d dlmZ G dd„ dƒZdS )é    N)Úcbooké   )ÚRendererAgg)Úprocess_figure_for_rasterizingc                   @   s2   e Zd ZdZddd„Zdd„ Zdd„ Zd	d
„ ZdS )ÚMixedModeRenderera&  
    A helper class to implement a renderer that switches between
    vector and raster drawing.  An example may be a PDF writer, where
    most things are drawn with PDF vector commands, but some very
    complex objects, such as quad meshes, are rasterised and then
    output as images.
    Nc                 C   sN   |du rt }|| _|| _|| _|| _|| _d| _|| _|j| _|| _	|| _
dS )a%  
        Parameters
        ----------
        figure : `matplotlib.figure.Figure`
            The figure instance.
        width : scalar
            The width of the canvas in logical units
        height : scalar
            The height of the canvas in logical units
        dpi : float
            The dpi of the canvas
        vector_renderer : `matplotlib.backend_bases.RendererBase`
            An instance of a subclass of
            `~matplotlib.backend_bases.RendererBase` that will be used for the
            vector drawing.
        raster_renderer_class : `matplotlib.backend_bases.RendererBase`
            The renderer class to use for the raster drawing.  If not provided,
            this will use the Agg backend (which is currently the only viable
            option anyway.)

        N)r   Ú_raster_renderer_classÚ_widthÚ_heightÚdpiÚ_vector_rendererÚ_raster_rendererÚfigureÚ_figdpiÚ_bbox_inches_restoreÚ	_renderer)Úselfr   ÚwidthÚheightr
   Zvector_rendererZraster_renderer_classZbbox_inches_restore© r   úr/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/lib/python3.9/site-packages/matplotlib/backends/backend_mixed.pyÚ__init__   s    zMixedModeRenderer.__init__c                 C   s   t | j|ƒS )N)Úgetattrr   )r   Úattrr   r   r   Ú__getattr__>   s    zMixedModeRenderer.__getattr__c                 C   sR   | j | j_ | jr$t| j| jƒ}|| _|  | j| j  | j| j  | j ¡| _| j| _dS )z›
        Enter "raster" mode.  All subsequent drawing commands (until
        `stop_rasterizing` is called) will be drawn with the raster backend.
        N)	r
   r   r   r   r   r   r	   r   r   )r   Úrr   r   r   Ústart_rasterizingG   s    
ÿÿz#MixedModeRenderer.start_rasterizingc              	   C   sÀ   | j | _| j| j }t | j ¡ ¡}t 	|d ¡\}}|||f }|j
rŽ| j ¡ }| j ||j| j | j ||j | j | j |ddd… ¡ d| _| j| j_| jr¼t| j| j| jƒ}|| _dS )z»
        Exit "raster" mode.  All of the drawing that was done since
        the last `start_rasterizing` call will be copied to the
        vector backend by calling draw_image.
        ).é   Néÿÿÿÿ)r   r   r	   r
   ÚnpZasarrayr   Zbuffer_rgbar   Z_get_nonzero_slicesÚsizeZnew_gcZ
draw_imageÚstartr   Ústopr   r   r   )r   r   ZimgZslice_yZslice_xZcropped_imgÚgcr   r   r   r   Ústop_rasterizingW   s*    
ü
þz"MixedModeRenderer.stop_rasterizing)NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r#   r   r   r   r   r      s     þ
.	r   )	Únumpyr   Z
matplotlibr   Zbackend_aggr   Zmatplotlib._tight_bboxr   r   r   r   r   r   Ú<module>   s   