1a9f280f938b5fd5891c5cfe0999f8f1d4945d7a1nicolasroard/*
2a9f280f938b5fd5891c5cfe0999f8f1d4945d7a1nicolasroard * Copyright (C) 2012 The Android Open Source Project
3a9f280f938b5fd5891c5cfe0999f8f1d4945d7a1nicolasroard *
4a9f280f938b5fd5891c5cfe0999f8f1d4945d7a1nicolasroard * Licensed under the Apache License, Version 2.0 (the "License");
5a9f280f938b5fd5891c5cfe0999f8f1d4945d7a1nicolasroard * you may not use this file except in compliance with the License.
6a9f280f938b5fd5891c5cfe0999f8f1d4945d7a1nicolasroard * You may obtain a copy of the License at
7a9f280f938b5fd5891c5cfe0999f8f1d4945d7a1nicolasroard *
8a9f280f938b5fd5891c5cfe0999f8f1d4945d7a1nicolasroard *      http://www.apache.org/licenses/LICENSE-2.0
9a9f280f938b5fd5891c5cfe0999f8f1d4945d7a1nicolasroard *
10a9f280f938b5fd5891c5cfe0999f8f1d4945d7a1nicolasroard * Unless required by applicable law or agreed to in writing, software
11a9f280f938b5fd5891c5cfe0999f8f1d4945d7a1nicolasroard * distributed under the License is distributed on an "AS IS" BASIS,
12a9f280f938b5fd5891c5cfe0999f8f1d4945d7a1nicolasroard * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13a9f280f938b5fd5891c5cfe0999f8f1d4945d7a1nicolasroard * See the License for the specific language governing permissions and
14a9f280f938b5fd5891c5cfe0999f8f1d4945d7a1nicolasroard * limitations under the License.
15a9f280f938b5fd5891c5cfe0999f8f1d4945d7a1nicolasroard */
16d42f6c69c5980110c16cd679f914c4e4e7caa29dJohn Hoford
17d42f6c69c5980110c16cd679f914c4e4e7caa29dJohn Hofordpackage com.android.gallery3d.filtershow.filters;
18d42f6c69c5980110c16cd679f914c4e4e7caa29dJohn Hoford
198cc3b55d615b349b4fcdff0eeeefe6907d4950ffnicolasroardimport com.android.gallery3d.R;
205aa08941bda0cfbcfba522c53937dd66867f890dJohn Hofordimport com.android.gallery3d.filtershow.editors.BasicEditor;
218cc3b55d615b349b4fcdff0eeeefe6907d4950ffnicolasroard
22d42f6c69c5980110c16cd679f914c4e4e7caa29dJohn Hofordimport android.graphics.Bitmap;
23d42f6c69c5980110c16cd679f914c4e4e7caa29dJohn Hoford
2471f04cbaedbb89e313e0b86b531640db2d3f6016nicolasroardpublic class ImageFilterHue extends SimpleImageFilter {
25afa8ed9d46e760d4b0c0331cfcb4bb49ef6ba280John Hoford    private static final String SERIALIZATION_NAME = "HUE";
26bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard    private ColorSpaceMatrix cmatrix = null;
27d42f6c69c5980110c16cd679f914c4e4e7caa29dJohn Hoford
28bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard    public ImageFilterHue() {
29bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard        mName = "Hue";
30bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard        cmatrix = new ColorSpaceMatrix();
3171f04cbaedbb89e313e0b86b531640db2d3f6016nicolasroard    }
3271f04cbaedbb89e313e0b86b531640db2d3f6016nicolasroard
3371f04cbaedbb89e313e0b86b531640db2d3f6016nicolasroard    public FilterRepresentation getDefaultRepresentation() {
344b1e6fbdf437b7a25fb3eb18a2ed43c9ab4eccc8John Hoford        FilterBasicRepresentation representation =
354b1e6fbdf437b7a25fb3eb18a2ed43c9ab4eccc8John Hoford                (FilterBasicRepresentation) super.getDefaultRepresentation();
3671f04cbaedbb89e313e0b86b531640db2d3f6016nicolasroard        representation.setName("Hue");
37afa8ed9d46e760d4b0c0331cfcb4bb49ef6ba280John Hoford        representation.setSerializationName(SERIALIZATION_NAME);
3871f04cbaedbb89e313e0b86b531640db2d3f6016nicolasroard        representation.setFilterClass(ImageFilterHue.class);
3971f04cbaedbb89e313e0b86b531640db2d3f6016nicolasroard        representation.setMinimum(-180);
4071f04cbaedbb89e313e0b86b531640db2d3f6016nicolasroard        representation.setMaximum(180);
416900cad45d240c9a54b92991538b6a33652e766cnicolasroard        representation.setTextId(R.string.hue);
426900cad45d240c9a54b92991538b6a33652e766cnicolasroard        representation.setEditorId(BasicEditor.ID);
43e5498da0262fc836738aad63ea30286d8afa643cnicolasroard        representation.setSupportsPartialRendering(true);
4471f04cbaedbb89e313e0b86b531640db2d3f6016nicolasroard        return representation;
45d42f6c69c5980110c16cd679f914c4e4e7caa29dJohn Hoford    }
46d42f6c69c5980110c16cd679f914c4e4e7caa29dJohn Hoford
47d42f6c69c5980110c16cd679f914c4e4e7caa29dJohn Hoford    native protected void nativeApplyFilter(Bitmap bitmap, int w, int h, float []matrix);
48d42f6c69c5980110c16cd679f914c4e4e7caa29dJohn Hoford
4981eb9976f967d9b3faa1749a8ab29d1743cf347dnicolasroard    @Override
5099baf61387ab1ef15bb9db5fa3b2b55591e87059John Hoford    public Bitmap apply(Bitmap bitmap, float scaleFactor, int quality) {
5171f04cbaedbb89e313e0b86b531640db2d3f6016nicolasroard        if (getParameters() == null) {
5271f04cbaedbb89e313e0b86b531640db2d3f6016nicolasroard            return bitmap;
5371f04cbaedbb89e313e0b86b531640db2d3f6016nicolasroard        }
54d42f6c69c5980110c16cd679f914c4e4e7caa29dJohn Hoford        int w = bitmap.getWidth();
55d42f6c69c5980110c16cd679f914c4e4e7caa29dJohn Hoford        int h = bitmap.getHeight();
5671f04cbaedbb89e313e0b86b531640db2d3f6016nicolasroard        float value = getParameters().getValue();
57d42f6c69c5980110c16cd679f914c4e4e7caa29dJohn Hoford        cmatrix.identity();
58d42f6c69c5980110c16cd679f914c4e4e7caa29dJohn Hoford        cmatrix.setHue(value);
59d42f6c69c5980110c16cd679f914c4e4e7caa29dJohn Hoford
60d42f6c69c5980110c16cd679f914c4e4e7caa29dJohn Hoford        nativeApplyFilter(bitmap, w, h, cmatrix.getMatrix());
6181eb9976f967d9b3faa1749a8ab29d1743cf347dnicolasroard
6281eb9976f967d9b3faa1749a8ab29d1743cf347dnicolasroard        return bitmap;
63d42f6c69c5980110c16cd679f914c4e4e7caa29dJohn Hoford    }
64d42f6c69c5980110c16cd679f914c4e4e7caa29dJohn Hoford}
65