I was wondering if there are any fast algorithms out there for taking an image and morphing it into the shape of a trapezoid (trapezium).
I found this method:
private final float A = W * 0.08f;
private final float B = W * (1f - 0.08f);
private final void createTrapezium(BufferedImage src, BufferedImage out) {
int[] pix = ((DataBufferInt) src.getRaster().getDataBuffer()).getData();
int[] pix2 = ((DataBufferInt) out.getRaster().getDataBuffer()).getData();
Arrays.fill(pix2, 0);
for (int y = 0; y < HEIGHT; y++) {
int yw = y * W;
float y_to_h = y / (float) HEIGHT;
float C_A_offset = A * (1 - y_to_h);
float trapeziumLine = -C_A_offset + B + (W - B) * y_to_h;
float k = trapeziumLine / W;
for (int x = 0; x < W; x++) {
int destX = (int) (C_A_offset + x * k);
pix2[yw + destX] = pix[yw + x];
}
}
}
But it’s pretty CPU intensive (using this in real-time for a changing background image at 30 FPS)… Is there an alternative to using JAI?