예제 #1
0
        public static Bitmap Decode(GNFTexture texture)
        {
            var ddsBytes = DecodeToDDS(texture);
            var ddsImage = new ImageEngineImage(ddsBytes);

            return(ImageEngineImageToBitmap(ddsImage));
        }
예제 #2
0
        /// <summary>
        /// Converts the given texture dictionary to a field texture archive, and returns a new texture dictionary filled with dummy textures for each texture in the given texture dictionary.
        /// </summary>
        /// <param name="textureDictionary"></param>
        /// <param name="archiveFilePath"></param>
        /// <returns></returns>
        public static TextureDictionary ConvertToFieldTextureArchive(TextureDictionary textureDictionary, string archiveFilePath, bool usePS4Format = false)
        {
            var archiveBuilder = new ArchiveBuilder();

            // Create bgTexArcData00.txt
            var fieldTextureArchiveDataInfoStream = new MemoryStream();

            using (var streamWriter = new StreamWriter(fieldTextureArchiveDataInfoStream, Encoding.Default, 4096, true))
            {
                streamWriter.WriteLine("1,");
                streamWriter.WriteLine($"{textureDictionary.Count},");
            }

            archiveBuilder.AddFile("bgTexArcData00.txt", fieldTextureArchiveDataInfoStream);

            // Convert textures
            foreach (var texture in textureDictionary.Textures)
            {
                var textureInfo      = TextureInfo.GetTextureInfo(texture);
                var texturePixelData = TextureUtilities.GetRawPixelData(texture);

                // Create field texture & save it
                Stream textureStream = new MemoryStream();
                if (!usePS4Format)
                {
                    var fieldTexture = new FieldTexturePS3(textureInfo.PixelFormat, ( byte )textureInfo.MipMapCount, ( short )textureInfo.Width,
                                                           ( short )textureInfo.Height, texturePixelData);
                    fieldTexture.Save(textureStream);
                }
                else
                {
                    var fieldTexture = new GNFTexture(textureInfo.PixelFormat, ( byte )textureInfo.MipMapCount, ( short )textureInfo.Width,
                                                      ( short )textureInfo.Height, texturePixelData);
                    fieldTexture.Save(textureStream);
                }

                archiveBuilder.AddFile(texture.Name, textureStream);
            }

            // Finally build archive file
            archiveBuilder.BuildFile(archiveFilePath);

            // Dummy out textures in texture dictionary
            var newTextureDictionary = new TextureDictionary(textureDictionary.Version);

            foreach (var texture in textureDictionary.Textures)
            {
                newTextureDictionary.Add(Texture.CreateDefaultTexture(texture.Name));
            }

            return(newTextureDictionary);
        }
예제 #3
0
        public static byte[] DecodeToDDS(GNFTexture texture)
        {
            var surfaceFormat = ImageEngineFormat.DDS_DXT1;

            if (texture.PixelFormat == 0x50)
            {
                surfaceFormat = ImageEngineFormat.DDS_DXT3;
            }

            var ddsBytes = new byte[0x80 + texture.Data.Length];

            // create & write header
            var ddsHeader = new DDS_Header(1, texture.Height, texture.Width, surfaceFormat);

            ddsHeader.WriteToArray(ddsBytes, 0);

            // write pixel data
            Array.Copy(texture.Data, 0, ddsBytes, 0x80, texture.Data.Length);

            return(ddsBytes);
        }