public unsafe void Rgb2YTest() { Pixel3B[] pixBuffer = new Pixel3B[256]; for (int i = 0; i < pixBuffer.Length; i++) { pixBuffer[i].SetGray((byte)i); } GCHandle hPix = GCHandle.Alloc(pixBuffer, GCHandleType.Pinned); byte * pByteBuff = (byte *)hPix.AddrOfPinnedObject(); int[] gammaLUT = PixelMap.GetGammaCorrection(2.2); GCHandle hGamma = GCHandle.Alloc(gammaLUT, GCHandleType.Pinned); int * pGammaLUT = (int *)hGamma.AddrOfPinnedObject(); int dataLength = pixBuffer.Length * 3; dataLength -= dataLength % 48; PixelMap.ApllyGamma(pByteBuff, pixBuffer.Length * 3, dataLength, pGammaLUT); hPix.Free(); hGamma.Free(); sbyte[] outBuff = new sbyte[256]; unsafe { fixed(Pixel3B *p = pixBuffer) fixed(sbyte *pOutBuff = outBuff) { Pixel *pBuff = (Pixel *)p; sbyte *pOut = pOutBuff; byte * pB = (byte *)p; InterWaveTransform.Rgb2Y(pBuff, 16, 16, 16 * 3, pOut, 16); } } int outLength = outBuff.Length - 1; for (int i = 0; i < outLength; i++) { //Console.WriteLine(unchecked((byte)outBuff[i])); if (i > 0) { if (i < 94) { Assert.True(unchecked ((byte)outBuff[i]) <= unchecked ((byte)outBuff[i + 1])); } Assert.NotEqual(0, unchecked ((byte)outBuff[i])); } } }
public void Rgb2YCbCr() { Pixel3B[] buffer = new Pixel3B[1920 * 1080]; GCHandle hBuffer = GCHandle.Alloc(buffer, GCHandleType.Pinned); IntPtr pBuffer = hBuffer.AddrOfPinnedObject(); GenerateRandomBuffer(pBuffer, buffer.Length * Marshal.SizeOf <Pixel3B>()); IntPtr result = ColorSpace.Rgb2YCbCr(pBuffer, PixelFormat.BGR24); if (hBuffer.IsAllocated) { hBuffer.Free(); } }