1 /* 2 * Copyright 2018 Google LLC All Rights Reserved. 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 17 package com.google.skar; 18 19 import android.graphics.ColorFilter; 20 import android.graphics.ColorMatrix; 21 import android.graphics.ColorMatrixColorFilter; 22 23 import java.util.Arrays; 24 25 public class PaintUtil { 26 27 private static final float MIDDLE_GRAY_GAMMA = 0.466f; 28 29 /** 30 * Returns a ColorFilter that can be used on a Paint to apply color correction effects 31 * as documented by ARCore. 32 * 33 * @param colorCorr output array of getColorCorrection() from ARCore 34 * @return ColorFilter with effects applied 35 */ createLightCorrectionColorFilter(float[] colorCorr)36 public static ColorFilter createLightCorrectionColorFilter(float[] colorCorr) { 37 float[] colorCorrCopy = Arrays.copyOf(colorCorr, 4); 38 39 for (int i = 0; i < 3; i++) { 40 colorCorrCopy[i] *= colorCorrCopy[3] / MIDDLE_GRAY_GAMMA; 41 } 42 43 ColorMatrix m = new ColorMatrix(); 44 m.setScale(colorCorrCopy[0], colorCorrCopy[1], colorCorrCopy[2], 1); 45 return new ColorMatrixColorFilter(m); 46 } 47 } 48