1 module skia.SKMaskFilter; 2 3 import skia.Definitions; 4 import skia.Exceptions; 5 import skia.MathTypes; 6 import skia.SKObject; 7 import skia.SkiaApi; 8 9 enum SKBlurMaskFilterFlags { 10 None = 0x00, 11 IgnoreTransform = 0x01, 12 HighQuality = 0x02, 13 All = IgnoreTransform | HighQuality, 14 } 15 16 // TODO: `getFormat` 17 // TODO: `computeFastBounds` 18 19 class SKMaskFilter : SKObject { 20 private enum float BlurSigmaScale = 0.57735f; 21 enum int TableMaxLength = 256; 22 23 this(void* handle, bool owns) { 24 super(handle, owns); 25 } 26 27 protected override void Dispose(bool disposing) { 28 return super.Dispose(disposing); 29 } 30 31 static float ConvertRadiusToSigma(float radius) { 32 return radius > 0 ? BlurSigmaScale * radius + 0.5f : 0.0f; 33 } 34 35 static float ConvertSigmaToRadius(float sigma) { 36 return sigma > 0.5f ? (sigma - 0.5f) / BlurSigmaScale : 0.0f; 37 } 38 39 static SKMaskFilter CreateBlur(SKBlurStyle blurStyle, float sigma) { 40 return GetObject(SkiaApi.sk_maskfilter_new_blur(blurStyle, sigma)); 41 } 42 43 static SKMaskFilter CreateBlur(SKBlurStyle blurStyle, float sigma, bool respectCTM) { 44 return GetObject(SkiaApi.sk_maskfilter_new_blur_with_flags(blurStyle, sigma, respectCTM)); 45 } 46 47 static SKMaskFilter CreateBlur(SKBlurStyle blurStyle, float sigma, SKBlurMaskFilterFlags flags) { 48 return CreateBlur(blurStyle, sigma, true); 49 } 50 51 static SKMaskFilter CreateBlur(SKBlurStyle blurStyle, float sigma, SKRect occluder) { 52 return CreateBlur(blurStyle, sigma, true); 53 } 54 55 static SKMaskFilter CreateBlur(SKBlurStyle blurStyle, float sigma, 56 SKRect occluder, SKBlurMaskFilterFlags flags) { 57 return CreateBlur(blurStyle, sigma, true); 58 } 59 60 static SKMaskFilter CreateBlur(SKBlurStyle blurStyle, float sigma, 61 SKRect occluder, bool respectCTM) { 62 return CreateBlur(blurStyle, sigma, respectCTM); 63 } 64 65 static SKMaskFilter CreateTable(ubyte[] table) { 66 if (table is null) 67 throw new ArgumentNullException(table.stringof); 68 if (table.length != TableMaxLength) 69 throw new ArgumentException("Table must have a length of {SKColorTable.MaxLength}.", 70 table.stringof); 71 ubyte* t = table.ptr; 72 return GetObject(SkiaApi.sk_maskfilter_new_table(t)); 73 } 74 75 static SKMaskFilter CreateGamma(float gamma) { 76 return GetObject(SkiaApi.sk_maskfilter_new_gamma(gamma)); 77 } 78 79 static SKMaskFilter CreateClip(ubyte min, ubyte max) { 80 return GetObject(SkiaApi.sk_maskfilter_new_clip(min, max)); 81 } 82 83 static SKMaskFilter GetObject(void* handle) { 84 return GetOrAddObject!(SKMaskFilter)(handle, (h, o) { return new SKMaskFilter(h, o); }); 85 } 86 87 }