Out of curiosity, what data types are dVal and bzero? Are they all integers or is any type conversion going on?
I’ve found that BinaryStream can actually be a slow way of reading data, even if it’s created from a string already in memory. So I would agree with Emile and say use a MemoryBlock in this situation
Thank you Mike for your input. I have gotten to the end of this one as best I can.
I removed the calls to binaryStream.readInt16
I read the file in holus using :-
string = binaryStream.read(fileLength, nil)
memoryBlock = string
memoryBlock.littleEndian = false
This took about 1.04 seconds; running through the memoryBlock to acquire info was 4.4 seconds instead of about 12 seconds (when using binaryStream.readInt16).
Note the target PC is a Panasonic Toughbook Core2 Duo T7700 @ 1.7 GHz, with 4 GB RAM, 120 GB SSD, and Win10 Pro build 19042.1288 … so not highly specified.
My Mac is a 2021 Intel Macbook Pro with a 2.4 GHz Corei9, 64 GB RAM, Radeon Pro 5500M. Much more highly specified.
In terms of speed, if the whole file is a set of greyscale values, might I suggest these changes anyway, regardless of the target…
1/ load the whole thing into a memoryblock
2/ treat the memoryblock as an ‘array’ of Uint16s
3/ precalculate the values of the greys… (I assume there are a maximum of 255, but the principle works for any range)
4/ precalc the offsets inside your loops
something like this:
(this wont work ‘first time’… I just typed it straight to the page as pseudo code)
dim greyvals(255) as color //or whatever, based on dhigh and dlow
dim v as integer
for gv as integer = 0 to 255
v = (gv /(dHigh - dLow)) * brightness
greyvals(gv) = rgb (v,v,v) //may wish to offset by bzero
next
dim x,y as integer
dim precalc as integer
dim ylim , xlim as integer
dim dval as integer
ylim = yMax - 1
xlim = xMax - 1
for y = 0 to ylim
precalc = xlim * y //this may need tweaking
for x = 0 to xlim
dval = memblock.uint16(precalc+x)
//use the ready made color instead of calling rgb every time
rgbs.pixel(x,y) = greyvals(dval)
next x
next y