コード例 #1
0
        private void OnConvertFtcxClick(object sender, RoutedEventArgs e)
        {
            try
            {
                OpenFileDialog dlg = new OpenFileDialog {
                    Filter = "FFX Picture (*.ftcx)|*.ftcx", Multiselect = true
                };
                if (dlg.ShowDialog() != true)
                {
                    return;
                }

                foreach (string filePath in dlg.FileNames)
                {
                    using (FileStream input = File.OpenRead(filePath))
                    {
                        FtcxFileReader fileReader = new FtcxFileReader(input);
                        FtcxFileHeader header     = fileReader.ReadHeader();
                        int            width      = header.BlockSize * 2;
                        short          height     = header.BlockCount;
                        fileReader.SkipUnknownSubHeader();
                        using (SafeHGlobalHandle image = fileReader.ReadImage())
                            using (UnmanagedMemoryStream imageInput = image.OpenStream(FileAccess.Read))
                                using (FileStream output = File.Create(Path.ChangeExtension(filePath, String.Format(".{0}x{1}.raw", width, height))))
                                    imageInput.CopyTo(output);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
コード例 #2
0
        private void WriteIndexedImage(GLTexture texture, GLTexture palette)
        {
            byte[]    palettesPixels = palette.GetManagedPixelsArray(PixelFormat.Format32bppArgb);
            TexHeader header         = CreateHeader(texture, palette, palettesPixels[3] == 0);

            _output.WriteStruct(header);
            _output.Write(palettesPixels, 0, palettesPixels.Length);
            using (SafeHGlobalHandle pixels = texture.GetUnmanagedPixelsArray(PixelFormat.Format8bppIndexed))
                using (UnmanagedMemoryStream input = pixels.OpenStream(FileAccess.Read))
                    input.CopyTo(_output);
        }
コード例 #3
0
        public bool ReadParticles(Location location)
        {
            ArchiveFileEntry pmdEntry = (ArchiveFileEntry)_locationDirectory.Childs.TryGetValue(_name + ".pmd");
            ArchiveFileEntry pmpEntry = (ArchiveFileEntry)_locationDirectory.Childs.TryGetValue(_name + ".pmp");

            if (pmdEntry == null || pmpEntry == null)
            {
                return(true);
            }

            SafeHGlobalHandle pmdContent, pmpContent;

            using (Stream input = pmdEntry.OpenReadableContentStream())
            {
                pmdContent = new SafeHGlobalHandle((int)input.Length);
                try
                {
                    using (Stream output = pmdContent.OpenStream(FileAccess.Write))
                        input.CopyTo(output);
                }
                catch
                {
                    pmdContent.SafeDispose();
                    throw;
                }
            }

            using (Stream input = pmpEntry.OpenReadableContentStream())
            {
                pmpContent = new SafeHGlobalHandle((int)input.Length);
                try
                {
                    using (Stream output = pmpContent.OpenStream(FileAccess.Write))
                        input.CopyTo(output);
                }
                catch
                {
                    pmpContent.SafeDispose();
                    throw;
                }
            }

            Particles result = new Particles(pmdContent, pmpContent);

            location.Particles = result;

            location.SaveRequest &= ~LocationProperty.Particles;
            location.Importable  &= ~LocationProperty.Particles;
            return(true);
        }
コード例 #4
0
ファイル: TexTexture2DReader.cs プロジェクト: rebootus/Esthar
        public GLTexture Read()
        {
            int size = _header.ImageWidth * _header.ImageHeight * _header.BytesPerPixel;
            PixelFormatDescriptor format = GetColorFormat();

            if (format != null)
            {
                return(ReadTexture(_input, format));
            }

            using (SafeHGlobalHandle pixels = _input.ReadBuff(size))
            {
                TexPixelFormatsConverter converter = new TexPixelFormatsConverter(_header, pixels, PixelFormats.Bgra32);
                using (SafeHGlobalHandle newPixels = converter.Convert())
                    using (UnmanagedMemoryStream input = newPixels.OpenStream(FileAccess.Read))
                        return(ReadTexture(input, PixelFormat.Format32bppArgb));
            }
        }
コード例 #5
0
        public bool ReadModels(Location location)
        {
            if (_root == null)
            {
                return(false);
            }

            XmlElement node = _root["Models"];

            if (node == null)
            {
                return(false);
            }

            if (!node.GetBoolean("IsExists"))
            {
                return(true);
            }

            string oneFile = PathEx.ChangeName(_xmlPath, Path.ChangeExtension(_xmlPath, ".one"));

            using (Stream input = new FileStream(oneFile, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                SafeHGlobalHandle oneContent = new SafeHGlobalHandle((int)input.Length);
                try
                {
                    using (Stream output = oneContent.OpenStream(FileAccess.Write))
                        input.CopyTo(output);
                    location.Models = oneContent;
                }
                catch
                {
                    oneContent.SafeDispose();
                    throw;
                }
            }

            location.SaveRequest &= ~LocationProperty.Models;
            location.Importable  |= LocationProperty.Models;
            return(true);
        }
コード例 #6
0
        public void WriteModels(SafeHGlobalHandle oneContent)
        {
            XmlElement node = _root.EnsureChildElement("Models");

            node.RemoveAll();

            bool isExists = oneContent != null;

            node.SetBoolean("IsExists", isExists);

            if (!isExists)
            {
                return;
            }

            string oneFile = PathEx.ChangeName(_xmlPath, Path.ChangeExtension(_xmlPath, ".one"));

            using (Stream input = oneContent.OpenStream(FileAccess.Read))
                using (Stream output = new FileStream(oneFile, FileMode.Create, FileAccess.Write, FileShare.None))
                    input.CopyTo(output);
        }
コード例 #7
0
ファイル: MimGLTextureReader.cs プロジェクト: rebootus/Esthar
        public async override Task <GLTexture> ReadTextureAsync(CancellationToken cancelationToken)
        {
            if (cancelationToken.IsCancellationRequested)
            {
                return(RaiseTextureReaded(null));
            }

            using (SafeHGlobalHandle pixels = new SafeHGlobalHandle(_map.Width * _map.Height * 3))
            {
                using (Stream stream = pixels.OpenStream(FileAccess.ReadWrite))
                {
                    if (cancelationToken.IsCancellationRequested)
                    {
                        return(RaiseTextureReaded(null));
                    }

                    CreateBackground(stream);

                    foreach (MimTile tile in _map.LayredTiles[0])
                    {
                        if (cancelationToken.IsCancellationRequested)
                        {
                            return(RaiseTextureReaded(null));
                        }

                        //if (tile.Layered.Z < _map.LayredTiles[0][0].Layered.Z)
                        //    break;

                        int position = tile.Layered.GetPositionInImage(_map, _map.Width * 3);
                        stream.Seek(position, SeekOrigin.Begin);

                        Color[] colors = ReadTileColors(tile);
                        for (int i = 0; i < 16; i++)
                        {
                            for (int k = 0; k < 16; k++)
                            {
                                WriteColor(colors[i * 16 + k], tile.Layered.BlendType, stream);
                            }

                            if (i < 15)
                            {
                                stream.Seek((_map.Width - 16) * 3, SeekOrigin.Current);
                            }
                        }
                    }
                }

                if (cancelationToken.IsCancellationRequested)
                {
                    return(RaiseTextureReaded(null));
                }

                PixelFormatDescriptor pixelFormat = System.Drawing.Imaging.PixelFormat.Format24bppRgb;

                int textureId;
                using (GLService.AcquireContext())
                {
                    GL.GenTextures(1, out textureId);
                    GL.BindTexture(TextureTarget.Texture2D, textureId);
                    GL.TexImage2D(TextureTarget.Texture2D, 0, pixelFormat, _map.Width, _map.Height, 0, pixelFormat, pixelFormat, pixels.DangerousGetHandle());

                    GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
                    GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
                    GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat);
                    GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat);
                }

                if (cancelationToken.IsCancellationRequested)
                {
                    return(RaiseTextureReaded(null));
                }

                return(new GLTexture(textureId, _map.Width, _map.Height, pixelFormat));
            }
        }
コード例 #8
0
        public bool ReadParticles(Location location)
        {
            if (_root == null)
            {
                return(false);
            }

            XmlElement node = _root["Particles"];

            if (node == null)
            {
                return(false);
            }

            if (!node.GetBoolean("IsExists"))
            {
                return(true);
            }

            SafeHGlobalHandle pmdContent, pmpContent;
            string            pmdFile = PathEx.ChangeName(_xmlPath, Path.ChangeExtension(_xmlPath, ".pmd"));
            string            pmpFile = PathEx.ChangeName(_xmlPath, Path.ChangeExtension(_xmlPath, ".pmp"));

            using (Stream input = new FileStream(pmdFile, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                pmdContent = new SafeHGlobalHandle((int)input.Length);
                try
                {
                    using (Stream output = pmdContent.OpenStream(FileAccess.Write))
                        input.CopyTo(output);
                }
                catch
                {
                    pmdContent.SafeDispose();
                    throw;
                }
            }

            using (Stream input = new FileStream(pmpFile, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                pmpContent = new SafeHGlobalHandle((int)input.Length);
                try
                {
                    using (Stream output = pmpContent.OpenStream(FileAccess.Write))
                        input.CopyTo(output);
                }
                catch
                {
                    pmpContent.SafeDispose();
                    throw;
                }
            }

            Particles result = new Particles(pmdContent, pmpContent);

            location.Particles = result;

            location.SaveRequest &= ~LocationProperty.Particles;
            location.Importable  |= LocationProperty.Particles;
            return(true);
        }