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 */ 160d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard 170d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroardpackage com.android.gallery3d.filtershow.filters; 180d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard 198cc3b55d615b349b4fcdff0eeeefe6907d4950ffnicolasroardimport com.android.gallery3d.R; 208cc3b55d615b349b4fcdff0eeeefe6907d4950ffnicolasroard 210d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroardimport android.graphics.Bitmap; 220d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard 2371f04cbaedbb89e313e0b86b531640db2d3f6016nicolasroardpublic class ImageFilterSaturated extends SimpleImageFilter { 24afa8ed9d46e760d4b0c0331cfcb4bb49ef6ba280John Hoford private static final String SERIALIZATION_NAME = "SATURATED"; 25bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard public ImageFilterSaturated() { 26bf93da72576b28f4e9dfb27f8f3fef702c8ae82dnicolasroard mName = "Saturated"; 270d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard } 280d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard 294b1e6fbdf437b7a25fb3eb18a2ed43c9ab4eccc8John Hoford @Override 3071f04cbaedbb89e313e0b86b531640db2d3f6016nicolasroard public FilterRepresentation getDefaultRepresentation() { 314b1e6fbdf437b7a25fb3eb18a2ed43c9ab4eccc8John Hoford FilterBasicRepresentation representation = 324b1e6fbdf437b7a25fb3eb18a2ed43c9ab4eccc8John Hoford (FilterBasicRepresentation) super.getDefaultRepresentation(); 3371f04cbaedbb89e313e0b86b531640db2d3f6016nicolasroard representation.setName("Saturated"); 34afa8ed9d46e760d4b0c0331cfcb4bb49ef6ba280John Hoford representation.setSerializationName(SERIALIZATION_NAME); 3571f04cbaedbb89e313e0b86b531640db2d3f6016nicolasroard representation.setFilterClass(ImageFilterSaturated.class); 366900cad45d240c9a54b92991538b6a33652e766cnicolasroard representation.setTextId(R.string.saturation); 374b1e6fbdf437b7a25fb3eb18a2ed43c9ab4eccc8John Hoford representation.setMinimum(-100); 384b1e6fbdf437b7a25fb3eb18a2ed43c9ab4eccc8John Hoford representation.setMaximum(100); 394b1e6fbdf437b7a25fb3eb18a2ed43c9ab4eccc8John Hoford representation.setDefaultValue(0); 40e5498da0262fc836738aad63ea30286d8afa643cnicolasroard representation.setSupportsPartialRendering(true); 4171f04cbaedbb89e313e0b86b531640db2d3f6016nicolasroard return representation; 4271f04cbaedbb89e313e0b86b531640db2d3f6016nicolasroard } 4371f04cbaedbb89e313e0b86b531640db2d3f6016nicolasroard 440d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard native protected void nativeApplyFilter(Bitmap bitmap, int w, int h, float saturation); 450d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard 4681eb9976f967d9b3faa1749a8ab29d1743cf347dnicolasroard @Override 4799baf61387ab1ef15bb9db5fa3b2b55591e87059John Hoford public Bitmap apply(Bitmap bitmap, float scaleFactor, int quality) { 4871f04cbaedbb89e313e0b86b531640db2d3f6016nicolasroard if (getParameters() == null) { 4971f04cbaedbb89e313e0b86b531640db2d3f6016nicolasroard return bitmap; 5071f04cbaedbb89e313e0b86b531640db2d3f6016nicolasroard } 510d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard int w = bitmap.getWidth(); 520d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard int h = bitmap.getHeight(); 5371f04cbaedbb89e313e0b86b531640db2d3f6016nicolasroard int p = getParameters().getValue(); 54d42f6c69c5980110c16cd679f914c4e4e7caa29dJohn Hoford float value = 1 + p / 100.0f; 550d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard nativeApplyFilter(bitmap, w, h, value); 5681eb9976f967d9b3faa1749a8ab29d1743cf347dnicolasroard return bitmap; 570d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard } 580d7cdf8e763fb65c32bfad65245b3753deb75737nicolasroard} 59