internal void Read(GifReader reader) { Byte size = reader.ReadByte(); if (size != 4) { System.Diagnostics.Debug.WriteLine("Wrong size of " + ToString()); } Byte flags = reader.ReadByte(); disposalMethod = (GifDisposalMethod)((flags & 0x1C) >> 2); userInputExpected = 0x02 == (flags & 0x02); transparency = 0x01 == (flags & 0x01); delay = reader.ReadUInt16(); transparencyIndex = reader.ReadByte(); Byte terminator = reader.ReadByte(); if (terminator != 0x00) { throw new Exception("Unknown extension terminator: 0x" + terminator.ToString("X2")); } }
/// <summary> /// Clears canvas colors and resets it to initial state /// </summary> public void Reset() { frameDisposalMethod = GifDisposalMethod.Keep; frameX = 0; frameY = 0; frameWidth = canvasWidth; frameHeight = canvasHeight; if (!canvasIsEmpty) { FillWithColor(0, 0, canvasWidth, canvasHeight, new Color32(BackgroundColor.r, BackgroundColor.g, BackgroundColor.b, 0)); canvasIsEmpty = true; } }
/// <summary> /// Method initiates new drawing, sequential calls to OutputPixel will draw everything on canvas /// </summary> /// <param name="x">Left offset of frame</param> /// <param name="y">Top offset of frame</param> /// <param name="width">Frame width</param> /// <param name="height">Frame height</param> /// <param name="palette">Color palette for this frame</param> /// <param name="transparentColorIndex">Index of transparent color, color from this index will be treated as transparent</param> /// <param name="isInterlaced">Apply deinterlacing during drawing</param> /// <param name="disposalMethod">Specifies, how to handle this frame when next frame is drawn</param> public void BeginNewFrame(int x, int y, int width, int height, Color32[] palette, int transparentColorIndex, bool isInterlaced, GifDisposalMethod disposalMethod) { switch (frameDisposalMethod) { case GifDisposalMethod.ClearToBackgroundColor: FillWithColor(frameX, frameY, frameWidth, frameHeight, new Color32(BackgroundColor.r, BackgroundColor.g, BackgroundColor.b, 0)); break; case GifDisposalMethod.Revert: if (disposalMethod != GifDisposalMethod.Keep) { Array.Copy(revertDisposalBuffer, 0, canvasColors, 0, revertDisposalBuffer.Length); } break; } switch (disposalMethod) { case GifDisposalMethod.Revert: if (revertDisposalBuffer == null) { revertDisposalBuffer = new Color32[canvasColors.Length]; } Array.Copy(canvasColors, 0, revertDisposalBuffer, 0, revertDisposalBuffer.Length); break; } framePalette = palette; frameDisposalMethod = disposalMethod; canvasIsEmpty = false; frameWidth = width; frameHeight = height; frameX = x; frameY = y; // Start before canvas, so next pixel output will load correct region frameCanvasPosition = 0; frameRowCurrent = -1; frameCanvasRowEndPosition = -1; frameTransparentColorIndex = transparentColorIndex; RouteFrameDrawing(x, y, width, height, isInterlaced); }
public void ConstructorImageFrameMetadata() { const int frameDelay = 42; const int colorTableLength = 128; const GifDisposalMethod disposalMethod = GifDisposalMethod.RestoreToBackground; var metaData = new ImageFrameMetadata(); GifFrameMetadata gifFrameMetadata = metaData.GetGifMetadata(); gifFrameMetadata.FrameDelay = frameDelay; gifFrameMetadata.ColorTableLength = colorTableLength; gifFrameMetadata.DisposalMethod = disposalMethod; var clone = new ImageFrameMetadata(metaData); GifFrameMetadata cloneGifFrameMetadata = clone.GetGifMetadata(); Assert.Equal(frameDelay, cloneGifFrameMetadata.FrameDelay); Assert.Equal(colorTableLength, cloneGifFrameMetadata.ColorTableLength); Assert.Equal(disposalMethod, cloneGifFrameMetadata.DisposalMethod); }
internal void Read(GifReader reader) { Byte size = reader.ReadByte(); if (size != 4) { System.Diagnostics.Debug.WriteLine("Wrong size of " + ToString()); } Byte flags = reader.ReadByte(); disposalMethod = (GifDisposalMethod)((flags & 0x1C) >> 2); userInputExpected = 0x02 == (flags & 0x02); transparency = 0x01 == (flags & 0x01); delay = reader.ReadUInt16(); transparencyIndex = reader.ReadByte(); Byte terminator = reader.ReadByte(); if (terminator != 0x00) { throw new Exception("Unknown extension terminator: 0x" + terminator.ToString("X2")); } }
public static GifDisposalMethod Clamp(this GifDisposalMethod m) => m <GifDisposalMethod.Preserve || m> GifDisposalMethod.RestorePrevious ? GifDisposalMethod.Preserve : m;
private void DecodeLzwImageToCanvas(int lzwMinCodeSize, int x, int y, int width, int height, Color32[] colorTable, int transparentColorIndex, bool isInterlaced, GifDisposalMethod disposalMethod) { if (header.hasGlobalColorTable) { canvas.BackgroundColor = globalColorTable[header.transparentColorIndex]; } canvas.BeginNewFrame(x, y, width, height, colorTable, transparentColorIndex, isInterlaced, disposalMethod); lzwDictionary.InitWithWordSize(lzwMinCodeSize); blockReader.StartNewReading(); lzwDictionary.DecodeStream(blockReader, canvas); blockReader.FinishReading(); }