public override void Render(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs, System.Drawing.Rectangle[] rois, int startIndex, int length) { TwoAmountsConfigToken tact = (TwoAmountsConfigToken)parameters; PixelOp redEyeRemove = new UnaryPixelOps.RedEyeRemove(tact.Amount1, tact.Amount2); redEyeRemove.Apply(dstArgs.Surface, srcArgs.Surface, rois, startIndex, length); }
public unsafe override void Render(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs, Rectangle[] rois, int startIndex, int length) { TwoAmountsConfigToken token = (TwoAmountsConfigToken)parameters; this.percentile = token.Amount2; foreach (Rectangle rect in rois) { RenderRect(token.Amount1, srcArgs.Surface, dstArgs.Surface, rect); } }
public override unsafe void Render(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs, Rectangle[] rois, int startIndex, int length) { TwoAmountsConfigToken tact = (TwoAmountsConfigToken)parameters; int dev = tact.Amount1 * tact.Amount1 / 64; //dev = target stddev / 16 int sat = tact.Amount2 * 4096 / 100; if (threadRand == null) { threadRand = new Random(unchecked (System.Threading.Thread.CurrentThread.GetHashCode() ^ unchecked ((int)DateTime.Now.Ticks))); } Random localRand = threadRand; int[] localLookup = lookup; for (int ri = startIndex; ri < startIndex + length; ++ri) { Rectangle rect = rois[ri]; for (int y = rect.Top; y < rect.Bottom; ++y) { ColorBgra *srcPtr = srcArgs.Surface.GetPointAddressUnchecked(rect.Left, y); ColorBgra *dstPtr = dstArgs.Surface.GetPointAddressUnchecked(rect.Left, y); for (int x = 0; x < rect.Width; ++x) { int r; int g; int b; int i; r = localLookup[localRand.Next(tableSize)]; g = localLookup[localRand.Next(tableSize)]; b = localLookup[localRand.Next(tableSize)]; i = (1867 * r + 9618 * g + 4899 * b) >> 14; r = i + (((r - i) * sat) >> 12); g = i + (((g - i) * sat) >> 12); b = i + (((b - i) * sat) >> 12); dstPtr->R = Utility.ClampToByte(srcPtr->R + ((r * dev * 16 + 32768) >> 16)); dstPtr->G = Utility.ClampToByte(srcPtr->G + ((g * dev * 16 + 32768) >> 16)); dstPtr->B = Utility.ClampToByte(srcPtr->B + ((b * dev * 16 + 32768) >> 16)); dstPtr->A = srcPtr->A; ++srcPtr; ++dstPtr; } } } }
public unsafe override void Render(EffectConfigToken properties, RenderArgs dstArgs, RenderArgs srcArgs, Rectangle[] rois, int startIndex, int length) { TwoAmountsConfigToken token = (TwoAmountsConfigToken)properties; int brushSize = token.Amount1; byte smoothness = (byte)token.Amount2; Surface src = srcArgs.Surface; Surface dst = dstArgs.Surface; int width = src.Width; int height = src.Height; int arrayLens = 1 + smoothness; int* intensityCount = stackalloc int[arrayLens]; uint* avgRed = stackalloc uint[arrayLens]; uint* avgGreen = stackalloc uint[arrayLens]; uint* avgBlue = stackalloc uint[arrayLens]; uint* avgAlpha = stackalloc uint[arrayLens]; byte maxIntensity = smoothness; for (int r = startIndex; r < startIndex + length; ++r) { Rectangle rect = rois[r]; int rectTop = rect.Top; int rectBottom = rect.Bottom; int rectLeft = rect.Left; int rectRight = rect.Right; for (int y = rectTop; y < rectBottom; ++y) { ColorBgra *dstPtr = dst.GetPointAddress(rect.Left, y); int top = y - brushSize; int bottom = y + brushSize + 1; if (top < 0) { top = 0; } if (bottom > height) { bottom = height; } for (int x = rectLeft; x < rectRight; ++x) { int left = x - brushSize; int right = x + brushSize + 1; if (left < 0) { left = 0; } if (right > width) { right = width; } for (int i = 0; i < arrayLens; ++i) { intensityCount[i] = 0; avgRed[i] = 0; avgGreen[i] = 0; avgBlue[i] = 0; avgAlpha[i] = 0; } int numInt = 0; for (int j = top; j < bottom; ++j) { ColorBgra *srcPtr = src.GetPointAddress(left, j); for (int i = left; i < right; ++i) { byte intensity = (byte)((srcPtr->GetIntensityByte() * maxIntensity) / 255); ++intensityCount[intensity]; ++numInt; avgRed[intensity] += srcPtr->R; avgGreen[intensity] += srcPtr->G; avgBlue[intensity] += srcPtr->B; avgAlpha[intensity] += srcPtr->A; ++srcPtr; } } byte chosenIntensity = 0; int maxInstance = 0; for (int i = 0; i <= maxIntensity; ++i) { if (intensityCount[i] > maxInstance) { chosenIntensity = (byte)i; maxInstance = intensityCount[i]; } } byte R = (byte)(avgRed[chosenIntensity] / maxInstance); byte G = (byte)(avgGreen[chosenIntensity] / maxInstance); byte B = (byte)(avgBlue[chosenIntensity] / maxInstance); byte A = (byte)(avgAlpha[chosenIntensity] / maxInstance); *dstPtr = ColorBgra.FromBgra(B, G, R, A); ++dstPtr; } } } }
protected override void InitialInitToken() { theEffectToken = new TwoAmountsConfigToken(Amount1Default, Amount2Default); }
public TwoAmountsConfigToken(TwoAmountsConfigToken copyMe) : base(copyMe) { this.amount1 = copyMe.amount1; this.amount2 = copyMe.amount2; }
public unsafe override void Render( EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs, System.Drawing.Rectangle[] rois, int startIndex, int length) { TwoAmountsConfigToken token = (TwoAmountsConfigToken)parameters; Surface dst = dstArgs.Surface; Surface src = srcArgs.Surface; float hw = dst.Width / 2.0f; float hh = dst.Height / 2.0f; float maxrad = Math.Min(hw, hh); float maxrad2 = maxrad * maxrad; float amt = token.Amount1 / 100.0f; int aaLevel = token.Amount2; int aaSamples = aaLevel * aaLevel + 1; PointF *aaPoints = stackalloc PointF[aaSamples]; for (int i = 0; i < aaSamples; ++i) { double x = (i * aaLevel) / (double)aaSamples; double y = i / (double)aaSamples; x -= (int)x; // RGSS + rotation to maximize AA quality aaPoints[i] = new PointF((float)x, (float)y); } for (int n = startIndex; n < startIndex + length; ++n) { Rectangle rect = rois[n]; for (int y = rect.Top; y < rect.Bottom; y++) { float j = y - hh; ColorBgra *dstPtr = dst.GetPointAddressUnchecked(rect.Left, y); for (int x = rect.Left; x < rect.Right; x++) { int b = 0, g = 0, r = 0, a = 0; float i = x - hw; for (int z = 0; z < aaSamples; ++z) { float u = i + aaPoints[z].X; float v = j - aaPoints[z].Y; float scale = Utility.Lerp(1, maxrad2 / (u * u + v * v), amt); float xp = u * scale; float yp = v * scale; ColorBgra sample = src.GetBilinearSampleWrapped(xp + hw, yp + hh); b += sample.B; g += sample.G; r += sample.R; a += sample.A; } *dstPtr = ColorBgra.FromBgra( (byte)(b / aaSamples), (byte)(g / aaSamples), (byte)(r / aaSamples), (byte)(a / aaSamples)); ++dstPtr; } } } }
public unsafe override void Render(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs, System.Drawing.Rectangle[] rois, int startIndex, int length) { TwoAmountsConfigToken token = (TwoAmountsConfigToken)parameters; float twist = token.Amount1; Surface dst = dstArgs.Surface; Surface src = srcArgs.Surface; float hw = dst.Width / 2.0f; float hh = dst.Height / 2.0f; float maxrad = Math.Min(hw, hh); twist = twist * twist * Math.Sign(twist); int aaLevel = token.Amount2; int aaSamples = aaLevel * aaLevel + 1; PointF *aaPoints = stackalloc PointF[aaSamples]; for (int i = 0; i < aaSamples; ++i) { PointF pt = new PointF( ((i * aaLevel) / (float)aaSamples), i / (float)aaSamples); pt.X -= (int)pt.X; aaPoints[i] = pt; } for (int n = startIndex; n < startIndex + length; ++n) { Rectangle rect = rois[n]; for (int y = rect.Top; y < rect.Bottom; y++) { float j = y - hh; ColorBgra *dstPtr = dst.GetPointAddressUnchecked(rect.Left, y); ColorBgra *srcPtr = src.GetPointAddressUnchecked(rect.Left, y); for (int x = rect.Left; x < rect.Right; x++) { float i = x - hw; if (i * i + j * j > (maxrad + 1) * (maxrad + 1)) { *dstPtr = *srcPtr; } else { int b = 0; int g = 0; int r = 0; int a = 0; for (int p = 0; p < aaSamples; ++p) { float u = i + aaPoints[p].X; float v = j + aaPoints[p].Y; double rad = Math.Sqrt(u * u + v * v); double theta = Math.Atan2(v, u); double t = 1 - rad / maxrad; t = (t < 0) ? 0 : (t * t * t); theta += (t * twist) / 100; ColorBgra sample = src.GetPointUnchecked( (int)(hw + (float)(rad * Math.Cos(theta))), (int)(hh + (float)(rad * Math.Sin(theta)))); b += sample.B; g += sample.G; r += sample.R; a += sample.A; } *dstPtr = ColorBgra.FromBgra( (byte)(b / aaSamples), (byte)(g / aaSamples), (byte)(r / aaSamples), (byte)(a / aaSamples)); } ++dstPtr; ++srcPtr; } } } }