Hi Juan,
Attempting to use your new FileFormatInstance.displayFunction API to write a custom displayFunction. Able to read but unable to write, as the script below shows. To run, open an .xisf, save with a new name, and you will see the error. Tried several variations, nothing works. Maybe it requires an xml format? Edit: on further tests, I got a color filter array error, maybe it is trying to parse CFA data by mistake?
Thanks,
Mike
// DisplayFunction.js
#include <pjsr/ColorSpace.jsh>
#include <pjsr/DataType.jsh>
#include <pjsr/FontFamily.jsh>
#include <pjsr/FrameStyle.jsh>
#include <pjsr/PenStyle.jsh>
#include <pjsr/SampleType.jsh>
#include <pjsr/Sizer.jsh>
#include <pjsr/StdButton.jsh>
#include <pjsr/StdIcon.jsh>
#include <pjsr/TextAlign.jsh>
#include <pjsr/UndoFlag.jsh>
function openFramePath() {
var openFileDialog = new OpenFileDialog;
openFileDialog.multipleSelections = false;
openFileDialog.caption = "Open frame";
openFileDialog.filters = [
["All supported formats", ".fit", ".fits", ".fts", ".xisf"],
["FITS Files", ".fit", ".fits", ".fts"],
["XISF Files", ".xisf"]
];
if (!openFileDialog.execute()) {
return null;
}
return openFileDialog.fileNames[0];
};
function saveFramePath() {
var saveFramePath = new SaveFileDialog;
saveFramePath.multipleSelections = false;
saveFramePath.caption = "Save frame";
saveFramePath.filters = [
["All supported formats", ".fit", ".fits", ".fts", ".xisf"],
["FITS Files", ".fit", ".fits", ".fts"],
["XISF Files", ".xisf"]
];
if (!saveFramePath.execute()) {
return null;
}
return saveFramePath.fileName;
};
function main() {
var openPath = openFramePath();
if (openPath == null) {
return;
}
console.writeln();
console.writeln("open path: ", openPath);
{
var fileFormat = new FileFormat(
File.extractExtension(openPath), true, false
);
if (fileFormat.isNull) {
throw "fileFormat.isNull";
}
var fileFormatInstance = new FileFormatInstance(fileFormat);
if (fileFormatInstance.isNull) {
throw "fileFormatInstance.isNull";
}
var result = fileFormatInstance.open(openPath, "");
if (result.length < 1) {
throw "unable to open file.";
}
if (result.length > 1) {
throw "multi-images are not supported.";
}
var displayFunction = fileFormatInstance.displayFunction;
console.writeln("displayFunction.length: ", displayFunction.length);
console.writeln("displayFunction: ", displayFunction);
for (var i = 0; i != displayFunction.length; ++i) {
console.writeln("displayFunction[", i, "].length:", displayFunction[i].length);
console.writeln("displayFunction[", i, "]:", displayFunction[i]);
}
}
var savePath = saveFramePath();
if (savePath == null) {
return;
}
console.writeln();
console.writeln("save path: ", savePath);
{
var fileFormat = new FileFormat(
File.extractExtension(savePath), false, true
);
if (fileFormat.isNull) {
throw "fileFormat.isNull";
}
var fileFormatInstance = new FileFormatInstance(fileFormat);
if (fileFormatInstance.isNull) {
throw "fileFormatInstance.isNull";
}
var result = fileFormatInstance.create(savePath, "");
if (!result) {
throw "unable to create file.";
}
// Attempt 1: invalid argument type: String expected.
fileFormatInstance.displayFunction = displayFunction;
// Attempt 2: invalid argument type: String expected.
// fileFormatInstance.displayFunction =
// [[0.5, 0, 1, 0, 1], [0.5, 0, 1, 0, 1], [0.5, 0, 1, 0, 1], [0.5, 0, 1, 0, 1]];
// Attempt 3: invalid argument type: String expected.
// fileFormatInstance.displayFunction =
// [[0.5, 0, 1, 0, 1], [0.5, 0, 1, 0, 1], [0.5, 0, 1, 0, 1], [0.5, 0, 1, 0, 1], "auto"];
}
}
main();
gc();