public void FromValues() { Assert.Throws <ArgumentNullException> (() => CIVector.FromValues(null), "null"); using (var v = CIVector.FromValues(new nfloat [0])) { Assert.That(v.Count, Is.EqualTo(0), "Count/empty"); } }
public CIImage OutputImage() { var inputImage = ValueForKey(new NSString("inputImage")); if (inputImage == null) { return(null); } // Monochrome var monochromeFilter = CIFilter.FromName("CIColorMatrix"); monochromeFilter.SetDefaults(); monochromeFilter.SetValueForKey(CIVector.Create(0, 0, 0), new NSString("inputRVector")); monochromeFilter.SetValueForKey(CIVector.Create(0, 0, 0.4f), new NSString("inputGVector")); monochromeFilter.SetValueForKey(CIVector.Create(0, 0, 1), new NSString("inputBVector")); monochromeFilter.SetValueForKey(CIVector.Create(0, 0, 1), new NSString("inputAVector")); monochromeFilter.SetValueForKey(inputImage, new NSString("inputImage")); var glowImage = (CIImage)monochromeFilter.ValueForKey(new NSString("outputImage")); // Scale var centerX = CenterX; var centerY = CenterY; if (centerX > 0) { var transform = new NSAffineTransform(); transform.Translate(centerX, centerY); transform.Scale(1.2f); transform.Translate(-centerX, -centerY); var affineTransformFilter = CIFilter.FromName("CIAffineTransform"); affineTransformFilter.SetDefaults(); affineTransformFilter.SetValueForKey(transform, new NSString("inputTransform")); affineTransformFilter.SetValueForKey(glowImage, new NSString("inputImage")); glowImage = (CIImage)affineTransformFilter.ValueForKey(new NSString("outputImage")); } // Blur var gaussianBlurFilter = CIFilter.FromName("CIGaussianBlur"); gaussianBlurFilter.SetDefaults(); gaussianBlurFilter.SetValueForKey(glowImage, new NSString("inputImage")); gaussianBlurFilter.SetValueForKey(InputRadius != null ? InputRadius : new NSNumber(10.0f), new NSString("inputRadius")); glowImage = (CIImage)gaussianBlurFilter.ValueForKey(new NSString("outputImage")); // Blend var blendFilter = CIFilter.FromName("CISourceOverCompositing"); blendFilter.SetDefaults(); blendFilter.SetValueForKey(glowImage, new NSString("inputBackgroundImage")); blendFilter.SetValueForKey(blendFilter, new NSString("inputImage")); glowImage = (CIImage)blendFilter.ValueForKey(new NSString("outputImage")); return(glowImage); }
private void Pointalize() { CIVector center = CIVector.Create(Bounds.GetMidX(), Bounds.GetMidY()); CIFilter pointalize = CIFilter.FromName("CIPointillize"); pointalize.SetValueForKey(NSNumber.FromFloat(1), CIFilterInputKey.Radius); pointalize.SetValueForKey(center, CIFilterInputKey.Center); controls.ContentFilters = new CIFilter[] { pointalize }; }
public CIImage RadialGradient() { var center = new CIVector(100, 100); // Default [150 150] var radGradient = new CIRadialGradient() { Center = center, Radius0 = 10F, // Default 5 Radius1 = 150F, // Default 100 Color0 = new CIColor(new CGColor(0, 255F, 0)), // Green Color1 = new CIColor(new CGColor(0, 0, 0)) // Black }; return(Crop(radGradient)); }
public CIImage LinearGradient() { var point0 = new CIVector(0, 0); // Default [0 0] var point1 = new CIVector(250, 250); // Default [200 200] var linearGrad = new CILinearGradient() { Point0 = point0, Point1 = point1, Color0 = new CIColor(UIColor.Red), Color1 = new CIColor(UIColor.Blue) }; return(Crop(linearGrad)); }
public CIImage GaussianGradient() { var centerVector = new CIVector(100, 100); // Default is [150 150] var color1 = CIColor.FromRgba(1, 0, 1, 1); var color0 = CIColor.FromRgba(0, 1, 1, 1); var gaussGradient = new CIGaussianGradient() { Center = centerVector, Color0 = color0, Color1 = color1, Radius = 280f // Default is 300 }; return(Crop(gaussGradient)); }
void ApplyFilter() { CIVector center = CIVector.Create(Bounds.GetMidX(), Bounds.GetMidY()); CIFilter torus = CIFilter.FromName("CITorusLensDistortion"); var keys = new NSString[] { CIFilterInputKey.Center, CIFilterInputKey.Radius, CIFilterInputKey.Width, CIFilterInputKey.Refraction }; var values = new NSObject[] { center, NSNumber.FromFloat(150), NSNumber.FromFloat(2), NSNumber.FromFloat(1.7f) }; torus.SetValuesForKeysWithDictionary(NSDictionary.FromObjectsAndKeys(values, keys)); controls.BackgroundFilters = new CIFilter[] { torus }; AddAnimationToTorusFilter(); }
public CIImage ToneCurve() { var point0 = new CIVector(0, 0); // Default [0 0] var point1 = new CIVector(.1F, .5F); // Default [.25 .25] var point2 = new CIVector(.3F, .15F); // Default [.3 .15] var point3 = new CIVector(.6F, .6F); // Default [.75 .75] var point4 = new CIVector(1.1F, 1F); // Default [1 1] var toneCurve = new CIToneCurve() { Image = flower, Point0 = point0, Point1 = point1, Point2 = point2, Point3 = point3, Point4 = point4, }; return(toneCurve.OutputImage); }
public CIImage ColorMatrix() { var rVector = new CIVector(.5F, 0F, 0F); // Multiple the Red Values by .5 (s.r = dot(s, rVector)) var gVector = new CIVector(0F, 1.5F, 0F); // Multiple the Green Vector by 1.5 (s.g = dot(s, gVector)) var bVector = new CIVector(0F, 0F, .75F); // Multiple the Blue Vectoer by .75 (s.b = dot(s, bVector)) var aVector = new CIVector(0F, 0F, 0F, 1.25F); // Multiple the Alpha values by 1.25 (s.a = dot(s, bVector)) var biasVector = new CIVector(0, 1, 0, 0); // A Bias to be Added to each Color Vector (s = s + bias) var colorMatrix = new CIColorMatrix() { Image = flower, RVector = rVector, GVector = gVector, BVector = bVector, AVector = aVector, BiasVector = biasVector }; return(colorMatrix.OutputImage); }
NSObject [] GetParms() { switch (Type) { case CustomerFilterType.NoOpColor: return(new NSObject[] { MyImage }); case CustomerFilterType.NoOpColorWithParam: return(new NSObject[] { MyImage, new NSNumber(5) }); case CustomerFilterType.ColorPositionKernel: var dod = MyImage.Extent; double radius = 0.5 * Math.Sqrt(Math.Pow(dod.Width, 2) + Math.Pow(dod.Height, 2)); CIVector centerOffset = new CIVector((float)(dod.Size.Width * .5), (float)(dod.Size.Height * .5)); return(new NSObject[] { MyImage, centerOffset, new NSNumber(radius) }); case CustomerFilterType.NoOpWarpKernel: return(new NSObject[] { }); } throw new InvalidOperationException(); }
public CIImage GaussianGradient () { var centerVector = new CIVector (100, 100); // Default is [150 150] var color1 = CIColor.FromRgba (1, 0, 1, 1); var color0 = CIColor.FromRgba (0, 1, 1, 1); var gaussGradient = new CIGaussianGradient () { Center = centerVector, Color0 = color0, Color1 = color1, Radius = 280f // Default is 300 }; return Crop (gaussGradient); }
public CIImage ToneCurve() { var point0 = new CIVector(0,0); // Default [0 0] var point1 = new CIVector(.1F, .5F); // Default [.25 .25] var point2 = new CIVector(.3F, .15F); // Default [.3 .15] var point3 = new CIVector(.6F, .6F); // Default [.75 .75] var point4 = new CIVector(1.1F, 1F); // Default [1 1] var toneCurve = new CIToneCurve() { Image = flower, Point0 = point0, Point1 = point1, Point2 = point2, Point3 = point3, Point4 = point4, }; return toneCurve.OutputImage; }
public CIImage ColorMatrix() { var rVector = new CIVector (.5F, 0F, 0F); // Multiple the Red Values by .5 (s.r = dot(s, rVector)) var gVector = new CIVector (0F, 1.5F, 0F); // Multiple the Green Vector by 1.5 (s.g = dot(s, gVector)) var bVector = new CIVector (0F, 0F, .75F); // Multiple the Blue Vectoer by .75 (s.b = dot(s, bVector)) var aVector = new CIVector (0F, 0F, 0F, 1.25F); // Multiple the Alpha values by 1.25 (s.a = dot(s, bVector)) var biasVector = new CIVector (0, 1, 0, 0); // A Bias to be Added to each Color Vector (s = s + bias) var colorMatrix = new CIColorMatrix () { Image = flower, RVector = rVector, GVector = gVector, BVector = bVector, AVector = aVector, BiasVector = biasVector }; return colorMatrix.OutputImage; }
public CIImage LinearGradient() { var point0 = new CIVector(0, 0); // Default [0 0] var point1 = new CIVector(250, 250); // Default [200 200] var linearGrad = new CILinearGradient() { Point0 = point0, Point1 = point1, Color0 = new CIColor (UIColor.Red), Color1 = new CIColor (UIColor.Blue) }; return Crop (linearGrad); }
public void DrawImage(Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttrs) { if (image == null) throw new ArgumentNullException ("image"); var srcRect1 = new RectangleF(srcX, srcY,srcWidth,srcHeight); // If the source units are not the same we need to convert them // The reason we check for Pixel here is that our graphics already has the Pixel's baked into the model view transform if (srcUnit != graphicsUnit && srcUnit != GraphicsUnit.Pixel) { ConversionHelpers.GraphicsUnitConversion (srcUnit, graphicsUnit, image.HorizontalResolution, image.VerticalResolution, ref srcRect1); } // Obtain the subImage var subImage = image.NativeCGImage.WithImageInRect (srcRect1.ToCGRect ()); // If we do not have anything to draw then we exit here if (subImage.Width == 0 || subImage.Height == 0) return; // var transform = image.imageTransform; //// // Reset our height on the transform to account for subImage // transform.y0 = subImage.Height; //// //// // Make sure we scale the image in case the source rectangle //// // overruns our subimage bouncs width and/or height // float scaleX = subImage.Width/srcRect1.Width; // float scaleY = subImage.Height/srcRect1.Height; // transform.Scale (scaleX, scaleY); bool attributesSet = imageAttrs.isColorMatrixSet || imageAttrs.isGammaSet; if (attributesSet) { InitializeImagingContext (); CIImage result = subImage; if (imageAttrs.isColorMatrixSet) { var ciFilter = CIFilter.FromName ("CIColorMatrix"); ciFilter.SetDefaults (); ciFilter.SetValueForKey (result, new NSString ("inputImage")); var inputRVector = new CIVector (imageAttrs.colorMatrix.Matrix00, imageAttrs.colorMatrix.Matrix01, imageAttrs.colorMatrix.Matrix02, imageAttrs.colorMatrix.Matrix03); var inputGVector = new CIVector (imageAttrs.colorMatrix.Matrix10, imageAttrs.colorMatrix.Matrix11, imageAttrs.colorMatrix.Matrix12, imageAttrs.colorMatrix.Matrix13); var inputBVector = new CIVector (imageAttrs.colorMatrix.Matrix20, imageAttrs.colorMatrix.Matrix21, imageAttrs.colorMatrix.Matrix22, imageAttrs.colorMatrix.Matrix23); var inputAVector = new CIVector (imageAttrs.colorMatrix.Matrix30, imageAttrs.colorMatrix.Matrix31, imageAttrs.colorMatrix.Matrix32, imageAttrs.colorMatrix.Matrix33); var inputBiasVector = new CIVector (imageAttrs.colorMatrix.Matrix40, imageAttrs.colorMatrix.Matrix41, imageAttrs.colorMatrix.Matrix42, imageAttrs.colorMatrix.Matrix43); ciFilter.SetValueForKey (inputRVector, new NSString ("inputRVector")); ciFilter.SetValueForKey (inputGVector, new NSString ("inputGVector")); ciFilter.SetValueForKey (inputBVector, new NSString ("inputBVector")); ciFilter.SetValueForKey (inputAVector, new NSString ("inputAVector")); ciFilter.SetValueForKey (inputBiasVector, new NSString ("inputBiasVector")); result = (CIImage)ciFilter.ValueForKey (new NSString ("outputImage")); } if (imageAttrs.isGammaSet) { var ciFilter = CIFilter.FromName ("CIGammaAdjust"); ciFilter.SetDefaults (); ciFilter.SetValueForKey (result, new NSString ("inputImage")); var inputPower = NSNumber.FromFloat (imageAttrs.gamma); ciFilter.SetValueForKey (inputPower, new NSString ("inputPower")); result = (CIImage)ciFilter.ValueForKey (new NSString ("outputImage")); } subImage = ciContext.CreateCGImage (result, result.Extent); } transform = image.imageTransform; transform.y0 = subImage.Height; float scaleX1 = subImage.Width/srcRect1.Width; float scaleY1 = subImage.Height/srcRect1.Height; transform.Scale (scaleX1, scaleY1); // Now draw our image DrawImage (destRect, subImage, transform); }
public void DrawImage(Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttrs) { if (image == null) { throw new ArgumentNullException("image"); } var srcRect1 = new RectangleF(srcX, srcY, srcWidth, srcHeight); // If the source units are not the same we need to convert them // The reason we check for Pixel here is that our graphics already has the Pixel's baked into the model view transform if (srcUnit != graphicsUnit && srcUnit != GraphicsUnit.Pixel) { ConversionHelpers.GraphicsUnitConversion(srcUnit, graphicsUnit, image.HorizontalResolution, image.VerticalResolution, ref srcRect1); } if (image.NativeCGImage == null) { DrawImage(image, destRect); return; } // Obtain the subImage var subImage = image.NativeCGImage.WithImageInRect(srcRect1.ToCGRect()); // If we do not have anything to draw then we exit here if (subImage.Width == 0 || subImage.Height == 0) { return; } // var transform = image.imageTransform; //// // Reset our height on the transform to account for subImage // transform.y0 = subImage.Height; //// //// // Make sure we scale the image in case the source rectangle //// // overruns our subimage bouncs width and/or height // float scaleX = subImage.Width/srcRect1.Width; // float scaleY = subImage.Height/srcRect1.Height; // transform.Scale (scaleX, scaleY); bool attributesSet = imageAttrs != null && (imageAttrs.isColorMatrixSet || imageAttrs.isGammaSet); if (attributesSet) { InitializeImagingContext(); CIImage result = subImage; if (imageAttrs.isColorMatrixSet) { var ciFilter = CIFilter.FromName("CIColorMatrix"); ciFilter.SetDefaults(); ciFilter.SetValueForKey(result, new NSString("inputImage")); var inputRVector = new CIVector(imageAttrs.colorMatrix.Matrix00, imageAttrs.colorMatrix.Matrix01, imageAttrs.colorMatrix.Matrix02, imageAttrs.colorMatrix.Matrix03); var inputGVector = new CIVector(imageAttrs.colorMatrix.Matrix10, imageAttrs.colorMatrix.Matrix11, imageAttrs.colorMatrix.Matrix12, imageAttrs.colorMatrix.Matrix13); var inputBVector = new CIVector(imageAttrs.colorMatrix.Matrix20, imageAttrs.colorMatrix.Matrix21, imageAttrs.colorMatrix.Matrix22, imageAttrs.colorMatrix.Matrix23); var inputAVector = new CIVector(imageAttrs.colorMatrix.Matrix30, imageAttrs.colorMatrix.Matrix31, imageAttrs.colorMatrix.Matrix32, imageAttrs.colorMatrix.Matrix33); var inputBiasVector = new CIVector(imageAttrs.colorMatrix.Matrix40, imageAttrs.colorMatrix.Matrix41, imageAttrs.colorMatrix.Matrix42, imageAttrs.colorMatrix.Matrix43); ciFilter.SetValueForKey(inputRVector, new NSString("inputRVector")); ciFilter.SetValueForKey(inputGVector, new NSString("inputGVector")); ciFilter.SetValueForKey(inputBVector, new NSString("inputBVector")); ciFilter.SetValueForKey(inputAVector, new NSString("inputAVector")); ciFilter.SetValueForKey(inputBiasVector, new NSString("inputBiasVector")); result = (CIImage)ciFilter.ValueForKey(new NSString("outputImage")); } if (imageAttrs.isGammaSet) { var ciFilter = CIFilter.FromName("CIGammaAdjust"); ciFilter.SetDefaults(); ciFilter.SetValueForKey(result, new NSString("inputImage")); var inputPower = NSNumber.FromFloat(imageAttrs.gamma); ciFilter.SetValueForKey(inputPower, new NSString("inputPower")); result = (CIImage)ciFilter.ValueForKey(new NSString("outputImage")); } subImage = ciContext.CreateCGImage(result, result.Extent); } transform = image.imageTransform; transform.y0 = subImage.Height; float scaleX1 = subImage.Width / srcRect1.Width; float scaleY1 = subImage.Height / srcRect1.Height; transform.Scale(scaleX1, scaleY1); // Now draw our image DrawImage(destRect, subImage, transform); }
public CIImage RadialGradient() { var center = new CIVector(100, 100); // Default [150 150] var radGradient = new CIRadialGradient() { Center = center, Radius0 = 10F, // Default 5 Radius1 = 150F, // Default 100 Color0 = new CIColor(new CGColor(0, 255F, 0)), // Green Color1 = new CIColor(new CGColor(0, 0, 0)) // Black }; return Crop (radGradient); }