Example #1
0
        /// <summary>
        /// Creates a new instance of <see cref="KanvasImage"/>.
        /// </summary>
        /// <param name="imageState">The image plugin the plugin information come from.</param>
        /// <param name="imageInfo">The image info to represent.</param>
        public KanvasImage(IImageState imageState, ImageInfo imageInfo)
        {
            ContractAssertions.IsNotNull(imageState, nameof(imageState));
            ContractAssertions.IsNotNull(imageInfo, nameof(imageInfo));
            ContractAssertions.IsElementContained(imageState.Images, imageInfo, nameof(imageState.Images), nameof(imageInfo));

            _imageState = imageState;
            _imageInfo  = imageInfo;
        }
Example #2
0
        public ImageContext(IStateInfo stateInfo, IContext parentContext)
        {
            ContractAssertions.IsNotNull(stateInfo, nameof(stateInfo));
            ContractAssertions.IsNotNull(parentContext, nameof(parentContext));

            _stateInfo     = stateInfo;
            _imageState    = _stateInfo.PluginState as IImageState;
            _parentContext = parentContext;
        }
Example #3
0
        public ImageContext(IFileState stateInfo, IContext parentContext, IProgressContext progressContext) :
            base(progressContext)
        {
            ContractAssertions.IsNotNull(stateInfo, nameof(stateInfo));
            ContractAssertions.IsNotNull(parentContext, nameof(parentContext));

            _stateInfo     = stateInfo;
            _imageState    = _stateInfo.PluginState as IImageState;
            _parentContext = parentContext;
        }
Example #4
0
        public EncodeImageViewModel(PluginManager pluginManager, IImageState state, ImageInfo imageInfo)
        {
            _pluginManager = pluginManager;
            _state         = state;
            _kanvasImage   = new KanvasImage(state, imageInfo);

            SelectedEncoding = state.SupportedEncodings[_kanvasImage.ImageFormat];
            SourceImage      = _kanvasImage.GetImage().ToBitmapImage();
            OutputImage      = SourceImage;
        }
Example #5
0
        public ImageInfo Load(Stream input, IFileManager pluginManager)
        {
            using var br = new BinaryReaderX(input);

            // Read header
            _header = br.ReadType <ImgxHeader>();

            // Load KTX
            _imageState = LoadKtx(input, "file.ktx", pluginManager).Result;

            return(_imageState.Images[0].ImageInfo);
        }
Example #6
0
        private void CheckIntegrity(IImageState imageState)
        {
            var encodingDefinition = imageState.EncodingDefinition;

            // Check if any encodings are given
            if (!encodingDefinition.HasColorEncodings && !encodingDefinition.HasIndexEncodings)
            {
                throw new InvalidOperationException("The plugin has no supported encodings defined.");
            }
            if (encodingDefinition.HasIndexEncodings && !encodingDefinition.HasPaletteEncodings)
            {
                throw new InvalidOperationException("The plugin has no supported palette encodings defined.");
            }
        }
Example #7
0
        // Constructor
        public ImageEditorViewModel(PluginManager pluginManager, IStateInfo koreFile)
        {
            _pluginManager = pluginManager;
            KoreFile       = koreFile;

            _state = KoreFile.PluginState as IImageState;

            if (_state?.Images != null)
            {
                KanvasImages = new ObservableCollection <KanvasImage>(_state.Images.Select(x => new KanvasImage(_state, x)));
            }

            SelectedKanvasImage = KanvasImages?.FirstOrDefault();
            SelectedZoomLevel   = 1;
        }
Example #8
0
        private void InjectImages(IImageState imageState, UPath filePath, IFileSystem destinationFileSystem)
        {
            for (var i = 0; i < imageState.Images.Count; i++)
            {
                var img = imageState.Images[i];

                var path = filePath / (img.Name ?? $"{i:00}") + ".png";
                if (!destinationFileSystem.FileExists(path))
                {
                    continue;
                }

                var openedImage = (Bitmap)Image.FromStream(destinationFileSystem.OpenFile(path));
                img.SetImage(openedImage);
            }
        }
Example #9
0
        private void ExtractImage(IImageState imageState, IFileSystem destinationFileSystem, UPath filePath)
        {
            if (imageState.Images.Count > 0)
            {
                CreateDirectory(destinationFileSystem, filePath);
            }

            var index = 0;

            foreach (var img in imageState.Images)
            {
                var fileStream = destinationFileSystem.OpenFile(filePath / (img.Name ?? $"{index:00}") + ".png", FileMode.Create, FileAccess.Write);
                img.GetImage().Save(fileStream, ImageFormat.Png);

                fileStream.Close();

                index++;
            }
        }