+
    UBil6                       ^ RI Ht ^ RIt^ RIt^ RIt^ RIHt ^RIHtH	t	H
t
Ht Rt]'       d   ^ RIHt ^ RIHt  ! R R	4      tR
 R ltR R ltR R lt ! R R]	P                  4      tR R ltR R lt]P.                  ! ]P0                  ]]4       ]P2                  ! ]P0                  ]4       ]P4                  ! ]P0                  . RO4       ]P6                  ! ]P0                  R4       R# )    )annotationsN)cast)Image	ImageFileImagePalette_binaryF)Callable)IOc                  r    ] tR t^tRtRR R lltR R ltR R ltR R	 ltR
 R lt	R R lt
R R ltRtR# )	BoxReaderzq
A small helper class to read fields stored in JPEG2000 header boxes
and to easily step into and read sub-boxes.
c               $    V ^8  d   QhRRRRRR/# )   fp	IO[bytes]lengthintreturnNone )formats   ":/usr/lib/python3.14/site-packages/PIL/Jpeg2KImagePlugin.py__annotate__BoxReader.__annotate__%   s!     # #9 #c #4 #    c                	@    Wn         V^ 8  V n        W n        RV n        R# )r   Nr   
has_lengthr   remaining_in_box)selfr   r   s   &&&r   __init__BoxReader.__init__%   s     A+ "r   c                    V ^8  d   QhRRRR/# )r   	num_bytesr   r   boolr   )r   s   "r   r   r   +   s      3 4 r   c                	    V P                   '       d3   V P                  P                  4       V,           V P                  8  d   R # V P                  ^ 8  d   WP                  8*  # R# )FT)r   r   tellr   r   )r    r$   s   &&r   	_can_readBoxReader._can_read+   sH    ???tww||~	9DKKG  A% 5 555r   c                    V ^8  d   QhRRRR/# )r   r$   r   r   bytesr   )r   s   "r   r   r   5   s      S U r   c                	2   V P                  V4      '       g   R p\        V4      hV P                  P                  V4      p\	        V4      V8  d   RV R\	        V4       R2p\        V4      hV P                  ^ 8  d   V ;P                  V,          un        V# )zNot enough data in headerzExpected to read z bytes but only got .)r(   SyntaxErrorr   readlenOSErrorr   )r    r$   msgdatas   &&  r   _read_bytesBoxReader._read_bytes5   s    ~~i((-Cc""ww||I&t9y %i[0DSYKqQC#,  1$!!Y.!r   c                    V ^8  d   QhRRRR/# )r   field_formatstrr   ztuple[int | bytes, ...]r   )r   s   "r   r   r   C   s     1 1 10G 1r   c                	|    \         P                  ! V4      pV P                  V4      p\         P                  ! W4      # N)structcalcsizer4   unpack)r    r7   sizer3   s   &&  r   read_fieldsBoxReader.read_fieldsC   s/    |,%}}\00r   c                   V ^8  d   QhRR/# )r   r   r   r   )r   s   "r   r   r   H   s     1 1I 1r   c                	|    V P                   pV P                  V4      p\        \        P                  ! V4      V4      # r:   )r   r4   r   ioBytesIO)r    r>   r3   s   &  r   
read_boxesBoxReader.read_boxesH   s3    $$%D)400r   c                   V ^8  d   QhRR/# )r   r   r%   r   )r   s   "r   r   r   M   s      d r   c                	    V P                   '       d9   V P                  P                  4       V P                  ,           V P                  8  # R # )T)r   r   r'   r   r   )r    s   &r   has_next_boxBoxReader.has_next_boxM   s2    ???77<<>D$9$99DKKGGr   c                   V ^8  d   QhRR/# )r   r   r+   r   )r   s   "r   r   r   S   s      u r   c                	   V P                   ^ 8  d5   V P                  P                  V P                   \        P                  4       RV n         \        \        \        \        3,          V P                  R4      4      w  rV^8X  d*   \        \        V P                  R4      ^ ,          4      p^pM^pW8  g   V P                  W,
          4      '       g   Rp\        V4      hW,
          V n         V# )r   z>I4sz>QzInvalid header lengthr   )r   r   seekosSEEK_CURr   tupler   r+   r?   r(   r.   )r    lboxtboxhlenr2   s   &    r   next_box_typeBoxReader.next_box_typeS   s      1$GGLL..< " %U
+T-=-=f-EF
19T--d3A67DDD;dnnT[99)Cc"" $r   r   N)r   )__name__
__module____qualname____firstlineno____doc__r!   r(   r4   r?   rE   rI   rT   __static_attributes__r   r   r   r   r      s/    
#1
1
 r   r   c                    V ^8  d   QhRRRR/# )r   r   r   r   ztuple[tuple[int, int], str]r   )r   s   "r   r   r   i   s      ) (C r   c                   V P                  ^4      p\        P                  ! V4      pWP                  V^,
          4      ,           p\        P                  ! RV4      w  r$rVrx   rWW,
          Wh,
          3pV
^8X  d@   \        P                  ! RV^&4      pV^ ,          ^,          ^,           ^8  d   RpW3# Rp W3# V
^8X  d   RpW3# V
^8X  d   RpW3# V
^8X  d   RpW3# Rp\        V4      h)	zParse the JPEG 2000 codestream to extract the size and component
count from the SIZ marker segment, returning a PIL (size, mode) tuple.z>HHIIIIIIIIHz>BI;16LLARGBRGBAz"unable to determine J2K image mode)r/   r   i16ber;   unpack_fromr.   )r   hdrlsizsizrsizxsizysizxosizyosiz_csizr>   ssizmoder2   s   &              r   _parse_codestreamrq   i   s    ''!*C==D
q!
!C=C=O=O>:DE!Q1 L$,'Dqy!!$R0GdNa!#D : D : 
 : 
 : 

 : 3#r   c               (    V ^8  d   QhRRRRRRRR/# )r   numr   denomexpr   zfloat | Noner   )r   s   "r   r   r      s(     5 5S 5 53 5< 5r   c                ^    V^ 8X  d   R# ^V ,          ^
V,          ,          RV,          ,          # )zConvert JPEG2000's (numerator, denominator, exponent-base-10) resolution,
calculated as (num / denom) * 10^exp and stored in dots per meter,
to floating-point dots per inch.Ni'  r   )rs   rt   ru   s   &&&r   _res_to_dpirw      s*     z#IS!eem44r   c                    V ^8  d   QhRRRR/# )r   r   r   r   zetuple[tuple[int, int], str, str | None, tuple[float, float] | None, ImagePalette.ImagePalette | None]r   )r   s   "r   r   r      s"     b. b.b.b.r   c                L   \        V 4      pRpRpVP                  4       '       dU   VP                  4       pVR8X  d   VP                  4       pM,VR8X  g   KG  VP	                  R4      ^ ,          R8X  g   Kf  RpKj  Vf   Q hRpRpRpRpRp	Rp
VP                  4       '       Edj   VP                  4       pVR8X  d   VP	                  R4      w  rr\        V\        4      '       g   Q h\        V\        4      '       g   Q h\        V\        4      '       g   Q hW3pV^8X  d   V^,          ^8  d   R	pK  V^8X  d   R
pK  V^8X  d   RpK  V^8X  d   RpK  V^8X  d   RpK  K  VR8X  d6   V^8X  d/   VP	                  R4      w  p rV^8X  d   V^8X  d   RpEK
  EK  EK  VR8X  EdL   VR9   EdD   VP	                  R4      w  pp\        V\        4      '       g   Q h\        V\        4      '       g   Q h^ pVP	                  RRV,          ,           4       F&  p\        V\        4      '       g   Q hVV8  g   K$  TpK(  	  V^8:  d   \        P                  ! V^8X  d   RMR4      p
\        V4       Fn  p. pVP	                  RRV,          ,           4       F,  p\        V\        4      '       g   Q hVP                  V4       K.  	  V
P                  \        V4      4       Kp  	  VR
8X  d   RMRpEK`  EKc  VR8X  g   EKm  VP                  4       pVP                  4       '       g   EK  VP                  4       pVR8X  g   K2  VP	                  R4      w  pppppp\        V\        4      '       g   Q h\        V\        4      '       g   Q h\        V\        4      '       g   Q h\        V\        4      '       g   Q h\        V\        4      '       g   Q h\        V\        4      '       g   Q h\        VVV4      p\        VVV4      p Ve	   V e   VV 3p	EK  Ve   Vf   Rp!\        V!4      hWVW9V
3# )zParse the JP2 header box to extract size, component count,
color space information, and optionally DPI information,
returning a (size, mode, mimetype, dpi) tuple.Ns   jp2hs   ftypz>4ss   jpx z	image/jpxs   ihdrz>IIHBr^   r_   r`   ra   rb   s   colrz>BBBICMYKs   pclrz>HB>BPPAs   res s   rescz>HHHHBBzMalformed JP2 header)r_   r`   )r   rI   rT   rE   r?   
isinstancer   r   rangeappendgetcolorrP   rw   r.   )"r   readerheadermimetyperR   r>   rp   bpcncdpipaletteheightwidthmethrm   enumcsnenpcmax_bitdepthbitdepthicolorvaluerestresvrcnvrcdhrcnhrcdvrcehrcehresvresr2   s"   &                                 r   _parse_jp2_headerr      s    r]FFH




##%7?&&(FW_!!%(+w6&DD
C	B
CG




##%7?%+%7%7%@"F2fc****eS))))c3''''?DQwC$J!+qqqq W_q!'!3!3G!<D!QqyVr\ *yW_!4((/GBb#&&&&c3''''L"..scCi/@A!(C0000l*#+L B q &33cQhFERrA')E!'!3!3C394E!F)%5555U+ "G $$U5\2 # #ckst ! W_##%C""$$((*7?9<9S6D$dD$%dC0000%dC0000%dC0000%dC0000%dC0000%dC0000&tT48D&tT48D'D,<#Tl|t|$#xg--r   c                     a  ] tR t^tRtRtR R ltR R lt]R V 3R ll4       t	]	P                  R	 R
 l4       t	R R ltRtV ;t# )Jpeg2KImageFileJPEG2000zJPEG 2000 (ISO 15444)c                   V ^8  d   QhRR/# r   r   r   r   )r   s   "r   r   Jpeg2KImageFile.__annotate__   s     2
 2
t 2
r   c           
     	   V P                   P                  ^4      pVR8X  d<   RV n        \        V P                   4      w  V n        V n        V P                  4        EM!WP                   P                  ^4      ,           pVR8X  d   RV n        \        V P                   4      pVw  V n        V n        V n        q0n	        Ve   W0P                  R&   V P                   P                  ^4      P                  R4      '       ds   V P                   P                  ^4      p\        P                  ! V4      pV P                   P                  V^,
          \        P                   4       V P                  4        MRp\#        V4      h^ V n        ^ V n        R
pR
p V P                   P)                  4       p\        P*                  ! V4      P,                  p\6        P8                  ! R	RT P:                  ,           ^ T P                  T P$                  T P&                  Yu34      .T n        R#   \.         d    R
p T P                   P1                  4       pT P                   P                  ^ \2        P4                  4       T P                   P1                  4       pT P                   P                  T4        L  \.         d    R
p  Li ; ii ; i)      OQj2k      jP  

jp2Nr   s   jp2cOQznot a JPEG 2000 filejpeg2kr   r   r   )r   r/   codecrq   _size_mode_parse_commentr   custom_mimetyper   infoendswithr   rc   rM   rN   rO   r.   _reducelayersfilenofstatst_size	Exceptionr'   rC   SEEK_ENDr   _Tiler>   tile)	r    sigr   r   re   r   r2   fdposs	   &        r   _openJpeg2KImageFile._open   s	   ggll1o%%DJ%6tww%?"DJ
!Q'C=="
*4773RXO
DJ(<c<?'*IIe$77<<#,,-DEE'',,q/C$]]3/FGGLL!R[[9''),!#&&	!BXXb\))F OO"T\\4;;C	
	  	BggllnQ,S! 	s+   :H   J>.A9J))J:6J>9J::J>c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   r   2  s     6 6 6r   c                	    V P                   P                  ^4      pV'       g   R# V^,          pVR9   d   R# V P                   P                  ^4      p\        P                  ! V4      pV^d8X  d9   V P                   P                  V^,
          4      R,          V P                  R&   R# V P                   P                  V^,
          \        P                  4       K  )T:r   NNcommentN)      )r   r/   r   rc   r   rM   rN   rO   )r    markertypre   r   s   &    r   r   Jpeg2KImageFile._parse_comment2  s    WW\\!_F)Cl"'',,q/C]]3'Fd{'+ww||FQJ'?'C		)$VaZ5r   c                   V ^8  d   QhRR/# )r   r   zVCallable[[int | tuple[int, int], tuple[int, int, int, int] | None], Image.Image] | intr   )r   s   "r   r   r   E  s     	. 	.		.r   c                	@   < V P                   ;'       g    \        SV `  # r:   )r   superreduce)r    	__class__s   &r   r   Jpeg2KImageFile.reduceD  s     ||--uw~-r   c                    V ^8  d   QhRRRR/# )r   r   r   r   r   r   )r   s   "r   r   r   Q  s      C D r   c                	    Wn         R # r:   )r   )r    r   s   &&r   r   r   P  s    r   c                   V ^8  d   QhRR/# )r   r   zImage.core.PixelAccess | Noner   )r   s   "r   r   r   T  s     . .3 .r   c                	   V P                   '       Ed>   V P                  '       Ed+   ^V P                  ,          pV^,	          p\        V P                  ^ ,          V,           V,          4      \        V P                  ^,          V,           V,          4      3V n        V P                   ^ ,          p\        V^,          \        4      '       g   Q hV^,          ^ ,          V P                  V P                  V^,          ^,          V^,          ^,          3p\        P                  ! V^ ,          RV P                  ,           V^,          V4      .V n         \        P                  P                  V 4      # )   r   )r   r   r   r>   r   r   rP   r   r   r   load)r    poweradjusttt3s   &    r   r   Jpeg2KImageFile.loadT  s    999%EaZFTYYq\F*e34TYYq\F*e34DJ 		!AadE****A$q'4<<ad1gqtAwGB"1v		/A1Q4LMDI""''--r   )r   r   r   r   r   r   r   r   )rV   rW   rX   rY   r   format_descriptionr   r   propertyr   setterr   r[   __classcell__)r   s   @r   r   r      sO    F02
h6$ 	. 	. ]] . .r   r   c                    V ^8  d   QhRRRR/# )r   prefixr+   r   r%   r   )r   s   "r   r   r   f  s      E d r   c                $    V P                  R4      # )r   )r   r   )
startswith)r   s   &r   _acceptr   f  s    F r   c               (    V ^8  d   QhRRRRRRRR/# )	r   imzImage.Imager   r   filenamezstr | bytesr   r   r   )r   s   "r   r   r   p  s4     @T @Tk @Ty @TK @TD @Tr   c                $   V P                   p\        V\        4      '       d   VP                  4       pVP	                  R 4      '       g   VP                  RR4      '       d   RpMRpVP                  RR4      pVP                  RR4      pVP                  RR4      pVP                  R	R
4      pVP                  RR4      p	V	ed   \        V	\        \        34      '       d;   \        ;QJ d    R V	 4       F  '       d   K   RM	  RM! R V	 4       4      '       g   Rp
\        V
4      hVP                  R^ 4      pVP                  RR4      pVP                  RR4      pVP                  RR4      pVP                  RR4      pVP                  RR4      pVP                  R^ 4      pVP                  RR4      pVP                  R4      p\        V\        4      '       d   VP                  4       pVP                  RR4      pRp\        VR4      '       d    VP                  4       pVVVVV	VVVVVVVVVVV3V n        \        P                  ! W\        P                   ! RRV P"                  ,           ^ V4      .4       R#   \         d    Rp Lhi ; i)s   .j2kno_jp2Fr   r   offsetNtile_offset	tile_sizequality_moderatesquality_layersc              3  N   "   T F  p\        V\        \        34      x  K  	  R # 5ir:   )r   r   float).0quality_layers   & r   	<genexpr>_save.<locals>.<genexpr>  s!      
IWJ}sEl33s   #%Tz,quality_layers must be a sequence of numbersnum_resolutionscodeblock_sizeprecinct_sizeirreversibleprogressionLRCPcinema_modenomctsignedr   pltr   r   r   r   )encoderinfor   r8   encoder   getlistrP   all
ValueErrorhasattrr   r   encoderconfigr   _saver   r>   )r   r   r   r   kindr   r   r   r   r   r2   r   	cblk_sizer   r   r   r   r   r   r   r   r   s   &&&                   r   r	  r	  p  sO   >>D(C  ??$!!TXXh%>%>XXh%F((=$/Kd+I88NG4LXX.5N!>D%=11C 
IW
CCC 
IW
 
 
 =ohh0!4O)40IHH_d3M88NE2L((=&1K((=$/K
((5!
CXXh&Fhhy!G'3.."
((5%
 C	Br8	B
 	
!B& OOBY__Xv7GDQRS-  	B	s   I? ?JJz	image/jp2)z.jp2z.j2kz.jpcz.jpfz.jpxz.j2c)
__future__r   rC   rN   r;   typingr    r   r   r   r   TYPE_CHECKINGcollections.abcr	   r
   r   rq   rw   r   r   r   r	  register_openr   register_saveregister_extensionsregister_mimer   r   r   <module>r     s     # 	 	   5 5(G GT>5b.Ri.i)) i.X@TN   O**OW E   O**E 2   L   O**K 8r   