blob: 285d069911ca28131f2b06c7fd53cbd2bdf8e1cb [file] [log] [blame]
/* include/graphics/SkColorFilter.h
**
** Copyright 2006, Google Inc.
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
#ifndef SkColorFilter_DEFINED
#define SkColorFilter_DEFINED
#include "SkRefCnt.h"
#include "SkColor.h"
#include "SkPorterDuff.h"
class SkColorFilter : public SkRefCnt {
public:
/** Called with a scanline of colors, as if there was a shader installed.
The implementation writes out its filtered version into result[].
Note: shader and result may be the same buffer.
@param shader array of colors, possibly generated by a shader
@param count the number of entries in the shader[] and result[] arrays
@param result written by the filter, these are the colors that will used to draw
*/
virtual void filterSpan(const SkPMColor shader[], int count, SkPMColor result[]);
/** Create a colorfilter that uses the specified color and xfermode proc.
@param srcColor The source color passed to the xfermode proc
@param proc The xfermode proc that is applied to each color in the colorfilter's filterSpan method
@return colorfilter object that applies the src color and xfermode proc, or NULL if proc is NULL
*/
static SkColorFilter* CreatXfermodeFilter(SkColor srcColor, SkXfermodeProc proc);
/** Create a colorfilter that uses the specified color and porter-duff mode.
@param srcColor The source color used with the specified porter-duff mode
@param porterDuffMode The porter-duff mode that is applied to each color in the colorfilter's filterSpan method
@return colorfilter object that applies the src color and porter-duff mode, or NULL is mode is out of range
*/
static SkColorFilter* CreatePorterDuffFilter(SkColor srcColor, SkPorterDuff::Mode porterDuffMode);
/** Create a colorfilter that multiplies the RGB channels by one color, and then adds a second color,
pinning the result for each component to [0..255]. The alpha components of the mul and add arguments
are ignored.
*/
static SkColorFilter* CreateLightingFilter(SkColor mul, SkColor add);
};
#include "SkShader.h"
class SkFilterShader : public SkShader {
public:
SkFilterShader(SkShader* shader, SkColorFilter* filter);
virtual ~SkFilterShader();
// override
virtual bool setContext(const SkBitmap& device, const SkPaint& paint, const SkMatrix& matrix);
virtual void shadeSpan(int x, int y, SkPMColor result[], int count);
private:
SkShader* fShader;
SkColorFilter* fFilter;
typedef SkShader INHERITED;
};
#endif