
    nj                         S SK r S SKJr  S rS rS rS r\ R                  4S jr\	S:X  a#  \ R                  " \" \ R                  5      5        gg)	    N)gdalc                  "   [        S5        [        S5        [        S5        [        S5        [        S5        [        S5        [        S5        [        S5        [        S5        [        S	5        [        S
5        [        S5        [        S5        g)NzIUsage:  dump_jp2 [-dump_gmljp2 out.xml|-] [-dump_crsdictionary out.xml|-]z9                 [-extract_all_xml_boxes filename_prefix]z                 test.jp2 z0Options (all are exclusive of the regular dump):zC-dump_gmljp2: Writes the content of the GMLJP2 box in the specifiedz<              file, or on the console if "-" syntax is used.zV-dump_crsdictionary: Writes the content of the GML CRS dictionary box in the specifiedzC                     file, or on the console if "-" syntax is used.zY-extract_all_xml_boxes: Extract all XML boxes in separate files, and prefix each filenamezX                        with the supplied prefix. gmljp2://xml/ link will be replaced byz/                        links to on-disk files.   )print     X/var/www/html/pdf-tiff/venv/lib/python3.13/site-packages/osgeo_utils/samples/dump_jp2.pyUsager   &   s    	
UV	
EF	
%&	"I	
<=	"I	
OP	
HI	` 

OP	c 
b 

;<r	   c                 @   [         R                  " U 5      nUc  [        SU -  5        gUR                  S5      nUc  [        SU -  5        gUS:X  a  [        US   5        g[	        US5      nUR                  US   5        UR                  5         [        SU-  5        g)	NCannot open %s   zxml:gml.root-instancezNo GMLJP2 content found in %s-r   wtz+INFO: %s written with content of GMLJP2 box)r   Openr   GetMetadataopenwriteclose)filename
out_gmljp2dsmddfs        r
   dump_gmljp2r   >   s    	8	B	z)*
..0
1C
{-89Sc!f 	 T"	A		;jHIr	   c           	         [         R                  " U 5      nUc  [        SU -  5        gUR                  5       nUc  / nU H  nUR	                  S5      (       d  M  UR                  U5      S   nSU;   d  SU;   d  M=  US:X  a  [        U5          g[        US5      nUR                  U5        UR                  5         [        S	U< S
USS  < S35          g   [        SU -  5        g)Nr   r   xml:r   z<Dictionaryz<gml:Dictionaryr   r   zINFO: z- written with content of CRS dictionary box (   )z%No CRS dictionary content found in %s)	r   r   r   GetMetadataDomainList
startswithr   r   r   r   )r   out_crsdictionaryr   mdd_listdomainmdd_itemr   s          r
   dump_crsdictionaryr&   Q   s    	8	B	z)*'')HV$$~~f-a0H(,=,I$+(O  .5AGGH%GGI,fQRj:    

1H
<=r	   c                 ,   [         R                  " U 5      nUc  [        SU -  5        gUR                  5       nUc  / nU GH=  nUR	                  S5      (       d  M  UR                  U5      S   nUSS  nUS:X  a  SnX-   nSnSn	 UR                  S	U	5      n
U
S:  a  XU	S  -  nOUR                  S
U
5      nUR                  SU
5      nSnUS:  a  US:  a  X:  a  UnOUnOUS:  a  UnOUS:  a  UnUS:  a.  UU
[        S	5      -   U nSU-   U;  a  [        SU< SU< S35        XX -  nX-  nU
[        S	5      -   n	M  [        US5      nUR                  U5        UR                  5         [        SU-  5        GM@     U(       d  [        S5        gg)Nr   r   r   r   r   zgml.root-instancezgml_root_instance.gmlr   zgmljp2://xml/ "zWarning: box z reference box z, but the latter is not foundr   zINFO: %s writtenzNo XML box found)r   r   r   r    r!   r   findlenr   r   r   )r   prefixr   r#   r$   r%   boxnameout_filenameout_contentposnew_posend_gmljp2_link_spaceend_gmljp2_link_double_quoteend_gmljp2_linkreferenced_boxr   s                   r
   extract_all_xml_boxesr7   m   s   	8	B	z)*'')HV$$~~f-a0HQRjG--1!+L KC"--=Q;CD>1K )1c7(C%/7}}S'/J,"$(A-2NRS2S,K*?*F*a/&;O1Q6&BO"a'%-#o"66&N /@&8
 44%O 44? B \4(AGGK GGI$|34_ b  !r	   c                    SnS nS nS nS nU[        U 5      :  a  X   S:X  a)  U[        U 5      S-
  :  a
  [        5       $ XS-      nUS-   nOX   S:X  a)  U[        U 5      S-
  :  a
  [        5       $ XS-      nUS-   nOXX   S:X  a)  U[        U 5      S-
  :  a
  [        5       $ XS-      nUS-   nO'X   S   S:X  a
  [        5       $ Uc  X   nO
[        5       $ US-   nU[        U 5      :  a  M  Uc
  [        5       $ U(       d  U(       d  U(       aF  U(       a  [        XR5      S:w  a  gU(       a  [        XS5      S:w  a  gU(       a  [	        XT5      S:w  a  gg[
        R                  " US/5      n[        U5        g)Nr   z-dump_gmljp2z-dump_crsdictionaryz-extract_all_xml_boxesr   r   zALL=YES)r,   r   r   r&   r7   r   GetJPEG2000StructureAsStringr   )argvir   r"   extract_all_xml_boxes_prefixr   ss          r
   mainr>      s   	AJ#' H
c$i-7n$CIM!w!eJAAW--CIM!w $UAAW00CIM!w+/A;(AAWQZ37NwH7NE/ c$i-2 w&*F80A5!(>!C'$XLPQQ
  --hDar	   __main__)sysosgeor   r   r   r&   r7   r:   r>   __name__exitr   r	   r
   <module>rD      sU   B  0&8<~ hh 0f zHHT#((^ r	   