Skip to content

Commit

Permalink
feat!: rename all type from CogTiff to just Tiff (#1227)
Browse files Browse the repository at this point in the history
This library is used a log with tiffs that are not COGs so makes sense
to update the types/docs to explain that.
  • Loading branch information
blacha authored Nov 26, 2023
1 parent 049e0bc commit 872263b
Show file tree
Hide file tree
Showing 16 changed files with 76 additions and 80 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Load a COG from a URL using `fetch`
import { SourceHttp } from '@chunkd/source-http';

const source = new SourceHttp('https://example.com/cog.tif');
const cog = await CogTiff.create(source);
const cog = await Tiff.create(source);

const img = cog.images[0];
if (img.isTiled()) throw new Error('Tiff is not tiled');
Expand Down
8 changes: 4 additions & 4 deletions packages/cli/src/commands/dump.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { basename } from 'node:path';
import { pathToFileURL } from 'node:url';

import { fsa } from '@chunkd/fs';
import { CogTiff, TiffMimeType } from '@cogeotiff/core';
import { Tiff, TiffMimeType } from '@cogeotiff/core';
import { log } from '@linzjs/tracing';
import { command, number, option, optional, restPositionals } from 'cmd-ts';
import pLimit from 'p-limit';
Expand Down Expand Up @@ -59,7 +59,7 @@ export const commandDump = command({
if (path == null) continue;
if (path.protocol === 's3:') await ensureS3fs();
const source = fsa.source(path);
const tiff = await new CogTiff(source).init();
const tiff = await new Tiff(source).init();
const img = tiff.images[args.image];
if (!img.isTiled()) throw Error(`Tiff: ${path.href} file is not tiled.`);
const output = new URL(`${basename(path.href)}-i${args.image}/`, args.output ?? cwd);
Expand All @@ -71,7 +71,7 @@ export const commandDump = command({
},
});

async function dumpBounds(tiff: CogTiff, target: URL, index: number): Promise<void> {
async function dumpBounds(tiff: Tiff, target: URL, index: number): Promise<void> {
const img = tiff.images[index];
if (!img.isTiled() || !img.isGeoLocated) return;

Expand Down Expand Up @@ -115,7 +115,7 @@ async function dumpBounds(tiff: CogTiff, target: URL, index: number): Promise<vo
await fs.writeFile(new URL(`i${index}.bounds.geojson`, target), JSON.stringify(featureCollection, null, 2));
}

async function dumpTiles(tiff: CogTiff, target: URL, index: number, logger: typeof log): Promise<number> {
async function dumpTiles(tiff: Tiff, target: URL, index: number, logger: typeof log): Promise<number> {
const promises: Promise<string | null>[] = [];
const img = tiff.images[index];
if (!img.isTiled()) return 0;
Expand Down
10 changes: 5 additions & 5 deletions packages/cli/src/commands/info.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { fsa } from '@chunkd/fs';
import {
CogTiff,
Tag,
TagOffset,
Tiff,
TiffImage,
TiffTag,
TiffTagGeo,
TiffTagGeoValueLookup,
TiffTagValueLookup,
TiffTagValueType,
TiffVersion,
} from '@cogeotiff/core';
import { CogTiffImage } from '@cogeotiff/core/src/cog.tiff.image.js';
import c from 'ansi-colors';
import { command, flag, option, optional, restPositionals } from 'cmd-ts';

Expand Down Expand Up @@ -45,7 +45,7 @@ export const commandInfo = command({
FetchLog.reset();

const source = fsa.source(path);
const tiff = await new CogTiff(source).init();
const tiff = await new Tiff(source).init();

const header = [
{ key: 'Tiff type', value: `${TiffVersion[tiff.version]} (v${String(tiff.version)})` },
Expand Down Expand Up @@ -123,7 +123,7 @@ export const commandInfo = command({
},
});

const TiffImageInfoTable = new CliTable<CogTiffImage>();
const TiffImageInfoTable = new CliTable<TiffImage>();
TiffImageInfoTable.add({ name: 'Id', width: 4, get: (_i, index) => String(index) });
TiffImageInfoTable.add({ name: 'Size', width: 20, get: (i) => `${i.size.width}x${i.size.height}` });
TiffImageInfoTable.add({
Expand Down Expand Up @@ -169,7 +169,7 @@ TiffImageInfoTable.add({
* TODO using a XML Parser will make this even better
* @param img
*/
function parseGdalMetadata(img: CogTiffImage): string[] | null {
function parseGdalMetadata(img: TiffImage): string[] | null {
const metadata = img.value(TiffTag.GdalMetadata);
if (typeof metadata !== 'string') return null;
if (!metadata.startsWith('<GDALMetadata>')) return null;
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/util.tile.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { promises as fs } from 'node:fs';

import { CogTiff, TiffMimeType } from '@cogeotiff/core';
import { Tiff, TiffMimeType } from '@cogeotiff/core';
import { log } from '@linzjs/tracing';

const FileExtension: Record<string, string> = {
Expand Down Expand Up @@ -34,7 +34,7 @@ export function getTileName(mimeType: string, index: number, x: number, y: numbe
}

export async function writeTile(
tiff: CogTiff,
tiff: Tiff,
x: number,
y: number,
index: number,
Expand Down
4 changes: 2 additions & 2 deletions packages/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ Load a COG from a remote http source

```typescript
import { SourceHttp } from '@chunkd/source-url';
import { CogTiff } from '@cogeotiff/core'
import { Tiff } from '@cogeotiff/core'

const source = new SourceHttp('https://example.com/cog.tif');
const tiff = await CogTiff.create(source);
const tiff = await Tiff.create(source);

/** Load a specific tile from a specific image */
const tile = await tiff.images[5].getTile(2, 2);
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/__benchmark__/cog.read.benchmark.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { readFile } from 'fs/promises';

import { CogTiff } from '../cog.tiff.js';
import { TiffTag } from '../index.js';
import { Tiff } from '../tiff.js';
import { SourceMemory } from './source.memory.js';

// console.log = console.trace;
Expand All @@ -10,10 +10,10 @@ async function main(): Promise<void> {
const buf = await readFile(process.argv[process.argv.length - 1]);
const source = new SourceMemory(buf);
for (let i = 0; i < 5_000; i++) {
performance.mark('cog:init');
const tiff = new CogTiff(source);
performance.mark('tiff:init');
const tiff = new Tiff(source);
await tiff.init();
performance.mark('cog:init:done');
performance.mark('tiff:init:done');

// 6 images
for (const img of tiff.images) await img.getTile(0, 0);
Expand Down
14 changes: 7 additions & 7 deletions packages/core/src/__test__/cog.image.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { promises as fs } from 'fs';

import { TestFileSource } from '../__benchmark__/source.file.js';
import { SourceMemory } from '../__benchmark__/source.memory.js';
import { CogTiff } from '../cog.tiff.js';
import { TiffMimeType } from '../const/tiff.mime.js';
import { Tiff } from '../tiff.js';
import { ByteSize } from '../util/bytes.js';

// 900913 properties.
Expand All @@ -17,9 +17,9 @@ function getResolution(zoom: number): number {
return InitialResolution / 2 ** zoom;
}

describe('CogTiled', () => {
describe('TiffTiled', () => {
const cogSourceFile = new TestFileSource(new URL('../../data/rgba8_tiled.tiff', import.meta.url));
const cog = new CogTiff(cogSourceFile);
const cog = new Tiff(cogSourceFile);

beforeEach(() => cog.init());

Expand Down Expand Up @@ -87,7 +87,7 @@ describe('Cog.Big', () => {
it('should support reading from memory', async () => {
const fullSource = new TestFileSource(new URL('../../data/sparse.tiff', import.meta.url));

const cog = new CogTiff(fullSource);
const cog = new Tiff(fullSource);
await cog.init();

const [firstImage] = cog.images;
Expand All @@ -101,7 +101,7 @@ describe('Cog.Big', () => {
it('should read using a memory source', async () => {
const bytes = await fs.readFile(new URL('../../data/sparse.tiff', import.meta.url));
const source = new SourceMemory(bytes.buffer);
const cog = new CogTiff(source);
const cog = new Tiff(source);
await cog.init();

const [firstImage] = cog.images;
Expand All @@ -115,7 +115,7 @@ describe('Cog.Big', () => {

describe('Cog.Sparse', () => {
const cogSourceFile = new TestFileSource(new URL('../../data/sparse.tiff', import.meta.url));
const cog = new CogTiff(cogSourceFile);
const cog = new Tiff(cogSourceFile);

it('should read metadata', async () => {
await cog.init();
Expand Down Expand Up @@ -164,7 +164,7 @@ describe('Cog.Sparse', () => {

describe('CogStrip', () => {
const cogSourceFile = new TestFileSource(new URL('../../data/rgba8_strip.tiff', import.meta.url));
const cog = new CogTiff(cogSourceFile);
const cog = new Tiff(cogSourceFile);

beforeEach(() => cog.init());

Expand Down
16 changes: 8 additions & 8 deletions packages/core/src/__test__/cog.read.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import assert from 'node:assert';
import { describe, it } from 'node:test';

import { TestFileSource } from '../__benchmark__/source.file.js';
import { CogTiff } from '../cog.tiff.js';
import { TiffMimeType } from '../const/tiff.mime.js';
import { TiffVersion } from '../const/tiff.version.js';
import { TiffTag, TiffTagGeo } from '../index.js';
import { Tiff } from '../tiff.js';

function validate(tif: CogTiff): void {
function validate(tif: Tiff): void {
assert.equal(tif.images.length, 5);

const [firstTif] = tif.images;
Expand All @@ -20,7 +20,7 @@ describe('CogRead', () => {
// TODO this does not load 100% yet
// it('should read big endian', async () => {
// const source = new TestFileSource(new URL('../../data/big_cog.tiff', import.meta.url));
// const tiff = new CogTiff(source);
// const tiff = new Tiff(source);

// await tiff.init();

Expand All @@ -31,7 +31,7 @@ describe('CogRead', () => {

it('should read big tiff', async () => {
const source = new TestFileSource(new URL('../../data/big_cog.tiff', import.meta.url));
const tiff = new CogTiff(source);
const tiff = new Tiff(source);

await tiff.init();

Expand All @@ -42,7 +42,7 @@ describe('CogRead', () => {

it('should read tiff', async () => {
const source = new TestFileSource(new URL('../../data/cog.tiff', import.meta.url));
const tiff = new CogTiff(source);
const tiff = new Tiff(source);

await tiff.init();

Expand All @@ -56,7 +56,7 @@ describe('CogRead', () => {

it('should allow multiple init', async () => {
const source = new TestFileSource(new URL('../../data/cog.tiff', import.meta.url));
const tiff = new CogTiff(source);
const tiff = new Tiff(source);

assert.equal(tiff.isInitialized, false);
await tiff.init();
Expand All @@ -70,7 +70,7 @@ describe('CogRead', () => {

it('should read ifds from anywhere in the file', async () => {
const source = new TestFileSource(new URL('../../data/DEM_BS28_2016_1000_1141.tif', import.meta.url));
const tiff = await CogTiff.create(source);
const tiff = await Tiff.create(source);

assert.equal(tiff.images.length, 1);
const im = tiff.images[0];
Expand All @@ -88,7 +88,7 @@ describe('CogRead', () => {
const source = new TestFileSource(
new URL('../../data/east_coast_phase3_2023_AY31_1000_3335.tif.gz', import.meta.url),
);
const tiff = await CogTiff.create(source);
const tiff = await Tiff.create(source);

assert.equal(tiff.images.length, 5);
const im = tiff.images[0];
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/__test__/example.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { SourceHttp } from '@chunkd/source-http';

import { CogTiff } from '../index.js';
import { Tiff } from '../index.js';

async function main(): Promise<void> {
const source = new SourceHttp('https://example.com/cog.tif');
const tiff = await CogTiff.create(source);
const tiff = await Tiff.create(source);

/** Load a specific tile from a specific image */
const tile = await tiff.images[5].getTile(2, 2);
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export { CogTiffImage } from './cog.tiff.image.js';
export { CogTiff } from './cog.tiff.js';
export { TiffEndian } from './const/tiff.endian.js';
export { TiffCompression, TiffMimeType } from './const/tiff.mime.js';
export { TiffTag, TiffTagGeo, TiffTagGeoValueLookup, TiffTagValueLookup } from './const/tiff.tag.id.js';
Expand All @@ -8,5 +6,7 @@ export { TiffVersion } from './const/tiff.version.js';
export { Tag, TagInline, TagLazy, TagOffset } from './read/tiff.tag.js';
export { getTiffTagSize } from './read/tiff.value.reader.js';
export { Source } from './source.js';
export { TiffImage } from './tiff.image.js';
export { Tiff } from './tiff.js';
export { toHex } from './util/util.hex.js';
export type { BoundingBox, Point, Size, Vector } from './vector.js';
2 changes: 1 addition & 1 deletion packages/core/src/read/tiff.gdal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export enum GhostOptionTileLeader {
* GDAL has made a ghost set of options for Tiff files
* this class represents the optimizations that GDAL has applied
*/
export class CogTifGhostOptions {
export class TiffGhostOptions {
options: Map<string, string> = new Map();

/**
Expand Down
14 changes: 7 additions & 7 deletions packages/core/src/read/tiff.tag.factory.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CogTiff } from '../cog.tiff.js';
import { TiffTag } from '../const/tiff.tag.id.js';
import { TiffTagValueType } from '../const/tiff.tag.value.js';
import { Tiff } from '../tiff.js';
import { getUint, getUint64 } from '../util/bytes.js';
import { DataViewOffset, hasBytes } from './data.view.offset.js';
import { Tag, TagLazy, TagOffset } from './tiff.tag.js';
Expand Down Expand Up @@ -54,7 +54,7 @@ function readTagValue(
}
}

function readValue<T>(tiff: CogTiff, bytes: DataView, offset: number, type: TiffTagValueType, count: number): T {
function readValue<T>(tiff: Tiff, bytes: DataView, offset: number, type: TiffTagValueType, count: number): T {
const typeSize = getTiffTagSize(type);
const dataLength = count * typeSize;

Expand All @@ -77,15 +77,15 @@ function readValue<T>(tiff: CogTiff, bytes: DataView, offset: number, type: Tiff
}

/**
* Determine if all the data for the tiff tag is loaded in and use that to create the specific CogTiffTag
* Determine if all the data for the tiff tag is loaded in and use that to create the specific TiffTag
*
* @see {@link Tag}
*
* @param tiff
* @param view Bytes to read from
* @param offset Offset in the dataview to read a tag
*/
export function createTag(tiff: CogTiff, view: DataViewOffset, offset: number): Tag<unknown> {
export function createTag(tiff: Tiff, view: DataViewOffset, offset: number): Tag<unknown> {
const tagId = view.getUint16(offset + 0, tiff.isLittleEndian);

const dataType = view.getUint16(offset + 2, tiff.isLittleEndian) as TiffTagValueType;
Expand Down Expand Up @@ -131,7 +131,7 @@ export function createTag(tiff: CogTiff, view: DataViewOffset, offset: number):
}

/** Fetch the value from a {@link TagLazy} tag */
export async function fetchLazy<T>(tag: TagLazy<T>, tiff: CogTiff): Promise<T> {
export async function fetchLazy<T>(tag: TagLazy<T>, tiff: Tiff): Promise<T> {
if (tag.value != null) return tag.value;
const dataTypeSize = getTiffTagSize(tag.dataType);
const dataLength = dataTypeSize * tag.count;
Expand All @@ -144,7 +144,7 @@ export async function fetchLazy<T>(tag: TagLazy<T>, tiff: CogTiff): Promise<T> {
/**
* Fetch all the values from a {@link TagOffset}
*/
export async function fetchAllOffsets(tiff: CogTiff, tag: TagOffset): Promise<number[]> {
export async function fetchAllOffsets(tiff: Tiff, tag: TagOffset): Promise<number[]> {
const dataTypeSize = getTiffTagSize(tag.dataType);

if (tag.view == null) {
Expand All @@ -166,7 +166,7 @@ export function setBytes(tag: TagOffset, view: DataViewOffset): void {
}

/** Partially fetch the values of a {@link TagOffset} and return the value for the offset */
export async function getValueAt(tiff: CogTiff, tag: TagOffset, index: number): Promise<number> {
export async function getValueAt(tiff: Tiff, tag: TagOffset, index: number): Promise<number> {
if (index > tag.count || index < 0) throw new Error('TagOffset: out of bounds :' + index);
if (tag.value[index] != null) return tag.value[index];
const dataTypeSize = getTiffTagSize(tag.dataType);
Expand Down
Loading

0 comments on commit 872263b

Please sign in to comment.