Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): support webp quality setting #586

Merged
merged 1 commit into from
May 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions packages/cog/src/cli/cogify/action.job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,16 @@ export class CLiInputData {
}

export class ActionJobCreate extends CommandLineAction {
private source?: CLiInputData;
private output?: CLiInputData;
private maxConcurrency?: CommandLineIntegerParameter;
private generateVrt?: CommandLineFlagParameter;
private resampling?: CommandLineStringParameter;
private cutline?: CommandLineStringParameter;
private cutlineBlend?: CommandLineIntegerParameter;
private overrideId?: CommandLineStringParameter;
private source: CLiInputData;
private output: CLiInputData;
private maxConcurrency: CommandLineIntegerParameter;
private generateVrt: CommandLineFlagParameter;
private resampling: CommandLineStringParameter;
private cutline: CommandLineStringParameter;
private cutlineBlend: CommandLineIntegerParameter;
private overrideId: CommandLineStringParameter;
private submitBatch: CommandLineFlagParameter;
private quality: CommandLineIntegerParameter;

MaxCogsDefault = 50;
MaxConcurrencyDefault = 5;
Expand Down Expand Up @@ -195,6 +196,7 @@ export class ActionJobCreate extends CommandLineAction {
output: {
...outputConfig,
resampling,
quality: this.quality.value ?? 90,
cutlineBlend: cutline != null ? this.cutlineBlend?.value ?? 0 : undefined,
nodata: metadata.nodata,
vrt: {
Expand Down Expand Up @@ -303,5 +305,12 @@ export class ActionJobCreate extends CommandLineAction {
description: 'Submit the job to AWS Batch',
required: false,
});

this.quality = this.defineIntegerParameter({
argumentName: 'QUALITY',
parameterLongName: '--quality',
description: 'Compression quality (0-100)',
required: false,
});
}
}
3 changes: 3 additions & 0 deletions packages/cog/src/cog/__test__/cog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ o.spec('cog', () => {
compression: 'webp',
resampling: 'bilinear',
blockSize: 512,
quality: 90,
});
o(gdalCogBuilder!.source).equals('/tmp/test.vrt');
o(gdalCogBuilder!.target).equals('/tmp/out-tiff');
Expand All @@ -65,6 +66,8 @@ o.spec('cog', () => {
'COMPRESS=webp',
'-co',
'ALIGNED_LEVELS=6',
'-co',
'QUALITY=90',
'-projwin',
'18472078.003508832',
'-5948635.289265559',
Expand Down
1 change: 1 addition & 0 deletions packages/cog/src/cog/cog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export async function buildCogForQuadKey(
bbox: [ulX, ulY, lrX, lrY],
alignmentLevels,
resampling: job.output.resampling,
quality: job.output.quality,
});
if (cogBuild.gdal.mount) {
job.source.files.forEach((f) => cogBuild.gdal.mount?.(f));
Expand Down
5 changes: 5 additions & 0 deletions packages/cog/src/cog/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ export interface CogJob {
output: {
resampling: GdalCogBuilderOptionsResampling;
nodata?: number;
/**
* Quality level to use
* @default 90
*/
quality: number;
cutlineBlend?: number;
vrt: {
options: VrtOptions;
Expand Down
6 changes: 6 additions & 0 deletions packages/cog/src/gdal/gdal.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,19 @@ export interface GdalCogBuilderOptions {
* @default 512
*/
blockSize: 256 | 512 | 1024 | 2048 | 4096;

/**
* Compression quality
*/
quality: number;
}

export const GdalCogBuilderDefaults: GdalCogBuilderOptions = {
resampling: 'bilinear',
compression: 'webp',
alignmentLevels: 1,
blockSize: 512,
quality: 90,
};

export const GdalResamplingOptions: Record<string, GdalCogBuilderOptionsResampling> = {
Expand Down
3 changes: 3 additions & 0 deletions packages/cog/src/gdal/gdal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export class GdalCogBuilder {
compression: config.compression ?? GdalCogBuilderDefaults.compression,
resampling: config.resampling ?? GdalCogBuilderDefaults.resampling,
blockSize: config.blockSize ?? GdalCogBuilderDefaults.blockSize,
quality: config.quality ?? GdalCogBuilderDefaults.quality,
};
this.gdal = GdalCogBuilder.getGdal();

Expand Down Expand Up @@ -104,6 +105,8 @@ export class GdalCogBuilder {
// Number of levels to align to web mercator
'-co',
`ALIGNED_LEVELS=${this.config.alignmentLevels}`,
'-co',
`QUALITY=${this.config.quality}`,
...this.getBounds(),

this.source,
Expand Down