@cogeotiff/core 7.2.0 → 8.0.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.
Files changed (147) hide show
  1. package/CHANGELOG.md +3 -500
  2. package/README.md +28 -10
  3. package/build/__benchmark__/cog.read.benchmark.d.ts +0 -1
  4. package/build/__benchmark__/cog.read.benchmark.js +6 -4
  5. package/build/__benchmark__/cog.read.benchmark.js.map +1 -0
  6. package/build/__benchmark__/source.file.d.ts +9 -0
  7. package/build/__benchmark__/source.file.js +29 -0
  8. package/build/__benchmark__/source.file.js.map +1 -0
  9. package/build/__benchmark__/source.memory.d.ts +9 -0
  10. package/build/__benchmark__/source.memory.js +32 -0
  11. package/build/__benchmark__/source.memory.js.map +1 -0
  12. package/build/__test__/cog.image.test.d.ts +1 -2
  13. package/build/__test__/cog.image.test.js +82 -90
  14. package/build/__test__/cog.image.test.js.map +1 -0
  15. package/build/__test__/cog.read.test.d.ts +1 -2
  16. package/build/__test__/cog.read.test.js +37 -55
  17. package/build/__test__/cog.read.test.js.map +1 -0
  18. package/build/__test__/example.d.ts +1 -0
  19. package/build/__test__/example.js +27 -0
  20. package/build/__test__/example.js.map +1 -0
  21. package/build/cog.tiff.d.ts +22 -28
  22. package/build/cog.tiff.image.d.ts +16 -28
  23. package/build/cog.tiff.image.js +147 -101
  24. package/build/cog.tiff.image.js.map +1 -0
  25. package/build/cog.tiff.js +141 -97
  26. package/build/cog.tiff.js.map +1 -0
  27. package/build/const/index.d.ts +1 -2
  28. package/build/const/index.js +2 -2
  29. package/build/const/index.js.map +1 -0
  30. package/build/const/tiff.endian.d.ts +0 -1
  31. package/build/const/tiff.endian.js +1 -1
  32. package/build/const/tiff.endian.js.map +1 -0
  33. package/build/const/tiff.mime.d.ts +10 -11
  34. package/build/const/tiff.mime.js +22 -22
  35. package/build/const/tiff.mime.js.map +1 -0
  36. package/build/const/tiff.tag.id.d.ts +5 -5
  37. package/build/const/tiff.tag.id.js +155 -154
  38. package/build/const/tiff.tag.id.js.map +1 -0
  39. package/build/const/tiff.tag.value.d.ts +15 -16
  40. package/build/const/tiff.tag.value.js +16 -16
  41. package/build/const/tiff.tag.value.js.map +1 -0
  42. package/build/const/tiff.version.d.ts +0 -1
  43. package/build/const/tiff.version.js +1 -1
  44. package/build/const/tiff.version.js.map +1 -0
  45. package/build/index.d.ts +11 -6
  46. package/build/index.js +9 -5
  47. package/build/index.js.map +1 -0
  48. package/build/read/data.view.offset.d.ts +15 -0
  49. package/build/read/data.view.offset.js +19 -0
  50. package/build/read/data.view.offset.js.map +1 -0
  51. package/build/read/tiff.gdal.d.ts +9 -12
  52. package/build/read/tiff.gdal.js +22 -17
  53. package/build/read/tiff.gdal.js.map +1 -0
  54. package/build/read/tiff.ifd.config.d.ts +6 -4
  55. package/build/read/tiff.ifd.config.js +2 -2
  56. package/build/read/tiff.ifd.config.js.map +1 -0
  57. package/build/read/tiff.tag.d.ts +37 -20
  58. package/build/read/tiff.tag.factory.d.ts +16 -0
  59. package/build/read/tiff.tag.factory.js +130 -0
  60. package/build/read/tiff.tag.factory.js.map +1 -0
  61. package/build/read/tiff.tag.js +2 -37
  62. package/build/read/tiff.tag.js.map +1 -0
  63. package/build/read/tiff.value.reader.d.ts +2 -6
  64. package/build/read/tiff.value.reader.js +16 -54
  65. package/build/read/tiff.value.reader.js.map +1 -0
  66. package/build/source.d.ts +5 -0
  67. package/build/source.js +2 -0
  68. package/build/source.js.map +1 -0
  69. package/build/util/bytes.d.ts +17 -0
  70. package/build/util/bytes.js +42 -0
  71. package/build/util/bytes.js.map +1 -0
  72. package/build/util/util.hex.d.ts +2 -3
  73. package/build/util/util.hex.js +4 -5
  74. package/build/util/util.hex.js.map +1 -0
  75. package/build/vector.d.ts +0 -1
  76. package/build/vector.js +1 -1
  77. package/build/vector.js.map +1 -0
  78. package/package.json +25 -30
  79. package/src/__benchmark__/cog.read.benchmark.ts +12 -10
  80. package/src/__benchmark__/source.file.ts +23 -0
  81. package/src/__benchmark__/source.memory.ts +23 -0
  82. package/src/__test__/cog.image.test.ts +188 -197
  83. package/src/__test__/cog.read.test.ts +50 -72
  84. package/src/__test__/example.ts +31 -0
  85. package/src/cog.tiff.image.ts +456 -448
  86. package/src/cog.tiff.ts +143 -146
  87. package/src/const/index.ts +1 -1
  88. package/src/const/tiff.endian.ts +2 -2
  89. package/src/const/tiff.mime.ts +21 -21
  90. package/src/const/tiff.tag.id.ts +159 -158
  91. package/src/const/tiff.tag.value.ts +16 -16
  92. package/src/const/tiff.version.ts +11 -11
  93. package/src/index.ts +11 -5
  94. package/src/read/data.view.offset.ts +23 -0
  95. package/src/read/tiff.gdal.ts +61 -63
  96. package/src/read/tiff.ifd.config.ts +35 -31
  97. package/src/read/tiff.tag.factory.ts +163 -0
  98. package/src/read/tiff.tag.ts +38 -39
  99. package/src/read/tiff.value.reader.ts +25 -73
  100. package/src/source.ts +5 -0
  101. package/src/util/bytes.ts +44 -0
  102. package/src/util/util.hex.ts +5 -7
  103. package/src/vector.ts +5 -5
  104. package/tsconfig.json +8 -10
  105. package/build/__benchmark__/cog.read.benchmark.d.ts.map +0 -1
  106. package/build/__test__/cog.image.test.d.ts.map +0 -1
  107. package/build/__test__/cog.read.test.d.ts.map +0 -1
  108. package/build/cog.tiff.d.ts.map +0 -1
  109. package/build/cog.tiff.image.d.ts.map +0 -1
  110. package/build/const/index.d.ts.map +0 -1
  111. package/build/const/tiff.endian.d.ts.map +0 -1
  112. package/build/const/tiff.mime.d.ts.map +0 -1
  113. package/build/const/tiff.tag.id.d.ts.map +0 -1
  114. package/build/const/tiff.tag.value.d.ts.map +0 -1
  115. package/build/const/tiff.version.d.ts.map +0 -1
  116. package/build/index.d.ts.map +0 -1
  117. package/build/read/tag/__test__/tag.test.d.ts +0 -2
  118. package/build/read/tag/__test__/tag.test.d.ts.map +0 -1
  119. package/build/read/tag/__test__/tag.test.js +0 -23
  120. package/build/read/tag/tiff.tag.base.d.ts +0 -55
  121. package/build/read/tag/tiff.tag.base.d.ts.map +0 -1
  122. package/build/read/tag/tiff.tag.base.js +0 -79
  123. package/build/read/tag/tiff.tag.lazy.d.ts +0 -7
  124. package/build/read/tag/tiff.tag.lazy.d.ts.map +0 -1
  125. package/build/read/tag/tiff.tag.lazy.js +0 -18
  126. package/build/read/tag/tiff.tag.offset.d.ts +0 -21
  127. package/build/read/tag/tiff.tag.offset.d.ts.map +0 -1
  128. package/build/read/tag/tiff.tag.offset.js +0 -54
  129. package/build/read/tag/tiff.tag.static.d.ts +0 -8
  130. package/build/read/tag/tiff.tag.static.d.ts.map +0 -1
  131. package/build/read/tag/tiff.tag.static.js +0 -17
  132. package/build/read/tiff.gdal.d.ts.map +0 -1
  133. package/build/read/tiff.ifd.config.d.ts.map +0 -1
  134. package/build/read/tiff.tag.d.ts.map +0 -1
  135. package/build/read/tiff.value.reader.d.ts.map +0 -1
  136. package/build/source/cog.source.view.d.ts +0 -33
  137. package/build/source/cog.source.view.d.ts.map +0 -1
  138. package/build/source/cog.source.view.js +0 -65
  139. package/build/util/util.hex.d.ts.map +0 -1
  140. package/build/vector.d.ts.map +0 -1
  141. package/src/@types/ieee754.d.ts +0 -18
  142. package/src/read/tag/__test__/tag.test.ts +0 -27
  143. package/src/read/tag/tiff.tag.base.ts +0 -126
  144. package/src/read/tag/tiff.tag.lazy.ts +0 -17
  145. package/src/read/tag/tiff.tag.offset.ts +0 -61
  146. package/src/read/tag/tiff.tag.static.ts +0 -15
  147. package/src/source/cog.source.view.ts +0 -77
@@ -1,90 +1,68 @@
1
- import o from 'ospec';
2
- import * as path from 'path';
3
- import 'source-map-support/register.js';
4
-
1
+ import assert from 'node:assert';
2
+ import { describe, it } from 'node:test';
5
3
  import { CogTiff } from '../cog.tiff.js';
6
- import { TiffVersion } from '../const/tiff.version.js';
7
4
  import { TiffMimeType } from '../const/tiff.mime.js';
8
- import { TestFileChunkSource } from '@chunkd/core/build/__test__/chunk.source.fake.js';
9
- import { fileURLToPath } from 'url';
10
-
11
- const __dirname = fileURLToPath(import.meta.url);
12
-
13
- o.spec('CogRead', () => {
14
- // TODO this does not load 100% yet
15
- // o('should read big endian', async () => {
16
- // const source = new TestFileChunkSource(path.join(__dirname, '../../../test/data/be_cog.tif'))
17
- // const tif = new CogTif(source);
18
-
19
- // await tif.init();
5
+ import { TestFileSource } from '../__benchmark__/source.file.js';
6
+ import { TiffVersion } from '../const/tiff.version.js';
20
7
 
21
- // o(source.isLittleEndian).equals(false);
22
- // o(source.version).equals(TiffVersion.Tiff);
23
- // o(tif.images.length).equals(5)
24
- // const [firstTif] = tif.images;
25
- // o(firstTif.isTiled()).equals(true);
26
- //
27
- // // o(firstTif.compression).equals('image/jpeg')
28
- // })
8
+ function validate(tif: CogTiff): void {
9
+ assert.equal(tif.images.length, 5);
29
10
 
30
- function validate(tif: CogTiff): void {
31
- o(tif.images.length).equals(5);
11
+ const [firstTif] = tif.images;
12
+ assert.equal(firstTif.isTiled(), true);
13
+ assert.deepEqual(firstTif.tileSize, { width: 256, height: 256 });
14
+ assert.deepEqual(firstTif.size, { width: 64, height: 64 });
15
+ }
32
16
 
33
- const [firstTif] = tif.images;
34
- o(firstTif.isTiled()).equals(true);
35
- o(firstTif.tileSize).deepEquals({ width: 256, height: 256 });
36
- o(firstTif.size).deepEquals({ width: 64, height: 64 });
37
- }
17
+ describe('CogRead', () => {
18
+ // TODO this does not load 100% yet
19
+ // it('should read big endian', async () => {
20
+ // const source = new TestFileSource(new URL('../../data/big_cog.tiff', import.meta.url));
21
+ // const tiff = new CogTiff(source);
38
22
 
39
- o('should read big tiff', async () => {
40
- const source = new TestFileChunkSource(path.join(__dirname, '../../../data/big_cog.tif'));
41
- const tiff = new CogTiff(source);
23
+ // await tiff.init();
42
24
 
43
- await tiff.init();
25
+ // assert.equal(tiff.isLittleEndian, false);
26
+ // assert.equal(tiff.version, TiffVersion.BigTiff);
27
+ // validate(tiff);
28
+ // });
44
29
 
45
- o(source.isLittleEndian).equals(true);
46
- o(tiff.version).equals(TiffVersion.BigTiff);
47
- validate(tiff);
48
- });
30
+ it('should read big tiff', async () => {
31
+ const source = new TestFileSource(new URL('../../data/big_cog.tiff', import.meta.url));
32
+ const tiff = new CogTiff(source);
49
33
 
50
- o('should read tiff', async () => {
51
- const source = new TestFileChunkSource(path.join(__dirname, '../../../data/cog.tif'));
52
- const tiff = new CogTiff(source);
34
+ await tiff.init();
53
35
 
54
- await tiff.init();
36
+ assert.equal(tiff.isLittleEndian, true);
37
+ assert.equal(tiff.version, TiffVersion.BigTiff);
38
+ validate(tiff);
39
+ });
55
40
 
56
- o(source.isLittleEndian).equals(true);
57
- o(tiff.version).equals(TiffVersion.Tiff);
58
- validate(tiff);
41
+ it('should read tiff', async () => {
42
+ const source = new TestFileSource(new URL('../../data/cog.tiff', import.meta.url));
43
+ const tiff = new CogTiff(source);
59
44
 
60
- const [firstTif] = tiff.images;
61
- o(firstTif.compression).equals(TiffMimeType.JPEG);
62
- });
45
+ await tiff.init();
63
46
 
64
- o('should allow multiple init', async () => {
65
- const source = new TestFileChunkSource(path.join(__dirname, '../../../data/cog.tif'));
66
- const tiff = new CogTiff(source);
47
+ assert.equal(tiff.isLittleEndian, true);
48
+ assert.equal(tiff.version, TiffVersion.Tiff);
49
+ validate(tiff);
67
50
 
68
- o(tiff.isInitialized).equals(false);
69
- await tiff.init();
70
- o(tiff.isInitialized).equals(true);
71
- o(tiff.images.length).equals(5);
51
+ const [firstTif] = tiff.images;
52
+ assert.equal(firstTif.compression, TiffMimeType.Jpeg);
53
+ });
72
54
 
73
- o(tiff.isInitialized).equals(true);
74
- await tiff.init();
75
- o(tiff.images.length).equals(5);
76
- });
55
+ it('should allow multiple init', async () => {
56
+ const source = new TestFileSource(new URL('../../data/cog.tiff', import.meta.url));
57
+ const tiff = new CogTiff(source);
77
58
 
78
- o('should close a source', async () => {
79
- const source = new TestFileChunkSource(path.join(__dirname, '../../../data/cog.tif'));
80
- const tiff = new CogTiff(source);
81
- // Should not close if there is no close
82
- source.close = undefined;
83
- await tiff.close();
59
+ assert.equal(tiff.isInitialized, false);
60
+ await tiff.init();
61
+ assert.equal(tiff.isInitialized, true);
62
+ assert.equal(tiff.images.length, 5);
84
63
 
85
- const closeSpy = o.spy(() => Promise.resolve());
86
- source.close = closeSpy;
87
- await tiff.close();
88
- o(closeSpy.callCount).equals(1);
89
- });
64
+ assert.equal(tiff.isInitialized, true);
65
+ await tiff.init();
66
+ assert.equal(tiff.images.length, 5);
67
+ });
90
68
  });
@@ -0,0 +1,31 @@
1
+ import { SourceHttp } from '@chunkd/source-http';
2
+ import { CogTiff } from '../index.js';
3
+
4
+ async function main(): Promise<void> {
5
+ const source = new SourceHttp('https://example.com/cog.tif');
6
+ const tiff = await CogTiff.create(source);
7
+
8
+ /** Load a specific tile from a specific image */
9
+ const tile = await tiff.images[5].getTile(2, 2);
10
+ if (tile != null) {
11
+ tile.bytes; // Raw image buffer or null if tile doesn't exist
12
+ }
13
+
14
+ /** Load the 5th image in the Tiff */
15
+ const img = tiff.images[5];
16
+ if (img.isTiled()) {
17
+ /** Load tile x:10 y:10 */
18
+ const tile = await img.getTile(10, 10);
19
+ if (tile != null) {
20
+ tile.mimeType; // image/jpeg
21
+ tile.bytes; // Raw image buffer
22
+ }
23
+ }
24
+
25
+ /** Get the origin point of the tiff */
26
+ img.origin;
27
+ /** Bounding box of the tiff */
28
+ img.bbox;
29
+ }
30
+
31
+ main();