Skip to content

Commit

Permalink
Use NativeImage rather than BufferedImage
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinrobot committed Jul 17, 2023
1 parent a182d8c commit bc6dbe8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
7 changes: 4 additions & 3 deletions src/client/java/net/vinrobot/mcemote/client/font/Emote.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.vinrobot.mcemote.client.font;

import java.awt.image.BufferedImage;
import net.minecraft.client.texture.NativeImage;

import java.io.IOException;
import java.time.Duration;

Expand All @@ -13,8 +14,8 @@ public interface Emote {

Frame[] loadFrames() throws IOException;

record Frame(BufferedImage image, Duration duration) {
public Frame(BufferedImage image) {
record Frame(NativeImage image, Duration duration) {
public Frame(NativeImage image) {
this(image, Duration.ofDays(1));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ private Frames loadAnimationManager(Integer integer) {
final Frames.Frame[] animatedFrames = new Frames.Frame[frames.length];
for (int i = 0; i < frames.length; i++) {
final Emote.Frame frame = frames[i];
final NativeImage nativeImage = NativeImageHelper.fromBufferedImage(frame.image());
final Glyph glyph = new NativeImageGlyph(nativeImage, advance, oversample);
final Glyph glyph = new NativeImageGlyph(frame.image(), advance, oversample);
animatedFrames[i] = new Frames.Frame(glyph, frame.duration());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.texture.NativeImage;
import net.vinrobot.mcemote.api.ffz.Emoticon;
import net.vinrobot.mcemote.client.font.Emote;
import net.vinrobot.mcemote.client.helpers.NativeImageHelper;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
Expand Down Expand Up @@ -40,6 +42,7 @@ public Frame[] loadFrames() throws IOException {
final Map<String, String> urls = this.emoticon.urls();
final String url = urls.containsKey("1") ? urls.get("1") : urls.values().iterator().next();
final BufferedImage image = Objects.requireNonNull(ImageIO.read(new URL(url)));
return new Frame[]{new Frame(image)};
final NativeImage nativeImage = NativeImageHelper.fromBufferedImage(image);
return new Frame[]{new Frame(nativeImage)};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.texture.NativeImage;
import net.vinrobot.mcemote.api.seventv.Emote;
import net.vinrobot.mcemote.api.seventv.EmoteData;
import net.vinrobot.mcemote.api.seventv.EmoteFile;
import net.vinrobot.mcemote.api.seventv.EmoteHost;
import net.vinrobot.mcemote.client.helpers.NativeImageHelper;
import webpdecoderjn.WebPDecoder;

import javax.imageio.ImageIO;
Expand Down Expand Up @@ -62,12 +64,14 @@ public Frame[] loadFrames() throws IOException {
final Frame[] frames = new Frame[frameCount];
for (int i = 0; i < frameCount; ++i) {
final WebPDecoder.WebPImageFrame frame = image.frames.get(i);
frames[i] = new Frame(frame.img, Duration.ofMillis(frame.delay));
final NativeImage nativeImage = NativeImageHelper.fromBufferedImage(frame.img);
frames[i] = new Frame(nativeImage, Duration.ofMillis(frame.delay));
}
return frames;
} else {
final BufferedImage image = Objects.requireNonNull(ImageIO.read(new URL(url)));
return new Frame[]{new Frame(image)};
final NativeImage nativeImage = NativeImageHelper.fromBufferedImage(image);
return new Frame[]{new Frame(nativeImage)};
}
}
}

0 comments on commit bc6dbe8

Please sign in to comment.