private static BitmapEx resize(Bitmap bitmap, int width, int height, Rectangle? clipRectangle) { using (var src = Surface.CopyFromBitmap(bitmap)) { var dest = new Surface(width, height); BitmapEx res = new BitmapEx(); res.surface = dest; dest.FitSurface(ResamplingAlgorithm.SuperSampling, src); if (clipRectangle == null) res.Bitmap = dest.CreateAliasedBitmap(); else res.Bitmap = dest.CreateAliasedBitmap(clipRectangle.Value); return res; } }
protected override void OnSetRenderInfo(PropertyBasedEffectConfigToken newToken, RenderArgs dstArgs, RenderArgs srcArgs) { Rectangle selection = EnvironmentParameters.GetSelection(srcArgs.Surface.Bounds).GetBoundsInt(); Surface selectionSurface = new Surface(selection.Width, selection.Height); selectionSurface.CopySurface(srcArgs.Surface, selection); Surface stretchedSurface = new Surface(selection.Width * 2, selection.Height); stretchedSurface.FitSurface(ResamplingAlgorithm.Bicubic, selectionSurface); processedSurface = new Surface(srcArgs.Surface.Size); ColorBgra t; for (int y = 0; y < stretchedSurface.Height; y++) { if (IsCancelRequested) return; int v = selection.Left; for (int x = 0; x < stretchedSurface.Width; x += 2) { if (x % 2 == 0) { t.R = stretchedSurface[x, y].R; t.G = stretchedSurface[x + 1, y].G; if (x != stretchedSurface.Width - 2) { t.B = stretchedSurface[x + 2, y].B; } else { t.B = (byte)((stretchedSurface[stretchedSurface.Width - 1, y].B + stretchedSurface[stretchedSurface.Width - 2, y].B) >> 1); } processedSurface[v, y + selection.Top] = ColorBgra.FromBgr(t.B, t.G, t.R); v++; } } } base.OnSetRenderInfo(newToken, dstArgs, srcArgs); }