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; } }
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; } }
public void Convert(BufferBase input, BufferBase output, int offset) { #if !AXIOM_SAFE_ONLY unsafe #endif { var inputPtr = input.ToUIntPointer(); var outputPtr = output.ToCol3BPointer(); var inp = inputPtr[offset]; outputPtr[offset] = new Col3b { x = (byte)((inp >> 0) & 0xFF), y = (byte)((inp >> 8) & 0xFF), z = (byte)((inp >> 16) & 0xFF), }; } }