Skip to content

Commit

Permalink
added support for writing of double tag types
Browse files Browse the repository at this point in the history
doubles: big endian 64-bit floating point values
  • Loading branch information
baadc0de authored Jan 29, 2018
1 parent b1848d8 commit 89afb63
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions UTIF.js
Original file line number Diff line number Diff line change
Expand Up @@ -524,14 +524,15 @@ UTIF._writeIFD = function(bin, data, offset, ifd)
bin.writeUshort(data, offset, type); offset+=2;
bin.writeUint (data, offset, num ); offset+=4;

var dlen = [-1, 1,1,2,4,8][type] * num;
var dlen = [-1, 1, 1, 2, 4, 8, 0, 0, 0, 0, 0, 0, 8][type] * num;
var toff = offset;
if(dlen>4) { bin.writeUint(data, offset, eoff); toff=eoff; }

if(type==2) { bin.writeASCII(data, toff, val); }
if(type==3) { for(var i=0; i<num; i++) bin.writeUshort(data, toff+2*i, val[i]); }
if(type==4) { for(var i=0; i<num; i++) bin.writeUint (data, toff+4*i, val[i]); }
if(type==5) { for(var i=0; i<num; i++) { bin.writeUint(data, toff+8*i, Math.round(val[i]*10000)); bin.writeUint(data, toff+8*i+4, 10000); } }
if (type == 12) { for (var i = 0; i < num; i++) bin.writeDouble(data, toff + 8 * i, val[i]); }

if(dlen>4) { dlen += (dlen&1); eoff += dlen; }
offset += 4;
Expand Down Expand Up @@ -626,6 +627,12 @@ UTIF._binBE = {
writeUshort: function(buff, p, n) { buff[p] = (n>> 8)&255; buff[p+1] = n&255; },
writeUint : function(buff, p, n) { buff[p] = (n>>24)&255; buff[p+1] = (n>>16)&255; buff[p+2] = (n>>8)&255; buff[p+3] = (n>>0)&255; },
writeASCII : function(buff, p, s) { for(var i = 0; i < s.length; i++) buff[p+i] = s.charCodeAt(i); }
writeDouble: function(buff, p, n) {
UTIF._binBE.fl64[0] = n;
for (var i = 0; i < 8; i++) {
buff[p + i] = UTIF._binBE.ui8[7 - i];
}
}
}
UTIF._binBE.ui8 = new Uint8Array (8);
UTIF._binBE.i16 = new Int16Array (UTIF._binBE.ui8.buffer);
Expand Down Expand Up @@ -658,4 +665,4 @@ UTIF._copyTile = function(tb, tw, th, b, w, h, xoff, yoff)
}

})(UTIF, pako);
})();
})();

0 comments on commit 89afb63

Please sign in to comment.