package com.its.api.utils;

import java.awt.*;
import java.awt.image.BufferedImage;

public class ImageUtils {

    public static Color getRGB(int value)
    {
        int v = value;
        int b = (v & 0xFF0000) >> 16;
        int g = (v & 0xFF00) >> 8;
        int r = v & 0xFF;

        return new Color(r, g, b);
    }

    public static void floodFill(BufferedImage image, int x, int y, int oldColor, int newColor)
    {
        if (x < 0 || y < 0) {
            return;
        }

        if (x >= image.getWidth() ||y >= image.getHeight()) {
            return;
        }

        if (image.getRGB(x, y) != oldColor) {
            return;
        }
        image.setRGB(x, y, newColor);

        floodFill(image, x - 1, y, oldColor, newColor);
        floodFill(image, x + 1, y, oldColor, newColor);
        floodFill(image, x, y - 1, oldColor, newColor);
        floodFill(image, x, y + 1, oldColor, newColor);
    }

}
