I am struggling to read data from a binary file. The file is a Tiff or RAW or JPEG image file. I have a working stack that uses Open URL commands but its is quite slow when dealing with multiple files on a SD card so I'm rewriting some handlers to only read in meta data from the image file.
My handler for reading selected bytes is here.
Code: Select all
function ReadFileBytes pfileName, pStartByte, pByteCount
/* pfileName is the full path to a file
LowByte and HighByte are integers specifying bytes requied
Note: codes adds a byte offset to account for JPEG files
*/
put 0 into tOffset
set itemdel to "."
put the last item of pFileName into tExtn
If tExtn is "jpg" then put 12 into tOffset
Open File pfileName for binary read
read from file pfileName at (pStartByte+tOffset) for pByteCount int1
Close File pfileName
return it
end ReadFileBytes
The read operation returns a comma separated list of decimal values which is good because it save me the effort of doing conversions. However the problem which originates with the line
is that it seems that binary read returns two's compliment eight bit binary.Open File pfileName for binary read
An example from the file is 0x87 (hex), I want the 255 bit decode of 135 decimal, but read from file returns -121 decimal. Now I could just add 256 to all negative values but that is a bit of a cop out as I'm sure there should be a way of specifying a non two's complement read.
From the dictionary :
I take this to mean the the list of encoding enumerations are only applicable to text files but when I try to use them I just get an unsupported error:open file filePath [for [ {[encoding] text | binary}] {update | read | write | append}]
Code: Select all
Open File pfileName for "ASCII" text read
Any ideas ?stack "Read-Image-Meta-Data": execution error at line 367 (open: unsupported encoding), char 1