Ejemplo n.º 1
0
        public override Stream Pack(ref Stream data)
        {
            // Convert the bitmap to a pvr
            try
            {
                PvrTextureEncoder TextureEncoder = new PvrTextureEncoder(data, PixelFormat, DataFormat);
                TextureEncoder.EnableGbix(GbixHeader);
                if (GbixHeader)
                    TextureEncoder.WriteGbix(GlobalIndex);
                if (CompressionFormat != PvrCompressionFormat.None)
                    TextureEncoder.SetCompressionFormat(CompressionFormat);

                return TextureEncoder.GetTextureAsStream();
            }
            catch { return null; }
        }
Ejemplo n.º 2
0
            public bool EncodeTexture(byte[] BitmapData, string PixelFormatText, string DataFormatText, string CompressionFormatText, 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, Data, and Compression Formats
                PvrPixelFormat PixelFormat = GetPixelFormat(PixelFormatText);
                PvrDataFormat DataFormat   = GetDataFormat(DataFormatText);
                PvrCompressionFormat CompressionFormat = GetCompressionFormat(CompressionFormatText);
                if (PixelFormat == PvrPixelFormat.Unknown || DataFormat == PvrDataFormat.Unknown)
                {
                    Console.WriteLine("ERROR: Unknown pixel or data format.");
                    return false;
                }

                // Load the bitmap
                PvrTextureEncoder PvrTextureEncoder = new PvrTextureEncoder(BitmapData, (PvrPixelFormat)PixelFormat, (PvrDataFormat)DataFormat);
                if (!PvrTextureEncoder.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;
                }
                PvrTextureEncoder.WriteGbix(GlobalIndex);
                if (CompressionFormat != PvrCompressionFormat.None)
                    PvrTextureEncoder.SetCompressionFormat(CompressionFormat);

                // Output information to the console
                PvrTextureInfo TextureInfo = (PvrTextureInfo)PvrTextureEncoder.GetTextureInfo();
                Console.WriteLine();
                Console.WriteLine("Texture Type : Pvr");
                if (TextureInfo.CompressionFormat != PvrCompressionFormat.None)
                    Console.WriteLine("Compression  : {0}",   TextureInfo.CompressionFormat);
                Console.WriteLine("Dimensions   : {0}x{1}",   TextureInfo.TextureWidth, TextureInfo.TextureHeight);
                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));
                Console.WriteLine();

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

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

                return true;
            }