public void combine_hspan(int x, int y, byte[] buffer, int bufferIndex, int num_pix) { int xmax = (int)m_rbuf.Width - 1; int ymax = (int)m_rbuf.Height - 1; int count = num_pix; byte[] covers = buffer; int coversIndex = bufferIndex; if (y < 0 || y > ymax) { AggMemMx.MemClear(buffer, bufferIndex, num_pix); return; } if (x < 0) { count += x; if (count <= 0) { AggMemMx.MemClear(buffer, bufferIndex, num_pix); return; } AggMemMx.MemClear(covers, coversIndex, -x); coversIndex -= x; x = 0; } if (x + count > xmax) { int rest = x + count - xmax - 1; count -= rest; if (count <= 0) { AggMemMx.MemClear(buffer, bufferIndex, num_pix); return; } AggMemMx.MemClear(covers, coversIndex + count, rest); } int maskIndex = m_rbuf.GetBufferOffsetXY(x, y); byte[] mask = m_rbuf.GetBuffer(); unsafe { fixed(byte *maskHead = &mask[maskIndex]) fixed(byte *coverHead = &covers[coversIndex]) { byte *c_mask_index = maskHead; byte *c_cover_index = coverHead; do { *c_cover_index = (byte)((*c_cover_index * (*c_mask_index) + 255) >> 8); c_cover_index++; c_mask_index++; }while (--count != 0); } } }
public void combine_hspanFullCover(int x, int y, byte[] covers, int coversIndex, int num_pix) { int xmax = (int)m_rbuf.Width - 1; int ymax = (int)m_rbuf.Height - 1; int count = num_pix; if (y < 0 || y > ymax) { AggMemMx.MemClear(covers, coversIndex, num_pix); return; } if (x < 0) { count += x; if (count <= 0) { AggMemMx.MemClear(covers, coversIndex, num_pix); return; } AggMemMx.MemClear(covers, coversIndex, -x); coversIndex -= x; x = 0; } if (x + count > xmax) { int rest = x + count - xmax - 1; count -= rest; if (count <= 0) { AggMemMx.MemClear(covers, coversIndex, num_pix); return; } AggMemMx.MemClear(covers, coversIndex + count, rest); } int maskIndex = m_rbuf.GetByteBufferOffsetXY(x, y); unsafe { TempMemPtr maskPtr = m_rbuf.GetBufferPtr(); byte * mask = (byte *)maskPtr.Ptr; do { covers[coversIndex++] = mask[maskIndex++]; }while (--count != 0); maskPtr.Release(); } }
void CopyFromNoClipping(IImageReaderWriter sourceImage, RectInt clippedSourceImageRect, int destXOffset, int destYOffset) { if (BytesBetweenPixelsInclusive != BitDepth / 8 || sourceImage.BytesBetweenPixelsInclusive != sourceImage.BitDepth / 8) { throw new Exception("WIP we only support packed pixel formats at this time."); } if (BitDepth == sourceImage.BitDepth) { int lengthInBytes = clippedSourceImageRect.Width * BytesBetweenPixelsInclusive; int sourceOffset = sourceImage.GetBufferOffsetXY(clippedSourceImageRect.Left, clippedSourceImageRect.Bottom); byte[] sourceBuffer = sourceImage.GetBuffer(); byte[] destBuffer = GetBuffer(); int destOffset = GetBufferOffsetXY(clippedSourceImageRect.Left + destXOffset, clippedSourceImageRect.Bottom + destYOffset); for (int i = 0; i < clippedSourceImageRect.Height; i++) { AggMemMx.memmove(destBuffer, destOffset, sourceBuffer, sourceOffset, lengthInBytes); sourceOffset += sourceImage.Stride; destOffset += Stride; } } else { bool haveConversion = true; switch (sourceImage.BitDepth) { case 24: switch (BitDepth) { case 32: { int numPixelsToCopy = clippedSourceImageRect.Width; for (int i = clippedSourceImageRect.Bottom; i < clippedSourceImageRect.Top; i++) { int sourceOffset = sourceImage.GetBufferOffsetXY(clippedSourceImageRect.Left, clippedSourceImageRect.Bottom + i); byte[] sourceBuffer = sourceImage.GetBuffer(); byte[] destBuffer = GetBuffer(); int destOffset = GetBufferOffsetXY(clippedSourceImageRect.Left + destXOffset, clippedSourceImageRect.Bottom + i + destYOffset); for (int x = 0; x < numPixelsToCopy; x++) { destBuffer[destOffset++] = sourceBuffer[sourceOffset++]; destBuffer[destOffset++] = sourceBuffer[sourceOffset++]; destBuffer[destOffset++] = sourceBuffer[sourceOffset++]; destBuffer[destOffset++] = 255; } } } break; default: haveConversion = false; break; } break; default: haveConversion = false; break; } if (!haveConversion) { throw new NotImplementedException("You need to write the " + sourceImage.BitDepth.ToString() + " to " + BitDepth.ToString() + " conversion"); } } }