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

tiff

Package Overview
Dependencies
Maintainers
3
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 4.1.3 to 4.2.0

9

History.md

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

# [4.2.0](https://github.com/image-js/tiff/compare/v4.1.3...v4.2.0) (2020-08-21)
### Features
* add support for alpha channel and compressed 16-bit images ([5f2e612](https://github.com/image-js/tiff/commit/5f2e6128ed7b096290c1ebe0b861a61d3849b255))
## [4.1.3](https://github.com/image-js/tiff/compare/v4.1.2...v4.1.3) (2020-08-07)

@@ -2,0 +11,0 @@

24

lib-esm/horizontalDifferencing.js
// Section 14: Differencing Predictor (p. 64)
export function applyHorizontalDifferencing(data, width) {
export function applyHorizontalDifferencing8Bit(data, width, components) {
let i = 0;
while (i < data.length) {
for (let j = 1; j < width; j++) {
data[i + j] = (data[i + j] + data[i + j - 1]) & 255;
for (let j = components; j < width * components; j += components) {
for (let k = 0; k < components; k++) {
data[i + j + k] =
(data[i + j + k] + data[i + j - (components - k)]) & 255;
}
}
i += width;
i += width * components;
}
}
export function applyHorizontalDifferencingColor(data, width) {
export function applyHorizontalDifferencing16Bit(data, width, components) {
let i = 0;
while (i < data.length) {
for (let j = 3; j < width * 3; j += 3) {
data[i + j] = (data[i + j] + data[i + j - 3]) & 255;
data[i + j + 1] = (data[i + j + 1] + data[i + j - 2]) & 255;
data[i + j + 2] = (data[i + j + 2] + data[i + j - 1]) & 255;
for (let j = components; j < width * components; j += components) {
for (let k = 0; k < components; k++) {
data[i + j + k] =
(data[i + j + k] + data[i + j - (components - k)]) & 65535;
}
}
i += width * 3;
i += width * components;
}
}
//# sourceMappingURL=horizontalDifferencing.js.map
import { IOBuffer } from 'iobuffer';
import { applyHorizontalDifferencing, applyHorizontalDifferencingColor, } from './horizontalDifferencing';
import { applyHorizontalDifferencing8Bit, applyHorizontalDifferencing16Bit, } from './horizontalDifferencing';
import IFD from './ifd';

@@ -151,2 +151,3 @@ import { getByteLength, readData } from './ifdValue';

this.applyPredictor(ifd);
this.convertAlpha(ifd);
if (ifd.type === 0) {

@@ -224,14 +225,9 @@ // WhiteIsZero: we invert the values

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');
}
applyHorizontalDifferencing8Bit(ifd.data, ifd.width, ifd.components);
}
else if (bitDepth === 16) {
applyHorizontalDifferencing16Bit(ifd.data, ifd.width, ifd.components);
}
else {
throw new Error('Horizontal differencing is only supported for 8-bit images');
throw new Error(`Horizontal differencing is only supported for images with a bit depth of ${bitDepth}`);
}

@@ -244,2 +240,13 @@ break;

}
convertAlpha(ifd) {
if (ifd.alpha && ifd.associatedAlpha) {
const { data, components, maxSampleValue } = ifd;
for (let i = 0; i < data.length; i += components) {
const alphaValue = data[i + components - 1];
for (let j = 0; j < components - 1; j++) {
data[i + j] = Math.round((data[i + j] * maxSampleValue) / alphaValue);
}
}
}
}
}

@@ -246,0 +253,0 @@ function getDataArray(size, bitDepth, sampleFormat) {

@@ -33,12 +33,12 @@ import Ifd from './ifd';

get newSubfileType() {
return this.get(254);
return this.get('NewSubfileType');
}
get imageWidth() {
return this.get(256);
return this.get('ImageWidth');
}
get imageLength() {
return this.get(257);
return this.get('ImageLength');
}
get bitsPerSample() {
const data = this.get(258);
const data = this.get('BitsPerSample');
if (data && typeof data !== 'number') {

@@ -49,68 +49,83 @@ return data[0];

}
get alpha() {
const extraSamples = this.extraSamples;
if (!extraSamples)
return false;
return extraSamples[0] !== 0;
}
get associatedAlpha() {
const extraSamples = this.extraSamples;
if (!extraSamples)
return false;
return extraSamples[0] === 1;
}
get extraSamples() {
return alwaysArray(this.get('ExtraSamples'));
}
get compression() {
return this.get(259) || 1;
return this.get('Compression') || 1;
}
get type() {
return this.get(262);
return this.get('PhotometricInterpretation');
}
get fillOrder() {
return this.get(266) || 1;
return this.get('FillOrder') || 1;
}
get documentName() {
return this.get(269);
return this.get('DocumentName');
}
get imageDescription() {
return this.get(270);
return this.get('ImageDescription');
}
get stripOffsets() {
return alwaysArray(this.get(273));
return alwaysArray(this.get('StripOffsets'));
}
get orientation() {
return this.get(274);
return this.get('Orientation');
}
get samplesPerPixel() {
return this.get(277) || 1;
return this.get('SamplesPerPixel') || 1;
}
get rowsPerStrip() {
return this.get(278);
return this.get('RowsPerStrip');
}
get stripByteCounts() {
return alwaysArray(this.get(279));
return alwaysArray(this.get('StripByteCounts'));
}
get minSampleValue() {
return this.get(280) || 0;
return this.get('MinSampleValue') || 0;
}
get maxSampleValue() {
return this.get(281) || Math.pow(2, this.bitsPerSample) - 1;
return this.get('MaxSampleValue') || Math.pow(2, this.bitsPerSample) - 1;
}
get xResolution() {
return this.get(282);
return this.get('XResolution');
}
get yResolution() {
return this.get(283);
return this.get('YResolution');
}
get planarConfiguration() {
return this.get(284) || 1;
return this.get('PlanarConfiguration') || 1;
}
get resolutionUnit() {
return this.get(296) || 2;
return this.get('ResolutionUnit') || 2;
}
get dateTime() {
return this.get(306);
return this.get('DateTime');
}
get predictor() {
return this.get(317) || 1;
return this.get('Predictor') || 1;
}
get sampleFormat() {
return this.get(339) || 1;
return this.get('SampleFormat') || 1;
}
get sMinSampleValue() {
return this.get(340) || this.minSampleValue;
return this.get('SMinSampleValue') || this.minSampleValue;
}
get sMaxSampleValue() {
return this.get(341) || this.maxSampleValue;
return this.get('SMaxSampleValue') || this.maxSampleValue;
}
get palette() {
const totalColors = 2 ** this.bitsPerSample;
const colorMap = this.get(320);
const colorMap = this.get('ColorMap');
if (!colorMap)

@@ -117,0 +132,0 @@ return undefined;

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

export {};
//# sourceMappingURL=types.js.map

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

export declare function applyHorizontalDifferencing(data: Uint8Array, width: number): void;
export declare function applyHorizontalDifferencingColor(data: Uint8Array, width: number): void;
export declare function applyHorizontalDifferencing8Bit(data: Uint8Array, width: number, components: number): void;
export declare function applyHorizontalDifferencing16Bit(data: Uint16Array, width: number, components: number): void;
"use strict";
// Section 14: Differencing Predictor (p. 64)
Object.defineProperty(exports, "__esModule", { value: true });
exports.applyHorizontalDifferencingColor = exports.applyHorizontalDifferencing = void 0;
function applyHorizontalDifferencing(data, width) {
exports.applyHorizontalDifferencing16Bit = exports.applyHorizontalDifferencing8Bit = void 0;
function applyHorizontalDifferencing8Bit(data, width, components) {
let i = 0;
while (i < data.length) {
for (let j = 1; j < width; j++) {
data[i + j] = (data[i + j] + data[i + j - 1]) & 255;
for (let j = components; j < width * components; j += components) {
for (let k = 0; k < components; k++) {
data[i + j + k] =
(data[i + j + k] + data[i + j - (components - k)]) & 255;
}
}
i += width;
i += width * components;
}
}
exports.applyHorizontalDifferencing = applyHorizontalDifferencing;
function applyHorizontalDifferencingColor(data, width) {
exports.applyHorizontalDifferencing8Bit = applyHorizontalDifferencing8Bit;
function applyHorizontalDifferencing16Bit(data, width, components) {
let i = 0;
while (i < data.length) {
for (let j = 3; j < width * 3; j += 3) {
data[i + j] = (data[i + j] + data[i + j - 3]) & 255;
data[i + j + 1] = (data[i + j + 1] + data[i + j - 2]) & 255;
data[i + j + 2] = (data[i + j + 2] + data[i + j - 1]) & 255;
for (let j = components; j < width * components; j += components) {
for (let k = 0; k < components; k++) {
data[i + j + k] =
(data[i + j + k] + data[i + j - (components - k)]) & 65535;
}
}
i += width * 3;
i += width * components;
}
}
exports.applyHorizontalDifferencingColor = applyHorizontalDifferencingColor;
exports.applyHorizontalDifferencing16Bit = applyHorizontalDifferencing16Bit;
//# sourceMappingURL=horizontalDifferencing.js.map

@@ -17,3 +17,3 @@ "use strict";

var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);

@@ -20,0 +20,0 @@ return result;

@@ -17,2 +17,3 @@ import { IOBuffer } from 'iobuffer';

private applyPredictor;
private convertAlpha;
}

@@ -156,2 +156,3 @@ "use strict";

this.applyPredictor(ifd);
this.convertAlpha(ifd);
if (ifd.type === 0) {

@@ -229,14 +230,9 @@ // WhiteIsZero: we invert the values

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');
}
horizontalDifferencing_1.applyHorizontalDifferencing8Bit(ifd.data, ifd.width, ifd.components);
}
else if (bitDepth === 16) {
horizontalDifferencing_1.applyHorizontalDifferencing16Bit(ifd.data, ifd.width, ifd.components);
}
else {
throw new Error('Horizontal differencing is only supported for 8-bit images');
throw new Error(`Horizontal differencing is only supported for images with a bit depth of ${bitDepth}`);
}

@@ -249,2 +245,13 @@ break;

}
convertAlpha(ifd) {
if (ifd.alpha && ifd.associatedAlpha) {
const { data, components, maxSampleValue } = ifd;
for (let i = 0; i < data.length; i += components) {
const alphaValue = data[i + components - 1];
for (let j = 0; j < components - 1; j++) {
data[i + j] = Math.round((data[i + j] * maxSampleValue) / alphaValue);
}
}
}
}
}

@@ -251,0 +258,0 @@ exports.default = TIFFDecoder;

@@ -13,2 +13,5 @@ import Ifd from './ifd';

get bitsPerSample(): number;
get alpha(): boolean;
get associatedAlpha(): boolean;
get extraSamples(): number[] | undefined;
get compression(): number;

@@ -15,0 +18,0 @@ get type(): number;

@@ -38,12 +38,12 @@ "use strict";

get newSubfileType() {
return this.get(254);
return this.get('NewSubfileType');
}
get imageWidth() {
return this.get(256);
return this.get('ImageWidth');
}
get imageLength() {
return this.get(257);
return this.get('ImageLength');
}
get bitsPerSample() {
const data = this.get(258);
const data = this.get('BitsPerSample');
if (data && typeof data !== 'number') {

@@ -54,68 +54,83 @@ return data[0];

}
get alpha() {
const extraSamples = this.extraSamples;
if (!extraSamples)
return false;
return extraSamples[0] !== 0;
}
get associatedAlpha() {
const extraSamples = this.extraSamples;
if (!extraSamples)
return false;
return extraSamples[0] === 1;
}
get extraSamples() {
return alwaysArray(this.get('ExtraSamples'));
}
get compression() {
return this.get(259) || 1;
return this.get('Compression') || 1;
}
get type() {
return this.get(262);
return this.get('PhotometricInterpretation');
}
get fillOrder() {
return this.get(266) || 1;
return this.get('FillOrder') || 1;
}
get documentName() {
return this.get(269);
return this.get('DocumentName');
}
get imageDescription() {
return this.get(270);
return this.get('ImageDescription');
}
get stripOffsets() {
return alwaysArray(this.get(273));
return alwaysArray(this.get('StripOffsets'));
}
get orientation() {
return this.get(274);
return this.get('Orientation');
}
get samplesPerPixel() {
return this.get(277) || 1;
return this.get('SamplesPerPixel') || 1;
}
get rowsPerStrip() {
return this.get(278);
return this.get('RowsPerStrip');
}
get stripByteCounts() {
return alwaysArray(this.get(279));
return alwaysArray(this.get('StripByteCounts'));
}
get minSampleValue() {
return this.get(280) || 0;
return this.get('MinSampleValue') || 0;
}
get maxSampleValue() {
return this.get(281) || Math.pow(2, this.bitsPerSample) - 1;
return this.get('MaxSampleValue') || Math.pow(2, this.bitsPerSample) - 1;
}
get xResolution() {
return this.get(282);
return this.get('XResolution');
}
get yResolution() {
return this.get(283);
return this.get('YResolution');
}
get planarConfiguration() {
return this.get(284) || 1;
return this.get('PlanarConfiguration') || 1;
}
get resolutionUnit() {
return this.get(296) || 2;
return this.get('ResolutionUnit') || 2;
}
get dateTime() {
return this.get(306);
return this.get('DateTime');
}
get predictor() {
return this.get(317) || 1;
return this.get('Predictor') || 1;
}
get sampleFormat() {
return this.get(339) || 1;
return this.get('SampleFormat') || 1;
}
get sMinSampleValue() {
return this.get(340) || this.minSampleValue;
return this.get('SMinSampleValue') || this.minSampleValue;
}
get sMaxSampleValue() {
return this.get(341) || this.maxSampleValue;
return this.get('SMaxSampleValue') || this.maxSampleValue;
}
get palette() {
const totalColors = 2 ** this.bitsPerSample;
const colorMap = this.get(320);
const colorMap = this.get('ColorMap');
if (!colorMap)

@@ -122,0 +137,0 @@ return undefined;

{
"name": "tiff",
"version": "4.1.3",
"version": "4.2.0",
"description": "TIFF image decoder written entirely in JavaScript",

@@ -43,11 +43,11 @@ "main": "lib/index.js",

"devDependencies": {
"@types/jest": "^26.0.8",
"@types/node": "^14.0.27",
"eslint": "^7.6.0",
"@types/jest": "^26.0.10",
"@types/node": "^14.6.0",
"eslint": "^7.7.0",
"eslint-config-cheminfo-typescript": "^7.0.0",
"jest": "^26.2.2",
"jest": "^26.4.1",
"prettier": "^2.0.5",
"rimraf": "^3.0.2",
"ts-jest": "^26.1.4",
"typescript": "^3.9.7"
"ts-jest": "^26.2.0",
"typescript": "^4.0.2"
},

@@ -54,0 +54,0 @@ "prettier": {

@@ -26,3 +26,3 @@ # tiff

The library can currently decode greyscale and RGB images (8, 16 or 32 bits).
It does not support any compression algorithm yet.
It supports LZW compression and images with an additional alpha channel.

@@ -51,2 +51,3 @@ ## API

- `bitsPerSample` - bit depth
- `alpha` - `true` if the image has an additional alpha channel
- `xResolution`

@@ -53,0 +54,0 @@ - `yResolution`

// Section 14: Differencing Predictor (p. 64)
export function applyHorizontalDifferencing(
export function applyHorizontalDifferencing8Bit(
data: Uint8Array,
width: number,
components: number,
): void {
let i = 0;
while (i < data.length) {
for (let j = 1; j < width; j++) {
data[i + j] = (data[i + j] + data[i + j - 1]) & 255;
for (let j = components; j < width * components; j += components) {
for (let k = 0; k < components; k++) {
data[i + j + k] =
(data[i + j + k] + data[i + j - (components - k)]) & 255;
}
}
i += width;
i += width * components;
}
}
export function applyHorizontalDifferencingColor(
data: Uint8Array,
export function applyHorizontalDifferencing16Bit(
data: Uint16Array,
width: number,
components: number,
): void {
let i = 0;
while (i < data.length) {
for (let j = 3; j < width * 3; j += 3) {
data[i + j] = (data[i + j] + data[i + j - 3]) & 255;
data[i + j + 1] = (data[i + j + 1] + data[i + j - 2]) & 255;
data[i + j + 2] = (data[i + j + 2] + data[i + j - 1]) & 255;
for (let j = components; j < width * components; j += components) {
for (let k = 0; k < components; k++) {
data[i + j + k] =
(data[i + j + k] + data[i + j - (components - k)]) & 65535;
}
}
i += width * 3;
i += width * components;
}
}
import { IOBuffer } from 'iobuffer';
import {
applyHorizontalDifferencing,
applyHorizontalDifferencingColor,
applyHorizontalDifferencing8Bit,
applyHorizontalDifferencing16Bit,
} from './horizontalDifferencing';

@@ -181,2 +181,3 @@ import IFD from './ifd';

this.applyPredictor(ifd);
this.convertAlpha(ifd);
if (ifd.type === 0) {

@@ -280,14 +281,16 @@ // WhiteIsZero: we invert the values

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',
);
}
applyHorizontalDifferencing8Bit(
ifd.data as Uint8Array,
ifd.width,
ifd.components,
);
} else if (bitDepth === 16) {
applyHorizontalDifferencing16Bit(
ifd.data as Uint16Array,
ifd.width,
ifd.components,
);
} else {
throw new Error(
'Horizontal differencing is only supported for 8-bit images',
`Horizontal differencing is only supported for images with a bit depth of ${bitDepth}`,
);

@@ -301,2 +304,14 @@ }

}
private convertAlpha(ifd: TiffIfd): void {
if (ifd.alpha && ifd.associatedAlpha) {
const { data, components, maxSampleValue } = ifd;
for (let i = 0; i < data.length; i += components) {
const alphaValue = data[i + components - 1];
for (let j = 0; j < components - 1; j++) {
data[i + j] = Math.round((data[i + j] * maxSampleValue) / alphaValue);
}
}
}
}
}

@@ -303,0 +318,0 @@

@@ -41,12 +41,12 @@ import Ifd from './ifd';

public get newSubfileType(): number {
return this.get(254);
return this.get('NewSubfileType');
}
public get imageWidth(): number {
return this.get(256);
return this.get('ImageWidth');
}
public get imageLength(): number {
return this.get(257);
return this.get('ImageLength');
}
public get bitsPerSample(): number {
const data = this.get(258);
const data = this.get('BitsPerSample');
if (data && typeof data !== 'number') {

@@ -57,68 +57,81 @@ return data[0];

}
public get alpha(): boolean {
const extraSamples = this.extraSamples;
if (!extraSamples) return false;
return extraSamples[0] !== 0;
}
public get associatedAlpha(): boolean {
const extraSamples = this.extraSamples;
if (!extraSamples) return false;
return extraSamples[0] === 1;
}
public get extraSamples(): number[] | undefined {
return alwaysArray(this.get('ExtraSamples'));
}
public get compression(): number {
return this.get(259) || 1;
return this.get('Compression') || 1;
}
public get type(): number {
return this.get(262);
return this.get('PhotometricInterpretation');
}
public get fillOrder(): number {
return this.get(266) || 1;
return this.get('FillOrder') || 1;
}
public get documentName(): string | undefined {
return this.get(269);
return this.get('DocumentName');
}
public get imageDescription(): string | undefined {
return this.get(270);
return this.get('ImageDescription');
}
public get stripOffsets(): number[] {
return alwaysArray(this.get(273));
return alwaysArray(this.get('StripOffsets'));
}
public get orientation(): number {
return this.get(274);
return this.get('Orientation');
}
public get samplesPerPixel(): number {
return this.get(277) || 1;
return this.get('SamplesPerPixel') || 1;
}
public get rowsPerStrip(): number {
return this.get(278);
return this.get('RowsPerStrip');
}
public get stripByteCounts(): number[] {
return alwaysArray(this.get(279));
return alwaysArray(this.get('StripByteCounts'));
}
public get minSampleValue(): number {
return this.get(280) || 0;
return this.get('MinSampleValue') || 0;
}
public get maxSampleValue(): number {
return this.get(281) || Math.pow(2, this.bitsPerSample) - 1;
return this.get('MaxSampleValue') || Math.pow(2, this.bitsPerSample) - 1;
}
public get xResolution(): number {
return this.get(282);
return this.get('XResolution');
}
public get yResolution(): number {
return this.get(283);
return this.get('YResolution');
}
public get planarConfiguration(): number {
return this.get(284) || 1;
return this.get('PlanarConfiguration') || 1;
}
public get resolutionUnit(): number {
return this.get(296) || 2;
return this.get('ResolutionUnit') || 2;
}
public get dateTime(): string {
return this.get(306);
return this.get('DateTime');
}
public get predictor(): number {
return this.get(317) || 1;
return this.get('Predictor') || 1;
}
public get sampleFormat(): number {
return this.get(339) || 1;
return this.get('SampleFormat') || 1;
}
public get sMinSampleValue(): number {
return this.get(340) || this.minSampleValue;
return this.get('SMinSampleValue') || this.minSampleValue;
}
public get sMaxSampleValue(): number {
return this.get(341) || this.maxSampleValue;
return this.get('SMaxSampleValue') || this.maxSampleValue;
}
public get palette(): [number, number, number][] | undefined {
const totalColors = 2 ** this.bitsPerSample;
const colorMap: number[] = this.get(320);
const colorMap: number[] = this.get('ColorMap');
if (!colorMap) return undefined;

@@ -125,0 +138,0 @@ if (colorMap.length !== 3 * totalColors) {

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

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