SkPorterDuff.h revision ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976e
1
2/*
3 * Copyright 2006 The Android Open Source Project
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9
10#ifndef SkPorterDuff_DEFINED
11#define SkPorterDuff_DEFINED
12
13#include "SkColor.h"
14#include "SkXfermode.h"
15
16class SkXfermode;
17
18/** DEPRECATED - use SkXfermode::Mode instead
19 */
20class SkPorterDuff {
21public:
22    /** List of predefined xfermodes. In general, the algebra for the modes
23        uses the following symbols:
24        Sa, Sc  - source alpha and color
25        Da, Dc - destination alpha and color (before compositing)
26        [a, c] - Resulting (alpha, color) values
27        For these equations, the colors are in premultiplied state.
28        If no xfermode is specified, kSrcOver is assumed.
29    */
30    enum Mode {
31        kClear_Mode,    //!< [0, 0]
32        kSrc_Mode,      //!< [Sa, Sc]
33        kDst_Mode,      //!< [Da, Dc]
34        kSrcOver_Mode,  //!< [Sa + Da - Sa*Da, Rc = Sc + (1 - Sa)*Dc]
35        kDstOver_Mode,  //!< [Sa + Da - Sa*Da, Rc = Dc + (1 - Da)*Sc]
36        kSrcIn_Mode,    //!< [Sa * Da, Sc * Da]
37        kDstIn_Mode,    //!< [Sa * Da, Sa * Dc]
38        kSrcOut_Mode,   //!< [Sa * (1 - Da), Sc * (1 - Da)]
39        kDstOut_Mode,   //!< [Da * (1 - Sa), Dc * (1 - Sa)]
40        kSrcATop_Mode,  //!< [Da, Sc * Da + (1 - Sa) * Dc]
41        kDstATop_Mode,  //!< [Sa, Sa * Dc + Sc * (1 - Da)]
42        kXor_Mode,      //!< [Sa + Da - 2 * Sa * Da, Sc * (1 - Da) + (1 - Sa) * Dc]
43        kDarken_Mode,   //!< [Sa + Da - Sa*Da, Sc*(1 - Da) + Dc*(1 - Sa) + min(Sc, Dc)]
44        kLighten_Mode,  //!< [Sa + Da - Sa*Da, Sc*(1 - Da) + Dc*(1 - Sa) + max(Sc, Dc)]
45        kMultiply_Mode, //!< [Sa * Da, Sc * Dc]
46        kScreen_Mode,   //!< [Sa + Da - Sa * Da, Sc + Dc - Sc * Dc]
47        kAdd_Mode,      //!< Saturate(S + D)
48#ifdef ANDROID
49        kOverlay_Mode,
50#endif
51
52        kModeCount
53    };
54
55    /** Return an SkXfermode object for the specified mode.
56    */
57    static SkXfermode* CreateXfermode(Mode mode);
58
59    /** Return a function pointer to a routine that applies the specified
60        porter-duff transfer mode.
61    */
62    static SkXfermodeProc GetXfermodeProc(Mode mode);
63
64    /** Return a function pointer to a routine that applies the specified
65        porter-duff transfer mode and srcColor to a 16bit device color. Note,
66        if the mode+srcColor might return a non-opaque color, then there is not
67        16bit proc, and this will return NULL.
68    */
69    static SkXfermodeProc16 GetXfermodeProc16(Mode mode, SkColor srcColor);
70
71    /** If the specified xfermode advertises itself as one of the porterduff
72        modes (via SkXfermode::Coeff), return true and if not null, set mode
73        to the corresponding porterduff mode. If it is not recognized as a one,
74        return false and ignore the mode parameter.
75    */
76    static bool IsMode(SkXfermode*, Mode* mode);
77
78    /** Return the corersponding SkXfermode::Mode
79     */
80    static SkXfermode::Mode ToXfermodeMode(Mode);
81};
82
83#endif
84
85