Exemple #1
0
            public bool EncodeTexture(byte[] BitmapData, string PixelFormatText, string DataFormatText, bool IncludeGI, uint GlobalIndex, out MemoryStream TextureData, out MemoryStream ClutData)
            {
                TextureData = null; // Set texture data to null
                ClutData    = null; // Set external clut data to null

                // Get the Pixel and Data Formats
                GvrPixelFormat PixelFormat = GetPixelFormat(PixelFormatText);
                GvrDataFormat DataFormat   = GetDataFormat(DataFormatText);
                if ((PixelFormat == GvrPixelFormat.Unknown && (DataFormat == GvrDataFormat.Index4 || DataFormat == GvrDataFormat.Index8)) || DataFormat == GvrDataFormat.Unknown)
                {
                    Console.WriteLine("ERROR: Unknown pixel or data format.");
                    return false;
                }
                if (PixelFormat == GvrPixelFormat.Unknown && DataFormat != GvrDataFormat.Index4 && DataFormat != GvrDataFormat.Index8)
                    PixelFormat = GvrPixelFormat.IntensityA8; // Just so it gets set to 00.

                // Load the bitmap
                GvrTextureEncoder GvrTextureEncoder = new GvrTextureEncoder(BitmapData, (GvrPixelFormat)PixelFormat, (GvrDataFormat)DataFormat);
                if (!GvrTextureEncoder.LoadSuccess())
                {
                    Console.WriteLine("ERROR: Unable to load image, file is not a supported image,");
                    Console.WriteLine("       or image cannot be converted to the specified pixel/data formats.");
                    return false;
                }
                GvrTextureEncoder.WriteGbix(GlobalIndex);

                // Output information to the console
                GvrTextureInfo TextureInfo = (GvrTextureInfo)GvrTextureEncoder.GetTextureInfo();
                Console.WriteLine();
                Console.WriteLine("Texture Type : Gvr");
                Console.WriteLine("Dimensions   : {0}x{1}", TextureInfo.TextureWidth, TextureInfo.TextureHeight);
                if (TextureInfo.PixelFormat != (byte)GvrPixelFormat.Unknown)
                    Console.WriteLine("Pixel Format : {0} ({1})", TextureInfo.PixelFormat.ToString("X2"), GetPixelFormatAsText(TextureInfo.PixelFormat));
                Console.WriteLine("Data Format  : {0} ({1})", TextureInfo.DataFormat.ToString("X2"), GetDataFormatAsText(TextureInfo.DataFormat));
                if (TextureInfo.DataFlags != 0x00)
                    Console.WriteLine("Data Flags   : {0} ({1})", TextureInfo.DataFlags.ToString("X2"), GetDataFlagsAsText(TextureInfo.DataFlags));
                Console.WriteLine();

                // Encode the texture
                try { TextureData = GvrTextureEncoder.GetTextureAsStream(); }
                catch
                {
                    Console.WriteLine("ERROR: Unable to encode texture.");
                    return false;
                }

                // Encode the clut (if it has one)
                if (GvrTextureEncoder.NeedsExternalClut())
                {
                    try { ClutData = GvrTextureEncoder.GetClutAsStream(); }
                    catch
                    {
                        Console.WriteLine("ERROR: Unable to encode clut.");
                        return false;
                    }
                }

                return true;
            }
Exemple #2
0
        public static void Encode(string[] args)
        {
            string outPath = Path.ChangeExtension(args[1], ".gvr");
            string outPalettePath = Path.ChangeExtension(args[1], ".gvp");

            GvrTextureEncoder texture = new GvrTextureEncoder(args[1], StringToPixelFormat(args[3]), StringToDataFormat(args[4]));

            // Was this texture initalized successfully
            if (!texture.Initalized)
            {
                Console.WriteLine("Error: Unable to encode using the specified texture.");
                return;
            }

            // Get arguments
            for (int i = 5; i < args.Length; i++)
            {
                string arg = args[i].ToLower();

                // Change the output path
                if (arg == "-o" && args.Length > i + 1)
                {
                    outPath = args[i + 1];
                    i++;
                }

                // Change the output path for the palette
                if (arg == "-op" && args.Length > i + 1)
                {
                    outPalettePath = args[i + 1];
                    i++;
                }

                // No global index
                if (arg == "-nogbix")
                {
                    texture.HasGlobalIndex = false;
                }

                // GBIX type is GCIX
                if (arg == "-gcix")
                {
                    texture.GbixType = GvrGbixType.Gcix;
                }

                // Set global index
                if (arg == "-gi" && args.Length > i + 1)
                {
                    uint globalIndex;
                    if (!uint.TryParse(args[i + 1], out globalIndex))
                    {
                        globalIndex = 0;
                    }
                    texture.GlobalIndex = globalIndex;

                    i++;
                }

                // Set that the texture has mipmaps
                if (arg == "-mipmaps")
                {
                    texture.HasMipmaps = true;
                }

                // Set that the texture has an external palette
                if (arg == "-ep")
                {
                    texture.NeedsExternalPalette = true;
                }
            }

            Console.WriteLine("Texture Information");
            Console.WriteLine("--------------------");
            Console.WriteLine("Format         : GVR");
            if (texture.HasGlobalIndex)
            {
                Console.WriteLine("Global Index   : {0}", texture.GlobalIndex);
            }
            Console.WriteLine("Dimensions     : {0}x{1}", texture.TextureWidth, texture.TextureHeight);
            if (texture.PixelFormat != GvrPixelFormat.Unknown)
            {
                Console.WriteLine("Palette Format : {0}", PixelFormatToString(texture.PixelFormat));
            }
            Console.WriteLine("Data Format    : {0}", DataFormatToString(texture.DataFormat));
            if (texture.DataFlags != GvrDataFlags.None)
            {
                Console.WriteLine("Data Flags     : {0}", DataFlagsToString(texture.DataFlags));
            }

            texture.Save(outPath);

            if (texture.NeedsExternalPalette)
            {
                texture.PaletteEncoder.Save(outPalettePath);
            }

            Console.WriteLine("\nTexture encoded successfully.");
        }
Exemple #3
0
        public override void Write(Stream source, Stream destination)
        {
            // Writing GVR textures is done through VrSharp, so just pass it to that
            GvrTextureEncoder texture = new GvrTextureEncoder(source, PaletteFormat, DataFormat);

            if (!texture.Initalized)
            {
                throw new TextureNotInitalizedException("Unable to initalize texture.");
            }

            texture.HasGlobalIndex = HasGlobalIndex;
            if (texture.HasGlobalIndex)
            {
                texture.GlobalIndex = GlobalIndex;
                texture.GbixType = GbixType;
            }

            texture.HasMipmaps = HasMipmaps;
            texture.NeedsExternalPalette = needsExternalPalette;

            // If we have an external palette file, save it
            if (texture.NeedsExternalPalette)
            {
                needsExternalPalette = true;

                PaletteStream = new MemoryStream();
                texture.PaletteEncoder.Save(PaletteStream);
            }
            else
            {
                needsExternalPalette = false;
            }

            texture.Save(destination);
        }