private static BufferedImage createTrapezium(BufferedImage src) {
int w = src.getWidth();
int h = src.getHeight();
float A = w * .1f;
float B = w * .9f;
//float C = 0;
//float D = w;
int[] pix = new int[h*w];
int[] pix2 = new int[h*w];
pix = (int[]) src.getRaster().getDataElements(0, 0,w,h, null);
for (int y = 0; y < h; y++) {
int yw = y*w;
final float y_to_h = (float) y / (float) h;
//float C_A = A;
final float C_A_offset = A* (1 - y_to_h);
//float offset = C_A_offset;
final float trapeziumLine = -C_A_offset + B + (w - B) * y_to_h;
final float k = trapeziumLine / w;
for (int x = 0; x < w; x++) {
int destX = Math.min(w - 1, Math.round(C_A_offset + x * k));
pix2[yw+destX] = pix[yw+x];
}
}
src.getRaster().setDataElements(0,0,w,h,pix2);
return src;
}
All right I got this. Wondering if this still can be improved?
The shape will always stay the same, and I would only render a square of it. So the top width is the would be the width of the square.
Edit:I just tried code on my game on my system, it can do it fine 30fps, but I believe it wont like slower computer so much, so any improvements will be great.