
    nj                         S SK r S SKrS SKJr  S rS rS r\ R                  4S jr\	S:X  a#  \ R                  " \" \ R                  5      5        gg)    N)gdalc                    [         R                  " U [         R                  " X5      5      n[         R                  " U [         R                  " X5      5      nUn[         R                  " XC5      n[         R                  " U R
                  S   U R
                  S   45      n[         R                  " XcU-
  U45      nX4-
  [         R                  " Xs5      -  n	X0-
  U-  n
X1-
  U-  nX2-
  U-  n[         R                  " X05      n[         R                  " X15      n[         R                  " X25      n[         R                  " U R
                  S   U R
                  S   45      n[         R                  " UUSU-   U
-
  45      n[         R                  " UUSU
-   U-
  45      n[         R                  " UUX-
  45      n[         R                  " US-  S5      n[         R                  " UX/5      nU$ )Nr      g      @g       @      @      ?)
numpymaximumminimumequalonesshapechoosezerosmodasarray)rgbmaxcmincvminc_eq_maxcr   maxc_minus_mincsrcgcbc	maxc_is_r	maxc_is_g	maxc_is_bhhsvs                     Y/var/www/html/pdf-tiff/venv/lib/python3.13/site-packages/osgeo_utils/samples/hsv_merge.py
rgb_to_hsvr$   1   s   ==EMM!/0D==EMM!/0DA;;t*L ::qwwqz1771:./Dll<+t1DEO	d11A
(o	%B
(o	%B
(o	%BD$ID$ID$IQWWQZ,-AYC"HrM 23AYC"HrM 23AYBG-A		!c'3A
--A	
"CJ    c                    U S   nU S   nU S   nUS-  R                  [        5      nUS-  U-
  nUSU-
  -  nUSX%-  -
  -  nUSUSU-
  -  -
  -  nUR                  X7XfX5      n	UR                  XX7Xf5      n
UR                  XfXX75      n[        R                  " XU/5      R                  [        R
                  5      nU$ )Nr   r      r   r   )astypeintr   r   r   uint8)r"   r!   r   r   ifpqtr   r   r   rgbs                r#   
hsv_to_rgbr1   Z   s    AAAAAA 
SA	
SAA	S1WA	S15[A	S1a= !A	qQ"A	qQ"A	qQ"A
--q	
"
)
)%++
6CJr%   c                      [        S5        g)Na5  Usage: hsv_merge.py [-q] [-of format] src_color src_greyscale dst_color

where src_color is a RGB or RGBA dataset,
      src_greyscale is a greyscale dataset (e.g. the result of gdaldem hillshade)
      dst_color will be a RGB or RGBA dataset using the greyscale as the
      intensity for the color dataset.
r'   )print r%   r#   Usager5   t   s    		 r%   c           	      2	   [         R                  " U 5      n U c  gSnS nS nS nSnSnU[        U 5      :  a[  X   nUS:X  a
  US-   nX   nO1US:X  d  US:X  a  SnO"Uc  X   nOUc  X   nOUc  X   nO
[        5       $ US-   nU[        U 5      :  a  M[  Uc
  [        5       $ [         R                  n[         R
                  " U[         R                  5      n	[         R
                  " U[         R                  5      n
U
R                  S	:w  a  U
R                  S
:w  a  [        S5        g[         R                  " U5      nUR                  UU
R                  U
R                  U
R                  U5      nUR                  U	R                  5       5        UR                  U	R!                  5       5        U
R#                  S5      nU
R#                  S5      nU
R#                  S	5      nU
R                  S
:X  a  U
R#                  S
5      nOS nU	R#                  S5      nUR%                  5       nUR&                  UR&                  :w  d  UR(                  UR(                  :w  a  [        S5        g[+        UR&                  5       GH  nUR-                  SUUR(                  SUR(                  S5      nUR-                  SUUR(                  SUR(                  S5      nUR-                  SUUR(                  SUR(                  S5      nUR-                  SUUR(                  SUR(                  S5      n[/        UUU5      nUb4  [0        R2                  " UU5      n[0        R4                  " UUUS   45      nOUn[0        R6                  " US   US   U/5      n[9        U5      nUR#                  S5      nUR;                  US   SU5        UR#                  S5      nUR;                  US   SU5        UR#                  S	5      nUR;                  US   SU5        UbN  UR-                  SUUR(                  SUR(                  S5      nUR#                  S
5      nUR;                  USU5        U(       a  GM  [         R<                  " [?        US-   5      UR&                  -  5        GM     g)Nr   GTiffFr   z-ofz-qz-quietT      zESource image does not appear to have three or four bands as required.r'   z4Color and hillshade must be the same size in pixels.) r   GeneralCmdLineProcessorlenr5   GDT_ByteOpenGA_ReadOnlyRasterCountr3   GetDriverByNameCreateRasterXSizeRasterYSizeSetProjectionGetProjectionSetGeoTransformGetGeoTransformGetRasterBandGetNoDataValueYSizeXSizerangeReadAsArrayr$   r   r   r   r   r1   
WriteArrayTermProgress_nocbfloat)argvdriver_namesrc_color_filenamesrc_greyscale_filenamedst_color_filenamequietr+   argdatatypehilldatasetcolordataset
out_driver
outdatasetrBandgBandbBandaBandhillbandhillbandnodatavalue	rScanline	gScanline	bScanlinehillScanliner"   equal_to_nodatar   hsv_adjusted	dst_coloroutband	aScanlines                                 r#   mainrl      s>   ''-D|K!E 	
A
c$i-g%<AA'KD[C8OE'!%#+%)W"'!%7NE+ c$i-. !w}}H))2D4D4DEK99/1A1ABL 1$)A)AQ)FUV %%k2J""      J [6689{::<= &&q)E&&q)E&&q)E1$**1-((+H"113 	x~~%5;;(..+HDE 8>>"%%aHNNAx~~qQ	%%aHNNAx~~qQ	%%aHNNAx~~qQ	++Aq(..!X^^UVW Iy9 *#kk,8KLO_|SV.DEAA }}c!fc!fa%89 |,	 **1-9Q<A.**1-9Q<A.**1-9Q<A.))!Q8>>STUI ..q1Gy!Q/ u""E!a%L8>>$ACM #P r%   __main__)sysr   osgeor   r$   r1   r5   rQ   rl   __name__exitr4   r%   r#   <module>rr      sT   D   R4
 hh wt zHHT#((^ r%   