Пример #1
0
        public static GvrDataCodec GetDataCodec(GvrDataFormat format)
        {
            switch (format)
            {
                case GvrDataFormat.Intensity4:
                    return new Intensity4();
                case GvrDataFormat.Intensity8:
                    return new Intensity8();
                case GvrDataFormat.IntensityA4:
                    return new IntensityA4();
                case GvrDataFormat.IntensityA8:
                    return new IntensityA8();
                case GvrDataFormat.Rgb565:
                    return new Rgb565();
                case GvrDataFormat.Rgb5a3:
                    return new Rgb5a3();
                case GvrDataFormat.Argb8888:
                    return new Argb8888();
                case GvrDataFormat.Index4:
                    return new Index4();
                case GvrDataFormat.Index8:
                    return new Index8();
                case GvrDataFormat.Dxt1:
                    return new Dxt1();
            }

            return null;
        }
Пример #2
0
        private static string DataFormatToString(GvrDataFormat format)
        {
            switch (format)
            {
            case GvrDataFormat.Intensity4:  return("4-bit Intensity");

            case GvrDataFormat.Intensity8:  return("8-bit Intensity");

            case GvrDataFormat.IntensityA4: return("4-bit Intensity with Alpha");

            case GvrDataFormat.IntensityA8: return("8-bit Intensity with Alpha");

            case GvrDataFormat.Rgb565:      return("RGB565");

            case GvrDataFormat.Rgb5a3:      return("RGB5A3");

            case GvrDataFormat.Argb8888:    return("ARGB8888");

            case GvrDataFormat.Index4:      return("4-bit Indexed");

            case GvrDataFormat.Index8:      return("8-bit Indexed");

            case GvrDataFormat.Dxt1:        return("DXT1 Compressed");
            }

            return("Unknown");
        }
Пример #3
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. If the data format does not require a pixel format, use GvrPixelFormat.Unknown.</param>
 /// <param name="dataFormat">Data format to encode the texture to.</param>
 public GvrTextureEncoder(string file, GvrPixelFormat pixelFormat, GvrDataFormat dataFormat) : base(file)
 {
     if (decodedBitmap != null)
     {
         initalized = Initalize(pixelFormat, dataFormat);
     }
 }
Пример #4
0
 /// <summary>
 /// Opens a texture to encode from a bitmap.
 /// </summary>
 /// <param name="source">Bitmap to encode.</param>
 /// <param name="pixelFormat">Pixel format to encode the texture to. If the data format does not require a pixel format, use GvrPixelFormat.Unknown.</param>
 /// <param name="dataFormat">Data format to encode the texture to.</param>
 public GvrTextureEncoder(Bitmap source, GvrPixelFormat pixelFormat, GvrDataFormat dataFormat)
     : base(source)
 {
     if (decodedBitmap != null)
     {
         initalized = Initalize(pixelFormat, dataFormat);
     }
 }
Пример #5
0
        byte DataFlags; // Data Flags

        #endregion Fields

        #region Constructors

        /// <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 GvrTextureEncoder(string file, GvrPixelFormat PixelFormat, GvrDataFormat DataFormat)
            : base(file)
        {
            this.PixelFormat = (byte)PixelFormat;
            this.DataFormat  = (byte)DataFormat;

            InitSuccess = Initalize();
        }
Пример #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. If the data format does not require a pixel format, use GvrPixelFormat.Unknown.</param>
 /// <param name="dataFormat">Data format to encode the texture to.</param>
 public GvrTextureEncoder(Stream source, GvrPixelFormat pixelFormat, GvrDataFormat dataFormat)
     : base(source)
 {
     if (decodedBitmap != null)
     {
         initalized = Initalize(pixelFormat, dataFormat);
     }
 }
Пример #7
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 GvrTextureEncoder(Bitmap bitmap, GvrPixelFormat PixelFormat, GvrDataFormat DataFormat)
            : base(bitmap)
        {
            this.PixelFormat = (byte)PixelFormat;
            this.DataFormat  = (byte)DataFormat;

            InitSuccess = Initalize();
        }
Пример #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. If the data format does not require a pixel format, use GvrPixelFormat.Unknown.</param>
 /// <param name="dataFormat">Data format to encode the texture to.</param>
 public GvrTextureEncoder(byte[] source, int offset, int length, GvrPixelFormat pixelFormat, GvrDataFormat dataFormat)
     : base(source, offset, length)
 {
     if (decodedBitmap != null)
     {
         initalized = Initalize(pixelFormat, dataFormat);
     }
 }
Пример #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. If the data format does not require a pixel format, use GvrPixelFormat.Unknown.</param>
 /// <param name="dataFormat">Data format to encode the texture to.</param>
 public GvrTextureEncoder(string file, GvrPixelFormat pixelFormat, GvrDataFormat dataFormat)
     : base(file)
 {
     if (decodedBitmap != null)
     {
         initalized = Initalize(pixelFormat, dataFormat);
     }
 }
Пример #10
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 GvrTextureEncoder(Stream stream, GvrPixelFormat PixelFormat, GvrDataFormat DataFormat)
            : base(stream)
        {
            this.PixelFormat = (byte)PixelFormat;
            this.DataFormat  = (byte)DataFormat;

            InitSuccess = Initalize();
        }
Пример #11
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 GvrTextureEncoder(byte[] array, GvrPixelFormat PixelFormat, GvrDataFormat DataFormat)
            : base(array)
        {
            this.PixelFormat = (byte)PixelFormat;
            this.DataFormat  = (byte)DataFormat;

            InitSuccess = Initalize();
        }
Пример #12
0
 public PakTextureInfo(string name, uint gbix, Bitmap bitmap, GvrDataFormat format = GvrDataFormat.Dxt1, NinjaSurfaceFlags flags = NinjaSurfaceFlags.Mipmapped)
 {
     Name         = name;
     GlobalIndex  = gbix;
     Image        = bitmap;
     DataFormat   = format;
     SurfaceFlags = flags;
     Mipmap       = (SurfaceFlags & NinjaSurfaceFlags.Mipmapped) != 0;
 }
Пример #13
0
 public PAKInfEntry(byte[] data)
 {
     filename = new byte[28];
     Array.Copy(data, filename, 0x1C);
     globalindex   = BitConverter.ToUInt32(data, 0x1C);
     Type          = (GvrDataFormat)BitConverter.ToUInt32(data, 0x20);
     BitDepth      = BitConverter.ToUInt32(data, 0x24);
     PixelFormat   = (GvrDataFormat)BitConverter.ToUInt32(data, 0x28);
     nWidth        = BitConverter.ToUInt32(data, 0x2C);
     nHeight       = BitConverter.ToUInt32(data, 0x30);
     TextureSize   = BitConverter.ToUInt32(data, 0x34);
     fSurfaceFlags = (NinjaSurfaceFlags)BitConverter.ToUInt32(data, 0x38);
 }
Пример #14
0
        private bool Initalize(GvrPixelFormat pixelFormat, GvrDataFormat dataFormat)
        {
            // Set the default values
            dataFlags      = GvrDataFlags.None;
            hasGlobalIndex = true;
            gbixType       = GvrGbixType.Gbix;
            globalIndex    = 0;

            // Set the data format and pixel format and load the appropiate codecs
            this.dataFormat = dataFormat;
            dataCodec       = GvrDataCodec.GetDataCodec(dataFormat);

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

            // Only palettized formats require a pixel codec.
            if (dataCodec.PaletteEntries != 0)
            {
                this.pixelFormat = pixelFormat;
                pixelCodec       = GvrPixelCodec.GetPixelCodec(pixelFormat);

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

                dataCodec.PixelCodec = pixelCodec;

                dataFlags |= GvrDataFlags.InternalPalette;

                // Convert the bitmap to an array containing indicies.
                decodedData = BitmapToRawIndexed(decodedBitmap, dataCodec.PaletteEntries, out texturePalette);
                //decodedData = BitmapToRawIndexed(decodedBitmap, 8, out texturePalette);
            }
            else
            {
                this.pixelFormat = GvrPixelFormat.Unknown;
                pixelCodec       = null;

                // Convert the bitmap to an array
                decodedData = BitmapToRaw(decodedBitmap);
            }

            return(true);
        }
Пример #15
0
        public static GvrDataCodec GetDataCodec(GvrDataFormat format)
        {
            switch (format)
            {
            case GvrDataFormat.Intensity4:
                return(new Intensity4());

            case GvrDataFormat.Intensity8:
                return(new Intensity8());

            case GvrDataFormat.IntensityA4:
                return(new IntensityA4());

            case GvrDataFormat.IntensityA8:
                return(new IntensityA8());

            case GvrDataFormat.Rgb565:
                return(new Rgb565());

            case GvrDataFormat.Rgb5a3:
                return(new Rgb5a3());

            case GvrDataFormat.Argb8888:
                return(new Argb8888());

            case GvrDataFormat.Index4:
                return(new Index4());

            case GvrDataFormat.Index8:
                return(new Index8());

            case GvrDataFormat.Dxt1:
                return(new Dxt1());
            }

            return(null);
        }
Пример #16
0
        protected override void Initalize()
        {
            // Check to see if what we are dealing with is a GVR texture
            if (!Is(encodedData))
            {
                throw new NotAValidTextureException("This is not a valid GVR texture.");
            }

            // Determine the offsets of the GBIX/GCIX (if present) and GCIX header chunks.
            if (PTMethods.Contains(encodedData, 0, Encoding.UTF8.GetBytes("GBIX")) ||
                PTMethods.Contains(encodedData, 0, Encoding.UTF8.GetBytes("GCIX")))
            {
                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 = PTMethods.ToUInt32BE(encodedData, gbixOffset + 0x08);
            }
            else
            {
                globalIndex = 0;
            }

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

            pixelFormat = (GvrPixelFormat)(encodedData[pvrtOffset + 0x0A] >> 4); // Only the first 4 bits matter
            dataFlags   = (GvrDataFlags)(encodedData[pvrtOffset + 0x0A] & 0x0F); // Only the last 4 bits matter
            dataFormat  = (GvrDataFormat)encodedData[pvrtOffset + 0x0B];

            // Get the codecs and make sure we can decode using them
            dataCodec = GvrDataCodec.GetDataCodec(dataFormat);

            // We need a pixel codec if this is a palettized texture
            if (dataCodec != null && dataCodec.PaletteEntries != 0)
            {
                pixelCodec = GvrPixelCodec.GetPixelCodec(pixelFormat);

                if (pixelCodec != null)
                {
                    dataCodec.PixelCodec = pixelCodec;
                    canDecode = true;
                }
            }
            else
            {
                pixelFormat = GvrPixelFormat.Unknown;

                if (dataCodec != null)
                {
                    canDecode = true;
                }
            }

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

            // If the texture contains mipmaps, gets the offsets of them
            if (canDecode && dataCodec.PaletteEntries == 0 && (dataFlags & GvrDataFlags.Mipmaps) != 0)
            {
                mipmapOffsets = new int[(int)Math.Log(textureWidth, 2) + 1];

                int mipmapOffset = 0;
                for (int i = 0, size = textureWidth; i < mipmapOffsets.Length; i++, size >>= 1)
                {
                    mipmapOffsets[i] = mipmapOffset;
                    mipmapOffset += Math.Max(size * size * (dataCodec.Bpp >> 3), 32);
                }
            }

            initalized = true;
        }
Пример #17
0
        private bool Initalize(GvrPixelFormat pixelFormat, GvrDataFormat dataFormat)
        {
            // Set the default values
            dataFlags = GvrDataFlags.None;
            hasGlobalIndex = true;
            gbixType = GvrGbixType.Gbix;
            globalIndex = 0;

            // Set the data format and pixel format and load the appropiate codecs
            this.dataFormat = dataFormat;
            dataCodec = GvrDataCodec.GetDataCodec(dataFormat);

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

            // Only palettized formats require a pixel codec.
            if (dataCodec.PaletteEntries != 0)
            {
                this.pixelFormat = pixelFormat;
                pixelCodec = GvrPixelCodec.GetPixelCodec(pixelFormat);

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

                dataCodec.PixelCodec = pixelCodec;

                dataFlags |= GvrDataFlags.InternalPalette;

                // Convert the bitmap to an array containing indicies.
                decodedData = BitmapToRawIndexed(decodedBitmap, dataCodec.PaletteEntries, out texturePalette);
            }
            else
            {
                this.pixelFormat = GvrPixelFormat.Unknown;
                pixelCodec = null;

                // Convert the bitmap to an array
                decodedData = BitmapToRaw(decodedBitmap);
            }

            return true;
        }
Пример #18
0
        private static string DataFormatToString(GvrDataFormat format)
        {
            switch (format)
            {
                case GvrDataFormat.Intensity4:  return "4-bit Intensity";
                case GvrDataFormat.Intensity8:  return "8-bit Intensity";
                case GvrDataFormat.IntensityA4: return "4-bit Intensity with Alpha";
                case GvrDataFormat.IntensityA8: return "8-bit Intensity with Alpha";
                case GvrDataFormat.Rgb565:      return "RGB565";
                case GvrDataFormat.Rgb5a3:      return "RGB5A3";
                case GvrDataFormat.Argb8888:    return "ARGB8888";
                case GvrDataFormat.Index4:      return "4-bit Indexed";
                case GvrDataFormat.Index8:      return "8-bit Indexed";
                case GvrDataFormat.Dxt1:        return "DXT1 Compressed";
            }

            return "Unknown";
        }
Пример #19
0
        protected override void Initalize()
        {
            // Check to see if what we are dealing with is a GVR texture
            if (!Is(encodedData))
            {
                throw new NotAValidTextureException("This is not a valid GVR texture.");
            }

            // Determine the offsets of the GBIX/GCIX (if present) and GCIX header chunks.
            if (PTMethods.Contains(encodedData, 0, Encoding.UTF8.GetBytes("GBIX")) ||
                PTMethods.Contains(encodedData, 0, Encoding.UTF8.GetBytes("GCIX")))
            {
                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 = PTMethods.ToUInt32BE(encodedData, gbixOffset + 0x08);
            }
            else
            {
                globalIndex = 0;
            }

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

            pixelFormat = (GvrPixelFormat)(encodedData[pvrtOffset + 0x0A] >> 4); // Only the first 4 bits matter
            dataFlags   = (GvrDataFlags)(encodedData[pvrtOffset + 0x0A] & 0x0F); // Only the last 4 bits matter
            dataFormat  = (GvrDataFormat)encodedData[pvrtOffset + 0x0B];

            // Get the codecs and make sure we can decode using them
            dataCodec = GvrDataCodec.GetDataCodec(dataFormat);

            // We need a pixel codec if this is a palettized texture
            if (dataCodec != null && dataCodec.PaletteEntries != 0)
            {
                pixelCodec = GvrPixelCodec.GetPixelCodec(pixelFormat);

                if (pixelCodec != null)
                {
                    dataCodec.PixelCodec = pixelCodec;
                    canDecode            = true;
                }
            }
            else
            {
                pixelFormat = GvrPixelFormat.Unknown;

                if (dataCodec != null)
                {
                    canDecode = true;
                }
            }

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

            // If the texture contains mipmaps, gets the offsets of them
            if (canDecode && paletteEntries == 0 && (dataFlags & GvrDataFlags.Mipmaps) != 0)
            {
                mipmapOffsets = new int[(int)Math.Log(textureWidth, 2) + 1];

                int mipmapOffset = 0;
                for (int i = 0, size = textureWidth; i < mipmapOffsets.Length; i++, size >>= 1)
                {
                    mipmapOffsets[i] = mipmapOffset;
                    mipmapOffset    += Math.Max(size * size * (dataCodec.Bpp >> 3), 32);
                }
            }

            initalized = true;
        }
Пример #20
0
 /// <summary>
 /// Opens a texture to encode from a stream.
 /// </summary>
 /// <param name="source">Stream that contains the texture data.</param>
 /// <param name="length">Number of bytes to read.</param>
 /// <param name="pixelFormat">Pixel format to encode the texture to. If the data format does not require a pixel format, use GvrPixelFormat.Unknown.</param>
 /// <param name="dataFormat">Data format to encode the texture to.</param>
 public GvrTextureEncoder(Stream source, int length, GvrPixelFormat pixelFormat, GvrDataFormat dataFormat)
     : base(source, length)
 {
     if (decodedBitmap != null)
     {
         initalized = Initalize(pixelFormat, dataFormat);
     }
 }