Socket
Socket
Sign inDemoInstall

utif

Package Overview
Dependencies
1
Maintainers
2
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.2.1 to 1.3.0

2

package.json
{
"name": "utif",
"description": "Fast and advanced TIFF decoder",
"version": "1.2.1",
"version": "1.3.0",
"homepage": "https://github.com/photopea/UTIF.js",

@@ -6,0 +6,0 @@ "author": "photopea (https://github.com/photopea)",

@@ -18,13 +18,17 @@ # UTIF.js

* `buffer`: ArrayBuffer containing TIFF or EXIF data
* returns an array of "images" (or "layers", "pages"). Each element of this array is an object with following properties:
* returns an array of "IFDs" (image file directories). Each IFD is an object, keys are "tXYZ" (XYZ is a TIFF tag number), values are values of these tags. You can get the the dimension (and other properties, "metadata") of the image without decompressing pixel data.
#### `UTIF.decodeImages(buffer, ifds)`
* `buffer`: ArrayBuffer containing TIFF or EXIF data
* `ifds`: the output of UTIF.decode()
* loops through each IFD. If there is an image inside it, it is decoded and three new properties are added to the IFD:
* * `width`: the width of the image
* * `height`: the height of the image
* * `data`: decompressed pixel data of the image
* * `tXYZ`: other TIFF tags
TIFF files may have different number of channels and different color depth. The interpretation of `data` depends on many tags (see the [TIFF 6 specification](http://www.npes.org/pdf/TIFF-v6.pdf)).
TIFF files may have various number of channels and various color depth. The interpretation of `data` depends on many tags (see the [TIFF 6 specification](http://www.npes.org/pdf/TIFF-v6.pdf)). The following function converts any TIFF image into a 8-bit RGBA image.
#### `UTIF.toRGBA8(img)`
* `img`: TIFF image object (returned by UTIF.decode())
* returns Uint8Array of the image in RGBA format, 8 bits per channel (ready to use in ctx.putImageData() etc.)
#### `UTIF.toRGBA8(ifd)`
* `ifd`: image file directory (element of "ifds" returned by UTIF.decode(), processed by UTIF.decodeImages())
* returns Uint8Array of the image in RGBA format, 8 bits per channel (ready to use in context2d.putImageData() etc.)

@@ -35,5 +39,6 @@ ### Example

function imgLoaded(e) {
var pages = UTIF.decode(e.target.response);
var rgba = UTIF.toRGBA8(pages[0]); // Uint8Array with RGBA pixels
console.log(pages[0].width, pages[0].height, pages[0]);
var ifds = UTIF.decode(e.target.response);
UTIF.decodeImages(e.target.response, ifds)
var rgba = UTIF.toRGBA8(ifds[0]); // Uint8Array with RGBA pixels
console.log(ifds[0].width, ifds[0].height, ifds[0]);
}

@@ -40,0 +45,0 @@

@@ -71,5 +71,11 @@

}
return ifds;
}
if(ifds[0]["t256"]==null) return ifds; // EXIF files don't have TIFF tags
UTIF.decodeImages = function(buff, ifds)
{
var data = new Uint8Array(buff);
var id = UTIF._binBE.readASCII(data, 0, 2);
for(var ii=0; ii<ifds.length; ii++)

@@ -119,3 +125,2 @@ {

}
return ifds;
}

@@ -524,3 +529,3 @@

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;

@@ -533,2 +538,3 @@ if(dlen>4) { bin.writeUint(data, offset, eoff); toff=eoff; }

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]); }

@@ -601,3 +607,5 @@ if(dlen>4) { dlen += (dlen&1); eoff += dlen; }

{
var page = UTIF.decode(e.target.response)[0], rgba = UTIF.toRGBA8(page), w=page.width, h=page.height;
var buff = e.target.response;
var ifds = UTIF.decode(buff), page = ifds[0]; UTIF.decodeImages(buff, ifds);
var rgba = UTIF.toRGBA8(page), w=page.width, h=page.height;
var ind = UTIF._xhrs.indexOf(e.target), img = UTIF._imgs[ind];

@@ -626,3 +634,9 @@ UTIF._xhrs.splice(ind,1); UTIF._imgs.splice(ind,1);

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); }
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];
}
}
}

@@ -660,2 +674,2 @@ UTIF._binBE.ui8 = new Uint8Array (8);

})(UTIF, pako);
})();
})();
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc