cog-tiler-wasm 0.3.1 → 0.3.2

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/cog-tiler.js CHANGED
@@ -275,6 +275,11 @@ async function makeReader(source) {
275
275
  export async function openCog(source) {
276
276
  await init();
277
277
  const { range, openTiff, label } = await makeReader(source);
278
+ // whitebox-wasm's streaming decoder currently materializes numeric tile
279
+ // samples as little-endian. Detect Motorola TIFFs up front so their pixels
280
+ // can be decoded by geotiff.js, which honors the header byte order.
281
+ const byteOrder = await range(0, 1);
282
+ const bigEndian = byteOrder[0] === 0x4d && byteOrder[1] === 0x4d;
278
283
  // Parse the COG header; grow the prefix and retry for large COGs whose IFDs
279
284
  // exceed 64 KB (many overviews / huge tile-offset arrays).
280
285
  let stream;
@@ -286,7 +291,7 @@ export async function openCog(source) {
286
291
  if (len >= 1 << 25) throw e; // give up past ~32 MB
287
292
  }
288
293
  }
289
- const gt = stream.geo_transform(); // [x0, px_w, rot, y0, rot, px_h]
294
+ let gt = stream.geo_transform(); // [x0, px_w, rot, y0, rot, px_h]
290
295
  const levels = JSON.parse(stream.levels_json());
291
296
  if (!Array.isArray(levels) || levels.length === 0) {
292
297
  throw new Error("levels_json() returned no levels");
@@ -297,12 +302,27 @@ export async function openCog(source) {
297
302
  // through geotiff.js instead (see _assembleWindow / point).
298
303
  const multiBand = levels[0].bands > 1;
299
304
  let tiff = null, img = null, planar = false;
300
- if (stream.epsg !== 3857 || multiBand) {
305
+ if (stream.epsg !== 3857 || multiBand || bigEndian) {
301
306
  tiff = await openTiff();
302
307
  img = await tiff.getImage();
303
308
  planar = multiBand && (await readTiffTag(img, "PlanarConfiguration")) === 2;
309
+ if (bigEndian && gt.length !== 6) {
310
+ const [x, y] = img.getOrigin();
311
+ const [pixelWidth, pixelHeight] = img.getResolution();
312
+ gt = [x, pixelWidth, 0, y, 0, -pixelHeight];
313
+ }
304
314
  }
305
- const base = { url: label, range, stream, levels, gt, nodata: stream.nodata, tiff, planar };
315
+ const base = {
316
+ url: label,
317
+ range,
318
+ stream,
319
+ levels,
320
+ gt,
321
+ nodata: stream.nodata,
322
+ tiff,
323
+ planar,
324
+ bigEndian,
325
+ };
306
326
 
307
327
  if (stream.epsg === 3857) {
308
328
  return new CogSource({
@@ -410,10 +430,11 @@ export class CogSource {
410
430
 
411
431
  // Fetch + decode band `band` (0-based) over a level pixel window into a
412
432
  // row-major buffer. Chunky COGs go through whitebox (cached, NaN for gaps);
413
- // planar (INTERLEAVE=BAND) COGs are read per-band via geotiff.js, which
414
- // whitebox's chunky-only streaming decoder can't address.
433
+ // Planar (INTERLEAVE=BAND) and big-endian COGs are read per-band via
434
+ // geotiff.js. Whitebox's streaming decoder cannot address planar tiles and
435
+ // currently interprets multi-byte tile samples as little-endian.
415
436
  async _assembleWindow(level, x, y, w, h, band = 0) {
416
- if (this.planar) {
437
+ if (this.planar || this.bigEndian) {
417
438
  const img = await this._tiffImage(level);
418
439
  const rasters = await img.readRasters({ window: [x, y, x + w, y + h], samples: [band] });
419
440
  return rasters[0]; // typed array, length w*h, row-major
Binary file
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "Qiusheng Wu <giswqs@gmail.com>"
6
6
  ],
7
7
  "description": "Serverless Cloud Optimized GeoTIFF (COG) dynamic tiling in WebAssembly. TiTiler-style XYZ tiles, no backend.",
8
- "version": "0.3.1",
8
+ "version": "0.3.2",
9
9
  "license": "MIT",
10
10
  "repository": {
11
11
  "type": "git",