// 
// Decompiled by Procyon v0.6.0
// 

package com.hypixel.hytale.server.worldgen.zoom;

import java.util.Arrays;
import java.awt.image.BufferedImage;
import javax.annotation.Nonnull;

public class PixelProvider
{
    @Nonnull
    protected final int[] pixels;
    protected final int width;
    protected final int height;
    
    public PixelProvider(@Nonnull final BufferedImage image) {
        this.width = image.getWidth();
        this.height = image.getHeight();
        this.pixels = new int[this.width * this.height];
        for (int x = 0; x < image.getWidth(); ++x) {
            for (int y = 0; y < image.getHeight(); ++y) {
                this.setPixel(x, y, image.getRGB(x, y) & 0xFFFFFF);
            }
        }
    }
    
    public PixelProvider(final PixelProvider other) {
        this.pixels = Arrays.copyOf(other.pixels, other.pixels.length);
        this.width = other.width;
        this.height = other.height;
    }
    
    public int getWidth() {
        return this.width;
    }
    
    public int getHeight() {
        return this.height;
    }
    
    public int[] getPixels() {
        return this.pixels;
    }
    
    public void setPixel(final int x, final int y, final int pixel) {
        this.pixels[this.arrIndex(x, y)] = pixel;
    }
    
    public int getPixel(int x, int y) {
        if (x < 0) {
            x = 0;
        }
        else if (x >= this.width) {
            x = this.width - 1;
        }
        if (y < 0) {
            y = 0;
        }
        else if (y >= this.height) {
            y = this.height - 1;
        }
        return this.pixels[this.arrIndex(x, y)];
    }
    
    protected int arrIndex(final int x, final int y) {
        return x * this.height + y;
    }
    
    public PixelProvider copy() {
        return new PixelProvider(this);
    }
    
    @Nonnull
    @Override
    public String toString() {
        return "PixelProvider{pixels=int[" + this.pixels.length + "], width=" + this.width + ", height=" + this.height;
    }
}
