1 /* 2 * Copyright (C) 2015 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 17 package android.renderscript.cts.refocus; 18 19 /** 20 * A struct containing all the data needed to apply a depth-of-field effect. 21 */ 22 public class DepthOfFieldOptions { 23 public final RGBZ rgbz; 24 public float focalDepth; 25 public float blurInfinity; 26 // The depth of field specifies the depth range in focus (i.e., zero blur) as 27 // a ratio of the focal depth. Its range is [0, 1). The depth of field range 28 // in depth units is computed as 29 // [(1 - depthOfField) * focalDepth,(1 + depthOfField) * focalDepth]. 30 public float depthOfField; 31 32 /** 33 * Creates a {@code DepthOfFieldOptions} from an {@code RGBZ}. 34 * 35 * @param rgbz the {@code RGBZ} to render 36 */ DepthOfFieldOptions(RGBZ rgbz)37 public DepthOfFieldOptions(RGBZ rgbz) { 38 this.focalDepth = (float)rgbz.getFocusDepth(); 39 this.depthOfField = (float)rgbz.getDepthOfField(); 40 this.blurInfinity = (float)rgbz.getBlurInfinity(); 41 this.rgbz = rgbz; 42 } 43 setFocusPoint(float x, float y)44 public void setFocusPoint(float x, float y) { 45 this.focalDepth = rgbz.getDepth((int)(x * rgbz.getWidth()), (int)(y * rgbz.getHeight())); 46 } 47 setBokeh(float bokeh)48 public void setBokeh(float bokeh) { 49 this.blurInfinity = bokeh * 200; 50 } 51 } 52