Beispiel #1
0
        /// <summary>
        /// Constructor for huffamn encoded image frame
        /// </summary>
        /// <param name="compressedBits">Compressed bits count</param>
        /// <param name="colorCodes">Color code count</param>
        /// <param name="maxCodeBitsLength">Longest bit length</param>
        /// <param name="originalImageDataLength">Original image header length</param>
        /// <param name="originalImageHeader">Original image header</param>
        public HuffmanImageFrame(int compressedBits, HeaderColorItem[] colorCodes, int maxCodeBitsLength, int originalImageDataLength, byte[] originalImageHeader)
        {
            var imageDataTotalLength = _calculateImageDataTotalSize(compressedBits);

            CompressedBits            = compressedBits;
            MaxCodeBitsLength         = maxCodeBitsLength;
            ColorCodeCount            = colorCodes.Length;
            OriginalImageHeaderLength = originalImageHeader.Length;
            OriginalImageDataLength   = originalImageDataLength;

            var totalBytes = FixedHeaderLength + ColorCodeHeaderLength + OriginalImageHeaderLength + imageDataTotalLength;

            Data = new byte[totalBytes];

            CompressedBits.AsBytes().CopyBytesTo(Data, HEADER_COMPRESSED_BITS_BYTES_POS);
            MaxCodeBitsLength.AsBytes().CopyBytesTo(Data, HEADER_MAX_CODE_BITS_BYTES_POS);
            ColorCodeCount.AsBytes().CopyBytesTo(Data, HEADER_COLOR_CODE_COUNT_BYTES_POS);
            OriginalImageHeaderLength.AsBytes().CopyBytesTo(Data, HEADER_ORIGINAL_IMAGE_HEADER_BYTES_POS);
            OriginalImageDataLength.AsBytes().CopyBytesTo(Data, HEADER_ORIGINAL_IMAGE_DATA_BYTES_POS);

            for (int i = 0; i < colorCodes.Length; i++)
            {
                var colorCode   = colorCodes[i];
                var headerIndex = i * HeaderColorItem.GetBytesLength() + FixedHeaderLength;
                Data[headerIndex++] = (byte)colorCode.Symbol;
                Data[headerIndex++] = (byte)colorCode.CodeBitsCount;
                ((uint)(colorCode.Code)).AsBytes().CopyBytesTo(Data, headerIndex);
            }

            originalImageHeader.CopyBytesTo(Data, FixedHeaderLength + ColorCodeHeaderLength);
        }
Beispiel #2
0
        /// <summary>
        /// Reads color code item from header from given index
        /// </summary>
        /// <param name="index">Color code index</param>
        /// <returns>Color code from given index</returns>
        public HeaderColorItem GetColorCodeItemFromHeader(int index)
        {
            var colorStartIndex = index * HeaderColorItem.GetBytesLength() + FixedHeaderLength;

            return(new HeaderColorItem(Data, colorStartIndex));
        }