1 module skia.SKColorFilter; 2 3 import skia.Definitions; 4 import skia.Exceptions; 5 import skia.SKObject; 6 import skia.SKColor; 7 import skia.SkiaApi; 8 import skia.SKColorSpace; 9 10 // TODO: `FilterColor` may be useful 11 12 /** 13 * 14 */ 15 class SKColorFilter : SKObject 16 { 17 enum ColorMatrixSize = 20; 18 enum TableMaxLength = 256; 19 20 this(void* handle, bool owns) 21 { 22 super(handle, owns); 23 } 24 25 override void* Handle() 26 { 27 return null; 28 } 29 30 protected override void Dispose (bool disposing) 31 { 32 return super.Dispose (disposing); 33 } 34 35 36 static SKColorFilter CreateBlendMode(SKColor c, SKBlendMode mode) 37 { 38 return GetObject (SkiaApi.sk_colorfilter_new_mode(cast(uint)c, mode)); 39 } 40 41 static SKColorFilter CreateLighting(SKColor mul, SKColor add) 42 { 43 return GetObject (SkiaApi.sk_colorfilter_new_lighting(cast(uint)mul, cast(uint)add)); 44 } 45 46 static SKColorFilter CreateCompose(SKColorFilter outer, SKColorFilter inner) 47 { 48 if (outer is null) 49 throw new ArgumentNullException("outer"); 50 if (inner is null) 51 throw new ArgumentNullException("inner"); 52 return GetObject (SkiaApi.sk_colorfilter_new_compose(cast(sk_colorfilter_t*)outer.Handle, cast(sk_colorfilter_t*)inner.Handle)); 53 } 54 55 static SKColorFilter CreateColorMatrix(float[] matrix) 56 { 57 if (matrix is null) 58 throw new ArgumentNullException("matrix"); 59 if (matrix.length != 20) 60 throw new ArgumentException("Matrix must have a length of 20.", "matrix"); 61 float* m = matrix.ptr; 62 return GetObject (SkiaApi.sk_colorfilter_new_color_matrix (m)); 63 } 64 65 static SKColorFilter CreateLumaColor() 66 { 67 return GetObject (SkiaApi.sk_colorfilter_new_luma_color()); 68 } 69 70 static SKColorFilter CreateTable(ubyte[] table) 71 { 72 if (table is null) 73 throw new ArgumentNullException("table"); 74 if (table.length != TableMaxLength) 75 throw new ArgumentException("Table must have a length of {TableMaxLength}.", "table"); 76 ubyte* t = cast(ubyte*)table.ptr; 77 return GetObject (SkiaApi.sk_colorfilter_new_table (t)); 78 } 79 80 static SKColorFilter CreateTable(ubyte[] tableA, ubyte[] tableR, ubyte[] tableG, ubyte[] tableB) 81 { 82 if (tableA !is null && tableA.length != TableMaxLength) 83 throw new ArgumentException("Table A must have a length of {TableMaxLength}.", "tableA"); 84 if (tableR !is null && tableR.length != TableMaxLength) 85 throw new ArgumentException("Table R must have a length of {TableMaxLength}.", "tableR"); 86 if (tableG !is null && tableG.length != TableMaxLength) 87 throw new ArgumentException("Table G must have a length of {TableMaxLength}.", "tableG"); 88 if (tableB !is null && tableB.length != TableMaxLength) 89 throw new ArgumentException("Table B must have a length of {TableMaxLength}.", "tableB"); 90 91 ubyte* a = tableA.ptr; 92 ubyte* r = tableR.ptr; 93 ubyte* g = tableG.ptr; 94 ubyte* b = tableB.ptr; 95 return GetObject (SkiaApi.sk_colorfilter_new_table_argb (a, r, g, b)); 96 } 97 98 static SKColorFilter CreateHighContrast(SKHighContrastConfig config) 99 { 100 return GetObject (SkiaApi.sk_colorfilter_new_high_contrast(&config)); 101 } 102 103 static SKColorFilter CreateHighContrast(bool grayscale, SKHighContrastConfigInvertStyle invertStyle, float contrast) 104 { 105 return CreateHighContrast(SKHighContrastConfig(grayscale, invertStyle, contrast)); 106 } 107 108 static SKColorFilter GetObject (void* handle) 109 { 110 return GetOrAddObject!(SKColorFilter)(handle, delegate SKColorFilter (h, o) { return new SKColorFilter (h, o);}); 111 } 112 113 }