本文整理汇总了C#中Surface.GetRowAddressUnchecked方法的典型用法代码示例。如果您正苦于以下问题:C# Surface.GetRowAddressUnchecked方法的具体用法?C# Surface.GetRowAddressUnchecked怎么用?C# Surface.GetRowAddressUnchecked使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Surface
的用法示例。
在下文中一共展示了Surface.GetRowAddressUnchecked方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FillStencilByColor
public static unsafe void FillStencilByColor(Surface surface, IBitVector2D stencil, ColorBgra cmp, int tolerance,
out Rectangle boundingBox, PdnRegion limitRegion, bool limitToSelection)
{
int top = int.MaxValue;
int bottom = int.MinValue;
int left = int.MaxValue;
int right = int.MinValue;
Rectangle[] scans;
stencil.Clear(false);
if (limitToSelection)
{
using (PdnRegion excluded = new PdnRegion(new Rectangle(0, 0, stencil.Width, stencil.Height)))
{
excluded.Xor(limitRegion);
scans = excluded.GetRegionScansReadOnlyInt();
}
}
else
{
scans = new Rectangle[0];
}
foreach (Rectangle rect in scans)
{
stencil.Set(rect, true);
}
for (int y = 0; y < surface.Height; ++y)
{
bool foundPixelInRow = false;
ColorBgra *ptr = surface.GetRowAddressUnchecked(y);
for (int x = 0; x < surface.Width; ++x)
{
if (CheckColor(cmp, *ptr, tolerance))
{
stencil.SetUnchecked(x, y, true);
if (x < left)
{
left = x;
}
if (x > right)
{
right = x;
}
foundPixelInRow = true;
}
++ptr;
}
if (foundPixelInRow)
{
if (y < top)
{
top = y;
}
if (y >= bottom)
{
bottom = y;
}
}
}
foreach (Rectangle rect in scans)
{
stencil.Set(rect, false);
}
boundingBox = Rectangle.FromLTRB(left, top, right + 1, bottom + 1);
}
示例2: FillStencilFromPoint
public static unsafe void FillStencilFromPoint(Surface surface, IBitVector2D stencil, Point start,
int tolerance, out Rectangle boundingBox, PdnRegion limitRegion, bool limitToSelection)
{
ColorBgra cmp = surface[start];
int top = int.MaxValue;
int bottom = int.MinValue;
int left = int.MaxValue;
int right = int.MinValue;
Rectangle[] scans;
stencil.Clear(false);
if (limitToSelection)
{
using (PdnRegion excluded = new PdnRegion(new Rectangle(0, 0, stencil.Width, stencil.Height)))
{
excluded.Xor(limitRegion);
scans = excluded.GetRegionScansReadOnlyInt();
}
}
else
{
scans = new Rectangle[0];
}
foreach (Rectangle rect in scans)
{
stencil.Set(rect, true);
}
Queue<Point> queue = new Queue<Point>(16);
queue.Enqueue(start);
while (queue.Count > 0)
{
Point pt = queue.Dequeue();
ColorBgra* rowPtr = surface.GetRowAddressUnchecked(pt.Y);
int localLeft = pt.X - 1;
int localRight = pt.X;
while (localLeft >= 0 &&
!stencil.GetUnchecked(localLeft, pt.Y) &&
CheckColor(cmp, rowPtr[localLeft], tolerance))
{
stencil.SetUnchecked(localLeft, pt.Y, true);
--localLeft;
}
while (localRight < surface.Width &&
!stencil.GetUnchecked(localRight, pt.Y) &&
CheckColor(cmp, rowPtr[localRight], tolerance))
{
stencil.SetUnchecked(localRight, pt.Y, true);
++localRight;
}
++localLeft;
--localRight;
if (pt.Y > 0)
{
int sleft = localLeft;
int sright = localLeft;
ColorBgra* rowPtrUp = surface.GetRowAddressUnchecked(pt.Y - 1);
for (int sx = localLeft; sx <= localRight; ++sx)
{
if (!stencil.GetUnchecked(sx, pt.Y - 1) &&
CheckColor(cmp, rowPtrUp[sx], tolerance))
{
++sright;
}
else
{
if (sright - sleft > 0)
{
queue.Enqueue(new Point(sleft, pt.Y - 1));
}
++sright;
sleft = sright;
}
}
if (sright - sleft > 0)
{
queue.Enqueue(new Point(sleft, pt.Y - 1));
}
}
if (pt.Y < surface.Height - 1)
{
int sleft = localLeft;
int sright = localLeft;
ColorBgra* rowPtrDown = surface.GetRowAddressUnchecked(pt.Y + 1);
for (int sx = localLeft; sx <= localRight; ++sx)
{
if (!stencil.GetUnchecked(sx, pt.Y + 1) &&
//.........这里部分代码省略.........
示例3: DrawACircle
private unsafe void DrawACircle(PointF pt, Surface srfSrc, Surface srfDst, Point difference, Rectangle rect)
{
float bw = AppEnvironment.PenInfo.Width / 2;
float envAlpha = AppEnvironment.PrimaryColor.A / 255.0f;
rect.Intersect(new Rectangle(difference, srfSrc.Size));
rect.Intersect(srfDst.Bounds);
if (rect.Width == 0 || rect.Height == 0)
{
return;
}
// envAlpha = envAlpha^4
envAlpha *= envAlpha;
envAlpha *= envAlpha;
for (int y = rect.Top; y < rect.Bottom; y++)
{
ColorBgra *srcRow = srfSrc.GetRowAddressUnchecked(y - difference.Y);
ColorBgra *dstRow = srfDst.GetRowAddressUnchecked(y);
for (int x = rect.Left; x < rect.Right; x++)
{
ColorBgra *srcPtr = unchecked(srcRow + x - difference.X);
ColorBgra *dstPtr = unchecked(dstRow + x);
float distFromRing = 0.5f + bw - Utility.Distance(pt, new PointF(x, y));
if (distFromRing > 0)
{
float alpha = antialiasing ? Utility.Clamp(distFromRing * envAlpha, 0, 1) : 1;
alpha *= srcPtr->A / 255.0f;
dstPtr->A = (byte)(255 - (255 - dstPtr->A) * (1 - alpha));
if (0 == (alpha + (1 - alpha) * dstPtr->A / 255))
{
dstPtr->Bgra = 0;
}
else
{
dstPtr->R = (byte)((srcPtr->R * alpha + dstPtr->R * (1 - alpha) * dstPtr->A / 255) / (alpha + (1 - alpha) * dstPtr->A / 255));
dstPtr->G = (byte)((srcPtr->G * alpha + dstPtr->G * (1 - alpha) * dstPtr->A / 255) / (alpha + (1 - alpha) * dstPtr->A / 255));
dstPtr->B = (byte)((srcPtr->B * alpha + dstPtr->B * (1 - alpha) * dstPtr->A / 255) / (alpha + (1 - alpha) * dstPtr->A / 255));
}
}
}
}
rect.Inflate(1, 1);
Document.Invalidate(rect);
}
示例4: 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;
}
//.........这里部分代码省略.........
示例5: OnSaveT
protected unsafe override void OnSaveT(Document input, Stream output, PropertyBasedSaveConfigToken token, Surface scratchSurface, ProgressEventHandler progressCallback)
{
using (RenderArgs ra = new RenderArgs(scratchSurface)) {
input.Render(ra, true);
}
int w = token.GetProperty<Int32Property>(PropertyNames.HorizCellSize).Value;
int h = token.GetProperty<Int32Property>(PropertyNames.VerticalCellSize).Value;
int W = scratchSurface.Width, H = scratchSurface.Height;
string chars;
PresetCharacters preset = (PresetCharacters)token.GetProperty<StaticListChoiceProperty>(PropertyNames.PresetCharacters).Value;
switch (preset) {
case PresetCharacters.Custom:
chars = token.GetProperty<StringProperty>(PropertyNames.Characters).Value;
break;
case PresetCharacters.AsciiChars:
chars = asciiChars;
break;
case PresetCharacters.Blocks:
chars = blocks;
break;
default:
chars = "";
break;
}
if (chars.Length == 0) {
chars = asciiChars;
}
// Special case where 1 cell corresponds directly to 1 pixel
// Written separately for performance
if (h == 1 && w == 1) {
StreamWriter writer = new StreamWriter(output);
for (int y = 0; y < H; y++) {
ColorBgra* current = scratchSurface.GetRowAddressUnchecked(y);
for (int x = 0; x < W; x++) {
int pos = (int)((1 - current->GetIntensity()) * chars.Length);
char c = chars[pos == chars.Length ? pos - 1 : pos];
writer.Write(c);
current++;
}
if (y != H - 1) {
writer.WriteLine();
}
}
writer.Flush();
} else {
double[,] totals = new double[W / w, H / h];
for (int y = 0; y < H / h * h; y++) {
ColorBgra* current = scratchSurface.GetRowAddressUnchecked(y);
for (int x = 0; x < W / w * w; x++) {
totals[x / w, y / h] += 1 - current->GetIntensity();
current++;
}
}
int ppc = w * h;
StreamWriter writer = new StreamWriter(output);
for (int y = 0; y < H / h; y++) {
for (int x = 0; x < W / w; x++) {
int pos = (int)(totals[x, y] / ppc * chars.Length);
char c = chars[pos == chars.Length ? pos - 1 : pos];
writer.Write(c);
}
if (y != H / h - 1) {
writer.WriteLine();
}
}
writer.Flush();
}
}