1/*
2 * Copyright (C) 2007 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 android.graphics;
18
19public class ColorMatrixColorFilter extends ColorFilter {
20    /**
21     * Create a colorfilter that transforms colors through a 4x5 color matrix.
22     *
23     * @param matrix 4x5 matrix used to transform colors. It is copied into
24     *               the filter, so changes made to the matrix after the filter
25     *               is constructed will not be reflected in the filter.
26     */
27    public ColorMatrixColorFilter(ColorMatrix matrix) {
28        final float[] colorMatrix = matrix.getArray();
29        native_instance = nativeColorMatrixFilter(colorMatrix);
30        nativeColorFilter = nColorMatrixFilter(native_instance, colorMatrix);
31    }
32
33    /**
34    * Create a colorfilter that transforms colors through a 4x5 color matrix.
35     *
36     * @param array array of floats used to transform colors, treated as a 4x5
37     *              matrix. The first 20 entries of the array are copied into
38     *              the filter. See ColorMatrix.
39     */
40    public ColorMatrixColorFilter(float[] array) {
41        if (array.length < 20) {
42            throw new ArrayIndexOutOfBoundsException();
43        }
44        native_instance = nativeColorMatrixFilter(array);
45        nativeColorFilter = nColorMatrixFilter(native_instance, array);
46    }
47
48    private static native int nativeColorMatrixFilter(float[] array);
49    private static native int nColorMatrixFilter(int nativeFilter, float[] array);
50}
51