unsafe private static void A8R8G8B8toB8G8R8(PixelBox src, PixelBox dst) { uint * srcptr = (uint *)(src.Data.ToPointer()); Col3b *dstptr = (Col3b *)(dst.Data.ToPointer()); int srcSliceSkip = src.SliceSkip; int dstSliceSkip = dst.SliceSkip; int k = src.Right - src.Left; for (int z = src.Front; z < src.Back; z++) { for (int y = src.Top; y < src.Bottom; y++) { for (int x = 0; x < k; x++) { uint inp = srcptr[x]; dstptr[x].x = (byte)((inp >> 0) & 0xFF); dstptr[x].y = (byte)((inp >> 8) & 0xFF); dstptr[x].z = (byte)((inp >> 16) & 0xFF); } srcptr += src.RowPitch; dstptr += dst.RowPitch; } srcptr += srcSliceSkip; dstptr += dstSliceSkip; } }
unsafe private static void R8G8B8toB8G8R8A8(PixelBox src, PixelBox dst) { Col3b *srcptr = (Col3b *)(src.Data.ToPointer()); uint * dstptr = (uint *)(dst.Data.ToPointer()); int xshift = 8; int yshift = 16; int zshift = 24; int ashift = 0; int srcSliceSkip = src.SliceSkip; int dstSliceSkip = dst.SliceSkip; int k = src.Right - src.Left; for (int z = src.Front; z < src.Back; z++) { for (int y = src.Top; y < src.Bottom; y++) { for (int x = 0; x < k; x++) { Col3b inp = srcptr[x]; #if BIG_ENDIAN dstptr[x] = ((uint)(0xFF << ashift)) | (((uint)inp.x) << xshift) | (((uint)inp.y) << yshift) | (((uint)inp.z) << zshift); #else dstptr[x] = ((uint)(0xFF << ashift)) | (((uint)inp.x) << zshift) | (((uint)inp.y) << yshift) | (((uint)inp.z) << xshift); #endif } srcptr += src.RowPitch; dstptr += dst.RowPitch; } srcptr += srcSliceSkip; dstptr += dstSliceSkip; } }
unsafe private static void B8G8R8toR8G8B8(PixelBox src, PixelBox dst) { Col3b *srcptr = (Col3b *)(src.Data.ToPointer()); Col3b *dstptr = (Col3b *)(dst.Data.ToPointer()); int srcSliceSkip = src.SliceSkip; int dstSliceSkip = dst.SliceSkip; int k = src.Right - src.Left; for (int z = src.Front; z < src.Back; z++) { for (int y = src.Top; y < src.Bottom; y++) { for (int x = 0; x < k; x++) { Col3b inp = srcptr[x]; dstptr[x].x = inp.z; dstptr[x].y = inp.y; dstptr[x].z = inp.x; } srcptr += src.RowPitch; dstptr += dst.RowPitch; } srcptr += srcSliceSkip; dstptr += dstSliceSkip; } }