Skip to content
This repository was archived by the owner on Apr 19, 2024. It is now read-only.

Commit a6ce6ac

Browse files
committed
finishing touches
1 parent 31523b2 commit a6ce6ac

2 files changed

Lines changed: 38 additions & 6 deletions

File tree

TextureGIF.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public void Draw(SpriteBatch spriteBatch, Rectangle destinationRectangle, Rectan
160160
/// </summary>
161161
public void UpdateGIF()
162162
{
163-
if (!IsPaused && !HasEnded)
163+
if (!IsPaused && !HasEnded)
164164
ForwardTicks(1);
165165
}
166166

@@ -178,7 +178,7 @@ public void ForwardTicks(int tickAmount)
178178

179179
FrameTick = 0;
180180

181-
if (FrameIndex < Frames.Length - 1)
181+
if (FrameIndex < Frames.Length - 1)
182182
FrameIndex++;
183183
else if (ShouldLoop)
184184
FrameIndex = 0;

Utilities/GIFBuilder.cs

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Drawing;
44
using System.Drawing.Imaging;
55
using System.IO;
6+
using System.Linq;
67
using Microsoft.Xna.Framework.Graphics;
78
using XnaColor = Microsoft.Xna.Framework.Color;
89

@@ -74,10 +75,11 @@ public static TextureGIF FromGIFFile(FileStream stream, GraphicsDevice graphicsD
7475
for (int x = 0; x < width; x++)
7576
for (int y = 0; y < height; y++)
7677
framePixels[x, y] = gifFrame.GetPixel(x, y);
78+
framePixels = Flip(Rotate(framePixels));
7779

7880
int flatIndex = 0;
79-
for (int x = 0; x < framePixels.GetUpperBound(0); x++)
80-
for (int y = 0; y < framePixels.GetUpperBound(1); y++)
81+
for (int x = 0; x < height; x++)
82+
for (int y = 0; y < width; y++)
8183
flattenedPixels[flatIndex++] = framePixels[x, y];
8284

8385
XnaColor[] usableColors = new XnaColor[flattenedPixels.Length];
@@ -93,8 +95,38 @@ public static TextureGIF FromGIFFile(FileStream stream, GraphicsDevice graphicsD
9395
frame.Dispose();
9496
}
9597

96-
return new TextureGIF(trueFrames.ToArray(), ticksPerFrame);
98+
return FromArray(trueFrames.ToArray(), ticksPerFrame);
9799
}
98100
}
101+
102+
private static Color[,] Rotate(Color[,] src)
103+
{
104+
int width = src.GetUpperBound(0) + 1;
105+
int height = src.GetUpperBound(1) + 1;
106+
Color[,] value = new Color[height, width];
107+
108+
for (int row = 0; row < height; row++)
109+
for (int col = 0; col < width; col++)
110+
{
111+
int newCol = height - (row + 1);
112+
value[newCol, col] = src[col, row];
113+
}
114+
115+
116+
return value;
117+
}
118+
119+
private static Color[,] Flip(Color[,] src)
120+
{
121+
int rows = src.GetUpperBound(0) + 1;
122+
int cols = src.GetUpperBound(1) + 1;
123+
Color[,] value = new Color[rows, cols];
124+
125+
for (int i = 0; i < rows; i++)
126+
for (int j = 0; j < cols; j++)
127+
value[rows - 1 - i, j] = src[i, j];
128+
129+
return value;
130+
}
99131
}
100-
}
132+
}

0 commit comments

Comments
 (0)