;i ddlmZmZddlmZddlmZmZddlm Z Gdde Z GddZ Gd d Z Gd d Z d ZGddZGddeZGddeZdS)) MIME_TYPEPNG_CHUNK_TYPE)InvalidImageStreamError) BIG_ENDIAN StreamReader)BaseImageHeadercTeZdZdZedZedZedZdS)Pngz#Image header parser for PNG images.ctjS)zUMIME content type for this image, unconditionally `image/png` for PNG images.)rPNGselfs BC:\PYTHON\MyICR_Workspace\venv\Lib\site-packages\docx/image/png.py content_typezPng.content_type s }cdS)z8Default filename extension, always 'png' for PNG images.pngr s r default_extzPng.default_exts urct|}|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_streamsJ!!&))?$ ??s8Y(;;;rN) __name__ __module__ __qualname____doc__propertyrr classmethodr rrrr r si-- X X < <[ < < $//77 l..0011s6{{rcXd}||}|td|S)zIHDR chunk in PNG image.c,|jtjkSr)) type_namerr2chunks rz_Chunks.IHDR..meo1DDrNzno IHDR chunk in PNG image) _find_firstr)rmatchr2s rr2z _Chunks.IHDRjs9ED&& <)*FGG G rc2d}||S)z2PHYs chunk in PNG image, or |None| if not present.c,|jtjkSr))rPrr7rQs rrSz_Chunks.pHYs..vrTr)rU)rrVs rr7z _Chunks.pHYsss!ED&&&rc8|jD]}||r|cSdS)zGReturn first chunk in stream order returning True for function `match`.N)r,)rrVrRs rrUz_Chunks._find_firstys6\  EuU||   tr) r!r"r#r$r+r&r r%r2r7rUrDrEs@rr0r0\sBB,,,,,[ X''X' rr0cDeZdZdZfdZedZdZdZxZ S)rKz(Extracts chunks from a PNG image stream.cdtt|||_dSr))r*rKr+ _stream_rdr)r stream_rdrr.s rr+z_ChunkParser.__init__s- lD!!**,,,%rcBt|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!"&*55 s:rc#rK|D]\}}t||j|}|V dS)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_chunkssQ#'":":"<"<   J!*d.>GGEKKKK  rc#Kd} |j|}|jd|d}|dz}||fV|dkrdS|d|zdzz }U)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. TIENDN)r\ read_longread_str)r chunk_offsetchunk_data_lenrb data_offsets rr`z _ChunkParser._iter_chunk_offsetss   7!-77 EEN)221lAFFJ&*Kk) ) ) )V## EN2Q6 6L 7r) r!r"r#r$r+r&r rLr`rDrEs@rrKrKsw22&&&&&[ 7777777rrKctjttjti}||t }||||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!!*f55I  Z @ @@rcNeZdZdZfdZedZedZxZ S)rqzUBase class for specific chunk types. Also serves as the default chunk type. cdtt|||_dSr))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_offsetss:rc|jS)z.The chunk type name, e.g. 'IHDR', 'pHYs', etc.)rwr s rrPz_Chunk.type_names r) r!r"r#r$r+r&rrr%rPrDrEs@rrqrqsx &&&&&[  X     rrqcdeZdZdZfdZedZedZedZ xZ S)rnz*IHDR chunk, contains the image dimensions.cttt||||_||_dSr))r*rnr+ _px_width _px_height)rrbrrr.s rr+z_IHDRChunk.__init__s3 j$((444!#rcr||}||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_offsets@''//((33 s:x333rc|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@rrnrns44$$$$$ 44[4XXrrnczeZdZdZfdZedZedZedZ edZ xZ S)roz/PYHs chunk, contains the image dpi information.ctt||||_||_||_dSr))r*ror+_horz_px_per_unit_vert_px_per_unit_units_specifier)rrbr:r>r9r.s rr+z_pHYsChunk.__init__s? j$((444!1!1 /rc||}||d}||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_offsets[&//77%//::$..vq99s:/1A?SSSrc|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@rroros9900000 TT[T&&X&&&X&%%X%%%%%rroN) constantsrr exceptionsrhelpersrrimagerr rr0rKrarqrnrorrrrs00000000//////--------""""""<<<<