コード例 #1
0
        public void Decode(ArithmeticDecoder decoder, long budget)
        {
            _decoder = decoder;
            _budget  = budget;

            Init();

            int thresholdBits = _decoder.DecodeSymbol(_thresholdModel);

            for (; thresholdBits >= 0; thresholdBits--)
            {
                _threshold = 1 << thresholdBits;

                if (!SortingPass1() || (_decoder.EofFlag))
                {
                    break;
                }
                if (!SortingPass2() || (_decoder.EofFlag))
                {
                    break;
                }
                if (!RefinementPass() || (_decoder.EofFlag))
                {
                    break;
                }

                GC.Collect();
            }

            EndDecoding();
        }
コード例 #2
0
        public CoefficientDecoder(CodeBlock codeBlock, byte[] bytes)
        {
            CodeBlock = codeBlock;

            Width  = codeBlock.Bounds.Width;
            Height = codeBlock.Bounds.Height;

            CoefficientArray = new Coefficient[(Width + 2) * (Height + 2)];

            for (int y = -1; y < Height + 1; y++)
            {
                for (int x = -1; x < Width + 1; x++)
                {
                    CoefficientArray[GetCoefficientIndex(x, y)] = new Coefficient();
                }
            }

            EntropyCoder = new ArithmeticDecoder(bytes, 0);

            ContextArray = new Context[Context.Count];
        }
コード例 #3
0
        public CabacSliceData(INalUnitReader reader, IState readerState)
        {
            _reader        = reader;
            _readerState   = readerState;
            _sliceState    = reader.State.SliceState;
            _pictureState  = _sliceState.PictureState;
            _sequenceState = _pictureState.SequenceState;
            _unavailableMacroblockState = _sliceState.IntraCoded
                                                        ? MacroblockState.UnavailableIntraCoded
                                                        : MacroblockState.UnavailableInterCoded;
            _macroblockStates  = new MacroblockState[PicSizeInMbs];
            _motionFieldL0     = IsList0Predicted ? new MotionField(_sliceState) : null;
            _motionFieldL1     = IsList1Predicted ? new MotionField(_sliceState) : null;
            _subMbTypes        = new ISubMacroblockType[4];
            _arithmeticDecoder = new ArithmeticDecoder(reader);

            for (int i = 0; i < _macroblockStates.Length; i++)
            {
                _macroblockStates[i] = _unavailableMacroblockState;
            }

            MbToSliceGroupMap = _mbToSliceGroup.CreateMacroBlockToSliceGroupMap(_sliceState);
        }
コード例 #4
0
        private static void CompressTest(HyperspectralImage image, string tempPath, string restoredPath, double compression)
        {
            var sw = new Stopwatch();

            sw.Start();

            IntPtr tempData     = Marshal.AllocHGlobal(image.SizeInBytes());
            IntPtr restoredData = Marshal.AllocHGlobal(image.SizeInBytes());

            var wavelet = new WaveletTransformationController(new Wavelet53RTransformation());

            wavelet.Encode3D(image.ToPointer(), image.ImageInfo.Width, image.ImageInfo.Height, image.ImageInfo.Bands,
                             image.ImageInfo.Width, image.ImageInfo.Height, 0, tempData);


            var budget = (long)(compression * image.SizeInBytes() * 8);

            using (var stream = File.Open(tempPath, FileMode.Create))
            {
                var coder      = new ArithmeticCoder(stream);
                var compressor = new Spiht3DCoder(tempData,
                                                  image.ImageInfo.Width,
                                                  image.ImageInfo.Height,
                                                  image.ImageInfo.Bands);

                compressor.Encode(coder, budget);
            }
            GC.Collect();

            using (var stream = File.Open(tempPath, FileMode.Open))
            {
                var decoder      = new ArithmeticDecoder(stream);
                var decompressor = new Spiht3DDecoder(tempData,
                                                      image.ImageInfo.Width,
                                                      image.ImageInfo.Height,
                                                      image.ImageInfo.Bands);

                decompressor.Decode(decoder, budget);
            }
            GC.Collect();



            wavelet.Decode3D(tempData, image.ImageInfo.Width, image.ImageInfo.Height, image.ImageInfo.Bands,
                             image.ImageInfo.Width, image.ImageInfo.Height, 0, restoredData);

            using (var stream = File.Open(restoredPath, FileMode.Create))
            {
                HyperspectralImage.Save(HyperspectralImage.Load(restoredData, image.ImageInfo), stream);
            }

            Console.WriteLine("Compression 1:{0}. PSNR = {1}", 1 / compression, PSNRCalculator.Calculate(image.ToPointer(), restoredData, image.ImageInfo));
            Console.WriteLine("Compression 1:{0}. MSE = {1}", 1 / compression, PSNRCalculator.CalculateMSE(image.ToPointer(), restoredData, image.ImageInfo));
            sw.Stop();

            Console.WriteLine("{0}:{1} (Ticks: {2})", sw.Elapsed.Seconds, sw.Elapsed.Milliseconds, sw.ElapsedTicks);


            Marshal.FreeHGlobal(tempData);
            Marshal.FreeHGlobal(restoredData);
        }