Esempio n. 1
0
        public static void WriteBlock(
            BitStream jpegStream,
            DCEncode dcValue,
            List <ACEncode> acValues,
            HuffmanTree dcTree,
            HuffmanTree acTree
            )
        {
            // encode dc value of block
            {
                //write huffman encoded category into bit stream
                dcTree.EncodeInt(dcValue.Category, jpegStream);
                // write bit pattern for value, provide category for length
                if (dcValue.Category != 0)
                {
                    jpegStream.writeBits(dcValue.BitPattern, dcValue.Category);
                }
            }

            // encode ac values of block
            acValues.ForEach(acValue =>
            {
                acTree.EncodeInt(acValue.Flag, jpegStream);
                if (acValue.Category != 0)
                {
                    jpegStream.writeBits(acValue.BitPattern, acValue.Category);
                }
            });
        }
Esempio n. 2
0
        public static (DCEncode[], List <ACEncode>[]) ChannelToArrayY(List <DCEncode> dcValues, List <List <ACEncode> > acValues, int length)
        {
            DCEncode[]        dcArray = dcValues.ToArray();
            List <ACEncode>[] acArray = acValues.ToArray();

            int amountBlocks = dcArray.Length; // dc length = ac length

            DCEncode[]        dcResult = new DCEncode[amountBlocks];
            List <ACEncode>[] acResult = new List <ACEncode> [amountBlocks];

            int index = 0;

            for (int i = 0; i < amountBlocks; i += 2)
            {
                if (((i / length) % 2) != 0)
                {
                    i += length - 2;
                    continue;
                }

                // [0] + [1] + [0 + length] + [1 + length]
                dcResult[index] = dcArray[i];
                acResult[index] = acArray[i];
                index++;

                dcResult[index] = dcArray[i + 1];
                acResult[index] = acArray[i + 1];
                index++;

                dcResult[index] = dcArray[i + length];
                acResult[index] = acArray[i + length];
                index++;

                dcResult[index] = dcArray[i + 1 + length];
                acResult[index] = acArray[i + 1 + length];
                index++;
            }

            return(dcArray, acArray);
        }