Comparing version 4.0.0 to 4.1.0
@@ -0,1 +1,10 @@ | ||
# [4.1.0](https://github.com/image-js/tiff/compare/v4.0.0...v4.1.0) (2020-08-04) | ||
### Features | ||
* support LZW compression ([20fbb50](https://github.com/image-js/tiff/commit/20fbb501b8855489e91ae22f519760c2112aae68)) | ||
# [4.0.0](https://github.com/image-js/tiff/compare/v3.0.1...v4.0.0) (2020-01-23) | ||
@@ -2,0 +11,0 @@ |
@@ -1,4 +0,4 @@ | ||
import * as standard from './tags/standard'; | ||
import * as exif from './tags/exif'; | ||
import * as gps from './tags/gps'; | ||
import * as standard from './tags/standard'; | ||
const tags = { | ||
@@ -5,0 +5,0 @@ standard, |
import { IOBuffer } from 'iobuffer'; | ||
import { applyHorizontalDifferencing, applyHorizontalDifferencingColor, } from './horizontalDifferencing'; | ||
import IFD from './ifd'; | ||
import { getByteLength, readData } from './ifdValue'; | ||
import { decompressLzw } from './lzw'; | ||
import TiffIfd from './tiffIfd'; | ||
@@ -148,2 +150,3 @@ const defaultOptions = { | ||
} | ||
this.applyPredictor(ifd); | ||
if (ifd.type === 0) { | ||
@@ -165,3 +168,2 @@ // WhiteIsZero: we invert the values | ||
const data = getDataArray(size, 1, bitDepth, sampleFormat); | ||
const compression = ifd.compression; | ||
const rowsPerStrip = ifd.rowsPerStrip; | ||
@@ -178,14 +180,21 @@ const maxPixels = rowsPerStrip * width; | ||
remainingPixels -= length; | ||
switch (compression) { | ||
case 1: // No compression | ||
pixel = this.fillUncompressed(bitDepth, sampleFormat, data, stripData, pixel, length); | ||
let dataToFill = stripData; | ||
switch (ifd.compression) { | ||
case 1: { | ||
// No compression, nothing to do | ||
break; | ||
case 5: // LZW | ||
throw unsupported('Compression', 'LZW'); | ||
} | ||
case 5: { | ||
// LZW compression | ||
dataToFill = decompressLzw(stripData); | ||
break; | ||
} | ||
case 2: // CCITT Group 3 1-Dimensional Modified Huffman run length encoding | ||
throw unsupported('Compression', 'CCITT Group 3'); | ||
case 32773: // PackBits compression | ||
throw unsupported('Compression', compression); | ||
throw unsupported('Compression', 'PackBits'); | ||
default: | ||
throw new Error(`invalid compression: ${compression}`); | ||
throw new Error(`invalid compression: ${ifd.compression}`); | ||
} | ||
pixel = this.fillUncompressed(bitDepth, sampleFormat, data, dataToFill, pixel, length); | ||
} | ||
@@ -208,2 +217,30 @@ ifd.data = data; | ||
} | ||
applyPredictor(ifd) { | ||
const bitDepth = validateBitDepth(ifd.bitsPerSample); | ||
switch (ifd.predictor) { | ||
case 1: { | ||
// No prediction scheme, nothing to do | ||
break; | ||
} | ||
case 2: { | ||
if (bitDepth === 8) { | ||
if (ifd.samplesPerPixel === 1) { | ||
applyHorizontalDifferencing(ifd.data, ifd.width); | ||
} | ||
else if (ifd.samplesPerPixel === 3) { | ||
applyHorizontalDifferencingColor(ifd.data, ifd.width); | ||
} | ||
else { | ||
throw new Error('Horizontal differencing is only supported for images with 1 or 3 samples per pixel'); | ||
} | ||
} | ||
else { | ||
throw new Error('Horizontal differencing is only supported for 8-bit images'); | ||
} | ||
break; | ||
} | ||
default: | ||
throw new Error(`invalid predictor: ${ifd.predictor}`); | ||
} | ||
} | ||
} | ||
@@ -210,0 +247,0 @@ function getDataArray(size, channels, bitDepth, sampleFormat) { |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | ||
result["default"] = mod; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const standard = __importStar(require("./tags/standard")); | ||
const exif = __importStar(require("./tags/exif")); | ||
const gps = __importStar(require("./tags/gps")); | ||
const standard = __importStar(require("./tags/standard")); | ||
const tags = { | ||
@@ -14,0 +26,0 @@ standard, |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.readData = exports.getByteLength = void 0; | ||
let types = new Map([ | ||
@@ -4,0 +5,0 @@ [1, [1, readByte]], |
@@ -0,3 +1,3 @@ | ||
import TiffIfd from './tiffIfd'; | ||
import { BufferType, IDecodeOptions } from './types'; | ||
import TiffIfd from './tiffIfd'; | ||
declare function decodeTIFF(data: BufferType, options?: IDecodeOptions): TiffIfd[]; | ||
@@ -4,0 +4,0 @@ declare function isMultiPage(data: BufferType): boolean; |
@@ -6,2 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.pageCount = exports.isMultiPage = exports.decode = void 0; | ||
const tiffDecoder_1 = __importDefault(require("./tiffDecoder")); | ||
@@ -8,0 +9,0 @@ function decodeTIFF(data, options) { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.tagsByName = exports.tagsById = void 0; | ||
const tagsById = { | ||
@@ -4,0 +5,0 @@ 0x829a: 'ExposureTime', |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.tagsByName = exports.tagsById = void 0; | ||
const tagsById = { | ||
@@ -4,0 +5,0 @@ 0x0000: 'GPSVersionID', |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.tagsByName = exports.tagsById = void 0; | ||
const tagsById = { | ||
@@ -4,0 +5,0 @@ // Baseline tags |
import { IOBuffer } from 'iobuffer'; | ||
import TiffIfd from './tiffIfd'; | ||
import { BufferType, IDecodeOptions } from './types'; | ||
import TiffIfd from './tiffIfd'; | ||
export default class TIFFDecoder extends IOBuffer { | ||
@@ -16,2 +16,3 @@ private _nextIFD; | ||
private fillUncompressed; | ||
private applyPredictor; | ||
} |
@@ -7,4 +7,6 @@ "use strict"; | ||
const iobuffer_1 = require("iobuffer"); | ||
const horizontalDifferencing_1 = require("./horizontalDifferencing"); | ||
const ifd_1 = __importDefault(require("./ifd")); | ||
const ifdValue_1 = require("./ifdValue"); | ||
const lzw_1 = require("./lzw"); | ||
const tiffIfd_1 = __importDefault(require("./tiffIfd")); | ||
@@ -154,2 +156,3 @@ const defaultOptions = { | ||
} | ||
this.applyPredictor(ifd); | ||
if (ifd.type === 0) { | ||
@@ -171,3 +174,2 @@ // WhiteIsZero: we invert the values | ||
const data = getDataArray(size, 1, bitDepth, sampleFormat); | ||
const compression = ifd.compression; | ||
const rowsPerStrip = ifd.rowsPerStrip; | ||
@@ -184,14 +186,21 @@ const maxPixels = rowsPerStrip * width; | ||
remainingPixels -= length; | ||
switch (compression) { | ||
case 1: // No compression | ||
pixel = this.fillUncompressed(bitDepth, sampleFormat, data, stripData, pixel, length); | ||
let dataToFill = stripData; | ||
switch (ifd.compression) { | ||
case 1: { | ||
// No compression, nothing to do | ||
break; | ||
case 5: // LZW | ||
throw unsupported('Compression', 'LZW'); | ||
} | ||
case 5: { | ||
// LZW compression | ||
dataToFill = lzw_1.decompressLzw(stripData); | ||
break; | ||
} | ||
case 2: // CCITT Group 3 1-Dimensional Modified Huffman run length encoding | ||
throw unsupported('Compression', 'CCITT Group 3'); | ||
case 32773: // PackBits compression | ||
throw unsupported('Compression', compression); | ||
throw unsupported('Compression', 'PackBits'); | ||
default: | ||
throw new Error(`invalid compression: ${compression}`); | ||
throw new Error(`invalid compression: ${ifd.compression}`); | ||
} | ||
pixel = this.fillUncompressed(bitDepth, sampleFormat, data, dataToFill, pixel, length); | ||
} | ||
@@ -214,2 +223,30 @@ ifd.data = data; | ||
} | ||
applyPredictor(ifd) { | ||
const bitDepth = validateBitDepth(ifd.bitsPerSample); | ||
switch (ifd.predictor) { | ||
case 1: { | ||
// No prediction scheme, nothing to do | ||
break; | ||
} | ||
case 2: { | ||
if (bitDepth === 8) { | ||
if (ifd.samplesPerPixel === 1) { | ||
horizontalDifferencing_1.applyHorizontalDifferencing(ifd.data, ifd.width); | ||
} | ||
else if (ifd.samplesPerPixel === 3) { | ||
horizontalDifferencing_1.applyHorizontalDifferencingColor(ifd.data, ifd.width); | ||
} | ||
else { | ||
throw new Error('Horizontal differencing is only supported for images with 1 or 3 samples per pixel'); | ||
} | ||
} | ||
else { | ||
throw new Error('Horizontal differencing is only supported for 8-bit images'); | ||
} | ||
break; | ||
} | ||
default: | ||
throw new Error(`invalid predictor: ${ifd.predictor}`); | ||
} | ||
} | ||
} | ||
@@ -216,0 +253,0 @@ exports.default = TIFFDecoder; |
{ | ||
"name": "tiff", | ||
"version": "4.0.0", | ||
"version": "4.1.0", | ||
"description": "TIFF image decoder written entirely in JavaScript", | ||
@@ -43,17 +43,11 @@ "main": "lib/index.js", | ||
"devDependencies": { | ||
"@types/jest": "^24.9.0", | ||
"@types/node": "^13.1.8", | ||
"@typescript-eslint/eslint-plugin": "^2.17.0", | ||
"@typescript-eslint/parser": "^2.17.0", | ||
"eslint": "^6.8.0", | ||
"eslint-config-cheminfo": "^2.0.4", | ||
"eslint-config-cheminfo-typescript": "^4.1.2", | ||
"eslint-plugin-import": "^2.20.0", | ||
"eslint-plugin-jest": "^23.6.0", | ||
"eslint-plugin-prettier": "^3.1.2", | ||
"jest": "^25.1.0", | ||
"prettier": "^1.19.1", | ||
"rimraf": "^3.0.0", | ||
"ts-jest": "^25.0.0", | ||
"typescript": "^3.7.5" | ||
"@types/jest": "^26.0.8", | ||
"@types/node": "^14.0.27", | ||
"eslint": "^7.6.0", | ||
"eslint-config-cheminfo-typescript": "^7.0.0", | ||
"jest": "^26.2.2", | ||
"prettier": "^2.0.5", | ||
"rimraf": "^3.0.2", | ||
"ts-jest": "^26.1.4", | ||
"typescript": "^3.9.7" | ||
}, | ||
@@ -60,0 +54,0 @@ "prettier": { |
# tiff | ||
[![NPM version][npm-image]][npm-url] | ||
[![build status][travis-image]][travis-url] | ||
[![build status][ci-image]][ci-url] | ||
[![npm download][download-image]][download-url] | ||
@@ -12,3 +12,3 @@ | ||
```console | ||
npm install tiff | ||
npm i tiff | ||
``` | ||
@@ -69,7 +69,9 @@ | ||
[npm-image]: https://img.shields.io/npm/v/tiff.svg?style=flat-square | ||
[npm-image]: https://img.shields.io/npm/v/tiff.svg | ||
[npm-url]: https://www.npmjs.com/package/tiff | ||
[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 | ||
[ci-image]: https://github.com/image-js/tiff/workflows/Node.js%20CI/badge.svg?branch=master | ||
[ci-url]: https://github.com/image-js/tiff/actions?query=workflow%3A%22Node.js+CI%22 | ||
[codecov-image]: https://img.shields.io/codecov/c/github/image-js/tiff.svg | ||
[codecov-url]: https://codecov.io/gh/image-js/tiff | ||
[download-image]: https://img.shields.io/npm/dm/tiff.svg | ||
[download-url]: https://www.npmjs.com/package/tiff |
@@ -1,4 +0,4 @@ | ||
import * as standard from './tags/standard'; | ||
import * as exif from './tags/exif'; | ||
import * as gps from './tags/gps'; | ||
import * as standard from './tags/standard'; | ||
import { IFDKind, DataArray } from './types'; | ||
@@ -5,0 +5,0 @@ |
import TIFFDecoder from './tiffDecoder'; | ||
import TiffIfd from './tiffIfd'; | ||
import { BufferType, IDecodeOptions } from './types'; | ||
import TiffIfd from './tiffIfd'; | ||
@@ -5,0 +5,0 @@ function decodeTIFF(data: BufferType, options?: IDecodeOptions): TiffIfd[] { |
import { IOBuffer } from 'iobuffer'; | ||
import { | ||
applyHorizontalDifferencing, | ||
applyHorizontalDifferencingColor, | ||
} from './horizontalDifferencing'; | ||
import IFD from './ifd'; | ||
import { getByteLength, readData } from './ifdValue'; | ||
import { decompressLzw } from './lzw'; | ||
import TiffIfd from './tiffIfd'; | ||
import { BufferType, IDecodeOptions, IFDKind, DataArray } from './types'; | ||
import TiffIfd from './tiffIfd'; | ||
@@ -175,2 +180,3 @@ const defaultOptions: IDecodeOptions = { | ||
} | ||
this.applyPredictor(ifd); | ||
if (ifd.type === 0) { | ||
@@ -195,3 +201,2 @@ // WhiteIsZero: we invert the values | ||
const compression = ifd.compression; | ||
const rowsPerStrip = ifd.rowsPerStrip; | ||
@@ -215,21 +220,30 @@ const maxPixels = rowsPerStrip * width; | ||
switch (compression) { | ||
case 1: // No compression | ||
pixel = this.fillUncompressed( | ||
bitDepth, | ||
sampleFormat, | ||
data, | ||
stripData, | ||
pixel, | ||
length, | ||
); | ||
let dataToFill = stripData; | ||
switch (ifd.compression) { | ||
case 1: { | ||
// No compression, nothing to do | ||
break; | ||
case 5: // LZW | ||
throw unsupported('Compression', 'LZW'); | ||
} | ||
case 5: { | ||
// LZW compression | ||
dataToFill = decompressLzw(stripData); | ||
break; | ||
} | ||
case 2: // CCITT Group 3 1-Dimensional Modified Huffman run length encoding | ||
throw unsupported('Compression', 'CCITT Group 3'); | ||
case 32773: // PackBits compression | ||
throw unsupported('Compression', compression); | ||
throw unsupported('Compression', 'PackBits'); | ||
default: | ||
throw new Error(`invalid compression: ${compression}`); | ||
throw new Error(`invalid compression: ${ifd.compression}`); | ||
} | ||
pixel = this.fillUncompressed( | ||
bitDepth, | ||
sampleFormat, | ||
data, | ||
dataToFill, | ||
pixel, | ||
length, | ||
); | ||
} | ||
@@ -258,2 +272,32 @@ | ||
} | ||
private applyPredictor(ifd: TiffIfd): void { | ||
const bitDepth = validateBitDepth(ifd.bitsPerSample); | ||
switch (ifd.predictor) { | ||
case 1: { | ||
// No prediction scheme, nothing to do | ||
break; | ||
} | ||
case 2: { | ||
if (bitDepth === 8) { | ||
if (ifd.samplesPerPixel === 1) { | ||
applyHorizontalDifferencing(ifd.data as Uint8Array, ifd.width); | ||
} else if (ifd.samplesPerPixel === 3) { | ||
applyHorizontalDifferencingColor(ifd.data as Uint8Array, ifd.width); | ||
} else { | ||
throw new Error( | ||
'Horizontal differencing is only supported for images with 1 or 3 samples per pixel', | ||
); | ||
} | ||
} else { | ||
throw new Error( | ||
'Horizontal differencing is only supported for 8-bit images', | ||
); | ||
} | ||
break; | ||
} | ||
default: | ||
throw new Error(`invalid predictor: ${ifd.predictor}`); | ||
} | ||
} | ||
} | ||
@@ -260,0 +304,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
176603
9
70
3349
76
0