public static int[] CopyImgBuffer(ActualImage img, int width) { //calculate stride for the width int destStride = ActualImage.CalculateStride(width, PixelFormat.ARGB32); int h = img.Height; int newBmpW = destStride / 4; int[] buff2 = new int[newBmpW * img.Height]; unsafe { TempMemPtr srcBufferPtr = ActualImage.GetBufferPtr(img); byte * srcBuffer = (byte *)srcBufferPtr.Ptr; int srcIndex = 0; int srcStride = img.Stride; fixed(int *destHead = &buff2[0]) { byte *destHead2 = (byte *)destHead; for (int line = 0; line < h; ++line) { //System.Runtime.InteropServices.Marshal.Copy(srcBuffer, srcIndex, (IntPtr)destHead2, destStride); NaitveMemMx.memcpy((byte *)destHead2, srcBuffer + srcIndex, destStride); srcIndex += srcStride; destHead2 += destStride; } } srcBufferPtr.Release(); } return(buff2); }
//-------------------------------------------------------------------- public byte pixel(int x, int y) { unsafe { int bufferIndex = m_rbuf.GetByteBufferOffsetXY(x, y); TempMemPtr tmpMem = m_rbuf.GetBufferPtr(); byte value = *((byte *)tmpMem.Ptr + bufferIndex); tmpMem.Release(); return(value); } }
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(); } }
public static int[] CopyImgBuffer(ActualImage img) { int[] buff2 = new int[img.Width * img.Height]; unsafe { //byte[] pixelBuffer = ActualImage.GetBuffer(img); TempMemPtr pixBuffer = ActualImage.GetBufferPtr(img); //fixed (byte* header = &pixelBuffer[0]) byte *header = (byte *)pixBuffer.Ptr; { System.Runtime.InteropServices.Marshal.Copy((IntPtr)header, buff2, 0, buff2.Length);//length in bytes } pixBuffer.Release(); } return(buff2); }
public void combine_hspan(int x, int y, byte[] covers, int coversIndex, int count) { unsafe { int maskIndex = m_rbuf.GetByteBufferOffsetXY(x, y); TempMemPtr maskPtr = m_rbuf.GetBufferPtr(); byte *mask = (byte *)maskPtr.Ptr; do { covers[coversIndex] = (byte)((255 + (covers[coversIndex]) * mask[maskIndex]) >> 8); coversIndex++; maskIndex++; }while (--count != 0); maskPtr.Release(); } }
public void combine_hspanFullCover(int x, int y, byte[] covers, int coversIndex, int count) { int maskIndex = m_rbuf.GetByteBufferOffsetXY(x, y); unsafe { TempMemPtr memPtr = m_rbuf.GetBufferPtr(); byte * m = ((byte *)memPtr.Ptr + maskIndex); do { covers[coversIndex++] = *m; //[maskIndex++]; m++; //move to next }while (--count != 0); memPtr.Release(); } //byte[] mask = m_rbuf.GetBuffer(); //do //{ // covers[coversIndex++] = mask[maskIndex++]; //} //while (--count != 0); }
//-------------------------------------------------------------------- public byte pixel(int x, int y) { unchecked { if ((uint)x < (uint)m_rbuf.Width && (uint)y < (uint)m_rbuf.Height) { unsafe { int bufferIndex = m_rbuf.GetByteBufferOffsetXY(x, y); TempMemPtr tmpMem = m_rbuf.GetBufferPtr(); byte value = *((byte *)tmpMem.Ptr + bufferIndex); tmpMem.Release(); return(value); } //int bufferIndex = m_rbuf.GetByteBufferOffsetXY(x, y); //byte[] buffer = m_rbuf.GetBuffer(); //return buffer[bufferIndex]; } } return(0); }
public static int[] CopyImgBuffer(ActualImage src, int srcX, int srcY, int srcW, int srcH) { //calculate stride for the width int destStride = ActualImage.CalculateStride(srcW, PixelFormat.ARGB32); int newBmpW = destStride / 4; int[] buff2 = new int[newBmpW * srcH]; unsafe { TempMemPtr srcBufferPtr = ActualImage.GetBufferPtr(src); byte * srcBuffer = (byte *)srcBufferPtr.Ptr; int srcIndex = 0; int srcStride = src.Stride; fixed(int *destHead = &buff2[0]) { byte *destHead2 = (byte *)destHead; //move to specific src line srcIndex += srcStride * srcY; int lineEnd = srcY + srcH; for (int line = srcY; line < lineEnd; ++line) { //System.Runtime.InteropServices.Marshal.Copy(srcBuffer, srcIndex, (IntPtr)destHead2, destStride); NaitveMemMx.memcpy((byte *)destHead2, srcBuffer + srcIndex, destStride); srcIndex += srcStride; destHead2 += destStride; } } srcBufferPtr.Release(); } return(buff2); }
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.GetByteBufferOffsetXY(clippedSourceImageRect.Left, clippedSourceImageRect.Bottom); unsafe { TempMemPtr memPtr = sourceImage.GetBufferPtr(); TempMemPtr destPtr = this.GetBufferPtr(); byte *sourceBuffer = (byte *)memPtr.Ptr; byte *destBuffer = (byte *)destPtr.Ptr; int destOffset = GetByteBufferOffsetXY(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; } memPtr.Release(); destPtr.Release(); } } else { bool haveConversion = true; switch (sourceImage.BitDepth) { case 24: switch (BitDepth) { case 32: { //TODO: review here, this may not correct int numPixelsToCopy = clippedSourceImageRect.Width; for (int i = clippedSourceImageRect.Bottom; i < clippedSourceImageRect.Top; i++) { int sourceOffset = sourceImage.GetByteBufferOffsetXY(clippedSourceImageRect.Left, clippedSourceImageRect.Bottom + i); //byte[] sourceBuffer = sourceImage.GetBuffer(); //byte[] destBuffer = GetBuffer(); TempMemPtr srcMemPtr = sourceImage.GetBufferPtr(); TempMemPtr destBufferPtr = this.GetBufferPtr(); int destOffset = GetByteBufferOffsetXY( clippedSourceImageRect.Left + destXOffset, clippedSourceImageRect.Bottom + i + destYOffset); unsafe { byte *destBuffer = (byte *)destBufferPtr.Ptr; byte *sourceBuffer = (byte *)srcMemPtr.Ptr; for (int x = 0; x < numPixelsToCopy; x++) { destBuffer[destOffset++] = sourceBuffer[sourceOffset++]; destBuffer[destOffset++] = sourceBuffer[sourceOffset++]; destBuffer[destOffset++] = sourceBuffer[sourceOffset++]; destBuffer[destOffset++] = 255; } } srcMemPtr.Release(); destBufferPtr.Release(); } } 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"); } } }
public static TempMemPtr GetBufferPtr(ActualImage img) { TempMemPtr tmp = new TempMemPtr(img.pixelBuffer); return(tmp); }
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.GetByteBufferOffsetXY(x, y); unsafe { TempMemPtr maskPtr = m_rbuf.GetBufferPtr(); byte * maskHead = (byte *)maskPtr.Ptr; 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); } maskPtr.Release(); } }
public void Fill(ImageReaderWriterBase bufferToFillOn, int x, int y) { y -= imageHeight; 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; } } _destImgRW = bufferToFillOn; TempMemPtr destBufferPtr = bufferToFillOn.GetBufferPtr(); unsafe { imageWidth = bufferToFillOn.Width; imageHeight = bufferToFillOn.Height; //reset new buffer, clear mem? pixelsChecked = new bool[imageWidth * imageHeight]; int *destBuffer = (int *)destBufferPtr.Ptr; int startColorBufferOffset = bufferToFillOn.GetBufferOffsetXY32(x, y); int start_color = *(destBuffer + startColorBufferOffset); fillRule.SetStartColor(Drawing.Color.FromArgb( (start_color >> 16) & 0xff, (start_color >> 8) & 0xff, (start_color) & 0xff)); LinearFill(destBuffer, 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 = bufferToFillOn.GetBufferOffsetXY32(rangeX, downY); if (fillRule.CheckPixel(*(destBuffer + bufferOffset))) { LinearFill(destBuffer, rangeX, downY); } } } if (range.y < (imageHeight - 1)) { if (!pixelsChecked[upPixelOffset]) { int bufferOffset = bufferToFillOn.GetBufferOffsetXY32(rangeX, upY); if (fillRule.CheckPixel(*(destBuffer + bufferOffset))) { LinearFill(destBuffer, rangeX, upY); } } } upPixelOffset++; downPixelOffset++; } } } destBufferPtr.Release(); }