package mapped;

import java.awt.Component;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Point;
import java.awt.Shape;
import java.awt.color.ColorSpace;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;
import java.awt.image.DirectColorModel;
import java.awt.image.Raster;
import java.awt.image.WritableRaster;
import java.util.Hashtable;
import net.runelite.mapping.ObfuscatedName;
import net.runelite.mapping.ObfuscatedSignature;
import net.runelite.rs.api.RSRasterProvider;

@ObfuscatedName("bg")
public final class RasterProvider extends AbstractRasterProvider implements RSRasterProvider {
   @ObfuscatedName("at")
   Component component;
   @ObfuscatedName("ah")
   Image image;

   RasterProvider(int var1, int var2, Component var3, boolean var4) {
      super.width = var1;
      super.height = var2;
      super.pixels = new int[var2 * var1 + 1];
      if(var4) {
         super.field5217 = new float[var2 * var1 + 1];
      }

      DataBufferInt var5 = new DataBufferInt(super.pixels, super.pixels.length);
      DirectColorModel var6 = new DirectColorModel(32, 16711680, 65280, 255);
      WritableRaster var7 = Raster.createWritableRaster(var6.createCompatibleSampleModel(super.width, super.height), var5, (Point)null);
      this.image = new BufferedImage(var6, var7, false, new Hashtable());
      this.setComponent_base(var3);
      this.apply_base();
      this.init(var1, var2, var3, var4);
   }

   @ObfuscatedName("at")
   @ObfuscatedSignature(
      descriptor = "(Ljava/awt/Component;B)V",
      garbageValue = "22"
   )
   final void setComponent_base(Component var1) {
      this.component = var1;
   }

   @ObfuscatedName("ah")
   @ObfuscatedSignature(
      descriptor = "(IIB)V",
      garbageValue = "-32"
   )
   public final void drawFull_base(int var1, int var2) {
      this.drawFull0_base(this.component.getGraphics(), var1, var2);
   }

   @ObfuscatedName("ar")
   @ObfuscatedSignature(
      descriptor = "(IIIIB)V",
      garbageValue = "1"
   )
   public final void draw_base(int var1, int var2, int var3, int var4) {
      this.draw0_base(this.component.getGraphics(), var1, var2, var3, var4);
   }

   @ObfuscatedName("ao")
   @ObfuscatedSignature(
      descriptor = "(Ljava/awt/Graphics;III)V",
      garbageValue = "-321512657"
   )
   final void drawFull0_base(Graphics var1, int var2, int var3) {
      SpriteMask.client.getCallbacks().draw(this, var1, var2, var3);
   }

   @ObfuscatedName("ab")
   @ObfuscatedSignature(
      descriptor = "(Ljava/awt/Graphics;IIIIB)V",
      garbageValue = "58"
   )
   final void draw0_base(Graphics var1, int var2, int var3, int var4, int var5) {
      try {
         Shape var6 = var1.getClip();
         var1.clipRect(var2, var3, var4, var5);
         var1.drawImage(this.image, 0, 0, this.component);
         var1.setClip(var6);
      } catch (Exception var7) {
         this.component.repaint();
      }

   }

   public void setImage(Image var1) {
      this.image = var1;
   }

   public void init(int var1, int var2, Component var3, boolean var4) {
      if(SpriteMask.client.isGpu()) {
         int[] var5 = this.getPixels();
         DataBufferInt var6 = new DataBufferInt(var5, var5.length);
         DirectColorModel var7 = new DirectColorModel(ColorSpace.getInstance(1000), 32, 16711680, 65280, 255, -16777216, true, 3);
         WritableRaster var8 = Raster.createWritableRaster(var7.createCompatibleSampleModel(var1, var2), var6, (Point)null);
         BufferedImage var9 = new BufferedImage(var7, var8, true, new Hashtable());
         this.setImage(var9);
      }
   }

   public Component getCanvas() {
      return this.component;
   }

   public Image getImage() {
      return this.image;
   }
}
