
    (eI                     N   d dl Z d dlZd dlmZ d dlZd dlmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZmZ d dlmZmZ ej(                  Z	 	 	 dd	e	d
ee	   de	dededee   fdZd Z G d de      Ze j6                  fdZedk(  r# e j<                   ee j6                               yy)    N)Optional)gdal)PathLikeOrStr)get_color_palette)get_color_table)GDALArgumentParser
GDALScript)GetOutputDriverForopen_dssrc_filenamepct_filenamedst_filenameband_number	out_bandsdriver_namec                 j   t        |       }|t        d|  d      |j                  |      }|t        |      }t	        j
                  |      }|t        d| d      |Yt        |      }	|	j                         r2|j                         }
|j                         }|	j                  |
|       t        |	      }n |j                         }|t        |  d      |j                         }t        j                  |      t        j                  |      t        j                  |      t        j                  |      dz  g}|<t!        |      D ].  }|j#                  |      }t!        d      D ]  }||   ||   |<    0 |j%                         dk(  r|}nd	}t	        j
                  d
      }|j'                  ||j(                  |j*                  |      }|j-                  |j/                                |j1                  |j3                                |j5                         dkD  r.|j7                  |j9                         |j;                                t=        d       t!        |j*                        D ]  }|j?                  d||j(                  d      }t!        |      D ]B  }||   }t        j@                  ||      }|j                  |dz         jC                  |d|       D t=        |dz   |j*                  z          ||k(  r|}|S |jE                  |xs d|      }d }|jG                  |       |S )NzUnable to open  "z" driver not registered.z has no color table      gtiffztemp.tifGTiffr   g           g      ? )$r   	ExceptionGetRasterBandr
   r   GetDriverByNamer   has_percents
GetMinimumapply_percentr   GetRasterColorTableGetCountnparangeonesrangeGetColorEntrylowerCreateRasterXSizeRasterYSizeSetProjectionGetProjectionSetGeoTransformGetGeoTransformGetGCPCountSetGCPsGetGCPsGetGCPProjectionprogressReadAsArraytake
WriteArray
CreateCopyDelete)r   r   r   r   r   r   src_dssrc_band
dst_driverpalmin_valmax_valctct_sizelookupientryctif_filenamegtiff_drivertif_dsiYsrc_dataiBandband_lookupdst_datadst_dss                              5/usr/lib/python3/dist-packages/osgeo_utils/pct2rgb.pypct2rgbrP   2   s#    \"F~/,q9::##K0H
 (6%%k2J!K=(@ABB
 -))+G))+Ggw/S!))+:|n,?@AAkkmG
		'
		'
		'
3	F 
~w 	(A$$Q'E1X ($Qxq	!(	( g%#!''0L  f((&*<*<iF --/0
61134av~~')@)@)BC
 SMF&&' 	2''2v/A/A1E9% 	HE -Kww{H5H  +66xBG		H 	"s(f0001	2 |# M	 &&|'9r6BL)M    c                  @    	 t        di | }|dfS # t        $ r Y yw xY w)Nr   )Nr    )rP   r   )kwargsdss     rO   doitrV      s/    v1u s    	c                   0     e Zd Z fdZdefdZd Z xZS )PCT2RGBc                 d    t         |           d| _        t        j                  d      | _        y )Nz+Convert an 8bit paletted image to 24bit RGBz            This utility will convert a pseudo-color band on the input file
            into an output RGB file of the desired format.)super__init__titletextwrapdedentdescription)self	__class__s    rO   r[   zPCT2RGB.__init__   s+    B
#??>
rQ   returnc           	      @   | j                   }|j                  dddd       |j                  dddd	d
d       |j                  ddddt        dd       |j                  ddt        d       |j                  dt        d       |j                  dt        d       |S )Nz-ofr   gdal_formatzSelect the output format. if not specified, the format is guessed from the extension. Use the short format name. Only output formats supporting pseudo-color tables should be used.)destmetavarhelpz-rgbar   store_constr      z8Generate a RGBA file (instead of a RGB file by default).)re   actionconstdefaultrg   z-bz-bandr   bandr   z&Band to convert to RGB, defaults to 1.)re   rf   typerl   rg   z-pctr   a%  Extract the color table from <palette_file> instead of getting it from <source_file>. Can be used to have a consistent color table for multiple files. The palette file must be either a raster file in a GDAL supported format with a palette or a color file in a supported format (txt, qml, qlr).)re   rn   rg   r   zThe input file.)rn   rg   r   z)The output RGB file that will be created.)parseradd_argumentintstr)r`   argvro   s      rO   
get_parserzPCT2RGB.get_parser   s    !Q	 	 	
 	 K 	 	
 	9 	 	
 	M	 	 	
 	N;LM+V 	 	
 rQ   c                     t        di |S )NrS   )rP   )r`   rT   s     rO   rV   zPCT2RGB.doit   s       rQ   )__name__
__module____qualname__r[   r   rt   rV   __classcell__)ra   s   @rO   rX   rX      s    
/"4 /b!rQ   rX   c                 4    t               j                  |       S )N)rX   main)rs   s    rO   r{   r{      s    9>>$rQ   __main__)r   ri   N)sysr]   typingr   numpyr#   osgeor   osgeo_utils.auxiliary.baser   #osgeo_utils.auxiliary.color_paletter   !osgeo_utils.auxiliary.color_tabler   #osgeo_utils.auxiliary.gdal_argparser   r	   osgeo_utils.auxiliary.utilr
   r   TermProgress_nocbr4   rq   rr   rP   rV   rX   rs   r{   rv   exitrS   rQ   rO   <module>r      s   D      4 A = N B!! !%ee=)e  e 	e
 e #eP<!j <!~ hh   zCHHT#((^ rQ   