Merge branch 'feature/exr_preview' into 'master'

Feature/exr preview

See merge request sheepitrenderfarm/client!154
This commit is contained in:
Sheepit Renderfarm
2023-01-06 14:53:06 +00:00
5 changed files with 48 additions and 11 deletions

View File

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

View File

@@ -40,6 +40,7 @@ import java.text.SimpleDateFormat;
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
@@ -63,6 +64,8 @@ import java.util.regex.Pattern;
private String rendererMD5;
private String id;
private String outputImagePath;
private String previewImagePath;
private long outputImageSize;
private String path; // path inside of the archive
private String rendererCommand;
@@ -502,7 +505,7 @@ import java.util.regex.Pattern;
}
if (files.length != 0) {
new File(files[0].getAbsolutePath()).delete();
Arrays.stream(files).forEach( file -> new File(file.getAbsolutePath()).delete());
}
if (isServerBlockJob()) {
return Error.Type.RENDERER_KILLED_BY_SERVER;
@@ -547,6 +550,15 @@ import java.util.regex.Pattern;
return Error.Type.NOOUTPUTFILE;
}
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());
this.outputImageSize = new File(getOutputImagePath()).length();
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.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
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) {
try {
ZipFile zipFile = new ZipFile(zipFileName_);
@@ -227,12 +237,14 @@ public class Utils {
mimeType = URLConnection.guessContentTypeFromName(file);
}
if (mimeType == null && file.endsWith(".tga")) { // fallback for TGA
mimeType = "image/tga";
if (mimeType == null || (mimeType.equals("image/aces") && file.toLowerCase().endsWith(".exr"))) {
try {
String extension = file.substring(file.lastIndexOf('.'));
mimeType = mimeTypes.get(extension);
}
catch (IndexOutOfBoundsException e) {
e.printStackTrace();
}
if (mimeType == null && file.endsWith(".exr")) { // fallback for EXR
mimeType = "image/x-exr";
}
return mimeType;

View File

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

View File

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