Hi, all
I've been writing a program that draws an image (based on file input), then outputs the image as a tiff file.
During debugging, I just wrote out the image one pixel at a time: for h := 1 to ht do for w := 1 to wid do write(Iout, Image^[w,h]);
It works fine, but of course it's slow. So once the rest of the program was working, I decided to speed it up. Now I allocate memory for one line of the image, dump the image one line at a time into it, and blockwrite that line:
type PBufary = ^Bufary; Bufary(mX : shortCard) = array[0..mX] of byteCard; [...]
var Buffy : PBufary; [...] New(Buffy,wid-1); Extend(Iout,OutFileName,wid); for h := 1 to ht do begin for w := 1 to wid do Buffy^[w-1] := Image^[w,h]; BlockWrite(Iout,Buffy^,1); end; Close(Iout); Dispose(Buffy);
It's way faster, as I expected. (The Extend is because I write the fileheader to a file of shortCard, close it, then re-open it with Extend so I can use the BlockWrite.)
BUT the image has a 2-pixel-wide black line down the left side. To get rid of it, I had to do:
for h := 1 to ht do begin for w := 1 to wid do Buffy^[w-3] := Image^[w,h]; { <== *** -3!?!?} BlockWrite(Iout,Buffy^,1); end;
This makes no sense, but it works. What's with this 2 byte offset? And why isn't the program complaining?
thanks, Toby