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

Commit 0210593

Browse files
committed
The most significant changes involve the refactoring of thread creation 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.
1 parent d55c117 commit 0210593

File tree

7 files changed

+57
-34
lines changed

7 files changed

+57
-34
lines changed

README-Eng.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@ A tool to load and export Spine animations
44
**Java 21** required
55
Pixel Buffers support required
66
Exporting MOV requires FFmpeg
7-
Current version: 2.0.5
7+
Current version: 2.1.0
88

99
![霜叶](https://i0.hdslb.com/bfs/album/98b4fd8a12bc6dbf691b967bed625db67713dff0.png@518w.png "明日方舟 - 霜叶")
1010

1111
## Get SuperSpineViewer
1212

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

15+
```bash
16+
java -XX:MaxRAMPercentage=75.0 --enable-preview -jar SuperSpineViewer.jar
17+
```
18+
1519
### Performance Settings Reference
1620

1721
* High Resolution (Camera) = High Memory Requirements

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,18 @@
66
需要 **Java 21 21 21**
77
需要 像素缓冲区支持
88
导出 MOV 需要 FFmpeg
9-
当前版本:2.0.5
9+
当前版本:2.1.0
1010

1111
![霜叶](https://i0.hdslb.com/bfs/album/98b4fd8a12bc6dbf691b967bed625db67713dff0.png@518w.png "明日方舟 - 霜叶")
1212

1313
## 获得SuperSpineViewer
1414

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

17+
```bash
18+
java -XX:MaxRAMPercentage=75.0 --enable-preview -jar SuperSpineViewer.jar
19+
```
20+
1721
### 性能设置参考
1822

1923
* 高分辨率 (Camera) = 高内存需求

pom.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>to.aloen</groupId>
88
<artifactId>SuperSpineViewer</artifactId>
9-
<version>2.0.5</version>
9+
<version>2.1.0</version>
1010
<repositories>
1111
<repository>
1212
<id>sonatype</id>
@@ -88,6 +88,11 @@
8888
<artifactId>javafx-fxml</artifactId>
8989
<version>21.0.2</version>
9090
</dependency>
91+
<dependency>
92+
<groupId>org.openjfx</groupId>
93+
<artifactId>javafx-swing</artifactId>
94+
<version>21.0.2</version>
95+
</dependency>
9196
<dependency>
9297
<groupId>org.rationalityfrontline.workaround</groupId>
9398
<artifactId>jfoenix</artifactId>

src/main/java/to/aloen/ssv/Loader.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,14 @@ public static void init() {
131131
gdxApp = new LwjglFXApplication(adapter, Main.spineRender);
132132
}
133133
} else {
134-
new Thread(() -> {
134+
Thread load = new Thread(() -> {
135135
if (Main.spineController.isLoaded()) {
136136
gdxApp = new LwjglFXApplication(adapter, Main.spineRender);
137137
Main.spineController = null;
138138
}
139-
}, "Loading").start();
139+
}, "Loading");
140+
load.setDaemon(true);
141+
load.start();
140142
}
141143
}
142144
}

src/main/java/to/aloen/ssv/RecordFX.java

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,34 @@
11
package to.aloen.ssv;
22

3-
import com.badlogic.gdx.Gdx;
4-
import com.badlogic.gdx.graphics.Pixmap;
5-
import com.badlogic.gdx.graphics.PixmapIO;
63
import javafx.application.Platform;
4+
import javafx.embed.swing.SwingFXUtils;
75
import javafx.scene.image.PixelReader;
6+
import javafx.scene.image.PixelWriter;
7+
import javafx.scene.image.WritableImage;
8+
import javafx.scene.paint.Color;
89
import to.aloen.spine.Spine;
910

11+
import javax.imageio.ImageIO;
1012
import java.io.File;
13+
import java.io.IOException;
1114
import java.nio.file.Files;
1215
import java.nio.file.Path;
1316
import java.util.Objects;
1417
import java.util.concurrent.ArrayBlockingQueue;
1518
import java.util.concurrent.LinkedBlockingQueue;
16-
import java.util.zip.Deflater;
1719

1820
public abstract class RecordFX {
1921
private static final LinkedBlockingQueue<Runnable> savePool = new LinkedBlockingQueue<>() {{
20-
new Thread(() -> {
22+
Thread saving = new Thread(() -> {
2123
while (true) {
2224
try {
2325
take().run();
2426
} catch (InterruptedException ignored) {
2527
}
2628
}
27-
}).start();
29+
}, "Long Saving");
30+
saving.setDaemon(true);
31+
saving.start();
2832
}};
2933

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

5155
RecordFX.fileName = fileName;
52-
Main.recording = true;
56+
Platform.runLater(() -> Main.recording = true);
5357
}
5458
}
5559

@@ -127,28 +131,30 @@ private static void encodeFX() {
127131
});
128132
}
129133

130-
private static Pixmap toPixmap(final PixelReader image) {
131-
final Pixmap pixmap = new Pixmap(Main.width, Main.height, Pixmap.Format.RGBA8888);
134+
private static WritableImage flipY(final PixelReader image) {
135+
final WritableImage flippedImage = new WritableImage(Main.width, Main.height);
136+
final PixelWriter pixelWriter = flippedImage.getPixelWriter();
132137

133-
for (int h = 0; h < Main.height; h++) {
134-
for (int w = 0; w < Main.width; w++) {
135-
int argb = image.getArgb(w, h);
136-
pixmap.drawPixel(w, h, (argb << 8) | (argb >>> 24));
138+
for (int y = 0; y < Main.height; y++) {
139+
for (int x = 0; x < Main.width; x++) {
140+
Color color = image.getColor(x, y);
141+
pixelWriter.setColor(x, Main.height - 1 - y, color);
137142
}
138143
}
139144

140-
return pixmap;
145+
return flippedImage;
141146
}
142147

143-
private static void writePNG(final Pixmap pixmap, final short index) {
148+
private static void writePNG(final WritableImage image, final short index) {
144149
try {
145-
PixmapIO.writePNG(Gdx.files.absolute(
146-
STR."\{Main.outPath}\{fileName}_Sequence\{File.separator}\{fileName}_\{index}.png"),
147-
pixmap, Deflater.NO_COMPRESSION, true
148-
);
149-
} finally {
150-
pixmap.dispose();
150+
File outputFile = new File(STR."\{Main.outPath}\{fileName}_Sequence\{File.separator}\{fileName}_\{index}.png");
151+
outputFile.getParentFile().mkdirs();
152+
outputFile.createNewFile();
151153

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

171177
@Override
172178
public void run() {
173-
final Pixmap pixmap = toPixmap(image);
179+
final WritableImage flipY = flipY(image);
174180
image = null;
175-
writePNG(pixmap, counter);
181+
writePNG(flipY, counter);
176182
}
177183
}
178184
}

src/main/java/to/aloen/ssv/controller/ExporterController.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,10 @@ void B_Export() {
5858
Spine.speed.set(Main.quality);
5959
Spine.isPlay.set(true);
6060

61-
System.out.println("请求:开始录制");
62-
RecordFX.Start(STR."\{Spine.projectName.get()}_\{Spine.animate.get()}");
61+
Thread.startVirtualThread(() -> {
62+
RecordFX.Start(STR."\{Spine.projectName.get()}_\{Spine.animate.get()}");
63+
System.out.println("请求:开始录制");
64+
});
6365
}
6466
}
6567

src/main/java/to/aloen/ssv/controller/SpineController.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,13 +317,13 @@ public void initialize(URL location, ResourceBundle resources) {
317317
fitWidthProperty().addListener((_, _, newValue) -> {
318318
T_Width.setPromptText(String.valueOf(newValue.intValue()));
319319
width = newValue.intValue();
320-
Pref.putDouble("stageWidth", newValue.doubleValue() + 368);
320+
Pref.putDouble("stageWidth", newValue.doubleValue() + 350);
321321
});
322322

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

@@ -367,8 +367,8 @@ public boolean isLoaded() {
367367
Viewer.getChildren().remove(loadPane);
368368
Viewer.setCenter(spineRender);
369369

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

373373
Viewer = null;
374374
loadPane = null;

0 commit comments

Comments
 (0)