o
    îÇhX  ã                   @   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                   @   s6   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 : float
            The width of the canvas in logical units
        height : float
            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
   Úvector_rendererÚraster_renderer_classÚbbox_inches_restore© r   úu/var/www/html/construction_image-detection-poc/venv/lib/python3.10/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
rG| j ¡ }| j ||j| j | j ||j | j | j |ddd… ¡ d| _| j| j_| jr`t| j| j| jƒ}|| _dS 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
   ÚnpÚasarrayr   Úbuffer_rgbar   Ú_get_nonzero_slicesÚsizeÚnew_gcÚ
draw_imageÚstartr   Ústopr   r   r   )r   r   ÚimgÚslice_yÚslice_xÚ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!   Ú
matplotlibr   Úbackend_aggr   Úmatplotlib._tight_bboxr   r   r   r   r   r   Ú<module>   s
    