Beispiel #1
0
        private void LoadPaletteFormats(IKanvasImage image)
        {
            if (image == null)
            {
                palettes.DataStore = Array.Empty <ImageEncodingElement>();
                return;
            }

            var definition = image.EncodingDefinition;

            IEnumerable <ImageEncodingElement> elements = Array.Empty <ImageEncodingElement>();

            if (image.IsIndexed && definition.HasPaletteEncodings)
            {
                var paletteEncodings = definition.PaletteEncodings;
                var encodingIndices  = definition.GetIndexEncoding(image.ImageFormat).PaletteEncodingIndices;

                if (image.IsIndexed && encodingIndices.Any())
                {
                    paletteEncodings = paletteEncodings.Where(x => encodingIndices.Contains(x.Key))
                                       .ToDictionary(x => x.Key, y => y.Value);
                }

                elements = elements.Concat(paletteEncodings.Select(x => new ImageEncodingElement(x.Key, x.Value)));
            }

            _currentPaletteFormats = elements.ToArray();
        }
Beispiel #2
0
        private void UpdateImagePreview(IKanvasImage image)
        {
            if (image == null)
            {
                return;
            }

            var definition = GetEncodingDefinition();

            // Set dropdown values
            formats.Text = definition.GetColorEncoding(image.ImageFormat)?.FormatName ??
                           definition.GetIndexEncoding(image.ImageFormat).IndexEncoding.FormatName;

            if (image.IsIndexed)
            {
                palettes.Text = definition.GetPaletteEncoding(image.PaletteFormat).FormatName;
            }

            // Set size
            width.Text  = image.ImageSize.Width.ToString();
            height.Text = image.ImageSize.Height.ToString();

            // Set image
            imageView.Image = image.GetImage().ToEto();
            imageView.Invalidate();

            // Update palette image
            if (image.IsIndexed)
            {
                UpdatePaletteImage();
            }
        }
Beispiel #3
0
        private void UpdatePaletteImage(IKanvasImage image)
        {
            if (!image.IsIndexed)
            {
                imagePalette.Palette = null;
                return;
            }

            imagePalette.Palette = image.GetPalette(_formInfo.Progress);
        }
Beispiel #4
0
        public void Save(Stream output, IKanvasImage image)
        {
            using var bw = new BinaryWriterX(output);

            // Header
            _header.width  = (short)image.ImageSize.Width;
            _header.height = (short)image.ImageSize.Height;
            _header.format = (byte)image.ImageFormat;

            // Writing
            bw.WriteType(_header);
            bw.BaseStream.Position = 0x80;
            bw.Write(image.ImageInfo.ImageData);
        }
Beispiel #5
0
        private void ExtractImageInternal(IKanvasImage image, IFileSystem destinationFileSystem, string fileName)
        {
            var newFileStream = destinationFileSystem.OpenFile(fileName, FileMode.Create, FileAccess.Write);

            var imageStream = new MemoryStream();

            image.GetImage(Progress).Save(imageStream, ImageFormat.Png);

            imageStream.Position = 0;
            imageStream.CopyTo(newFileStream);

            imageStream.Close();
            newFileStream.Close();
        }
Beispiel #6
0
        private void UpdateImagePreview(IKanvasImage image)
        {
            if (image == null)
            {
                return;
            }

            // Set dropdown values
            UpdateSelectedImageFormats();

            // Set size
            width.Text  = image.ImageSize.Width.ToString();
            height.Text = image.ImageSize.Height.ToString();

            // Set image
            imageView.Image = image.GetImage().ToEto();
            imageView.Invalidate();
        }
Beispiel #7
0
        private void LoadFormats(IKanvasImage selectedImage)
        {
            var definition = selectedImage.EncodingDefinition;

            IEnumerable <ImageEncodingElement> elements = Array.Empty <ImageEncodingElement>();

            if (definition.HasColorEncodings)
            {
                elements = elements.Concat(
                    definition.ColorEncodings.Select(x => new ImageEncodingElement(x.Key, x.Value)));
            }
            if (definition.HasIndexEncodings)
            {
                elements = elements.Concat(
                    definition.IndexEncodings.Select(x => new ImageEncodingElement(x.Key, x.Value)));
            }

            _currentFormats = elements.ToArray();
        }
Beispiel #8
0
        public void Save(Stream output, IKanvasImage image)
        {
            using var bw = new BinaryWriterX(output);

            // Prepare image data
            var imgData = new MemoryStream();

            switch (_magic)
            {
            case 0x89504E47:        // PNG
                ((BitmapKanvasImage)image).GetImage().Save(imgData, ImageFormat.Png);
                break;

            case 0x4C5A3737:        // LZ77
                imgData.Write(((KanvasImage)image).ImageInfo.ImageData);
                imgData.Write(((KanvasImage)image).ImageInfo.PaletteData);

                imgData.Position = 0;
                var compData = new MemoryStream();
                Compressions.StingLz.Build().Compress(imgData, compData);

                imgData = compData;
                break;
            }

            // Write headers
            bw.WriteType(new PckHeader {
                magic = "Texture ", size = (int)(imgData.Length + HeaderSize + TexHeaderSize)
            });
            bw.WriteType(new TexHeader {
                unk1 = _texHeader.unk1, dataSize = (int)imgData.Length, width = image.ImageSize.Width, height = image.ImageSize.Height
            });

            // Write image data
            imgData.Position = 0;
            imgData.CopyTo(output);
            bw.WriteAlignment(4);

            // Write unknown region
            bw.Write(_unkRegion);
        }
Beispiel #9
0
        private void PopulatePaletteDropdown(IKanvasImage image)
        {
            tsbPalette.DropDownItems.Clear();

            if (!image.IsIndexed)
            {
                return;
            }

            var items = new List <ToolStripItem>();

            if (EncodingDefinition.HasPaletteEncodings)
            {
                var paletteEncodings = EncodingDefinition.PaletteEncodings;

                var indices = EncodingDefinition.GetIndexEncoding(image.ImageFormat).PaletteEncodingIndices;
                if (image.IsIndexed && indices.Any())
                {
                    paletteEncodings = EncodingDefinition.PaletteEncodings.Where(x => indices.Contains(x.Key))
                                       .ToDictionary(x => x.Key, y => y.Value);
                }

                items.AddRange(paletteEncodings.Select(f => new ToolStripMenuItem
                {
                    Text    = f.Value.FormatName,
                    Tag     = f.Key,
                    Checked = f.Key == ImageState.Images[_selectedImageIndex].ImageFormat
                }));
            }

            tsbPalette.DropDownItems.AddRange(items.ToArray());
            if (tsbPalette.DropDownItems.Count <= 0)
            {
                return;
            }

            foreach (var tsb in tsbPalette.DropDownItems)
            {
                ((ToolStripMenuItem)tsb).Click += tsbPalette_Click;
            }
        }
Beispiel #10
0
        public void Save(Stream output, IKanvasImage image)
        {
            using var bw = new BinaryWriterX(output);

            // Header
            _header.width       = (short)image.ImageSize.Width;
            _header.height      = (short)image.ImageSize.Height;
            _header.imageFormat = (byte)image.ImageFormat;
            _header.bitDepth    = (byte)image.BitDepth;

            // Write image data to stream
            var combinedImageStream = new MemoryStream();

            combinedImageStream.Write(image.ImageInfo.ImageData);
            for (var i = 0; i < image.ImageInfo.MipMapCount; i++)
            {
                combinedImageStream.Write(image.ImageInfo.MipMapData[i]);
            }

            // Create reduced tiles and indices
            var(imageData, tileTable) = SplitTiles(combinedImageStream, image.BitDepth);

            // Write tile table
            output.Position = _headerSize;
            Level5Compressor.Compress(tileTable, output, _tileTableCompression);

            _header.tileTableSize       = (int)output.Length - _headerSize;
            _header.tileTableSizePadded = (_header.tileTableSize + 3) & ~3;

            // Write image tiles
            output.Position = _headerSize + _header.tileTableSizePadded;
            Level5Compressor.Compress(imageData, output, _imageDataCompression);
            bw.WriteAlignment(4);

            _header.imgDataSize = (int)(output.Length - (_headerSize + _header.tileTableSizePadded));

            // Write header
            bw.BaseStream.Position = 0;
            bw.WriteType(_header);
        }
Beispiel #11
0
 public void Save(Stream output, IKanvasImage image)
 {
     using (var bw = new BinaryWriterX(output, true))
     {
     }
 }
Beispiel #12
0
 public void Save(Stream output, IKanvasImage image)
 {
 }