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

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

            for (int i = 0; i < testCount + testsToSkip; i++)
            {
                watch.Restart();
                sbyte[] outY  = new sbyte[width * height];
                sbyte[] outCb = new sbyte[width * height];
                sbyte[] outCr = new sbyte[width * height];

                unsafe
                {
                    fixed(sbyte *pData = data)
                    fixed(sbyte *pOutY  = outY)
                    fixed(sbyte *pOutCb = outCb)
                    fixed(sbyte *pOutCr = outCr)
                    {
                        Pixel *pPix = (Pixel *)pData;

                        InterWaveTransform.Rgb2YCbCr(pPix, width, height, width * bytesPerPixel, pOutY, pOutCb, pOutCr, width);
                    }
                }
                watch.Stop();
                if (i >= testsToSkip)
                {
                    time += watch.ElapsedMilliseconds;
                }
            }

            Console.WriteLine($"Optimized Rgb2YCbCr conversion time ms {((double)time / testCount).ToString("0#.000")}");
        }
Exemple #2
0
        public static IPixelMap PixelMapFromBitmap(System.Drawing.Bitmap bmp)
        {
            IPixelMap  pixMap = PixelMapTests.CreateInitVerifyPixelMap(bmp.Width, bmp.Height, Pixel.WhitePixel);
            BitmapData data   = null;

            try
            {
                data = bmp.LockBits(new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
                unsafe
                {
                    // TODO: Fix me!
                    fixed(sbyte *dest = pixMap.Data)
                    MemoryUtilities.MoveMemory(dest, (void *)data.Scan0, pixMap.Data.Length);
                }
            }
            catch (Exception ex)
            {
                throw new DjvuAggregateException(
                          $"Error with bitmap. Width: {bmp.Width}, Height: {bmp.Height}, PixelFormat: {bmp.PixelFormat}", ex);
            }
            finally
            {
                if (data != null)
                {
                    bmp.UnlockBits(data);
                }
            }
            return(pixMap);
        }
Exemple #3
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")}");
        }