--- openphotopod-0.0.1/org/valen16/openphotopod/img/ImageHandler.java	2006-02-19 11:12:55.000000000 -0500
+++ openphotopod-0.0.1-modified/org/valen16/openphotopod/img/ImageHandler.java	2005-11-07 10:34:01.000000000 -0500
@@ -60,13 +60,14 @@
 	{
 		int size = buffer.length;
 		
-		BufferedImage res = new BufferedImage(height,width,BufferedImage.TYPE_INT_ARGB);
+		BufferedImage res = new BufferedImage(width,height,BufferedImage.TYPE_INT_ARGB);
 		
 		int[] buf = new int[3];
 		int x = 0;
 		int y = 0;
 		
 		int h = 0;
+		System.out.println("createImageNorm("+width+","+height+")");
 		while(h<size-1)
 		{
 			//create the RGB 565 Value from the bytes in the buffer
@@ -78,13 +79,14 @@
 			
 			int rgb = (new Color(buf[0], buf[1], buf[2])).getRGB();
 			if(y<height && x<width)
-			res.setRGB(height-y-1,x,rgb);
-			
-			x++;
-			if(x%height==0)
 			{
-				y++;
-				x=0;
+				res.setRGB(width-x-1,y,rgb);
+			}	
+			y++;
+			if(y%height==0)
+			{
+				x++;
+				y=0;
 			}
 			h+=2;// increment the counter
 		}
@@ -219,12 +221,13 @@
 		int x = 0;
 		int y = 0;
 		int h = 0;
+		System.out.println("createBufferFromNorm("+width+","+height+")");
 		while(h<size-1)
 		{
 			//create the RGB 565 Value from the Color value
 			Color color = null;
 			try{
-				color = new Color(res.getRGB(height-y,x));
+				color = new Color(res.getRGB(width-x,y));
 			}catch(Exception ex)
 			{
 				color = Color.BLACK;
@@ -237,11 +240,11 @@
 			
 			buffer[h] = buf[0];
 			buffer[h+1] = buf[1];
-			x++;
-			if(x%height==0)
+			y++;
+			if(y%height==0)
 			{
-				y++;
-				x=0;
+				x++;
+				y=0;
 			}
 			h+=2;// increment the counter
 		}
@@ -327,7 +330,16 @@
 			resw = w;
 			resh = (resw/aw)*ah;
 		}
-		Image scaled = img.getScaledInstance(w,h,BufferedImage.SCALE_SMOOTH);
+		// Keep the aspect ratio by scaling along the largest dimension
+		Image scaled;
+		if (w > h)
+		{
+			scaled = img.getScaledInstance(w,-1,BufferedImage.SCALE_SMOOTH);
+		}
+		else
+		{
+			scaled = img.getScaledInstance(-1,h,BufferedImage.SCALE_SMOOTH);
+		}
 		int dist_x = w - scaled.getWidth(null)/2;
 		int dist_y = h - scaled.getHeight(null)/2;
 		result.getGraphics().drawImage(scaled,0,0,Color.BLACK,null);
