Have two pointers (byte*) to 1. B8G8R8A8 pixel data 2. byte buffer to put cropped pixel data, very simple issue. Here is my implementation:
private unsafe void Crop(byte* src, byte* dst, Rectangle rSrc, Rectangle rDst)
{
int sSrc = 4 * rSrc.Width, sDst = 4 * rDst.Width; // stride
for (int x = 0; x < rDst.Width; x++) for (int y = 0; y < rDst.Height; y++)
{
dst[(x * 4 + y * (sDst)) + 0] = src[((rDst.X + x) * 4 + (rDst.Y + y) * (sSrc)) + 0];
dst[(x * 4 + y * (sDst)) + 1] = src[((rDst.X + x) * 4 + (rDst.Y + y) * (sSrc)) + 1];
dst[(x * 4 + y * (sDst)) + 2] = src[((rDst.X + x) * 4 + (rDst.Y + y) * (sSrc)) + 2];
dst[(x * 4 + y * (sDst)) + 3] = src[((rDst.X + x) * 4 + (rDst.Y + y) * (sSrc)) + 3];
}
}
And it works: ~ 100ms for 1920x1080, but need ~ 10 - 15 ms. Is it possible to make it faster? For example plain copy (without crop) provides much better performance 8 ms (for the same resolution), here is function:
private unsafe void Copy(void* dst, void* src, long count)
{
long block; block = count >> 3;
long* pDst = (long*)dst; long* pSrc = (long*)src;
{
for (int i = 0; i < block; i++) { *pDst = *pSrc; pDst++; pSrc++; }
}
}
Need your thoughts!
Thanks.