I am using a complied Emscripten port of LibTIFF C code called tiff.js by seikichi on github. In my code I need to get some of the TIFF Tags. In tiff.js you can call tiff.getField(tag value). One tag I need specifically is ROWSPERSTRIP with is 278 so to get this tag I call as follows:
var rps = tiff.getField(278); //return rows per strip tiff tag
This seems to work fine for some smaller values 1 to 176 (not exactly sure yet?) but I have several files that AsTiffTagViewer reports as 224 rows per strip and one that file with 746 rows per strip. However tiff.js gets reports both of this values incorrectly as 6 and 1 respectively. I was stepping through the debugger in tiff.js and notice it comes to a place with the following code:
do{if(b>>>0<=65535){d=e[j+24>>1]|0;if((1<<(d&31)&c[a+40+(d>>>5<<2)>>2)]|0)==0){k=0}else{break}i=f;return k|0}}while(0);
It's ugly I suspect because its the best Emscripten can do with C code. Now I know what ">>" and "<<" do but I can't seem to find anything about ">>>". I don't have any idea yet if this is the section of code in tiff.js that is causing tiff.getField(278) to not return some larger rows per strip values incorrectly (all I know right now is it appears smaller rows per strip values are returned correctly where as larger ones are not returned correctly it appears.
So my main question is what is ">>>" and my second question is does anyone have any ideas on why tiff.getField(278) may not be working correctly for larger values. NOTE: most of the other basic TIFF Tags do return correct values such as tiff.getField(PHOTOMETRIC) and tiff.getField(SAMPLESPERPIXLE)...etc.
Thanks in advance for ideas
It's a bitwise zero-fill right shift, from MDN
This operator shifts the first operand the specified number of bits to the right. Excess bits shifted off to the right are discarded. Zero bits are shifted in from the left. The sign bit becomes 0, so the result is always non-negative.
For non-negative numbers, zero-fill right shift and sign-propagating right shift yield the same result. For example, 9 >>> 2 yields 2, the same as 9 >> 2:
As for why tiff.js doesn't work when you call tiff.getField(278), I have no idea, I think it should, and there doesn't seem to be any known issues about this on the Github pages, but you can try adding an issue and see if the developers know.
-3 >>> 0 is an unsigned shift right by 0 bits. I.e. the number is converted to an unsigned 32bit integer as opposed to -3 | 0 which converts the number to a 32bit signed integer.
-3 >>> 0 === 4294967293
-3 | 0 === -3
11.7.3 The Unsigned Right Shift Operator ( >>> )
Performs a zero-filling bitwise right shift operation on the left operand by the amount specified by the right operand.
The production
ShiftExpression : ShiftExpression >>> AdditiveExpressionis evaluated as follows:
Let
lrefbe the result of evaluatingShiftExpression.Let
lvalbeGetValue(lref).Let
rrefbe the result of evaluatingAdditiveExpression.Let
rvalbeGetValue(rref).Let
lnumbeToUint32(lval).Let
rnumbeToUint32(rval).Let
shiftCountbe the result of masking out all but the least significant 5 bits ofrnum, that is, computernum & 0x1F.Return the result of performing a zero-filling right shift of
lnumbyshiftCountbits. Vacated bits are filled with zero. The result is an unsigned 32-bit integer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With