public function setFilter($filter)
    {
        $validFilters = self::NO_FILTER |
                self::FILTER_NONE | self::FILTER_SUB |
                self::FILTER_UP | self::FILTER_AVG |
                self::FILTER_PAETH | self::ALL_FILTERS;

        $filter = $filter & $validFilters;

        $this->filter = (integer) $filter;

        return $this;
    }