Skip to content

Commit

Permalink
Close #1301 disable interpolation if larger than 8096px + add "willRe…
Browse files Browse the repository at this point in the history
…adFrequently" option
  • Loading branch information
mistic100 committed May 14, 2024
1 parent d90c4db commit 9d0b53d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
14 changes: 9 additions & 5 deletions packages/core/src/adapters/EquirectangularAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ export class EquirectangularAdapter extends AbstractAdapter<string, Texture, Pan
logWarn('Web Worker API not available');
this.config.interpolateBackground = false;
} else {
this.interpolationWorker = new Worker(interpolationWorkerSrc);
this.interpolationWorker = new Worker(interpolationWorkerSrc, {
name: 'photo-sphere-viewer-interpolation',
});
}
}

Expand Down Expand Up @@ -321,10 +323,12 @@ export class EquirectangularAdapter extends AbstractAdapter<string, Texture, Pan

const t = createTexture(buffer);

if (this.config.interpolateBackground && (
panoData.croppedWidth !== panoData.fullWidth
|| panoData.croppedHeight !== panoData.fullHeight
)) {
if (this.config.interpolateBackground
&& resizedPanoData.fullWidth <= 8096
&& (
panoData.croppedWidth !== panoData.fullWidth
|| panoData.croppedHeight !== panoData.fullHeight
)) {
this.interpolationWorker.postMessage({
image: ctx.getImageData(
resizedPanoData.croppedX,
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/adapters/interpolationWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ function interpolationWorker() {
const panoData: PanoData = e.data.panoData;

const buffer = new OffscreenCanvas(panoData.fullWidth, panoData.fullHeight);
const ctx = buffer.getContext('2d');
const ctx = buffer.getContext('2d', {
willReadFrequently: true,
});

const img = new OffscreenCanvas(panoData.croppedWidth, panoData.croppedHeight);
const ctxImg = img.getContext('2d');
Expand Down

0 comments on commit 9d0b53d

Please sign in to comment.