Skip to content

Commit 1bc0b09

Browse files
authored
chore: Update code for new upstream SamplesPerPixel typing (#245)
Code cleanups to reflect new `SamplesPerPixel` type from blacha/cogeotiff#1394 released in https://github.com/blacha/cogeotiff/releases/tag/core-v9.2.0
1 parent 9d133b8 commit 1bc0b09

4 files changed

Lines changed: 6 additions & 9 deletions

File tree

packages/geotiff/src/fetch.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@ export async function fetchTile(
5555
translation(x * self.tileWidth, y * self.tileHeight),
5656
);
5757

58-
// https://github.com/blacha/cogeotiff/pull/1394
59-
const samplesPerPixel =
60-
(self.image.value(TiffTag.SamplesPerPixel) as number) ?? 1;
58+
const samplesPerPixel = self.image.value(TiffTag.SamplesPerPixel) ?? 1;
6159

6260
const decodedPixels = await decode(bytes, compression, {
6361
sampleFormat,

packages/geotiff/src/geotiff.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ export class GeoTIFF {
221221

222222
/** Number of bands (samples per pixel). */
223223
get count(): number {
224-
return (this.image.value(TiffTag.SamplesPerPixel) as number) ?? 1;
224+
return this.image.value(TiffTag.SamplesPerPixel) ?? 1;
225225
}
226226

227227
/** Bounding box [minX, minY, maxX, maxY] in the CRS. */

packages/geotiff/src/ifd.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export interface CachedTags {
99
nodata: number | null;
1010
photometric: TiffTagType[TiffTag.Photometric];
1111
sampleFormat: TiffTagType[TiffTag.SampleFormat];
12-
samplesPerPixel: number; // TiffTagType[TiffTag.SamplesPerPixel];
12+
samplesPerPixel: TiffTagType[TiffTag.SamplesPerPixel];
1313
}
1414

1515
/** Pre-fetch TIFF tags for easier visualization. */
@@ -52,8 +52,7 @@ export async function prefetchTags(image: TiffImage): Promise<CachedTags> {
5252
// Uint is the default sample format according to the spec
5353
// https://web.archive.org/web/20240329145340/https://www.awaresystems.be/imaging/tiff/tifftags/sampleformat.html
5454
sampleFormat: sampleFormat ?? [SampleFormat.Uint],
55-
// Waiting for release with https://github.com/blacha/cogeotiff/pull/1394
56-
samplesPerPixel: samplesPerPixel as number,
55+
samplesPerPixel,
5756
};
5857
}
5958

packages/geotiff/tests/decode.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe("decode", () => {
1414
const sampleFormat =
1515
(image.value(TiffTag.SampleFormat) as SampleFormat[] | null)?.[0] ??
1616
SampleFormat.Uint;
17-
const samplesPerPixel = image.value(TiffTag.SamplesPerPixel) as number;
17+
const samplesPerPixel = image.value(TiffTag.SamplesPerPixel) ?? 1;
1818

1919
const result = await decode(tile!.bytes, tile!.compression, {
2020
sampleFormat,
@@ -43,7 +43,7 @@ describe("decode", () => {
4343
const sampleFormat =
4444
(image.value(TiffTag.SampleFormat) as SampleFormat[] | null)?.[0] ??
4545
SampleFormat.Uint;
46-
const samplesPerPixel = image.value(TiffTag.SamplesPerPixel) as number;
46+
const samplesPerPixel = image.value(TiffTag.SamplesPerPixel) ?? 1;
4747

4848
const result = await decode(tile!.bytes, tile!.compression, {
4949
sampleFormat,

0 commit comments

Comments
 (0)