Performs filtering on a row of an image. This method may be
overridden in order to provide a custom algorithm for choosing
the filter type for a given row.
The method is supplied with the current and previous rows
of the image. For the first row of the image, or of an
interlacing pass, the previous row array will be filled with
zeros as required by the PNG specification.
The method is also supplied with five scratch arrays.
These arrays may be used within the method for any purpose.
At method exit, the array at the index given by the return
value of the method should contain the filtered data. The
return value will also be used as the filter type.
The default implementation of the method performs a trial
encoding with each of the filter types, and computes the sum of
absolute values of the differences between the raw bytes of the
current row and the predicted values. The index of the filter
producing the smallest result is returned.
As an example, to perform only 'sub' filtering, this method
could be implemented (non-optimally) as follows:
for (int i = bytesPerPixel; i < bytesPerRow + bytesPerPixel; i++) {
int curr = currRow[i] & 0xff;
int left = currRow[i - bytesPerPixel] & 0xff;
scratchRow[PNG_FILTER_SUB][i] = (byte)(curr - left);
}
return PNG_FILTER_SUB;