 	int ymax = max(max(max(y1, y2), y3), y4);
 
 
-	*xtrans =  - transform[2];
-	*ytrans =  - transform[5];
+	*xtrans = - transform[2];
+	*ytrans = - transform[5];
+	*dwidth = xmax - xmin;
+	*dheight = ymax - ymin;
+}
+
+/* Given the set of transformation matrices, find the final destination
+ * translation wrt to the original, and size
+ */
+__host__ void find_dest_multi(float *transforms, int num_transforms, int width,
+		int height, int *xtrans, int *ytrans, int *dwidth, int *dheight)
+{
+	//Start with assuming no transformation
+	int xmin = 0;
+	int ymin = 0;
+	int xmax = width;
+	int ymax = height;
+
+	for (int i = 0; i < num_transforms; i++)
+	{
+		int index = i*9;
+		//Find the farthest transform that's above and to the left
+		if (-transforms[index + 2] < *xtrans)
+			*xtrans = -transforms[index + 2];
+		if (-transforms[index + 5] < *ytrans)
+			*ytrans = -transforms[index + 5];
+
+		//Translate the four corners to find the largest dimensions
+		int x1 = -width/2 * transforms[index]
+		         - height/2 * transforms[index + 1] + transforms[index + 2];
+		int y1 = -width/2 * transforms[index + 3]
+		         - height/2 * transforms[index + 4] + transforms[index + 5];
+		int x2 = -width/2 * transforms[index]
+		         + height/2 * transforms[index + 1] + transforms[index + 2];
+		int y2 = -width/2 * transforms[index + 3]
+		         + height/2 * transforms[index + 4] + transforms[index + 5];
+		int x3 = width/2 * transforms[index]
+		         - height/2 * transforms[index + 1] + transforms[index + 2];
+		int y3 = width/2 * transforms[index + 3]
+		         - height/2 * transforms[index + 4] + transforms[index + 5];
+		int x4 = width/2 * transforms[index]
+		         + height/2 * transforms[index + 1] + transforms[index + 2];
+		int y4 = width/2 * transforms[index + 3]
+		         + height/2 * transforms[index + 4] + transforms[index + 5];
+
+		xmin = min(min(min(min(x1, x2), x3), x4), xmin);
+		ymin = min(min(min(min(y1, y2), y3), y4), ymin);
+		xmax = max(max(max(max(x1, x2), x3), x4), xmax);
+		ymax = max(max(max(max(y1, y2), y3), y4), ymax);
+	}
+
 	*dwidth = xmax - xmin;
 	*dheight = ymax - ymin;
 }

	float *input;
	readOpenEXRFile(argv[1], &input, width, height);

	float *transform = (float *) malloc(sizeof(float) * 9);\
	transform[0] = 0.707;
	transform[1] = -0.707;
	transform[2] = 100;

		output[i] = 1;
	}

	apply_transform(input, output, new_trans, width, height, xtrans, ytrans, dwidth, dheight);
	writeOpenEXRFile("multi_trans.exr", output, dwidth, dheight);

	apply_transform(input, output, &new_trans[9], width, height, xtrans, ytrans, dwidth, dheight);
	writeOpenEXRFile("multi_orig.exr", output, dwidth, dheight);


	free(transform);
	free(output);
	free(input);
