Author Topic: PJSR: 1185 Win7 FileFormatInstance.displayFunction issue?  (Read 4880 times)

Offline mschuster

  • PTeam Member
  • PixInsight Jedi
  • *****
  • Posts: 1087
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

Code: [Select]
// 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();
« Last Edit: 2015 October 11 16:06:01 by mschuster »

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: PJSR: 1185 Win7 FileFormatInstance.displayFunction issue?
« Reply #1 on: 2015 October 30 09:42:18 »
Hi Mike,

This is a bug in build 1185. It is now fixed in version 1.8.4.1187, where your test script works without problems (the generated XISF file is invalid, of course, since it does not store any image).

The displayFunction property, namey:

Array FileFormatInstance.displayFunction

is an array of four arrays:

[[m0,s0,h0,l0,r0],
 [m1,s1,h1,l1,r1],
 [m2,s2,h2,l2,r2],
 [m3,s3,h3,l3,r3]]


where the vector components are parameters of a display function property:

mi    midtones balance
si    shadows clipping point
hi    highlights clipping point
li    shadows dynamic range expansion
ri    highlights dynamic range expansion


and array subscripts correspond to the following image components:

0    Red/Gray
1    Green
2    Blue
3    Lightness


For more details on display function parameters, see the XISF specification and the PCL documentation for the pcl::DisplayFunction class.

Thank you for discovering this bug.
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline mschuster

  • PTeam Member
  • PixInsight Jedi
  • *****
  • Posts: 1087
Re: PJSR: 1185 Win7 FileFormatInstance.displayFunction issue?
« Reply #2 on: 2015 November 14 08:37:10 »
Thank you Juan for this information and fix. I am using this now, it is working well.

Would it make sense to include a "Use 24-bit STF LUTs" property in a View and in .xisf, and have a scriptable interface?

Some script generated images with a set displayFunction really need to use 24-bit STF to visualize properly, it would be nice to be able to tag them appropriately. But on slower computers this could be a performance issue (my laptop), so I am not sure this is a good idea.

Thanks,
Mike