Comparing version 5.0.1 to 5.0.2
@@ -0,0 +0,0 @@ // Section 14: Differencing Predictor (p. 64) |
@@ -0,0 +0,0 @@ import * as exif from './tags/exif'; |
@@ -0,0 +0,0 @@ let types = new Map([ |
@@ -0,0 +0,0 @@ import TIFFDecoder from './tiffDecoder'; |
@@ -7,23 +7,28 @@ import { IOBuffer } from 'iobuffer'; | ||
const MIN_BIT_LENGTH = 9; | ||
const stringTable = []; | ||
for (let i = 0; i < 256; i++) { | ||
stringTable.push([i]); | ||
let stringTable = []; | ||
function initializeStringTable() { | ||
if (stringTable.length === 0) { | ||
for (let i = 0; i < 256; i++) { | ||
stringTable.push([i]); | ||
} | ||
// Fill the table with dummy data. | ||
// Elements at indices > 257 will be replaced during decompression. | ||
const dummyString = []; | ||
for (let i = 256; i < 4096; i++) { | ||
stringTable.push(dummyString); | ||
} | ||
} | ||
} | ||
// Fill the table with dummy data. | ||
// Elements at indices > 257 will be replaced during decompression. | ||
const dummyString = [0]; | ||
for (let i = 256; i < 4096; i++) { | ||
stringTable.push(dummyString); | ||
} | ||
const andTable = [511, 1023, 2047, 4095]; | ||
const bitJumps = [0, 0, 0, 0, 0, 0, 0, 0, 0, 511, 1023, 2047, 4095]; | ||
class LzwDecoder { | ||
constructor(data) { | ||
this.stripArray = new Uint8Array(data.buffer, data.byteOffset, data.byteLength); | ||
const table = new Map(); | ||
for (let i = 0; i < 256; i++) { | ||
table.set(i, [i]); | ||
} | ||
this.currentBit = 0; | ||
this.nextData = 0; | ||
this.nextBits = 0; | ||
this.bytePointer = 0; | ||
this.tableLength = TABLE_START; | ||
this.currentBitLength = MIN_BIT_LENGTH; | ||
this.stripArray = new Uint8Array(data.buffer, data.byteOffset, data.byteLength); | ||
this.outData = new IOBuffer(data.byteLength); | ||
this.initializeTable(); | ||
} | ||
@@ -59,2 +64,3 @@ decode() { | ||
initializeTable() { | ||
initializeStringTable(); | ||
this.tableLength = TABLE_START; | ||
@@ -75,3 +81,7 @@ this.currentBitLength = MIN_BIT_LENGTH; | ||
stringTable[this.tableLength++] = string; | ||
if (this.tableLength + 1 === 2 ** this.currentBitLength) { | ||
if (stringTable.length > 4096) { | ||
stringTable = []; | ||
throw new Error('LZW decoding error. Please open an issue at https://github.com/image-js/tiff/issues/new/choose (include a test image).'); | ||
} | ||
if (this.tableLength === bitJumps[this.currentBitLength]) { | ||
this.currentBitLength++; | ||
@@ -81,24 +91,19 @@ } | ||
getNextCode() { | ||
const d = this.currentBit % 8; | ||
const a = this.currentBit >>> 3; | ||
const de = 8 - d; | ||
const ef = this.currentBit + this.currentBitLength - (a + 1) * 8; | ||
let fg = 8 * (a + 2) - (this.currentBit + this.currentBitLength); | ||
const dg = (a + 2) * 8 - this.currentBit; | ||
fg = Math.max(0, fg); | ||
let chunk1 = this.stripArray[a] & (2 ** (8 - d) - 1); | ||
chunk1 <<= this.currentBitLength - de; | ||
let chunks = chunk1; | ||
if (a + 1 < this.stripArray.length) { | ||
let chunk2 = this.stripArray[a + 1] >>> fg; | ||
chunk2 <<= Math.max(0, this.currentBitLength - dg); | ||
chunks += chunk2; | ||
this.nextData = | ||
(this.nextData << 8) | (this.stripArray[this.bytePointer++] & 0xff); | ||
this.nextBits += 8; | ||
if (this.nextBits < this.currentBitLength) { | ||
this.nextData = | ||
(this.nextData << 8) | (this.stripArray[this.bytePointer++] & 0xff); | ||
this.nextBits += 8; | ||
} | ||
if (ef > 8 && a + 2 < this.stripArray.length) { | ||
const hi = (a + 3) * 8 - (this.currentBit + this.currentBitLength); | ||
const chunk3 = this.stripArray[a + 2] >>> hi; | ||
chunks += chunk3; | ||
const code = (this.nextData >> (this.nextBits - this.currentBitLength)) & | ||
andTable[this.currentBitLength - 9]; | ||
this.nextBits -= this.currentBitLength; | ||
// This should not really happen but is present in other codes as well. | ||
// See: https://github.com/sugark/Tiffus/blob/15a60123813d1612f4ae9e4fab964f9f7d71cf63/src/org/eclipse/swt/internal/image/TIFFLZWDecoder.java | ||
if (this.bytePointer > this.stripArray.length) { | ||
return 257; | ||
} | ||
this.currentBit += this.currentBitLength; | ||
return chunks; | ||
return code; | ||
} | ||
@@ -105,0 +110,0 @@ } |
@@ -0,0 +0,0 @@ const tagsById = { |
@@ -0,0 +0,0 @@ const tagsById = { |
@@ -0,0 +0,0 @@ const tagsById = { |
@@ -176,3 +176,3 @@ import { IOBuffer } from 'iobuffer'; | ||
for (let i = 0; i < stripOffsets.length; i++) { | ||
let stripData = new DataView(this.buffer, stripOffsets[i], stripByteCounts[i]); | ||
let stripData = new DataView(this.buffer, this.byteOffset + stripOffsets[i], stripByteCounts[i]); | ||
// Last strip can be smaller | ||
@@ -179,0 +179,0 @@ let length = remainingPixels > maxPixels ? maxPixels : remainingPixels; |
@@ -0,0 +0,0 @@ import Ifd from './ifd'; |
export {}; | ||
//# sourceMappingURL=types.js.map |
@@ -0,0 +0,0 @@ import { inflate } from 'pako'; |
export declare function applyHorizontalDifferencing8Bit(data: Uint8Array, width: number, components: number): void; | ||
export declare function applyHorizontalDifferencing16Bit(data: Uint16Array, width: number, components: number): void; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { IFDKind, DataArray } from './types'; |
@@ -0,0 +0,0 @@ "use strict"; |
import TIFFDecoder from './tiffDecoder'; | ||
export declare function getByteLength(type: number, count: number): number; | ||
export declare function readData(decoder: TIFFDecoder, type: number, count: number): any; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import TiffIfd from './tiffIfd'; |
@@ -0,0 +0,0 @@ "use strict"; |
export declare function decompressLzw(stripData: DataView): DataView; |
@@ -10,23 +10,28 @@ "use strict"; | ||
const MIN_BIT_LENGTH = 9; | ||
const stringTable = []; | ||
for (let i = 0; i < 256; i++) { | ||
stringTable.push([i]); | ||
let stringTable = []; | ||
function initializeStringTable() { | ||
if (stringTable.length === 0) { | ||
for (let i = 0; i < 256; i++) { | ||
stringTable.push([i]); | ||
} | ||
// Fill the table with dummy data. | ||
// Elements at indices > 257 will be replaced during decompression. | ||
const dummyString = []; | ||
for (let i = 256; i < 4096; i++) { | ||
stringTable.push(dummyString); | ||
} | ||
} | ||
} | ||
// Fill the table with dummy data. | ||
// Elements at indices > 257 will be replaced during decompression. | ||
const dummyString = [0]; | ||
for (let i = 256; i < 4096; i++) { | ||
stringTable.push(dummyString); | ||
} | ||
const andTable = [511, 1023, 2047, 4095]; | ||
const bitJumps = [0, 0, 0, 0, 0, 0, 0, 0, 0, 511, 1023, 2047, 4095]; | ||
class LzwDecoder { | ||
constructor(data) { | ||
this.stripArray = new Uint8Array(data.buffer, data.byteOffset, data.byteLength); | ||
const table = new Map(); | ||
for (let i = 0; i < 256; i++) { | ||
table.set(i, [i]); | ||
} | ||
this.currentBit = 0; | ||
this.nextData = 0; | ||
this.nextBits = 0; | ||
this.bytePointer = 0; | ||
this.tableLength = TABLE_START; | ||
this.currentBitLength = MIN_BIT_LENGTH; | ||
this.stripArray = new Uint8Array(data.buffer, data.byteOffset, data.byteLength); | ||
this.outData = new iobuffer_1.IOBuffer(data.byteLength); | ||
this.initializeTable(); | ||
} | ||
@@ -62,2 +67,3 @@ decode() { | ||
initializeTable() { | ||
initializeStringTable(); | ||
this.tableLength = TABLE_START; | ||
@@ -78,3 +84,7 @@ this.currentBitLength = MIN_BIT_LENGTH; | ||
stringTable[this.tableLength++] = string; | ||
if (this.tableLength + 1 === 2 ** this.currentBitLength) { | ||
if (stringTable.length > 4096) { | ||
stringTable = []; | ||
throw new Error('LZW decoding error. Please open an issue at https://github.com/image-js/tiff/issues/new/choose (include a test image).'); | ||
} | ||
if (this.tableLength === bitJumps[this.currentBitLength]) { | ||
this.currentBitLength++; | ||
@@ -84,24 +94,19 @@ } | ||
getNextCode() { | ||
const d = this.currentBit % 8; | ||
const a = this.currentBit >>> 3; | ||
const de = 8 - d; | ||
const ef = this.currentBit + this.currentBitLength - (a + 1) * 8; | ||
let fg = 8 * (a + 2) - (this.currentBit + this.currentBitLength); | ||
const dg = (a + 2) * 8 - this.currentBit; | ||
fg = Math.max(0, fg); | ||
let chunk1 = this.stripArray[a] & (2 ** (8 - d) - 1); | ||
chunk1 <<= this.currentBitLength - de; | ||
let chunks = chunk1; | ||
if (a + 1 < this.stripArray.length) { | ||
let chunk2 = this.stripArray[a + 1] >>> fg; | ||
chunk2 <<= Math.max(0, this.currentBitLength - dg); | ||
chunks += chunk2; | ||
this.nextData = | ||
(this.nextData << 8) | (this.stripArray[this.bytePointer++] & 0xff); | ||
this.nextBits += 8; | ||
if (this.nextBits < this.currentBitLength) { | ||
this.nextData = | ||
(this.nextData << 8) | (this.stripArray[this.bytePointer++] & 0xff); | ||
this.nextBits += 8; | ||
} | ||
if (ef > 8 && a + 2 < this.stripArray.length) { | ||
const hi = (a + 3) * 8 - (this.currentBit + this.currentBitLength); | ||
const chunk3 = this.stripArray[a + 2] >>> hi; | ||
chunks += chunk3; | ||
const code = (this.nextData >> (this.nextBits - this.currentBitLength)) & | ||
andTable[this.currentBitLength - 9]; | ||
this.nextBits -= this.currentBitLength; | ||
// This should not really happen but is present in other codes as well. | ||
// See: https://github.com/sugark/Tiffus/blob/15a60123813d1612f4ae9e4fab964f9f7d71cf63/src/org/eclipse/swt/internal/image/TIFFLZWDecoder.java | ||
if (this.bytePointer > this.stripArray.length) { | ||
return 257; | ||
} | ||
this.currentBit += this.currentBitLength; | ||
return chunks; | ||
return code; | ||
} | ||
@@ -108,0 +113,0 @@ } |
declare const tagsById: Record<number, string>; | ||
declare const tagsByName: Record<string, number>; | ||
export { tagsById, tagsByName }; |
@@ -0,0 +0,0 @@ "use strict"; |
declare const tagsById: Record<number, string>; | ||
declare const tagsByName: Record<string, number>; | ||
export { tagsById, tagsByName }; |
@@ -0,0 +0,0 @@ "use strict"; |
declare const tagsById: Record<number, string>; | ||
declare const tagsByName: Record<string, number>; | ||
export { tagsById, tagsByName }; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { IOBuffer } from 'iobuffer'; |
@@ -181,3 +181,3 @@ "use strict"; | ||
for (let i = 0; i < stripOffsets.length; i++) { | ||
let stripData = new DataView(this.buffer, stripOffsets[i], stripByteCounts[i]); | ||
let stripData = new DataView(this.buffer, this.byteOffset + stripOffsets[i], stripByteCounts[i]); | ||
// Last strip can be smaller | ||
@@ -184,0 +184,0 @@ let length = remainingPixels > maxPixels ? maxPixels : remainingPixels; |
@@ -0,0 +0,0 @@ import Ifd from './ifd'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ /// <reference types="node" /> |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//# sourceMappingURL=types.js.map |
export declare function decompressZlib(stripData: DataView): DataView; |
@@ -0,0 +0,0 @@ "use strict"; |
{ | ||
"name": "tiff", | ||
"version": "5.0.1", | ||
"version": "5.0.2", | ||
"description": "TIFF image decoder written entirely in JavaScript", | ||
@@ -47,11 +47,11 @@ "main": "lib/index.js", | ||
"@types/jest": "^27.0.2", | ||
"@types/node": "^16.10.3", | ||
"@types/node": "^16.11.6", | ||
"@types/pako": "^1.0.2", | ||
"eslint": "^7.30.0", | ||
"eslint-config-cheminfo-typescript": "^9.0.0", | ||
"jest": "^27.2.5", | ||
"eslint": "^8.1.0", | ||
"eslint-config-cheminfo-typescript": "^10.1.1", | ||
"jest": "^27.3.1", | ||
"prettier": "^2.4.1", | ||
"rimraf": "^3.0.2", | ||
"ts-jest": "^27.0.5", | ||
"typescript": "^4.4.3" | ||
"ts-jest": "^27.0.7", | ||
"typescript": "^4.4.4" | ||
}, | ||
@@ -58,0 +58,0 @@ "prettier": { |
@@ -9,18 +9,27 @@ import { IOBuffer } from 'iobuffer'; | ||
const stringTable: number[][] = []; | ||
for (let i = 0; i < 256; i++) { | ||
stringTable.push([i]); | ||
let stringTable: number[][] = []; | ||
function initializeStringTable() { | ||
if (stringTable.length === 0) { | ||
for (let i = 0; i < 256; i++) { | ||
stringTable.push([i]); | ||
} | ||
// Fill the table with dummy data. | ||
// Elements at indices > 257 will be replaced during decompression. | ||
const dummyString: number[] = []; | ||
for (let i = 256; i < 4096; i++) { | ||
stringTable.push(dummyString); | ||
} | ||
} | ||
} | ||
// Fill the table with dummy data. | ||
// Elements at indices > 257 will be replaced during decompression. | ||
const dummyString = [0]; | ||
for (let i = 256; i < 4096; i++) { | ||
stringTable.push(dummyString); | ||
} | ||
const andTable = [511, 1023, 2047, 4095]; | ||
const bitJumps = [0, 0, 0, 0, 0, 0, 0, 0, 0, 511, 1023, 2047, 4095]; | ||
class LzwDecoder { | ||
private stripArray: Uint8Array; | ||
private currentBit: number; | ||
private tableLength: number; | ||
private currentBitLength: number; | ||
private nextData = 0; | ||
private nextBits = 0; | ||
private bytePointer = 0; | ||
private tableLength = TABLE_START; | ||
private currentBitLength = MIN_BIT_LENGTH; | ||
private outData: IOBuffer; | ||
@@ -34,10 +43,4 @@ | ||
); | ||
const table = new Map<number, number[]>(); | ||
for (let i = 0; i < 256; i++) { | ||
table.set(i, [i]); | ||
} | ||
this.currentBit = 0; | ||
this.tableLength = TABLE_START; | ||
this.currentBitLength = MIN_BIT_LENGTH; | ||
this.outData = new IOBuffer(data.byteLength); | ||
this.initializeTable(); | ||
} | ||
@@ -73,2 +76,3 @@ | ||
const outArray = this.outData.toArray(); | ||
return new DataView( | ||
@@ -82,2 +86,3 @@ outArray.buffer, | ||
private initializeTable(): void { | ||
initializeStringTable(); | ||
this.tableLength = TABLE_START; | ||
@@ -102,3 +107,9 @@ this.currentBitLength = MIN_BIT_LENGTH; | ||
stringTable[this.tableLength++] = string; | ||
if (this.tableLength + 1 === 2 ** this.currentBitLength) { | ||
if (stringTable.length > 4096) { | ||
stringTable = []; | ||
throw new Error( | ||
'LZW decoding error. Please open an issue at https://github.com/image-js/tiff/issues/new/choose (include a test image).', | ||
); | ||
} | ||
if (this.tableLength === bitJumps[this.currentBitLength]) { | ||
this.currentBitLength++; | ||
@@ -109,24 +120,24 @@ } | ||
private getNextCode(): number { | ||
const d = this.currentBit % 8; | ||
const a = this.currentBit >>> 3; | ||
const de = 8 - d; | ||
const ef = this.currentBit + this.currentBitLength - (a + 1) * 8; | ||
let fg = 8 * (a + 2) - (this.currentBit + this.currentBitLength); | ||
const dg = (a + 2) * 8 - this.currentBit; | ||
fg = Math.max(0, fg); | ||
let chunk1 = this.stripArray[a] & (2 ** (8 - d) - 1); | ||
chunk1 <<= this.currentBitLength - de; | ||
let chunks = chunk1; | ||
if (a + 1 < this.stripArray.length) { | ||
let chunk2 = this.stripArray[a + 1] >>> fg; | ||
chunk2 <<= Math.max(0, this.currentBitLength - dg); | ||
chunks += chunk2; | ||
this.nextData = | ||
(this.nextData << 8) | (this.stripArray[this.bytePointer++] & 0xff); | ||
this.nextBits += 8; | ||
if (this.nextBits < this.currentBitLength) { | ||
this.nextData = | ||
(this.nextData << 8) | (this.stripArray[this.bytePointer++] & 0xff); | ||
this.nextBits += 8; | ||
} | ||
if (ef > 8 && a + 2 < this.stripArray.length) { | ||
const hi = (a + 3) * 8 - (this.currentBit + this.currentBitLength); | ||
const chunk3 = this.stripArray[a + 2] >>> hi; | ||
chunks += chunk3; | ||
const code = | ||
(this.nextData >> (this.nextBits - this.currentBitLength)) & | ||
andTable[this.currentBitLength - 9]; | ||
this.nextBits -= this.currentBitLength; | ||
// This should not really happen but is present in other codes as well. | ||
// See: https://github.com/sugark/Tiffus/blob/15a60123813d1612f4ae9e4fab964f9f7d71cf63/src/org/eclipse/swt/internal/image/TIFFLZWDecoder.java | ||
if (this.bytePointer > this.stripArray.length) { | ||
return 257; | ||
} | ||
this.currentBit += this.currentBitLength; | ||
return chunks; | ||
return code; | ||
} | ||
@@ -133,0 +144,0 @@ } |
@@ -212,3 +212,3 @@ import { IOBuffer } from 'iobuffer'; | ||
this.buffer, | ||
stripOffsets[i], | ||
this.byteOffset + stripOffsets[i], | ||
stripByteCounts[i], | ||
@@ -215,0 +215,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
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
3478
179211