コード例 #1
0
        protected override Task<ResultStatus> DoCommandOverride(ICommandContext commandContext)
        {
            var assetManager = new AssetManager();

            // Load image
            var image = assetManager.Load<Image>(InputUrl);

            // Initialize TextureTool library
            using (var texTool = new TextureTool())
            using (var texImage = texTool.Load(image))
            {
                var outputFormat = Format.HasValue ? Format.Value : image.Description.Format;

                // Apply transformations
                texTool.Decompress(texImage);
                if (IsAbsolute)
                {
                    texTool.Resize(texImage, (int)Width, (int)Height, Filter.Rescaling.Lanczos3);
                }
                else
                {
                    texTool.Rescale(texImage, Width / 100.0f, Height / 100.0f, Filter.Rescaling.Lanczos3);
                }

                // Generate mipmaps
                if (GenerateMipmaps)
                {
                    texTool.GenerateMipMaps(texImage, Filter.MipMapGeneration.Box);
                }

                // Convert/Compress to output format
                texTool.Compress(texImage, outputFormat);

                // Save
                using (var outputImage = texTool.ConvertToParadoxImage(texImage))
                {
                    assetManager.Save(OutputUrl, outputImage);

                    commandContext.Logger.Verbose("Compression successful [{3}] to ({0}x{1},{2})",
                                                  outputImage.Description.Width,
                                                  outputImage.Description.Height, outputImage.Description.Format, OutputUrl);
                }
            }

            return Task.FromResult(ResultStatus.Successful);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: h78hy78yhoi8j/xenko
        private void HandleResizing(TextureTool texTool, TexImage image)
        {
            if (Width != null && Height != null)
            {
                bool targetInPercent;
                var width = ParsePixelSize(Width, out targetInPercent);
                var height = ParsePixelSize(Height, out targetInPercent);

                if (targetInPercent)
                    texTool.Rescale(image, width / 100f, height / 100f, RescalingFilter);
                else
                    texTool.Resize(image, width, height, RescalingFilter);
            }
            else if (Width != null && Height == null)
            {
                bool targetInPercent;
                var width = ParsePixelSize(Width, out targetInPercent);

                if (targetInPercent)
                    texTool.Rescale(image, width / 100f, 1, RescalingFilter);
                else
                    texTool.Resize(image, width, image.Height, RescalingFilter);
            }
            else if (Width == null && Height != null)
            {
                bool targetInPercent;
                var height = ParsePixelSize(Height, out targetInPercent);

                if (targetInPercent)
                    texTool.Rescale(image, 1, height / 100f, RescalingFilter);
                else
                    texTool.Resize(image, image.Width, height, RescalingFilter);
            }
        }