public static int TweetPicture(int shape, int ori, int w, int h, int squareSize, IntPtr ptr)
{
try
{
//ptr is the pointer to the photo bits.
byte[] pixels = new byte[w * h * 3];
Marshal.Copy(ptr, pixels, 0, w * h * 3);
ImageUtils.BlackOut(pixels,shape,ori,w,h);
int orientation = Tetronimos.OrientationConversion(shape, ori);
string TweetString = Tetronimos.GetString(shape, orientation);
string TweetFileName = "" + TweetString + " " + GameID + " " + numPhotos + imgExt;
makeFullImage(pixels, w, h, TweetFileName); //mainstream pictures
//twitter.UploadPhoto(pixels, TweetString, TweetFileName);
string TweetShhString = "BLOCK," + numPhotos + "," + Tetronimos.GetShhName(shape) + "," + 90*ori + ",";
byte[][] blocks = new byte[4][];
switch (shape)
{
//Derek's canonical rotations: convention: [row, column], i.e. [y,x]
case 1: //LINE
blocks[0] = ImageUtils.ImageSubset(pixels, w, h, 0, 0, w, h * 1 / 4);
blocks[1] = ImageUtils.ImageSubset(pixels, w, h, 0, h * 1 / 4, w, h * 2 / 4);
blocks[2] = ImageUtils.ImageSubset(pixels, w, h, 0, h * 2 / 4, w, h * 3 / 4);
blocks[3] = ImageUtils.ImageSubset(pixels, w, h, 0, h * 3 / 4, w, h);
for (int i = 0; i < 4; i++)
{
makeBlockImage(blocks[i], w, w, TweetShhString + i + ",0" + "," +imgExt);
}
break;
case 2: //LEL
switch (orientation)
{
case 0:
blocks[0] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 0, 0);
blocks[1] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 0, 1);
blocks[2] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 1, 1);
blocks[3] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 2, 1);
break;
case 90:
blocks[0] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 0, 2);
blocks[1] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 1, 2);
blocks[2] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 1, 1);
blocks[3] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 1, 0);
break;
case 180:
blocks[0] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 2, 1);
blocks[1] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 2, 0);
blocks[2] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 1, 0);
blocks[3] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 0, 0);
break;
case 270:
blocks[0] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 1, 0);
blocks[1] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 0, 0);
blocks[2] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 0, 1);
blocks[3] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 0, 2);
break;
}
for (int i = 0; i < 4; i++)
{
blocks[i] = ImageUtils.RotateImage90s(blocks[i], squareSize, squareSize, orientation);
}
//ROW,COL
makeBlockImage(blocks[0], squareSize, squareSize, TweetShhString + "0,0" + "," +imgExt);
makeBlockImage(blocks[1], squareSize, squareSize, TweetShhString + "0,1" + "," +imgExt);
makeBlockImage(blocks[2], squareSize, squareSize, TweetShhString + "1,1" + "," +imgExt);
makeBlockImage(blocks[3], squareSize, squareSize, TweetShhString + "2,1" + "," +imgExt);
break;
case 3: //REL
switch (orientation)
{
case 0:
blocks[0] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 0, 0);
blocks[1] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 0, 1);
blocks[2] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 1, 0);
blocks[3] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 2, 0);
break;
case 90:
blocks[0] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 0, 2);
blocks[1] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 1, 2);
blocks[2] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 0, 1);
blocks[3] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 0, 0);
break;
case 180:
blocks[0] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 2, 1);
blocks[1] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 2, 0);
blocks[2] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 1, 1);
blocks[3] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 0, 1);
break;
case 270:
blocks[0] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 1, 0);
blocks[1] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 0, 0);
blocks[2] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 1, 1);
blocks[3] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 1, 2);
break;
}
for (int i = 0; i < 4; i++)
{
blocks[i] = ImageUtils.RotateImage90s(blocks[i], squareSize, squareSize, orientation);
}
//ROW,COL
makeBlockImage(blocks[0], squareSize, squareSize, TweetShhString + "2,1" + "," +imgExt);
makeBlockImage(blocks[1], squareSize, squareSize, TweetShhString + "2,0" + "," +imgExt);
makeBlockImage(blocks[2], squareSize, squareSize, TweetShhString + "1,1" + "," +imgExt);
makeBlockImage(blocks[3], squareSize, squareSize, TweetShhString + "2,1" + "," +imgExt);
break;
case 4: //SQUARE
blocks[0] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 0, 0);
blocks[1] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 0, 1);
blocks[2] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 1, 0);
blocks[3] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 1, 1);
makeBlockImage(blocks[0], squareSize, squareSize, TweetShhString + "1,0" + "," +imgExt);
makeBlockImage(blocks[1], squareSize, squareSize, TweetShhString + "2,0" + "," +imgExt);
makeBlockImage(blocks[2], squareSize, squareSize, TweetShhString + "1,1" + "," +imgExt);
makeBlockImage(blocks[3], squareSize, squareSize, TweetShhString + "2,1" + "," +imgExt);
break;
case 5: // Z/RESS
switch (orientation)
{
case 0:
blocks[0] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 0, 0);
blocks[1] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 0, 1);
blocks[2] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 1, 1);
blocks[3] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 2, 1);
break;
case 180:
blocks[0] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 1, 0);
blocks[1] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 1, 1);
blocks[2] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 0, 1);
blocks[3] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 0, 2);
break;
}
for (int i = 0; i < 4; i++)
{
blocks[i] = ImageUtils.RotateImage90s(blocks[i], squareSize, squareSize, orientation);
}
//ROW,COL
makeBlockImage(blocks[0], squareSize, squareSize, TweetShhString + "0,0" + "," +imgExt);
makeBlockImage(blocks[1], squareSize, squareSize, TweetShhString + "0,1" + "," +imgExt);
makeBlockImage(blocks[2], squareSize, squareSize, TweetShhString + "1,1" + "," +imgExt);
makeBlockImage(blocks[3], squareSize, squareSize, TweetShhString + "2,1" + "," +imgExt);
break;
case 6: //TEE
switch (orientation)
{
case 0:
blocks[0] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 0, 0);
blocks[1] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 1, 0);
blocks[2] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 1, 1);
blocks[3] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 2, 0);
break;
case 90:
blocks[0] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 0, 2);
blocks[1] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 0, 1);
blocks[2] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 1, 1);
blocks[3] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 0, 0);
break;
case 180:
blocks[0] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 2, 1);
blocks[1] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 1, 1);
blocks[2] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 1, 0);
blocks[3] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 0, 1);
break;
case 270:
blocks[0] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 1, 2);
blocks[1] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 1, 1);
blocks[2] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 0, 1);
blocks[3] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 1, 0);
break;
}
for (int i = 0; i < 4; i++)
{
blocks[i] = ImageUtils.RotateImage90s(blocks[i], squareSize, squareSize, orientation);
}
//ROW,COL
makeBlockImage(blocks[0], squareSize, squareSize, TweetShhString + "2,2" + "," +imgExt);
makeBlockImage(blocks[1], squareSize, squareSize, TweetShhString + "1,2" + "," +imgExt);
makeBlockImage(blocks[2], squareSize, squareSize, TweetShhString + "1,1" + "," +imgExt);
makeBlockImage(blocks[3], squareSize, squareSize, TweetShhString + "0,2" + "," +imgExt);
break;
case 7: // S/LESS
switch (orientation)
{
case 0:
blocks[0] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 0, 1);
blocks[1] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 1, 1);
blocks[2] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 1, 0);
blocks[3] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 2, 0);
break;
case 180:
blocks[0] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 2, 1);
blocks[1] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 1, 1);
blocks[2] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 0, 1);
blocks[3] = ImageUtils.ImageGetSquare(pixels, w, h, squareSize, 0, 0);
break;
}
for (int i = 0; i < 4; i++)
{
blocks[i] = ImageUtils.RotateImage90s(blocks[i], squareSize, squareSize, orientation);
}
//ROW,COL
makeBlockImage(blocks[0], squareSize, squareSize, TweetShhString + "0,0" + "," +imgExt);
makeBlockImage(blocks[1], squareSize, squareSize, TweetShhString + "1,0" + "," +imgExt);
makeBlockImage(blocks[2], squareSize, squareSize, TweetShhString + "1,1" + "," +imgExt);
makeBlockImage(blocks[3], squareSize, squareSize, TweetShhString + "2,1" + "," +imgExt);
break;
}
//HACK Marshal.FreeHGlobal(ptr);
//this may cause slowdown - do it on another thread?
//TODO free image memory to prevent memory leak...
}
catch (Exception e)
{
Console.WriteLine(e);
}
numPhotos++;
return 0;
}