Adding support for other orientations.

This commit is contained in:
Knut Forkalsrud 2009-08-15 15:18:19 -07:00
parent 6e178b77a6
commit d3937058f9

View file

@ -173,18 +173,40 @@ public class PictureScaler {
ImageReadParam param = reader.getDefaultReadParam();
BufferedImage img = reader.read(0, param);
// The orientation is about flipping and rotating. Here is what an 'F' looks like
// on pictures with each orientation.
//
// 1 2 3 4 5 6 7 8
//
// 888888 888888 88 88 8888888888 88 88 8888888888
// 88 88 88 88 88 88 88 88 88 88 88 88
// 8888 8888 8888 8888 88 8888888888 8888888888 88
// 88 88 88 88
// 88 88 888888 888888
//
// The first four are obtained with only flipping X and/or Y
// The last four are obtained by rotating 90 degrees and then flipping X and/or Y.
double[] flipX = new double[] { +1, -1, -1, +1, -1, +1, +1, -1 };
double[] flipY = new double[] { +1, +1, -1, -1, +1, +1, -1, -1 };
int idx = thumbnail.getOrientation() - 1;
// Recalculate scale after sub-sampling was applied
double scale;
AffineTransform xform;
if (thumbnail.getOrientation() == 6) {
xform = AffineTransform.getTranslateInstance(intermediate.getWidth() / 2d, intermediate.getHeight() / 2d);
AffineTransform xform = new AffineTransform();
boolean rotate = idx >= 4;
if (rotate) {
xform.translate(intermediate.getWidth() / 2d, intermediate.getHeight() / 2d);
xform.rotate(Math.PI / 2);
scale = (double)intermediate.getHeight() / img.getWidth();
xform.scale(scale, scale);
scale = (double)intermediate.getHeight() / img.getWidth();
} else {
scale = (double)intermediate.getWidth() / img.getWidth();
}
xform.scale(scale, scale);
xform.scale(flipX[idx], flipY[idx]);
if (rotate) {
xform.translate(-img.getWidth() / 2d, -img.getHeight() / 2d);
} else {
scale = (double)intermediate.getWidth() / img.getWidth();
xform = AffineTransform.getScaleInstance(scale, scale);
}
int imgType = img.getType();