Skip to content

Commit

Permalink
Fix #4: don't re-encode file if it is unchanged
Browse files Browse the repository at this point in the history
  • Loading branch information
Gegy committed Sep 26, 2023
1 parent 7d38027 commit 99396f2
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion 1.14/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group 'com.mojang'
version '1.1.2-SNAPSHOT'
version '1.1.3-SNAPSHOT'

mainClassName = "com.mojang.slicer.Main"
archivesBaseName = distributions.main.distributionBaseName = "slicer-1.14"
Expand Down
2 changes: 1 addition & 1 deletion 1.20.2/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group 'com.mojang'
version '1.1.2-SNAPSHOT'
version '1.1.3-SNAPSHOT'

mainClassName = "com.mojang.slicer.Main"
archivesBaseName = distributions.main.distributionBaseName = "slicer-1.20.2"
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

group 'com.mojang'
version '1.1.2-SNAPSHOT'
version '1.1.3-SNAPSHOT'

java {
toolchain {
Expand Down
15 changes: 10 additions & 5 deletions src/main/java/com/mojang/slicer/OutputFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,18 @@ public void process(final Path root, final Path imagePath, final BufferedImage i
final int y = box.scaleY(height);
final int w = box.scaleW(width);
final int h = box.scaleH(height);
BufferedImage subImage = image.getSubimage(x, y, w, h);

for (final UnaryOperator<BufferedImage> op : transformers) {
subImage = op.apply(subImage);
}
Files.createDirectories(outputPath.getParent());

Slicer.writeImage(outputPath, subImage);
if (x == 0 && y == 0 && w == width && h == height && transformers.isEmpty()) {
Files.copy(imagePath, outputPath, StandardCopyOption.REPLACE_EXISTING);
} else {
BufferedImage subImage = image.getSubimage(x, y, w, h);
for (final UnaryOperator<BufferedImage> op : transformers) {
subImage = op.apply(subImage);
}
Slicer.writeImage(outputPath, subImage);
}

final Path inputMetaPath = getMetaPath(imagePath);
if (Files.exists(inputMetaPath)) {
Expand Down

0 comments on commit 99396f2

Please sign in to comment.