コード例 #1
0
 public SendServerResponseCommand(Guid clientId, string response, ResponseTypes responseType, MessageHeader header)
 {
     _clientId = clientId;
     _response = response;
     _responseType = responseType;
     _compressionType = header.CompressionType;
     _encryptionType = header.EncryptionHeader.EncryptionType;
 }
コード例 #2
0
 public BroadcastMessageCommand(Guid[] clientList, string response, ResponseTypes responseType, MessageHeader header)
 {
     _clientList = clientList;
     _response = response;
     _responseType = responseType;
     _compressionType = header.CompressionType;
     _encryptionType = header.EncryptionHeader.EncryptionType;
 }
コード例 #3
0
 /// <summary>
 /// تبدیل تصویر
 /// </summary>
 /// <param name="image">تصویر</param>
 /// <param name="format">نوع</param>
 /// <param name="compressionType">فشرده سازی</param>
 /// <returns></returns>
 public static Image ConvertImage(Image image, ImageFormat format, CompressionTypes compressionType)
 {
     System.IO.MemoryStream ms = new System.IO.MemoryStream();
     if (compressionType == CompressionTypes.CompressionNone)
     {
         image.Save(ms, format);
     }
     else
     {
         EncoderParameters encoderParameters = new EncoderParameters(1);
         encoderParameters.Param[0] = new EncoderParameter(Encoder.Compression, (long)compressionType);
         image.Save(ms, GetImageCodecInfo(format), encoderParameters);
     }
     return(Image.FromStream(ms));
 }
コード例 #4
0
        public void Clear(params string[] cacheKeys)
        {
            this.cacheManager.Clear(cacheKeys);

            var contentTypeCacheKeys = cacheKeys.ToList().ConvertAll(x => x + MimeTypes.GetExtension(this.ContentType));

            foreach (var cacheKey in contentTypeCacheKeys)
            {
                var filePath        = Path.Combine(this.baseCachePath, cacheKey);
                var gzipFilePath    = Path.Combine(this.baseCachePath, cacheKey + CompressionTypes.GetExtension(CompressionTypes.GZip));
                var deflateFilePath = Path.Combine(this.baseCachePath, cacheKey + CompressionTypes.GetExtension(CompressionTypes.Deflate));

                DeleteFiles(filePath, gzipFilePath, deflateFilePath);
            }
        }
コード例 #5
0
 /// <summary>
 /// تبدیل تصویر
 /// </summary>
 /// <param name="image">تصویر</param>
 /// <param name="format">نوع</param>
 /// <param name="compressionType">فشرده سازی</param>
 /// <param name="saveTo">مسیر ذخیره</param>
 public static void ConvertImage(Image image, ImageFormat format, CompressionTypes compressionType, string saveTo)
 {
     using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
     {
         if (compressionType == CompressionTypes.CompressionNone)
         {
             image.Save(ms, format);
         }
         else
         {
             EncoderParameters encoderParameters = new EncoderParameters(1);
             encoderParameters.Param[0] = new EncoderParameter(Encoder.Compression, (long)compressionType);
             image.Save(ms, GetImageCodecInfo(format), encoderParameters);
         }
         System.IO.File.WriteAllBytes(saveTo, ms.ToArray());
     }
 }
コード例 #6
0
        public override string ToString()
        {
            CompressionTypes NoOp = CompressionTypes.Unused | CompressionTypes.StoreInSeparatefile;

            StringBuilder info = new StringBuilder();

            info.AppendFormat("Size: {0} x {1} {2}", sizeX, sizeY, Environment.NewLine);
            info.AppendLine("Compression: " + compFlag);
            if (((CompressionTypes)compFlag & NoOp) != 0)
            {
                info.AppendLine("Data for this MipMap is stored external!");
            }
            info.AppendLine("Compressed Size: " + compressedSize);
            info.AppendLine("Uncompressed Size: " + uncompressedSize);
            info.AppendLine("Blocks: " + blocks.Count);
            blocks.ForEach(b => info.AppendFormat("Block: Uncompressed Size: {0}, Compressed Size: {1} {2}", b.uncompressedDataSize, b.compressedSize, Environment.NewLine));
            return(info.ToString());
        }
コード例 #7
0
        private CompressionTypes GetMaximumCompression()
        {
            CompressionTypes result = CompressionTypes.Unit;

            if (NegativeFeedbackCount > MINIMUM_FEEDBACK_COUNT_FOR_UNIT_SIMPLE_TREE)
            {
                result = CompressionTypes.UnitSimpleTree;
            }
            if (NegativeFeedbackCount > MINIMUM_FEEDBACK_COUNT_FOR_UNIT_COUNT_TREE)
            {
                result = CompressionTypes.UnitCountTree;
            }
            if (NegativeFeedbackCount > MINIMUM_FEEDBACK_COUNT_FOR_MULTI_UNIT_COUNT_TREE)
            {
                result = CompressionTypes.MultiUnitCountTree;
            }
            return(result);
        }
コード例 #8
0
        public static byte[] ConvertImagesToMultiTiffBytes(Image[] pages, CompressionTypes compressionType = CompressionTypes.CompressionNone)
        {
            using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
            {
                Image image = pages[0];

                ImageCodecInfo    encoderInfo = ImageCodecInfo.GetImageEncoders().First(i => i.MimeType == "image/tiff");
                EncoderParameters encoderParameters;
                if (compressionType == CompressionTypes.CompressionNone)
                {
                    encoderParameters = new EncoderParameters(1);
                }
                else
                {
                    encoderParameters = new EncoderParameters(2);
                }

                encoderParameters.Param[0] = new EncoderParameter(Encoder.SaveFlag, (long)EncoderValue.MultiFrame);
                if (compressionType != CompressionTypes.CompressionNone)
                {
                    encoderParameters.Param[1] = new EncoderParameter(Encoder.Compression, (long)(compressionType));
                }
                image.Save(ms, encoderInfo, encoderParameters);

                encoderParameters.Param[0] = new EncoderParameter(Encoder.SaveFlag, (long)EncoderValue.FrameDimensionPage);
                if (compressionType != CompressionTypes.CompressionNone)
                {
                    encoderParameters.Param[1] = new EncoderParameter(Encoder.Compression, (long)(compressionType));
                }
                for (int i = 1; i < pages.Length; i++)
                {
                    image.SaveAdd(pages[i], encoderParameters);
                }

                encoderParameters          = new EncoderParameters(1);
                encoderParameters.Param[0] = new EncoderParameter(Encoder.SaveFlag, (long)EncoderValue.Flush);
                image.SaveAdd(encoderParameters);
                ms.Flush();
                return(ms.ToArray());
            }
        }
コード例 #9
0
        public override string ToString()
        {
            CompressionTypes NoOp = CompressionTypes.Unused | CompressionTypes.StoreInSeparatefile;

            StringBuilder info = new StringBuilder();

            info.AppendFormat("Size: {0} x {1} {2}", sizeX, sizeY, Environment.NewLine);
            info.AppendLine("Compression: " + flags);

            if (((CompressionTypes)flags & CompressionTypes.StoreInSeparatefile) != 0)
            {
                if (textureCacheProp != null && textureCachePath != null)
                {
                    info.AppendLine(String.Format("Data for this MipMap is stored in tfc {0} @ {1}", textureCacheProp.value, textureCachePath));
                }
                else
                {
                    info.AppendLine("Data for this MipMap is stored in tfc");
                }

                if (compressedSize == 0)
                {
                    info.AppendLine("TFC data was not found. Searched for tfc file at " + textureCachePath);
                }
            }
            else if (((CompressionTypes)flags & NoOp) != 0)
            {
                info.AppendLine("Data for this MipMap is stored external!");
            }



            info.AppendLine("Compressed Size: " + compressedSize);
            info.AppendLine("Uncompressed Size: " + uncompressedSize);
            info.AppendLine("Blocks: " + blocks.Count);
            blocks.ForEach(b => info.AppendFormat("Block: Uncompressed Size: {0}, Compressed Size: {1} {2}", b.uncompressedDataSize, b.compressedSize, Environment.NewLine));
            return(info.ToString());
        }
コード例 #10
0
        public static RequestHeader BuildRequestHeader(EncryptionTypes encryptionType, CompressionTypes compressionType, RequestTypes requestType)
        {
            // first create headers
            EncryptionHeader encryptionHeader = new EncryptionHeader()
            {
                EncryptionType = encryptionType
            };

            MessageHeader messageHeader = new MessageHeader()
            {
                CompressionType = compressionType,
                EncryptionHeader = encryptionHeader
            };

            RequestHeader requestHeader = new RequestHeader()
            {
                RequestType = requestType,
                MessageHeader = messageHeader
            };

            // send response header first
            return requestHeader;
        }
コード例 #11
0
        static public List <IPartialSnapshotCompression> NewInstances(ISensationSnapshot snapshot, FieldOfVisionTypes fieldOfVision, DirectionTypes direction, CompressionTypes maximumCompression)
        {
            var result = new List <IPartialSnapshotCompression>();

            ISensationSnapshot partialSnapshot = SensationSnapshot.ExtractSnapshot(snapshot, fieldOfVision, direction);

            // Single units for fieldOfVision.Single and fieldOfVision.ThreeByThree allows to find 0 and 9
            var unitCountDictonary = SensationSnapshot.CountUnits(partialSnapshot);


            result.AddRange(NewInstancesOfUnitCompression(unitCountDictonary, fieldOfVision));

            if (maximumCompression >= CompressionTypes.UnitSimpleTree)
            {
                // Find 1 and 8 if a field around is marked as Filled or Empty (two pattern with single unit) --> fieldOfVision.ThreeByThree
                result.AddRange(NewInstancesOfUnitSimpleTreeCompression(unitCountDictonary, partialSnapshot, snapshot, fieldOfVision, direction));
            }

            if (maximumCompression >= CompressionTypes.UnitCountTree)
            {
                // ToDo: Find 2-7 if 2-7 fields around are marked as Filled or Empty (two pattern with counted units) --> fieldOfVision.ThreeByThree
                result.AddRange(NewInstancesOfUnitCountTreeCompression(unitCountDictonary, partialSnapshot, snapshot, fieldOfVision, direction));
            }

            if (maximumCompression >= CompressionTypes.MultiUnitCountTree)
            {
                // ToDo: Find 1-5 fields at the boarder with combination of Empty and Outside  --> fieldOfVision.ThreeByThree
                result.AddRange(NewInstancesOfMultiUnitCountTreeCompression(unitCountDictonary, partialSnapshot, snapshot, fieldOfVision, direction));
            }

            return(result);
        }
コード例 #12
0
        public static RequestHeader BuildRequestHeader(EncryptionTypes encryptionType, CompressionTypes compressionType, RequestTypes requestType)
        {
            // first create headers
            EncryptionHeader encryptionHeader = new EncryptionHeader()
            {
                EncryptionType = encryptionType
            };

            MessageHeader messageHeader = new MessageHeader()
            {
                CompressionType  = compressionType,
                EncryptionHeader = encryptionHeader
            };

            RequestHeader requestHeader = new RequestHeader()
            {
                RequestType   = requestType,
                MessageHeader = messageHeader
            };

            // send response header first
            return(requestHeader);
        }
コード例 #13
0
ファイル: DomainHeader.cs プロジェクト: Oragi/UPKManager
        public async Task ReadHeaderAsync(Action <DomainLoadProgress> progress)
        {
            DomainLoadProgress message = new DomainLoadProgress {
                Text = "Parsing Header..."
            };

            progress?.Invoke(message);

            await readUpkHeader();

            const CompressionTypes validCompression = CompressionTypes.LZO | CompressionTypes.LZO_ENC;

            if (((CompressionTypes)CompressionFlags & validCompression) > 0)
            {
                message.Text = "Decompressing...";

                progress?.Invoke(message);

                reader = await decompressChunks();
            }
            else if (CompressionFlags > 0)
            {
                throw new Exception($"Unsupported compression type 0x{CompressionFlags:X8}.");
            }

            await readNameTable(progress);

            await readImportTable(progress);

            await readExportTable(progress);

            message.Text = "Slicing and Dicing...";

            progress?.Invoke(message);

            await readDependsTable();

            await decodePointers();

            message.Text  = "Reading Objects...";
            message.Total = ExportTableCount;

            progress?.Invoke(message);

            await ExportTable.ForEachAsync(export =>
            {
                return(export.ReadDomainObject(reader).ContinueWith(t =>
                {
                    message.IncrementCurrent();

                    if (ExportTableCount > 100)
                    {
                        progress?.Invoke(message);
                    }
                }));
            });

            message.IsComplete = true;

            progress?.Invoke(message);
        }
コード例 #14
0
 /// <summary>
 ///    Converts the type of the compression.
 /// </summary>
 /// <param name="compressionType">Type of the compression.</param>
 public string ConvertCompressionType(CompressionTypes? compressionType)
 {
     compressionType = compressionType ?? default(CompressionTypes);
     return _compressionTypes.Where(item => item.Item2 == compressionType)
         .Select(item => item.Item1)
         .FirstOrDefault();
 }
コード例 #15
0
ファイル: ImageEncoder.cs プロジェクト: ZePilOt/scummeditor
        private byte GetSubstractionCode(bool hasTransparency, bool horizontalDirection, CompressionTypes compressionType, bool method2AlternateCode = false)
        {
            /*
             * IDs          Method          Rendering Direction     Transparent     Param Subtraction   Remarks
             * 0x01             Uncompressed    Horizontal              No              -   -
             * 0x0E .. 0x12     1st method      Vertical                No              0x0A
             * 0x18 .. 0x1C     1st method      Horizontal              No              0x14
             * 0x22 .. 0x26     1st method      Vertical                Yes             0x1E
             * 0x2C .. 0x30     1st method      Horizontal              Yes             0x28
             *
             * 0x40 .. 0x44     2nd method      Horizontal              No              0x3C                //Não sei se essas duas linhas estão certas, pois nenhuma imagem no DOTT ou SAM&MAX utiliza essas compressões
             * 0x54 .. 0x58     2nd method      Horizontal              Yes             0x50                //Não sei se essas duas linhas estão certas, pois nenhuma umagem no DOTT ou SAM&MAX utiliza essas compressões
             * 0x68 .. 0x6C     2nd method      Horizontal              No              0x64                Same as 0x54 .. 0x58 //Eu inverti essas 2 transparencias, estava errado no site.
             * 0x7C .. 0x80     2nd method      Horizontal              Yes	            0x78                Same as 0x40 .. 0x44 //Eu inverti essas 2 transparencias, estava errado no site.
             */
            if (compressionType == CompressionTypes.Uncompressed || compressionType == CompressionTypes.Unknow)
            {
                return(0);
            }
            if (compressionType == CompressionTypes.Method1)
            {
                // ReSharper disable ConditionIsAlwaysTrueOrFalse
                //I know the redundancy below, but I left here because it easier to understand later.
                if (!hasTransparency && !horizontalDirection)
                {
                    return(0x0A);
                }
                if (!hasTransparency && horizontalDirection)
                {
                    return(0x14);
                }
                if (hasTransparency && !horizontalDirection)
                {
                    return(0x1E);
                }
                if (hasTransparency && horizontalDirection)
                {
                    return(0x28);
                }
                // ReSharper restore ConditionIsAlwaysTrueOrFalse
            }
            if (compressionType == CompressionTypes.Method2)
            {
                if (hasTransparency)
                {
                    return((byte)(method2AlternateCode ? 0x50 : 0x78));
                }
                return((byte)(method2AlternateCode ? 0x3C : 0x64));
            }

            throw new ImageEncodeException("Unexpected Exception");
        }
コード例 #16
0
 /// <summary>
 /// تبدیل تصاویر به یک تصویر چند صفحه ای
 /// MultiTiff
 /// </summary>
 /// <param name="pages">تصاویر</param>
 /// <param name="saveTo">مسیر ذخیره</param>
 /// <param name="compressionType">نوع فشرده سازی</param>
 /// <returns></returns>
 public static Image ConvertImagesToMultiTiff(Image[] pages, string saveTo, CompressionTypes compressionType = CompressionTypes.CompressionNone)
 {
     byte[] bytes = ConvertImagesToMultiTiffBytes(pages, compressionType);
     System.IO.File.WriteAllBytes(saveTo, bytes);
     return(Image.FromFile(saveTo));
 }