Adding support for other orientations.
This commit is contained in:
parent
6e178b77a6
commit
d3937058f9
1 changed files with 31 additions and 9 deletions
|
|
@ -173,18 +173,40 @@ public class PictureScaler {
|
||||||
ImageReadParam param = reader.getDefaultReadParam();
|
ImageReadParam param = reader.getDefaultReadParam();
|
||||||
BufferedImage img = reader.read(0, param);
|
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
|
// Recalculate scale after sub-sampling was applied
|
||||||
double scale;
|
double scale;
|
||||||
AffineTransform xform;
|
AffineTransform xform = new AffineTransform();
|
||||||
if (thumbnail.getOrientation() == 6) {
|
boolean rotate = idx >= 4;
|
||||||
xform = AffineTransform.getTranslateInstance(intermediate.getWidth() / 2d, intermediate.getHeight() / 2d);
|
|
||||||
|
if (rotate) {
|
||||||
|
xform.translate(intermediate.getWidth() / 2d, intermediate.getHeight() / 2d);
|
||||||
xform.rotate(Math.PI / 2);
|
xform.rotate(Math.PI / 2);
|
||||||
scale = (double)intermediate.getHeight() / img.getWidth();
|
scale = (double)intermediate.getHeight() / img.getWidth();
|
||||||
xform.scale(scale, scale);
|
|
||||||
xform.translate(-img.getWidth() / 2d, -img.getHeight() / 2d);
|
|
||||||
} else {
|
} else {
|
||||||
scale = (double)intermediate.getWidth() / img.getWidth();
|
scale = (double)intermediate.getWidth() / img.getWidth();
|
||||||
xform = AffineTransform.getScaleInstance(scale, scale);
|
}
|
||||||
|
xform.scale(scale, scale);
|
||||||
|
xform.scale(flipX[idx], flipY[idx]);
|
||||||
|
if (rotate) {
|
||||||
|
xform.translate(-img.getWidth() / 2d, -img.getHeight() / 2d);
|
||||||
}
|
}
|
||||||
|
|
||||||
int imgType = img.getType();
|
int imgType = img.getType();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue