Exemplo n.º 1
0
        public static DcCategoryEncodedPair CalculateDifferenceDc(ColorChannel channel, int i)
        {
            int result = (int)channel.GetBlock(i)[0, 0];

            if (i != 0)
            {
                result = (int)channel.GetBlock(i)[0, 0] - (int)channel.GetBlock(i - 1)[0, 0];
            }

            return(new DcCategoryEncodedPair(AbstractCategoryEncodedPair.CalculateCategory(result),
                                             AbstractCategoryEncodedPair.EncodeCategory(result)));
        }
Exemplo n.º 2
0
 private void QuantizeChannel(ColorChannel channel, DoubleMatrix quantizationTable)
 {
     for (int i = 0; i < channel.GetNumOfBlocks(); i++)
     {
         CosineTransformation.Quantize(channel.GetBlock(i), quantizationTable);
     }
 }
Exemplo n.º 3
0
        private CountdownEvent TransformChannel(ColorChannel channel)
        {
            CountdownEvent e          = new CountdownEvent(1);
            int            blockCount = channel.GetNumOfBlocks();

            if (blockCount < 500 >> 4)
            {
                for (int i = 0; i < channel.GetNumOfBlocks(); i++)
                {
                    Arai.Calc(channel.GetBlock(i));
                }
            }
            else
            {
                int threadCount = 8;

                if (blockCount < 1000 >> 4)
                {
                    threadCount = 4;
                }

                for (int i = 0; i < blockCount; i += blockCount / threadCount)
                {
                    e.AddCount();
                    ThreadPool.QueueUserWorkItem(
                        state =>
                    {
                        object[] inp = state as object[];

                        //Console.WriteLine($"Thread with block {(int) inp[0]} to block {(int) inp[1]} started...");

                        int upper = (int)inp[1];

                        for (int j = (int)inp[0]; j < upper; j++)
                        {
                            Arai.Calc(channel.GetBlock(j));
                        }

                        e.Signal();
                    }, new object[] { i, i + (blockCount / threadCount) });
                }
            }

            e.Signal();
            return(e);
        }
Exemplo n.º 4
0
        public static List <AcCategoryEncodedPair> GetAllACs(ColorChannel channel)
        {
            List <AcCategoryEncodedPair> result = new List <AcCategoryEncodedPair>();

            for (int i = 0; i < channel.GetNumOfBlocks(); i++)
            {
                DoubleMatrix block = channel.GetBlock(i);
                List <AcRunlengthEncodedPair> runLengthEncodedBlock = EncodeRunlength(Util.ZigzagSort(block));
                List <AcCategoryEncodedPair>  categoryEncodedBlock  = EncodeCategoriesAc(runLengthEncodedBlock);
                result.AddRange(categoryEncodedBlock);
            }

            return(result);
        }
Exemplo n.º 5
0
        private void WriteAcDcEncodedBlock(ColorChannel channel, int xOfChannel, int yOfChannel,
                                           Dictionary <int, CodeWord> dcCodeBook,
                                           Dictionary <int, CodeWord> acCodeBook)
        {
            DcCategoryEncodedPair dc = AcDcEncoder.CalculateDifferenceDc(channel,
                                                                         channel
                                                                         .GetPlainIndexOfBlock(
                                                                             xOfChannel,
                                                                             yOfChannel));

            List <AcRunlengthEncodedPair> acRunLengthEncodedPairs =
                AcDcEncoder.EncodeRunlength(Util.ZigzagSort(channel.GetBlock(xOfChannel,
                                                                             yOfChannel)));
            List <AcCategoryEncodedPair> acCategoryEncodedPairs = AcDcEncoder.EncodeCategoriesAc(
                acRunLengthEncodedPairs);

            AcDcEncoder.WriteDcCoefficient(BitStream, dc, dcCodeBook);
            AcDcEncoder.WriteAcCoefficients(BitStream, acCategoryEncodedPairs, acCodeBook);
        }