1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
use crate::prelude::*; use skia_bindings as sb; use skia_bindings::{SkColorMatrix, SkColorMatrix_Axis}; pub type ColorMatrix = Handle<SkColorMatrix>; impl NativeDrop for SkColorMatrix { fn drop(&mut self) {} } impl NativePartialEq for SkColorMatrix { fn eq(&self, rhs: &Self) -> bool { unsafe { sb::C_SkColorMatrix_equals(self, rhs) } } } impl Default for Handle<SkColorMatrix> { fn default() -> Self { ColorMatrix::construct(|cm| unsafe { (*cm).setIdentity() }) } } impl Handle<SkColorMatrix> { pub fn set_identity(&mut self) { unsafe { self.native_mut().setIdentity() } } pub fn set_scale( &mut self, r_scale: f32, g_scale: f32, b_scale: f32, a_scale: impl Into<Option<f32>>, ) { unsafe { self.native_mut() .setScale(r_scale, g_scale, b_scale, a_scale.into().unwrap_or(1.0)) } } pub fn set_row_major(&mut self, src: &[f32; 20]) { self.set_20(src) } pub fn get_row_major(&mut self, dst: &mut [f32; 20]) { self.get_20(dst); } pub fn set_rotate(&mut self, axis: Axis, degrees: f32) { unsafe { self.native_mut().setRotate(axis.into_native(), degrees) } } pub fn set_sin_cos(&mut self, axis: Axis, sine: f32, cosine: f32) { unsafe { self.native_mut() .setSinCos(axis.into_native(), sine, cosine) } } pub fn pre_rotate(&mut self, axis: Axis, degrees: f32) { unsafe { self.native_mut().preRotate(axis.into_native(), degrees) } } pub fn post_rotate(&mut self, axis: Axis, degrees: f32) { unsafe { self.native_mut().postRotate(axis.into_native(), degrees) } } pub fn post_translate(&mut self, dr: f32, dg: f32, db: f32, da: f32) { unsafe { self.native_mut().postTranslate(dr, dg, db, da) } } pub fn set_concat(&mut self, a: &ColorMatrix, b: &ColorMatrix) { unsafe { self.native_mut().setConcat(a.native(), b.native()) } } pub fn pre_concat(&mut self, mat: &ColorMatrix) { let self_ptr = self.native() as *const _; unsafe { self.native_mut().setConcat(self_ptr, mat.native()) } } pub fn post_concat(&mut self, mat: &ColorMatrix) { let self_ptr = self.native() as *const _; unsafe { self.native_mut().setConcat(mat.native(), self_ptr) } } pub fn set_saturation(&mut self, sat: f32) { unsafe { self.native_mut().setSaturation(sat) } } pub fn set_rgb_2_yuv(&mut self) { unsafe { self.native_mut().setRGB2YUV() } } pub fn set_yuv_2_rgb(&mut self) { unsafe { self.native_mut().setYUV2RGB() } } pub fn get_20<'a>(&self, m: &'a mut [f32; 20]) -> &'a mut [f32; 20] { unsafe { sb::C_SkColorMatrix_get20(self.native(), m.as_mut_ptr()) }; m } pub fn set_20(&mut self, m: &[f32; 20]) { unsafe { sb::C_SkColorMatrix_set20(self.native_mut(), m.as_ptr()) }; } } #[derive(Copy, Clone, PartialEq, Eq, Debug)] #[repr(i32)] pub enum Axis { R = SkColorMatrix_Axis::kR_Axis as _, G = SkColorMatrix_Axis::kG_Axis as _, B = SkColorMatrix_Axis::kB_Axis as _, } impl NativeTransmutable<SkColorMatrix_Axis> for Axis {} #[test] fn test_axis_layout() { Axis::test_layout(); }