コード例 #1
0
        /// <summary>Function to open a content object from this plugin.</summary>
        /// <param name="file">The file that contains the content.</param>
        /// <param name = "fileManager" > The file manager used to access other content files.</param>
        /// <param name="injector">Parameters for injecting dependency objects.</param>
        /// <param name="scratchArea">The file system for the scratch area used to write transitory information.</param>
        /// <param name="undoService">The undo service for the plug in.</param>
        /// <returns>A new IEditorContent object.</returns>
        /// <remarks>
        /// The <paramref name="scratchArea" /> parameter is the file system where temporary files to store transitory information for the plug in is stored. This file system is destroyed when the
        /// application or plug in is shut down, and is not stored with the project.
        /// </remarks>
        protected async override Task <IEditorContent> OnOpenContentAsync(IContentFile file, IContentFileManager fileManager, IGorgonFileSystemWriter <Stream> scratchArea, IUndoService undoService)
        {
            FileInfo          texConvExe = GetTexConvExe();
            TexConvCompressor compressor = null;

            if (texConvExe.Exists)
            {
                compressor = new TexConvCompressor(texConvExe, scratchArea, _ddsCodec);
            }

            var imageIO = new ImageIOService(_ddsCodec,
                                             _codecs,
                                             new ExportImageDialogService(_settings),
                                             new ImportImageDialogService(_settings, _codecs),
                                             CommonServices.BusyService,
                                             scratchArea,
                                             compressor,
                                             CommonServices.Log);

            (IGorgonImage image, IGorgonVirtualFile workingFile, BufferFormat originalFormat)imageData = await Task.Run(() => {
                using (Stream inStream = file.OpenRead())
                {
                    return(imageIO.LoadImageFile(inStream, file.Name));
                }
            });

            var services = new ImageEditorServices
            {
                CommonServices        = CommonServices,
                ImageIO               = imageIO,
                UndoService           = undoService,
                ImageUpdater          = new ImageUpdaterService(),
                ExternalEditorService = new ImageExternalEditService(CommonServices.Log)
            };

            var cropResizeSettings = new CropResizeSettings();
            var dimensionSettings  = new DimensionSettings();
            var mipSettings        = new MipMapSettings();

            cropResizeSettings.Initialize(CommonServices);
            dimensionSettings.Initialize(new DimensionSettingsParameters(GraphicsContext.Graphics.VideoAdapter, CommonServices));
            mipSettings.Initialize(CommonServices);


            var content = new ImageContent();

            content.Initialize(new ImageContentParameters(file,
                                                          _settings,
                                                          cropResizeSettings,
                                                          dimensionSettings,
                                                          mipSettings,
                                                          imageData,
                                                          GraphicsContext.Graphics.VideoAdapter,
                                                          GraphicsContext.Graphics.FormatSupport,
                                                          services));

            return(content);
        }
コード例 #2
0
 /// <summary>Initializes a new instance of the <see cref="T:Gorgon.Editor.ImageEditor.ImageIO"/> class.</summary>
 /// <param name="defaultCodec">The default codec used by the plug in.</param>
 /// <param name="installedCodecs">The list of installed codecs.</param>
 /// <param name="importDialog">The dialog service used to export an image.</param>
 /// <param name="busyService">The busy state service.</param>
 /// <param name="scratchArea">The file system writer used to write to the temporary area.</param>
 /// <param name="bcCompressor">The block compressor used to block (de)compress image data.</param>
 /// <param name="log">The logging interface to use.</param>
 public ImageIOService(IGorgonImageCodec defaultCodec,
                       ICodecRegistry installedCodecs,
                       IExportImageDialogService exportDialog,
                       IImportImageDialogService importDialog,
                       IBusyStateService busyService,
                       IGorgonFileSystemWriter <Stream> scratchArea,
                       TexConvCompressor bcCompressor,
                       IGorgonLog log)
 {
     _exportDialog   = exportDialog;
     _importDialog   = importDialog;
     DefaultCodec    = defaultCodec;
     InstalledCodecs = installedCodecs;
     ScratchArea     = scratchArea;
     _compressor     = bcCompressor;
     _busyState      = busyService;
     _log            = log ?? GorgonLog.NullLog;
 }