-
Notifications
You must be signed in to change notification settings - Fork 22.4k
/
index.md
285 lines (262 loc) · 8.91 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
---
title: <feComposite>
slug: Web/SVG/Element/feComposite
page-type: svg-element
browser-compat: svg.elements.feComposite
---
{{SVGRef}}
The **`<feComposite>`** [SVG](/en-US/docs/Web/SVG) filter primitive performs the combination of two input images pixel-wise in image space using one of the Porter-Duff compositing operations: `over`, `in`, `atop`, `out`, `xor`, `lighter`, or `arithmetic`.
The table below shows each of these operations using an image of the MDN logo composited with a red circle:
<table class="no-markdown">
<tbody>
<tr>
<th>Operation</th>
<th>Description</th>
</tr>
<tr>
<td>
<p>over <img src="operation_over.png" alt="over operator" /></p>
</td>
<td>
The source graphic defined by the {{SVGAttr("in")}} attribute
(the MDN logo) is placed over the destination graphic defined by the
{{SVGAttr("in2")}} attribute (the circle).
<p>
This is the <em>default operation</em>, which will be used if no
operation or an unsupported operation is specified.
</p>
</td>
</tr>
<tr>
<td>
<p>in <img src="operation_in.png" alt="in operator" /></p>
</td>
<td>
The parts of the source graphic defined by the <code>in</code> attribute
that overlap the destination graphic defined in the
<code>in2</code> attribute, replace the destination graphic.
</td>
</tr>
<tr>
<td>
<p>out <img src="operation_out.png" alt="out operator" /></p>
</td>
<td>
The parts of the source graphic defined by the <code>in</code> attribute
that fall outside the destination graphic defined in the
<code>in2</code> attribute, are displayed.
</td>
</tr>
<tr>
<td>
<p>atop <img src="operation_atop.png" alt="atop operator" /></p>
</td>
<td>
The parts of the source graphic defined in the
<code>in</code> attribute, which overlap the destination graphic defined
in the <code>in2</code> attribute, replace the destination graphic. The
parts of the destination graphic that do not overlap with the source
graphic stay untouched.
</td>
</tr>
<tr>
<td>
<p>xor <img src="operation_xor.png" alt="xor operator" /></p>
</td>
<td>
The non-overlapping regions of the source graphic defined in the
<code>in</code> attribute and the destination graphic defined in the
<code>in2</code> attribute are combined.
</td>
</tr>
<tr>
<td>
<p>
lighter <img src="operation_lighter.png" alt="lighter operator" />
</p>
</td>
<td>
The sum of the source graphic defined in the <code>in</code> attribute
and the destination graphic defined in the <code>in2</code> attribute is
displayed.
</td>
</tr>
<tr>
<td>
<p>
arithmetic
<img src="operation_arithmetic.png" alt="arithmetic operator" />
</p>
</td>
<td>
<p>
The <code>arithmetic</code> operation is useful for combining the
output from the {{SVGElement("feDiffuseLighting")}} and
{{SVGElement("feSpecularLighting")}} filters with texture
data. If the <code>arithmetic</code> operation is chosen, each result
pixel is computed using the following formula:
</p>
<pre class="brush: plain">result = k1*i1*i2 + k2*i1 + k3*i2 + k4</pre>
<p>where:</p>
<ul>
<li>
<code>i1</code> and <code>i2</code> indicate the corresponding pixel
channel values of the input image, which map to
{{SVGAttr("in")}} and {{SVGAttr("in2")}} respectively
</li>
<li>
{{SVGAttr("k1")}}, {{SVGAttr("k2")}},
{{SVGAttr("k3")}}, and {{SVGAttr("k4")}} indicate the
values of the attributes with the same name.
</li>
</ul>
</td>
</tr>
</tbody>
</table>
## Usage context
{{svginfo}}
## Attributes
- {{SVGAttr("in")}}: First input for the given filter primitive.
- {{SVGAttr("in2")}}: Second input for the given filter primitive (works the same as the `in` attribute).
- {{SVGAttr("operator")}}: `over` | `in` | `out` | `atop` | `xor` | `lighter` | `arithmetic`
- {{SVGAttr("k1")}}, {{SVGAttr("k2")}}, {{SVGAttr("k3")}}, {{SVGAttr("k4")}}: Values used for calculating the result pixel in `arithmetic` {{SVGAttr("operator")}} filter primitives.
## DOM Interface
This element implements the {{domxref("SVGFECompositeElement")}} interface.
## Example
This example defines filters for each of the supported operations (`over`, `atop`, `lighter`, etc.), which composite an input `SourceGraphic` with an image of the MDN logo. The filters are each applied to a circle element, which is then used as the `SourceGraphic`.
> **Note:** `BackgroundImage` cannot be used as a compositing source on modern browsers, so we can't define a filter that composites using whatever pixels happen to be under the filter as one of the sources. The approach taken here is a [workaround because we can't use `BackgroundImage`](/en-US/docs/Web/SVG/Attribute/in#workaround_for_backgroundimage).
### SVG
```html
<svg
style="width:800px; height:400px; display: inline;"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<filter id="imageOver">
<feImage href="mdn_logo_only_color.png" x="10px" y="10px" width="160px" />
<feComposite in2="SourceGraphic" operator="over" />
</filter>
<filter id="imageIn">
<feImage href="mdn_logo_only_color.png" x="10px" y="10px" width="160px" />
<feComposite in2="SourceGraphic" operator="in" />
</filter>
<filter id="imageOut">
<feImage href="mdn_logo_only_color.png" x="10px" y="10px" width="160px" />
<feComposite in2="SourceGraphic" operator="out" />
</filter>
<filter id="imageAtop">
<feImage href="mdn_logo_only_color.png" x="10px" y="10px" width="160px" />
<feComposite in2="SourceGraphic" operator="atop" />
</filter>
<filter id="imageXor">
<feImage href="mdn_logo_only_color.png" x="10px" y="10px" width="160px" />
<feComposite in2="SourceGraphic" operator="xor" />
</filter>
<filter id="imageArithmetic">
<feImage href="mdn_logo_only_color.png" x="10px" y="10px" width="160px" />
<feComposite
in2="SourceGraphic"
operator="arithmetic"
k1="0.1"
k2="0.2"
k3="0.3"
k4="0.4" />
</filter>
<filter id="imageLighter">
<feImage href="mdn_logo_only_color.png" x="10px" y="10px" width="160px" />
<feComposite in2="SourceGraphic" operator="lighter" />
</filter>
</defs>
<g transform="translate(0,25)">
<circle
cx="90px"
cy="80px"
r="70px"
fill="#c00"
style="filter:url(#imageOver)" />
<text x="80" y="-5">over</text>
</g>
<g transform="translate(200,25)">
<circle
cx="90px"
cy="80px"
r="70px"
fill="#c00"
style="filter:url(#imageIn)" />
<text x="80" y="-5">in</text>
</g>
<g transform="translate(400,25)">
<circle
cx="90px"
cy="80px"
r="70px"
fill="#c00"
style="filter:url(#imageOut)" />
<text x="80" y="-5">out</text>
</g>
<g transform="translate(600,25)">
<circle
cx="90px"
cy="80px"
r="70px"
fill="#c00"
style="filter:url(#imageAtop)" />
<text x="80" y="-5">atop</text>
</g>
<g transform="translate(0,240)">
<circle
cx="90px"
cy="80px"
r="70px"
fill="#c00"
style="filter:url(#imageXor)" />
<text x="80" y="-5">xor</text>
</g>
<g transform="translate(200,240)">
<circle
cx="90px"
cy="80px"
r="70px"
fill="#c00"
style="filter:url(#imageArithmetic)" />
<text x="70" y="-5">arithmetic</text>
</g>
<g transform="translate(400,240)">
<circle
cx="90px"
cy="80px"
r="70px"
fill="#c00"
style="filter:url(#imageLighter)" />
<text x="80" y="-5">lighter</text>
</g>
</svg>
```
### Result
{{EmbedLiveSample("Example", 100, 450)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [SVG filter primitive attributes](/en-US/docs/Web/SVG/Attribute#filter_primitive_attributes)
- {{SVGElement("filter")}}
- {{SVGElement("animate")}}
- {{SVGElement("set")}}
- {{SVGElement("feBlend")}}
- {{SVGElement("feColorMatrix")}}
- {{SVGElement("feComponentTransfer")}}
- {{SVGElement("feConvolveMatrix")}}
- {{SVGElement("feDiffuseLighting")}}
- {{SVGElement("feDisplacementMap")}}
- {{SVGElement("feFlood")}}
- {{SVGElement("feGaussianBlur")}}
- {{SVGElement("feImage")}}
- {{SVGElement("feMerge")}}
- {{SVGElement("feMorphology")}}
- {{SVGElement("feOffset")}}
- {{SVGElement("feSpecularLighting")}}
- {{SVGElement("feTile")}}
- {{SVGElement("feTurbulence")}}
- [SVG tutorial: Filter effects](/en-US/docs/Web/SVG/Tutorial/Filter_effects)