コード例 #1
0
ファイル: FCompressPicture.cs プロジェクト: whztt07/MoCross
        //============================================================
        // <T>导出多个打包到目录。</T>
        //
        // @param fileName 文件名称
        // @param widthCount 横向分割个数
        // @param hightCount 纵向分割个数
        //============================================================
        public void ExportPath(string path, int tileWidth, int tileHight, int colorCount, int widthCount, int hightCount)
        {
            // 计算分割数量
            int tileCx = _bitmap.Width / tileWidth;
            int tileCy = _bitmap.Height / tileHight;

            // 分割图片
            for (int y = 0; y < tileCy; y++)
            {
                for (int x = 0; x < tileCx; x++)
                {
                    // 绘制局部图形
                    FBitmap bitmap = new FBitmap(tileWidth, tileHight);
                    bitmap.Fill(_bitmap, tileWidth * x, tileHight * y);
                    // 存储索引图片
                    string fileName = path + "_" + RString.PadLeft(y.ToString(), 2, '0') + "_" + RString.PadLeft(x.ToString(), 2, '0') + "." + EXTEND_NAME;
                    _logger.Debug(this, "ExportPath", "Export path file. (file_name={0}, color_count={1}, width_count={2}, hight_count={3})",
                                  fileName, colorCount, widthCount, hightCount);

                    FLzmaFile file = new FLzmaFile();
                    file.EnsureSize(tileWidth * tileHight);
                    StoreCompress(file, bitmap.Native, colorCount, widthCount, hightCount);
                    file.Compress(fileName);
                    file.Reset();
                }
            }
        }
コード例 #2
0
ファイル: FCompressPicture.cs プロジェクト: whztt07/MoCross
        //============================================================
        // <T>导出打包文件。</T>
        //
        // @param fileName 文件名称
        // @param widthCount 横向分割个数
        // @param hightCount 纵向分割个数
        //============================================================
        public void ExportFile(string fileName, int colorCount, int widthCount, int hightCount)
        {
            _logger.Debug(this, "ExportFile", "Export file. (file_name={0}, color_count={1}, width_count={2}, hight_count={3})",
                          fileName, colorCount, widthCount, hightCount);
            // 创建压缩文件
            FLzmaFile file = new FLzmaFile();

            file.EnsureSize(_bitmap.Width * _bitmap.Height);
            StoreCompress(file, _bitmap, colorCount, widthCount, hightCount);
            file.Compress(fileName);
        }
コード例 #3
0
 //============================================================
 // <T>序列化位图数据。</T>
 //
 // @params output     输出流
 // @params colorCount 调色板颜色数量
 // @params pixelCount 分块的像素个数
 //============================================================
 public bool Compress(IOutput output, int compressCd, int colorCount, int pixelCount)
 {
     // 保存数据
     using (FByteStream stream = new FByteStream()) {
         Serialize(stream, colorCount, pixelCount);
         // 压缩数据
         byte[] data = null;
         if (compressCd == ERsCompress.NoneValue)
         {
             data = stream.ToArray();
         }
         else if (compressCd == ERsCompress.DeflateValue)
         {
             //using(FRsCompressFile compress = new FRsCompressFile(ERsCompress.Deflate, stream, RResourceManager.CompressBlockSplit)) {
             using (FCompressFile compress = new FCompressFile(stream)) {
                 data = compress.Compress();
             }
             if (data.Length > stream.Length)
             {
                 compressCd = ERsCompress.NoneValue;
                 data       = stream.ToArray();
             }
         }
         else if (compressCd == ERsCompress.LzmaValue)
         {
             using (FLzmaFile compress = new FLzmaFile(stream)) {
                 data = compress.CompressNative();
             }
             if (data.Length > stream.Length)
             {
                 compressCd = ERsCompress.NoneValue;
                 data       = stream.ToArray();
             }
         }
         output.WriteInt32(compressCd);
         output.WriteInt32(data.Length);
         output.WriteBytes(data, 0, data.Length);
     }
     return(true);
 }
コード例 #4
0
ファイル: FRsCompressFile.cs プロジェクト: whztt07/MoCross
        //============================================================
        // <T>压缩字节数据。</T>
        //
        // @return 字节数据
        //============================================================
        public byte[] CompressBytes()
        {
            byte[] data = null;
            // Deflate压缩
            string compressCd = _compressCd;

            switch (compressCd)
            {
            case ERsCompress.Deflate:
                using (FCompressFile file = new FCompressFile()) {
                    file.Append(_memory, 0, _length);
                    if (_blockSize > 0)
                    {
                        data = file.BlockCompress(_blockSize);
                    }
                    else
                    {
                        data = file.Compress();
                    }
                }
                break;

            case ERsCompress.Lzma:
                using (FLzmaFile file = new FLzmaFile()) {
                    file.Append(_memory, 0, _length);
                    if (_blockSize > 0)
                    {
                        data = file.BlockCompress(_blockSize);
                    }
                    else
                    {
                        data = file.Compress();
                    }
                }
                break;

            case ERsCompress.LzmaAlchemy:
                using (FLzmaFile file = new FLzmaFile()) {
                    file.Append(_memory, 0, _length);
                    if (_blockSize > 0)
                    {
                        data = file.BlockCompressNative(_blockSize);
                    }
                    else
                    {
                        data = file.CompressNative();
                    }
                }
                break;
            }
            // 检查大小,如果压缩后更大,则不压缩数据
            if (data.Length > _length)
            {
                data       = ToArray();
                compressCd = ERsCompress.None;
            }
            // 计算效验码
            _vertifyCode = RByte.ComputeHash32(data, 0, data.Length);
            // 写入文件
            byte[] result = null;
            using (FByteStream stream = new FByteStream()) {
                // 写入信息
                stream.WriteUint8((byte)ERsCompress.Parse(compressCd));
                stream.WriteInt32(_length);
                stream.WriteInt32(_vertifyCode);
                stream.WriteInt32(_blockSize);
                // 写入数据
                if ((ERsCompress.None != compressCd) && (_blockSize > 0))
                {
                    stream.WriteBytes(data, 0, data.Length);
                }
                else
                {
                    stream.WriteInt32(1);
                    stream.WriteInt32(data.Length);
                    stream.WriteBytes(data, 0, data.Length);
                }
                result = stream.ToArray();
            }
            return(result);
        }