Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tiff

Package Overview
Dependencies
Maintainers
2
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tiff - npm Package Compare versions

Comparing version 2.1.0 to 3.0.0

History.md

30

package.json
{
"name": "tiff",
"version": "2.1.0",
"version": "3.0.0",
"description": "TIFF image decoder written entirely in JavaScript",
"main": "src/index.js",
"main": "lib/index.js",
"module": "src/index.js",
"files": [
"lib",
"src"

@@ -12,8 +14,9 @@ ],

"eslint-fix": "npm run eslint -- --fix",
"test": "npm run test-mocha && npm run eslint",
"test-mocha": "mocha --require should --reporter mocha-better-spec-reporter --recursive"
"prepare": "rollup -c",
"test": "run-s testonly eslint",
"testonly": "jest"
},
"repository": {
"type": "git",
"url": "git+https://github.com/image-js/tiff-js.git"
"url": "git+https://github.com/image-js/tiff.git"
},

@@ -23,16 +26,17 @@ "author": "Michaël Zasso",

"bugs": {
"url": "https://github.com/image-js/tiff-js/issues"
"url": "https://github.com/image-js/tiff/issues"
},
"homepage": "https://github.com/image-js/tiff-js#readme",
"homepage": "https://github.com/image-js/tiff#readme",
"dependencies": {
"iobuffer": "^2.1.0"
"iobuffer": "^3.2.0"
},
"devDependencies": {
"eslint": "^3.8.1",
"babel-plugin-transform-es2015-modules-commonjs": "^6.24.1",
"eslint": "^4.2.0",
"eslint-config-cheminfo": "^1.5.2",
"eslint-plugin-no-only-tests": "^1.1.0",
"mocha": "^3.0.2",
"mocha-better-spec-reporter": "^3.0.2",
"should": "^11.1.0"
"eslint-plugin-no-only-tests": "^2.0.0",
"jest": "^21.2.1",
"npm-run-all": "^4.0.2",
"rollup": "^0.50.0"
}
}

@@ -1,2 +0,2 @@

# tiff-js
# tiff

@@ -23,5 +23,5 @@ [![NPM version][npm-image]][npm-url]

### TIFF standard
### [TIFF standard](./TIFF6.pdf)
Currently, only greyscale images (8, 16 or 32 bits) can be decoded.
The library can currently decode greyscale and RGB images (8, 16 or 32 bits). It does not support any compression algorithm yet.

@@ -55,2 +55,12 @@ ## API

### tiff.pageCount(data)
Returns the number of IFDs (pages) in the file.
### tiff.isMultiPage(data)
Returns true if the file has 2 or more IFDs (pages) and false if it has 1. This is slightly more
efficient than calling `pageCount()` if all you need to know is whether the file has multiple
pages or not.
## License

@@ -62,5 +72,5 @@

[npm-url]: https://www.npmjs.com/package/tiff
[travis-image]: https://img.shields.io/travis/image-js/tiff-js/master.svg?style=flat-square
[travis-url]: https://travis-ci.org/image-js/tiff-js
[travis-image]: https://img.shields.io/travis/image-js/tiff/master.svg?style=flat-square
[travis-url]: https://travis-ci.org/image-js/tiff
[download-image]: https://img.shields.io/npm/dm/tiff.svg?style=flat-square
[download-url]: https://www.npmjs.com/package/tiff

@@ -1,10 +0,12 @@

'use strict';
import * as standard from './tags/standard';
import * as exif from './tags/exif';
import * as gps from './tags/gps';
const tags = {
standard: require('./tags/standard'),
exif: require('./tags/exif'),
gps: require('./tags/gps')
standard,
exif,
gps
};
class IFD {
export default class IFD {
constructor(kind) {

@@ -43,3 +45,1 @@ if (!kind) {

}
module.exports = IFD;

@@ -1,25 +0,23 @@

'use strict';
var types = new Map([
[1, [1, readByte]], // BYTE
[2, [1, readASCII]], // ASCII
[3, [2, readShort]], // SHORT
[4, [4, readLong]], // LONG
[5, [8, readRational]], // RATIONAL
[6, [1, readSByte]], // SBYTE
[7, [1, readByte]], // UNDEFINED
[8, [2, readSShort]], // SSHORT
[9, [4, readSLong]], // SLONG
[1, [1, readByte]], // BYTE
[2, [1, readASCII]], // ASCII
[3, [2, readShort]], // SHORT
[4, [4, readLong]], // LONG
[5, [8, readRational]], // RATIONAL
[6, [1, readSByte]], // SBYTE
[7, [1, readByte]], // UNDEFINED
[8, [2, readSShort]], // SSHORT
[9, [4, readSLong]], // SLONG
[10, [8, readSRational]], // SRATIONAL
[11, [4, readFloat]], // FLOAT
[12, [8, readDouble]] // DOUBLE
[11, [4, readFloat]], // FLOAT
[12, [8, readDouble]] // DOUBLE
]);
exports.getByteLength = function (type, count) {
export function getByteLength(type, count) {
return types.get(type)[0] * count;
};
}
exports.readData = function (decoder, type, count) {
export function readData(decoder, type, count) {
return types.get(type)[1](decoder, count);
};
}

@@ -26,0 +24,0 @@ function readByte(decoder, count) {

@@ -1,3 +0,22 @@

'use strict';
import TIFFDecoder from './tiffDecoder';
exports.decode = require('./decode');
function decodeTIFF(data, options = {}) {
const decoder = new TIFFDecoder(data, options);
return decoder.decode(options);
}
function isMultiPage(data) {
const decoder = new TIFFDecoder(data);
return decoder.isMultiPage;
}
function pageCount(data) {
const decoder = new TIFFDecoder(data);
return decoder.pageCount;
}
export {
decodeTIFF as decode,
isMultiPage,
pageCount,
};

@@ -1,3 +0,1 @@

'use strict';
const tagsById = {

@@ -80,5 +78,5 @@ 0x829A: 'ExposureTime',

module.exports = {
export {
tagsById,
tagsByName
};

@@ -1,3 +0,1 @@

'use strict';
const tagsById = {

@@ -43,5 +41,5 @@ 0x0000: 'GPSVersionID',

module.exports = {
export {
tagsById,
tagsByName
};

@@ -1,3 +0,1 @@

'use strict';
const tagsById = {

@@ -185,5 +183,5 @@ // Baseline tags

module.exports = {
export {
tagsById,
tagsByName
};

@@ -1,8 +0,6 @@

'use strict';
import IOBuffer from 'iobuffer';
import IFD from './ifd';
import TiffIFD from './tiffIfd';
import {getByteLength, readData} from './ifdValue';
const IOBuffer = require('iobuffer');
const IFD = require('./ifd');
const TiffIFD = require('./tiffIfd');
const IFDValue = require('./ifdValue');
const defaultOptions = {

@@ -13,3 +11,3 @@ ignoreImageData: false,

class TIFFDecoder extends IOBuffer {
export default class TIFFDecoder extends IOBuffer {
constructor(data, options) {

@@ -20,2 +18,31 @@ super(data, options);

get isMultiPage() {
let c = 0;
this.decodeHeader();
while (this._nextIFD) {
c++;
this.decodeIFD({ignoreImageData: true});
if (c === 2) {
return true;
}
}
if (c === 1) {
return false;
}
throw unsupported('ifdCount', c);
}
get pageCount() {
let c = 0;
this.decodeHeader();
while (this._nextIFD) {
c++;
this.decodeIFD({ignoreImageData: true});
}
if (c > 0) {
return c;
}
throw unsupported('ifdCount', c);
}
decode(options) {

@@ -36,3 +63,3 @@ options = Object.assign({}, defaultOptions, options);

// Byte offset
let value = this.readUint16();
const value = this.readUint16();
if (value === 0x4949) {

@@ -47,4 +74,3 @@ this.setLittleEndian();

// Magic number
value = this.readUint16();
if (value !== 42) {
if (this.readUint16() !== 42) {
throw new Error('not a TIFF file');

@@ -89,3 +115,3 @@ }

const valueByteLength = IFDValue.getByteLength(type, numValues);
const valueByteLength = getByteLength(type, numValues);
if (valueByteLength > 4) {

@@ -95,3 +121,3 @@ this.seek(this.readUint32());

const value = IFDValue.readData(this, type, numValues);
const value = readData(this, type, numValues);
ifd.fields.set(tag, value);

@@ -124,3 +150,3 @@

if (orientation && orientation !== 1) {
unsupported('orientation', orientation);
throw unsupported('orientation', orientation);
}

@@ -133,4 +159,3 @@ switch (ifd.type) {

default:
unsupported('image type', ifd.type);
break;
throw unsupported('image type', ifd.type);
}

@@ -145,3 +170,3 @@ }

const sampleFormat = ifd.sampleFormat;
let size = width * height;
const size = width * height;
const data = getDataArray(size, 1, bitDepth, sampleFormat);

@@ -155,16 +180,22 @@

var remainingPixels = size;
var pixel = 0;
for (var i = 0; i < stripOffsets.length; i++) {
var stripData = this.getStripData(compression, stripOffsets[i], stripByteCounts[i]);
var stripData = new DataView(this.buffer, stripOffsets[i], stripByteCounts[i]);
// Last strip can be smaller
var length = size > maxPixels ? maxPixels : size;
size -= length;
if (bitDepth === 8) {
pixel = fill8bit(data, stripData, pixel, length);
} else if (bitDepth === 16) {
pixel = fill16bit(data, stripData, pixel, length, this.isLittleEndian());
} else if (bitDepth === 32 && sampleFormat === 3) {
pixel = fillFloat32(data, stripData, pixel, length, this.isLittleEndian());
} else {
unsupported('bitDepth', bitDepth);
var length = remainingPixels > maxPixels ? maxPixels : remainingPixels;
remainingPixels -= length;
switch (compression) {
case 1: // No compression
pixel = this.fillUncompressed(bitDepth, sampleFormat, data, stripData, pixel, length);
break;
case 5: // LZW
throw unsupported('lzw');
case 2: // CCITT Group 3 1-Dimensional Modified Huffman run length encoding
case 32773: // PackBits compression
throw unsupported('Compression', compression);
default:
throw new Error('invalid compression: ' + compression);
}

@@ -176,11 +207,11 @@ }

getStripData(compression, offset, byteCounts) {
switch (compression) {
case 1: // No compression
return new DataView(this.buffer, offset, byteCounts);
case 2: // CCITT Group 3 1-Dimensional Modified Huffman run length encoding
case 32773: // PackBits compression
return unsupported('Compression', compression);
default:
throw new Error('invalid compression: ' + compression);
fillUncompressed(bitDepth, sampleFormat, data, stripData, pixel, length) {
if (bitDepth === 8) {
return fill8bit(data, stripData, pixel, length);
} else if (bitDepth === 16) {
return fill16bit(data, stripData, pixel, length, this.isLittleEndian());
} else if (bitDepth === 32 && sampleFormat === 3) {
return fillFloat32(data, stripData, pixel, length, this.isLittleEndian());
} else {
throw unsupported('bitDepth', bitDepth);
}

@@ -190,4 +221,2 @@ }

module.exports = TIFFDecoder;
function getDataArray(size, channels, bitDepth, sampleFormat) {

@@ -201,3 +230,3 @@ if (bitDepth === 8) {

} else {
return unsupported('bit depth / sample format', bitDepth + ' / ' + sampleFormat);
throw unsupported('bit depth / sample format', bitDepth + ' / ' + sampleFormat);
}

@@ -228,3 +257,3 @@ }

function unsupported(type, value) {
throw new Error('Unsupported ' + type + ': ' + value);
return new Error('Unsupported ' + type + ': ' + value);
}

@@ -238,3 +267,3 @@

if (bitDepthArray[i] !== bitDepth) {
unsupported('bit depth', bitDepthArray);
throw unsupported('bit depth', bitDepthArray);
}

@@ -241,0 +270,0 @@ }

@@ -1,8 +0,6 @@

'use strict';
import Ifd from './ifd';
const Ifd = require('./ifd');
const dateTimeRegex = /^(\d{4}):(\d{2}):(\d{2}) (\d{2}):(\d{2}):(\d{2})$/;
class TiffIfd extends Ifd {
export default class TiffIfd extends Ifd {
constructor() {

@@ -115,3 +113,1 @@ super('standard');

}
module.exports = TiffIfd;
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc