/// <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); } }
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(); }
/// <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(); }
/// <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); } }
/// <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); } }
/// <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(); }
/// <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); } }
/// <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); } }
public GvrTextureInfo(string name, uint gbix, Bitmap bitmap) { Name = name; GlobalIndex = gbix; DataFormat = GvrDataFormat.Unknown; PixelFormat = GvrPixelFormat.Unknown; Image = bitmap; }
/// <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); } }
/// <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(); }
public GvrTextureInfo(string name, GvrTexture texture) { Name = name; GlobalIndex = texture.GlobalIndex; DataFormat = texture.DataFormat; Mipmap = texture.HasMipmaps; PixelFormat = texture.PixelFormat; Image = texture.ToBitmap(); }
public GvrTextureInfo(TextureInfo tex) { Name = tex.Name; GlobalIndex = tex.GlobalIndex; Image = tex.Image; Mipmap = tex.Mipmap; PixelFormat = GvrPixelFormat.Unknown; DataFormat = GvrDataFormat.Unknown; }
private static string PixelFormatToString(GvrPixelFormat format) { switch (format) { case GvrPixelFormat.IntensityA8: return("8-bit Intensity with Alpha"); case GvrPixelFormat.Rgb565: return("RGB565"); case GvrPixelFormat.Rgb5a3: return("RGB5A3"); } return("None"); }
public static GvrPixelCodec GetPixelCodec(GvrPixelFormat format) { switch (format) { case GvrPixelFormat.IntensityA8: return new IntensityA8(); case GvrPixelFormat.Rgb565: return new Rgb565(); case GvrPixelFormat.Rgb5a3: return new Rgb5a3(); } return null; }
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); }
public static GvrPixelCodec GetPixelCodec(GvrPixelFormat format) { switch (format) { case GvrPixelFormat.IntensityA8: return(new IntensityA8()); case GvrPixelFormat.Rgb565: return(new Rgb565()); case GvrPixelFormat.Rgb5a3: return(new Rgb5a3()); } return(null); }
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 = (GvrPixelFormat)encodedData[0x09]; pixelCodec = GvrPixelCodec.GetPixelCodec(pixelFormat); if (pixelCodec == null) { return(false); } // Get the number of colors contained in the palette paletteEntries = PTMethods.ToUInt16BE(encodedData, 0x0E); return(true); }
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 = (GvrPixelFormat)encodedData[0x09]; pixelCodec = GvrPixelCodec.GetPixelCodec(pixelFormat); if (pixelCodec == null) return false; // Get the number of colors contained in the palette paletteEntries = PTMethods.ToUInt16BE(encodedData, 0x0E); return true; }
public GvrTextureInfo(GvrTextureInfo tex) : this((TextureInfo)tex) { PixelFormat = tex.PixelFormat; DataFormat = tex.DataFormat; }
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; }
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; }
/// <summary> /// Load a clut from a byte array. /// </summary> /// <param name="array">Byte array that contains the clut data.</param> public GvpClutEncoder(byte[] array, ushort NumClutEntries, GvrPixelFormat PixelFormat) : base(array, NumClutEntries) { this.PixelFormat = PixelFormat; }
GvrPixelFormat 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 GvpClutEncoder(MemoryStream stream, ushort NumClutEntries, GvrPixelFormat PixelFormat) : base(stream, NumClutEntries) { this.PixelFormat = PixelFormat; }
private static string PixelFormatToString(GvrPixelFormat format) { switch (format) { case GvrPixelFormat.IntensityA8: return "8-bit Intensity with Alpha"; case GvrPixelFormat.Rgb565: return "RGB565"; case GvrPixelFormat.Rgb5a3: return "RGB5A3"; } return "None"; }
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; }
private GvrPixelFormat pixelFormat; // Pixel format #endregion #region Constructors & Initalizers internal GvpPaletteEncoder(byte[][] palette, ushort numColors, GvrPixelFormat pixelFormat, VrPixelCodec pixelCodec) : base(palette, numColors, pixelCodec) { this.pixelFormat = pixelFormat; }
private GvrPixelFormat pixelFormat; // Pixel format #endregion Fields #region Constructors internal GvpPaletteEncoder(byte[][] palette, ushort numColors, GvrPixelFormat pixelFormat, VrPixelCodec pixelCodec) : base(palette, numColors, pixelCodec) { this.pixelFormat = pixelFormat; }