Xj ddlmZmZddlmZddlmZmZddlm Z Gdde Z GddZ Gd d Z Gd d Z d ZGddZGddeZGddeZy)) MIME_TYPEPNG_CHUNK_TYPE)InvalidImageStreamError) BIG_ENDIAN StreamReader)BaseImageHeaderc@eZdZdZedZedZedZy)Pngz#Image header parser for PNG images.c"tjS)zUMIME content type for this image, unconditionally `image/png` for PNG images.)rPNGselfs b/mnt/ssd/data/Dropbox/adrian/vault-secondbrain/venv/lib/python3.12/site-packages/docx/image/png.py content_typezPng.content_type s}}cy)z8Default filename extension, always 'png' for PNG images.pngr s r default_extzPng.default_extsrctj|}|j}|j}|j}|j }|||||S)zWReturn a |Png| instance having header properties parsed from image in `stream`.) _PngParserparsepx_width px_heighthorz_dpivert_dpi)clsstreamparserrrrrs r from_streamzPng.from_streamsK!!&)??$$ ????8Y(;;rN) __name__ __module__ __qualname____doc__propertyrr classmethodr rrrr r s?-   < z_Chunks.IHDR..meoo1D1DDrzno IHDR chunk in PNG image) _find_firstr)rmatchr2s rr2z _Chunks.IHDRjs0E& <)*FG G rc*d}|j|S)z2PHYs chunk in PNG image, or |None| if not present.c<|jtjk(Sr))rPrr7rQs rrSz_Chunks.pHYs..vrTr)rU)rrVs rr7z _Chunks.pHYsssE&&rc>|jD]}||s |cSy)zGReturn first chunk in stream order returning True for function `match`.N)r,)rrVrRs rrUz_Chunks._find_firstys&\\ EU|  r) r!r"r#r$r+r&r r%r2r7rUrDrEs@rr0r0\sLB, '' rr0c>eZdZdZfdZedZdZdZxZ S)rKz(Extracts chunks from a PNG image stream.c8tt| ||_yr))r*rKr+ _stream_rdr)r stream_rdrr.s rr+z_ChunkParser.__init__s lD*,%rc2t|t}||S)zdReturn a |_ChunkParser| instance that can extract the chunks from the PNG image in `stream`.)rr)rrr]s rr z_ChunkParser.from_streams"&*5 :rc#rK|jD] \}}t||j|}|"yw)zGenerate a |_Chunk| subclass instance for each chunk in this parser's PNG stream, in the order encountered in the stream.N)_iter_chunk_offsets _ChunkFactoryr\)r chunk_typeoffsetrRs rrLz_ChunkParser.iter_chunkss>#'":":"<  J!*d.>.>GEK s57c#Kd} |jj|}|jjd|d}|dz}||f|dk(ry|d|zdzz }Uw)zGenerate a (chunk_type, chunk_offset) 2-tuple for each of the chunks in the PNG image stream. Iteration stops after the IEND chunk is returned. IENDN)r\ read_longread_str)r chunk_offsetchunk_data_lenrb data_offsets rr`z _ChunkParser._iter_chunk_offsetssy  !--77 EN))221lAFJ&*Kk) )V# EN2Q6 6LsAA) r!r"r#r$r+r&r rLr`rDrEs@rrKrKs)2& 7rrKctjttjti}|j |t }|j|||S)ziReturn a |_Chunk| subclass instance appropriate to `chunk_type` parsed from `stream_rdr` at `offset`.)rr2 _IHDRChunkr7 _pHYsChunkget_Chunk from_offset)rbr]rc chunk_cls_map chunk_clss rrarasJ ZZM!!*f5I  Z @@rcBeZdZdZfdZedZedZxZ S)rqzUBase class for specific chunk types. Also serves as the default chunk type. c8tt| ||_yr))r*rqr+ _chunk_type)rrbr.s rr+z_Chunk.__init__s fd$&%rc||S)z@Return a default _Chunk instance that only knows its chunk type.r)rrbr]rcs rrrz_Chunk.from_offsets:rc|jS)z.The chunk type name, e.g. 'IHDR', 'pHYs', etc.)rwr s rrPz_Chunk.type_namesr) r!r"r#r$r+r&rrr%rPrDrEs@rrqrqs5 &  rrqcReZdZdZfdZedZedZedZ xZ S)rnz*IHDR chunk, contains the image dimensions.cHtt| |||_||_yr))r*rnr+ _px_width _px_height)rrbrrr.s rr+z_IHDRChunk.__init__s  j$(4!#rc\|j|}|j|d}||||S)z|Return an _IHDRChunk instance containing the image dimensions extracted from the IHDR chunk in `stream` at `offset`.rf)rh)rrbr]rcrrs rrrz_IHDRChunk.from_offsets5''/((3 :x33rc|jSr))r|r s rrz_IHDRChunk.px_widths ~~rc|jSr))r}r s rrz_IHDRChunk.px_heights r) r!r"r#r$r+r&rrr%rrrDrEs@rrnrnsG4$ 44rrncbeZdZdZfdZedZedZedZ edZ xZ S)roz/PYHs chunk, contains the image dpi information.cVtt| |||_||_||_yr))r*ror+_horz_px_per_unit_vert_px_per_unit_units_specifier)rrbr:r>r9r.s rr+z_pHYsChunk.__init__s* j$(4!1!1 /rc|j|}|j|d}|j|d}|||||S)z{Return a _pHYsChunk instance containing the image resolution extracted from the pHYs chunk in `stream` at `offset`.rfre)rh read_byte)rrbr]rcr:r>r9s rrrz_pHYsChunk.from_offsetsM&//7%//:$..vq9:/1A?SSrc|jSr))rr s rr:z_pHYsChunk.horz_px_per_unit%%%rc|jSr))rr s rr>z_pHYsChunk.vert_px_per_unitrrc|jSr))rr s rr9z_pHYsChunk.units_specifiers$$$r) r!r"r#r$r+r&rrr%r:r>r9rDrEs@rroros]90 TT&&&&%%rroN) constantsrr exceptionsrhelpersrrimagerr rr0rKrarqrnrorrrrsf0/-"