public GifFrame(Gif gif, int id) : base(gif.HostSPA, id) { FrameCount = 1; VerticalFrameCount = 1; TextureScale = Vector2.one; Gif = gif; }
public override bool LoadData(byte[] data, ImagePackage package) { // Create it now: GifFile = new Gif(data); return(true); }
public static Color32[] LoadFramePixels(Color32[] prevImage, byte[] pixels, Color32[] colorTable, bool interlaceFlag, GifFrame frame) { Gif gif = frame.Gif; int fw = frame.Width; int iw = gif.Width; int ih = gif.Height; // Get transparency index: int transIndex = frame.TransparencyIndex; // Based on disposal method, we may actually be using prevImage. Color32[] fullImage = prevImage; int disposal = frame.DisposalMethod; int maxY = ih - 1; bool drawTransparent = (disposal == 2); /* * if(disposal==0){ * // Undefined - do nothing. * // - Safe to reuse prevImage here. * }else if(disposal==1){ * // Don't dispose. Return the frame from this function. * // - Safe to reuse prevImage here. * }else if(disposal==2){ * // Restore to background. * // - Safe to reuse prevImage here. * } */ if (disposal == 3) { // Restore to previous. Return prevImage. // - Can't reuse prevImage here. fullImage = null; } // Create the image area if one is needed: if (fullImage == null) { fullImage = new Color32[iw * ih]; } // Got a previous image? if (prevImage != null && prevImage != fullImage) { // Blit previous into fullImage: Array.Copy(prevImage, 0, fullImage, 0, fullImage.Length); } int startRowPoint = ((maxY - frame.OffsetY) * iw); int offSet = 0; if (interlaceFlag) { int i = 0; int row = 0; int rowPoint = startRowPoint; int pass = 0; while (pass < 4) { if (pass == 1) { rowPoint = startRowPoint - (4 * iw); offSet += 4 * fw; } else if (pass == 2) { rowPoint = startRowPoint - (2 * iw); offSet += 2 * fw; } else if (pass == 3) { rowPoint = startRowPoint - (1 * iw); offSet += 1 * fw; } int rate = 1; if (pass == 0 | pass == 1) { rate = 7; } else if (pass == 2) { rate = 3; } while (i < pixels.Length) { int colIndex = pixels[i++]; if (colIndex == transIndex) { if (drawTransparent) { fullImage[rowPoint + row + frame.OffsetX] = new Color32(0, 0, 0, 0); } } else { fullImage[rowPoint + row + frame.OffsetX] = colorTable[colIndex]; } row++; offSet++; if (row == fw) { // End of the row row = 0; rowPoint -= (rate + 1) * iw; offSet += (fw * rate); if (offSet >= pixels.Length) { pass++; offSet = 0; break; } } } } } else { int row = 0; int rowPoint = startRowPoint; for (int i = 0; i < pixels.Length; i++) { int colIndex = pixels[i]; if (colIndex == transIndex) { if (drawTransparent) { fullImage[rowPoint + row + frame.OffsetX] = new Color32(0, 0, 0, 0); } } else { fullImage[rowPoint + row + frame.OffsetX] = colorTable[colIndex]; } row++; if (row == fw) { row = 0; rowPoint -= iw; } } } // Create frame texture: Texture2D tex = new Texture2D(frame.Gif.Width, frame.Gif.Height); tex.SetPixels32(fullImage); // Make sure it filters correctly. // This is so we don't see parts of other frames around the edge of the image onscreen: tex.filterMode = FilterMode.Point; tex.Apply(); frame.Sprite = tex; if (disposal == 3) { return(prevImage); } if (disposal == 2) { // Restore to background. int graphicSize = fw * frame.Height; int row = 0; int rowPoint = startRowPoint; Color32 background = gif.BackgroundColour; for (int i = 0; i < graphicSize; i++) { fullImage[rowPoint + row + frame.OffsetX] = background; row++; if (row == fw) { // End of the row row = 0; rowPoint -= iw; } } } return(fullImage); }
public GifFormat(Gif gif) { GifFile = gif; }
public override void ClearX() { GifFile = null; }