<commit_before>using System;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using MonoTouch.CoreImage;

using System.Collections.Generic;
using MonoTouch.Dialog;
using System.Drawing;
using System.Linq;
using System.Reflection;
using MonoTouch.CoreGraphics;

namespace coreimage
{
	[Register ("AppDelegate")]
	public partial class AppDelegate : UIApplicationDelegate
	{
		/// <summary>
		/// "Flower" © 2012 <NAME>, used under a Creative Commons Attribution-ShareAlike license: http://creativecommons.org/licenses/by-sa/3.0/ 
		/// </summary>
		CIImage flower = CIImage.FromCGImage (UIImage.FromFile ("flower.png").CGImage);
		
		/// <summary>
		/// "Sunrise near Atkeison Plateau" © 2012 <NAME>, used under a Creative Commons Attribution-ShareAlike license: http://creativecommons.org/licenses/by-sa/3.0/ 
		/// </summary>
		CIImage clouds = CIImage.FromCGImage (UIImage.FromFile ("clouds.jpg").CGImage);
		
		/// <summary>
		/// "canon" © 2012 cuatrok77 hernandez, used under a Creative Commons Attribution-ShareAlike license: http://creativecommons.org/licenses/by-sa/3.0/ 
		/// </summary>
		CIImage heron = CIImage.FromCGImage (UIImage.FromFile ("heron.jpg").CGImage);
		UIWindow window;
		
		#region UIApplicationDelegate Methods
		public override bool FinishedLaunching (UIApplication app, NSDictionary options)
		{
			var root = new RootElement ("Effects") {
				new Section () {
					new RootElement ("Color Adjustment"){
						new Section () {
							new RootElement ("ColorControls", (x) => Demo (ColorControls)),
							new RootElement ("ColorMatrix", (x) => Demo (ColorMatrix)),
							new RootElement ("ExposureAdjust", (x) => Demo (ExposureAdjust)),
							new RootElement ("GammaAdjust", (x) => Demo (GammaAdjust)),
							new RootElement ("HueAdjust", (x) => Demo (HueAdjust)),
							new RootElement ("TemperatureAndTint", (x) => Demo (TemperatureAndTint)),
							new RootElement ("ToneCurve", (x) => Demo (ToneCurve)),
							new RootElement ("Vibrance", (x) => Demo (Vibrance)),
							new RootElement ("WhitePointAdjust", (x) => Demo(WhitePointAdjust))
						}
					},
					new RootElement ("Color Effect"){
						new Section () {
							new RootElement ("ColorCube", (x) => Demo (ColorCube)),
							new RootElement ("ColorInvert", (x) => Demo (ColorInvert)),
							new RootElement ("ColorMonochrome", (x) => Demo (ColorMonochrome)),
							new RootElement ("FalseColor", (x) => Demo (FalseColor)),
							new RootElement ("SepiaTone", (x) => Demo (SepiaTone)),
						}
					},
					new RootElement ("Composite Operation"){
						new Section () {
							new RootElement ("AdditionCompositing", (x) => Demo (AdditionCompositing)),
							new RootElement ("ColorBlendMode", (x) => Demo (ColorBlendMode)),
							new RootElement ("ColorBurnBlendMode", (x) => Demo (ColorBurnBlendMode)),
							new RootElement ("ColorDodgeBlendMode", (x) => Demo (ColorDodgeBlendMode)),
							new RootElement ("DifferenceBlendMode", (x) => Demo (DifferenceBlendMode)),
							new RootElement ("ExclusionBlendMode", (x) => Demo (ExclusionBlendMode)),
							new RootElement ("HardLightBlendMode", (x) => Demo (HardLightBlendMode)),
							new RootElement ("HueBlendMode", (x) => Demo (HueBlendMode)),
							new RootElement ("LightenBlendMode", (x) => Demo (LightenBlendMode)),
							new RootElement ("LuminosityBlendMode", (x) => Demo (LuminosityBlendMode)),
							new RootElement ("MaximumCompositing", (x) => Demo (MaximumCompositing)),
							new RootElement ("MultiplyCompositing", (x) => Demo (MultiplyCompositing)),
							new RootElement ("MultiplyBlendMode", (x) => Demo (MultiplyBlendMode)),
							new RootElement ("OverlayBlendMode", (x) => Demo (OverlayBlendMode)),
							new RootElement ("SaturationBlendMode", (x) => Demo (SaturationBlendMode)),
							new RootElement ("ScreenBlendMode", (x) => Demo (ScreenBlendMode)),
							new RootElement ("SoftLightBlendMode", (x) => Demo (SoftLightBlendMode)),
							new RootElement ("SourceAtopCompositing", (x) => Demo (SourceAtopCompositing)),
							new RootElement ("SourceInCompositing", (x) => Demo(SourceInCompositing)),
							new RootElement ("SourceOutCompositing", (x) => Demo(SourceOutCompositing)),
							new RootElement ("SourceOverCompositing", (x) => Demo (SourceOverCompositing)),
						}
					},
					new RootElement ("Distortions"){
						new Section () {
						}
					},
					new RootElement ("Generators"){
						new Section () {
							new RootElement ("CheckerboardGenerator", (x) => Demo (CheckerboardGenerator)),
							new RootElement ("ConstantColorGenerator", (x) => Demo (ConstantColorGenerator)),
							new RootElement ("StripesGenerator", (x) => Demo (StripesGenerator)),
						}
					},
					new RootElement ("Geometry Adjust"){
						new Section () {
							new RootElement ("AffineTransform", (x) => Demo (AffineTransform)),
							new RootElement ("Crop", (x) => Demo (Crop)),
							new RootElement ("StraightenFilter", (x) => Demo (StraightenFilter)),
						}
					},
					new RootElement ("Gradients"){
						new Section () {
							new RootElement ("GaussianGradient", (x) => Demo (GaussianGradient)),
							new RootElement ("LinearGradient", (x) =>Demo(LinearGradient)),
							new RootElement ("RadialGradient", (x) => Demo (RadialGradient)),
						}
					},
					new RootElement ("Stylize"){
						new Section () {
							new RootElement ("HighlightShadowAdjust", (x) => Demo (HighlightShadowAdjust)),
						}
					},
					new RootElement ("Vignette", (x) => Demo (Vignette))
				}
			};					
			
			window = new UIWindow (UIScreen.MainScreen.Bounds) {
				RootViewController = new UINavigationController (new DialogViewController (root))
			};
			window.MakeKeyAndVisible ();

			return true;
		}
		#endregion
		
		#region Helper Methods
		// 
		// Utility function used by pure-output generation filters
		//
		public CIImage Crop (CIFilter input)
		{
			return new CICrop () { 
				Image = input.OutputImage,
				Rectangle = new CIVector (0, 0, window.Bounds.Width, window.Bounds.Height) 
			}.OutputImage;			
		}
		
		public delegate CIImage ImageFilter ();
		
		public UIViewController Demo (ImageFilter makeDemo)
		{
			var v = new UIViewController ();
			var imageView = new UIImageView (v.View.Bounds);
			v.View.AddSubview (imageView);
			
			var output = makeDemo ();
			var context = CIContext.FromOptions (null);
			var result = context.CreateCGImage (output, output.Extent);
			imageView.Image = UIImage.FromImage (result);
			return v;
		}	
		#endregion
		
		#region Filter Methods
		#region CICategoryColorAdjustment
		/// <summary>
		/// Multiplies source color values and adds a bias factor to each color component.
		/// </summary>
		/// <returns>
		/// The altered Image
		/// </returns>
		[Filter]
		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;
		}
		
		/// <summary>
		/// Adjusts saturation, brightness, and contrast values.
		/// </summary>
		/// <returns>
		/// Altered Image
		/// </returns>
		[Filter]
		public CIImage ColorControls ()
		{
			var colorCtrls = new CIColorControls (){
				Image = flower,
				Brightness = .5F,
				Saturation = 1.2F,
				Contrast = 3.1F
			};
			
			return colorCtrls.OutputImage;
		}
		
		/// <summary>
		/// Changes the overall hue, or tint, of the source pixels.
		/// </summary>
		/// <returns>
		/// The Altered Image.
		/// </returns>
		[Filter]
		public CIImage HueAdjust()
		{
			var hueAdjust = new CIHueAdjust()
			{
				Image = flower,
				Angle = 1F // Default is 0
			};
			
			return hueAdjust.OutputImage;
		}
		
		/// <summary>
		/// Adapts the reference white point for an image.
		/// </summary>
		/// <returns>
		/// The Color Adjusted Image
		/// </returns>
		[Filter]
		public CIImage TemperatureAndTint()
		{
			var temperatureAdjust = new CITemperatureAndTint()
			{
				Image = flower,
				Neutral = new CIVector(6500, 0), // Default [6500, 0]
				TargetNeutral = new CIVector(4000, 0), // Default [6500, 0]
			};
			
			return temperatureAdjust.OutputImage;
		}
		
		/// <summary>
		/// Adjusts tone response of the R, G, and B channels of an image.
		/// </summary>
		/// <returns>
		/// The adjusted image
		/// </returns>
		[Filter]
		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;
		}
		
		/// <summary>
		/// Adjusts the saturation of an image while keeping pleasing skin tones.
		/// </summary>
		[Filter]
		public CIImage Vibrance()
		{
			var vibrance = new CIVibrance()
			{
				Image = flower,
				Amount = -1.0F // Default 0
			};
			
			return vibrance.OutputImage;
		}
		
		/// <summary>
		/// Add a reduction of an image's brightness or saturation at the periphery compared to the image center.
		/// </summary>
		[Filter]
		public CIImage Vignette()
		{
			var vignette = new CIVignette()
			{
				Image = flower,
				Intensity = 2F,
				Radius = 10F,
			};
			
			return vignette.OutputImage;
		}
		
		/// <summary>
		/// Adjusts the reference white point for an image and maps all colors in the source using the new reference.
		/// </summary>
		/// <returns>
		/// The Color Adjusted Image
		/// </returns>
		public CIImage WhitePointAdjust()
		{
			var whitePointAdjust = new CIWhitePointAdjust()
			{
				Image = flower,
				Color = new CIColor(new CGColor(255F, 0, 187F)) // A Magenta Color
			};
			
			return whitePointAdjust.OutputImage;
		}
		#endregion
		
		#region CICategoryColorEffect
		
		/// <summary>
		/// Applies a Sepia Filter to an Image
		/// </summary>
		/// <returns>
		/// Image with Sepia Filter
		/// </returns>
		[Filter]
		public CIImage SepiaTone ()
		{
			var sepia = new CISepiaTone () {
				Image = flower,
				Intensity = .8f
			};
			return sepia.OutputImage;
		}
			
		/// <summary>
		/// Uses a three-dimensional color table to transform the source image pixels.
		/// </summary>
		/// <returns>
		/// The Altered Image
		/// </returns>
		[Filter]
		public CIImage ColorCube ()
		{
			var data = new NSData ();
			
			var cube = new CIColorCube ()
			{
				Image = flower,
				CubeDimension = Convert.ToSingle (Math.Pow (2F, 2F)),
			//CubeData = 
			};
			
			return cube.OutputImage;
		}
		
		/// <summary>
		/// Inverts the colors in an image.
		/// </summary>
		/// <returns>
		/// The Altered Image
		/// </returns>
		public CIImage ColorInvert ()
		{
			var invert = new CIColorInvert ()
			{
				Image = flower
			};
			
			return invert.OutputImage;
		}
		
		/// <summary>
		/// Remaps colors so they fall within shades of a single color.
		/// </summary>
		/// <returns>
		/// The Altered Image
		/// </returns>
		[Filter]
		public CIImage ColorMonochrome ()
		{
			var inputColor = new CIColor (new CGColor (100F, 0F, 100F)); // Make it Purple R + B = Purple
			var monoChrome = new CIColorMonochrome ()
			{
				Image = flower,
				Color = inputColor,
				Intensity = 1F,
			};
			
			return monoChrome.OutputImage;
		}
		
		/// <summary>
		/// Maps luminance to a color ramp of two colors.
		/// </summary>
		/// <returns>
		/// The altered Image
		/// </returns>
		[Filter]
		public CIImage FalseColor ()
		{
			var color0 = new CIColor (new CGColor (255F, 251F, 0F)); // A Yellowish Color
			var color1 = new CIColor (new CGColor (51F, 0F, 255F)); // A Purplish Color
			var falseColor = new CIFalseColor ()
			{
				Image = flower,
				Color0 = color0,
				Color1 = color1
			};
			
			return falseColor.OutputImage;
		}
		
		/// <summary>
		/// Adjusts midtone brightness.
		/// </summary>
		/// <returns>
		/// Alters the image
		/// </returns>
		[Filter]
		public CIImage GammaAdjust ()
		{
			var gammaAdjust = new CIGammaAdjust ()
			{
				Image = flower,
				Power = 3F, // Default value: 0.75
			};
			
			return gammaAdjust.OutputImage;
		}
		#endregion
		
		#region CategoryGradient
		/// <summary>
		/// Generates a gradient that varies from one color to another using a Gaussian distribution.
		/// </summary>
		/// <returns>
		/// The gradient.
		/// </returns>
		[Filter]
		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);
		}
		
		/// <summary>
		/// Generates a gradient that varies along a linear axis between two defined endpoints.
		/// </summary>
		/// <returns>
		/// The gradient.
		/// </returns>
		[Filter]
		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);
		}
		
		/// <summary>
		/// Generates a gradient that varies radially between two circles having the same center.
		/// </summary>
		/// <returns>
		/// The gradient.
		/// </returns>
		[Filter]
		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);
		}
		#endregion
		
		#region CICategoryGeometryAdjustment
		/// <summary>
		/// Applies a crop to an image.
		/// </summary>
		[Filter]
		public CIImage Crop ()
		{
			var crop = new CICrop () {
				Image = flower,
				Rectangle = new CIVector (0, 0, 300, 300)
			};
			return crop.OutputImage;
		}
		
		/// <summary>
		/// Applies an affine transform to an image
		/// </summary>
		/// <returns>
		/// The Altered Image
		/// </returns>
		[Filter]
		public CIImage AffineTransform ()
		{
			// Create an AffineTransform to Skew the Image
			var transform = new CGAffineTransform (1F, .5F, .5F, 1F, 0F, 0F);
			
			var affineTransform = new CIAffineTransform ()
			{
				Image = flower,
				Transform = transform
			};
			
			return affineTransform.OutputImage;
		}
		
		/// <summary>
		/// Adjusts the exposure setting for an image similar to the way you control exposure for a camera when you change the F-stop.
		/// </summary>
		/// <returns>
		/// The altered Image
		/// </returns>
		[Filter]
		public CIImage ExposureAdjust ()
		{
			var exposureAdjust = new CIExposureAdjust ()
			{
				Image = flower,
				EV = 2F // Default value: 0.50 Minimum: 0.00 Maximum: 0.00 Slider minimum: -10.00 Slider maximum: 10.00 Identity: 0.00
			};
			
			return exposureAdjust.OutputImage;
		}
		
		/// <summary>
		/// Rotates the source image by the specified angle in radians.
		/// </summary>
		/// <returns>
		/// The filtered Image
		/// </returns>
		[Filter]
		public CIImage StraightenFilter()
		{
			var straightFilter = new CIStraightenFilter()
			{
				Image = heron,
				Angle = Convert.ToSingle(Math.PI / 4.0) // Change by 45 degrees = pi/4 Radians.
			};
			
			return straightFilter.OutputImage;
		}
		
		
		#endregion
		
		#region CICategoryCompositeOperation
		/// <summary>
		/// Adds color components to achieve a brightening effect.
		/// </summary>
		/// <returns>
		/// The composite Image
		/// </returns>
		[Filter]
		public CIImage AdditionCompositing ()
		{
			var addComp = new CIAdditionCompositing ()
			{
				Image = heron,
				BackgroundImage = clouds,
			};
			
			return addComp.OutputImage;
		}
		
		/// <summary>
		/// Uses the luminance values of the background with the hue and saturation values of the source image.
		/// </summary>
		/// <returns>
		/// The composite image
		/// </returns>
		[Filter]
		public CIImage ColorBlendMode ()
		{
			var colorBlend = new CIColorBlendMode ()
			{
				Image = heron,
				BackgroundImage = clouds
			};
			
			return colorBlend.OutputImage;
		}
		
		/// <summary>
		/// Darkens the background image samples to reflect the source image samples.
		/// </summary>
		/// <returns>
		/// The composite image
		/// </returns>
		[Filter]
		public CIImage ColorBurnBlendMode()
		{
			var colorBurn = new CIColorBurnBlendMode()
			{
				Image = heron,
				BackgroundImage = clouds
			};
			
			return colorBurn.OutputImage;
		}
		
		/// <summary>
		/// Brightens the background image samples to reflect the source image samples.
		/// </summary>
		/// <returns>
		/// The composite Image
		/// </returns>
		public CIImage ColorDodgeBlendMode ()
		{
			var colorDodgeBlend = new CIColorDodgeBlendMode ()
			{
				Image = heron,
				BackgroundImage = clouds,
			};
			
			return colorDodgeBlend.OutputImage;<commit_msg>Added the CIDarkenBlendMode filter<commit_after>using System;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using MonoTouch.CoreImage;

using System.Collections.Generic;
using MonoTouch.Dialog;
using System.Drawing;
using System.Linq;
using System.Reflection;
using MonoTouch.CoreGraphics;

namespace coreimage
{
	[Register ("AppDelegate")]
	public partial class AppDelegate : UIApplicationDelegate
	{
		/// <summary>
		/// "Flower" © 2012 <NAME>, used under a Creative Commons Attribution-ShareAlike license: http://creativecommons.org/licenses/by-sa/3.0/ 
		/// </summary>
		CIImage flower = CIImage.FromCGImage (UIImage.FromFile ("flower.png").CGImage);
		
		/// <summary>
		/// "Sunrise near Atkeison Plateau" © 2012 <NAME>, used under a Creative Commons Attribution-ShareAlike license: http://creativecommons.org/licenses/by-sa/3.0/ 
		/// </summary>
		CIImage clouds = CIImage.FromCGImage (UIImage.FromFile ("clouds.jpg").CGImage);
		
		/// <summary>
		/// "canon" © 2012 cuatrok77 hernandez, used under a Creative Commons Attribution-ShareAlike license: http://creativecommons.org/licenses/by-sa/3.0/ 
		/// </summary>
		CIImage heron = CIImage.FromCGImage (UIImage.FromFile ("heron.jpg").CGImage);
		UIWindow window;
		
		#region UIApplicationDelegate Methods
		public override bool FinishedLaunching (UIApplication app, NSDictionary options)
		{
			var root = new RootElement ("Effects") {
				new Section () {
					new RootElement ("Color Adjustment"){
						new Section () {
							new RootElement ("ColorControls", (x) => Demo (ColorControls)),
							new RootElement ("ColorMatrix", (x) => Demo (ColorMatrix)),
							new RootElement ("ExposureAdjust", (x) => Demo (ExposureAdjust)),
							new RootElement ("GammaAdjust", (x) => Demo (GammaAdjust)),
							new RootElement ("HueAdjust", (x) => Demo (HueAdjust)),
							new RootElement ("TemperatureAndTint", (x) => Demo (TemperatureAndTint)),
							new RootElement ("ToneCurve", (x) => Demo (ToneCurve)),
							new RootElement ("Vibrance", (x) => Demo (Vibrance)),
							new RootElement ("WhitePointAdjust", (x) => Demo(WhitePointAdjust))
						}
					},
					new RootElement ("Color Effect"){
						new Section () {
							new RootElement ("ColorCube", (x) => Demo (ColorCube)),
							new RootElement ("ColorInvert", (x) => Demo (ColorInvert)),
							new RootElement ("ColorMonochrome", (x) => Demo (ColorMonochrome)),
							new RootElement ("FalseColor", (x) => Demo (FalseColor)),
							new RootElement ("SepiaTone", (x) => Demo (SepiaTone)),
						}
					},
					new RootElement ("Composite Operation"){
						new Section () {
							new RootElement ("AdditionCompositing", (x) => Demo (AdditionCompositing)),
							new RootElement ("ColorBlendMode", (x) => Demo (ColorBlendMode)),
							new RootElement ("ColorBurnBlendMode", (x) => Demo (ColorBurnBlendMode)),
							new RootElement ("ColorDodgeBlendMode", (x) => Demo (ColorDodgeBlendMode)),
							new RootElement ("DarkenBlendMode", (x) => Demo (DarkenBlendMode)),
							new RootElement ("DifferenceBlendMode", (x) => Demo (DifferenceBlendMode)),
							new RootElement ("ExclusionBlendMode", (x) => Demo (ExclusionBlendMode)),
							new RootElement ("HardLightBlendMode", (x) => Demo (HardLightBlendMode)),
							new RootElement ("HueBlendMode", (x) => Demo (HueBlendMode)),
							new RootElement ("LightenBlendMode", (x) => Demo (LightenBlendMode)),
							new RootElement ("LuminosityBlendMode", (x) => Demo (LuminosityBlendMode)),
							new RootElement ("MaximumCompositing", (x) => Demo (MaximumCompositing)),
							new RootElement ("MultiplyCompositing", (x) => Demo (MultiplyCompositing)),
							new RootElement ("MultiplyBlendMode", (x) => Demo (MultiplyBlendMode)),
							new RootElement ("OverlayBlendMode", (x) => Demo (OverlayBlendMode)),
							new RootElement ("SaturationBlendMode", (x) => Demo (SaturationBlendMode)),
							new RootElement ("ScreenBlendMode", (x) => Demo (ScreenBlendMode)),
							new RootElement ("SoftLightBlendMode", (x) => Demo (SoftLightBlendMode)),
							new RootElement ("SourceAtopCompositing", (x) => Demo (SourceAtopCompositing)),
							new RootElement ("SourceInCompositing", (x) => Demo(SourceInCompositing)),
							new RootElement ("SourceOutCompositing", (x) => Demo(SourceOutCompositing)),
							new RootElement ("SourceOverCompositing", (x) => Demo (SourceOverCompositing)),
						}
					},
					new RootElement ("Distortions"){
						new Section () {
						}
					},
					new RootElement ("Generators"){
						new Section () {
							new RootElement ("CheckerboardGenerator", (x) => Demo (CheckerboardGenerator)),
							new RootElement ("ConstantColorGenerator", (x) => Demo (ConstantColorGenerator)),
							new RootElement ("StripesGenerator", (x) => Demo (StripesGenerator)),
						}
					},
					new RootElement ("Geometry Adjust"){
						new Section () {
							new RootElement ("AffineTransform", (x) => Demo (AffineTransform)),
							new RootElement ("Crop", (x) => Demo (Crop)),
							new RootElement ("StraightenFilter", (x) => Demo (StraightenFilter)),
						}
					},
					new RootElement ("Gradients"){
						new Section () {
							new RootElement ("GaussianGradient", (x) => Demo (GaussianGradient)),
							new RootElement ("LinearGradient", (x) =>Demo(LinearGradient)),
							new RootElement ("RadialGradient", (x) => Demo (RadialGradient)),
						}
					},
					new RootElement ("Stylize"){
						new Section () {
							new RootElement ("HighlightShadowAdjust", (x) => Demo (HighlightShadowAdjust)),
						}
					},
					new RootElement ("Vignette", (x) => Demo (Vignette))
				}
			};					
			
			window = new UIWindow (UIScreen.MainScreen.Bounds) {
				RootViewController = new UINavigationController (new DialogViewController (root))
			};
			window.MakeKeyAndVisible ();

			return true;
		}
		#endregion
		
		#region Helper Methods
		// 
		// Utility function used by pure-output generation filters
		//
		public CIImage Crop (CIFilter input)
		{
			return new CICrop () { 
				Image = input.OutputImage,
				Rectangle = new CIVector (0, 0, window.Bounds.Width, window.Bounds.Height) 
			}.OutputImage;			
		}
		
		public delegate CIImage ImageFilter ();
		
		public UIViewController Demo (ImageFilter makeDemo)
		{
			var v = new UIViewController ();
			var imageView = new UIImageView (v.View.Bounds);
			v.View.AddSubview (imageView);
			
			var output = makeDemo ();
			var context = CIContext.FromOptions (null);
			var result = context.CreateCGImage (output, output.Extent);
			imageView.Image = UIImage.FromImage (result);
			return v;
		}	
		#endregion
		
		#region Filter Methods
		#region CICategoryColorAdjustment
		/// <summary>
		/// Multiplies source color values and adds a bias factor to each color component.
		/// </summary>
		/// <returns>
		/// The altered Image
		/// </returns>
		[Filter]
		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;
		}
		
		/// <summary>
		/// Adjusts saturation, brightness, and contrast values.
		/// </summary>
		/// <returns>
		/// Altered Image
		/// </returns>
		[Filter]
		public CIImage ColorControls ()
		{
			var colorCtrls = new CIColorControls ()
			{
				Image = flower,
				Brightness = .5F, // Min: 0 Max: 2
				Saturation = 1.2F, // Min: -1 Max: 1
				Contrast = 3.1F // Min: 0 Max: 4
			};
			
			return colorCtrls.OutputImage;
		}
		
		/// <summary>
		/// Changes the overall hue, or tint, of the source pixels.
		/// </summary>
		/// <returns>
		/// The Altered Image.
		/// </returns>
		[Filter]
		public CIImage HueAdjust()
		{
			var hueAdjust = new CIHueAdjust()
			{
				Image = flower,
				Angle = 1F // Default is 0
			};
			
			return hueAdjust.OutputImage;
		}
		
		/// <summary>
		/// Adapts the reference white point for an image.
		/// </summary>
		/// <returns>
		/// The Color Adjusted Image
		/// </returns>
		[Filter]
		public CIImage TemperatureAndTint()
		{
			var temperatureAdjust = new CITemperatureAndTint()
			{
				Image = flower,
				Neutral = new CIVector(6500, 0), // Default [6500, 0]
				TargetNeutral = new CIVector(4000, 0), // Default [6500, 0]
			};
			
			return temperatureAdjust.OutputImage;
		}
		
		/// <summary>
		/// Adjusts tone response of the R, G, and B channels of an image.
		/// </summary>
		/// <returns>
		/// The adjusted image
		/// </returns>
		[Filter]
		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;
		}
		
		/// <summary>
		/// Adjusts the saturation of an image while keeping pleasing skin tones.
		/// </summary>
		[Filter]
		public CIImage Vibrance()
		{
			var vibrance = new CIVibrance()
			{
				Image = flower,
				Amount = -1.0F // Default 0
			};
			
			return vibrance.OutputImage;
		}
		
		/// <summary>
		/// Add a reduction of an image's brightness or saturation at the periphery compared to the image center.
		/// </summary>
		[Filter]
		public CIImage Vignette()
		{
			var vignette = new CIVignette()
			{
				Image = flower,
				Intensity = 2F,
				Radius = 10F,
			};
			
			return vignette.OutputImage;
		}
		
		/// <summary>
		/// Adjusts the reference white point for an image and maps all colors in the source using the new reference.
		/// </summary>
		/// <returns>
		/// The Color Adjusted Image
		/// </returns>
		public CIImage WhitePointAdjust()
		{
			var whitePointAdjust = new CIWhitePointAdjust()
			{
				Image = flower,
				Color = new CIColor(new CGColor(255F, 0, 187F)) // A Magenta Color
			};
			
			return whitePointAdjust.OutputImage;
		}
		#endregion
		
		#region CICategoryColorEffect
		
		/// <summary>
		/// Applies a Sepia Filter to an Image
		/// </summary>
		/// <returns>
		/// Image with Sepia Filter
		/// </returns>
		[Filter]
		public CIImage SepiaTone ()
		{
			var sepia = new CISepiaTone () {
				Image = flower,
				Intensity = .8f
			};
			return sepia.OutputImage;
		}
			
		/// <summary>
		/// Uses a three-dimensional color table to transform the source image pixels.
		/// </summary>
		/// <returns>
		/// The Altered Image
		/// </returns>
		[Filter]
		public CIImage ColorCube ()
		{
			var data = new NSData ();
			
			var cube = new CIColorCube ()
			{
				Image = flower,
				CubeDimension = Convert.ToSingle (Math.Pow (2F, 2F)),
			//CubeData = 
			};
			
			return cube.OutputImage;
		}
		
		/// <summary>
		/// Inverts the colors in an image.
		/// </summary>
		/// <returns>
		/// The Altered Image
		/// </returns>
		public CIImage ColorInvert ()
		{
			var invert = new CIColorInvert ()
			{
				Image = flower
			};
			
			return invert.OutputImage;
		}
		
		/// <summary>
		/// Remaps colors so they fall within shades of a single color.
		/// </summary>
		/// <returns>
		/// The Altered Image
		/// </returns>
		[Filter]
		public CIImage ColorMonochrome ()
		{
			var inputColor = new CIColor (new CGColor (100F, 0F, 100F)); // Make it Purple R + B = Purple
			var monoChrome = new CIColorMonochrome ()
			{
				Image = flower,
				Color = inputColor,
				Intensity = 1F, // Default 1
			};
			
			return monoChrome.OutputImage;
		}
		
		/// <summary>
		/// Maps luminance to a color ramp of two colors.
		/// </summary>
		/// <returns>
		/// The altered Image
		/// </returns>
		[Filter]
		public CIImage FalseColor ()
		{
			var color0 = new CIColor (new CGColor (255F, 251F, 0F)); // A Yellowish Color
			var color1 = new CIColor (new CGColor (51F, 0F, 255F)); // A Purplish Color
			var falseColor = new CIFalseColor ()
			{
				Image = flower,
				Color0 = color0,
				Color1 = color1
			};
			
			return falseColor.OutputImage;
		}
		
		/// <summary>
		/// Adjusts midtone brightness.
		/// </summary>
		/// <returns>
		/// Alters the image
		/// </returns>
		[Filter]
		public CIImage GammaAdjust ()
		{
			var gammaAdjust = new CIGammaAdjust ()
			{
				Image = flower,
				Power = 3F, // Default value: 0.75
			};
			
			return gammaAdjust.OutputImage;
		}
		#endregion
		
		#region CategoryGradient
		/// <summary>
		/// Generates a gradient that varies from one color to another using a Gaussian distribution.
		/// </summary>
		/// <returns>
		/// The gradient.
		/// </returns>
		[Filter]
		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);
		}
		
		/// <summary>
		/// Generates a gradient that varies along a linear axis between two defined endpoints.
		/// </summary>
		/// <returns>
		/// The gradient.
		/// </returns>
		[Filter]
		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);
		}
		
		/// <summary>
		/// Generates a gradient that varies radially between two circles having the same center.
		/// </summary>
		/// <returns>
		/// The gradient.
		/// </returns>
		[Filter]
		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);
		}
		#endregion
		
		#region CICategoryGeometryAdjustment
		/// <summary>
		/// Applies a crop to an image.
		/// </summary>
		[Filter]
		public CIImage Crop ()
		{
			var crop = new CICrop () {
				Image = flower,
				Rectangle = new CIVector (0, 0, 300, 300)
			};
			return crop.OutputImage;
		}
		
		/// <summary>
		/// Applies an affine transform to an image
		/// </summary>
		/// <returns>
		/// The Altered Image
		/// </returns>
		[Filter]
		public CIImage AffineTransform ()
		{
			// Create an AffineTransform to Skew the Image
			var transform = new CGAffineTransform (1F, .5F, .5F, 1F, 0F, 0F);
			
			var affineTransform = new CIAffineTransform ()
			{
				Image = flower,
				Transform = transform
			};
			
			return affineTransform.OutputImage;
		}
		
		/// <summary>
		/// Adjusts the exposure setting for an image similar to the way you control exposure for a camera when you change the F-stop.
		/// </summary>
		/// <returns>
		/// The altered Image
		/// </returns>
		[Filter]
		public CIImage ExposureAdjust ()
		{
			var exposureAdjust = new CIExposureAdjust ()
			{
				Image = flower,
				EV = 2F // Default value: 0.50 Minimum: 0.00 Maximum: 0.00 Slider minimum: -10.00 Slider maximum: 10.00 Identity: 0.00
			};
			
			return exposureAdjust.OutputImage;
		}
		
		/// <summary>
		/// Rotates the source image by the specified angle in radians.
		/// </summary>
		/// <returns>
		/// The filtered Image
		/// </returns>
		[Filter]
		public CIImage StraightenFilter()
		{
			var straightFilter = new CIStraightenFilter()
			{
				Image = heron,
				Angle = Convert.ToSingle(Math.PI / 4.0) // Change by 45 degrees = pi/4 Radians.
			};
			
			return straightFilter.OutputImage;
		}
		
		
		#endregion
		
		#region CICategoryCompositeOperation
		/// <summary>
		/// Adds color components to achieve a brightening effect.
		/// </summary>
		/// <returns>
		/// The composite Image
		/// </returns>
		[Filter]
		public CIImage AdditionCompositing ()
		{
			var addComp = new CIAdditionCompositing ()
			{
				Image = heron,
				BackgroundImage = clouds,
			};
			
			return addComp.OutputImage;
		}
		
		/// <summary>
		/// Uses the luminance values of the background with the hue and saturation values of the source image.
		/// </summary>
		/// <returns>
		/// The composite image
		/// </returns>
		[Filter]
		public CIImage ColorBlendMode ()
		{
			var colorBlend = new CIColorBlendMode ()
			{
				Image = heron,
				BackgroundImage = clouds
			};
			
			return colorBlend.OutputImage;
		}
		
		/// <summary>
		/// Darkens the background image samples to reflect the source image samples.
		/// </summary>
		/// <returns>
		/// The composite image
		/// </returns>
		[Filter]
		public CIImage ColorBurnBlendMode()
		{
			var colorBurn = new CIColorBurnBlendMode()
			{
				Image = heron,
				BackgroundImage = clouds
			};
			
			return colorBurn.OutputImage;
		}
		
		/// <summary>
		/// Brightens the background image samples to reflect the source image samples.
		/// </summary>
		/// <returns>
		/// The composite Image
		/// </returns>
		public CIImage ColorDodgeBlendMode ()
		{
			var colorDodgeBlend = new CIColorDodgeBlendMode ()
			{
				Image = heron,
				BackgroundImage = clouds,
			};
			
			return colorDodgeBlend.OutputImage;
		}
		
		/// <summary>
		/// Creates composite image samples by choosing the darker samples (from either the source image or the background).
		/// </summary>
		/// <returns>
		/// The composite Image
		/// </returns>
		[Filter]
		public CIImage DarkenBlendMode()
		{
			var darkenBlend = new CIDarkenBlendMode()
			{
				Image = heron,
				BackgroundImage = clouds
			};
			
			return darkenBlend.OutputImage;
{'fraction_non_alphanumeric': 0.13577976615249493, 'fraction_numerical': 0.016440687270132294, 'mean_word_length': 2.6135078845581674, 'pattern_counts': {'":': 0, '<': 211, '<?xml version=': 0, '>': 304, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7426301', 'n_tokens_mistral': 15046, 'n_tokens_neox': 11504, 'n_words': 3374}