Vanilla PHP and GeoTIFF: How to know byte address and byte length of a "strip" in an
I have a situation where I need to read cell values from a GeoTiff using vanilla PHP, and while I've been successful reading values from an uncompressed TIF (~800MB), I'm having difficulty reading values from the same TIF after LZW compression (~80MB).
I believe my trouble stems from knowing the byte address of a "strip" and the number of bytes belonging to that strip--as my understanding of LZW is that the decompression routine needs an entire strip, which it uses to create a translation table relative to that strip, before individual cell values represented in that strip can be interrogated.
Here's how I'm interpreting the TIFF spec: I can read the bytes for any "strip" by starting at the Strip Offsets tag value (fyi: my RowsPerStrip tag value is 1), and getting the offset for the exact scanline I'm targeting like this:
$stripOffset = $STRIP_OFFSETS + ($rowNum * 4); // i.e. 2 bytes per entry
Then, to get the number of bytes I need to read ahead for my target strip/scanline, I do the same thing against the StripByteCounts tag:
$stripByteCount = $STRIP_BYTE_COUNTS + ($rowNum * 4); // also 2 bytes per entry
With these values in hand, I thought I could then extract the entire strip
// Open the tiff file and point at the strip's byte address..fseek($this->fp, $stripOffset);// Read N bytes from the strip's byte address$stripBytes = fread($this->fp, $stripByteCount);// THESE BYTES SHOULD BE THE WHOLE STRIP, yes?$strip_data = unpack('Vstrip_data', $stripBytes);However, it seems like I'm getting more than one strip's worth of data--as what comes back begins with, and has several reoccurring instances of 128 in it, which should represent the so-called "ClearCode" mentioned in the spec.
..it's important to stress that, what comes back indeed starts with 128, which I am relatively certain is that ClearCode value. So I suspect I'm hitting the start of a strip, I'm just not grabbing a correct number of bytes.
My question is, am I properly evaluating the byte address and number of bytes for a target strip/scanline? And assuming no--what am I doing wrong here??
As mentioned--I've got this working with uncompressed TIFs by benefiting from this question, and this code, courtesy of Bob Osola. Therefore I'm certain my Easting/Northing
أكثر...
I have a situation where I need to read cell values from a GeoTiff using vanilla PHP, and while I've been successful reading values from an uncompressed TIF (~800MB), I'm having difficulty reading values from the same TIF after LZW compression (~80MB).
I believe my trouble stems from knowing the byte address of a "strip" and the number of bytes belonging to that strip--as my understanding of LZW is that the decompression routine needs an entire strip, which it uses to create a translation table relative to that strip, before individual cell values represented in that strip can be interrogated.
Here's how I'm interpreting the TIFF spec: I can read the bytes for any "strip" by starting at the Strip Offsets tag value (fyi: my RowsPerStrip tag value is 1), and getting the offset for the exact scanline I'm targeting like this:
$stripOffset = $STRIP_OFFSETS + ($rowNum * 4); // i.e. 2 bytes per entry
Then, to get the number of bytes I need to read ahead for my target strip/scanline, I do the same thing against the StripByteCounts tag:
$stripByteCount = $STRIP_BYTE_COUNTS + ($rowNum * 4); // also 2 bytes per entry
With these values in hand, I thought I could then extract the entire strip
// Open the tiff file and point at the strip's byte address..fseek($this->fp, $stripOffset);// Read N bytes from the strip's byte address$stripBytes = fread($this->fp, $stripByteCount);// THESE BYTES SHOULD BE THE WHOLE STRIP, yes?$strip_data = unpack('Vstrip_data', $stripBytes);However, it seems like I'm getting more than one strip's worth of data--as what comes back begins with, and has several reoccurring instances of 128 in it, which should represent the so-called "ClearCode" mentioned in the spec.
"The first code written is a ClearCode, which is defined to be code 256."
So my impression is that I'm either not correctly understanding how to evaluate a strip/scanline's byte address and/or byte count ..or ..I don't know!?!
My question is, am I properly evaluating the byte address and number of bytes for a target strip/scanline? And assuming no--what am I doing wrong here??
As mentioned--I've got this working with uncompressed TIFs by benefiting from this question, and this code, courtesy of Bob Osola. Therefore I'm certain my Easting/Northing
أكثر...