/** * Returns the "destination image" pixel */ private final int rotatedPixel(int x, int y) { double tx = -(cx - x); double ty = -(cy - y); double rx = cos * tx - sin * ty; double ry = cos * ty + sin * tx; return pixelBilinear(rx + cx, ry + cy); }
/** * Rotate all pixels. */ private void rotate() { int[] newpixels = new int[width * height]; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { newpixels[y * width + x] = rotatedPixel(x, y); } } raster = newpixels; }
int fy = (int) Math.floor(y); int alpha0 = alpha(pixel(fx, fy)); int alpha1 = alpha(pixel(fx + 1, fy)); int alpha2 = alpha(pixel(fx, fy + 1)); int alpha3 = alpha(pixel(fx + 1, fy + 1)); int red0 = red(pixel(fx, fy)); int red1 = red(pixel(fx + 1, fy)); int red2 = red(pixel(fx, fy + 1)); int red3 = red(pixel(fx + 1, fy + 1)); int green0 = green(pixel(fx, fy)); int green1 = green(pixel(fx + 1, fy)); int green2 = green(pixel(fx, fy + 1)); int green3 = green(pixel(fx + 1, fy + 1)); int blue0 = blue(pixel(fx, fy)); int blue1 = blue(pixel(fx + 1, fy)); int blue2 = blue(pixel(fx, fy + 1)); int blue3 = blue(pixel(fx + 1, fy + 1)); return combine(alpha, red, green, blue);
/** * Here's where we do the work. */ @Override public void imageComplete(int status) { if (status == IMAGEERROR || status == IMAGEABORTED) { consumer.imageComplete(status); return; } // filter everything rotate(); // done! consumer.setPixels(0, 0, width, height, ColorModel.getRGBdefault(), raster, 0, width); consumer.imageComplete(status); }