MCPcopy Index your code
hub / github.com/plotly/plotly.py / _deinterlace

Method _deinterlace

_plotly_utils/png.py:1472–1521  ·  view source on GitHub ↗

Read raw pixel data, undo filters, deinterlace, and flatten. Return a single array of values.

(self, raw)

Source from the content-addressed store, hash-verified

1470 return result
1471
1472 def _deinterlace(self, raw):
1473 """
1474 Read raw pixel data, undo filters, deinterlace, and flatten.
1475 Return a single array of values.
1476 """
1477
1478 # Values per row (of the target image)
1479 vpr = self.width * self.planes
1480
1481 # Values per image
1482 vpi = vpr * self.height
1483 # Interleaving writes to the output array randomly
1484 # (well, not quite), so the entire output array must be in memory.
1485 # Make a result array, and make it big enough.
1486 if self.bitdepth > 8:
1487 a = array("H", [0] * vpi)
1488 else:
1489 a = bytearray([0] * vpi)
1490 source_offset = 0
1491
1492 for lines in adam7_generate(self.width, self.height):
1493 # The previous (reconstructed) scanline.
1494 # `None` at the beginning of a pass
1495 # to indicate that there is no previous line.
1496 recon = None
1497 for x, y, xstep in lines:
1498 # Pixels per row (reduced pass image)
1499 ppr = int(math.ceil((self.width - x) / float(xstep)))
1500 # Row size in bytes for this pass.
1501 row_size = int(math.ceil(self.psize * ppr))
1502
1503 filter_type = raw[source_offset]
1504 source_offset += 1
1505 scanline = raw[source_offset : source_offset + row_size]
1506 source_offset += row_size
1507 recon = self.undo_filter(filter_type, scanline, recon)
1508 # Convert so that there is one element per pixel value
1509 flat = self._bytes_to_values(recon, width=ppr)
1510 if xstep == 1:
1511 assert x == 0
1512 offset = y * vpr
1513 a[offset : offset + vpr] = flat
1514 else:
1515 offset = y * vpr + x * self.planes
1516 end_offset = (y + 1) * vpr
1517 skip = self.planes * xstep
1518 for i in range(self.planes):
1519 a[offset + i : end_offset : skip] = flat[i :: self.planes]
1520
1521 return a
1522
1523 def _iter_bytes_to_values(self, byte_rows):
1524 """

Callers 1

rows_from_interlaceMethod · 0.95

Calls 4

undo_filterMethod · 0.95
_bytes_to_valuesMethod · 0.95
adam7_generateFunction · 0.85
intFunction · 0.85

Tested by

no test coverage detected