Generator for interlaced scanlines from an array. `pixels` is the full source image as a single array of values. The generator yields each scanline of the reduced passes in turn, each scanline being a sequence of values.
(self, pixels)
| 865 | yield pixels[start:stop] |
| 866 | |
| 867 | def array_scanlines_interlace(self, pixels): |
| 868 | """ |
| 869 | Generator for interlaced scanlines from an array. |
| 870 | `pixels` is the full source image as a single array of values. |
| 871 | The generator yields each scanline of the reduced passes in turn, |
| 872 | each scanline being a sequence of values. |
| 873 | """ |
| 874 | |
| 875 | # http://www.w3.org/TR/PNG/#8InterlaceMethods |
| 876 | # Array type. |
| 877 | fmt = "BH"[self.bitdepth > 8] |
| 878 | # Value per row |
| 879 | vpr = self.width * self.planes |
| 880 | |
| 881 | # Each iteration generates a scanline starting at (x, y) |
| 882 | # and consisting of every xstep pixels. |
| 883 | for lines in adam7_generate(self.width, self.height): |
| 884 | for x, y, xstep in lines: |
| 885 | # Pixels per row (of reduced image) |
| 886 | ppr = int(math.ceil((self.width - x) / float(xstep))) |
| 887 | # Values per row (of reduced image) |
| 888 | reduced_row_len = ppr * self.planes |
| 889 | if xstep == 1: |
| 890 | # Easy case: line is a simple slice. |
| 891 | offset = y * vpr |
| 892 | yield pixels[offset : offset + vpr] |
| 893 | continue |
| 894 | # We have to step by xstep, |
| 895 | # which we can do one plane at a time |
| 896 | # using the step in Python slices. |
| 897 | row = array(fmt) |
| 898 | # There's no easier way to set the length of an array |
| 899 | row.extend(pixels[0:reduced_row_len]) |
| 900 | offset = y * vpr + x * self.planes |
| 901 | end_offset = (y + 1) * vpr |
| 902 | skip = self.planes * xstep |
| 903 | for i in range(self.planes): |
| 904 | row[i :: self.planes] = pixels[offset + i : end_offset : skip] |
| 905 | yield row |
| 906 | |
| 907 | |
| 908 | def write_chunk(outfile, tag, data=b""): |
no test coverage detected