Skip to content

Commit

Permalink
perf: reduce packaging size
Browse files Browse the repository at this point in the history
  • Loading branch information
hongfaqiu committed Jul 31, 2023
1 parent 169c829 commit 1455d78
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
4 changes: 2 additions & 2 deletions packages/TIFFImageryProvider/src/TIFFImageryProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import GeoTIFF, { Pool, fromUrl, fromBlob, GeoTIFFImage } from 'geotiff';

import { addColorScale, plot } from './plotty'
import WorkerFarm from "./worker-farm";
import { getMinMax, generateColorScale, findAndSortBandNumbers } from "./utils";
import { getMinMax, generateColorScale, findAndSortBandNumbers, stringColorToRgba } from "./utils";
import { ColorScaleNames, TypedArray } from "./plotty/typing";
import TIFFImageryProviderTilingScheme from "./TIFFImageryProviderTilingScheme";

Expand Down Expand Up @@ -513,7 +513,7 @@ export class TIFFImageryProvider {
bands: this.bands,
noData: this.noData,
resampleMethod: this.options.resampleMethod,
colorMapping: this.renderOptions.colorMapping ?? { 'black': 'transparent' },
colorMapping: Object.entries(this.renderOptions.colorMapping ?? { 'black': 'transparent' }).map((val) => val. map(stringColorToRgba)),
}
if (!this._workerFarm?.worker) {
throw new DeveloperError('web workers bootstrap error');
Expand Down
8 changes: 3 additions & 5 deletions packages/TIFFImageryProvider/src/generateImage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getRange, decimal2rgb, stringColorToRgba } from "./utils";
import { getRange, decimal2rgb } from "./utils";
import { MultiBandRenderOptions } from "./TIFFImageryProvider";

export type GenerateImageOptions = {
Expand All @@ -10,7 +10,7 @@ export type GenerateImageOptions = {
max: number;
}>;
noData?: number;
colorMapping: Record<string, string>;
colorMapping: number[][][];
}

export async function generateImage(data: Float32Array[], opts: GenerateImageOptions) {
Expand All @@ -36,9 +36,7 @@ export async function generateImage(data: Float32Array[], opts: GenerateImageOpt
let blue = decimal2rgb((blueData[i] - ranges[2].min) / ranges[2].range);
let alpha = ifNoDataFunc(redData[i], greenData[i], blueData[i]) ? 0 : 255;

Object.entries(colorMapping).map(([key, value]) => {
const colorFrom = stringColorToRgba(key);
const colorTo = stringColorToRgba(value);
colorMapping.map(([colorFrom, colorTo]) => {
if (red === colorFrom[0] && green === colorFrom[1] && blue === colorFrom[2]) {
red = colorTo[0];
green = colorTo[1];
Expand Down

0 comments on commit 1455d78

Please sign in to comment.