L i\>UddlmZddlZddlZddlZddlmZddlmZddl m Z ddl m Z m Z mZmZmZmZddlmZmZddlmZdd lmZe r(dd l mZddlm Zdd lmZmZmZdd l m!Z!dd l"m#Z$ddl%m&Z&edZ'de(d<ee'dejRe*e e+fZ,de(d<edZ-de(d<edZ.de(d<ee.dfZ/de(d<e,ee,zZ0de(d<dZ1de(d<GddeZ2d e2jf_4d!e2jj_4d"e2jl_4d0d#Z7d0d$Z8 d1d%Z9 d2 d3d&Z:d4d'Z;d5d6d(Z d9d+Z?d:d,Z@ d;d-ZAdd/ZCy)?) annotationsN)Sequence)IntEnum)Path) TYPE_CHECKINGFinalLiteral TypeAliasUnioncast)runtimeurl_util)StreamlitAPIException)caching)Any)GifImagePluginImage ImageFile) LayoutConfig) ImageList) NumpyShape)zImageFile.ImageFilez Image.ImagezGifImagePlugin.GifImageFiler PILImagenpt.NDArray[Any] AtomicImage)RGBBGRChannels)JPEGPNGGIF ImageFormatautoImageFormatOrAutoImageOrImageListiz Final[int]MAXIMUM_CONTENT_WIDTHc$eZdZdZdZdZdZdZdZy) WidthBehaviorz| Special values that are recognized by the frontend and allow us to change the behavior of the displayed image. N) __name__ __module__ __qualname____doc__ORIGINALCOLUMNAUTOMIN_IMAGE_OR_CONTAINERMAX_IMAGE_OR_CONTAINERh/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/streamlit/elements/lib/image_utils.pyr'r'<s$ H F Dr7r'z'Display the image at its original widthz5Display the image at the width of the column it's in.zDisplay the image at its original width, unless it would exceed the width of its column in which case clamp it to its column widthc|jdvS)N)RGBALAP)modeimages r8_image_may_have_alpha_channelr@Rs ::, ,,r7c |jdk(S)Nr )formatr>s r8 _image_is_gifrCVs <<5  r7c|j}|dvr td|S|dk(ryt|tr,ddlm}|j tj|}n|}t|ryt|ryy) apReturn either "JPEG", "PNG", or "GIF", based on the input `format` string. - If `format` is "JPEG" or "JPG" (or any capitalization thereof), return "JPEG" - If `format` is "PNG" (or any capitalization thereof), return "PNG" - For all other strings, return "PNG" if the image has an alpha channel, "GIF" if the image is a GIF, and "JPEG" otherwise. >rrr!JPGrrrr r) upperr isinstancebytesPILropenioBytesIOrCr@) image_datarB img_formatr pil_images r8_validate_image_format_stringrQZswJ_$M:..U*e$EJJrzz*56  Y$Y/ r7ctj}|dk(rt|r|jd}|j ||||j S)zConvert a PIL image to bytes.rrrBquality)rLrMr@convertsavegetvalue)r?rBrTtmps r8 _pil_to_bytesrY|sM **,C9%@ e$ JJs67J3 <<>r7cD|jd|jSNr)seekrW)datas r8_bytesio_to_bytesr^sIIaL ==?r7cddl}ddlm}|j|j |j }t ||}t||S)NrrF)numpyrJr fromarrayastypeuint8rQrY)array output_formatnprimgrOs r8_np_array_to_bytesrhs> %//%,,rxx0 1C.sMBJ j ))r7c|j}t|dvr tdt|dk(r|ddvrtd|dd|t|dk(r|ddk(r |ddddd f}|S) N)z'Numpy shape has to be of length 2 or 3.rkr()rkz#Channel can only be 1, 3, or 4 got z . Shape is rlr)shapelenr)rdrns r8_verify_np_shaperps E 5z#$MNN 5zQ59I5#1%)Kw O   5zQ59>aAg Lr7c(d|jS)z2Get the mimetype string for the given ImageFormat.zimage/)lower) image_formats r8_get_image_format_mimetyperts L&&() **r7cddlm}|jtj|}|j \}}t |jtr |jnt}|dkDrF||kDrAtd|z|z|z }|j||f|j}t||dS|j|k7rt||dS|S)zResize an image if it exceeds the given width, or if exceeds MAXIMUM_CONTENT_WIDTH. Ensure the image's format corresponds to the given ImageFormat. Return the (possibly resized and reformatted) image bytes. rrF?)resampleZrS)rJrrKrLrMsizerHwidthintr%resizeBILINEARrYrB) rN layout_configrsrrP actual_width actual_height target_width new_heights r8_ensure_image_size_and_formatrs$%**RZZ %;\s)xmlnsz>& !bggnnU&;e (  ( 99JE Re# F  & 0 0g1F G N Nw W /0A/BC C eT" &aVVX  &" EI//= >25-H "5*5 E2:: &&u-  E2:: &,U3U; u 5;;1$aIo.+4 (e=Q  1]KL.z=,WJ),7H~~""$3377 HhW Hh? [ ( (* & &  #..u5KHa5&&(77;;E8XVC  # #E8X >J s7,J%+ J?7J2J?%J/2J<7J??A-L/.L/c rt|jdDcgc]}||ddddddfc}Scc}wr[)rangern)rdis r8_4d_to_list_3dr\s0',U[[^'< =!E!Q1*  == =s4c ddl}td|j}t|tt t fr t |} nGt||jr$t|jdk(r t|} n td|g} t|tr|} nqt|tr|g} n]t||jr)t|jdk(r|j} n|dgt| z} n t|g} t| ts tdt| t| k7r$tdt| d t| d tt| | d D]P\} \} } |j j#}| t| |_|d | }t'| ||||||_Ry)aFill an ImageListProto with a list of images and their captions. The images will be resized and reformatted as necessary. Parameters ---------- coordinates A string identifying the images' location in the frontend. image The image or images to include in the ImageListProto. caption Image caption. If displaying multiple images, caption should be a list of captions (one for each image). width The desired width of the image or images. This parameter will be passed to the frontend. Positive values set the image width explicitly. Negative values has some special. For details, see: `WidthBehaviour` proto_imgs The ImageListProto to fill in. clamp Clamp image pixel values to a valid range ([0-255] per channel). This is only meaningful for byte array images; the parameter is ignored for image URLs. If this is not set, and an image has an out-of-range value, an error will be thrown. channels If image is an nd.array, this parameter denotes the format used to represent color information. Defaults to 'RGB', meaning `image[:, :, 0]` is the red channel, `image[:, :, 1]` is green, and `image[:, :, 2]` is blue. For images coming from libraries like OpenCV you should set this to 'BGR', instead. output_format This parameter specifies the format to use when transferring the image data. Photos should use the JPEG format for lossy compression while diagrams should use the PNG format for lossless compression. Defaults to 'auto' which identifies the compression type based on the type and format of the image argument. rNrrmzSequence[AtomicImage]rlz9If image is a list then caption should be a list as well.z Cannot pair z captions with z images.F)strict-)r`r rGrHlistsettuplerrornrrtolistr enumeratezipimgsrcaptionrr) coordinatesr?rr~ proto_imgsrrrerfimagescaptions coord_suffix single_imagesingle_caption proto_imgrs r8marshall_imagesr`s^J 01H%$U+,e E2:: &3u{{+;q+@&-w7'4 )0 GS !9 GRZZ (S-?1-D>># 6CK'L> h %# G   8}F ##3x=/V X N  9B FHU+9  4 4|^OO'')  % #N 3I "]!L>2$ --   r7)r?rreturnbool)rNzbytes | PILImagerBrrr!)rd)r?rrBr!rTr{rrI)r]z io.BytesIOrrI)r)rdrrerrrI)rdrrr)rsr!rr)rNrIr~rrsr!rrI)r?rrrrr)r?rr~rrrrrrer#rrrr)rdrrzlist[npt.NDArray[Any]])rr")rrr?r$rz)str | npt.NDArray[Any] | list[str] | Noner~rrImageListProtorrrrrer#rNone)D __future__rrLrrcollections.abcrenumrpathlibrtypingrrr r r r streamlitr rstreamlit.errorsrstreamlit.runtimerr numpy.typingnptrJrrr#streamlit.elements.lib.layout_utilsrstreamlit.proto.Image_pb2rrstreamlit.type_utilrr__annotations__rMrrIrrr!r#r$r%r'r1r0r2r3r@rCrQrYr^rhrprtrrrrrr6r7r8rso# $HH'2%44@E.G)  "**c4> Yl+)+ !56 Y6&{F':;9;)H[,AA)A %,z+  G  "O ?  -! *-H!   " *  + &&&2&BM& &R"n nn n n % n  n nb>'-_ _ _ 7_  _  _  _ _ %_  _ r7