本文整理汇总了C#中Surface.GetPointAddressUnchecked方法的典型用法代码示例。如果您正苦于以下问题:C# Surface.GetPointAddressUnchecked方法的具体用法?C# Surface.GetPointAddressUnchecked怎么用?C# Surface.GetPointAddressUnchecked使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Surface
的用法示例。
在下文中一共展示了Surface.GetPointAddressUnchecked方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RenderRect
public unsafe void RenderRect(
int rad,
Surface src,
Surface dst,
Rectangle rect)
{
int width = src.Width;
int height = src.Height;
int* leadingEdgeX = stackalloc int[rad + 1];
int stride = src.Stride / sizeof(ColorBgra);
// approximately (rad + 0.5)^2
int cutoff = ((rad * 2 + 1) * (rad * 2 + 1) + 2) / 4;
for (int v = 0; v <= rad; ++v)
{
for (int u = 0; u <= rad; ++u)
{
if (u * u + v * v <= cutoff)
{
leadingEdgeX[v] = u;
}
}
}
for (int y = rect.Top; y < rect.Bottom; y++)
{
int* hb = stackalloc int[256];
int* hg = stackalloc int[256];
int* hr = stackalloc int[256];
int* ha = stackalloc int[256];
int area = 0;
ColorBgra* ps = src.GetPointAddressUnchecked(rect.Left, y);
ColorBgra* pd = dst.GetPointAddressUnchecked(rect.Left, y);
// assert: v + y >= 0
int top = -Math.Min(rad, y);
// assert: v + y <= height - 1
int bottom = Math.Min(rad, height - 1 - y);
// assert: u + x >= 0
int left = -Math.Min(rad, rect.Left);
// assert: u + x <= width - 1
int right = Math.Min(rad, width - 1 - rect.Left);
for (int v = top; v <= bottom; ++v)
{
ColorBgra* psamp = src.GetPointAddressUnchecked(rect.Left + left, y + v);
for (int u = left; u <= right; ++u)
{
if ((u * u + v * v) <= cutoff)
{
++area;
++hb[psamp->B];
++hg[psamp->G];
++hr[psamp->R];
++ha[psamp->A];
}
++psamp;
}
}
for (int x = rect.Left; x < rect.Right; x++)
{
*pd = Apply(*ps, area, hb, hg, hr, ha);
// assert: u + x >= 0
left = -Math.Min(rad, x);
// assert: u + x <= width - 1
right = Math.Min(rad + 1, width - 1 - x);
// Subtract trailing edge top half
int v = -1;
while (v >= top)
{
int u = leadingEdgeX[-v];
if (-u >= left)
{
break;
}
--v;
}
while (v >= top)
{
int u = leadingEdgeX[-v];
ColorBgra* p = unchecked(ps + (v * stride)) - u;
--hb[p->B];
--hg[p->G];
//.........这里部分代码省略.........
示例2: RenderClouds
private unsafe void RenderClouds(Surface surface, Rectangle rect)
{
ColorBgra colorFrom = EnvironmentParameters.PrimaryColor;
ColorBgra colorTo = EnvironmentParameters.SecondaryColor;
int w = surface.Width;
int h = surface.Height;
for (int y = rect.Top; y < rect.Bottom; ++y)
{
ColorBgra* ptr = surface.GetPointAddressUnchecked(rect.Left, y);
int dy = 2 * y - h;
for (int x = rect.Left; x < rect.Right; ++x)
{
int dx = 2 * x - w;
double val = 0;
double mult = 1;
int div = this.scale;
for (int i = 0; i < 12 && mult > 0.03 && div > 0; ++i)
{
double dxr = 65536 + (double)dx / (double)div;
double dyr = 65536 + (double)dy / (double)div;
int dxd = (int)dxr;
int dyd = (int)dyr;
dxr -= dxd;
dyr -= dyd;
double noise = Noise(
unchecked((byte)dxd),
unchecked((byte)dyd),
dxr, //(double)dxr / div,
dyr, //(double)dyr / div,
(byte)(seed ^ i));
val += noise * mult;
div /= 2;
mult *= this.power;
}
*ptr = ColorBgra.Lerp(colorFrom, colorTo, (val + 1) / 2);
++ptr;
}
}
}
示例3: DrawText
private unsafe void DrawText(Surface dst, Font textFont, string text, Point pt, Size measuredSize, bool antiAliasing, Surface brush8x8)
{
Point pt2 = pt;
Size measuredSize2 = measuredSize;
int offset = (int)textFont.Height;
pt.X -= offset;
measuredSize.Width += 2 * offset;
Rectangle dstRect = new Rectangle(pt, measuredSize);
Rectangle dstRectClipped = Rectangle.Intersect(dstRect, ScratchSurface.Bounds);
if (dstRectClipped.Width == 0 || dstRectClipped.Height == 0)
{
return;
}
// We only use the first 8,8 of brush
using (RenderArgs renderArgs = new RenderArgs(this.ScratchSurface))
{
renderArgs.Graphics.FillRectangle(Brushes.White, pt.X, pt.Y, measuredSize.Width, measuredSize.Height);
if (measuredSize.Width > 0 && measuredSize.Height > 0)
{
using (Surface s2 = renderArgs.Surface.CreateWindow(dstRectClipped))
{
using (RenderArgs renderArgs2 = new RenderArgs(s2))
{
SystemLayer.Fonts.DrawText(
renderArgs2.Graphics,
this.font,
text,
new Point(dstRect.X - dstRectClipped.X + offset, dstRect.Y - dstRectClipped.Y),
AppEnvironment.AntiAliasing,
AppEnvironment.FontSmoothing);
}
}
}
// Mask out anything that isn't within the user's clip region (selected region)
using (PdnRegion clip = Selection.CreateRegion())
{
clip.Xor(renderArgs.Surface.Bounds); // invert
clip.Intersect(new Rectangle(pt, measuredSize));
renderArgs.Graphics.FillRegion(Brushes.White, clip.GetRegionReadOnly());
}
int skipX;
if (pt.X < 0)
{
skipX = -pt.X;
}
else
{
skipX = 0;
}
int xEnd = Math.Min(dst.Width, pt.X + measuredSize.Width);
bool blending = AppEnvironment.AlphaBlending;
if (dst.IsColumnVisible(pt.X + skipX))
{
for (int y = pt.Y; y < pt.Y + measuredSize.Height; ++y)
{
if (!dst.IsRowVisible(y))
{
continue;
}
ColorBgra *dstPtr = dst.GetPointAddressUnchecked(pt.X + skipX, y);
ColorBgra *srcPtr = ScratchSurface.GetPointAddress(pt.X + skipX, y);
ColorBgra *brushPtr = brush8x8.GetRowAddressUnchecked(y & 7);
for (int x = pt.X + skipX; x < xEnd; ++x)
{
ColorBgra srcPixel = *srcPtr;
ColorBgra dstPixel = *dstPtr;
ColorBgra brushPixel = brushPtr[x & 7];
int alpha = ((255 - srcPixel.R) * brushPixel.A) / 255; // we could use srcPixel.R, .G, or .B -- the choice here is arbitrary
brushPixel.A = (byte)alpha;
if (srcPtr->R == 255) // could use R, G, or B -- arbitrary choice
{
// do nothing -- leave dst alone
}
else if (alpha == 255 || !blending)
{
// copy it straight over
*dstPtr = brushPixel;
}
else
{
// do expensive blending
*dstPtr = UserBlendOps.NormalBlendOp.ApplyStatic(dstPixel, brushPixel);
}
++dstPtr;
++srcPtr;
}
//.........这里部分代码省略.........
示例4: LoadOrSaveSurfaceRegion
private static unsafe void LoadOrSaveSurfaceRegion(FileStream fileHandle, Surface surface, PdnRegion region, bool trueForSave)
{
Rectangle[] scans = region.GetRegionScansReadOnlyInt();
Rectangle regionBounds = region.GetBoundsInt();
Rectangle surfaceBounds = surface.Bounds;
int scanCount = 0;
void*[] ppvBuffers;
uint[] lengths;
regionBounds.Intersect(surfaceBounds);
long length = (long)regionBounds.Width * (long)regionBounds.Height * (long)ColorBgra.SizeOf;
if (scans.Length == 1 &&
length <= uint.MaxValue &&
surface.IsContiguousMemoryRegion(regionBounds))
{
ppvBuffers = new void*[1];
lengths = new uint[1];
ppvBuffers[0] = surface.GetPointAddressUnchecked(regionBounds.Location);
lengths[0] = (uint)length;
}
else
{
for (int i = 0; i < scans.Length; ++i)
{
Rectangle rect = scans[i];
rect.Intersect(surfaceBounds);
if (rect.Width != 0 && rect.Height != 0)
{
scanCount += rect.Height;
}
}
int scanIndex = 0;
ppvBuffers = new void*[scanCount];
lengths = new uint[scanCount];
for (int i = 0; i < scans.Length; ++i)
{
Rectangle rect = scans[i];
rect.Intersect(surfaceBounds);
if (rect.Width != 0 && rect.Height != 0)
{
for (int y = rect.Top; y < rect.Bottom; ++y)
{
ppvBuffers[scanIndex] = surface.GetPointAddressUnchecked(rect.Left, y);
lengths[scanIndex] = (uint)(rect.Width * ColorBgra.SizeOf);
++scanIndex;
}
}
}
}
if (trueForSave)
{
FileSystem.WriteToStreamingFileGather(fileHandle, ppvBuffers, lengths);
}
else
{
FileSystem.ReadFromStreamScatter(fileHandle, ppvBuffers, lengths);
}
}
示例5: RenderRectWithAlpha
//same as RenderRect, except the histogram is alpha-weighted instead of keeping a separate alpha channel histogram.
public unsafe void RenderRectWithAlpha(
int rad,
Surface src,
Surface dst,
Rectangle rect)
{
int width = src.Width;
int height = src.Height;
int* leadingEdgeX = stackalloc int[rad + 1];
int stride = src.Stride / sizeof(ColorBgra);
// approximately (rad + 0.5)^2
int cutoff = ((rad * 2 + 1) * (rad * 2 + 1) + 2) / 4;
for (int v = 0; v <= rad; ++v)
{
for (int u = 0; u <= rad; ++u)
{
if (u * u + v * v <= cutoff)
{
leadingEdgeX[v] = u;
}
}
}
const int hLength = 256;
int* hb = stackalloc int[hLength];
int* hg = stackalloc int[hLength];
int* hr = stackalloc int[hLength];
uint hSize = (uint)(sizeof(int) * hLength);
for (int y = rect.Top; y < rect.Bottom; y++)
{
Memory.SetToZero(hb, hSize);
Memory.SetToZero(hg, hSize);
Memory.SetToZero(hr, hSize);
int area = 0;
int sum = 0;
ColorBgra* ps = src.GetPointAddressUnchecked(rect.Left, y);
ColorBgra* pd = dst.GetPointAddressUnchecked(rect.Left, y);
// assert: v + y >= 0
int top = -Math.Min(rad, y);
// assert: v + y <= height - 1
int bottom = Math.Min(rad, height - 1 - y);
// assert: u + x >= 0
int left = -Math.Min(rad, rect.Left);
// assert: u + x <= width - 1
int right = Math.Min(rad, width - 1 - rect.Left);
for (int v = top; v <= bottom; ++v)
{
ColorBgra* psamp = src.GetPointAddressUnchecked(rect.Left + left, y + v);
for (int u = left; u <= right; ++u)
{
byte w = psamp->A;
if ((u * u + v * v) <= cutoff)
{
++area;
sum += w;
hb[psamp->B] += w;
hg[psamp->G] += w;
hr[psamp->R] += w;
}
++psamp;
}
}
for (int x = rect.Left; x < rect.Right; x++)
{
*pd = ApplyWithAlpha(*ps, area, sum, hb, hg, hr);
// assert: u + x >= 0
left = -Math.Min(rad, x);
// assert: u + x <= width - 1
right = Math.Min(rad + 1, width - 1 - x);
// Subtract trailing edge top half
int v = -1;
while (v >= top)
{
int u = leadingEdgeX[-v];
if (-u >= left)
{
break;
}
--v;
//.........这里部分代码省略.........