1 /* 2 * Copyright 2021 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 package org.skia.androidkit; 9 10 public class SamplingOptions { 11 private FilterMode mFilter; 12 private MipmapMode mMipmap; 13 private float mCubicCoeffB, 14 mCubicCoeffC; 15 private boolean mUseCubic; 16 17 public enum FilterMode { 18 NEAREST, 19 LINEAR, 20 }; 21 22 public enum MipmapMode { 23 NONE, 24 NEAREST, 25 LINEAR, 26 } 27 SamplingOptions()28 public SamplingOptions() { 29 this(FilterMode.NEAREST); 30 } 31 SamplingOptions(FilterMode f)32 public SamplingOptions(FilterMode f) { 33 this(f, MipmapMode.NONE); 34 } 35 SamplingOptions(FilterMode f, MipmapMode m)36 public SamplingOptions(FilterMode f, MipmapMode m) { 37 mFilter = f; 38 mMipmap = m; 39 mUseCubic = false; 40 } 41 SamplingOptions(float cubicCoeffB, float cubicCoeffC)42 public SamplingOptions(float cubicCoeffB, float cubicCoeffC) { 43 mFilter = FilterMode.NEAREST; 44 mMipmap = MipmapMode.NONE; 45 mCubicCoeffB = cubicCoeffB; 46 mCubicCoeffC = cubicCoeffC; 47 mUseCubic = true; 48 } 49 MITCHELL()50 public static SamplingOptions MITCHELL() { 51 return new SamplingOptions(1/3.0f, 1/3.0f); 52 } 53 CATMULLROM()54 public static SamplingOptions CATMULLROM() { 55 return new SamplingOptions(0.0f, 1/2.0f); 56 } 57 58 // package private getNativeDesc()59 int getNativeDesc() { 60 // Encode all options except coefficients in a bit field: 61 // 62 // b0 -> useCubic 63 // b1 -> filter 64 // b2,3 -> mipmap 65 66 int desc = mUseCubic ? 0x01 : 0x00; 67 68 switch (mFilter) { 69 case NEAREST: 70 break; 71 case LINEAR: 72 desc |= 0x02; 73 break; 74 } 75 76 switch (mMipmap) { 77 case NONE: 78 break; 79 case NEAREST: 80 desc |= 0x04; 81 break; 82 case LINEAR: 83 desc |= 0x08; 84 break; 85 } 86 87 return desc; 88 } 89 getCubicCoeffB()90 float getCubicCoeffB() { 91 return mCubicCoeffB; 92 } 93 getCubicCoeffC()94 float getCubicCoeffC() { 95 return mCubicCoeffC; 96 } 97 }