本文整理汇总了C#中MatterHackers.Agg.Image.ImageBuffer.GetBufferOffsetY方法的典型用法代码示例。如果您正苦于以下问题:C# ImageBuffer.GetBufferOffsetY方法的具体用法?C# ImageBuffer.GetBufferOffsetY怎么用?C# ImageBuffer.GetBufferOffsetY使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MatterHackers.Agg.Image.ImageBuffer
的用法示例。
在下文中一共展示了ImageBuffer.GetBufferOffsetY方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoXBlur
internal static void DoXBlur(ImageBuffer sourceDest)
{
if (sourceDest.BitDepth != 8)
{
throw new NotImplementedException("We only work with 8 bit at the moment.");
}
int height = sourceDest.Height;
int width = sourceDest.Width;
byte[] buffer = sourceDest.GetBuffer();
byte[] cache = new byte[width];
for (int y = 0; y < height; y++)
{
int offset = sourceDest.GetBufferOffsetY(y);
for (int x = 0; x < width; x++)
{
cache[x] = buffer[offset + x];
}
for (int x = 1; x < width - 1; x++)
{
int newValue = (cache[x - 1] + cache[x] * 2 + cache[x + 1] + 2) / 4; // the + 2 is so that we will round correctly
buffer[offset + x] = (byte)newValue;
}
}
}
示例2: DoThreshold
public static void DoThreshold(ImageBuffer result, ImageBuffer sourceImage, int threshold, TestThreshold testFunction)
{
if (sourceImage.BitDepth != result.BitDepth)
{
throw new NotImplementedException("All the images have to be the same bit depth.");
}
if (sourceImage.Width != result.Width || sourceImage.Height != result.Height)
{
throw new Exception("All images must be the same size.");
}
switch (sourceImage.BitDepth)
{
case 32:
{
int height = sourceImage.Height;
int width = sourceImage.Width;
byte[] resultBuffer = result.GetBuffer();
byte[] sourceBuffer = sourceImage.GetBuffer();
for (int y = 0; y < height; y++)
{
int offset = sourceImage.GetBufferOffsetY(y);
for (int x = 0; x < width; x++)
{
if (testFunction(sourceBuffer, offset, threshold))
{
resultBuffer[offset + 0] = (byte)255;
resultBuffer[offset + 1] = (byte)255;
resultBuffer[offset + 2] = (byte)255;
resultBuffer[offset + 3] = (byte)255;
}
else
{
resultBuffer[offset + 0] = (byte)0;
resultBuffer[offset + 1] = (byte)0;
resultBuffer[offset + 2] = (byte)0;
resultBuffer[offset + 3] = (byte)0;
}
offset += 4;
}
}
}
break;
default:
throw new NotImplementedException();
}
}
示例3: DoSubtract
public static void DoSubtract(ImageBuffer result, ImageBuffer imageToSubtractFrom, ImageBuffer imageToSubtract)
{
if (lookupSubtractAndClamp == null)
{
CreateLookup();
}
if (imageToSubtractFrom.BitDepth != imageToSubtract.BitDepth || imageToSubtract.BitDepth != result.BitDepth)
{
throw new NotImplementedException("All the images have to be the same bit depth.");
}
if (imageToSubtractFrom.Width != imageToSubtract.Width || imageToSubtractFrom.Height != imageToSubtract.Height
|| imageToSubtractFrom.Width != result.Width || imageToSubtractFrom.Height != result.Height)
{
throw new Exception("All images must be the same size.");
}
switch (imageToSubtractFrom.BitDepth)
{
case 32:
{
int height = imageToSubtractFrom.Height;
int width = imageToSubtractFrom.Width;
byte[] resultBuffer = result.GetBuffer();
byte[] imageABuffer = imageToSubtractFrom.GetBuffer();
byte[] imageBBuffer = imageToSubtract.GetBuffer();
for (int y = 0; y < height; y++)
{
int offset = imageToSubtractFrom.GetBufferOffsetY(y);
for (int x = 0; x < width; x++)
{
resultBuffer[offset] = (byte)lookupSubtractAndClamp[imageABuffer[offset] - imageBBuffer[offset] + 255]; // add 255 to make sure not < 0
offset++;
resultBuffer[offset] = (byte)lookupSubtractAndClamp[imageABuffer[offset] - imageBBuffer[offset] + 255];
offset++;
resultBuffer[offset] = (byte)lookupSubtractAndClamp[imageABuffer[offset] - imageBBuffer[offset] + 255];
offset++;
resultBuffer[offset] = 255;
offset++;
}
}
}
break;
default:
throw new NotImplementedException();
}
}
示例4: DoInvertLightness
public static void DoInvertLightness(ImageBuffer result, ImageBuffer sourceImage)
{
if (sourceImage.BitDepth != result.BitDepth)
{
throw new NotImplementedException("All the images have to be the same bit depth.");
}
if (sourceImage.Width != result.Width || sourceImage.Height != result.Height)
{
throw new Exception("All images must be the same size.");
}
switch (sourceImage.BitDepth)
{
case 32:
{
int height = sourceImage.Height;
int width = sourceImage.Width;
byte[] resultBuffer = result.GetBuffer();
byte[] sourceBuffer = sourceImage.GetBuffer();
for (int y = 0; y < height; y++)
{
int offset = sourceImage.GetBufferOffsetY(y);
for (int x = 0; x < width; x++)
{
RGBA_Bytes color = new RGBA_Bytes(resultBuffer[offset + 2], resultBuffer[offset + 1], resultBuffer[offset + 0], resultBuffer[offset + 3]);
RGBA_Bytes invertedColor = InvertColor(color);
resultBuffer[offset + 0] = invertedColor.blue;
resultBuffer[offset + 1] = invertedColor.green;
resultBuffer[offset + 2] = invertedColor.blue;
resultBuffer[offset + 3] = invertedColor.alpha;
offset += 4;
}
}
}
break;
default:
throw new NotImplementedException();
}
}
示例5: DoMultiply
public static void DoMultiply(ImageBuffer result, ImageBuffer imageA, ImageBuffer imageB)
{
if (imageA.BitDepth != imageB.BitDepth || imageB.BitDepth != result.BitDepth)
{
throw new NotImplementedException("All the images have to be the same bit depth.");
}
if (imageA.Width != imageB.Width || imageA.Height != imageB.Height
|| imageA.Width != result.Width || imageA.Height != result.Height)
{
throw new Exception("All images must be the same size.");
}
switch (imageA.BitDepth)
{
case 32:
{
int height = imageA.Height;
int width = imageA.Width;
byte[] resultBuffer = result.GetBuffer();
byte[] imageABuffer = imageA.GetBuffer();
byte[] imageBBuffer = imageB.GetBuffer();
for (int y = 0; y < height; y++)
{
int offsetA = imageA.GetBufferOffsetY(y);
int offsetB = imageB.GetBufferOffsetY(y);
int offsetResult = result.GetBufferOffsetY(y);
for (int x = 0; x < width; x++)
{
resultBuffer[offsetResult++] = (byte)((imageABuffer[offsetA++] * imageBBuffer[offsetB++]) / 255);
resultBuffer[offsetResult++] = (byte)((imageABuffer[offsetA++] * imageBBuffer[offsetB++]) / 255);
resultBuffer[offsetResult++] = (byte)((imageABuffer[offsetA++] * imageBBuffer[offsetB++]) / 255);
resultBuffer[offsetResult++] = 255; offsetA++; offsetB++;
}
}
}
break;
default:
throw new NotImplementedException();
}
}
示例6: DoWhiteToColor
public static void DoWhiteToColor(ImageBuffer result, ImageBuffer imageA, RGBA_Bytes color)
{
if (imageA.BitDepth != result.BitDepth)
{
throw new NotImplementedException("All the images have to be the same bit depth.");
}
if (imageA.Width != result.Width || imageA.Height != result.Height)
{
throw new Exception("All images must be the same size.");
}
switch (imageA.BitDepth)
{
case 32:
{
int height = imageA.Height;
int width = imageA.Width;
byte[] resultBuffer = result.GetBuffer();
byte[] imageABuffer = imageA.GetBuffer();
for (int y = 0; y < height; y++)
{
int offsetA = imageA.GetBufferOffsetY(y);
int offsetResult = result.GetBufferOffsetY(y);
byte amoutOfWhite = imageABuffer[offsetA];
for (int x = 0; x < width; x++)
{
resultBuffer[offsetResult++] = (byte)(color.blue * amoutOfWhite / 255); offsetA++;
resultBuffer[offsetResult++] = (byte)(color.green * amoutOfWhite / 255); offsetA++;
resultBuffer[offsetResult++] = (byte)(color.red * amoutOfWhite / 255); offsetA++;
resultBuffer[offsetResult++] = imageABuffer[offsetA++];
}
}
}
break;
default:
throw new NotImplementedException();
}
}
示例7: Copy8BitDataToImage
private static void Copy8BitDataToImage(ImageBuffer destImage, Bitmap m_WidowsBitmap)
{
destImage.Allocate(m_WidowsBitmap.Width, m_WidowsBitmap.Height, m_WidowsBitmap.Width * 4, 32);
BitmapData bitmapData = m_WidowsBitmap.LockBits(new Rectangle(0, 0, m_WidowsBitmap.Width, m_WidowsBitmap.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, m_WidowsBitmap.PixelFormat);
int sourceIndex = 0;
int destIndex = 0;
unsafe
{
int offset;
byte[] destBuffer = destImage.GetBuffer(out offset);
byte* pSourceBuffer = (byte*)bitmapData.Scan0;
Color[] colors = m_WidowsBitmap.Palette.Entries;
for (int y = 0; y < destImage.Height; y++)
{
sourceIndex = y * bitmapData.Stride;
destIndex = destImage.GetBufferOffsetY(destImage.Height - 1 - y);
for (int x = 0; x < destImage.Width; x++)
{
Color color = colors[pSourceBuffer[sourceIndex++]];
destBuffer[destIndex++] = color.B;
destBuffer[destIndex++] = color.G;
destBuffer[destIndex++] = color.R;
destBuffer[destIndex++] = color.A;
}
}
}
m_WidowsBitmap.UnlockBits(bitmapData);
}
示例8: DoAllWhite
public static void DoAllWhite(ImageBuffer result, ImageBuffer imageA)
{
if (imageA.BitDepth != result.BitDepth)
{
throw new NotImplementedException("All the images have to be the same bit depth.");
}
if (imageA.Width != result.Width || imageA.Height != result.Height)
{
throw new Exception("All images must be the same size.");
}
switch (imageA.BitDepth)
{
case 32:
{
int height = imageA.Height;
int width = imageA.Width;
byte[] resultBuffer = result.GetBuffer();
byte[] imageABuffer = imageA.GetBuffer();
for (int y = 0; y < height; y++)
{
int offsetA = imageA.GetBufferOffsetY(y);
int offsetResult = result.GetBufferOffsetY(y);
for (int x = 0; x < width; x++)
{
int alpha = imageABuffer[offsetA+3];
if (alpha > 0)
{
resultBuffer[offsetResult++] = (byte)255; offsetA++;
resultBuffer[offsetResult++] = (byte)255; offsetA++;
resultBuffer[offsetResult++] = (byte)255; offsetA++;
resultBuffer[offsetResult++] = (byte)alpha; offsetA++;
}
else
{
resultBuffer[offsetResult++] = (byte)0; offsetA++;
resultBuffer[offsetResult++] = (byte)0; offsetA++;
resultBuffer[offsetResult++] = (byte)0; offsetA++;
resultBuffer[offsetResult++] = (byte)0; offsetA++;
}
}
}
result.SetRecieveBlender(new BlenderPreMultBGRA());
}
break;
default:
throw new NotImplementedException();
}
}
示例9: FindLeastSquaresMatch
public bool FindLeastSquaresMatch(ImageBuffer imageToFind, out Vector2 bestPosition, out double bestLeastSquares, double maxError = double.MaxValue)
{
bestPosition = Vector2.Zero;
bestLeastSquares = double.MaxValue;
if (Width >= imageToFind.Width
&& Height >= imageToFind.Height
&& BitDepth == imageToFind.BitDepth)
{
int bytesPerPixel = BitDepth / 8;
int aDistanceBetweenPixels = GetBytesBetweenPixelsInclusive();
int bDistanceBetweenPixels = imageToFind.GetBytesBetweenPixelsInclusive();
byte[] thisBuffer = GetBuffer();
byte[] containedBuffer = imageToFind.GetBuffer();
for (int matchY = 0; matchY <= Height - imageToFind.Height; matchY++)
{
for (int matchX = 0; matchX <= Width - imageToFind.Width; matchX++)
{
double currentLeastSquares = 0;
for (int imageToFindY = 0; imageToFindY < imageToFind.Height; imageToFindY++)
{
int thisBufferOffset = GetBufferOffsetXY(matchX, matchY + imageToFindY);
int imageToFindBufferOffset = imageToFind.GetBufferOffsetY(imageToFindY);
for (int imageToFindX = 0; imageToFindX < imageToFind.Width; imageToFindX++)
{
for (int byteIndex = 0; byteIndex < bytesPerPixel; byteIndex++)
{
byte aByte = thisBuffer[thisBufferOffset + byteIndex];
byte bByte = containedBuffer[imageToFindBufferOffset + byteIndex];
int difference = (int)aByte - (int)bByte;
currentLeastSquares += difference * difference;
}
thisBufferOffset += aDistanceBetweenPixels;
imageToFindBufferOffset += bDistanceBetweenPixels;
if (currentLeastSquares > maxError)
{
// stop checking we have too much error.
imageToFindX = imageToFind.Width;
imageToFindY = imageToFind.Height;
}
}
}
if (currentLeastSquares < bestLeastSquares)
{
bestPosition = new Vector2(matchX, matchY);
bestLeastSquares = currentLeastSquares;
if (maxError > currentLeastSquares)
{
maxError = currentLeastSquares;
if (currentLeastSquares == 0)
{
return true;
}
}
}
}
}
}
return bestLeastSquares <= maxError;
}
示例10: Contains
public bool Contains(ImageBuffer imageToFind, out int matchX, out int matchY, int maxError = 0)
{
matchX = 0;
matchY = 0;
if (Width >= imageToFind.Width
&& Height >= imageToFind.Height
&& BitDepth == imageToFind.BitDepth)
{
int bytesPerPixel = BitDepth / 8;
int aDistanceBetweenPixels = GetBytesBetweenPixelsInclusive();
int bDistanceBetweenPixels = imageToFind.GetBytesBetweenPixelsInclusive();
byte[] thisBuffer = GetBuffer();
byte[] containedBuffer = imageToFind.GetBuffer();
for (matchY = 0; matchY <= Height - imageToFind.Height; matchY++)
{
for (matchX = 0; matchX <= Width - imageToFind.Width; matchX++)
{
bool foundBadMatch = false;
for (int imageToFindY = 0; imageToFindY < imageToFind.Height; imageToFindY++)
{
int thisBufferOffset = GetBufferOffsetXY(matchX, matchY + imageToFindY);
int imageToFindBufferOffset = imageToFind.GetBufferOffsetY(imageToFindY);
for (int imageToFindX = 0; imageToFindX < imageToFind.Width; imageToFindX++)
{
for (int byteIndex = 0; byteIndex < bytesPerPixel; byteIndex++)
{
byte aByte = thisBuffer[thisBufferOffset + byteIndex];
byte bByte = containedBuffer[imageToFindBufferOffset + byteIndex];
if (aByte < (bByte - maxError) || aByte > (bByte + maxError))
{
foundBadMatch = true;
byteIndex = bytesPerPixel;
imageToFindX = imageToFind.Width;
imageToFindY = imageToFind.Height;
}
}
thisBufferOffset += aDistanceBetweenPixels;
imageToFindBufferOffset += bDistanceBetweenPixels;
}
}
if (!foundBadMatch)
{
return true;
}
}
}
}
return false;
}
示例11: Equals
public bool Equals(ImageBuffer b, int maxError = 0)
{
if (Width == b.Width
&& Height == b.Height
&& BitDepth == b.BitDepth
&& StrideInBytes() == b.StrideInBytes()
&& m_OriginOffset == b.m_OriginOffset)
{
int bytesPerPixel = BitDepth / 8;
int aDistanceBetweenPixels = GetBytesBetweenPixelsInclusive();
int bDistanceBetweenPixels = b.GetBytesBetweenPixelsInclusive();
byte[] aBuffer = GetBuffer();
byte[] bBuffer = b.GetBuffer();
for (int y = 0; y < Height; y++)
{
int aBufferOffset = GetBufferOffsetY(y);
int bBufferOffset = b.GetBufferOffsetY(y);
for (int x = 0; x < Width; x++)
{
for (int byteIndex = 0; byteIndex < bytesPerPixel; byteIndex++)
{
byte aByte = aBuffer[aBufferOffset + byteIndex];
byte bByte = bBuffer[bBufferOffset + byteIndex];
if (aByte < (bByte - maxError) || aByte > (bByte + maxError))
{
return false;
}
}
aBufferOffset += aDistanceBetweenPixels;
bBufferOffset += bDistanceBetweenPixels;
}
}
return true;
}
return false;
}
示例12: MarchingSquaresByte
public MarchingSquaresByte(ImageBuffer imageToMarch, PositiveArea0to1 thresholdFunction, int debugColor)
{
thersholdPerPixel = new double[imageToMarch.Width * imageToMarch.Height];
{
byte[] buffer = imageToMarch.GetBuffer();
int strideInBytes = imageToMarch.StrideInBytes();
for (int y = 0; y < imageToMarch.Height; y++)
{
int imageBufferOffset = imageToMarch.GetBufferOffsetY(y);
int thresholdBufferOffset = y * imageToMarch.Width;
for (int x = 0; x < imageToMarch.Width; x++)
{
int imageBufferOffsetWithX = imageBufferOffset + x * 4;
thersholdPerPixel[thresholdBufferOffset + x] = thresholdFunction(GetRGBA(buffer, imageBufferOffsetWithX));
}
}
}
this.thresholdFunction = thresholdFunction;
this.imageToMarch = imageToMarch;
this.debugColor = debugColor;
CreateLineSegments();
}
示例13: CopyNoramlBufferToImage
public void CopyNoramlBufferToImage(ImageBuffer destImage, RectangleInt viewport)
{
if (destImage.BitDepth != 32)
{
throw new Exception("We can only render to 32 bit dest at the moment.");
}
Byte[] destBuffer = destImage.GetBuffer();
viewport.Bottom = Math.Max(0, Math.Min(destImage.Height, viewport.Bottom));
viewport.Top = Math.Max(0, Math.Min(destImage.Height, viewport.Top));
#if MULTI_THREAD
System.Threading.Tasks.Parallel.For(viewport.Bottom, viewport.Height, y => //
#else
for (int y = viewport.Bottom; y < viewport.Height; y++)
#endif
{
for (int x = viewport.Left; x < viewport.Right; x++)
{
int bufferOffset = destImage.GetBufferOffsetY(y);
// we don't need to set this if we are anti-aliased
int totalOffset = bufferOffset + x * 4;
destBuffer[totalOffset++] = (byte)((normalBuffer[x][y].x + 1) * 128);
destBuffer[totalOffset++] = (byte)((normalBuffer[x][y].y + 1) * 128); ;
destBuffer[totalOffset++] = (byte)((normalBuffer[x][y].z + 1) * 128); ;
destBuffer[totalOffset] = 255;
}
}
#if MULTI_THREAD
);
#endif
destImage.MarkImageChanged();
}
示例14: CopyDepthBufferToImage
public void CopyDepthBufferToImage(ImageBuffer destImage, RectangleInt viewport)
{
if (destImage.BitDepth != 32)
{
throw new Exception("We can only render to 32 bit dest at the moment.");
}
Byte[] destBuffer = destImage.GetBuffer();
viewport.Bottom = Math.Max(0, Math.Min(destImage.Height, viewport.Bottom));
viewport.Top = Math.Max(0, Math.Min(destImage.Height, viewport.Top));
double minZ = 5000;
double maxZ = 0;
for (int y = viewport.Bottom; y < viewport.Height; y++)
{
for (int x = viewport.Left; x < viewport.Right; x++)
{
double depthAtXY = depthBuffer[x][y];
if (depthAtXY < 5000)
{
minZ = Math.Min(minZ, depthAtXY);
maxZ = Math.Max(maxZ, depthAtXY);
}
}
}
double divisor = maxZ - minZ;
#if MULTI_THREAD
System.Threading.Tasks.Parallel.For(viewport.Bottom, viewport.Height, y => //
#else
for (int y = viewport.Bottom; y < viewport.Height; y++)
#endif
{
for (int x = viewport.Left; x < viewport.Right; x++)
{
int bufferOffset = destImage.GetBufferOffsetY(y);
// we don't need to set this if we are anti-aliased
int totalOffset = bufferOffset + x * 4;
double depthXY = depthBuffer[x][y];
double rangedDepth = (depthXY - minZ) / divisor;
double clampedDepth = Math.Max(0, Math.Min(255, rangedDepth * 255));
byte depthColor = (byte)(clampedDepth);
destBuffer[totalOffset++] = depthColor;
destBuffer[totalOffset++] = depthColor;
destBuffer[totalOffset++] = depthColor;
destBuffer[totalOffset] = 255;
}
}
#if MULTI_THREAD
);
#endif
destImage.MarkImageChanged();
}