public cImage ApplyXbrz(int scale) { var result = new cImage(this.Width * scale, this.Height * scale); switch (scale) { case 2: libXBRz.ScaleImage(libXBRz.ScaleSize.TIMES2, this.GetImageData(), result.GetImageData(), Width, Height, 0, 0, Width, Height); break; case 3: libXBRz.ScaleImage(libXBRz.ScaleSize.TIMES3, this.GetImageData(), result.GetImageData(), Width, Height, 0, 0, Width, Height); break; case 4: libXBRz.ScaleImage(libXBRz.ScaleSize.TIMES4, this.GetImageData(), result.GetImageData(), Width, Height, 0, 0, Width, Height); break; case 5: libXBRz.ScaleImage(libXBRz.ScaleSize.TIMES5, this.GetImageData(), result.GetImageData(), Width, Height, 0, 0, Width, Height); break; default: break; } return(result); }
/// <summary> /// Applies the XBR pixel scaler. /// </summary> /// <param name="type">The type of scaler to use.</param> /// <param name="filterRegion">The filter region, if any.</param> /// <returns> /// The rescaled image. /// </returns> public cImage ApplyScaler(XbrzScalerType type, Rectangle? filterRegion = null) { var info = GetPixelScalerInfo(type); var scaleX = info.Item1; var scaleY = info.Item2; var scaler = info.Item3; if (filterRegion == null) filterRegion = new Rectangle(0, 0, this.Width, this.Height); var result = new cImage(this.Width * scaleX, this.Height * scaleY); // TODO: generic pixel loop scaler(this.GetImageData(), result.GetImageData(), this.Width, this.Height, filterRegion.Value.Left, filterRegion.Value.Top, filterRegion.Value.Right, filterRegion.Value.Bottom); return (result); }
/// <summary> /// Applies the XBR pixel scaler. /// </summary> /// <param name="type">The type of scaler to use.</param> /// <param name="filterRegion">The filter region, if any.</param> /// <returns> /// The rescaled image. /// </returns> public cImage ApplyScaler(XbrzScalerType type, Rectangle?filterRegion = null) { var info = GetPixelScalerInfo(type); var scaleX = info.Item1; var scaleY = info.Item2; var scaler = info.Item3; if (filterRegion == null) { filterRegion = new Rectangle(0, 0, this.Width, this.Height); } var result = new cImage(this.Width * scaleX, this.Height * scaleY); // TODO: generic pixel loop scaler(this.GetImageData(), result.GetImageData(), this.Width, this.Height, filterRegion.Value.Left, filterRegion.Value.Top, filterRegion.Value.Right, filterRegion.Value.Bottom); return(result); }
private cImage _RunLoop(Rectangle?filterRegion, byte scaleX, byte scaleY, Action <PixelWorker <sPixel> > scaler) { var startX = filterRegion == null ? 0 : Math.Max(0, filterRegion.Value.Left); var startY = filterRegion == null ? 0 : Math.Max(0, filterRegion.Value.Top); var endX = filterRegion == null ? this.Width : Math.Min(this.Width, filterRegion.Value.Right); var endY = filterRegion == null ? this.Height : Math.Min(this.Height, filterRegion.Value.Bottom); var width = endX - startX; var result = new cImage(width * scaleX, (endY - startY) * scaleY); Parallel.ForEach( Partitioner.Create(startY, endY), () => 0, (range, _, threadStorage) => { var threadSrcMinY = range.Item1; var threadSrcMaxY = range.Item2; var targetY = (threadSrcMinY - startY) * scaleY; for (var sourceY = threadSrcMinY; sourceY < threadSrcMaxY; ++sourceY) { var worker = new PixelWorker <sPixel>( i => this.GetImageData()[i], startX, sourceY, this._width, this._height, this._width, this._horizontalOutOfBoundsHandler, this._verticalOutOfBoundsHandler, (i, c) => result.GetImageData()[i] = c, 0, targetY, result._width ); var xRange = width; while (xRange >= 64) { xRange -= 64; scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); } for (; xRange > 0; --xRange) { scaler(worker); worker.IncrementX(scaleX); } targetY += scaleY; } return(threadStorage); }, _ => { } ); return(result); }
private cImage _RunLoop(Rectangle? filterRegion, byte scaleX, byte scaleY, Action<PixelWorker<sPixel>> scaler) { var startX = filterRegion == null ? 0 : Math.Max(0, filterRegion.Value.Left); var startY = filterRegion == null ? 0 : Math.Max(0, filterRegion.Value.Top); var endX = filterRegion == null ? this.Width : Math.Min(this.Width, filterRegion.Value.Right); var endY = filterRegion == null ? this.Height : Math.Min(this.Height, filterRegion.Value.Bottom); var width = endX - startX; var result = new cImage(width * scaleX, (endY - startY) * scaleY); Parallel.ForEach( Partitioner.Create(startY, endY), () => 0, (range, _, threadStorage) => { var threadSrcMinY = range.Item1; var threadSrcMaxY = range.Item2; var targetY = (threadSrcMinY - startY) * scaleY; for (var sourceY = threadSrcMinY; sourceY < threadSrcMaxY;++sourceY) { var worker=new PixelWorker<sPixel>( this.GetImageData(), startX, sourceY, this._width, this._height, this._horizontalOutOfBoundsHandler, this._verticalOutOfBoundsHandler, result.GetImageData(), 0, targetY, result._width ); var xRange=width; while(xRange>=64){ xRange-=64; scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); scaler(worker); worker.IncrementX(scaleX); } for (; xRange>0;--xRange) { scaler(worker); worker.IncrementX(scaleX); } targetY += scaleY; } return (threadStorage); }, _ => { } ); return(result); }