ImageFilterHue.java revision 5aa08941bda0cfbcfba522c53937dd66867f890d
1/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
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
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17package com.android.gallery3d.filtershow.filters;
18
19import com.android.gallery3d.R;
20import com.android.gallery3d.filtershow.editors.BasicEditor;
21
22import android.graphics.Bitmap;
23
24public class ImageFilterHue extends ImageFilter {
25    private ColorSpaceMatrix cmatrix = null;
26
27    public ImageFilterHue() {
28        mName = "Hue";
29        cmatrix = new ColorSpaceMatrix();
30        mMaxParameter = 180;
31        mMinParameter = -180;
32    }
33
34    @Override
35    public int getButtonId() {
36        return R.id.hueButton;
37    }
38
39    @Override
40    public int getTextId() {
41        return R.string.hue;
42    }
43
44    @Override
45    public int getEditingViewId() {
46        return BasicEditor.ID;
47    }
48
49    @Override
50    public ImageFilter clone() throws CloneNotSupportedException {
51        ImageFilterHue filter = (ImageFilterHue) super.clone();
52        filter.cmatrix = new ColorSpaceMatrix(cmatrix);
53        return filter;
54    }
55
56    native protected void nativeApplyFilter(Bitmap bitmap, int w, int h, float []matrix);
57
58    @Override
59    public Bitmap apply(Bitmap bitmap, float scaleFactor, boolean highQuality) {
60        int w = bitmap.getWidth();
61        int h = bitmap.getHeight();
62        float p = mParameter;
63        float value = p;
64        cmatrix.identity();
65        cmatrix.setHue(value);
66
67        nativeApplyFilter(bitmap, w, h, cmatrix.getMatrix());
68
69        return bitmap;
70    }
71}
72