public GetBufferOffsetXY ( int x, int y ) : int | ||
x | int | |
y | int | |
Результат | int |
public void Fill(ImageReaderWriterBase bufferToFillOn, int x, int y) { unchecked // this way we can overflow the uint on negative and get a big number { if ((uint)x > bufferToFillOn.Width || (uint)y > bufferToFillOn.Height) { return; } } destImage = bufferToFillOn; imageStride = destImage.Stride; destBuffer = destImage.GetBuffer(); int imageWidth = destImage.Width; int imageHeight = destImage.Height; pixelsChecked = new bool[destImage.Width * destImage.Height]; int startColorBufferOffset = destImage.GetBufferOffsetXY(x, y); fillRule.SetStartColor(Drawing.Color.FromArgb(destImage.GetBuffer()[startColorBufferOffset + 2], destImage.GetBuffer()[startColorBufferOffset + 1], destImage.GetBuffer()[startColorBufferOffset])); LinearFill(x, y); while (ranges.Count > 0) { Range range = ranges.Dequeue(); int downY = range.y - 1; int upY = range.y + 1; int downPixelOffset = (imageWidth * (range.y - 1)) + range.startX; int upPixelOffset = (imageWidth * (range.y + 1)) + range.startX; for (int rangeX = range.startX; rangeX <= range.endX; rangeX++) { if (range.y > 0) { if (!pixelsChecked[downPixelOffset]) { int bufferOffset = destImage.GetBufferOffsetXY(rangeX, downY); if (fillRule.CheckPixel(destBuffer, bufferOffset)) { LinearFill(rangeX, downY); } } } if (range.y < (imageHeight - 1)) { if (!pixelsChecked[upPixelOffset]) { int bufferOffset = destImage.GetBufferOffsetXY(rangeX, upY); if (fillRule.CheckPixel(destBuffer, bufferOffset)) { LinearFill(rangeX, upY); } } } upPixelOffset++; downPixelOffset++; } } }
public void SetPixelHighRes(ImageReaderWriterBase sourceImage, ColorRGBA[] destBuffer, int destBufferOffset, int x, int y) { int r, g, b, a; r = g = b = a = LineAA.SUBPIXEL_SCALE * LineAA.SUBPIXEL_SCALE / 2; int weight; int x_lr = x >> LineAA.SUBPIXEL_SHIFT; int y_lr = y >> LineAA.SUBPIXEL_SHIFT; x &= LineAA.SUBPIXEL_MARK; y &= LineAA.SUBPIXEL_MARK; int sourceOffset; byte[] ptr = sourceImage.GetBuffer(); sourceOffset = sourceImage.GetBufferOffsetXY(x_lr, y_lr); weight = (LineAA.SUBPIXEL_SCALE - x) * (LineAA.SUBPIXEL_SCALE - y); r += weight * ptr[sourceOffset + CO.R]; g += weight * ptr[sourceOffset + CO.G]; b += weight * ptr[sourceOffset + CO.B]; a += weight * ptr[sourceOffset + CO.A]; sourceOffset += sourceImage.BytesBetweenPixelsInclusive; weight = x * (LineAA.SUBPIXEL_SCALE - y); r += weight * ptr[sourceOffset + CO.R]; g += weight * ptr[sourceOffset + CO.G]; b += weight * ptr[sourceOffset + CO.B]; a += weight * ptr[sourceOffset + CO.A]; sourceOffset = sourceImage.GetBufferOffsetXY(x_lr, y_lr + 1); weight = (LineAA.SUBPIXEL_SCALE - x) * y; r += weight * ptr[sourceOffset + CO.R]; g += weight * ptr[sourceOffset + CO.G]; b += weight * ptr[sourceOffset + CO.B]; a += weight * ptr[sourceOffset + CO.A]; sourceOffset += sourceImage.BytesBetweenPixelsInclusive; weight = x * y; r += weight * ptr[sourceOffset + CO.R]; g += weight * ptr[sourceOffset + CO.G]; b += weight * ptr[sourceOffset + CO.B]; a += weight * ptr[sourceOffset + CO.A]; destBuffer[destBufferOffset].red = (byte)(r >> LineAA.SUBPIXEL_SHIFT * 2); destBuffer[destBufferOffset].green = (byte)(g >> LineAA.SUBPIXEL_SHIFT * 2); destBuffer[destBufferOffset].blue = (byte)(b >> LineAA.SUBPIXEL_SHIFT * 2); destBuffer[destBufferOffset].alpha = (byte)(a >> LineAA.SUBPIXEL_SHIFT * 2); }
public void SetPixelHighRes(ImageReaderWriterBase sourceImage, Color[] destBuffer, int destBufferOffset, int x, int y) { int r, g, b, a; r = g = b = a = LineAA.SUBPIXEL_SCALE * LineAA.SUBPIXEL_SCALE / 2; int weight; int x_lr = x >> LineAA.SUBPIXEL_SHIFT; int y_lr = y >> LineAA.SUBPIXEL_SHIFT; x &= LineAA.SUBPIXEL_MARK; y &= LineAA.SUBPIXEL_MARK; int sourceOffset; byte[] ptr = sourceImage.GetBuffer(); sourceOffset = sourceImage.GetBufferOffsetXY(x_lr, y_lr); weight = (LineAA.SUBPIXEL_SCALE - x) * (LineAA.SUBPIXEL_SCALE - y); r += weight * ptr[sourceOffset + CO.R]; g += weight * ptr[sourceOffset + CO.G]; b += weight * ptr[sourceOffset + CO.B]; a += weight * ptr[sourceOffset + CO.A]; sourceOffset += sourceImage.BytesBetweenPixelsInclusive; weight = x * (LineAA.SUBPIXEL_SCALE - y); r += weight * ptr[sourceOffset + CO.R]; g += weight * ptr[sourceOffset + CO.G]; b += weight * ptr[sourceOffset + CO.B]; a += weight * ptr[sourceOffset + CO.A]; sourceOffset = sourceImage.GetBufferOffsetXY(x_lr, y_lr + 1); weight = (LineAA.SUBPIXEL_SCALE - x) * y; r += weight * ptr[sourceOffset + CO.R]; g += weight * ptr[sourceOffset + CO.G]; b += weight * ptr[sourceOffset + CO.B]; a += weight * ptr[sourceOffset + CO.A]; sourceOffset += sourceImage.BytesBetweenPixelsInclusive; weight = x * y; r += weight * ptr[sourceOffset + CO.R]; g += weight * ptr[sourceOffset + CO.G]; b += weight * ptr[sourceOffset + CO.B]; a += weight * ptr[sourceOffset + CO.A]; destBuffer[destBufferOffset].red = (byte)(r >> LineAA.SUBPIXEL_SHIFT * 2); destBuffer[destBufferOffset].green = (byte)(g >> LineAA.SUBPIXEL_SHIFT * 2); destBuffer[destBufferOffset].blue = (byte)(b >> LineAA.SUBPIXEL_SHIFT * 2); destBuffer[destBufferOffset].alpha = (byte)(a >> LineAA.SUBPIXEL_SHIFT * 2); }
void LinearFill(int x, int y) { int bytesPerPixel = destImage.BytesBetweenPixelsInclusive; int imageWidth = destImage.Width; int leftFillX = x; int bufferOffset = destImage.GetBufferOffsetXY(x, y); int pixelOffset = (imageWidth * y) + x; while (true) { fillRule.SetPixel(destBuffer, bufferOffset); pixelsChecked[pixelOffset] = true; leftFillX--; pixelOffset--; bufferOffset -= bytesPerPixel; if (leftFillX <= 0 || (pixelsChecked[pixelOffset]) || !fillRule.CheckPixel(destBuffer, bufferOffset)) { break; } } leftFillX++; int rightFillX = x; bufferOffset = destImage.GetBufferOffsetXY(x, y); pixelOffset = (imageWidth * y) + x; while (true) { fillRule.SetPixel(destBuffer, bufferOffset); pixelsChecked[pixelOffset] = true; rightFillX++; pixelOffset++; bufferOffset += bytesPerPixel; if (rightFillX >= imageWidth || pixelsChecked[pixelOffset] || !fillRule.CheckPixel(destBuffer, bufferOffset)) { break; } } rightFillX--; ranges.Enqueue(new Range(leftFillX, rightFillX, y)); }
public static void CopySubBufferToInt32Array(ImageReaderWriterBase buff, int mx, int my, int w, int h, int[] buffer) { int i = 0; byte[] mBuffer = buff.m_ByteBuffer; for (int y = my; y < h; ++y) { int xbufferOffset = buff.GetBufferOffsetXY(0, y); for (int x = mx; x < w; ++x) { //rgba byte r = mBuffer[xbufferOffset + 2]; byte g = mBuffer[xbufferOffset + 1]; byte b = mBuffer[xbufferOffset]; xbufferOffset += 4; buffer[i] = b | (g << 8) | (r << 16); i++; } } }
public void Fill(ImageReaderWriterBase bufferToFillOn, int x, int y) { unchecked // this way we can overflow the uint on negative and get a big number { if ((uint)x > bufferToFillOn.Width || (uint)y > bufferToFillOn.Height) { return; } } destImage = bufferToFillOn; imageStride = destImage.Stride; destBuffer = destImage.GetBuffer(); int imageWidth = destImage.Width; int imageHeight = destImage.Height; pixelsChecked = new bool[destImage.Width * destImage.Height]; int startColorBufferOffset = destImage.GetBufferOffsetXY(x, y); fillRule.SetStartColor(Drawing.Color.FromArgb(destImage.GetBuffer()[startColorBufferOffset + 2], destImage.GetBuffer()[startColorBufferOffset + 1], destImage.GetBuffer()[startColorBufferOffset])); LinearFill(x, y); while (ranges.Count > 0) { Range range = ranges.Dequeue(); int downY = range.y - 1; int upY = range.y + 1; int downPixelOffset = (imageWidth * (range.y - 1)) + range.startX; int upPixelOffset = (imageWidth * (range.y + 1)) + range.startX; for (int rangeX = range.startX; rangeX <= range.endX; rangeX++) { if (range.y > 0) { if (!pixelsChecked[downPixelOffset]) { int bufferOffset = destImage.GetBufferOffsetXY(rangeX, downY); if (fillRule.CheckPixel(destBuffer, bufferOffset)) { LinearFill(rangeX, downY); } } } if (range.y < (imageHeight - 1)) { if (!pixelsChecked[upPixelOffset]) { int bufferOffset = destImage.GetBufferOffsetXY(rangeX, upY); if (fillRule.CheckPixel(destBuffer, bufferOffset)) { LinearFill(rangeX, upY); } } } upPixelOffset++; downPixelOffset++; } } }
public static void CopySubBufferToInt32Array(ImageReaderWriterBase buff, int mx, int my, int w, int h, int[] buffer) { int i = 0; byte[] mBuffer = buff.m_ByteBuffer; for (int y = my; y < h; ++y) { int xbufferOffset = buff.GetBufferOffsetXY(0, y); for (int x = mx; x < w; ++x) { //rgba byte r = mBuffer[xbufferOffset + 2]; byte g = mBuffer[xbufferOffset + 1]; byte b = mBuffer[xbufferOffset]; xbufferOffset += 4; buffer[i] = b | (g << 8) | (r << 16); i++; } } }