protected ScanlineFilter getScanlineFilter(int filter_type,
            int BytesPerPixel) throws ImageReadException, IOException
    {
        ScanlineFilter filter;

        switch (filter_type)
        {
        case 0: // None
            filter = new ScanlineFilterNone();
            break;

        case 1: // Sub
            filter = new ScanlineFilterSub(BytesPerPixel);
            break;

        case 2: // Up
            filter = new ScanlineFilterUp(BytesPerPixel);
            break;

        case 3: // Average
            filter = new ScanlineFilterAverage(BytesPerPixel);
            break;

        case 4: // Paeth
            filter = new ScanlineFilterPaeth(BytesPerPixel);
            break;

        default:
            throw new ImageReadException("PNG: unknown filter_type: "
                    + filter_type);

        }

        return filter;
    }