+
    f0iO              	       T   ^ RI t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIHt ^ RIt	^ RI
Ht ^ RIHt ^ RIHt ^ RIHt ^ RIHt ^ RIHtHtHtHtHt ]! R4      RJt]! R4      RJt]P@                  ! ]!4      t"R t#]$! ]PJ                  PL                  ]PJ                  PN                  ]PP                  ! ]PJ                  PN                  RR	7      ]#R
7      t)Rt*]$! R^]+R7      t,]$! RRRRR7      t-R t. ! R R4      t/ ! R R]/4      t0 ! R R]04      t1 ! R R]/4      t2R t3R t4R t5R t6R t7R# )     N)Path)	find_spec)	add_input	get_inputsetup_loggingiterator_hasvalueBooleanOptionalActionPILcv2c                     V\         P                  8X  d   R pM<V\         P                  8X  d   RpM$\        R\        P
                  V,           R24      h\        P                  P                  ! WV.VO5/ VB # )FTz5Cannot create foreign_simple bitmap with bitmap type .)	pdfium_cFPDFBitmap_BGRxFPDFBitmap_BGRARuntimeErrorpdfium_iBitmapTypeToStrpdfium	PdfBitmapnew_foreign_simple)widthheightformatargskwargs	use_alphas   &&&*, [/Users/agent/.openclaw/workspace/venv/lib/python3.14/site-packages/pypdfium2/_cli/render.py_bitmap_wrapper_foreign_simpler      sp    )))		8++	+	RS[SkSklrSsRttuvww..uiY$YRXYY    T)force_packed)nativeforeignforeign_packedforeign_simpleC)metavarnargstype)	path_fillpath_stroke	text_filltext_strokec           
        a \        V R R7       V P                  RRR R RR7       V P                  RRR	7       V P                  R
R\        P                  RR7       R\        R\
        R\        /oV P                  RRV3R lR\        SP                  4       4       2R7       V P                  R^\        RR7       V P                  R^ \        RcRR7       V P                  ! RdRR/\        B  V P                  RReRR 7       V P                  R!R"^\        RfR#R$7       V P                  R%\        R R&R'7       V P                  R(\        R R)R'7       V P                  R*R+. Rg\        P                  R,R-7       V P                  R.R/R0R17       V P                  R2R3R47      pVP                  R5\        P                  4       R6R7\        P                  R87       VP                  R9R/R:R17       VP                  R;R<R= R>R7       VP                  R?R@\        RARB7       VP                  RC\        RDR17       V P                  RERFR47      pVP                  RGRH\        \        P                   RIRJ7       VP                  RK\"        P$                  ! 4       \        RLR7       VP                  RMRhRN\        P                  RORP7       VP                  RQRiRR\        P                  RSRP7       VP                  RT\        P                  RUR7       V P                  RVRWR47      pVP                  RXR/RYR17       VP                  ! Rj/ \        B  VP                  ! Rk/ \        B  VP                  ! Rl/ \        B  VP                  ! Rm/ \        B  VP                  RZR/R[R17       V P                  R\R]R47      pVP                  R^R/R_R17       VP                  R`R/RaR17       Rb# )nT)pagesz--outputz-oc                 P    \        V 4      P                  4       P                  4       # N)r   
expanduserresolve)ps   &r   <lambda>attach.<locals>.<lambda><   s    a++-557r   zDOutput directory where the serially numbered images shall be placed.)r(   requiredhelpz--prefixzDCustom prefix for the images. Defaults to the input filename's stem.)r7   z--formatz-fz/The image format to use (default: conditional).)r(   r7   pilz	numpy+pilz	numpy+cv2z--engine
engine_clsc                 2   < SV P                  4       ,          # r0   lower)kengines_maps   &r   r4   r5   M   s    QWWY/r   zThe saver engine to use )destr(   r7   z--scalezDefine the resolution of the output images. By default, one PDF point (1/72in) is rendered to 1x1 pixel. This factor scales the number of pixels that represent one point.)defaultr(   r7   z
--rotationz'Rotate pages by 90, 180 or 270 degrees.)r@   r(   choicesr7   r7   zColor the bitmap will be filled with before rendering. Shall be given in RGBA format as a sequence of integers ranging from 0 to 255. Defaults to white.z--optimize-modez3The rendering optimisation mode. None if not given.)rA   r7   z--cropr%   z/Amount to crop from (left, bottom, right, top).)r&   r'   r(   r@   r7   z--draw-annotsz1Whether annotations may be shown (default: true).)actionr@   r7   z--draw-formsz+Whether forms may be shown (default: true).z--no-antialias+z&Item types that shall not be smoothed.)r'   r@   rA   r(   r7   z--force-halftone
store_truez)Always use halftone for image stretching.)rB   r7   zBitmap optionsz&Bitmap config, including pixel format.)titledescriptionz--bitmap-makerr!   zThe bitmap maker to use.)rA   r@   r7   r(   z--grayscalez0Whether to render in grayscale mode (no colors).z--byteorderrev_byteorderc                 8    R RRR/V P                  4       ,          # )bgrFrgbTr;   )vs   &r   r4   r5      s    %t4QWWY?r   z;Whether to use BGR or RGB byteorder (default: conditional).z--x-channelprefer_bgrxz@Whether to prefer BGRx/RGBx over BGR/RGB (default: conditional).)r?   rB   r7   z--maybe-alphazWhether to use BGRA if page content has transparency. Note, this makes format selection page-dependent. As this behavior can be confusing, it is not currently the default, but recommended for performance in these cases.Parallelizationz.Options for rendering with multiple processes.z--linear?zRender non-parallel if page count is less or equal to the specified value (default: 4). If this flag is given without a value, then render linear regardless of document length.)r'   r(   constr7   z--processeszXThe maximum number of parallel rendering processes. Defaults to the number of CPU cores.z--parallel-strategyspawnzQThe process start method to use. ('fork' is discouraged due to stability issues.))rA   r@   r(   r7   z--parallel-libmpzRThe parallelization module to use (mp = multiprocessing, ft = concurrent.futures).z--parallel-mapzLThe map function to use (backend specific, the default is an iterative map).zFlat color schemezOptions for using pdfium's color scheme renderer. Note that this may flatten different colors into one, so the usability of this is limited. Alternatively, consider post-processing with lightness inversion (see below).z--sample-themezWUse a dark background sample theme as base. Explicit color params override selectively.z--fill-to-strokea  When rendering with custom color scheme, only draw borders around fill areas using the `path_stroke` color, instead of filling with the `path_fill` color. This is actually recommended, since with a single fill color for paths the boundaries of adjacent fill paths are less visible.zPost processingzgOptions to post-process rendered images. Note, this may have a strongly negative impact on performance.z--invert-lightnessa]  Invert lightness using the HLS color space (e.g. white<->black, dark_blue<->light_blue). The intent is to achieve a dark theme for documents with light background, while providing better visual results than classical color inversion or a flat pdfium color scheme. However, note that --optimize-mode lcd is not recommendable when inverting lightness.z--exclude-imagesz7Whether to exclude PDF images from lightness inversion.N)r   Z      i  )z--fill-color)lcdprint)r   r   r   r   )textimagepath)rP   
forkserverforkrQ   ft)z--path-fill)z--path-stroke)z--text-fill)z--text-stroke)r   add_argumentstrr<   	PILEngineNumpyPILEngineNumpyCV2Enginetuplekeysfloatint	ColorOptsr	   add_argument_groupBitmapMakersmathinfos	cpu_count)parserbitmapparallelcolor_schemepostprocr>   s   &    @r   attachrr   8   s   fD!
D7U	   U   Dyy@  
 )[.+~^K
/)%0@0@0B*C)DE	    |	   #8     j 
 "D  
 15@	   &B	   &<	   +yy7   :   && > ' F ##%)yy   A  
 ?L	   &Q	   & m   ((!F ) H  B   ,,.i	   1yyb   yyc   yy]   ,,# s - L h  
 ;;;;;;;; k   ((! ) H  o  
 H  r   c                   2   a  ] tR t^t o R tR tR tRtV tR# )SavingEnginec                    Wn         W n        R # r0   r   postproc_kwargs)self
saver_argsrw   s   &&&r   __init__SavingEngine.__init__   s    	.r   c                    V P                   pVP                  VP                   V^,           RVP                   R2 RV 2,          # )   0dr   )r   
output_dirprefixn_digits)rx   iextr   s   &&& r   	_get_pathSavingEngine._get_path   sA    yyDKK=1Qt}}oQ4F0Gq!NNNr   c                   V P                   P                  '       dP   V P                   P                  R9   d5   \        P                  ! V4      '       d   \
        P                  R4       RpMV P                   P                  pV P                  W4      pV P                  WRW0P                  4       \
        P                  RV^,            RVP                   24       R# )jpgz8Page has transparency - overriding output format to PNG.pngzWrote page z as N)r   jpeg)r   maybe_alphar   r   FPDFPage_HasTransparencyloggerinfor   _saving_hookrw   name)rx   r   rn   pager   out_paths   &&&&  r   __call__SavingEngine.__call__   s    99   TYY%5%5%HXMnMnosMtMtKKRSC))""C>>!)(D2F2FGk!A#d8==/:;r   rv   N)	__name__
__module____qualname____firstlineno__rz   r   r   __static_attributes____classdictcell____classdict__s   @r   rt   rt      s     /O	< 	<r   rt   c                      a  ] tR tRt o R t]! ]P                  P                  4      t	R t
]R 4       t^t]]P                  ! ^R7      R 4       4       t]R 4       tRtV tR	# )
r_   i  c                    V P                   R ,          '       g   R# \        P                  R4       ^ RIs^ RIs^ RIs^ RIsR# )invert_lightnessNz&PIL engine imports for post-processing)rw   r   debug	PIL.Imager
   PIL.ImageOpsPIL.ImageFilterPIL.ImageDrawrx   s   &r   
do_importsPILEngine.do_imports
  s0    ##$677=>r   c                    VP                  V4      pV P                  V4      pV P                  ! WcV3/ VB pVP                  V4       R # r0   )get_posconv_to_pil_hookpostprocesssave)rx   r   rn   r   rw   posconv	pil_images   &&&&&  r   r   PILEngine._saving_hook  sE    $$T*%%f-	$$YgQQ	x r   c                v    \         P                  ! WV4      w  r4p^V,
          p\         P                  ! W4V4      # )r}   )colorsys
rgb_to_hls
hls_to_rgb)rgbhlss   &&&   r   _invert_px_lightnessPILEngine._invert_px_lightness  s4    %%aA.aE""1++r   )maxsizec                ~    \         P                  P                  P                  V P                  V P
                  4      # r0   )r
   ImageFilter
Color3DLUTgenerateLINV_LUT_SIZEr   )clss   &r   _get_linv_lutPILEngine._get_linv_lut$  s-     ))2233D3DcF^F^__r   c           	        TpV'       Ed7   VP                   R 8X  d!   \        P                  P                  V4      pMVP	                  V P                  4       4      pV'       d   \        VP                  \        P                  .^R7      4      w  rxV'       d   \        P                  P                  RVP                  4      p	\        P                  P                  V	4      p
V FH  pVP                  4        UUu. uF  w  rVP!                  W4      NK  	  pppV
P#                  V^R7       KJ  	  VP%                  WR7       V# u uppi )L	max_depth1)fill)mask)moder
   ImageOpsinvertfilterr   r   get_objectsr   FPDF_PAGEOBJ_IMAGEImagenewsize	ImageDrawDrawget_quad_points	to_bitmappolygonpaste)r   	src_imager   r   r   exclude_images	dst_imagehave_images
obj_walkerr   drawobjxyqpointss   &&&&&&         r   r   PILEngine.postprocess)  s   	~~$LL//	:	%,,S->->-@A	 +<T=M=MxOjOjNkwx=M=y*{'99==inn=D==--d3D)GJGZGZG\"]G\tq7#4#4Q#:G\"]W15  * OOIO9 #^s   :E N)r   r   r   r   r   staticmethodr   r   to_pilr   r   r   r   classmethod	functools	lru_cacher   r   r   r   r   s   @r   r_   r_     s}        0 0 7 78L! , ,
 M#` $ `  r   r_   c                   B   a a ] tR tRt oV 3R lt]R 4       tRtVtV ;t	# )r`   i?  c                V   < \         P                  R 4       ^ RIs\        SV `  4        R# )zNumPy+PIL engine importsN)r   r   r   r
   superr   )rx   	__class__s   &r   r   NumpyPILEngine.do_importsA  s    /0r   c                r    \         P                  P                  V P                  4       V P                  4      # r0   )r
   r   	fromarrayto_numpyr   )rn   s   &r   r   NumpyPILEngine._to_pil_hookG  s$    yy""6??#4fkkBBr   r   )
r   r   r   r   r   r   r   r   r   __classcell__)r   r   s   @@r   r`   r`   ?  s&      C C Cr   r`   c                   <   a  ] tR tRt o R tR t]R 4       tRtV t	R# )ra   iL  c                v    \         P                  R 4       ^ RIsV P                  R,          '       d   ^ RIsR# R# )zNumPy+cv2 engine importsNr   )r   r   r   rw   numpynpr   s   &r   r   NumpyCV2Engine.do_importsN  s,    /0 011 2r   c                    VP                  4       pV P                  ! WRV3/ VB p\        P                  \	        V4      V4       R # r0   )r   r   r   imwriter^   )rx   r   rn   r   rw   np_arrays   &&&&& r   r   NumpyCV2Engine._saving_hookU  s7    ??$##HdNoNCM8,r   c                L   TpV'       Ed   VP                   \        P                  8X  d   V( pMVP                  '       d!   \        P
                  \        P                  3M\        P                  \        P                  3w  rx\        P                  Wg4      p\        P                  V4      w  rpV
( p
\        P                  WV.4      p\        P                  Wh4      pV'       Ed7   VP                   \        P                  8w  g   Q R 4       hVP                  V4      p\        VP                  \        P                   .^R7      4      w  rV'       d   \"        P%                  VP&                  VP(                  ^3\"        P*                  4      pV Fr  p\"        P-                  VP/                  4        UUu. uF  w  ppVP1                  VV4      NK  	  upp\"        P2                  4      p\        P5                  VV.^4       Kt  	  \        P7                  WVR7      pV# u uppi )z=Not sure how to paste with mask on {RGB,BGR}X image using cv2r   )r   dst)r   r   FPDFBitmap_GrayrG   r   COLOR_RGB2HLSCOLOR_HLS2RGBCOLOR_BGR2HLSCOLOR_HLS2BGRcvtColorsplitmerger   r   r   r   r   r   zerosr   r   uint8arrayr   r   int32fillPolycopyTo)r   r   rn   r   r   r   r   
convert_toconvert_fromr   r   r   r   r   r   r   r   r   r   r   s   &&&&&&              r   r   NumpyCV2Engine.postprocessZ  s   	}} 8 88&J	U[UiUiUiC,=,=s?P?P+Qps  qB  qB  DG  DU  DU  pV(
LL?	))I.aBIIqQi0	LLA	~}}(@(@@  B  CB  B@ ,,T2*;T=M=MxOjOjNkwx=M=y*{'88V]]FLL!$DbhhOD)"$((PSPcPcPe+fPe1G,=,=a,CPe+fhjhphp"qTG9a8  * !$

9Y
 OI ,gs   6H r   N)
r   r   r   r   r   r   r   r   r   r   r   s   @r   ra   ra   L  s#     -
  r   ra   c                     V ! 4        \         P                  R \        P                  ! 4        24       V! 4        \        P
                  ! W#RR7      pV'       d   VP                  4        WuV3sR# )zInitializing data for process T)password	autocloseN)r   r   rk   getpidr   PdfDocument
init_formsProcObjs)logging_initengine_initinputr  may_init_formsr   enginepdfs   &&&&&&& r   _render_parallel_initr  t  sQ    N
KK0>?M


U
FC V$Hr   c                 L    W,          pVP                   ! R/ VB pV! WV4       R # )Nr   )render)r   r  r   r  r   rn   s   &&&&  r   _render_jobr"    s$    6D[["6"F
1dr   c                 (    \        V .\        O5!   R # r0   )r"  r  )r   s   &r   _render_parallel_jobr$    s    Hr   c                      R # r0   r   r   r   r   _do_nothingr&    s    4r   c                   a V P                   P                  4       '       g   \        R V P                   : 24      h\        W P                  R7      p\        V4      o\        ;QJ d)    V3R lV P                   4       F  '       d   K   RM	  RM! V3R lV P                   4       4      '       g   \        R4      h\        V P                  4      \        \        V P                  4      4      8w  d   \        R4      hV P                  f   V P                  P                   R2V n	        V P                  f   V P                  '       d   RMRV n        V P                  f"   V P                  ^,          ^8X  d   R	MR
V n        V P                  f   ^V n        V P                   f`   \"        '       g   \$        '       g   Q R4       h\"        '       d   \$        '       d   V P                  R
8X  d   \&        V n        M\(        V n        V P*                  f    \-        V P                   \(        4      V n        V P.                  f7   \-        V P                   \(        4      ;'       d    V P                  R
8g  V n        \1        4       pV P                  '       d   VP2                  ! R / \4        B  VP2                  ! R / \6         Uu/ uF"  p\9        W4      '       g   K  V\9        W4      bK$  	  upB  V'       d   \:        P<                  ! R / VB MRp\1        V P>                  V P@                  V PB                  V PD                  V P                  V PF                  V PH                  V P                  V PJ                  V P*                  V P.                  V PL                  \N        V PP                  ,          VV PR                  R7      pV PT                   F  pRVRV 2&   K  	  \V        PX                  ! V P                   V P                  \        \[        S4      4      V P                  V PL                  R7      p\1        V P\                  V P^                  R7      pV P\                  '       d'   V PF                  R8X  d   \`        Pc                  R4       \e        V 4      Pg                  4       p	V	R V	R V	R,          '       d   RV	R&   \`        Pi                  V	 4       V'       d   \`        Pi                  V 4       V P!                  Wx4      p
\        V P                  4      V P                  8:  dG   \`        Pk                  R4       V
Pm                  4        V P                   F  p\o        WWZ4       K  	  R# \`        Pk                  R4       \p        Pr                  ! V Pt                  4      p\1        VPv                  R3\x        Pz                  ! \|        P~                  VR7      R3R7      pWP                  ,          w  rV P                  '       d   V P                  pV Pt                  R8X  d   \        \        ppV
Pm                  4        M\        V
Pl                  pp\1        \        VVVP                  V P                  V P                  WZ3R7      p\        V P                  \        V P                  4      4      pV! V3/ VB ;_uu_ 4       p\9        VV4      pV! \        V P                  4       F  pK  	  RRR4       R# u upi   + '       g   i     R# ; i)!z*Output path is not an existing directory: )r  c              3   P   <"   T F  p^ Tu;8*  ;'       d    S8  Mu x  K  	  R# 5i)r   Nr   ).0r   pdf_lens   & r   	<genexpr>main.<locals>.<genexpr>  s!     4AqAs   &&FTz*Out-of-bounds page indices are prohibited.z&Duplicate page indices are prohibited.N_r   r   z?Either pillow or numpy+cv2 must be installed for rendering CLI.)scalerotationcrop	grayscale
fill_coloroptimize_modedraw_annotsmay_draw_formsforce_halftonerG   rL   r   bitmap_makerrp   fill_to_stroke	no_smooth)r   r   r   r   r   )r   r   rT   ztLCD optimization clashes with lightness inversion, as post-processing colors defeats the idea of subpixel rendering.
subcommandr.   r  z<obfuscated>zLinear rendering ...zParallel rendering ...imap)
mp_contextmapr[   rZ   )initializerinitargs)r   r   r      r@  r@  r@  r@  r   )Joutputis_dir
ValueErrorr   
draw_formslenallr.   setr   r  stemr2  sample_themer   linearr9   have_pilhave_cv2ra   r_   rG   
issubclassrL   dictupdateSampleThemeColorSchemeFieldsgetattrr   PdfColorSchemer.  r/  r0  r1  r3  r4  r6  r   rh   r7  r8  no_antialiastypesSimpleNamespacer^   r   r   r   warningvarscopyr   r   r   r"  rQ   get_contextparallel_strategyPoolr   partialr\   ProcessPoolExecutorparallel_libparallel_mapr&  r   r  _inputr  min	processesr$  )r   r  	cs_kwargsfrp   r   r(   ry   rw   
print_argsr  r   ctxpool_backends	pool_ctormap_attrr  r  pool_kwargsn_procspoolmap_funcr-  r*  s   &                      @r   mainrp    s;   ;;Edkk_UVV
D__
5C#hG3443334444EFF
4::#c$**o..ABB{{)+,0,=,=,=.CW{{#q1S8ee{{ x88f%ff#hh4;;%+?,DO'DO !'C%dooyAZZdkkUZFZI';'\5F[5F'RVJZ+74++5F[\9B6((595L

==yyNN__**&&,,**&&&&#D$5$56#,,F" !!%)4&!" " &&[[s7|$&&J 00,,O !3!3u!<  N  	Od"J< *W"5*!/
:
LLJ<!~'__Z9F
4::$++%*+A/ 
 	,-nnT334((F###B$:$:sKUS
 ,,=,=>	((H!!V+(3[+L(5v7H7H+L/$k3::t}}doo_en

 dnnc$**o6w.+..$tX.H2DJJ? @ /._ \^ /..s   ;[.[.9+[33\	)   d   r   r@  )r      r@  r@  rA  )rs  r@  r   r@  )8rk   ri   rV  loggingr   r   pathlibr   multiprocessingrQ   concurrent.futuresfuturesr\   importlib.utilr   pypdfium2._helpers_helpersr   pypdfium2.internalinternalr   pypdfium2.rawrawr   pypdfium2._cli._parsersr   r   r   r   r	   rL  rM  	getLoggerr   r   r   rO  r   
new_nativenew_foreignr^  rh   rR  re   rf   rQ  rr   rt   r_   r`   ra   r  r"  r$  r&  rp  r   r   r   <module>r     s8   
         $ # %    U4'U4'			8	$Z ((**&&v'7'7'C'CRVW3	 M AC0	&&&&wt< <,4 4n
Ci 
C%l %P% {r   