Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package cg2d.v4jpaint.filters;
- import cg2d.v4jpaint.base.BaseFilter;
- import java.awt.Point;
- import java.awt.image.BufferedImage;
- public class DisplFilters implements BaseFilter {
- public BufferedImage process(BufferedImage image){
- int W = image.getWidth();
- int H = image.getHeight();
- BufferedImage result = clone(image);
- Point[][]dmx = new Point[W][H];
- /* Vertical Flip
- for(int x = 0; x < W; x++)
- for(int y = 0; y < H; y++)
- dmx[x][y] = new Point(x, H - y - 1);
- */
- /*Horizontal Flip
- for (int x = 0; x < width; x++)
- for (int y = 0; y < height; y++)
- dmx[x][y] = new Point(width - x - 1, y);
- */
- //Wave
- for(int x = 0; x < W; x++)
- for(int y = 0; y < H; y++){
- int newY = (int) (y + Math.sin(x * 0.03) * 15.0);
- dmx[x][y] = new Point(x, newY);
- }
- for(int x = 0; x < W; x++)
- for(int y = 0; y < H; y++){
- int pixel = image.getRGB(x, y);
- int newX = dmx[x][y].x;
- int newY = dmx[x][y].y;
- if ((newX >= 0) && (newX < W) && (newY >= 0) && (newY < H))
- result.setRGB(newX, newY, pixel);
- else
- result.setRGB(x, y, pixel); // ostavi piksel tu gde jeste
- }
- return result;
- }
- private BufferedImage clone(BufferedImage source){
- int W = source.getWidth();
- int H = source.getHeight();
- BufferedImage result = new BufferedImage(W,H,BufferedImage.TYPE_INT_RGB);
- for(int x = 0; x < W; x++)
- for(int y = 0; y < H; y++)
- result.setRGB(x, y, source.getRGB(x, y));
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement