Skip to content

Commit

Permalink
Protect each image attribute writing when saving an image stack.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgobbo committed Feb 16, 2024
1 parent e9ff62d commit 9b57944
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions src/main/java/ch/psi/pshell/ui/CamServerViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2909,22 +2909,34 @@ protected String saveImages(String name, ArrayList<StreamValue> images, Map<Stri
if (id.equals(CHANNEL_IMAGE)) {
} else if (id.equals(CHANNEL_PARAMETERS)) {
Map<String, Object> pars = getProcessingParameters(first);
for (String key : pars.keySet()) {
for (String key : pars.keySet()) {
if ((pars.get(key) != null) && (pars.get(key) instanceof Map)) {
for (Object k : ((Map) pars.get(key)).keySet()) {
Object v = ((Map) pars.get(key)).get(k);
dm.setAttribute(pathImage, key + " " + k, (v == null) ? "" : v);
}
String keyName = key + " " + k;
try{
dm.setAttribute(pathImage, keyName, (v == null) ? "" : v);
} catch (Exception ex) {
Logger.getLogger(CamServerViewer.class.getName()).warning("Error set image attribute " + keyName + " to " + v + ": " + ex.getMessage());
} }
} else {
Object value = pars.get(key);
if (value == null) {
value = "";
} else if (value instanceof List) {
Class cls = (((List) value).size() > 0) ? ((List) value).get(0).getClass() : double.class;
value = Convert.toPrimitiveArray(value, cls);
//value = Convert.toDouble(value);
}
dm.setAttribute(pathImage, key, value);
try{
if (value == null) {
value = "";
} else if (value instanceof List) {
Class cls = (((List) value).size() > 0) ? ((List) value).get(0).getClass() : double.class;
if (cls == String.class){
value = Convert.toStringArray(value);
} else {
value = Convert.toPrimitiveArray(value, cls);
}
//value = Convert.toDouble(value);
}
dm.setAttribute(pathImage, key, value);
} catch (Exception ex) {
Logger.getLogger(CamServerViewer.class.getName()).warning("Error set image attribute " + key + " to " + value + ": " + ex.getMessage());
}
}
}
} else if (val.getClass().isArray()) {
Expand Down

0 comments on commit 9b57944

Please sign in to comment.