@ac-kit/format-tiff 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +49 -0
- package/LICENSE +28 -0
- package/README.md +114 -2
- package/dist/codec/_deflate.d.ts +12 -0
- package/dist/codec/_deflate.d.ts.map +1 -0
- package/dist/codec/_deflate.js +33 -0
- package/dist/codec/_deflate.js.map +1 -0
- package/dist/codec/_lzw.d.ts +18 -0
- package/dist/codec/_lzw.d.ts.map +1 -0
- package/dist/codec/_lzw.js +134 -0
- package/dist/codec/_lzw.js.map +1 -0
- package/dist/codec/_packbits.d.ts +10 -0
- package/dist/codec/_packbits.d.ts.map +1 -0
- package/dist/codec/_packbits.js +34 -0
- package/dist/codec/_packbits.js.map +1 -0
- package/dist/codec/_predictor.d.ts +15 -0
- package/dist/codec/_predictor.d.ts.map +1 -0
- package/dist/codec/_predictor.js +68 -0
- package/dist/codec/_predictor.js.map +1 -0
- package/dist/codec/tiff-decoder.d.ts +54 -0
- package/dist/codec/tiff-decoder.d.ts.map +1 -0
- package/dist/codec/tiff-decoder.js +2 -0
- package/dist/codec/tiff-decoder.js.map +1 -0
- package/dist/container/_ifd.d.ts +45 -0
- package/dist/container/_ifd.d.ts.map +1 -0
- package/dist/container/_ifd.js +160 -0
- package/dist/container/_ifd.js.map +1 -0
- package/dist/container/_image.d.ts +37 -0
- package/dist/container/_image.d.ts.map +1 -0
- package/dist/container/_image.js +201 -0
- package/dist/container/_image.js.map +1 -0
- package/dist/container/_reader.d.ts +18 -0
- package/dist/container/_reader.d.ts.map +1 -0
- package/dist/container/_reader.js +53 -0
- package/dist/container/_reader.js.map +1 -0
- package/dist/container/open-tiff.d.ts +40 -0
- package/dist/container/open-tiff.d.ts.map +1 -0
- package/dist/container/open-tiff.js +209 -0
- package/dist/container/open-tiff.js.map +1 -0
- package/dist/container/read-tiff-gdal-metadata.d.ts +33 -0
- package/dist/container/read-tiff-gdal-metadata.d.ts.map +1 -0
- package/dist/container/read-tiff-gdal-metadata.js +82 -0
- package/dist/container/read-tiff-gdal-metadata.js.map +1 -0
- package/dist/container/tiff.d.ts +119 -0
- package/dist/container/tiff.d.ts.map +1 -0
- package/dist/container/tiff.js +2 -0
- package/dist/container/tiff.js.map +1 -0
- package/dist/errors.d.ts +34 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +43 -0
- package/dist/errors.js.map +1 -0
- package/dist/field/_field-values.d.ts +10 -0
- package/dist/field/_field-values.d.ts.map +1 -0
- package/dist/field/_field-values.js +51 -0
- package/dist/field/_field-values.js.map +1 -0
- package/dist/field/tiff-field-type.d.ts +42 -0
- package/dist/field/tiff-field-type.d.ts.map +1 -0
- package/dist/field/tiff-field-type.js +68 -0
- package/dist/field/tiff-field-type.js.map +1 -0
- package/dist/field/tiff-field.d.ts +62 -0
- package/dist/field/tiff-field.d.ts.map +1 -0
- package/dist/field/tiff-field.js +125 -0
- package/dist/field/tiff-field.js.map +1 -0
- package/dist/field/tiff-tag.d.ts +120 -0
- package/dist/field/tiff-tag.d.ts.map +1 -0
- package/dist/field/tiff-tag.js +124 -0
- package/dist/field/tiff-tag.js.map +1 -0
- package/dist/geotiff/geo-key.d.ts +67 -0
- package/dist/geotiff/geo-key.d.ts.map +1 -0
- package/dist/geotiff/geo-key.js +69 -0
- package/dist/geotiff/geo-key.js.map +1 -0
- package/dist/geotiff/geotiff-raster-to-model.d.ts +36 -0
- package/dist/geotiff/geotiff-raster-to-model.d.ts.map +1 -0
- package/dist/geotiff/geotiff-raster-to-model.js +70 -0
- package/dist/geotiff/geotiff-raster-to-model.js.map +1 -0
- package/dist/geotiff/index.d.ts +4 -0
- package/dist/geotiff/index.d.ts.map +1 -0
- package/dist/geotiff/index.js +4 -0
- package/dist/geotiff/index.js.map +1 -0
- package/dist/geotiff/read-geotiff.d.ts +63 -0
- package/dist/geotiff/read-geotiff.d.ts.map +1 -0
- package/dist/geotiff/read-geotiff.js +150 -0
- package/dist/geotiff/read-geotiff.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/raster/_decode-chunk.d.ts +29 -0
- package/dist/raster/_decode-chunk.d.ts.map +1 -0
- package/dist/raster/_decode-chunk.js +159 -0
- package/dist/raster/_decode-chunk.js.map +1 -0
- package/dist/raster/_layout.d.ts +27 -0
- package/dist/raster/_layout.d.ts.map +1 -0
- package/dist/raster/_layout.js +79 -0
- package/dist/raster/_layout.js.map +1 -0
- package/dist/raster/_samples.d.ts +52 -0
- package/dist/raster/_samples.d.ts.map +1 -0
- package/dist/raster/_samples.js +192 -0
- package/dist/raster/_samples.js.map +1 -0
- package/dist/raster/read-tiff-window.d.ts +109 -0
- package/dist/raster/read-tiff-window.d.ts.map +1 -0
- package/dist/raster/read-tiff-window.js +396 -0
- package/dist/raster/read-tiff-window.js.map +1 -0
- package/dist/raster/tiff-sample-array.d.ts +7 -0
- package/dist/raster/tiff-sample-array.d.ts.map +1 -0
- package/dist/raster/tiff-sample-array.js +2 -0
- package/dist/raster/tiff-sample-array.js.map +1 -0
- package/package.json +68 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# @ac-kit/format-tiff
|
|
2
|
+
|
|
3
|
+
## 0.1.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [66187b7]
|
|
8
|
+
- @ac-kit/core@0.15.0
|
|
9
|
+
- @ac-kit/format-xml@0.3.1
|
|
10
|
+
- @ac-kit/math-linear@0.5.1
|
|
11
|
+
|
|
12
|
+
## 0.1.0
|
|
13
|
+
|
|
14
|
+
### Minor Changes
|
|
15
|
+
|
|
16
|
+
- 5c203e7: New package: TIFF 6.0, BigTIFF and Cloud Optimized GeoTIFF files read by
|
|
17
|
+
ranges within limits. `openTiff(source, limits, signal?)` takes a `Blob`,
|
|
18
|
+
bytes or any `ByteRangeSource`, and reads the header, GDAL's ghost area, every
|
|
19
|
+
IFD and SubIFD and every tag value — a COG in one or two reads. Each
|
|
20
|
+
`TiffImage` keeps every tag raw (`tiffFieldNumbers`, `tiffFieldBigInts`,
|
|
21
|
+
`tiffFieldRationals`, `tiffFieldText`), decodes the baseline ones with their
|
|
22
|
+
defaults and `GDAL_NODATA`, and lists its overviews and mask by
|
|
23
|
+
`NewSubfileType`; `readTiffGdalMetadata` reads `GDAL_METADATA`.
|
|
24
|
+
`readTiffWindow` and `readTiffTile` read only the strips or tiles they touch,
|
|
25
|
+
coalescing close ones into one request, and decode every sample format and
|
|
26
|
+
layout (1–32 and 64-bit integers, 16/24/32/64-bit floats, complex, chunky and
|
|
27
|
+
planar, `FillOrder` 2, sparse chunks) from none, PackBits, LZW and Deflate
|
|
28
|
+
(`DecompressionStream`) with predictors 2 and 3; any other compression goes to
|
|
29
|
+
a caller's `decoders` entry, else `TiffUnsupportedError` names its code.
|
|
30
|
+
`TiffLimits` bounds images, tag bytes, stored and decoded chunk bytes;
|
|
31
|
+
broken files throw `TiffFormatError`. `@ac-kit/format-tiff/geotiff` reads
|
|
32
|
+
GeoTIFF 1.1 keys, the raster type and the horizontal and vertical EPSG codes
|
|
33
|
+
(`readGeoTiff`), and writes the raster-to-model `Affine2`
|
|
34
|
+
(`geotiffRasterToModel`).
|
|
35
|
+
|
|
36
|
+
### Patch Changes
|
|
37
|
+
|
|
38
|
+
- Updated dependencies [5c203e7]
|
|
39
|
+
- Updated dependencies [5c203e7]
|
|
40
|
+
- Updated dependencies [5c203e7]
|
|
41
|
+
- Updated dependencies [5c203e7]
|
|
42
|
+
- Updated dependencies [5c203e7]
|
|
43
|
+
- Updated dependencies [5c203e7]
|
|
44
|
+
- Updated dependencies [5c203e7]
|
|
45
|
+
- Updated dependencies [5c203e7]
|
|
46
|
+
- Updated dependencies [5c203e7]
|
|
47
|
+
- @ac-kit/core@0.14.0
|
|
48
|
+
- @ac-kit/format-xml@0.3.0
|
|
49
|
+
- @ac-kit/math-linear@0.5.0
|
package/LICENSE
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-2026 Anthony Champagne and contributors
|
|
4
|
+
|
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
|
7
|
+
|
|
8
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
9
|
+
list of conditions and the following disclaimer.
|
|
10
|
+
|
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
12
|
+
this list of conditions and the following disclaimer in the documentation
|
|
13
|
+
and/or other materials provided with the distribution.
|
|
14
|
+
|
|
15
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
16
|
+
contributors may be used to endorse or promote products derived from
|
|
17
|
+
this software without specific prior written permission.
|
|
18
|
+
|
|
19
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
20
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
21
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
22
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
23
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
24
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
25
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
26
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
27
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
28
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,115 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @ac-kit/format-tiff
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
TIFF 6.0, BigTIFF and Cloud Optimized GeoTIFF (COG) files, read by ranges
|
|
4
|
+
without holding them whole: every IFD and tag, overviews and masks, and windows
|
|
5
|
+
or tiles of any image decoded within limits. `./geotiff` reads GeoTIFF 1.1
|
|
6
|
+
georeferencing. Portable (`P`): Web APIs only.
|
|
7
|
+
|
|
8
|
+
```ts
|
|
9
|
+
import { openTiff, readTiffWindow } from "@ac-kit/format-tiff";
|
|
10
|
+
import { geotiffRasterToModel, readGeoTiff } from "@ac-kit/format-tiff/geotiff";
|
|
11
|
+
import { affine2Create } from "@ac-kit/math-linear";
|
|
12
|
+
|
|
13
|
+
const tiff = await openTiff(
|
|
14
|
+
{
|
|
15
|
+
size,
|
|
16
|
+
read: async (offset, length, signal) => {
|
|
17
|
+
const response = await fetch(url, {
|
|
18
|
+
headers: { Range: `bytes=${offset}-${offset + length - 1}` },
|
|
19
|
+
signal,
|
|
20
|
+
});
|
|
21
|
+
return response.bytes();
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
maxImages: 64,
|
|
26
|
+
maxTagBytes: 16 * 1024 * 1024,
|
|
27
|
+
maxTileBytes: 64 * 1024 * 1024,
|
|
28
|
+
maxDecodedBytes: 256 * 1024 * 1024,
|
|
29
|
+
},
|
|
30
|
+
);
|
|
31
|
+
const [dem] = tiff.images;
|
|
32
|
+
const window = { x: 570, y: 70, width: 750, height: 930 };
|
|
33
|
+
const heights = await readTiffWindow(
|
|
34
|
+
dem!,
|
|
35
|
+
window,
|
|
36
|
+
new Float32Array(window.width * window.height),
|
|
37
|
+
{ band: 0 },
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
readGeoTiff(dem!)?.verticalCrs; // 3855: EGM2008 heights
|
|
41
|
+
const rasterToModel = affine2Create();
|
|
42
|
+
geotiffRasterToModel(rasterToModel, dem!, { origin: "center" });
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Reading
|
|
46
|
+
|
|
47
|
+
- `openTiff(source, limits, signal?)` takes a `Blob` (a `File`, Node's
|
|
48
|
+
`fs.openAsBlob`), bytes in memory, or any `ByteRangeSource` from
|
|
49
|
+
`@ac-kit/core` (HTTP `Range`, object storage). It reads the first 16 KiB,
|
|
50
|
+
which in a COG holds the header, GDAL's ghost area and every IFD, then the
|
|
51
|
+
tag values outside it in as few reads as their gaps allow: a COG opens in
|
|
52
|
+
one or two reads. Every IFD of the chain and every SubIFD becomes a
|
|
53
|
+
`TiffImage`, complete when the promise resolves.
|
|
54
|
+
- `TiffImage` holds every tag raw (`fields`, read with `tiffFieldNumbers`,
|
|
55
|
+
`tiffFieldBigInts`, `tiffFieldRationals`, `tiffFieldText`), the baseline
|
|
56
|
+
ones decoded with their defaults, GDAL's `GDAL_NODATA` (`noData`,
|
|
57
|
+
`noDataValue`), and its place in the file: `overviews` (largest first) and
|
|
58
|
+
`mask` by `NewSubfileType`, as GDAL groups them, `subImages`, `parent`.
|
|
59
|
+
`readTiffGdalMetadata(image)` reads `GDAL_METADATA`: band scales, offsets,
|
|
60
|
+
descriptions and any other item.
|
|
61
|
+
- `readTiffWindow(image, window, out, options?)` and `readTiffTile(image,
|
|
62
|
+
column, row, out, options?)` read only the strips or tiles they touch,
|
|
63
|
+
coalescing those close together into one request, and decode them into
|
|
64
|
+
`out`: one `band`, or every sample pixel-interleaved.
|
|
65
|
+
`createTiffSampleArray(image, pixels, band?)` makes the natural array.
|
|
66
|
+
|
|
67
|
+
### Samples
|
|
68
|
+
|
|
69
|
+
Every TIFF 6.0 sample format and layout: unsigned and signed integers of 1 to
|
|
70
|
+
32 bits (packed, rows byte-aligned, widths that differ per sample) and of 64
|
|
71
|
+
bits (as `bigint`), floats of 16, 24, 32 and 64 bits, complex integers and
|
|
72
|
+
floats as (real, imaginary) pairs; chunky and planar images; strips and
|
|
73
|
+
tiles; `FillOrder` 2. Samples are as stored, with no colour conversion. A
|
|
74
|
+
sparse chunk (offset and byte count 0, as GDAL writes it) reads as the
|
|
75
|
+
no-data value.
|
|
76
|
+
|
|
77
|
+
### Codecs
|
|
78
|
+
|
|
79
|
+
Built in: none, PackBits, LZW (TIFF 6.0 and libtiff's older variant) and
|
|
80
|
+
Deflate through `DecompressionStream`, with predictors 2 (horizontal
|
|
81
|
+
differencing) and 3 (floating point). Any other compression — JPEG, ZSTD,
|
|
82
|
+
LERC, WebP, JPEG XL, CCITT — is decoded by a `decoders` entry keyed by its
|
|
83
|
+
`Compression` value, which receives the stored chunk and returns it as an
|
|
84
|
+
uncompressed chunk holds it; the reader undoes the predictor after it.
|
|
85
|
+
Without one, reading throws `TiffUnsupportedError`, whose `code` is the
|
|
86
|
+
compression.
|
|
87
|
+
|
|
88
|
+
### Limits
|
|
89
|
+
|
|
90
|
+
Inputs are untrusted. `TiffLimits` bounds the IFD count, the bytes of IFDs and
|
|
91
|
+
tag values (and so the chunk tables), each stored chunk and each decoded one,
|
|
92
|
+
each checked before the read or allocation it would cause; Deflate stops once
|
|
93
|
+
a chunk's rows are full, so a compression bomb costs no more than they hold.
|
|
94
|
+
The GDAL metadata XML is parsed with no external entity and no entity
|
|
95
|
+
expansion. Errors: `TiffFormatError` (broken structure, with the byte
|
|
96
|
+
`position`), `TiffLimitError`, `TiffUnsupportedError`.
|
|
97
|
+
|
|
98
|
+
## GeoTIFF
|
|
99
|
+
|
|
100
|
+
`readGeoTiff(image)` (from `@ac-kit/format-tiff/geotiff`) reads the
|
|
101
|
+
GeoTIFF 1.1 (OGC 19-008r4) key directory — every key by ID, `GeoKey` naming
|
|
102
|
+
them with the 1.1 names — the raster type (PixelIsArea or PixelIsPoint), the
|
|
103
|
+
horizontal and vertical EPSG codes, tiepoints, pixel scale and
|
|
104
|
+
transformation. `geotiffRasterToModel(out, image, { origin })` writes the
|
|
105
|
+
raster-to-model affine transform into a `math-linear` `Affine2`, with
|
|
106
|
+
`(0, 0)` at the first pixel's outer corner (GDAL's geotransform) or at its
|
|
107
|
+
centre, whatever the file's raster type.
|
|
108
|
+
|
|
109
|
+
## Not here
|
|
110
|
+
|
|
111
|
+
Writing TIFF files, and the codecs left to callers.
|
|
112
|
+
|
|
113
|
+
See the
|
|
114
|
+
[generated API docs](https://anthochamp.pages.grenadine.io/node-essentials/api/format-tiff/)
|
|
115
|
+
for the full reference.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inflates zlib data (RFC 1950, TIFF's Deflate) into `out` through
|
|
3
|
+
* `DecompressionStream`, stopping and cancelling the stream once `out` is full,
|
|
4
|
+
* so a chunk inflating past its rows costs no more than they hold. What follows
|
|
5
|
+
* the bytes needed, data or a broken tail, is never looked at.
|
|
6
|
+
*
|
|
7
|
+
* @returns The bytes written, fewer than `out.length` when the stream ends.
|
|
8
|
+
* @throws {TypeError} When the data is not zlib before `out` is full.
|
|
9
|
+
* @throws When `signal` aborts, its reason.
|
|
10
|
+
*/
|
|
11
|
+
export declare function inflate_(input: Uint8Array<ArrayBuffer>, out: Uint8Array, signal: AbortSignal | undefined): Promise<number>;
|
|
12
|
+
//# sourceMappingURL=_deflate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_deflate.d.ts","sourceRoot":"","sources":["../../src/codec/_deflate.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,wBAAsB,QAAQ,CAC7B,KAAK,EAAE,UAAU,CAAC,WAAW,CAAC,EAC9B,GAAG,EAAE,UAAU,EACf,MAAM,EAAE,WAAW,GAAG,SAAS,GAC7B,OAAO,CAAC,MAAM,CAAC,CAoBjB"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { readStreamChunks } from "@ac-kit/core";
|
|
2
|
+
/**
|
|
3
|
+
* Inflates zlib data (RFC 1950, TIFF's Deflate) into `out` through
|
|
4
|
+
* `DecompressionStream`, stopping and cancelling the stream once `out` is full,
|
|
5
|
+
* so a chunk inflating past its rows costs no more than they hold. What follows
|
|
6
|
+
* the bytes needed, data or a broken tail, is never looked at.
|
|
7
|
+
*
|
|
8
|
+
* @returns The bytes written, fewer than `out.length` when the stream ends.
|
|
9
|
+
* @throws {TypeError} When the data is not zlib before `out` is full.
|
|
10
|
+
* @throws When `signal` aborts, its reason.
|
|
11
|
+
*/
|
|
12
|
+
export async function inflate_(input, out, signal) {
|
|
13
|
+
const stream = new ReadableStream({
|
|
14
|
+
start(controller) {
|
|
15
|
+
controller.enqueue(input);
|
|
16
|
+
controller.close();
|
|
17
|
+
},
|
|
18
|
+
}).pipeThrough(new DecompressionStream("deflate"));
|
|
19
|
+
let written = 0;
|
|
20
|
+
for await (const chunk of readStreamChunks(stream, signal)) {
|
|
21
|
+
const length = Math.min(chunk.length, out.length - written);
|
|
22
|
+
out.set(chunk.subarray(0, length), written);
|
|
23
|
+
written += length;
|
|
24
|
+
if (written === out.length) {
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (written === out.length) {
|
|
29
|
+
await stream.cancel().catch(() => { });
|
|
30
|
+
}
|
|
31
|
+
return written;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=_deflate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_deflate.js","sourceRoot":"","sources":["../../src/codec/_deflate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAC7B,KAA8B,EAC9B,GAAe,EACf,MAA+B;IAE/B,MAAM,MAAM,GAAG,IAAI,cAAc,CAA0B;QAC1D,KAAK,CAAC,UAAU;YACf,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YAC1B,UAAU,CAAC,KAAK,EAAE,CAAC;QACpB,CAAC;KACD,CAAC,CAAC,WAAW,CAAC,IAAI,mBAAmB,CAAC,SAAS,CAAC,CAAC,CAAC;IACnD,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,gBAAgB,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;QAC5D,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,OAAO,CAAC,CAAC;QAC5D,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC;QAC5C,OAAO,IAAI,MAAM,CAAC;QAClB,IAAI,OAAO,KAAK,GAAG,CAAC,MAAM,EAAE,CAAC;YAC5B,MAAM;QACP,CAAC;IACF,CAAC;IACD,IAAI,OAAO,KAAK,GAAG,CAAC,MAAM,EAAE,CAAC;QAC5B,MAAM,MAAM,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IACvC,CAAC;IACD,OAAO,OAAO,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decodes TIFF LZW (TIFF 6.0 §13) into `out`, stopping once it is full.
|
|
3
|
+
*
|
|
4
|
+
* Codes are 9 to 12 bits, most significant bit first, and widen one code early
|
|
5
|
+
* (at 511, 1023, 2047), as TIFF 6.0 specifies and libtiff writes. The pre-6.0
|
|
6
|
+
* variant libtiff still reads, least significant bit first and widening at 512,
|
|
7
|
+
* 1024, 2048, is recognised by its first code, a Clear written LSB-first (bytes
|
|
8
|
+
* `00` then one with its low bit set), as libtiff recognises it. A full table
|
|
9
|
+
* stops growing until the next Clear.
|
|
10
|
+
*
|
|
11
|
+
* Time linear in the output; memory one 4096-entry table.
|
|
12
|
+
*
|
|
13
|
+
* @returns The bytes written, fewer than `out.length` when the input ends (with
|
|
14
|
+
* or without an end-of-information code).
|
|
15
|
+
* @throws {RangeError} On a code past the next free one: corrupt data.
|
|
16
|
+
*/
|
|
17
|
+
export declare function decodeLzw_(input: Uint8Array, out: Uint8Array): number;
|
|
18
|
+
//# sourceMappingURL=_lzw.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_lzw.d.ts","sourceRoot":"","sources":["../../src/codec/_lzw.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,EAAE,GAAG,EAAE,UAAU,GAAG,MAAM,CAqGrE"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
const CLEAR_ = 256;
|
|
2
|
+
const END_ = 257;
|
|
3
|
+
const FIRST_ = 258;
|
|
4
|
+
const MAX_BITS_ = 12;
|
|
5
|
+
const TABLE_SIZE_ = 1 << MAX_BITS_;
|
|
6
|
+
/**
|
|
7
|
+
* Decodes TIFF LZW (TIFF 6.0 §13) into `out`, stopping once it is full.
|
|
8
|
+
*
|
|
9
|
+
* Codes are 9 to 12 bits, most significant bit first, and widen one code early
|
|
10
|
+
* (at 511, 1023, 2047), as TIFF 6.0 specifies and libtiff writes. The pre-6.0
|
|
11
|
+
* variant libtiff still reads, least significant bit first and widening at 512,
|
|
12
|
+
* 1024, 2048, is recognised by its first code, a Clear written LSB-first (bytes
|
|
13
|
+
* `00` then one with its low bit set), as libtiff recognises it. A full table
|
|
14
|
+
* stops growing until the next Clear.
|
|
15
|
+
*
|
|
16
|
+
* Time linear in the output; memory one 4096-entry table.
|
|
17
|
+
*
|
|
18
|
+
* @returns The bytes written, fewer than `out.length` when the input ends (with
|
|
19
|
+
* or without an end-of-information code).
|
|
20
|
+
* @throws {RangeError} On a code past the next free one: corrupt data.
|
|
21
|
+
*/
|
|
22
|
+
export function decodeLzw_(input, out) {
|
|
23
|
+
const oldStyle = input.length >= 2 && input[0] === 0 && (input[1] & 1) === 1;
|
|
24
|
+
const early = oldStyle ? 0 : 1;
|
|
25
|
+
const prefixes = new Uint16Array(TABLE_SIZE_);
|
|
26
|
+
const suffixes = new Uint8Array(TABLE_SIZE_);
|
|
27
|
+
const lengths = new Uint16Array(TABLE_SIZE_);
|
|
28
|
+
for (let code = 0; code < 256; code++) {
|
|
29
|
+
suffixes[code] = code;
|
|
30
|
+
lengths[code] = 1;
|
|
31
|
+
}
|
|
32
|
+
const capacity = out.length;
|
|
33
|
+
let read = 0;
|
|
34
|
+
let buffer = 0;
|
|
35
|
+
let bufferBits = 0;
|
|
36
|
+
let width = 9;
|
|
37
|
+
let next = FIRST_;
|
|
38
|
+
let previous = -1;
|
|
39
|
+
let written = 0;
|
|
40
|
+
while (written < capacity) {
|
|
41
|
+
while (bufferBits < width && read < input.length) {
|
|
42
|
+
const byte = input[read];
|
|
43
|
+
read++;
|
|
44
|
+
if (oldStyle) {
|
|
45
|
+
buffer |= byte << bufferBits;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
buffer = ((buffer & ((1 << bufferBits) - 1)) << 8) | byte;
|
|
49
|
+
}
|
|
50
|
+
bufferBits += 8;
|
|
51
|
+
}
|
|
52
|
+
if (bufferBits < width) {
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
let code;
|
|
56
|
+
if (oldStyle) {
|
|
57
|
+
code = buffer & ((1 << width) - 1);
|
|
58
|
+
buffer >>>= width;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
code = (buffer >>> (bufferBits - width)) & ((1 << width) - 1);
|
|
62
|
+
}
|
|
63
|
+
bufferBits -= width;
|
|
64
|
+
if (code === END_) {
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
if (code === CLEAR_) {
|
|
68
|
+
width = 9;
|
|
69
|
+
next = FIRST_;
|
|
70
|
+
previous = -1;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (previous === -1) {
|
|
74
|
+
if (code >= 256) {
|
|
75
|
+
throw new RangeError(`LZW code ${code} after a Clear`);
|
|
76
|
+
}
|
|
77
|
+
out[written] = code;
|
|
78
|
+
written++;
|
|
79
|
+
previous = code;
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
let first;
|
|
83
|
+
if (code < next) {
|
|
84
|
+
// The first byte of the string is the root of its prefix chain.
|
|
85
|
+
let root = code;
|
|
86
|
+
while (root >= 256) {
|
|
87
|
+
root = prefixes[root];
|
|
88
|
+
}
|
|
89
|
+
first = root;
|
|
90
|
+
written = writeString_(code, prefixes, suffixes, lengths, out, written);
|
|
91
|
+
}
|
|
92
|
+
else if (code === next && next < TABLE_SIZE_) {
|
|
93
|
+
let root = previous;
|
|
94
|
+
while (root >= 256) {
|
|
95
|
+
root = prefixes[root];
|
|
96
|
+
}
|
|
97
|
+
first = root;
|
|
98
|
+
written = writeString_(previous, prefixes, suffixes, lengths, out, written);
|
|
99
|
+
if (written < capacity) {
|
|
100
|
+
out[written] = first;
|
|
101
|
+
written++;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
throw new RangeError(`LZW code ${code} past the next free code ${next}`);
|
|
106
|
+
}
|
|
107
|
+
if (next < TABLE_SIZE_) {
|
|
108
|
+
prefixes[next] = previous;
|
|
109
|
+
suffixes[next] = first;
|
|
110
|
+
lengths[next] = lengths[previous] + 1;
|
|
111
|
+
next++;
|
|
112
|
+
if (next + early >= 1 << width && width < MAX_BITS_) {
|
|
113
|
+
width++;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
previous = code;
|
|
117
|
+
}
|
|
118
|
+
return written;
|
|
119
|
+
}
|
|
120
|
+
/** Writes the string of `code` at `written`, truncated to `out`'s end. */
|
|
121
|
+
function writeString_(code, prefixes, suffixes, lengths, out, written) {
|
|
122
|
+
const length = lengths[code];
|
|
123
|
+
let position = written + length - 1;
|
|
124
|
+
let current = code;
|
|
125
|
+
for (let index = 0; index < length; index++) {
|
|
126
|
+
if (position < out.length) {
|
|
127
|
+
out[position] = suffixes[current];
|
|
128
|
+
}
|
|
129
|
+
position--;
|
|
130
|
+
current = prefixes[current];
|
|
131
|
+
}
|
|
132
|
+
return Math.min(out.length, written + length);
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=_lzw.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_lzw.js","sourceRoot":"","sources":["../../src/codec/_lzw.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,GAAG,GAAG,CAAC;AACnB,MAAM,IAAI,GAAG,GAAG,CAAC;AACjB,MAAM,MAAM,GAAG,GAAG,CAAC;AACnB,MAAM,SAAS,GAAG,EAAE,CAAC;AACrB,MAAM,WAAW,GAAG,CAAC,IAAI,SAAS,CAAC;AAEnC;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,UAAU,CAAC,KAAiB,EAAE,GAAe;IAC5D,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,IAAI,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;IAC9E,MAAM,KAAK,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/B,MAAM,QAAQ,GAAG,IAAI,WAAW,CAAC,WAAW,CAAC,CAAC;IAC9C,MAAM,QAAQ,GAAG,IAAI,UAAU,CAAC,WAAW,CAAC,CAAC;IAC7C,MAAM,OAAO,GAAG,IAAI,WAAW,CAAC,WAAW,CAAC,CAAC;IAC7C,KAAK,IAAI,IAAI,GAAG,CAAC,EAAE,IAAI,GAAG,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC;QACvC,QAAQ,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;Q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ACpC,CAAC;QACD,QAAQ,EAAE,CAAC;QACX,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAE,CAAC;IAC9B,CAAC;IACD,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAAC,CAAC;AAC/C,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decodes PackBits (TIFF 6.0 §9) into `out`, stopping once it is full: a header
|
|
3
|
+
* byte `n` in 0–127 copies the next `n + 1` bytes, one in −127–−1 repeats the
|
|
4
|
+
* next byte `1 − n` times, and −128 is skipped.
|
|
5
|
+
*
|
|
6
|
+
* @returns The bytes written, fewer than `out.length` when the input ends or a
|
|
7
|
+
* run is cut short.
|
|
8
|
+
*/
|
|
9
|
+
export declare function decodePackBits_(input: Uint8Array, out: Uint8Array): number;
|
|
10
|
+
//# sourceMappingURL=_packbits.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_packbits.d.ts","sourceRoot":"","sources":["../../src/codec/_packbits.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,UAAU,EAAE,GAAG,EAAE,UAAU,GAAG,MAAM,CA2B1E"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decodes PackBits (TIFF 6.0 §9) into `out`, stopping once it is full: a header
|
|
3
|
+
* byte `n` in 0–127 copies the next `n + 1` bytes, one in −127–−1 repeats the
|
|
4
|
+
* next byte `1 − n` times, and −128 is skipped.
|
|
5
|
+
*
|
|
6
|
+
* @returns The bytes written, fewer than `out.length` when the input ends or a
|
|
7
|
+
* run is cut short.
|
|
8
|
+
*/
|
|
9
|
+
export function decodePackBits_(input, out) {
|
|
10
|
+
let read = 0;
|
|
11
|
+
let written = 0;
|
|
12
|
+
const capacity = out.length;
|
|
13
|
+
while (read < input.length && written < capacity) {
|
|
14
|
+
const header = input[read];
|
|
15
|
+
read++;
|
|
16
|
+
if (header < 128) {
|
|
17
|
+
const length = Math.min(header + 1, input.length - read, capacity - written);
|
|
18
|
+
out.set(input.subarray(read, read + length), written);
|
|
19
|
+
read += header + 1;
|
|
20
|
+
written += length;
|
|
21
|
+
}
|
|
22
|
+
else if (header > 128) {
|
|
23
|
+
if (read >= input.length) {
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
const length = Math.min(257 - header, capacity - written);
|
|
27
|
+
out.fill(input[read], written, written + length);
|
|
28
|
+
read++;
|
|
29
|
+
written += length;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return written;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=_packbits.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_packbits.js","sourceRoot":"","sources":["../../src/codec/_packbits.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAAC,KAAiB,EAAE,GAAe;IACjE,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,MAAM,QAAQ,GAAG,GAAG,CAAC,MAAM,CAAC;IAC5B,OAAO,IAAI,GAAG,KAAK,CAAC,MAAM,IAAI,OAAO,GAAG,QAAQ,EAAE,CAAC;QAClD,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAE,CAAC;QAC5B,IAAI,EAAE,CAAC;QACP,IAAI,MAAM,GAAG,GAAG,EAAE,CAAC;YAClB,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CACtB,MAAM,GAAG,CAAC,EACV,KAAK,CAAC,MAAM,GAAG,IAAI,EACnB,QAAQ,GAAG,OAAO,CAClB,CAAC;YACF,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC;YACtD,IAAI,IAAI,MAAM,GAAG,CAAC,CAAC;YACnB,OAAO,IAAI,MAAM,CAAC;QACnB,CAAC;aAAM,IAAI,MAAM,GAAG,GAAG,EAAE,CAAC;YACzB,IAAI,IAAI,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;gBAC1B,MAAM;YACP,CAAC;YACD,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,MAAM,EAAE,QAAQ,GAAG,OAAO,CAAC,CAAC;YAC1D,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAE,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAAC,CAAC;YAClD,IAAI,EAAE,CAAC;YACP,OAAO,IAAI,MAAM,CAAC;QACnB,CAAC;IACF,CAAC;IACD,OAAO,OAAO,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Undoes horizontal differencing (TIFF 6.0 §14) in place, row by row: each
|
|
3
|
+
* sample adds the same sample of the pixel before it, modulo its width. For 8-,
|
|
4
|
+
* 16-, 32- and 64-bit samples in the file's byte order; `stride` is the samples
|
|
5
|
+
* per pixel of the chunk (1 in a planar one).
|
|
6
|
+
*/
|
|
7
|
+
export declare function undoHorizontalDifferencing_(data: Uint8Array, rows: number, rowBytes: number, columns: number, stride: number, bits: number, littleEndian: boolean): void;
|
|
8
|
+
/**
|
|
9
|
+
* Undoes the floating-point predictor (Adobe Photoshop TIFF Technical Note 3)
|
|
10
|
+
* in place, row by row: the row's bytes are differenced as 8-bit samples with
|
|
11
|
+
* `stride`, then hold each value's bytes as planes, most significant first. The
|
|
12
|
+
* values come back in the file's byte order. `scratch` holds one row.
|
|
13
|
+
*/
|
|
14
|
+
export declare function undoFloatingPointPredictor_(data: Uint8Array, rows: number, rowBytes: number, columns: number, stride: number, bytesPerSample: number, littleEndian: boolean, scratch: Uint8Array): void;
|
|
15
|
+
//# sourceMappingURL=_predictor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_predictor.d.ts","sourceRoot":"","sources":["../../src/codec/_predictor.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAC1C,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,OAAO,GACnB,IAAI,CAkDN;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAC1C,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,MAAM,EACtB,YAAY,EAAE,OAAO,EACrB,OAAO,EAAE,UAAU,GACjB,IAAI,CAkBN"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Undoes horizontal differencing (TIFF 6.0 §14) in place, row by row: each
|
|
3
|
+
* sample adds the same sample of the pixel before it, modulo its width. For 8-,
|
|
4
|
+
* 16-, 32- and 64-bit samples in the file's byte order; `stride` is the samples
|
|
5
|
+
* per pixel of the chunk (1 in a planar one).
|
|
6
|
+
*/
|
|
7
|
+
export function undoHorizontalDifferencing_(data, rows, rowBytes, columns, stride, bits, littleEndian) {
|
|
8
|
+
const values = columns * stride;
|
|
9
|
+
const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
10
|
+
for (let row = 0; row < rows; row++) {
|
|
11
|
+
const start = row * rowBytes;
|
|
12
|
+
switch (bits) {
|
|
13
|
+
case 8:
|
|
14
|
+
for (let index = stride; index < values; index++) {
|
|
15
|
+
data[start + index] =
|
|
16
|
+
(data[start + index] + data[start + index - stride]) & 0xff;
|
|
17
|
+
}
|
|
18
|
+
break;
|
|
19
|
+
case 16:
|
|
20
|
+
for (let index = stride; index < values; index++) {
|
|
21
|
+
const at = start + index * 2;
|
|
22
|
+
view.setUint16(at, view.getUint16(at, littleEndian) +
|
|
23
|
+
view.getUint16(at - stride * 2, littleEndian), littleEndian);
|
|
24
|
+
}
|
|
25
|
+
break;
|
|
26
|
+
case 32:
|
|
27
|
+
for (let index = stride; index < values; index++) {
|
|
28
|
+
const at = start + index * 4;
|
|
29
|
+
view.setUint32(at, (view.getUint32(at, littleEndian) +
|
|
30
|
+
view.getUint32(at - stride * 4, littleEndian)) >>>
|
|
31
|
+
0, littleEndian);
|
|
32
|
+
}
|
|
33
|
+
break;
|
|
34
|
+
default:
|
|
35
|
+
for (let index = stride; index < values; index++) {
|
|
36
|
+
const at = start + index * 8;
|
|
37
|
+
view.setBigUint64(at, BigInt.asUintN(64, view.getBigUint64(at, littleEndian) +
|
|
38
|
+
view.getBigUint64(at - stride * 8, littleEndian)), littleEndian);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Undoes the floating-point predictor (Adobe Photoshop TIFF Technical Note 3)
|
|
45
|
+
* in place, row by row: the row's bytes are differenced as 8-bit samples with
|
|
46
|
+
* `stride`, then hold each value's bytes as planes, most significant first. The
|
|
47
|
+
* values come back in the file's byte order. `scratch` holds one row.
|
|
48
|
+
*/
|
|
49
|
+
export function undoFloatingPointPredictor_(data, rows, rowBytes, columns, stride, bytesPerSample, littleEndian, scratch) {
|
|
50
|
+
const values = columns * stride;
|
|
51
|
+
const length = values * bytesPerSample;
|
|
52
|
+
for (let row = 0; row < rows; row++) {
|
|
53
|
+
const start = row * rowBytes;
|
|
54
|
+
for (let index = start + stride; index < start + length; index++) {
|
|
55
|
+
data[index] = (data[index] + data[index - stride]) & 0xff;
|
|
56
|
+
}
|
|
57
|
+
scratch.set(data.subarray(start, start + length));
|
|
58
|
+
for (let value = 0; value < values; value++) {
|
|
59
|
+
const at = start + value * bytesPerSample;
|
|
60
|
+
for (let plane = 0; plane < bytesPerSample; plane++) {
|
|
61
|
+
const byte = scratch[plane * values + value];
|
|
62
|
+
data[littleEndian ? at + bytesPerSample - 1 - plane : at + plane] =
|
|
63
|
+
byte;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=_predictor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_predictor.js","sourceRoot":"","sources":["../../src/codec/_predictor.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,2BAA2B,CAC1C,IAAgB,EAChB,IAAY,EACZ,QAAgB,EAChB,OAAe,EACf,MAAc,EACd,IAAY,EACZ,YAAqB;IAErB,MAAM,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;IAChC,MAAM,IAAI,GAAG,IAAI,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IACzE,KAAK,IAAI,GAAG,GAAG,CAAC,EAAE,GAAG,GAAG,IAAI,EAAE,GAAG,EAAE,EAAE,CAAC;QACrC,MAAM,KAAK,GAAG,GAAG,GAAG,QAAQ,CAAC;QAC7B,QAAQ,IAAI,EAAE,CAAC;YACd,KAAK,CAAC;gBACL,KAAK,IAAI,KAAK,GAAG,MAAM,EAAE,KAAK,GAAG,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;oBAClD,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;wBAClB,CAAC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAE,GAAG,IAAI,CAAC,KAAK,GAAG,KAAK,GAAG,MAAM,CAAE,CAAC,GAAG,IAAI,CAAC;gBAChE,CAAC;gBACD,MAAM;YACP,KAAK,EAAE;gBACN,KAAK,IAAI,KAAK,GAAG,MAAM,EAAE,KAAK,GAAG,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;oBAClD,MAAM,EAAE,GAAG,KAAK,GAAG,KAAK,GAAG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@link TiffDecoder} is given: one stored strip or tile. */
|
|
4
|
+
export type TiffDecoderInput = {
|
|
5
|
+
/**
|
|
6
|
+
* The stored bytes, most significant bit first: a `FillOrder` 2 chunk has its
|
|
7
|
+
* bits reversed already.
|
|
8
|
+
*/
|
|
9
|
+
readonly bytes: Uint8Array<ArrayBuffer>;
|
|
10
|
+
/** The image's `Compression`. */
|
|
11
|
+
readonly compression: number;
|
|
12
|
+
/** Columns of the chunk: the tile width, or the image width for a strip. */
|
|
13
|
+
readonly width: number;
|
|
14
|
+
/** Rows of the chunk: the tile height, or the rows of this strip. */
|
|
15
|
+
readonly height: number;
|
|
16
|
+
/** Samples per pixel in the chunk: 1 in a planar image. */
|
|
17
|
+
readonly samplesPerPixel: number;
|
|
18
|
+
/** Bits of each of the chunk's samples. */
|
|
19
|
+
readonly bitsPerSample: readonly number[];
|
|
20
|
+
/** Format of each of the chunk's samples. */
|
|
21
|
+
readonly sampleFormat: readonly number[];
|
|
22
|
+
/** The file's byte order, which the decoded bytes are in. */
|
|
23
|
+
readonly littleEndian: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Bytes the decoded chunk holds: `height` rows of `width × samplesPerPixel`
|
|
26
|
+
* samples, each row padded to a whole byte.
|
|
27
|
+
*/
|
|
28
|
+
readonly byteLength: number;
|
|
29
|
+
/**
|
|
30
|
+
* The image, for the tags a codec reads: `JPEGTables`, `LercParameters`,
|
|
31
|
+
* `PhotometricInterpretation`, `YCbCrSubsampling`.
|
|
32
|
+
*/
|
|
33
|
+
readonly image: TiffImage;
|
|
34
|
+
readonly signal: AbortSignal | undefined;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Decodes one stored chunk to the bytes an uncompressed chunk of the same image
|
|
38
|
+
* would hold, in the file's byte order (a decoder whose codec gives native
|
|
39
|
+
* values swaps them for a big-endian file), before any predictor: the reader
|
|
40
|
+
* undoes `Predictor` after it. At least {@link TiffDecoderInput.byteLength}
|
|
41
|
+
* bytes; any more are ignored.
|
|
42
|
+
*/
|
|
43
|
+
export type TiffDecoder = MaybeAsyncCallable<[
|
|
44
|
+
input: TiffDecoderInput
|
|
45
|
+
], Uint8Array>;
|
|
46
|
+
/**
|
|
47
|
+
* Decoders by `Compression` value, for the codecs not built in (JPEG 7, ZSTD
|
|
48
|
+
* 50000, LERC 34887, WebP 50001, JPEG XL 50002, CCITT 2–4, …) or in place of a
|
|
49
|
+
* built-in one.
|
|
50
|
+
*/
|
|
51
|
+
export type TiffDecoders = {
|
|
52
|
+
readonly [compression: number]: TiffDecoder | undefined;
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=tiff-decoder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tiff-decoder.d.ts","sourceRoot":"","sources":["../../src/codec/tiff-decoder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAEvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEtD,qEAAqE;AACrE,MAAM,MAAM,gBAAgB,GAAG;IAC9B;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC;IACxC,iCAAiC;IACjC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,4EAA4E;IAC5E,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,qEAAqE;IACrE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,2DAA2D;IAC3D,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,2CAA2C;IAC3C,QAAQ,CAAC,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1C,6CAA6C;IAC7C,QAAQ,CAAC,YAAY,EAAE,SAAS,MAAM,EAAE,CAAC;IACzC,6DAA6D;IAC7D,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;IAC/B;;;OAGG;IACH,QAAQ,CAAC,UAAU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