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

Remove clipImageData completely #4201

Merged
merged 2 commits into from
Oct 13, 2022
Merged
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
32 changes: 9 additions & 23 deletions src/browser/renderer/shared/TextureAtlas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -768,27 +775,6 @@ export class TextureAtlas implements ITextureAtlas {
}
};
}

private _clipImageData(imageData: ImageData, boundingBox: IBoundingBox): ImageData {
// Operate on pixels instead of channels to reduce the amount of work
const originalData = new Uint32Array(imageData.data.buffer);

// Create a new view on the same buffer for the clipped data. The clipping operation is done in
// place to avoid allocating another buffer
const width = boundingBox.right - boundingBox.left + 1;
const height = boundingBox.bottom - boundingBox.top + 1;
const clippedData = new Uint32Array(imageData.data.buffer, 0, width * height);

// Perform clipping and return the result
let x = 0;
let y = 0;
for (y = boundingBox.top; y <= boundingBox.bottom; y++) {
for (x = boundingBox.left; x <= boundingBox.right; x++) {
clippedData[(y - boundingBox.top) * width + (x - boundingBox.left)] = originalData[y * imageData.width + x];
}
}
return new ImageData(new Uint8ClampedArray(clippedData.buffer, clippedData.byteOffset, clippedData.byteLength), width, height);
}
}

/**
Expand Down