Skip to content

Commit

Permalink
Slightly optimize non-gif images
Browse files Browse the repository at this point in the history
I need a way to cache gif images... If anyone has any ideas on how to do
that, lemme know
  • Loading branch information
Morphan1 committed Feb 13, 2015
1 parent 77b46f3 commit 7e7d515
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
Expand Up @@ -13,7 +13,7 @@ public class MapAnimatedImage extends MapImage {
protected AnimationObserver observer = null;

public MapAnimatedImage(String xTag, String yTag, String visibilityTag, boolean debug, String fileTag, int width, int height) {
super(xTag, yTag, visibilityTag, debug, fileTag, width, height);
super(xTag, yTag, visibilityTag, debug, fileTag, width, height, false);
}

@Override
Expand Down
25 changes: 23 additions & 2 deletions src/main/java/net/aufdemrand/denizen/utilities/maps/MapImage.java
Expand Up @@ -16,15 +16,27 @@

public class MapImage extends MapObject {

protected boolean useCache;
protected byte[] cachedImage;
protected Image image;
protected ImageIcon imageIcon;
protected int width = 0;
protected int height = 0;
protected String fileTag;
protected String actualFile = null;

public MapImage(String xTag, String yTag, String visibilityTag, boolean debug, String fileTag, int width, int height) {
public MapImage(String xTag, String yTag, String visibilityTag, boolean debug, String fileTag,
int width, int height) {
this(xTag, yTag, visibilityTag, debug, fileTag, width, height, false);
}

public MapImage(String xTag, String yTag, String visibilityTag, boolean debug, String fileTag,
int width, int height, boolean useCache) {
super(xTag, yTag, visibilityTag, debug);
this.useCache = useCache;
if (useCache) {
this.cachedImage = null;
}
this.fileTag = fileTag;
if (width > 0 || height > 0) {
this.width = width > 0 ? width : 0;
Expand Down Expand Up @@ -61,7 +73,16 @@ public void render(MapView mapView, MapCanvas mapCanvas, dPlayer player, UUID uu
}
}
// Use custom functions to draw image to allow transparency and reduce lag intensely
byte[] bytes = imageToBytes(image, width, height);
byte[] bytes;
if (!useCache || cachedImage == null) {
bytes = imageToBytes(image, width, height);
if (useCache) {
cachedImage = bytes;
}
}
else {
bytes = cachedImage;
}
int x = getX(player, uuid);
int y = getY(player, uuid);
for (int x2 = 0; x2 < width; ++x2) {
Expand Down

0 comments on commit 7e7d515

Please sign in to comment.