Feat: extract exr preview file to be displayed on GUI

This commit is contained in:
harlekin
2023-01-06 14:53:06 +00:00
committed by Sheepit Renderfarm
parent 3cb7b5fc5f
commit 690ad36adb
5 changed files with 48 additions and 11 deletions

View File

@@ -1164,6 +1164,12 @@ import okhttp3.HttpUrl;
frame.delete(); frame.delete();
ajob.setOutputImagePath(null); ajob.setOutputImagePath(null);
if (ajob.getPreviewImagePath() != null) {
frame = new File(ajob.getPreviewImagePath());
frame.delete();
ajob.setPreviewImagePath(null);
}
return confirmJobReturnCode; return confirmJobReturnCode;
} }

View File

@@ -40,6 +40,7 @@ import java.text.SimpleDateFormat;
import java.time.Duration; import java.time.Duration;
import java.time.Instant; import java.time.Instant;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@@ -63,6 +64,8 @@ import java.util.regex.Pattern;
private String rendererMD5; private String rendererMD5;
private String id; private String id;
private String outputImagePath; private String outputImagePath;
private String previewImagePath;
private long outputImageSize; private long outputImageSize;
private String path; // path inside of the archive private String path; // path inside of the archive
private String rendererCommand; private String rendererCommand;
@@ -502,7 +505,7 @@ import java.util.regex.Pattern;
} }
if (files.length != 0) { if (files.length != 0) {
new File(files[0].getAbsolutePath()).delete(); Arrays.stream(files).forEach( file -> new File(file.getAbsolutePath()).delete());
} }
if (isServerBlockJob()) { if (isServerBlockJob()) {
return Error.Type.RENDERER_KILLED_BY_SERVER; return Error.Type.RENDERER_KILLED_BY_SERVER;
@@ -547,6 +550,15 @@ import java.util.regex.Pattern;
return Error.Type.NOOUTPUTFILE; return Error.Type.NOOUTPUTFILE;
} }
else { else {
if (files.length == 2) {
Arrays.sort(files); //in case of an exr we end up with 2 images, the output as an exr and the preview as a jpg, we want to ensure the output comes first
String path = files[1].getAbsolutePath();
String extension = path.substring(path.lastIndexOf(".") + 1).toLowerCase();
if ("jpg".equals(extension)) {
setPreviewImagePath(files[1].getAbsolutePath());
}
}
setOutputImagePath(files[0].getAbsolutePath()); setOutputImagePath(files[0].getAbsolutePath());
this.outputImageSize = new File(getOutputImagePath()).length(); this.outputImageSize = new File(getOutputImagePath()).length();
log.debug(String.format("Job::render pictureFilename: %s, size: %d'", getOutputImagePath(), this.outputImageSize)); log.debug(String.format("Job::render pictureFilename: %s, size: %d'", getOutputImagePath(), this.outputImageSize));

View File

@@ -41,11 +41,21 @@ import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.TimeZone; import java.util.TimeZone;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
public class Utils { public class Utils {
private static Map<String, String> mimeTypes = new HashMap<>();
static {
mimeTypes.put(".tga", "image/tga");
mimeTypes.put(".exr", "image/x-exr");
}
public static int unzipFileIntoDirectory(String zipFileName_, String destinationDirectory, char[] password, Log log) { public static int unzipFileIntoDirectory(String zipFileName_, String destinationDirectory, char[] password, Log log) {
try { try {
ZipFile zipFile = new ZipFile(zipFileName_); ZipFile zipFile = new ZipFile(zipFileName_);
@@ -227,12 +237,14 @@ public class Utils {
mimeType = URLConnection.guessContentTypeFromName(file); mimeType = URLConnection.guessContentTypeFromName(file);
} }
if (mimeType == null && file.endsWith(".tga")) { // fallback for TGA if (mimeType == null || (mimeType.equals("image/aces") && file.toLowerCase().endsWith(".exr"))) {
mimeType = "image/tga"; try {
} String extension = file.substring(file.lastIndexOf('.'));
mimeType = mimeTypes.get(extension);
if (mimeType == null && file.endsWith(".exr")) { // fallback for EXR }
mimeType = "image/x-exr"; catch (IndexOutOfBoundsException e) {
e.printStackTrace();
}
} }
return mimeType; return mimeType;

View File

@@ -47,7 +47,6 @@ import javax.swing.border.EmptyBorder;
import java.awt.AWTException; import java.awt.AWTException;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.FontMetrics; import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.GridBagLayout; import java.awt.GridBagLayout;
import java.awt.Image; import java.awt.Image;
@@ -64,7 +63,6 @@ import java.awt.image.BufferedImage;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.net.URL; import java.net.URL;
import java.util.Objects;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;

View File

@@ -31,6 +31,7 @@ import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.awt.Image; import java.awt.Image;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.Date; import java.util.Date;
import java.util.Objects; import java.util.Objects;
@@ -416,8 +417,16 @@ public class Working implements Activity {
icon = new ImageIcon(getClass().getResource("/frame_power_detection.jpg")); icon = new ImageIcon(getClass().getResource("/frame_power_detection.jpg"));
} }
else { else {
String path = null;
try { try {
String path = lastJob.getOutputImagePath(); boolean hasPreview = lastJob.getPreviewImagePath() != null;
if (hasPreview) {
path = lastJob.getPreviewImagePath();
}
else {
path = lastJob.getOutputImagePath();
}
BufferedImage img = ImageIO.read(new File(path)); BufferedImage img = ImageIO.read(new File(path));
float width = img.getWidth(); float width = img.getWidth();
@@ -433,7 +442,7 @@ public class Working implements Activity {
} }
catch (Exception e) { catch (Exception e) {
log.error(String.format("Working::showLastRender() Unable to load/preview rendered frame [%s]. Exception %s", log.error(String.format("Working::showLastRender() Unable to load/preview rendered frame [%s]. Exception %s",
lastJob.getOutputImagePath(), e.getMessage())); path, e.getMessage()));
} }
} }