/// <summary> /// Returns a copy of the image frame in the given pixel format. /// </summary> /// <param name="scaleFunc">A function that allows for the correction of vector scaling between unknown color formats.</param> /// <typeparam name="TColor2">The pixel format.</typeparam> /// <typeparam name="TPacked2">The packed format. <example>uint, long, float.</example></typeparam> /// <returns>The <see cref="ImageFrame{TColor2, TPacked2}"/></returns> public ImageFrame <TColor2, TPacked2> To <TColor2, TPacked2>(Func <Vector4, Vector4> scaleFunc = null) where TColor2 : struct, IPackedPixel <TPacked2> where TPacked2 : struct, IEquatable <TPacked2> { scaleFunc = PackedPixelConverterHelper.ComputeScaleFunction <TColor, TColor2>(scaleFunc); ImageFrame <TColor2, TPacked2> target = new ImageFrame <TColor2, TPacked2> { Quality = this.Quality, FrameDelay = this.FrameDelay }; target.InitPixels(this.Width, this.Height); using (PixelAccessor <TColor, TPacked> pixels = this.Lock()) using (PixelAccessor <TColor2, TPacked2> targetPixels = target.Lock()) { Parallel.For( 0, target.Height, Bootstrapper.Instance.ParallelOptions, y => { for (int x = 0; x < target.Width; x++) { TColor2 color = default(TColor2); color.PackFromVector4(scaleFunc(pixels[x, y].ToVector4())); targetPixels[x, y] = color; } }); } return(target); }
/// <summary> /// Returns a copy of the image in the given pixel format. /// </summary> /// <param name="scaleFunc">A function that allows for the correction of vector scaling between unknown color formats.</param> /// <typeparam name="TColor2">The pixel format.</typeparam> /// <returns>The <see cref="Image{TColor2}"/></returns> public Image <TColor2> To <TColor2>(Func <Vector4, Vector4> scaleFunc = null) where TColor2 : struct, IPixel <TColor2> { scaleFunc = PackedPixelConverterHelper.ComputeScaleFunction <TColor, TColor2>(scaleFunc); Image <TColor2> target = new Image <TColor2>(this.Width, this.Height, this.Configuration); target.CopyProperties(this); using (PixelAccessor <TColor> pixels = this.Lock()) using (PixelAccessor <TColor2> targetPixels = target.Lock()) { Parallel.For( 0, target.Height, this.Configuration.ParallelOptions, y => { for (int x = 0; x < target.Width; x++) { TColor2 color = default(TColor2); color.PackFromVector4(scaleFunc(pixels[x, y].ToVector4())); targetPixels[x, y] = color; } }); } for (int i = 0; i < this.Frames.Count; i++) { target.Frames.Add(this.Frames[i].To <TColor2>()); } return(target); }
/// <summary> /// Returns a copy of the image in the given pixel format. /// </summary> /// <param name="scaleFunc">A function that allows for the correction of vector scaling between unknown color formats.</param> /// <typeparam name="TColor2">The pixel format.</typeparam> /// <typeparam name="TPacked2">The packed format. <example>uint, long, float.</example></typeparam> /// <returns>The <see cref="Image{TColor2, TPacked2}"/></returns> public Image <TColor2, TPacked2> To <TColor2, TPacked2>(Func <Vector4, Vector4> scaleFunc = null) where TColor2 : struct, IPackedPixel <TPacked2> where TPacked2 : struct, IEquatable <TPacked2> { scaleFunc = PackedPixelConverterHelper.ComputeScaleFunction <TColor, TColor2>(scaleFunc); Image <TColor2, TPacked2> target = new Image <TColor2, TPacked2>(this.Width, this.Height) { Quality = this.Quality, FrameDelay = this.FrameDelay, HorizontalResolution = this.HorizontalResolution, VerticalResolution = this.VerticalResolution, CurrentImageFormat = this.CurrentImageFormat, RepeatCount = this.RepeatCount }; using (PixelAccessor <TColor, TPacked> pixels = this.Lock()) using (PixelAccessor <TColor2, TPacked2> targetPixels = target.Lock()) { Parallel.For( 0, target.Height, Bootstrapper.Instance.ParallelOptions, y => { for (int x = 0; x < target.Width; x++) { TColor2 color = default(TColor2); color.PackFromVector4(scaleFunc(pixels[x, y].ToVector4())); targetPixels[x, y] = color; } }); } if (this.ExifProfile != null) { target.ExifProfile = new ExifProfile(this.ExifProfile); } foreach (ImageFrame <TColor, TPacked> frame in this.Frames) { target.Frames.Add(frame.To <TColor2, TPacked2>()); } return(target); }