MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / _writePng

Method _writePng

lib/matplotlib/backends/backend_pdf.py:1622–1649  ·  view source on GitHub ↗

Write the image *img* into the pdf file using png predictors with Flate compression.

(self, img)

Source from the content-addressed store, hash-verified

1620 return rgb, alpha
1621
1622 def _writePng(self, img):
1623 """
1624 Write the image *img* into the pdf file using png
1625 predictors with Flate compression.
1626 """
1627 buffer = BytesIO()
1628 img.save(buffer, format="png")
1629 buffer.seek(8)
1630 png_data = b''
1631 bit_depth = palette = None
1632 while True:
1633 length, type = struct.unpack(b'!L4s', buffer.read(8))
1634 if type in [b'IHDR', b'PLTE', b'IDAT']:
1635 data = buffer.read(length)
1636 if len(data) != length:
1637 raise RuntimeError("truncated data")
1638 if type == b'IHDR':
1639 bit_depth = int(data[8])
1640 elif type == b'PLTE':
1641 palette = data
1642 elif type == b'IDAT':
1643 png_data += data
1644 elif type == b'IEND':
1645 break
1646 else:
1647 buffer.seek(length, 1)
1648 buffer.seek(4, 1) # skip CRC
1649 return png_data, bit_depth, palette
1650
1651 def _writeImg(self, data, id, smask=None):
1652 """

Callers 1

_writeImgMethod · 0.95

Calls 1

saveMethod · 0.80

Tested by

no test coverage detected