ImageFilterHue.java revision 8cc3b55d615b349b4fcdff0eeeefe6907d4950ff
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;
20
21import android.graphics.Bitmap;
22
23public class ImageFilterHue extends ImageFilter {
24    private ColorSpaceMatrix cmatrix = null;
25
26    public ImageFilterHue() {
27        mName = "Hue";
28        cmatrix = new ColorSpaceMatrix();
29        mMaxParameter = 180;
30        mMinParameter = -180;
31    }
32
33    @Override
34    public int getButtonId() {
35        return R.id.hueButton;
36    }
37
38    @Override
39    public int getTextId() {
40        return R.string.hue;
41    }
42
43    @Override
44    public ImageFilter clone() throws CloneNotSupportedException {
45        ImageFilterHue filter = (ImageFilterHue) super.clone();
46        filter.cmatrix = new ColorSpaceMatrix(cmatrix);
47        return filter;
48    }
49
50    native protected void nativeApplyFilter(Bitmap bitmap, int w, int h, float []matrix);
51
52    @Override
53    public Bitmap apply(Bitmap bitmap, float scaleFactor, boolean highQuality) {
54        int w = bitmap.getWidth();
55        int h = bitmap.getHeight();
56        float p = mParameter;
57        float value = p;
58        cmatrix.identity();
59        cmatrix.setHue(value);
60
61        nativeApplyFilter(bitmap, w, h, cmatrix.getMatrix());
62
63        return bitmap;
64    }
65}
66