Author Topic: Dumb questions related to Javascript programming in PixInsight (part 1):  (Read 2908 times)

Offline bulrichl

  • PixInsight Guru
  • ****
  • Posts: 524
In my first private JavaScript "project" I wanted to retrieve some specific metadata from the raw camera file (CR2), metadata that cannot be found in the XISF file. So I wrote a script that reads the whole CR2 file, searches for the Image File Directories (IFDs), gets the Exif tags and retrieves some data, e. g. the camera temperature. Apparently you can read such a file only into a ByteArray, so I did it. Then, in order to get the data from the ByteArray, I programmed the data fetching for each data type that a CR2 file may contain: byte, word, long, rational each signed/unsigned; single and double float, character and string and the conversion of APEX values (Shutter Speed and Aperture).

OK, the script works, but I am convinced that if anybody ever had a look at that code, he would judge that this is not JavaScript. Part of the code (especially the data fetching) looks rather circumstancial and I ask me, whether one is able to achieve the same result more elegantly and also performing much better. (Whereas in this case performance was not an important criterium, I have other projects in mind where performance is absolutely crucial.) Maybe JavaScript might not be the best choice of programming language to realize this 'close to bits and bytes' project, maybe I am simply missing the obvious.

Here the first part of my questions:

1) In the Object Explorer some Core JavaScript Objects are marked with a ball, others with a pyramid or tetraeder - what do the different symbols mean?
2) Is it possible to read directly from a file into a typed array instead into a ByteArray (reason: performance of subsequent data processing)?
3) Array, ByteArray, typed Arrays; is it possible to convert one into another and how? Or is there actually no need for such conversions because in JavaScript there are different ways to achieve that?
4) Is it possible to retrieve data from a ByteArray in a more elegant way than I did or is it really necessary to program a function for each data type?
5) The ByteArray method "buffer.insert()" throws an error, when the Byte Array is created by: "var buffer = new ByteArray();". However, it works without error with "var buffer = new ByteArray(1);". But then one has to remove the last byte from the ByteArray in order to get the correct ByteArray.length. So why is it not possible to insert into an empty ByteArray? Is this a peculiarity of JavaScript?

Please consider that I am totally unexperienced with object oriented programming, so some questions may seem rather dumb. I would also appreciate replies like "the answer can be found here: (link)".

Bernd