Exemplo n.º 1
0
        private static CciHeader IntepretBinHeader(byte[] headerData)
        {
            var cciHeader = new CciHeader();

            cciHeader.X = (ushort)((headerData[0] << 8) + headerData[1]);
            cciHeader.Y = headerData[2];

            return(cciHeader);
        }
Exemplo n.º 2
0
        public void PerformNibbleCompression(string filePath)
        {
            Data = File.ReadAllBytes(filePath);

            //extract the first 3 bytes as X,Y size information. This is needed for the destination compressed format
            const int binFileHeaderSize = 3;
            var       headerData        = Data.Take(binFileHeaderSize).ToArray();

            CompressedFileHeader = IntepretBinHeader(headerData);
            Data = Data.Skip(binFileHeaderSize).ToArray();

            CreateCompressedNibbleData();

            var compressedDataBytes = CompressData.Count;

            Console.WriteLine("Compressed Data: {0} bytes", compressedDataBytes);
            const int paletteSize = 3 * 16;

            Console.WriteLine("Palette Data: {0} bytes", paletteSize);
            Console.WriteLine("All Data: {0} bytes", compressedDataBytes + paletteSize);

            // write all data to output file
            var fullPath = Path.GetFullPath(filePath);

            outputFileName = Path.GetDirectoryName(fullPath) + "\\" + Path.GetFileNameWithoutExtension(fullPath) + ".cci";
            var outputFileData = new List <byte>();

            var outputBytes = ConvertCompressNibbleDataToBytes().ToList();

            CompressedFileHeader.FileSize = (ushort)(outputBytes.Count);

            outputFileData.AddRange(CompressedFileHeader.GetRawRepresentation());
            outputFileData.AddRange(outputBytes);

            File.WriteAllBytes(outputFileName, outputFileData.ToArray());

            // make reference decompresssion and compare result
            var refimage = ReferenceNibbleDecompressImage();

            if (refimage.Count != Data.Length)
            {
                Console.WriteLine("incorrect size of reference decompression!");
            }

            for (int i = 0; i < refimage.Count; i++)
            {
                if (refimage[i] != Data[i])
                {
                    Console.WriteLine("Data error! Not same data in reference decompression at {0}!", i);
                    return;
                }
            }

            Console.WriteLine("Exact match of reference data!");
        }