// Flush the current scanline. public void FlushScanline() { byte[] temp; int x, posn, width; int bpp = bytesPerPixel; int bytesPerLine = this.bytesPerLine; // Filter the scanline. We use a fairly simple approach, // using no filter for indexed images and the "Paeth" // filter for RGB images, as recommended by RFC-2083. // It is possible to dynamically adjust the filter to // match the scanline, but we don't do that at the moment. if (usePaeth && y > 0 && bytesPerLine > 0) { // Apply the "Paeth" filter to the line. temp = paeth; for (posn = 0; posn < bpp; ++posn) { temp[posn] = (byte)(Buffer[posn] - PngReader.Paeth(0, prevScanline[posn], 0)); } for (posn = bpp; posn < bytesPerLine; ++posn) { temp[posn] = (byte)(Buffer[posn] - PngReader.Paeth (Buffer[posn - bpp], prevScanline[posn], prevScanline[posn - bpp])); } filter[0] = 4; } else { // No filter is needed for this scanline. temp = Buffer; filter[0] = 0; } // Write the filter type byte and the filtered scanline. compressor.Write(filter, 0, 1); compressor.Write(temp, 0, bytesPerLine); // Swap the buffers and advance to the next scanline. temp = Buffer; Buffer = prevScanline; prevScanline = temp; ++y; }