diff --git a/src/azure-c.cpp b/src/azure-c.cpp index f69e062..c68827f 100644 --- a/src/azure-c.cpp +++ b/src/azure-c.cpp @@ -745,6 +745,15 @@ AzFilterNodeSetFloatAttribute(AzFilterNodeRef aFilter, uint32_t aIndex, AzFloat gfxFilterNode->SetAttribute(aIndex, aValue); } +extern "C" void +AzFilterNodeSetFloatArrayAttribute(AzFilterNodeRef aFilter, + uint32_t aIndex, + const AzFloat *aFloats, + uint32_t aSize) { + gfx::FilterNode *gfxFilterNode = reinterpret_cast(aFilter); + gfxFilterNode->SetAttribute(aIndex, aFloats, aSize); +} + extern "C" void AzFilterNodeSetColorAttribute(AzFilterNodeRef aFilter, uint32_t aIndex, const AzColor *aValue) { gfx::FilterNode *gfxFilterNode = reinterpret_cast(aFilter); @@ -752,3 +761,19 @@ AzFilterNodeSetColorAttribute(AzFilterNodeRef aFilter, uint32_t aIndex, const Az gfxFilterNode->SetAttribute(aIndex, aValue); } +extern "C" void +AzFilterNodeSetMatrix5x4Attribute(AzFilterNodeRef aFilter, + uint32_t aIndex, + const AzMatrix5x4 *aValue) { + gfx::FilterNode *gfxFilterNode = reinterpret_cast(aFilter); + const gfx::Matrix5x4 *gfxMatrix5x4 = reinterpret_cast(aValue); + gfxFilterNode->SetAttribute(aIndex, *gfxMatrix5x4); +} + +extern "C" void +AzFilterNodeSetBoolAttribute(AzFilterNodeRef aFilter, uint32_t aIndex, bool aValue) { + gfx::FilterNode *gfxFilterNode = reinterpret_cast(aFilter); + gfxFilterNode->SetAttribute(aIndex, aValue); +} + + diff --git a/src/azure-c.h b/src/azure-c.h index 38207d9..36e9661 100644 --- a/src/azure-c.h +++ b/src/azure-c.h @@ -289,6 +289,13 @@ typedef struct _AzMatrix { AzFloat _31, _32; } AzMatrix; +typedef struct _AzMatrix5x4 { + AzFloat _11, _12, _13, _14; + AzFloat _21, _22, _23, _24; + AzFloat _31, _32, _33, _34; + AzFloat _41, _42, _43, _44; + AzFloat _51, _52, _53, _54; +} AzMatrix5x4; /* 2D.h */ @@ -469,6 +476,10 @@ void AzFilterNodeSetFloatAttribute(AzFilterNodeRef aFilter, uint32_t aIndex, AzF void AzFilterNodeSetColorAttribute(AzFilterNodeRef aFilter, uint32_t aIndex, const AzColor *aValue); +void AzFilterNodeSetMatrix5x4Attribute(AzFilterNodeRef aFilter, + uint32_t aIndex, + const AzMatrix5x4 *aValue); +void AzFilterNodeSetBoolAttribute(AzFilterNodeRef aFilter, uint32_t aIndex, bool aValue); /* Factory.h */ diff --git a/src/azure.rs b/src/azure.rs index 7a979bc..838663a 100644 --- a/src/azure.rs +++ b/src/azure.rs @@ -79,7 +79,7 @@ pub static AZ_FILTER_TYPE_DISTANT_DIFFUSE: u32 = 21_u32; pub static AZ_FILTER_TYPE_DISTANT_SPECULAR: u32 = 22_u32; pub static AZ_FILTER_TYPE_CROP: u32 = 23_u32; pub static AZ_FILTER_TYPE_PREMULTIPLY: u32 = 24_u32; -pub static AZ_FILTER_TYPE_UNPREMULTIPL: u32 = 25_u32; +pub static AZ_FILTER_TYPE_UNPREMULTIPLY: u32 = 25_u32; pub type AzFilterType = enum_AzFilterType; @@ -193,6 +193,15 @@ pub static AZ_eSideRight: u32 = 1_u32; pub static AZ_eSideBottom: u32 = 2_u32; pub static AZ_eSideLeft: u32 = 3_u32; +pub type enum_AzColorMatrixFilterAtts = u32; +pub static AZ_ATT_COLOR_MATRIX_MATRIX: u32 = 0; + +pub type enum_AzColorMatrixFilterInputs = u32; +pub static AZ_IN_COLOR_MATRIX_IN: u32 = 0; + +pub type enum_AzCompositeFilterInputs = u32; +pub static AZ_IN_COMPOSITE_IN: u32 = 0; + pub type enum_AzFloodFilterAtts = u32; pub static AZ_ATT_FLOOD_COLOR: u32 = 0; @@ -205,6 +214,34 @@ pub static AZ_ATT_GAUSSIAN_BLUR_STD_DEVIATION: u32 = 0; pub type enum_AzGaussianBlurInputs = u32; pub static AZ_IN_GAUSSIAN_BLUR_IN: u32 = 0; +pub type enum_LinearTransferAtts = u32; +pub static AZ_ATT_LINEAR_TRANSFER_SLOPE_R: u32 = 4; +pub static AZ_ATT_LINEAR_TRANSFER_SLOPE_G: u32 = 5; +pub static AZ_ATT_LINEAR_TRANSFER_SLOPE_B: u32 = 6; +pub static AZ_ATT_LINEAR_TRANSFER_SLOPE_A: u32 = 7; +pub static AZ_ATT_LINEAR_TRANSFER_INTERCEPT_R: u32 = 8; +pub static AZ_ATT_LINEAR_TRANSFER_INTERCEPT_G: u32 = 9; +pub static AZ_ATT_LINEAR_TRANSFER_INTERCEPT_B: u32 = 10; +pub static AZ_ATT_LINEAR_TRANSFER_INTERCEPT_A: u32 = 11; + +pub type enum_AzLinearTransferInputs = u32; +pub static AZ_IN_LINEAR_TRANSFER_IN: u32 = 0; + +pub type enum_AzTableTransferAtts = u32; +pub static AZ_ATT_TABLE_TRANSFER_TABLE_R: u32 = 4; +pub static AZ_ATT_TABLE_TRANSFER_TABLE_G: u32 = 5; +pub static AZ_ATT_TABLE_TRANSFER_TABLE_B: u32 = 6; +pub static AZ_ATT_TABLE_TRANSFER_TABLE_A: u32 = 7; + +pub type enum_AzTableTransferInputs = u32; +pub static AZ_IN_TABLE_TRANSFER_IN: u32 = 0; + +pub type enum_TransferAtts = u32; +pub static AZ_ATT_TRANSFER_DISABLE_R: u32 = 0; +pub static AZ_ATT_TRANSFER_DISABLE_G: u32 = 1; +pub static AZ_ATT_TRANSFER_DISABLE_B: u32 = 2; +pub static AZ_ATT_TRANSFER_DISABLE_A: u32 = 3; + #[repr(C)] #[deriving(Clone)] pub struct struct__AzColor { @@ -287,6 +324,18 @@ pub struct struct__AzMatrix { pub type AzMatrix = struct__AzMatrix; +#[repr(C)] +#[deriving(PartialEq, Clone)] +pub struct struct__AzMatrix5x4 { + pub _11: AzFloat, pub _12: AzFloat, pub _13: AzFloat, pub _14: AzFloat, + pub _21: AzFloat, pub _22: AzFloat, pub _23: AzFloat, pub _24: AzFloat, + pub _31: AzFloat, pub _32: AzFloat, pub _33: AzFloat, pub _34: AzFloat, + pub _41: AzFloat, pub _42: AzFloat, pub _43: AzFloat, pub _44: AzFloat, + pub _51: AzFloat, pub _52: AzFloat, pub _53: AzFloat, pub _54: AzFloat, +} + +pub type AzMatrix5x4 = struct__AzMatrix5x4; + #[repr(C)] pub struct struct__AzDrawOptions { pub mAlpha: AzFloat, @@ -553,8 +602,17 @@ pub fn AzFilterNodeSetFilterNodeInput(aFilter: AzFilterNodeRef, aIndex: u32, aInputFilter: AzFilterNodeRef); pub fn AzFilterNodeSetFloatAttribute(aFilter: AzFilterNodeRef, aIndex: u32, aValue: AzFloat); +pub fn AzFilterNodeSetFloatArrayAttribute(aFilter: AzFilterNodeRef, + aIndex: u32, + aFloats: *const AzFloat, + aSize: u32); pub fn AzFilterNodeSetColorAttribute(aFilter: AzFilterNodeRef, aIndex: u32, aValue: *const AzColor); +pub fn AzFilterNodeSetMatrix5x4Attribute(aFilter: AzFilterNodeRef, + aIndex: u32, + aValue: *const AzMatrix5x4); + +pub fn AzFilterNodeSetBoolAttribute(aFilter: AzFilterNodeRef, aIndex: u32, aValue: bool); } diff --git a/src/azure_hl.rs b/src/azure_hl.rs index d343991..29816ab 100644 --- a/src/azure_hl.rs +++ b/src/azure_hl.rs @@ -4,9 +4,20 @@ //! High-level bindings to Azure. -use azure::{AZ_CAP_BUTT, AZ_JOIN_MITER_OR_BEVEL, AZ_FILTER_TYPE_FLOOD}; -use azure::{AZ_FILTER_TYPE_GAUSSIAN_BLUR, AZ_IN_FLOOD_IN, AZ_IN_GAUSSIAN_BLUR_IN}; -use azure::{AZ_ATT_FLOOD_COLOR, AZ_ATT_GAUSSIAN_BLUR_STD_DEVIATION}; +use azure::{AZ_CAP_BUTT, AZ_JOIN_MITER_OR_BEVEL, AZ_FILTER_TYPE_COLOR_MATRIX}; +use azure::{AZ_FILTER_TYPE_FLOOD, AZ_FILTER_TYPE_GAUSSIAN_BLUR, AZ_FILTER_TYPE_LINEAR_TRANSFER}; +use azure::{AZ_FILTER_TYPE_TABLE_TRANSFER, AZ_IN_COLOR_MATRIX_IN, AZ_IN_COMPOSITE_IN}; +use azure::{AZ_IN_FLOOD_IN, AZ_IN_GAUSSIAN_BLUR_IN, AZ_IN_LINEAR_TRANSFER_IN}; +use azure::{AZ_ATT_COLOR_MATRIX_MATRIX, AZ_ATT_FLOOD_COLOR, AZ_ATT_GAUSSIAN_BLUR_STD_DEVIATION}; +use azure::{AZ_FILTER_TYPE_COMPOSITE, AZ_IN_TABLE_TRANSFER_IN, AZ_ATT_LINEAR_TRANSFER_SLOPE_R}; +use azure::{AZ_ATT_LINEAR_TRANSFER_SLOPE_G, AZ_ATT_LINEAR_TRANSFER_SLOPE_B}; +use azure::{AZ_ATT_LINEAR_TRANSFER_SLOPE_A, AZ_ATT_LINEAR_TRANSFER_INTERCEPT_R}; +use azure::{AZ_ATT_LINEAR_TRANSFER_INTERCEPT_G, AZ_ATT_LINEAR_TRANSFER_INTERCEPT_B}; +use azure::{AZ_ATT_LINEAR_TRANSFER_INTERCEPT_A, AZ_ATT_TABLE_TRANSFER_TABLE_R}; +use azure::{AZ_ATT_TABLE_TRANSFER_TABLE_G, AZ_ATT_TABLE_TRANSFER_TABLE_B}; +use azure::{AZ_ATT_TABLE_TRANSFER_TABLE_A, AZ_ATT_TRANSFER_DISABLE_R}; +use azure::{AZ_ATT_TRANSFER_DISABLE_G, AZ_ATT_TRANSFER_DISABLE_B}; +use azure::{AZ_ATT_TRANSFER_DISABLE_A}; use azure::{AzPoint, AzRect, AzFloat, AzIntSize, AzColor, AzColorPatternRef, AzGradientStopsRef}; use azure::{AzStrokeOptions, AzDrawOptions, AzSurfaceFormat, AzFilter, AzDrawSurfaceOptions}; use azure::{AzBackendType, AzDrawTargetRef, AzSourceSurfaceRef, AzDataSourceSurfaceRef}; @@ -14,7 +25,7 @@ use azure::{AzScaledFontRef, AzGlyphRenderingOptionsRef, AzExtendMode, AzGradien use azure::{AzCompositionOp}; use azure::{struct__AzColor, struct__AzGlyphBuffer}; use azure::{struct__AzDrawOptions, struct__AzDrawSurfaceOptions, struct__AzIntSize}; -use azure::{struct__AzPoint, struct__AzRect, struct__AzStrokeOptions}; +use azure::{struct__AzPoint, struct__AzRect, struct__AzStrokeOptions, struct__AzMatrix5x4}; use azure::{AzGLContext, AzSkiaSharedGLContextRef}; use azure::{AzCreateColorPattern, AzCreateDrawTarget, AzCreateDrawTargetForData}; use azure::{AzDataSourceSurfaceGetData, AzDataSourceSurfaceGetStride}; @@ -40,7 +51,9 @@ use azure::{AzDrawTargetDrawSurfaceWithShadow, AzDrawTargetCreateShadowDrawTarge use azure::{AzDrawTargetCreateSimilarDrawTarget, AzDrawTargetGetTransform}; use azure::{AzFilterNodeSetSourceSurfaceInput, AzReleaseFilterNode, AzDrawTargetCreateFilter}; use azure::{AzFilterNodeSetColorAttribute, AzFilterNodeSetFloatAttribute}; -use azure::{AzFilterNodeSetFilterNodeInput, AzDrawTargetDrawFilter, AzFilterNodeRef, AzFilterType}; +use azure::{AzFilterNodeSetMatrix5x4Attribute, AzFilterNodeSetFilterNodeInput}; +use azure::{AzFilterNodeSetFloatArrayAttribute, AzFilterNodeSetBoolAttribute}; +use azure::{AzDrawTargetDrawFilter, AzFilterNodeRef, AzFilterType}; use sync::Arc; use geom::matrix2d::Matrix2D; @@ -583,7 +596,7 @@ impl DrawTarget { } pub fn draw_filter(&self, - filter: FilterNode, + filter: &FilterNode, source_rect: &Rect, dest_point: &Point2D, options: DrawOptions) { @@ -1034,14 +1047,34 @@ impl FilterNode { } } +pub struct ColorMatrixInput; + +pub struct CompositeInput; + pub struct FloodFilterInput; pub struct GaussianBlurInput; +pub struct LinearTransferInput; + +pub struct TableTransferInput; + pub trait FilterInputIndex { fn azure_index(&self) -> u32; } +impl FilterInputIndex for ColorMatrixInput { + fn azure_index(&self) -> u32 { + AZ_IN_COLOR_MATRIX_IN + } +} + +impl FilterInputIndex for CompositeInput { + fn azure_index(&self) -> u32 { + AZ_IN_COMPOSITE_IN + } +} + impl FilterInputIndex for FloodFilterInput { fn azure_index(&self) -> u32 { AZ_IN_FLOOD_IN @@ -1054,10 +1087,26 @@ impl FilterInputIndex for GaussianBlurInput { } } +impl FilterInputIndex for LinearTransferInput { + fn azure_index(&self) -> u32 { + AZ_IN_LINEAR_TRANSFER_IN + } +} + +impl FilterInputIndex for TableTransferInput { + fn azure_index(&self) -> u32 { + AZ_IN_TABLE_TRANSFER_IN + } +} + pub trait FilterAttribute { fn set(&self, filter_node: &FilterNode); } +pub enum ColorMatrixAttribute { + Matrix(Matrix5x4), +} + pub enum FloodAttribute { Color(Color), } @@ -1066,6 +1115,43 @@ pub enum GaussianBlurAttribute { StdDeviation(AzFloat), } +pub enum LinearTransferAttribute { + DisableR(bool), + DisableG(bool), + DisableB(bool), + DisableA(bool), + SlopeR(AzFloat), + SlopeG(AzFloat), + SlopeB(AzFloat), + SlopeA(AzFloat), + InterceptR(AzFloat), + InterceptG(AzFloat), + InterceptB(AzFloat), + InterceptA(AzFloat), +} + +pub enum TableTransferAttribute<'a> { + DisableR(bool), + DisableG(bool), + DisableB(bool), + DisableA(bool), + TableR(&'a [AzFloat]), + TableG(&'a [AzFloat]), + TableB(&'a [AzFloat]), + TableA(&'a [AzFloat]), +} + +impl FilterAttribute for ColorMatrixAttribute { + fn set(&self, filter_node: &FilterNode) { + let ColorMatrixAttribute::Matrix(value) = *self; + unsafe { + AzFilterNodeSetMatrix5x4Attribute(filter_node.azure_filter_node, + AZ_ATT_COLOR_MATRIX_MATRIX, + &value.as_azure_matrix_5x4()) + } + } +} + impl FilterAttribute for FloodAttribute { fn set(&self, filter_node: &FilterNode) { let FloodAttribute::Color(value) = *self; @@ -1088,16 +1174,146 @@ impl FilterAttribute for GaussianBlurAttribute { } } +impl FilterAttribute for LinearTransferAttribute { + fn set(&self, filter_node: &FilterNode) { + unsafe { + match *self { + LinearTransferAttribute::DisableR(value) => { + AzFilterNodeSetBoolAttribute(filter_node.azure_filter_node, + AZ_ATT_TRANSFER_DISABLE_R, + value) + } + LinearTransferAttribute::DisableG(value) => { + AzFilterNodeSetBoolAttribute(filter_node.azure_filter_node, + AZ_ATT_TRANSFER_DISABLE_G, + value) + } + LinearTransferAttribute::DisableB(value) => { + AzFilterNodeSetBoolAttribute(filter_node.azure_filter_node, + AZ_ATT_TRANSFER_DISABLE_B, + value) + } + LinearTransferAttribute::DisableA(value) => { + AzFilterNodeSetBoolAttribute(filter_node.azure_filter_node, + AZ_ATT_TRANSFER_DISABLE_A, + value) + } + LinearTransferAttribute::SlopeR(value) => { + AzFilterNodeSetFloatAttribute(filter_node.azure_filter_node, + AZ_ATT_LINEAR_TRANSFER_SLOPE_R, + value) + } + LinearTransferAttribute::SlopeG(value) => { + AzFilterNodeSetFloatAttribute(filter_node.azure_filter_node, + AZ_ATT_LINEAR_TRANSFER_SLOPE_G, + value) + } + LinearTransferAttribute::SlopeB(value) => { + AzFilterNodeSetFloatAttribute(filter_node.azure_filter_node, + AZ_ATT_LINEAR_TRANSFER_SLOPE_B, + value) + } + LinearTransferAttribute::SlopeA(value) => { + AzFilterNodeSetFloatAttribute(filter_node.azure_filter_node, + AZ_ATT_LINEAR_TRANSFER_SLOPE_A, + value) + } + LinearTransferAttribute::InterceptR(value) => { + AzFilterNodeSetFloatAttribute(filter_node.azure_filter_node, + AZ_ATT_LINEAR_TRANSFER_INTERCEPT_R, + value) + } + LinearTransferAttribute::InterceptG(value) => { + AzFilterNodeSetFloatAttribute(filter_node.azure_filter_node, + AZ_ATT_LINEAR_TRANSFER_INTERCEPT_G, + value) + } + LinearTransferAttribute::InterceptB(value) => { + AzFilterNodeSetFloatAttribute(filter_node.azure_filter_node, + AZ_ATT_LINEAR_TRANSFER_INTERCEPT_B, + value) + } + LinearTransferAttribute::InterceptA(value) => { + AzFilterNodeSetFloatAttribute(filter_node.azure_filter_node, + AZ_ATT_LINEAR_TRANSFER_INTERCEPT_A, + value) + } + } + } + } +} + +impl<'a> FilterAttribute for TableTransferAttribute<'a> { + fn set(&self, filter_node: &FilterNode) { + unsafe { + match *self { + TableTransferAttribute::DisableR(value) => { + AzFilterNodeSetBoolAttribute(filter_node.azure_filter_node, + AZ_ATT_TRANSFER_DISABLE_R, + value) + } + TableTransferAttribute::DisableG(value) => { + AzFilterNodeSetBoolAttribute(filter_node.azure_filter_node, + AZ_ATT_TRANSFER_DISABLE_G, + value) + } + TableTransferAttribute::DisableB(value) => { + AzFilterNodeSetBoolAttribute(filter_node.azure_filter_node, + AZ_ATT_TRANSFER_DISABLE_B, + value) + } + TableTransferAttribute::DisableA(value) => { + AzFilterNodeSetBoolAttribute(filter_node.azure_filter_node, + AZ_ATT_TRANSFER_DISABLE_A, + value) + } + TableTransferAttribute::TableR(value) => { + AzFilterNodeSetFloatArrayAttribute(filter_node.azure_filter_node, + AZ_ATT_TABLE_TRANSFER_TABLE_R, + value.as_ptr(), + value.len() as u32) + } + TableTransferAttribute::TableG(value) => { + AzFilterNodeSetFloatArrayAttribute(filter_node.azure_filter_node, + AZ_ATT_TABLE_TRANSFER_TABLE_G, + value.as_ptr(), + value.len() as u32) + } + TableTransferAttribute::TableB(value) => { + AzFilterNodeSetFloatArrayAttribute(filter_node.azure_filter_node, + AZ_ATT_TABLE_TRANSFER_TABLE_B, + value.as_ptr(), + value.len() as u32) + } + TableTransferAttribute::TableA(value) => { + AzFilterNodeSetFloatArrayAttribute(filter_node.azure_filter_node, + AZ_ATT_TABLE_TRANSFER_TABLE_A, + value.as_ptr(), + value.len() as u32) + } + } + } + } +} + pub enum FilterType { + ColorMatrix, + Composite, Flood, GaussianBlur, + LinearTransfer, + TableTransfer, } impl FilterType { pub fn as_azure_filter_type(self) -> AzFilterType { match self { + FilterType::ColorMatrix => AZ_FILTER_TYPE_COLOR_MATRIX, + FilterType::Composite => AZ_FILTER_TYPE_COMPOSITE, FilterType::Flood => AZ_FILTER_TYPE_FLOOD, FilterType::GaussianBlur => AZ_FILTER_TYPE_GAUSSIAN_BLUR, + FilterType::LinearTransfer => AZ_FILTER_TYPE_LINEAR_TRANSFER, + FilterType::TableTransfer => AZ_FILTER_TYPE_TABLE_TRANSFER, } } } @@ -1124,3 +1340,25 @@ impl FilterInput for FilterNode { } } +#[deriving(PartialEq, Clone, Show)] +pub struct Matrix5x4 { + pub m11: AzFloat, pub m12: AzFloat, pub m13: AzFloat, pub m14: AzFloat, + pub m21: AzFloat, pub m22: AzFloat, pub m23: AzFloat, pub m24: AzFloat, + pub m31: AzFloat, pub m32: AzFloat, pub m33: AzFloat, pub m34: AzFloat, + pub m41: AzFloat, pub m42: AzFloat, pub m43: AzFloat, pub m44: AzFloat, + pub m51: AzFloat, pub m52: AzFloat, pub m53: AzFloat, pub m54: AzFloat, +} + +impl Matrix5x4 { + #[inline] + pub fn as_azure_matrix_5x4(&self) -> struct__AzMatrix5x4 { + struct__AzMatrix5x4 { + _11: self.m11, _12: self.m12, _13: self.m13, _14: self.m14, + _21: self.m21, _22: self.m22, _23: self.m23, _24: self.m24, + _31: self.m31, _32: self.m32, _33: self.m33, _34: self.m34, + _41: self.m41, _42: self.m42, _43: self.m43, _44: self.m44, + _51: self.m51, _52: self.m52, _53: self.m53, _54: self.m54, + } + } +} +