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(new ColorRGBA(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 override void GenerateColors(ColorRGBA[] outputColors, int startIndex, int x, int y, int len) { int bytesBetweenPixelsInclusive = srcRW.BytesBetweenPixelsInclusive; ISpanInterpolator spanInterpolator = Interpolator; spanInterpolator.Begin(x + dx, y + dy, len); int x_hr; int y_hr; spanInterpolator.GetCoord(out x_hr, out y_hr); int x_lr = x_hr >> img_subpix_const.SHIFT; int y_lr = y_hr >> img_subpix_const.SHIFT; int bufferIndex; bufferIndex = srcRW.GetBufferOffsetXY(x_lr, y_lr); byte[] srcBuff = srcRW.GetBuffer(); unsafe { fixed(byte *pSource = srcBuff) { do { outputColors[startIndex].red = pSource[bufferIndex]; outputColors[startIndex].green = pSource[bufferIndex]; outputColors[startIndex].blue = pSource[bufferIndex]; outputColors[startIndex].alpha = 255; startIndex++; bufferIndex += bytesBetweenPixelsInclusive; } while (--len != 0); } } }
public override void GenerateColors(ColorRGBA[] outputColors, int startIndex, int x, int y, int len) { ISpanInterpolator spanInterpolator = Interpolator; spanInterpolator.Begin(x + dx, y + dy, len); int x_hr; int y_hr; spanInterpolator.GetCoord(out x_hr, out y_hr); int x_lr = x_hr >> img_subpix_const.SHIFT; int y_lr = y_hr >> img_subpix_const.SHIFT; int bufferIndex = srcRW.GetBufferOffsetXY(x_lr, y_lr); byte[] srcBuffer = srcRW.GetBuffer(); unsafe { fixed(byte *pSource = srcBuffer) { do { outputColors[startIndex++] = *(ColorRGBA *)&(pSource[bufferIndex]); bufferIndex += 4; } while (--len != 0); } } }
public override void GenerateColors(ColorRGBA[] outputColors, int startIndex, int x, int y, int len) { ISpanInterpolator spanInterpolator = Interpolator; spanInterpolator.Begin(x + dx, y + dy, len); int x_hr; int y_hr; spanInterpolator.GetCoord(out x_hr, out y_hr); int x_lr = x_hr >> img_subpix_const.SHIFT; int y_lr = y_hr >> img_subpix_const.SHIFT; int bufferIndex = srcRW.GetBufferOffsetXY(x_lr, y_lr); byte[] srcBuff = srcRW.GetBuffer(); ColorRGBA color = ColorRGBA.White; do { color.blue = srcBuff[bufferIndex++]; color.green = srcBuff[bufferIndex++]; color.red = srcBuff[bufferIndex++]; outputColors[startIndex++] = color; } while (--len != 0); }
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 override void GenerateColors(ColorRGBA[] outputColors, int startIndex, int x, int y, int len) { ISpanInterpolator spanInterpolator = base.Interpolator; int bufferIndex; byte[] srcBuffer = srcRW.GetBuffer(); if (spanInterpolator.GetType() == typeof(PixelFarm.Agg.Transform.SpanInterpolatorLinear) && ((PixelFarm.Agg.Transform.SpanInterpolatorLinear)spanInterpolator).Transformer.GetType() == typeof(PixelFarm.Agg.Transform.Affine) && ((PixelFarm.Agg.Transform.Affine)((PixelFarm.Agg.Transform.SpanInterpolatorLinear)spanInterpolator).Transformer).IsIdentity()) { bufferIndex = srcRW.GetBufferOffsetXY(x, y); //unsafe { #if true do { outputColors[startIndex].blue = (byte)srcBuffer[bufferIndex++]; outputColors[startIndex].green = (byte)srcBuffer[bufferIndex++]; outputColors[startIndex].red = (byte)srcBuffer[bufferIndex++]; outputColors[startIndex].alpha = (byte)srcBuffer[bufferIndex++]; ++startIndex; } while (--len != 0); #else fixed(byte *pSource = &fg_ptr[bufferIndex]) { int *pSourceInt = (int *)pSource; fixed(RGBA_Bytes *pDest = &span[spanIndex]) { int *pDestInt = (int *)pDest; do { *pDestInt++ = *pSourceInt++; } while (--len != 0); } } #endif } return; } spanInterpolator.Begin(x + base.dx, y + base.dy, len); int accColor0, accColor1, accColor2, accColor3; int back_r = m_bgcolor.red; int back_g = m_bgcolor.green; int back_b = m_bgcolor.blue; int back_a = m_bgcolor.alpha; int maxx = srcRW.Width - 1; int maxy = srcRW.Height - 1; srcBuffer = srcRW.GetBuffer(); unchecked { do { int x_hr; int y_hr; spanInterpolator.GetCoord(out x_hr, out y_hr); x_hr -= base.dxInt; y_hr -= base.dyInt; int x_lr = x_hr >> img_subpix_const.SHIFT; int y_lr = y_hr >> img_subpix_const.SHIFT; int weight; if (x_lr >= 0 && y_lr >= 0 && x_lr < maxx && y_lr < maxy) { accColor0 = accColor1 = accColor2 = accColor3 = (int)img_subpix_const.SCALE * (int)img_subpix_const.SCALE / 2; x_hr &= (int)img_subpix_const.MASK; y_hr &= (int)img_subpix_const.MASK; bufferIndex = srcRW.GetBufferOffsetXY(x_lr, y_lr); weight = (((int)img_subpix_const.SCALE - x_hr) * ((int)img_subpix_const.SCALE - y_hr)); if (weight > BASE_MASK) { accColor0 += weight * srcBuffer[bufferIndex + CO.R]; accColor1 += weight * srcBuffer[bufferIndex + CO.G]; accColor2 += weight * srcBuffer[bufferIndex + CO.B]; accColor3 += weight * srcBuffer[bufferIndex + CO.A]; } weight = (x_hr * ((int)img_subpix_const.SCALE - y_hr)); if (weight > BASE_MASK) { bufferIndex += bytesBetweenPixelInclusive; accColor0 += weight * srcBuffer[bufferIndex + CO.R]; accColor1 += weight * srcBuffer[bufferIndex + CO.G]; accColor2 += weight * srcBuffer[bufferIndex + CO.B]; accColor3 += weight * srcBuffer[bufferIndex + CO.A]; } weight = (((int)img_subpix_const.SCALE - x_hr) * y_hr); if (weight > BASE_MASK) { ++y_lr; bufferIndex = srcRW.GetBufferOffsetXY(x_lr, y_lr); accColor0 += weight * srcBuffer[bufferIndex + CO.R]; accColor1 += weight * srcBuffer[bufferIndex + CO.G]; accColor2 += weight * srcBuffer[bufferIndex + CO.B]; accColor3 += weight * srcBuffer[bufferIndex + CO.A]; } weight = (x_hr * y_hr); if (weight > BASE_MASK) { bufferIndex += bytesBetweenPixelInclusive; accColor0 += weight * srcBuffer[bufferIndex + CO.R]; accColor1 += weight * srcBuffer[bufferIndex + CO.G]; accColor2 += weight * srcBuffer[bufferIndex + CO.B]; accColor3 += weight * srcBuffer[bufferIndex + CO.A]; } accColor0 >>= img_subpix_const.SHIFT * 2; accColor1 >>= img_subpix_const.SHIFT * 2; accColor2 >>= img_subpix_const.SHIFT * 2; accColor3 >>= img_subpix_const.SHIFT * 2; } else { if (x_lr < -1 || y_lr < -1 || x_lr > maxx || y_lr > maxy) { accColor0 = back_r; accColor1 = back_g; accColor2 = back_b; accColor3 = back_a; } else { accColor0 = accColor1 = accColor2 = accColor3 = (int)img_subpix_const.SCALE * (int)img_subpix_const.SCALE / 2; x_hr &= (int)img_subpix_const.MASK; y_hr &= (int)img_subpix_const.MASK; weight = (((int)img_subpix_const.SCALE - x_hr) * ((int)img_subpix_const.SCALE - y_hr)); if (weight > BASE_MASK) { } x_lr++; weight = (x_hr * ((int)img_subpix_const.SCALE - y_hr)); if (weight > BASE_MASK) { if ((uint)x_lr <= (uint)maxx && (uint)y_lr <= (uint)maxy) { BlendInFilterPixel(ref accColor0, ref accColor1, ref accColor2, ref accColor3, srcRW.GetBuffer(), srcRW.GetBufferOffsetXY(x_lr, y_lr), weight); } else { accColor0 += back_r * weight; accColor1 += back_g * weight; accColor2 += back_b * weight; accColor3 += back_a * weight; } } x_lr--; y_lr++; weight = (((int)img_subpix_const.SCALE - x_hr) * y_hr); if (weight > BASE_MASK) { if ((uint)x_lr <= (uint)maxx && (uint)y_lr <= (uint)maxy) { BlendInFilterPixel(ref accColor0, ref accColor1, ref accColor2, ref accColor3, srcRW.GetBuffer(), srcRW.GetBufferOffsetXY(x_lr, y_lr), weight); } else { accColor0 += back_r * weight; accColor1 += back_g * weight; accColor2 += back_b * weight; accColor3 += back_a * weight; } } x_lr++; weight = (x_hr * y_hr); if (weight > BASE_MASK) { if ((uint)x_lr <= (uint)maxx && (uint)y_lr <= (uint)maxy) { BlendInFilterPixel(ref accColor0, ref accColor1, ref accColor2, ref accColor3, srcRW.GetBuffer(), srcRW.GetBufferOffsetXY(x_lr, y_lr), weight); } else { accColor0 += back_r * weight; accColor1 += back_g * weight; accColor2 += back_b * weight; accColor3 += back_a * weight; } } accColor0 >>= img_subpix_const.SHIFT * 2; accColor1 >>= img_subpix_const.SHIFT * 2; accColor2 >>= img_subpix_const.SHIFT * 2; accColor3 >>= img_subpix_const.SHIFT * 2; } } outputColors[startIndex].red = (byte)accColor0; outputColors[startIndex].green = (byte)accColor1; outputColors[startIndex].blue = (byte)accColor2; outputColors[startIndex].alpha = (byte)accColor3; ++startIndex; spanInterpolator.Next(); } while (--len != 0); } }
public override void GenerateColors(ColorRGBA[] outputColors, int startIndex, int x, int y, int len) { ISpanInterpolator spanInterpolator = base.Interpolator; spanInterpolator.Begin(x + base.dx, y + base.dy, len); int accColor0, accColor1, accColor2; int sourceAlpha; int back_r = m_bgcolor.red; int back_g = m_bgcolor.green; int back_b = m_bgcolor.blue; int back_a = m_bgcolor.alpha; int bufferIndex; int maxx = (int)srcRW.Width - 1; int maxy = (int)srcRW.Height - 1; byte[] srcBuffer = srcRW.GetBuffer(); unchecked { do { int x_hr; int y_hr; spanInterpolator.GetCoord(out x_hr, out y_hr); x_hr -= base.dxInt; y_hr -= base.dyInt; int x_lr = x_hr >> img_subpix_const.SHIFT; int y_lr = y_hr >> img_subpix_const.SHIFT; int weight; if (x_lr >= 0 && y_lr >= 0 && x_lr < maxx && y_lr < maxy) { accColor0 = accColor1 = accColor2 = img_subpix_const.SCALE * img_subpix_const.SCALE / 2; x_hr &= img_subpix_const.MASK; y_hr &= img_subpix_const.MASK; bufferIndex = srcRW.GetBufferOffsetXY(x_lr, y_lr); weight = ((img_subpix_const.SCALE - x_hr) * (img_subpix_const.SCALE - y_hr)); accColor0 += weight * srcBuffer[bufferIndex + CO.R]; accColor1 += weight * srcBuffer[bufferIndex + CO.G]; accColor2 += weight * srcBuffer[bufferIndex + CO.B]; bufferIndex += 3; weight = (x_hr * (img_subpix_const.SCALE - y_hr)); accColor0 += weight * srcBuffer[bufferIndex + CO.R]; accColor1 += weight * srcBuffer[bufferIndex + CO.G]; accColor2 += weight * srcBuffer[bufferIndex + CO.B]; y_lr++; bufferIndex = srcRW.GetBufferOffsetXY(x_lr, y_lr); weight = ((img_subpix_const.SCALE - x_hr) * y_hr); accColor0 += weight * srcBuffer[bufferIndex + CO.R]; accColor1 += weight * srcBuffer[bufferIndex + CO.G]; accColor2 += weight * srcBuffer[bufferIndex + CO.B]; bufferIndex += 3; weight = (x_hr * y_hr); accColor0 += weight * srcBuffer[bufferIndex + CO.R]; accColor1 += weight * srcBuffer[bufferIndex + CO.G]; accColor2 += weight * srcBuffer[bufferIndex + CO.B]; accColor0 >>= img_subpix_const.SHIFT * 2; accColor1 >>= img_subpix_const.SHIFT * 2; accColor2 >>= img_subpix_const.SHIFT * 2; sourceAlpha = BASE_MASK; } else { if (x_lr < -1 || y_lr < -1 || x_lr > maxx || y_lr > maxy) { accColor0 = back_r; accColor1 = back_g; accColor2 = back_b; sourceAlpha = back_a; } else { accColor0 = accColor1 = accColor2 = img_subpix_const.SCALE * img_subpix_const.SCALE / 2; sourceAlpha = img_subpix_const.SCALE * img_subpix_const.SCALE / 2; x_hr &= img_subpix_const.MASK; y_hr &= img_subpix_const.MASK; weight = ((img_subpix_const.SCALE - x_hr) * (img_subpix_const.SCALE - y_hr)); if ((uint)x_lr <= (uint)maxx && (uint)y_lr <= (uint)maxy) { BlendInFilterPixel(ref accColor0, ref accColor1, ref accColor2, ref sourceAlpha, srcRW.GetBuffer(), srcRW.GetBufferOffsetXY(x_lr, y_lr), weight); } else { accColor0 += back_r * weight; accColor1 += back_g * weight; accColor2 += back_b * weight; sourceAlpha += back_a * weight; } x_lr++; weight = (x_hr * (img_subpix_const.SCALE - y_hr)); if ((uint)x_lr <= (uint)maxx && (uint)y_lr <= (uint)maxy) { BlendInFilterPixel(ref accColor0, ref accColor1, ref accColor2, ref sourceAlpha, srcRW.GetBuffer(), srcRW.GetBufferOffsetXY(x_lr, y_lr), weight); } else { accColor0 += back_r * weight; accColor1 += back_g * weight; accColor2 += back_b * weight; sourceAlpha += back_a * weight; } x_lr--; y_lr++; weight = ((img_subpix_const.SCALE - x_hr) * y_hr); if ((uint)x_lr <= (uint)maxx && (uint)y_lr <= (uint)maxy) { BlendInFilterPixel(ref accColor0, ref accColor1, ref accColor2, ref sourceAlpha, srcRW.GetBuffer(), srcRW.GetBufferOffsetXY(x_lr, y_lr), weight); } else { accColor0 += back_r * weight; accColor1 += back_g * weight; accColor2 += back_b * weight; sourceAlpha += back_a * weight; } x_lr++; weight = (x_hr * y_hr); if ((uint)x_lr <= (uint)maxx && (uint)y_lr <= (uint)maxy) { BlendInFilterPixel(ref accColor0, ref accColor1, ref accColor2, ref sourceAlpha, srcRW.GetBuffer(), srcRW.GetBufferOffsetXY(x_lr, y_lr), weight); } else { accColor0 += back_r * weight; accColor1 += back_g * weight; accColor2 += back_b * weight; sourceAlpha += back_a * weight; } accColor0 >>= img_subpix_const.SHIFT * 2; accColor1 >>= img_subpix_const.SHIFT * 2; accColor2 >>= img_subpix_const.SHIFT * 2; sourceAlpha >>= img_subpix_const.SHIFT * 2; } } outputColors[startIndex].red = (byte)accColor0; outputColors[startIndex].green = (byte)accColor1; outputColors[startIndex].blue = (byte)accColor2; outputColors[startIndex].alpha = (byte)sourceAlpha; startIndex++; spanInterpolator.Next(); } while (--len != 0); } }