Skip to content

Commit

Permalink
Remove added imports
Browse files Browse the repository at this point in the history
  • Loading branch information
barnabwhy committed Jul 21, 2024
1 parent 0e5c71c commit b73dd38
Showing 1 changed file with 10 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,10 @@ Subject: [PATCH] Reduce work done in CraftMapCanvas.drawImage by limiting size


diff --git a/src/main/java/org/bukkit/craftbukkit/map/CraftMapCanvas.java b/src/main/java/org/bukkit/craftbukkit/map/CraftMapCanvas.java
index ff59f759669620795ef355c988b664bdcda39f52..59f61beb0f179d543fa6adab0989e676a06ab802 100644
index ff59f759669620795ef355c988b664bdcda39f52..54a3c1cea840f45385f1102988f8d2c8c415127b 100644
--- a/src/main/java/org/bukkit/craftbukkit/map/CraftMapCanvas.java
+++ b/src/main/java/org/bukkit/craftbukkit/map/CraftMapCanvas.java
@@ -1,8 +1,10 @@
package org.bukkit.craftbukkit.map;

import com.google.common.base.Preconditions;
import java.awt.Color;
+import java.awt.Graphics2D;
import java.awt.Image;
+import java.awt.image.BufferedImage;
import java.util.Arrays;
import org.bukkit.map.MapCanvas;
import org.bukkit.map.MapCursorCollection;
@@ -59,8 +64,10 @@ public class CraftMapCanvas implements MapCanvas {
@@ -59,8 +59,10 @@ public class CraftMapCanvas implements MapCanvas {

@Override
public void setPixel(int x, int y, byte color) {
Expand All @@ -33,7 +22,7 @@ index ff59f759669620795ef355c988b664bdcda39f52..59f61beb0f179d543fa6adab0989e676
if (this.buffer[y * 128 + x] != color) {
this.buffer[y * 128 + x] = color;
this.mapView.worldMap.setColorsDirty(x, y);
@@ -69,15 +76,19 @@ public class CraftMapCanvas implements MapCanvas {
@@ -69,15 +71,19 @@ public class CraftMapCanvas implements MapCanvas {

@Override
public byte getPixel(int x, int y) {
Expand All @@ -55,7 +44,7 @@ index ff59f759669620795ef355c988b664bdcda39f52..59f61beb0f179d543fa6adab0989e676
return this.base[y * 128 + x];
}

@@ -91,12 +102,41 @@ public class CraftMapCanvas implements MapCanvas {
@@ -91,12 +97,41 @@ public class CraftMapCanvas implements MapCanvas {

@Override
public void drawImage(int x, int y, Image image) {
Expand All @@ -70,20 +59,20 @@ index ff59f759669620795ef355c988b664bdcda39f52..59f61beb0f179d543fa6adab0989e676
+ height = image.getHeight(null);
+
+ // Create a subimage if the image is larger than the max allowed size
+ BufferedImage temp;
+ if (image.getWidth(null) >= width && image instanceof BufferedImage bImage) {
+ java.awt.image.BufferedImage temp;
+ if (image.getWidth(null) >= width && image instanceof java.awt.image.BufferedImage bImage) {
+ // If the image is larger than the max allowed size, get a subimage, otherwise use the image as is
+ if (image.getWidth(null) > width || image.getHeight(null) > height) {
+ temp = bImage.getSubimage(0, 0, width, height);
+ } else {
+ temp = bImage;
}
+ } else {
+ temp = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
+ Graphics2D graphics = temp.createGraphics();
+ temp = new java.awt.image.BufferedImage(width, height, java.awt.image.BufferedImage.TYPE_INT_ARGB);
+ java.awt.Graphics2D graphics = temp.createGraphics();
+ graphics.drawImage(image, 0, 0, null);
+ graphics.dispose();
+ }
}
+
+ byte[] bytes = MapPalette.imageToBytes(temp);
+
Expand All @@ -96,7 +85,7 @@ index ff59f759669620795ef355c988b664bdcda39f52..59f61beb0f179d543fa6adab0989e676
+
+ for (int y2 = 0; y2 < height; ++y2) {
+ System.arraycopy(bytes, 0, this.buffer, (y + y2) * 128 + x, width);
}
+ }
+ // Paper end
}

Expand Down

0 comments on commit b73dd38

Please sign in to comment.