Ejemplo n.º 1
0
 /// <summary>
 /// Opens a texture to encode from a file.
 /// </summary>
 /// <param name="file">Filename of the file that contains the texture data.</param>
 /// <param name="pixelFormat">Pixel format to encode the texture to.</param>
 /// <param name="dataFormat">Data format to encode the texture to.</param>
 public SvrTextureEncoder(string file, SvrPixelFormat pixelFormat, SvrDataFormat dataFormat) : base(file)
 {
     if (decodedBitmap != null)
     {
         initalized = Initalize(pixelFormat, dataFormat);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Open a bitmap from a stream.
        /// </summary>
        /// <param name="stream">Stream that contains the bitmap data.</param>
        /// <param name="PixelFormat">Pixel Format</param>
        /// <param name="DataFormat">Data Format</param>
        public SvrTextureEncoder(Stream stream, SvrPixelFormat PixelFormat, SvrDataFormat DataFormat)
            : base(stream)
        {
            this.PixelFormat = (byte)PixelFormat;
            this.DataFormat  = (byte)DataFormat;

            InitSuccess = Initalize();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Open a bitmap from a System.Drawing.Bitmap.
        /// </summary>
        /// <param name="bitmap">A System.Drawing.Bitmap instance.</param>
        /// <param name="PixelFormat">Pixel Format</param>
        /// <param name="DataFormat">Data Format</param>
        public SvrTextureEncoder(Bitmap bitmap, SvrPixelFormat PixelFormat, SvrDataFormat DataFormat)
            : base(bitmap)
        {
            this.PixelFormat = (byte)PixelFormat;
            this.DataFormat  = (byte)DataFormat;

            InitSuccess = Initalize();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Open a bitmap from a file.
        /// </summary>
        /// <param name="file">Filename of the file that contains the bitmap data.</param>
        /// <param name="PixelFormat">Pixel Format</param>
        /// <param name="DataFormat">Data Format</param>
        public SvrTextureEncoder(string file, SvrPixelFormat PixelFormat, SvrDataFormat DataFormat)
            : base(file)
        {
            this.PixelFormat = (byte)PixelFormat;
            this.DataFormat  = (byte)DataFormat;

            InitSuccess = Initalize();
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Opens a texture to encode from a byte array.
 /// </summary>
 /// <param name="source">Byte array that contains the texture data.</param>
 /// <param name="offset">Offset of the texture in the array.</param>
 /// <param name="length">Number of bytes to read.</param>
 /// <param name="pixelFormat">Pixel format to encode the texture to.</param>
 /// <param name="dataFormat">Data format to encode the texture to.</param>
 public SvrTextureEncoder(byte[] source, int offset, int length, SvrPixelFormat pixelFormat, SvrDataFormat dataFormat)
     : base(source, offset, length)
 {
     if (decodedBitmap != null)
     {
         initalized = Initalize(pixelFormat, dataFormat);
     }
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Opens a texture to encode from a stream.
 /// </summary>
 /// <param name="source">Stream that contains the texture data.</param>
 /// <param name="pixelFormat">Pixel format to encode the texture to.</param>
 /// <param name="dataFormat">Data format to encode the texture to.</param>
 public SvrTextureEncoder(Stream source, SvrPixelFormat pixelFormat, SvrDataFormat dataFormat)
     : base(source)
 {
     if (decodedBitmap != null)
     {
         initalized = Initalize(pixelFormat, dataFormat);
     }
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Opens a texture to encode from a stream.
 /// </summary>
 /// <param name="source">Stream that contains the texture data.</param>
 /// <param name="pixelFormat">Pixel format to encode the texture to.</param>
 /// <param name="dataFormat">Data format to encode the texture to.</param>
 public SvrTextureEncoder(Stream source, SvrPixelFormat pixelFormat, SvrDataFormat dataFormat)
     : base(source)
 {
     if (decodedBitmap != null)
     {
         initalized = Initalize(pixelFormat, dataFormat);
     }
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Opens a texture to encode from a byte array.
 /// </summary>
 /// <param name="source">Byte array that contains the texture data.</param>
 /// <param name="offset">Offset of the texture in the array.</param>
 /// <param name="length">Number of bytes to read.</param>
 /// <param name="pixelFormat">Pixel format to encode the texture to.</param>
 /// <param name="dataFormat">Data format to encode the texture to.</param>
 public SvrTextureEncoder(byte[] source, int offset, int length, SvrPixelFormat pixelFormat, SvrDataFormat dataFormat)
     : base(source, offset, length)
 {
     if (decodedBitmap != null)
     {
         initalized = Initalize(pixelFormat, dataFormat);
     }
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Opens a texture to encode from a file.
 /// </summary>
 /// <param name="file">Filename of the file that contains the texture data.</param>
 /// <param name="pixelFormat">Pixel format to encode the texture to.</param>
 /// <param name="dataFormat">Data format to encode the texture to.</param>
 public SvrTextureEncoder(string file, SvrPixelFormat pixelFormat, SvrDataFormat dataFormat)
     : base(file)
 {
     if (decodedBitmap != null)
     {
         initalized = Initalize(pixelFormat, dataFormat);
     }
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Open a bitmap from a byte array.
        /// </summary>
        /// <param name="array">Byte array that contains the bitmap data.</param>
        /// <param name="PixelFormat">Pixel Format</param>
        /// <param name="DataFormat">Data Format</param>
        public SvrTextureEncoder(byte[] array, SvrPixelFormat PixelFormat, SvrDataFormat DataFormat)
            : base(array)
        {
            this.PixelFormat = (byte)PixelFormat;
            this.DataFormat  = (byte)DataFormat;

            InitSuccess = Initalize();
        }
Ejemplo n.º 11
0
        private static string PixelFormatToString(SvrPixelFormat format)
        {
            switch (format)
            {
            case SvrPixelFormat.Rgb5a3:   return("RGB5A3");

            case SvrPixelFormat.Argb8888: return("ARGB8888");
            }

            return("Unknown");
        }
Ejemplo n.º 12
0
        public static SvrPixelCodec GetPixelCodec(SvrPixelFormat format)
        {
            switch (format)
            {
                case SvrPixelFormat.Rgb5a3:
                    return new Rgb5a3();
                case SvrPixelFormat.Argb8888:
                    return new Argb8888();
            }

            return null;
        }
Ejemplo n.º 13
0
        public static SvrPixelCodec GetPixelCodec(SvrPixelFormat format)
        {
            switch (format)
            {
            case SvrPixelFormat.Rgb5a3:
                return(new Rgb5a3());

            case SvrPixelFormat.Argb8888:
                return(new Argb8888());
            }

            return(null);
        }
Ejemplo n.º 14
0
        protected override bool Initalize()
        {
            // Check to see if what we are dealing with is a GVP palette
            if (!Is(encodedData))
            {
                return(false);
            }

            // Get the pixel format and the codec and make sure we can decode using them
            pixelFormat = (SvrPixelFormat)encodedData[0x08];
            pixelCodec  = SvrPixelCodec.GetPixelCodec(pixelFormat);
            if (pixelCodec == null)
            {
                return(false);
            }

            // Get the number of colors contained in the palette
            paletteEntries = BitConverter.ToUInt16(encodedData, 0x0E);

            return(true);
        }
Ejemplo n.º 15
0
        private static string PixelFormatToString(SvrPixelFormat format)
        {
            switch (format)
            {
                case SvrPixelFormat.Rgb5a3:   return "RGB5A3";
                case SvrPixelFormat.Argb8888: return "ARGB8888";
            }

            return "Unknown";
        }
Ejemplo n.º 16
0
        protected override bool Initalize()
        {
            // Check to see if what we are dealing with is a GVP palette
            if (!Is(encodedData))
                return false;

            // Get the pixel format and the codec and make sure we can decode using them
            pixelFormat = (SvrPixelFormat)encodedData[0x08];
            pixelCodec = SvrPixelCodec.GetPixelCodec(pixelFormat);
            if (pixelCodec == null) return false;

            // Get the number of colors contained in the palette
            paletteEntries = BitConverter.ToUInt16(encodedData, 0x0E);

            return true;
        }
Ejemplo n.º 17
0
        protected override void Initalize()
        {
            // Check to see if what we are dealing with is a SVR texture
            if (!Is(encodedData))
            {
                throw new NotAValidTextureException("This is not a valid GVR texture.");
            }

            // Determine the offsets of the GBIX (if present) and PVRT header chunks.
            if (PTMethods.Contains(encodedData, 0, Encoding.UTF8.GetBytes("GBIX")))
            {
                gbixOffset = 0x00;
                pvrtOffset = 0x10;
            }
            else
            {
                gbixOffset = -1;
                pvrtOffset = 0x00;
            }

            // Read the global index (if it is present). If it is not present, just set it to 0.
            if (gbixOffset != -1)
            {
                globalIndex = BitConverter.ToUInt32(encodedData, gbixOffset + 0x08);
            }
            else
            {
                globalIndex = 0;
            }

            // Read information about the texture
            textureWidth  = BitConverter.ToUInt16(encodedData, pvrtOffset + 0x0C);
            textureHeight = BitConverter.ToUInt16(encodedData, pvrtOffset + 0x0E);

            pixelFormat = (SvrPixelFormat)encodedData[pvrtOffset + 0x08];
            dataFormat  = (SvrDataFormat)encodedData[pvrtOffset + 0x09];

            // Get the codecs and make sure we can decode using them
            pixelCodec = SvrPixelCodec.GetPixelCodec(pixelFormat);
            dataCodec  = SvrDataCodec.GetDataCodec(dataFormat);

            if (dataCodec != null && pixelCodec != null)
            {
                dataCodec.PixelCodec = pixelCodec;
                canDecode            = true;
            }

            // Set the palette and data offsets
            paletteEntries = dataCodec.PaletteEntries;
            if (!canDecode || paletteEntries == 0 || dataCodec.NeedsExternalPalette)
            {
                paletteOffset = -1;
                dataOffset    = pvrtOffset + 0x10;
            }
            else
            {
                paletteOffset = pvrtOffset + 0x10;
                dataOffset    = paletteOffset + (paletteEntries * (pixelCodec.Bpp >> 3));
            }

            initalized = true;
        }
Ejemplo n.º 18
0
        private SvrPixelFormat pixelFormat; // Pixel format
        #endregion

        #region Constructors & Initalizers
        internal SvpPaletteEncoder(byte[][] palette, ushort numColors, SvrPixelFormat pixelFormat, VrPixelCodec pixelCodec)
            : base(palette, numColors, pixelCodec)
        {
            this.pixelFormat = pixelFormat;
        }
Ejemplo n.º 19
0
        protected override void Initalize()
        {
            // Check to see if what we are dealing with is a SVR texture
            if (!Is(encodedData))
            {
                throw new NotAValidTextureException("This is not a valid GVR texture.");
            }

            // Determine the offsets of the GBIX (if present) and PVRT header chunks.
            if (PTMethods.Contains(encodedData, 0, Encoding.UTF8.GetBytes("GBIX")))
            {
                gbixOffset = 0x00;
                pvrtOffset = 0x10;
            }
            else
            {
                gbixOffset = -1;
                pvrtOffset = 0x00;
            }

            // Read the global index (if it is present). If it is not present, just set it to 0.
            if (gbixOffset != -1)
            {
                globalIndex = BitConverter.ToUInt32(encodedData, gbixOffset + 0x08);
            }
            else
            {
                globalIndex = 0;
            }

            // Read information about the texture
            textureWidth  = BitConverter.ToUInt16(encodedData, pvrtOffset + 0x0C);
            textureHeight = BitConverter.ToUInt16(encodedData, pvrtOffset + 0x0E);

            pixelFormat = (SvrPixelFormat)encodedData[pvrtOffset + 0x08];
            dataFormat  = (SvrDataFormat)encodedData[pvrtOffset + 0x09];

            // Get the codecs and make sure we can decode using them
            pixelCodec = SvrPixelCodec.GetPixelCodec(pixelFormat);
            dataCodec = SvrDataCodec.GetDataCodec(dataFormat);

            if (dataCodec != null && pixelCodec != null)
            {
                dataCodec.PixelCodec = pixelCodec;
                canDecode = true;
            }

            // Set the palette and data offsets
            paletteEntries = dataCodec.PaletteEntries;
            if (!canDecode || paletteEntries == 0 || dataCodec.NeedsExternalPalette)
            {
                paletteOffset = -1;
                dataOffset = pvrtOffset + 0x10;
            }
            else
            {
                paletteOffset = pvrtOffset + 0x10;
                dataOffset = paletteOffset + (paletteEntries * (pixelCodec.Bpp >> 3));
            }

            initalized = true;
        }
Ejemplo n.º 20
0
        private SvrPixelFormat pixelFormat; // Pixel format

        #endregion Fields

        #region Constructors

        internal SvpPaletteEncoder(byte[][] palette, ushort numColors, SvrPixelFormat pixelFormat, VrPixelCodec pixelCodec)
            : base(palette, numColors, pixelCodec)
        {
            this.pixelFormat = pixelFormat;
        }
Ejemplo n.º 21
0
        // Checks to see if we can encode the texture based on data format specific things
        private bool CanEncode(SvrPixelFormat PixelFormat, SvrDataFormat DataFormat, int width, int height)
        {
            // The converter should check to see that a pixel codec and data codec exists,
            // along with checking that width >= 8 and height >= 8.
            switch (DataFormat)
            {
                case SvrDataFormat.Index4RectRgb5a3:
                case SvrDataFormat.Index8RectRgb5a3:
                    return (PixelFormat == SvrPixelFormat.Rgb5a3);
                case SvrDataFormat.Index4SqrRgb5a3:
                case SvrDataFormat.Index8SqrRgb5a3:
                    return (width == height && PixelFormat == SvrPixelFormat.Rgb5a3);
                case SvrDataFormat.Index4RectArgb8:
                case SvrDataFormat.Index8RectArgb8:
                    return (PixelFormat == SvrPixelFormat.Argb8888);
                case SvrDataFormat.Index4SqrArgb8:
                case SvrDataFormat.Index8SqrArgb8:
                    return (width == height && PixelFormat == SvrPixelFormat.Argb8888);
            }

            return true;
        }
Ejemplo n.º 22
0
 /// <summary>
 /// Load a clut from a byte array.
 /// </summary>
 /// <param name="array">Byte array that contains the clut data.</param>
 public SvpClutEncoder(byte[] array, ushort NumClutEntries, SvrPixelFormat PixelFormat)
     : base(array, NumClutEntries)
 {
     this.PixelFormat = PixelFormat;
 }
Ejemplo n.º 23
0
            private SvrDataFormat GetDataFormat(string format, SvrPixelFormat? PixelFormat, int width, int height)
            {
                switch (format.ToLower())
                {
                    case "rect": case "60":
                        return SvrDataFormat.Rectangle;
                    case "index4ec": case "62":
                        return SvrDataFormat.Index4ExtClut;
                    case "index8ec": case "64":
                        return SvrDataFormat.Index8ExtClut;
                    case "index4":
                        if (PixelFormat == SvrPixelFormat.Rgb5a3)
                        {
                            if (width == height) return SvrDataFormat.Index4SqrRgb5a3;
                            else return SvrDataFormat.Index4RectRgb5a3;
                        }
                        else if (PixelFormat == SvrPixelFormat.Argb8888)
                        {
                            if (width == height) return SvrDataFormat.Index4SqrArgb8;
                            else return SvrDataFormat.Index4RectArgb8;
                        }

                        break;
                    case "index8":
                        if (PixelFormat == SvrPixelFormat.Rgb5a3)
                        {
                            if (width == height) return SvrDataFormat.Index8SqrRgb5a3;
                            else return SvrDataFormat.Index8RectRgb5a3;
                        }
                        else if (PixelFormat == SvrPixelFormat.Argb8888)
                        {
                            if (width == height) return SvrDataFormat.Index8SqrArgb8;
                            else return SvrDataFormat.Index8RectArgb8;
                        }

                        break;
                    case "66": return SvrDataFormat.Index4RectRgb5a3;
                    case "67": return SvrDataFormat.Index4SqrRgb5a3;
                    case "68": return SvrDataFormat.Index4RectArgb8;
                    case "69": return SvrDataFormat.Index4SqrArgb8;
                    case "6a": return SvrDataFormat.Index8RectRgb5a3;
                    case "6b": return SvrDataFormat.Index8SqrRgb5a3;
                    case "6c": return SvrDataFormat.Index8RectArgb8;
                    case "6d": return SvrDataFormat.Index8SqrArgb8;
                }

                return SvrDataFormat.Unknown; // Unknown format
            }
Ejemplo n.º 24
0
        private bool Initalize(SvrPixelFormat pixelFormat, SvrDataFormat dataFormat)
        {
            // Set the default values
            hasGlobalIndex = true;
            globalIndex = 0;

            // Set the data format and pixel format and load the appropiate codecs
            this.pixelFormat = pixelFormat;
            pixelCodec = SvrPixelCodec.GetPixelCodec(pixelFormat);

            this.dataFormat = dataFormat;
            dataCodec = SvrDataCodec.GetDataCodec(dataFormat);

            // Make sure the pixel and data codecs exists and we can encode to it
            if (pixelCodec == null || !pixelCodec.CanEncode) return false;
            if (dataCodec == null || !dataCodec.CanEncode) return false;

            // Set the correct data format (it's ok to do it after getting the codecs).
            if (dataFormat == SvrDataFormat.Index4Rgb5a3Rectangle || dataFormat == SvrDataFormat.Index4Rgb5a3Square ||
                dataFormat == SvrDataFormat.Index4Argb8Rectangle || dataFormat == SvrDataFormat.Index4Argb8Square)
            {
                if (textureWidth == textureHeight) // Square texture
                {
                    if (pixelFormat == SvrPixelFormat.Rgb5a3)
                    {
                        dataFormat = SvrDataFormat.Index4Rgb5a3Square;
                    }
                    else
                    {
                        dataFormat = SvrDataFormat.Index4Argb8Square;
                    }
                }
                else // Rectangular texture
                {
                    if (pixelFormat == SvrPixelFormat.Rgb5a3)
                    {
                        dataFormat = SvrDataFormat.Index4Rgb5a3Rectangle;
                    }
                    else
                    {
                        dataFormat = SvrDataFormat.Index4Argb8Rectangle;
                    }
                }
            }

            else if (dataFormat == SvrDataFormat.Index8Rgb5a3Rectangle || dataFormat == SvrDataFormat.Index8Rgb5a3Square ||
                dataFormat == SvrDataFormat.Index8Argb8Rectangle || dataFormat == SvrDataFormat.Index8Argb8Square)
            {
                if (textureWidth == textureHeight) // Square texture
                {
                    if (pixelFormat == SvrPixelFormat.Rgb5a3)
                    {
                        dataFormat = SvrDataFormat.Index8Rgb5a3Square;
                    }
                    else
                    {
                        dataFormat = SvrDataFormat.Index8Argb8Square;
                    }
                }
                else // Rectangular texture
                {
                    if (pixelFormat == SvrPixelFormat.Rgb5a3)
                    {
                        dataFormat = SvrDataFormat.Index8Rgb5a3Rectangle;
                    }
                    else
                    {
                        dataFormat = SvrDataFormat.Index8Argb8Rectangle;
                    }
                }
            }

            if (dataCodec.PaletteEntries != 0)
            {
                // Convert the bitmap to an array containing indicies.
                decodedData = BitmapToRawIndexed(decodedBitmap, dataCodec.PaletteEntries, out texturePalette);

                // If this texture has an external palette file, set up the palette encoder
                if (dataCodec.NeedsExternalPalette)
                {
                    paletteEncoder = new SvpPaletteEncoder(texturePalette, (ushort)dataCodec.PaletteEntries, pixelFormat, pixelCodec);
                }
            }
            else
            {
                // Convert the bitmap to an array
                decodedData = BitmapToRaw(decodedBitmap);
            }

            return true;
        }
Ejemplo n.º 25
0
        private bool Initalize(SvrPixelFormat pixelFormat, SvrDataFormat dataFormat)
        {
            // Set the default values
            hasGlobalIndex = true;
            globalIndex    = 0;

            // Set the data format and pixel format and load the appropiate codecs
            this.pixelFormat = pixelFormat;
            pixelCodec       = SvrPixelCodec.GetPixelCodec(pixelFormat);

            this.dataFormat = dataFormat;
            dataCodec       = SvrDataCodec.GetDataCodec(dataFormat);

            // Make sure the pixel and data codecs exists and we can encode to it
            if (pixelCodec == null || !pixelCodec.CanEncode)
            {
                return(false);
            }
            if (dataCodec == null || !dataCodec.CanEncode)
            {
                return(false);
            }

            // Set the correct data format (it's ok to do it after getting the codecs).
            if (dataFormat == SvrDataFormat.Index4Rgb5a3Rectangle || dataFormat == SvrDataFormat.Index4Rgb5a3Square ||
                dataFormat == SvrDataFormat.Index4Argb8Rectangle || dataFormat == SvrDataFormat.Index4Argb8Square)
            {
                if (textureWidth == textureHeight) // Square texture
                {
                    if (pixelFormat == SvrPixelFormat.Rgb5a3)
                    {
                        dataFormat = SvrDataFormat.Index4Rgb5a3Square;
                    }
                    else
                    {
                        dataFormat = SvrDataFormat.Index4Argb8Square;
                    }
                }
                else // Rectangular texture
                {
                    if (pixelFormat == SvrPixelFormat.Rgb5a3)
                    {
                        dataFormat = SvrDataFormat.Index4Rgb5a3Rectangle;
                    }
                    else
                    {
                        dataFormat = SvrDataFormat.Index4Argb8Rectangle;
                    }
                }
            }

            else if (dataFormat == SvrDataFormat.Index8Rgb5a3Rectangle || dataFormat == SvrDataFormat.Index8Rgb5a3Square ||
                     dataFormat == SvrDataFormat.Index8Argb8Rectangle || dataFormat == SvrDataFormat.Index8Argb8Square)
            {
                if (textureWidth == textureHeight) // Square texture
                {
                    if (pixelFormat == SvrPixelFormat.Rgb5a3)
                    {
                        dataFormat = SvrDataFormat.Index8Rgb5a3Square;
                    }
                    else
                    {
                        dataFormat = SvrDataFormat.Index8Argb8Square;
                    }
                }
                else // Rectangular texture
                {
                    if (pixelFormat == SvrPixelFormat.Rgb5a3)
                    {
                        dataFormat = SvrDataFormat.Index8Rgb5a3Rectangle;
                    }
                    else
                    {
                        dataFormat = SvrDataFormat.Index8Argb8Rectangle;
                    }
                }
            }

            if (dataCodec.PaletteEntries != 0)
            {
                // Convert the bitmap to an array containing indicies.
                decodedData = BitmapToRawIndexed(decodedBitmap, dataCodec.PaletteEntries, out texturePalette);

                // If this texture has an external palette file, set up the palette encoder
                if (dataCodec.NeedsExternalPalette)
                {
                    paletteEncoder = new SvpPaletteEncoder(texturePalette, (ushort)dataCodec.PaletteEntries, pixelFormat, pixelCodec);
                }
            }
            else
            {
                // Convert the bitmap to an array
                decodedData = BitmapToRaw(decodedBitmap);
            }

            return(true);
        }
Ejemplo n.º 26
0
        SvrPixelFormat PixelFormat; // Pixel Format

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Load a clut from a memory stream.
        /// </summary>
        /// <param name="stream">MemoryStream that contains the clut data.</param>
        /// <param name="NumClutEntries">Number of entries in the clut.</param>
        public SvpClutEncoder(MemoryStream stream, ushort NumClutEntries, SvrPixelFormat PixelFormat)
            : base(stream, NumClutEntries)
        {
            this.PixelFormat = PixelFormat;
        }