本文整理汇总了C#中ISurface.GetRowAddress方法的典型用法代码示例。如果您正苦于以下问题:C# ISurface.GetRowAddress方法的具体用法?C# ISurface.GetRowAddress怎么用?C# ISurface.GetRowAddress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISurface
的用法示例。
在下文中一共展示了ISurface.GetRowAddress方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
public static unsafe SurfaceDiff Create (ISurface original, ISurface updated_surf, bool force = false)
{
if (original.Width != updated_surf.Width || original.Height != updated_surf.Height) {
// If the surface changed size, only throw an error if the user forced the use of a diff.
if (force) {
throw new InvalidOperationException ("SurfaceDiff requires surfaces to be same size.");
} else {
return null;
}
}
// Cache some pinvokes
var orig_width = original.Width;
var orig_height = original.Height;
#if DEBUG_DIFF
Console.WriteLine ("Original surface size: {0}x{1}", orig_width, orig_height);
System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
timer.Start();
#endif
// STEP 1 - Find the bounds of the changed pixels.
var orig_ptr = (int*)original.GetRowAddress (0);
var updated_ptr = (int*)updated_surf.GetRowAddress (0);
DiffBounds diff_bounds = new DiffBounds (orig_width, orig_height);
object diff_bounds_lock = new Object();
// Split up the work among several threads, each of which processes one row at a time
// and updates the bounds of the changed pixels it has seen so far. At the end, the
// results from each thread are merged together to find the overall bounds of the changed
// pixels.
Parallel.For<DiffBounds>(0, orig_height, () => new DiffBounds (orig_width, orig_height),
(row, loop, my_bounds) => {
var offset = row * orig_width;
var orig = orig_ptr + offset;
var updated = updated_ptr + offset;
bool change_in_row = false;
for (int i = 0; i < orig_width; ++i) {
if (*(orig++) != *(updated++)) {
change_in_row = true;
my_bounds.left = System.Math.Min(my_bounds.left, i);
my_bounds.right = System.Math.Max(my_bounds.right, i);
}
}
if (change_in_row) {
my_bounds.top = System.Math.Min(my_bounds.top, row);
my_bounds.bottom = System.Math.Max(my_bounds.bottom, row);
}
return my_bounds;
}, (my_bounds) => {
lock (diff_bounds_lock) {
diff_bounds.Merge (my_bounds);
}
return;
});
var bounds = new Rectangle (diff_bounds.left, diff_bounds.top,
diff_bounds.right - diff_bounds.left + 1,
diff_bounds.bottom - diff_bounds.top + 1);
#if DEBUG_DIFF
Console.WriteLine ("Truncated surface size: {0}x{1}", bounds.Width, bounds.Height);
#endif
// STEP 2 - Create a bitarray of whether each pixel in the bounds has changed, and count
// how many changed pixels we need to store.
var bitmask = new BitArray (bounds.Width * bounds.Height);
int index = 0;
int num_changed = 0;
int bottom = bounds.Bottom;
int right = bounds.Right;
int bounds_x = bounds.X;
int bounds_y = bounds.Y;
for (int y = bounds_y; y <= bottom; ++y) {
var offset = y * orig_width;
var updated = updated_ptr + offset + bounds_x;
var orig = orig_ptr + offset + bounds_x;
for (int x = bounds_x; x <= right; ++x) {
bool changed = *(orig++) != *(updated++);
bitmask[index++] = changed;
if (changed) {
num_changed++;
}
}
}
var savings = 100 - (float)num_changed / (float)(orig_width * orig_height) * 100;
#if DEBUG_DIFF
Console.WriteLine ("Compressed bitmask: {0}/{1} = {2}%", num_changed, orig_height * orig_width, 100 - savings);
#endif
//.........这里部分代码省略.........
示例2: ApplyAndSwap
private unsafe void ApplyAndSwap (ISurface dst, bool swap)
{
dst.BeginUpdate ();
var dest_width = dst.Width;
var dst_ptr = (ColorBgra*)dst.GetRowAddress (0);
var mask_index = 0;
ColorBgra swap_pixel;
fixed (ColorBgra* fixed_ptr = pixels) {
var pixel_ptr = fixed_ptr;
dst_ptr += bounds.X + bounds.Y * dest_width;
for (int y = bounds.Y; y <= bounds.Bottom; y++) {
for (int x = bounds.X; x <= bounds.Right; x++) {
if (bitmask[mask_index++])
if (swap) {
swap_pixel = *dst_ptr;
*dst_ptr = *pixel_ptr;
*pixel_ptr++ = swap_pixel;
} else {
*dst_ptr = *pixel_ptr++;
}
dst_ptr++;
}
dst_ptr += dest_width - bounds.Width;
}
}
dst.EndUpdate ();
}
示例3: ApplyLoop
protected void ApplyLoop (ISurface lhs, ISurface rhs, ISurface dst, Rectangle roi, CancellationToken token, IRenderProgress progress)
{
var completed_lines = new bool[roi.Height];
var last_completed_index = 0;
if (Settings.SingleThreaded || roi.Height <= 1) {
for (var y = roi.Y; y <= roi.Bottom; ++y) {
if (token.IsCancellationRequested)
return;
var dstPtr = dst.GetRowAddress (y);
var lhsPtr = lhs.GetRowAddress (y);
var rhsPtr = rhs.GetRowAddress (y);
Apply (lhsPtr, rhsPtr, dstPtr, roi.Width);
completed_lines[y - roi.Top] = true;
if (progress != null) {
var last_y = FindLastCompletedLine (completed_lines, last_completed_index);
last_completed_index = last_y;
progress.CompletedRoi = new Rectangle (roi.X, roi.Y, roi.Width, last_y);
progress.PercentComplete = (float)last_y / (float)roi.Height;
}
}
} else {
ParallelExtensions.OrderedFor (roi.Y, roi.Bottom + 1, token, (y) => {
var dstPtr = dst.GetRowAddress (y);
var lhsPtr = lhs.GetRowAddress (y);
var rhsPtr = rhs.GetRowAddress (y);
Apply (lhsPtr, rhsPtr, dstPtr, roi.Width);
completed_lines[y - roi.Top] = true;
if (progress != null) {
var last_y = FindLastCompletedLine (completed_lines, last_completed_index);
last_completed_index = last_y;
progress.CompletedRoi = new Rectangle (roi.X, roi.Y, roi.Width, last_y);
progress.PercentComplete = (float)last_y / (float)roi.Height;
}
});
}
}
示例4: GetBilinearSampleWrapped
public static unsafe ColorBgra GetBilinearSampleWrapped (ISurface src, float x, float y)
{
return GetBilinearSampleWrapped (src, (ColorBgra*)src.GetRowAddress (0), src.Width, src.Height, x, y);
}
示例5: RenderLine
protected unsafe override void RenderLine (ISurface src, ISurface dest, Rectangle roi)
{
// Glow backgound
glow_effect.Render (src, dest, roi);
// Create black outlines by finding the edges of objects
for (int y = roi.Top; y <= roi.Bottom; ++y) {
int top = y - radius;
int bottom = y + radius + 1;
if (top < 0) {
top = 0;
}
if (bottom > dest.Height) {
bottom = dest.Height;
}
ColorBgra* srcPtr = src.GetPointAddress (roi.X, y);
ColorBgra* dstPtr = dest.GetPointAddress (roi.X, y);
for (int x = roi.Left; x <= roi.Right; ++x) {
int left = x - radius;
int right = x + radius + 1;
if (left < 0) {
left = 0;
}
if (right > dest.Width) {
right = dest.Width;
}
int r = 0;
int g = 0;
int b = 0;
for (int v = top; v < bottom; v++) {
ColorBgra* pRow = src.GetRowAddress (v);
int j = v - y + radius;
for (int u = left; u < right; u++) {
int i1 = u - x + radius;
int w = conv[j][i1];
ColorBgra* pRef = pRow + u;
r += pRef->R * w;
g += pRef->G * w;
b += pRef->B * w;
}
}
ColorBgra topLayer = ColorBgra.FromBgr (
Utility.ClampToByte (b),
Utility.ClampToByte (g),
Utility.ClampToByte (r));
// Desaturate
topLayer = this.desaturate_op.Apply (topLayer);
// Adjust Brightness and Contrast
if (topLayer.R > (ink_outline * 255 / 100)) {
topLayer = ColorBgra.FromBgra (255, 255, 255, topLayer.A);
} else {
topLayer = ColorBgra.FromBgra (0, 0, 0, topLayer.A);
}
// Change Blend Mode to Darken
ColorBgra myPixel = this.darken_op.Apply (topLayer, *dstPtr);
*dstPtr = myPixel;
++srcPtr;
++dstPtr;
}
}
}