Returns a palette that is a sequence of 3-tuples or 4-tuples, synthesizing it from the ``PLTE`` and ``tRNS`` chunks. These chunks should have already been processed (for example, by calling the :meth:`preamble` method). All the tuples are the same size:
(self, alpha="natural")
| 1870 | return x, y, pixel, info |
| 1871 | |
| 1872 | def palette(self, alpha="natural"): |
| 1873 | """ |
| 1874 | Returns a palette that is a sequence of 3-tuples or 4-tuples, |
| 1875 | synthesizing it from the ``PLTE`` and ``tRNS`` chunks. |
| 1876 | These chunks should have already been processed (for example, |
| 1877 | by calling the :meth:`preamble` method). |
| 1878 | All the tuples are the same size: |
| 1879 | 3-tuples if there is no ``tRNS`` chunk, |
| 1880 | 4-tuples when there is a ``tRNS`` chunk. |
| 1881 | |
| 1882 | Assumes that the image is colour type |
| 1883 | 3 and therefore a ``PLTE`` chunk is required. |
| 1884 | |
| 1885 | If the `alpha` argument is ``'force'`` then an alpha channel is |
| 1886 | always added, forcing the result to be a sequence of 4-tuples. |
| 1887 | """ |
| 1888 | |
| 1889 | if not self.plte: |
| 1890 | raise FormatError("Required PLTE chunk is missing in colour type 3 image.") |
| 1891 | plte = group(array("B", self.plte), 3) |
| 1892 | if self.trns or alpha == "force": |
| 1893 | trns = array("B", self.trns or []) |
| 1894 | trns.extend([255] * (len(plte) - len(trns))) |
| 1895 | plte = list(map(operator.add, plte, group(trns, 1))) |
| 1896 | return plte |
| 1897 | |
| 1898 | def asDirect(self): |
| 1899 | """ |
no test coverage detected