| 1977 | typecode = "BH"[info["bitdepth"] > 8] |
| 1978 | |
| 1979 | def itertrns(pixels): |
| 1980 | for row in pixels: |
| 1981 | # For each row we group it into pixels, then form a |
| 1982 | # characterisation vector that says whether each |
| 1983 | # pixel is opaque or not. Then we convert |
| 1984 | # True/False to 0/maxval (by multiplication), |
| 1985 | # and add it as the extra channel. |
| 1986 | row = group(row, planes) |
| 1987 | opa = map(it.__ne__, row) |
| 1988 | opa = map(maxval.__mul__, opa) |
| 1989 | opa = list(zip(opa)) # convert to 1-tuples |
| 1990 | yield array(typecode, itertools.chain(*map(operator.add, row, opa))) |
| 1991 | |
| 1992 | pixels = itertrns(pixels) |
| 1993 | targetbitdepth = None |