public Decode ( ExtendedImage image, Stream stream ) : void | ||
image | ExtendedImage | The image, where the data should be set to. /// Cannot be null (Nothing in Visual Basic). |
stream | Stream | The stream, where the image should be /// decoded from. Cannot be null (Nothing in Visual Basic). |
return | void |
public void Decode(ExtendedImage image, Stream stream)
{
_image = image;
_stream = stream;
_stream.Seek(6, SeekOrigin.Current);
ReadLogicalScreenDescriptor();
if (_logicalScreenDescriptor.GlobalColorTableFlag == true)
{
_globalColorTable = new byte[_logicalScreenDescriptor.GlobalColorTableSize * 3];
// Read the global color table from the stream
stream.Read(_globalColorTable, 0, _globalColorTable.Length);
}
int nextFlag = stream.ReadByte();
while (nextFlag != 0)
{
if (nextFlag == ImageLabel)
{
ReadFrame();
}
else if (nextFlag == ExtensionIntroducer)
{
int gcl = stream.ReadByte();
switch (gcl)
{
case GraphicControlLabel:
ReadGraphicalControlExtension();
break;
case CommentLabel:
ReadComments();
break;
case ApplicationExtensionLabel:
Skip(12);
break;
case PlainTextLabel:
Skip(13);
break;
}
}
else if (nextFlag == EndIntroducer)
{
break;
}
nextFlag = stream.ReadByte();
}
}
private void init(Stream stream, GIFFrameUpdatedCallbackMethod frameUpdatedCallback) { // set gif frame update callback this.FrameUpdatedCallback = frameUpdatedCallback; // decode gif image var gifDecoder = new GifDecoder(); var image = new ExtendedImage(); gifDecoder.Decode(image, stream); // add frames and load unity textures frames = new List<TextureGIFFrame>(); var firstFrame = new TextureGIFFrame(createTexture(image.PixelWidth, image.PixelHeight, image.Pixels), TimeSpan.FromSeconds(image.DelayTime / 100d)); frames.Add(firstFrame); var lastFrame = firstFrame; foreach (var frame in image.Frames) { var newFrame = new TextureGIFFrame(createTexture(frame.PixelWidth, frame.PixelHeight, frame.Pixels), TimeSpan.FromSeconds(frame.DelayTime / 100d)); frames.Add(newFrame); if (lastFrame != null) lastFrame.nextFrame = newFrame; lastFrame = newFrame; } // set starting image CurrentFrame = frames[0]; lastFrame.nextFrame = firstFrame; }