diff --git a/core/jni/android/graphics/MaskFilter.cpp b/core/jni/android/graphics/MaskFilter.cpp index 0f8dff1210551..455449e5349d1 100644 --- a/core/jni/android/graphics/MaskFilter.cpp +++ b/core/jni/android/graphics/MaskFilter.cpp @@ -1,6 +1,7 @@ #include "GraphicsJNI.h" #include "SkMaskFilter.h" #include "SkBlurMaskFilter.h" +#include "SkTableMaskFilter.h" #include @@ -39,6 +40,19 @@ public: ThrowIAE_IfNull(env, filter); return filter; } + + static SkMaskFilter* createTable(JNIEnv* env, jobject, jbyteArray jtable) { + AutoJavaByteArray autoTable(env, jtable, 256); + return new SkTableMaskFilter((const uint8_t*)autoTable.ptr()); + } + + static SkMaskFilter* createClipTable(JNIEnv* env, jobject, int min, int max) { + return SkTableMaskFilter::CreateClip(min, max); + } + + static SkMaskFilter* createGammaTable(JNIEnv* env, jobject, float gamma) { + return SkTableMaskFilter::CreateGamma(gamma); + } }; static JNINativeMethod gMaskFilterMethods[] = { @@ -53,6 +67,12 @@ static JNINativeMethod gEmbossMaskFilterMethods[] = { { "nativeConstructor", "([FFFF)I", (void*)SkMaskFilterGlue::createEmboss } }; +static JNINativeMethod gTableMaskFilterMethods[] = { + { "nativeNewTable", "([B)I", (void*)SkMaskFilterGlue::createTable }, + { "nativeNewClip", "(II)I", (void*)SkMaskFilterGlue::createClipTable }, + { "nativeNewGamma", "(F)I", (void*)SkMaskFilterGlue::createGammaTable } +}; + #include #define REG(env, name, array) \ @@ -67,6 +87,7 @@ int register_android_graphics_MaskFilter(JNIEnv* env) REG(env, "android/graphics/MaskFilter", gMaskFilterMethods); REG(env, "android/graphics/BlurMaskFilter", gBlurMaskFilterMethods); REG(env, "android/graphics/EmbossMaskFilter", gEmbossMaskFilterMethods); + REG(env, "android/graphics/TableMaskFilter", gTableMaskFilterMethods); return 0; } diff --git a/graphics/java/android/graphics/TableMaskFilter.java b/graphics/java/android/graphics/TableMaskFilter.java new file mode 100644 index 0000000000000..a8a7ff0528e13 --- /dev/null +++ b/graphics/java/android/graphics/TableMaskFilter.java @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2006 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.graphics; + +/** + * @hide + */ +public class TableMaskFilter extends MaskFilter { + + public TableMaskFilter(byte[] table) { + if (table.length < 256) { + throw new RuntimeException("table.length must be >= 256"); + } + native_instance = nativeNewTable(table); + } + + private TableMaskFilter(int ni) { + native_instance = ni; + } + + public static TableMaskFilter CreateClipTable(int min, int max) { + return new TableMaskFilter(nativeNewClip(min, max)); + } + + public static TableMaskFilter CreateGammaTable(float gamma) { + return new TableMaskFilter(nativeNewGamma(gamma)); + } + + private static native int nativeNewTable(byte[] table); + private static native int nativeNewClip(int min, int max); + private static native int nativeNewGamma(float gamma); +}