2 * Copyright (C) 2013 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.android.gallery3d.filtershow.filters;
19 import android.util.JsonReader;
20 import android.util.JsonWriter;
22 import com.android.gallery3d.R;
23 import com.android.gallery3d.filtershow.controller.BasicParameterInt;
24 import com.android.gallery3d.filtershow.controller.Parameter;
25 import com.android.gallery3d.filtershow.controller.ParameterSet;
26 import com.android.gallery3d.filtershow.editors.EditorChanSat;
27 import com.android.gallery3d.filtershow.imageshow.ControlPoint;
28 import com.android.gallery3d.filtershow.imageshow.Spline;
30 import java.io.IOException;
31 import java.util.Vector;
34 * Representation for a filter that has per channel & Master saturation
36 public class FilterChanSatRepresentation extends FilterRepresentation implements ParameterSet {
37 private static final String LOGTAG = "FilterChanSatRepresentation";
38 private static final String ARGS = "ARGS";
39 private static final String SERIALIZATION_NAME = "channelsaturation";
41 public static final int MODE_MASTER = 0;
42 public static final int MODE_RED = 1;
43 public static final int MODE_YELLOW = 2;
44 public static final int MODE_GREEN = 3;
45 public static final int MODE_CYAN = 4;
46 public static final int MODE_BLUE = 5;
47 public static final int MODE_MAGENTA = 6;
48 private int mParameterMode = MODE_MASTER;
50 private static int MINSAT = -100;
51 private static int MAXSAT = 100;
52 private BasicParameterInt mParamMaster = new BasicParameterInt(MODE_MASTER, 0, MINSAT, MAXSAT);
53 private BasicParameterInt mParamRed = new BasicParameterInt(MODE_RED, 0, MINSAT, MAXSAT);
54 private BasicParameterInt mParamYellow = new BasicParameterInt(MODE_YELLOW, 0, MINSAT, MAXSAT);
55 private BasicParameterInt mParamGreen = new BasicParameterInt(MODE_GREEN, 0, MINSAT, MAXSAT);
56 private BasicParameterInt mParamCyan = new BasicParameterInt(MODE_CYAN, 0, MINSAT, MAXSAT);
57 private BasicParameterInt mParamBlue = new BasicParameterInt(MODE_BLUE, 0, MINSAT, MAXSAT);
58 private BasicParameterInt mParamMagenta = new BasicParameterInt(MODE_MAGENTA, 0, MINSAT, MAXSAT);
60 private BasicParameterInt[] mAllParam = {
69 public FilterChanSatRepresentation() {
70 super("ChannelSaturation");
71 setTextId(R.string.saturation);
72 setFilterType(FilterRepresentation.TYPE_NORMAL);
73 setSerializationName(SERIALIZATION_NAME);
74 setFilterClass(ImageFilterChanSat.class);
75 setEditorId(EditorChanSat.ID);
76 setSupportsPartialRendering(true);
79 public String toString() {
80 return getName() + " : " + mParamRed + ", " + mParamCyan + ", " + mParamRed
81 + ", " + mParamGreen + ", " + mParamMaster + ", " + mParamYellow;
85 public FilterRepresentation copy() {
86 FilterChanSatRepresentation representation = new FilterChanSatRepresentation();
87 copyAllParameters(representation);
88 return representation;
92 protected void copyAllParameters(FilterRepresentation representation) {
93 super.copyAllParameters(representation);
94 representation.useParametersFrom(this);
97 public void useParametersFrom(FilterRepresentation a) {
98 if (a instanceof FilterChanSatRepresentation) {
99 FilterChanSatRepresentation representation = (FilterChanSatRepresentation) a;
101 for (int i = 0; i < mAllParam.length; i++) {
102 mAllParam[i].copyFrom(representation.mAllParam[i]);
108 public boolean equals(FilterRepresentation representation) {
109 if (!super.equals(representation)) {
112 if (representation instanceof FilterChanSatRepresentation) {
113 FilterChanSatRepresentation rep = (FilterChanSatRepresentation) representation;
114 for (int i = 0; i < mAllParam.length; i++) {
115 if (rep.getValue(i) != getValue(i))
123 public int getValue(int mode) {
124 return mAllParam[mode].getValue();
127 public void setValue(int mode, int value) {
128 mAllParam[mode].setValue(value);
131 public int getMinimum() {
132 return mParamMaster.getMinimum();
135 public int getMaximum() {
136 return mParamMaster.getMaximum();
139 public int getParameterMode() {
140 return mParameterMode;
143 public void setParameterMode(int parameterMode) {
144 mParameterMode = parameterMode;
147 public int getCurrentParameter() {
148 return getValue(mParameterMode);
151 public void setCurrentParameter(int value) {
152 setValue(mParameterMode, value);
156 public int getNumberOfParameters() {
161 public Parameter getFilterParameter(int index) {
162 return mAllParam[index];
166 public void serializeRepresentation(JsonWriter writer) throws IOException {
167 writer.beginObject();
171 writer.value(getValue(MODE_MASTER));
172 writer.value(getValue(MODE_RED));
173 writer.value(getValue(MODE_YELLOW));
174 writer.value(getValue(MODE_GREEN));
175 writer.value(getValue(MODE_CYAN));
176 writer.value(getValue(MODE_BLUE));
177 writer.value(getValue(MODE_MAGENTA));
183 public void deSerializeRepresentation(JsonReader sreader) throws IOException {
184 sreader.beginObject();
186 while (sreader.hasNext()) {
187 String name = sreader.nextName();
188 if (name.startsWith(ARGS)) {
189 sreader.beginArray();
191 setValue(MODE_MASTER, sreader.nextInt());
193 setValue(MODE_RED, sreader.nextInt());
195 setValue(MODE_YELLOW, sreader.nextInt());
197 setValue(MODE_GREEN, sreader.nextInt());
199 setValue(MODE_CYAN, sreader.nextInt());
201 setValue(MODE_BLUE, sreader.nextInt());
203 setValue(MODE_MAGENTA, sreader.nextInt());