Skip to content
Snippets Groups Projects
Select Git revision
  • 743c10c285d444492f49e3a2f446bbe19b9e0c1d
  • main default protected
  • master
3 results

Outline.java

Blame
  • Forked from LABOUREL Arnaud / Mandelbrot Template
    Source project has a limited visibility.
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    Outline.java 1.38 KiB
    import java.util.ArrayList;
    import java.util.List;
    
    /**
     * Created by Arnaud Labourel on 04/10/2018.
     */
    public class Outline implements Transform {
        private final double threshold;
    
        public Outline(double threshold) {
            this.threshold = threshold;
        }
    
        private List<GrayColor> southEastNeighborPixels(GrayImage image, int x, int y){
            List<GrayColor> neighborPixels = new ArrayList<>();
            if (x != image.getWidth() - 1) {
                neighborPixels.add(image.getPixelGrayColor(x + 1, y));
            }
            if (y != image.getHeight() - 1) {
                neighborPixels.add(image.getPixelGrayColor(x, y + 1));
            }
            return neighborPixels;
        }
    
        @Override
        public void applyTo(GrayImage image) {
            for(int x = 0; x < image.getWidth(); x++) {
                for(int y = 0; y < image.getHeight(); y++) {
                    modifyPixel(image, x, y);
                }
            }
        }
    
        private void modifyPixel(GrayImage image, int x, int y) {
            List<GrayColor> neighborPixels = southEastNeighborPixels(image, x, y);
            ByteGrayColor newColor = ByteGrayColor.WHITE;
    
            for(GrayColor neighborPixel : neighborPixels){
    
                if(Math.abs(neighborPixel.getLuminosity() - image.getPixelGrayColor(x,y).getLuminosity()) > threshold) {
                    newColor = ByteGrayColor.BLACK;
                }
            }
    
            image.setPixel(newColor, x, y);
        }
    
    }