Example #1
0
        public void Rgb2YCbCrFragmentedTest()
        {
            sbyte[] data = PixelMapTests.GetRandomData(width, height, bytesPerPixel);

            long      time  = 0;
            Stopwatch watch = new Stopwatch();

            sbyte[] outY  = new sbyte[width * height];
            sbyte[] outCb = new sbyte[width * height];
            sbyte[] outCr = new sbyte[width * height];

            for (int i = 0; i < testCount; i++)
            {
                watch.Restart();
                unsafe
                {
                    GCHandle hData  = GCHandle.Alloc(data, GCHandleType.Pinned);
                    GCHandle hOutY  = GCHandle.Alloc(outY, GCHandleType.Pinned);
                    GCHandle hOutCb = GCHandle.Alloc(outCb, GCHandleType.Pinned);
                    GCHandle hOutCr = GCHandle.Alloc(outCr, GCHandleType.Pinned);
                    sbyte *  pY     = (sbyte *)hOutY.AddrOfPinnedObject();
                    sbyte *  pCb    = (sbyte *)hOutCb.AddrOfPinnedObject();
                    sbyte *  pCr    = (sbyte *)hOutCr.AddrOfPinnedObject();
                    Pixel *  pPix   = (Pixel *)hData.AddrOfPinnedObject();

                    InterWaveTransform.Rgb2Y(pPix, width, height, width * bytesPerPixel, pY, width);
                    InterWaveTransform.Rgb2Cb(pPix, width, height, width * bytesPerPixel, pCb, width);
                    InterWaveTransform.Rgb2Cr(pPix, width, height, width * bytesPerPixel, pCr, width);

                    hData.Free();
                    hOutY.Free();
                    hOutCb.Free();
                    hOutCr.Free();
                }
                watch.Stop();
                if (i >= testsToSkip)
                {
                    time += watch.ElapsedMilliseconds;
                }
            }

            Console.WriteLine($"Fragmented Rgb2YCbCr conversion time ms {((double)time / testCount).ToString("0#.000")}");
        }
Example #2
0
        public void Rgb2CbTest()
        {
            Pixel[] pixBuffer = new Pixel[256];
            for (int i = 0; i < pixBuffer.Length; i++)
            {
                pixBuffer[i].SetGray((sbyte)(i - 128));
            }

            sbyte[] outBuff = new sbyte[256];

            unsafe
            {
                fixed(Pixel *p = pixBuffer)
                fixed(sbyte *pOutBuff = outBuff)
                {
                    Pixel *pBuff = p;
                    sbyte *pOut  = pOutBuff;

                    InterWaveTransform.Rgb2Cb(pBuff, 16, 16, 16 * 3, pOut, 16);
                }
            }

            int outLength = outBuff.Length - 1;

            for (int i = 0; i < outLength; i++)
            {
                //Console.WriteLine($"i: {i}, Y: {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]));
                }
            }
        }