Пример #1
0
        public async Task HandleAsync(DomainCommandContext context, GenerateTexturePreviewCommand command)
        {
            var settings = new TextureConversionSettings
            {
                ColorSpace   = command.ColorSpace,
                FileType     = FileType.WIC,
                MaxHeight    = command.MaxSize,
                MaxWidth     = command.MaxSize,
                OutputFormat = command.OutputFormat,
                KeepMipmaps  = false
            };

            var metadata = _textureService.GetMetadata(command.FilePath);

            if (metadata == null)
            {
                await context.EmitAsync(new ErrorOccuredNotification());
            }

            var texture = _textureService.Convert(command.FilePath, settings);

            if (texture?.Metadata == null)
            {
                await context.EmitAsync(new ErrorOccuredNotification());
            }

            await context.EmitAsync(new GeneratedTexturePreviewNotification(texture, metadata));
        }
Пример #2
0
 public ConvertTextureCommand(
     string fileName,
     string sourceDirectoryPath,
     string destinationDirectoryPath,
     TextureConversionSettings settings)
 {
     FileName                 = fileName;
     SourceDirectoryPath      = sourceDirectoryPath;
     DestinationDirectoryPath = destinationDirectoryPath;
     Settings                 = settings;
 }
 private ConvertTextureCommand CreateConvertTextureCommand(string fileName, TextureConversionSettings settings)
 {
     return(new ConvertTextureCommand(
                fileName,
                _settings.SourceDirectory,
                _settings.DestinationDirectory,
                new ApplicationModel.TextureConversionSettings
     {
         ColorSpace = settings.ColorSpace,
         KeepMipmaps = settings.KeepMipmaps,
         OutputFormat = settings.OutputFormat
     }));
 }
Пример #4
0
        public Texture Convert(string filePath, TextureConversionSettings settings)
        {
            Model.Texture texture;
            var           textureConverstionSettings = new Model.TextureConversionSettings(
                settings.MaxHeight,
                settings.MaxWidth,
                (uint)settings.OutputFormat,
                (uint)settings.ColorSpace,
                settings.KeepMipmaps,
                (uint)settings.FileType);

            var result = ImagingDriver.ConvertTexture(filePath, textureConverstionSettings, out texture);

            if ((result < 0) || (texture.Buffer == IntPtr.Zero))
            {
                return(null);
            }

            try
            {
                var metadata = new TextureMetadata
                {
                    Height       = texture.Metadata.Height,
                    Width        = texture.Metadata.Width,
                    MipmapsCount = texture.Metadata.MipmapsCount,
                    Format       = (DxgiFormat)texture.Metadata.DxgiFormat
                };

                var output = new Texture
                {
                    Buffer   = new byte[texture.Size],
                    Metadata = metadata
                };

                Marshal.Copy(texture.Buffer, output.Buffer, 0, output.Buffer.Length);

                return(output);
            }
            finally
            {
                ImagingDriver.ReleaseTextureBuffer(texture.Buffer);
            }
        }
Пример #5
0
 internal static extern long ConvertTexture(string sourceTexturePath, TextureConversionSettings settings, out Texture texture);