@Test public void testVerticalBlackBars() { TriangleVerticesCalculator calculator = new TriangleVerticesCalculator(); float[] verticesData = calculator.getAspectRatioVerticesData(1280, 720, 640, 480); assertAlmostEqual(verticesData, verticalBlackBars, 0.01); }
public float[] getAspectRatioVerticesData(int widthIn, int heightIn, int widthOut, int heightOut) { System.arraycopy(defaultTriangleVerticesData, 0, triangleVerticesData, 0, defaultTriangleVerticesData.length); float aspectRatioIn = (float) widthIn / heightIn; float heightOutCalculated = (float) widthOut / aspectRatioIn; if (heightOutCalculated < heightOut) { float deltaHeight = (heightOut - heightOutCalculated) / heightOut; GetMinMax vertical = new GetMinMax(1).invoke(); triangleVerticesData[vertical.getMin1()] += deltaHeight; triangleVerticesData[vertical.getMin2()] += deltaHeight; triangleVerticesData[vertical.getMax1()] -= deltaHeight; triangleVerticesData[vertical.getMax2()] -= deltaHeight; } else { float deltaWidth = (widthOut - heightOut * aspectRatioIn) / widthOut; GetMinMax horizontal = new GetMinMax(0).invoke(); triangleVerticesData[horizontal.getMin1()] += deltaWidth; triangleVerticesData[horizontal.getMin2()] += deltaWidth; triangleVerticesData[horizontal.getMax1()] -= deltaWidth; triangleVerticesData[horizontal.getMax2()] -= deltaWidth; } return triangleVerticesData; }
TriangleVerticesCalculator { public float[] getAspectRatioVerticesData(int widthIn, int heightIn, int widthOut, int heightOut) { System.arraycopy(defaultTriangleVerticesData, 0, triangleVerticesData, 0, defaultTriangleVerticesData.length); float aspectRatioIn = (float) widthIn / heightIn; float heightOutCalculated = (float) widthOut / aspectRatioIn; if (heightOutCalculated < heightOut) { float deltaHeight = (heightOut - heightOutCalculated) / heightOut; GetMinMax vertical = new GetMinMax(1).invoke(); triangleVerticesData[vertical.getMin1()] += deltaHeight; triangleVerticesData[vertical.getMin2()] += deltaHeight; triangleVerticesData[vertical.getMax1()] -= deltaHeight; triangleVerticesData[vertical.getMax2()] -= deltaHeight; } else { float deltaWidth = (widthOut - heightOut * aspectRatioIn) / widthOut; GetMinMax horizontal = new GetMinMax(0).invoke(); triangleVerticesData[horizontal.getMin1()] += deltaWidth; triangleVerticesData[horizontal.getMin2()] += deltaWidth; triangleVerticesData[horizontal.getMax1()] -= deltaWidth; triangleVerticesData[horizontal.getMax2()] -= deltaWidth; } return triangleVerticesData; } }
TriangleVerticesCalculator { public float[] getAspectRatioVerticesData(int widthIn, int heightIn, int widthOut, int heightOut) { System.arraycopy(defaultTriangleVerticesData, 0, triangleVerticesData, 0, defaultTriangleVerticesData.length); float aspectRatioIn = (float) widthIn / heightIn; float heightOutCalculated = (float) widthOut / aspectRatioIn; if (heightOutCalculated < heightOut) { float deltaHeight = (heightOut - heightOutCalculated) / heightOut; GetMinMax vertical = new GetMinMax(1).invoke(); triangleVerticesData[vertical.getMin1()] += deltaHeight; triangleVerticesData[vertical.getMin2()] += deltaHeight; triangleVerticesData[vertical.getMax1()] -= deltaHeight; triangleVerticesData[vertical.getMax2()] -= deltaHeight; } else { float deltaWidth = (widthOut - heightOut * aspectRatioIn) / widthOut; GetMinMax horizontal = new GetMinMax(0).invoke(); triangleVerticesData[horizontal.getMin1()] += deltaWidth; triangleVerticesData[horizontal.getMin2()] += deltaWidth; triangleVerticesData[horizontal.getMax1()] -= deltaWidth; triangleVerticesData[horizontal.getMax2()] -= deltaWidth; } return triangleVerticesData; } TriangleVerticesCalculator();  TriangleVerticesCalculator(float[] triangleVerticesData); }
TriangleVerticesCalculator { public float[] getAspectRatioVerticesData(int widthIn, int heightIn, int widthOut, int heightOut) { System.arraycopy(defaultTriangleVerticesData, 0, triangleVerticesData, 0, defaultTriangleVerticesData.length); float aspectRatioIn = (float) widthIn / heightIn; float heightOutCalculated = (float) widthOut / aspectRatioIn; if (heightOutCalculated < heightOut) { float deltaHeight = (heightOut - heightOutCalculated) / heightOut; GetMinMax vertical = new GetMinMax(1).invoke(); triangleVerticesData[vertical.getMin1()] += deltaHeight; triangleVerticesData[vertical.getMin2()] += deltaHeight; triangleVerticesData[vertical.getMax1()] -= deltaHeight; triangleVerticesData[vertical.getMax2()] -= deltaHeight; } else { float deltaWidth = (widthOut - heightOut * aspectRatioIn) / widthOut; GetMinMax horizontal = new GetMinMax(0).invoke(); triangleVerticesData[horizontal.getMin1()] += deltaWidth; triangleVerticesData[horizontal.getMin2()] += deltaWidth; triangleVerticesData[horizontal.getMax1()] -= deltaWidth; triangleVerticesData[horizontal.getMax2()] -= deltaWidth; } return triangleVerticesData; } TriangleVerticesCalculator();  TriangleVerticesCalculator(float[] triangleVerticesData); float[] getScale_PreserveAspectFit(int angle, int widthIn, int heightIn, int widthOut, int heightOut); float[] getScale_PreserveAspectCrop(int angle, int widthIn, int heightIn, int widthOut, int heightOut); float[] getAspectRatioVerticesData(int widthIn, int heightIn, int widthOut, int heightOut); static float[] getDefaultTriangleVerticesData(); }
TriangleVerticesCalculator { public float[] getAspectRatioVerticesData(int widthIn, int heightIn, int widthOut, int heightOut) { System.arraycopy(defaultTriangleVerticesData, 0, triangleVerticesData, 0, defaultTriangleVerticesData.length); float aspectRatioIn = (float) widthIn / heightIn; float heightOutCalculated = (float) widthOut / aspectRatioIn; if (heightOutCalculated < heightOut) { float deltaHeight = (heightOut - heightOutCalculated) / heightOut; GetMinMax vertical = new GetMinMax(1).invoke(); triangleVerticesData[vertical.getMin1()] += deltaHeight; triangleVerticesData[vertical.getMin2()] += deltaHeight; triangleVerticesData[vertical.getMax1()] -= deltaHeight; triangleVerticesData[vertical.getMax2()] -= deltaHeight; } else { float deltaWidth = (widthOut - heightOut * aspectRatioIn) / widthOut; GetMinMax horizontal = new GetMinMax(0).invoke(); triangleVerticesData[horizontal.getMin1()] += deltaWidth; triangleVerticesData[horizontal.getMin2()] += deltaWidth; triangleVerticesData[horizontal.getMax1()] -= deltaWidth; triangleVerticesData[horizontal.getMax2()] -= deltaWidth; } return triangleVerticesData; } TriangleVerticesCalculator();  TriangleVerticesCalculator(float[] triangleVerticesData); float[] getScale_PreserveAspectFit(int angle, int widthIn, int heightIn, int widthOut, int heightOut); float[] getScale_PreserveAspectCrop(int angle, int widthIn, int heightIn, int widthOut, int heightOut); float[] getAspectRatioVerticesData(int widthIn, int heightIn, int widthOut, int heightOut); static float[] getDefaultTriangleVerticesData();  }