summaryrefslogtreecommitdiffstats
path: root/src/com/android/gallery3d/filtershow/filters/FilterVignetteRepresentation.java
blob: 9827088ff0c2b3c8fe5b0e55e09f0755f218fffe (plain)
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
/*
 * Copyright (C) 2012 The Android Open Source Project
 *
 * 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.
 */

package com.android.gallery3d.filtershow.filters;

import com.android.gallery3d.R;
import com.android.gallery3d.filtershow.editors.EditorVignette;
import com.android.gallery3d.filtershow.imageshow.Oval;

public class FilterVignetteRepresentation extends FilterBasicRepresentation implements Oval {
    private static final String LOGTAG = "FilterVignetteRepresentation";
    private float mCenterX = Float.NaN;
    private float mCenterY;
    private float mRadiusX = Float.NaN;
    private float mRadiusY;

    public FilterVignetteRepresentation() {
        super("Vignette", -100, 50, 100);
        setSerializationName("VIGNETTE");
        setShowParameterValue(true);
        setPriority(FilterRepresentation.TYPE_VIGNETTE);
        setTextId(R.string.vignette);
        setButtonId(R.id.vignetteEditor);
        setEditorId(EditorVignette.ID);
        setName("Vignette");
        setFilterClass(ImageFilterVignette.class);

        setMinimum(-100);
        setMaximum(100);
        setDefaultValue(0);
    }

    @Override
    public void useParametersFrom(FilterRepresentation a) {
        super.useParametersFrom(a);
        mCenterX = ((FilterVignetteRepresentation) a).mCenterX;
        mCenterY = ((FilterVignetteRepresentation) a).mCenterY;
        mRadiusX = ((FilterVignetteRepresentation) a).mRadiusX;
        mRadiusY = ((FilterVignetteRepresentation) a).mRadiusY;
    }

    @Override
    public FilterRepresentation clone() throws CloneNotSupportedException {
        FilterVignetteRepresentation representation = (FilterVignetteRepresentation) super
                .clone();
        representation.mCenterX = mCenterX;
        representation.mCenterY = mCenterY;

        return representation;
    }

    @Override
    public void setCenter(float centerX, float centerY) {
        mCenterX = centerX;
        mCenterY = centerY;
    }

    @Override
    public float getCenterX() {
        return mCenterX;
    }

    @Override
    public float getCenterY() {
        return mCenterY;
    }

    @Override
    public void setRadius(float radiusX, float radiusY) {
        mRadiusX = radiusX;
        mRadiusY = radiusY;
    }

    @Override
    public void setRadiusX(float radiusX) {
        mRadiusX = radiusX;
    }

    @Override
    public void setRadiusY(float radiusY) {
        mRadiusY = radiusY;
    }

    @Override
    public float getRadiusX() {
        return mRadiusX;
    }

    @Override
    public float getRadiusY() {
        return mRadiusY;
    }

    public boolean isCenterSet() {
        return mCenterX != Float.NaN;
    }

    @Override
    public boolean isNil() {
        return getValue() == 0;
    }

    private static final String[] sParams = {
            "Name", "value", "mCenterX", "mCenterY", "mRadiusX",
            "mRadiusY"
    };

    @Override
    public String[][] serializeRepresentation() {
        String[][] ret = {
                { sParams[0], getName() },
                { sParams[1], Integer.toString(getValue()) },
                { sParams[2], Float.toString(mCenterX) },
                { sParams[3], Float.toString(mCenterY) },
                { sParams[4], Float.toString(mRadiusX) },
                { sParams[5], Float.toString(mRadiusY) }
        };
        return ret;
    }

    @Override
    public void deSerializeRepresentation(String[][] rep) {
        super.deSerializeRepresentation(rep);
        for (int i = 0; i < rep.length; i++) {
            String key = rep[i][0];
            String value = rep[i][1];
            if (sParams[0].equals(key)) {
                setName(value);
            } else if (sParams[1].equals(key)) {
               setValue(Integer.parseInt(value));
            } else if (sParams[2].equals(key)) {
                mCenterX = Float.parseFloat(value);
            } else if (sParams[3].equals(key)) {
                mCenterY = Float.parseFloat(value);
            } else if (sParams[4].equals(key)) {
                mRadiusX = Float.parseFloat(value);
            } else if (sParams[5].equals(key)) {
                mRadiusY = Float.parseFloat(value);
            }
        }
    }
}