From 50d1834871bb4b4d336bd8d4650f8e5779c64841 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Thu, 13 Oct 2022 06:25:13 -0700 Subject: [PATCH] Remove clipImageData completely putImageData works a little differently to drawImage which confused me for a bit, you need to offset the destination as putImageData draws the 'dirty' parts of the texture using the same source image dimensions Fixes #4197 --- src/browser/renderer/shared/TextureAtlas.ts | 28 +++++++-------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/src/browser/renderer/shared/TextureAtlas.ts b/src/browser/renderer/shared/TextureAtlas.ts index d450cfdc..162c7bdf 100644 --- a/src/browser/renderer/shared/TextureAtlas.ts +++ b/src/browser/renderer/shared/TextureAtlas.ts @@ -612,7 +612,6 @@ export class TextureAtlas implements ITextureAtlas { } const rasterizedGlyph = this._findGlyphBoundingBox(imageData, this._workBoundingBox, allowedWidth, restrictedPowerlineGlyph, customGlyph, padding); - const clippedImageData = this._clipImageData(imageData, this._workBoundingBox); // Find the best atlas row to use let activeRow: ICharAtlasActiveRow; @@ -676,7 +675,15 @@ export class TextureAtlas implements ITextureAtlas { activeRow.x += rasterizedGlyph.size.x; // putImageData doesn't do any blending, so it will overwrite any existing cache entry for us - this._cacheCtx.putImageData(clippedImageData, rasterizedGlyph.texturePosition.x, rasterizedGlyph.texturePosition.y); + this._cacheCtx.putImageData( + imageData, + rasterizedGlyph.texturePosition.x - this._workBoundingBox.left, + rasterizedGlyph.texturePosition.y - this._workBoundingBox.top, + this._workBoundingBox.left, + this._workBoundingBox.top, + rasterizedGlyph.size.x, + rasterizedGlyph.size.y + ); return rasterizedGlyph; } @@ -768,23 +775,6 @@ export class TextureAtlas implements ITextureAtlas { } }; } - - private _clipImageData(imageData: ImageData, boundingBox: IBoundingBox): ImageData { - const width = boundingBox.right - boundingBox.left + 1; - const height = boundingBox.bottom - boundingBox.top + 1; - const clippedData = new Uint8ClampedArray(width * height * 4); - for (let y = boundingBox.top; y <= boundingBox.bottom; y++) { - for (let x = boundingBox.left; x <= boundingBox.right; x++) { - const oldOffset = y * this._tmpCanvas.width * 4 + x * 4; - const newOffset = (y - boundingBox.top) * width * 4 + (x - boundingBox.left) * 4; - clippedData[newOffset] = imageData.data[oldOffset]; - clippedData[newOffset + 1] = imageData.data[oldOffset + 1]; - clippedData[newOffset + 2] = imageData.data[oldOffset + 2]; - clippedData[newOffset + 3] = imageData.data[oldOffset + 3]; - } - } - return new ImageData(clippedData, width, height); - } } /**