Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

Commit

Permalink
The most significant changes involve the refactoring of thread creati…
Browse files Browse the repository at this point in the history
…on in `Loader.java` and `RecordFX.java`, the addition of a new dependency in the `pom.xml` file, and the replacement of the `toPixmap()` method with `flipY()` in `RecordFX.java`.

1. The `pom.xml` file has been updated to include a new dependency for `javafx-swing` version `21.0.2`. This change suggests that the project is transitioning to use JavaFX for its GUI components.

2. In `Loader.java` and `RecordFX.java`, the creation of new threads has been refactored. Instead of directly creating and starting a new thread, a `Thread` object named `load` is created, set as a daemon thread, and then started. This change improves the manageability of threads in the application.

3. The `RecordFX.java` file has seen several changes. Import statements for `com.badlogic.gdx.Gdx`, `com.badlogic.gdx.graphics.Pixmap`, and `com.badlogic.gdx.graphics.PixmapIO` have been removed, while import statements for `javafx.embed.swing.SwingFXUtils`, `javafx.scene.image.PixelWriter`, `javafx.scene.image.WritableImage`, `javafx.scene.paint.Color`, and `javax.imageio.ImageIO` have been added. This indicates a shift from using the libGDX library to the JavaFX library for image processing.

4. The `toPixmap()` method in `RecordFX.java` has been replaced with `flipY()`, which creates a `WritableImage` instead of a `Pixmap`. The `writePNG()` method has also been updated to work with `WritableImage` instead of `Pixmap`, and now uses `ImageIO.write()` instead of `PixmapIO.writePNG()`. These changes further confirm the transition from libGDX to JavaFX for image processing.

5. In `SpineController.java`, the `fitWidthProperty()` and `fitHeightProperty()` listeners and bindings have been updated to add `350` and `50` respectively, instead of `368` and `103`. This change suggests a modification in the dimensions of some GUI components.

6. The `Main.recording` boolean is now set to `true` on the JavaFX Application Thread using `Platform.runLater()`. This ensures that the recording status is updated in a thread-safe manner.

7. In `ExporterController.java`, the `Start()` method of `RecordFX` is now called on a new virtual thread. This change improves the responsiveness of the application by offloading potentially time-consuming operations to a separate thread.
  • Loading branch information
Aloento committed Jan 21, 2024
1 parent d55c117 commit 0210593
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 34 deletions.
6 changes: 5 additions & 1 deletion README-Eng.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ A tool to load and export Spine animations
**Java 21** required
Pixel Buffers support required
Exporting MOV requires FFmpeg
Current version: 2.0.5
Current version: 2.1.0

![霜叶](https://i0.hdslb.com/bfs/album/[email protected] "明日方舟 - 霜叶")

## Get SuperSpineViewer

[**Released Stable Version**](https://github.com/Aloento/SuperSpineViewer/releases/latest)

```bash
java -XX:MaxRAMPercentage=75.0 --enable-preview -jar SuperSpineViewer.jar
```

### Performance Settings Reference

* High Resolution (Camera) = High Memory Requirements
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@
需要 **Java 21 21 21**
需要 像素缓冲区支持
导出 MOV 需要 FFmpeg
当前版本:2.0.5
当前版本:2.1.0

![霜叶](https://i0.hdslb.com/bfs/album/[email protected] "明日方舟 - 霜叶")

## 获得SuperSpineViewer

[**发布的稳定版本**](https://github.com/Aloento/SuperSpineViewer/releases/latest)

```bash
java -XX:MaxRAMPercentage=75.0 --enable-preview -jar SuperSpineViewer.jar
```

### 性能设置参考

* 高分辨率 (Camera) = 高内存需求
Expand Down
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>to.aloen</groupId>
<artifactId>SuperSpineViewer</artifactId>
<version>2.0.5</version>
<version>2.1.0</version>
<repositories>
<repository>
<id>sonatype</id>
Expand Down Expand Up @@ -88,6 +88,11 @@
<artifactId>javafx-fxml</artifactId>
<version>21.0.2</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-swing</artifactId>
<version>21.0.2</version>
</dependency>
<dependency>
<groupId>org.rationalityfrontline.workaround</groupId>
<artifactId>jfoenix</artifactId>
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/to/aloen/ssv/Loader.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,14 @@ public static void init() {
gdxApp = new LwjglFXApplication(adapter, Main.spineRender);
}
} else {
new Thread(() -> {
Thread load = new Thread(() -> {
if (Main.spineController.isLoaded()) {
gdxApp = new LwjglFXApplication(adapter, Main.spineRender);
Main.spineController = null;
}
}, "Loading").start();
}, "Loading");
load.setDaemon(true);
load.start();
}
}
}
52 changes: 29 additions & 23 deletions src/main/java/to/aloen/ssv/RecordFX.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
package to.aloen.ssv;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.PixmapIO;
import javafx.application.Platform;
import javafx.embed.swing.SwingFXUtils;
import javafx.scene.image.PixelReader;
import javafx.scene.image.PixelWriter;
import javafx.scene.image.WritableImage;
import javafx.scene.paint.Color;
import to.aloen.spine.Spine;

import javax.imageio.ImageIO;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Objects;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.zip.Deflater;

public abstract class RecordFX {
private static final LinkedBlockingQueue<Runnable> savePool = new LinkedBlockingQueue<>() {{
new Thread(() -> {
Thread saving = new Thread(() -> {
while (true) {
try {
take().run();
} catch (InterruptedException ignored) {
}
}
}).start();
}, "Long Saving");
saving.setDaemon(true);
saving.start();
}};

private static String fileName;
Expand All @@ -49,7 +53,7 @@ public static void Start(String fileName) {
Thread.onSpinWait();

RecordFX.fileName = fileName;
Main.recording = true;
Platform.runLater(() -> Main.recording = true);
}
}

Expand Down Expand Up @@ -127,28 +131,30 @@ private static void encodeFX() {
});
}

private static Pixmap toPixmap(final PixelReader image) {
final Pixmap pixmap = new Pixmap(Main.width, Main.height, Pixmap.Format.RGBA8888);
private static WritableImage flipY(final PixelReader image) {
final WritableImage flippedImage = new WritableImage(Main.width, Main.height);
final PixelWriter pixelWriter = flippedImage.getPixelWriter();

for (int h = 0; h < Main.height; h++) {
for (int w = 0; w < Main.width; w++) {
int argb = image.getArgb(w, h);
pixmap.drawPixel(w, h, (argb << 8) | (argb >>> 24));
for (int y = 0; y < Main.height; y++) {
for (int x = 0; x < Main.width; x++) {
Color color = image.getColor(x, y);
pixelWriter.setColor(x, Main.height - 1 - y, color);
}
}

return pixmap;
return flippedImage;
}

private static void writePNG(final Pixmap pixmap, final short index) {
private static void writePNG(final WritableImage image, final short index) {
try {
PixmapIO.writePNG(Gdx.files.absolute(
STR."\{Main.outPath}\{fileName}_Sequence\{File.separator}\{fileName}_\{index}.png"),
pixmap, Deflater.NO_COMPRESSION, true
);
} finally {
pixmap.dispose();
File outputFile = new File(STR."\{Main.outPath}\{fileName}_Sequence\{File.separator}\{fileName}_\{index}.png");
outputFile.getParentFile().mkdirs();
outputFile.createNewFile();

ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", outputFile);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (!Main.recording) {
var percent = (double) items++ / counter;
Platform.runLater(() -> Main.progressBar.setProgress(percent));
Expand All @@ -170,9 +176,9 @@ private Task(PixelReader image, short counter) {

@Override
public void run() {
final Pixmap pixmap = toPixmap(image);
final WritableImage flipY = flipY(image);
image = null;
writePNG(pixmap, counter);
writePNG(flipY, counter);
}
}
}
6 changes: 4 additions & 2 deletions src/main/java/to/aloen/ssv/controller/ExporterController.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ void B_Export() {
Spine.speed.set(Main.quality);
Spine.isPlay.set(true);

System.out.println("请求:开始录制");
RecordFX.Start(STR."\{Spine.projectName.get()}_\{Spine.animate.get()}");
Thread.startVirtualThread(() -> {
RecordFX.Start(STR."\{Spine.projectName.get()}_\{Spine.animate.get()}");
System.out.println("请求:开始录制");
});
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/to/aloen/ssv/controller/SpineController.java
Original file line number Diff line number Diff line change
Expand Up @@ -317,13 +317,13 @@ public void initialize(URL location, ResourceBundle resources) {
fitWidthProperty().addListener((_, _, newValue) -> {
T_Width.setPromptText(String.valueOf(newValue.intValue()));
width = newValue.intValue();
Pref.putDouble("stageWidth", newValue.doubleValue() + 368);
Pref.putDouble("stageWidth", newValue.doubleValue() + 350);
});

fitHeightProperty().addListener((_, _, newValue) -> {
T_Height.setPromptText(String.valueOf(newValue.intValue()));
height = newValue.intValue();
Pref.putDouble("stageHeight", newValue.doubleValue() + 103);
Pref.putDouble("stageHeight", newValue.doubleValue() + 50);
});
}};

Expand Down Expand Up @@ -367,8 +367,8 @@ public boolean isLoaded() {
Viewer.getChildren().remove(loadPane);
Viewer.setCenter(spineRender);

spineRender.fitHeightProperty().bind(spineRender.getScene().heightProperty().add(-103));
spineRender.fitWidthProperty().bind(spineRender.getScene().widthProperty().add(-368));
spineRender.fitHeightProperty().bind(spineRender.getScene().heightProperty().add(-50));
spineRender.fitWidthProperty().bind(spineRender.getScene().widthProperty().add(-350));

Viewer = null;
loadPane = null;
Expand Down

0 comments on commit 0210593

Please sign in to comment.