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;
            }