/// <summary>
/// Decodes a texture from a stream.
/// </summary>
/// <param name="source">The stream to read from.</param>
/// <param name="destination">The stream to write to.</param>
/// <param name="length">Number of bytes to read.</param>
public override void Read(Stream source, Stream destination)
{
// Reading PVR textures is done through VrSharp, so just pass it to that
VrSharp.PvrTexture.PvrTexture texture = new VrSharp.PvrTexture.PvrTexture(source);
// Check to see if this texture requires an external palette and throw an exception
// if we do not have one defined
if (texture.NeedsExternalPalette)
{
if (PaletteStream != null)
{
if (PaletteLength == -1)
{
texture.SetPalette(new PvpPalette(PaletteStream));
}
else
{
texture.SetPalette(new PvpPalette(PaletteStream, PaletteLength));
}
PaletteStream = null;
PaletteLength = -1;
}
else
{
throw new TextureNeedsPaletteException();
}
}
texture.Save(destination);
}