24
|
1 |
/* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
*
|
|
3 |
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
4 |
* copy of this software and /or associated documentation files
|
|
5 |
* (the "Materials "), to deal in the Materials without restriction,
|
|
6 |
* including without limitation the rights to use, copy, modify, merge,
|
|
7 |
* publish, distribute, sublicense, and/or sell copies of the Materials,
|
|
8 |
* and to permit persons to whom the Materials are furnished to do so,
|
|
9 |
* subject to the following conditions:
|
|
10 |
*
|
|
11 |
* The above copyright notice and this permission notice shall be included
|
|
12 |
* in all copies or substantial portions of the Materials.
|
|
13 |
*
|
|
14 |
* THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15 |
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16 |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
17 |
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
18 |
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
19 |
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
|
|
20 |
* THE USE OR OTHER DEALINGS IN THE MATERIALS.
|
|
21 |
*/
|
|
22 |
|
|
23 |
#ifndef __SFMASK_H
|
|
24 |
#define __SFMASK_H
|
|
25 |
|
|
26 |
#include "VG/openvg.h"
|
|
27 |
|
|
28 |
#ifndef __RIDEFS_H
|
|
29 |
# include "riDefs.h"
|
|
30 |
#endif
|
|
31 |
|
|
32 |
#ifndef __RIIMAGE_H
|
|
33 |
# include "riImage.h"
|
|
34 |
#endif
|
|
35 |
|
|
36 |
// Contains implementations of some mask operations that are needed in both the
|
|
37 |
// pixel-pipeline and the blitter.
|
|
38 |
|
|
39 |
namespace OpenVGRI {
|
|
40 |
|
|
41 |
RI_INLINE IntegerColor intMaskOperation(RIuint32 coverage, const IntegerColor& d, VGMaskOperation maskOperation);
|
|
42 |
|
|
43 |
RI_INLINE IntegerColor intMaskOperation(RIuint32 coverage, const IntegerColor& d, VGMaskOperation maskOperation)
|
|
44 |
{
|
|
45 |
RIuint32 newCoverage;
|
|
46 |
switch (maskOperation)
|
|
47 |
{
|
|
48 |
case VG_SET_MASK:
|
|
49 |
// \note This should work approximately if coverage < 256 always.
|
|
50 |
// See other cases for proper conversions.
|
|
51 |
return IntegerColor(0, 0, 0, coverage); // nop.
|
|
52 |
break;
|
|
53 |
case VG_UNION_MASK:
|
|
54 |
{
|
|
55 |
RIuint32 oldCoverage = d.a;
|
|
56 |
oldCoverage += (oldCoverage >> 7);
|
|
57 |
RIuint32 im = 256 - coverage;
|
|
58 |
RIuint32 ip = 256 - oldCoverage;
|
|
59 |
newCoverage = 256 - ((im * ip) >> 8);
|
|
60 |
break;
|
|
61 |
}
|
|
62 |
case VG_INTERSECT_MASK:
|
|
63 |
{
|
|
64 |
RIuint32 oldCoverage = d.a;
|
|
65 |
oldCoverage += (oldCoverage >> 7);
|
|
66 |
newCoverage = (coverage * oldCoverage) >> 8;
|
|
67 |
break;
|
|
68 |
}
|
|
69 |
default:
|
|
70 |
{
|
|
71 |
RI_ASSERT(maskOperation == VG_SUBTRACT_MASK);
|
|
72 |
RIuint32 im = 256 - coverage;
|
|
73 |
RIuint32 oldCoverage = d.a;
|
|
74 |
oldCoverage += (oldCoverage >> 7);
|
|
75 |
newCoverage = (oldCoverage * im) >> 8;
|
|
76 |
break;
|
|
77 |
}
|
|
78 |
}
|
|
79 |
return IntegerColor(0, 0, 0, newCoverage - (newCoverage >> 8));
|
|
80 |
}
|
|
81 |
|
|
82 |
}
|
|
83 |
|
|
84 |
#endif
|
|
85 |
|