Ok, I wrote some code and now I'm wondering if I'm on crack, the file reader not liking unix based files or the files are incorrect.
ASSUMPTIONS MADE:
- All the MIT animation files are based on 16 columns and 32 rows.
- The content is composed of 3 char's with the value of char being an int that between 0 and 255
- If I take the mod of the length of the file by 3 by 16 by 32, I will get 0
With Test.ddf, I got the file length to be 1508 chars. Now that isn't a good number since right away I know it isn't divisible by three. How do I know this? Add up all the numbers, if that number is divisible by three, then you're good. 1+5 is, 8 is not. Also that number isn't divisible by 512.
Colorchart.ddf, reads in at 1524. Divides nicely by three. But the issue is, that is only 508 (1524 / 3), not 512 colors.
To prove I'm not crazy, here is the code for it so far.
IO.ReadFile is a wrapper function around a StreamReader.ReadToEnd() so the stream is closed and what not. Code reusablity blargh. Returns a string.
public Animation(string AnimationFilePath, int Rows, int Columns)
{
// load using IO.readfile
this.Cols = Columns;
this.Rows = Rows;
// mit animation file defaults
// 32 rows x 16 columns
int manipulateRows = 32;
int manipulateCols = 16;
// non-standard MIT animation file
string[] entireAnimationFileArray = Regex.Split(IO.ReadFile(AnimationFilePath), "\r\n|\n|\n\r");
string entireAnimationFile;
if (entireAnimationFileArray.Length == 3)
{
if( !int.TryParse(entireAnimationFileArray[0], out manipulateRows) )
throw new FileLoadException("Non-standard ddf animation file, Rows [first line] did not parse");
if (!int.TryParse(entireAnimationFileArray[1], out manipulateCols))
throw new FileLoadException("Non-standard ddf animation file, Columns [second line] did not parse");
entireAnimationFile = entireAnimationFileArray[2];
}
else if (entireAnimationFileArray.Length == 1)
entireAnimationFile = entireAnimationFileArray[0];
else
throw new FileLoadException("Non-standard ddf animation file");
if (entireAnimationFile.Length % ( manipulateRows * manipulateCols * 3) != 0)
throw new FileLoadException(string.Format("Non-standard ddf animation file, the file is does not contain the proper amount of data for {0} rows and {1} columns", manipulateRows, manipulateCols));
AnimationBuffer = new int[(entireAnimationFile.Length / (manipulateRows * manipulateCols * 3))][];
for (int i = 0; i < AnimationBuffer.Length; i++)
{
AnimationBuffer[i] = new int[this.Rows * this.Cols * 3]; // RGB that bizzo
}
// think I should just stretch the image to fit.
}