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
21public class ImageFilterSharpen extends ImageFilterRS {
22
23    private static final String LOGTAG = "ImageFilterSharpen";
24    private ScriptC_convolve3x3 mScript;
25
26    public ImageFilterSharpen() {
27        mName = "Sharpen";
28    }
29
30    @Override
31    public void createFilter(android.content.res.Resources res, float scaleFactor,
32            boolean highQuality) {
33        int w = mInPixelsAllocation.getType().getX();
34        int h = mInPixelsAllocation.getType().getY();
35
36        float p1 = mParameter * scaleFactor;
37        float value = p1 / 100.0f;
38        float f[] = new float[9];
39        float p = value;
40        f[0] = -p;
41        f[1] = -p;
42        f[2] = -p;
43        f[3] = -p;
44        f[4] = 8 * p + 1;
45        f[5] = -p;
46        f[6] = -p;
47        f[7] = -p;
48        f[8] = -p;
49        if (mScript == null) {
50            mScript = new ScriptC_convolve3x3(getRenderScriptContext(), res, R.raw.convolve3x3);
51        }
52        mScript.set_gCoeffs(f);
53        mScript.set_gWidth(w);
54        mScript.set_gHeight(h);
55    }
56
57    @Override
58    public void runFilter() {
59        mScript.set_gIn(mInPixelsAllocation);
60        mScript.bind_gPixels(mInPixelsAllocation);
61        mScript.forEach_root(mInPixelsAllocation, mOutPixelsAllocation);
62    }
63
64}
65