1 | /*
|
---|
2 | * SVG Salamander
|
---|
3 | * Copyright (c) 2004, Mark McKay
|
---|
4 | * All rights reserved.
|
---|
5 | *
|
---|
6 | * Redistribution and use in source and binary forms, with or
|
---|
7 | * without modification, are permitted provided that the following
|
---|
8 | * conditions are met:
|
---|
9 | *
|
---|
10 | * - Redistributions of source code must retain the above
|
---|
11 | * copyright notice, this list of conditions and the following
|
---|
12 | * disclaimer.
|
---|
13 | * - Redistributions in binary form must reproduce the above
|
---|
14 | * copyright notice, this list of conditions and the following
|
---|
15 | * disclaimer in the documentation and/or other materials
|
---|
16 | * provided with the distribution.
|
---|
17 | *
|
---|
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
---|
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
---|
20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
---|
21 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
---|
22 | * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
---|
23 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
---|
24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
---|
25 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
---|
26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
---|
27 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
---|
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
---|
29 | * OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
30 | *
|
---|
31 | * Mark McKay can be contacted at mark@kitfox.com. Salamander and other
|
---|
32 | * projects can be found at http://www.kitfox.com
|
---|
33 | *
|
---|
34 | * Created on April 1, 2004, 6:41 AM
|
---|
35 | */
|
---|
36 |
|
---|
37 | package com.kitfox.svg.composite;
|
---|
38 |
|
---|
39 | import java.awt.*;
|
---|
40 | import java.awt.image.*;
|
---|
41 |
|
---|
42 | /**
|
---|
43 | * @author Mark McKay
|
---|
44 | * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
|
---|
45 | */
|
---|
46 | public class AdobeCompositeContext implements CompositeContext
|
---|
47 | {
|
---|
48 | final int compositeType;
|
---|
49 | final float extraAlpha;
|
---|
50 |
|
---|
51 | float[] rgba_src = new float[4];
|
---|
52 | float[] rgba_dstIn = new float[4];
|
---|
53 | float[] rgba_dstOut = new float[4];
|
---|
54 |
|
---|
55 | /** Creates a new instance of AdobeCompositeContext */
|
---|
56 | public AdobeCompositeContext(int compositeType, float extraAlpha)
|
---|
57 | {
|
---|
58 | this.compositeType = compositeType;
|
---|
59 | this.extraAlpha = extraAlpha;
|
---|
60 |
|
---|
61 | rgba_dstOut[3] = 1f;
|
---|
62 | }
|
---|
63 |
|
---|
64 | public void compose(Raster src, Raster dstIn, WritableRaster dstOut)
|
---|
65 | {
|
---|
66 | int width = src.getWidth();
|
---|
67 | int height = src.getHeight();
|
---|
68 |
|
---|
69 | for (int j = 0; j < height; j++)
|
---|
70 | {
|
---|
71 | for (int i = 0; i < width; i++)
|
---|
72 | {
|
---|
73 | src.getPixel(i, j, rgba_src);
|
---|
74 | dstIn.getPixel(i, j, rgba_dstIn);
|
---|
75 |
|
---|
76 | //Ignore transparent pixels
|
---|
77 | if (rgba_src[3] == 0)
|
---|
78 | {
|
---|
79 | // dstOut.setPixel(i, j, rgba_dstIn);
|
---|
80 | continue;
|
---|
81 | }
|
---|
82 |
|
---|
83 | float alpha = rgba_src[3];
|
---|
84 |
|
---|
85 | switch (compositeType)
|
---|
86 | {
|
---|
87 | default:
|
---|
88 | case AdobeComposite.CT_NORMAL:
|
---|
89 | rgba_dstOut[0] = rgba_src[0] * alpha + rgba_dstIn[0] * (1f - alpha);
|
---|
90 | rgba_dstOut[1] = rgba_src[1] * alpha + rgba_dstIn[1] * (1f - alpha);
|
---|
91 | rgba_dstOut[2] = rgba_src[2] * alpha + rgba_dstIn[2] * (1f - alpha);
|
---|
92 | break;
|
---|
93 | case AdobeComposite.CT_MULTIPLY:
|
---|
94 | rgba_dstOut[0] = rgba_src[0] * rgba_dstIn[0] * alpha + rgba_dstIn[0] * (1f - alpha);
|
---|
95 | rgba_dstOut[1] = rgba_src[1] * rgba_dstIn[1] * alpha + rgba_dstIn[1] * (1f - alpha);
|
---|
96 | rgba_dstOut[2] = rgba_src[2] * rgba_dstIn[2] * alpha + rgba_dstIn[2] * (1f - alpha);
|
---|
97 | break;
|
---|
98 | }
|
---|
99 | }
|
---|
100 | }
|
---|
101 | }
|
---|
102 |
|
---|
103 | public void dispose() {
|
---|
104 | }
|
---|
105 |
|
---|
106 | }
|
---|