(self)
| 1541 | return name, ob |
| 1542 | |
| 1543 | def writeGouraudTriangles(self): |
| 1544 | gouraudDict = dict() |
| 1545 | for name, ob, points, colors in self.gouraudTriangles: |
| 1546 | gouraudDict[name] = ob |
| 1547 | shape = points.shape |
| 1548 | flat_points = points.reshape((shape[0] * shape[1], 2)) |
| 1549 | colordim = colors.shape[2] |
| 1550 | assert colordim in (1, 4) |
| 1551 | flat_colors = colors.reshape((shape[0] * shape[1], colordim)) |
| 1552 | if colordim == 4: |
| 1553 | # strip the alpha channel |
| 1554 | colordim = 3 |
| 1555 | points_min = np.min(flat_points, axis=0) - (1 << 8) |
| 1556 | points_max = np.max(flat_points, axis=0) + (1 << 8) |
| 1557 | factor = 0xffffffff / (points_max - points_min) |
| 1558 | |
| 1559 | self.beginStream( |
| 1560 | ob.id, None, |
| 1561 | {'ShadingType': 4, |
| 1562 | 'BitsPerCoordinate': 32, |
| 1563 | 'BitsPerComponent': 8, |
| 1564 | 'BitsPerFlag': 8, |
| 1565 | 'ColorSpace': Name( |
| 1566 | 'DeviceRGB' if colordim == 3 else 'DeviceGray' |
| 1567 | ), |
| 1568 | 'AntiAlias': False, |
| 1569 | 'Decode': ([points_min[0], points_max[0], |
| 1570 | points_min[1], points_max[1]] |
| 1571 | + [0, 1] * colordim), |
| 1572 | }) |
| 1573 | |
| 1574 | streamarr = np.empty( |
| 1575 | (shape[0] * shape[1],), |
| 1576 | dtype=[('flags', 'u1'), |
| 1577 | ('points', '>u4', (2,)), |
| 1578 | ('colors', 'u1', (colordim,))]) |
| 1579 | streamarr['flags'] = 0 |
| 1580 | streamarr['points'] = (flat_points - points_min) * factor |
| 1581 | streamarr['colors'] = flat_colors[:, :colordim] * 255.0 |
| 1582 | |
| 1583 | self.write(streamarr.tobytes()) |
| 1584 | self.endStream() |
| 1585 | self.writeObject(self.gouraudObject, gouraudDict) |
| 1586 | |
| 1587 | def imageObject(self, image): |
| 1588 | """Return name of an image XObject representing the given image.""" |
no test coverage detected