pixel-data-js 0.28.0 → 0.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.prod.cjs +294 -240
- package/dist/index.prod.cjs.map +1 -1
- package/dist/index.prod.d.ts +42 -33
- package/dist/index.prod.js +286 -240
- package/dist/index.prod.js.map +1 -1
- package/package.json +1 -1
- package/src/Canvas/CanvasFrameRenderer.ts +2 -2
- package/src/Internal/_constants.ts +3 -0
- package/src/Paint/AlphaMaskPaintBuffer.ts +0 -56
- package/src/Paint/BinaryMaskPaintBuffer.ts +0 -56
- package/src/Paint/ColorPaintBuffer.ts +0 -53
- package/src/Paint/Commit/AlphaMaskPaintBufferCommitter.ts +26 -0
- package/src/Paint/Commit/AlphaMaskPaintBufferManager.ts +34 -0
- package/src/Paint/Commit/BinaryMaskPaintBufferCommitter.ts +26 -0
- package/src/Paint/Commit/BinaryMaskPaintBufferManager.ts +31 -0
- package/src/Paint/Commit/ColorPaintBufferCommitter.ts +23 -0
- package/src/Paint/Commit/ColorPaintBufferManager.ts +34 -0
- package/src/Paint/Commit/commitColorPaintBuffer.ts +55 -0
- package/src/Paint/Commit/commitMaskPaintBuffer.ts +78 -0
- package/src/Paint/{AlphaMaskPaintBufferCanvasRenderer.ts → Render/AlphaMaskPaintBufferCanvasRenderer.ts} +9 -9
- package/src/Paint/{BinaryMaskPaintBufferCanvasRenderer.ts → Render/BinaryMaskPaintBufferCanvasRenderer.ts} +9 -9
- package/src/Paint/{ColorPaintBufferCanvasRenderer.ts → Render/ColorPaintBufferCanvasRenderer.ts} +8 -10
- package/src/Paint/{PaintCursorRenderer.ts → Render/PaintCursorRenderer.ts} +23 -22
- package/src/index.ts +15 -4
package/dist/index.prod.js
CHANGED
|
@@ -1919,13 +1919,13 @@ function makeReusableCanvasMeta(factory) {
|
|
|
1919
1919
|
|
|
1920
1920
|
// src/Canvas/CanvasFrameRenderer.ts
|
|
1921
1921
|
function makeCanvasFrameRenderer(reusableCanvasFactory = makeReusableOffscreenCanvas) {
|
|
1922
|
-
const
|
|
1922
|
+
const getBuffer = reusableCanvasFactory();
|
|
1923
1923
|
return function renderCanvasFrame(pixelCanvas, scale, getImageData, drawPixelLayer, drawScreenLayer) {
|
|
1924
1924
|
const canvas = pixelCanvas.canvas;
|
|
1925
1925
|
const ctx = pixelCanvas.ctx;
|
|
1926
1926
|
const w = canvas.width;
|
|
1927
1927
|
const h = canvas.height;
|
|
1928
|
-
const buffer =
|
|
1928
|
+
const buffer = getBuffer(w, h);
|
|
1929
1929
|
const img = getImageData();
|
|
1930
1930
|
if (img) {
|
|
1931
1931
|
buffer.ctx.putImageData(img, 0, 0);
|
|
@@ -5012,7 +5012,6 @@ var AlphaMaskPaintBuffer = class {
|
|
|
5012
5012
|
w: 0,
|
|
5013
5013
|
h: 0
|
|
5014
5014
|
};
|
|
5015
|
-
blendColorPixelDataAlphaMaskFn = blendColorPixelDataAlphaMask;
|
|
5016
5015
|
forEachLinePointFn = forEachLinePoint;
|
|
5017
5016
|
trimRectBoundsFn = trimRectBounds;
|
|
5018
5017
|
eachTileInBoundsFn = eachTileInBounds;
|
|
@@ -5151,88 +5150,11 @@ var AlphaMaskPaintBuffer = class {
|
|
|
5151
5150
|
});
|
|
5152
5151
|
return changed;
|
|
5153
5152
|
}
|
|
5154
|
-
opts = {
|
|
5155
|
-
alpha: 255,
|
|
5156
|
-
blendFn: sourceOverPerfect,
|
|
5157
|
-
x: 0,
|
|
5158
|
-
y: 0,
|
|
5159
|
-
w: 0,
|
|
5160
|
-
h: 0
|
|
5161
|
-
};
|
|
5162
|
-
commit(accumulator, color, alpha = 255, blendFn = sourceOverPerfect) {
|
|
5163
|
-
const blendColorPixelDataAlphaMaskFn = this.blendColorPixelDataAlphaMaskFn;
|
|
5164
|
-
const tileShift = this.config.tileShift;
|
|
5165
|
-
const lookup = this.lookup;
|
|
5166
|
-
const opts = this.opts;
|
|
5167
|
-
opts.alpha = alpha;
|
|
5168
|
-
opts.blendFn = blendFn;
|
|
5169
|
-
for (let i = 0; i < lookup.length; i++) {
|
|
5170
|
-
const tile = lookup[i];
|
|
5171
|
-
if (tile) {
|
|
5172
|
-
const didChange = accumulator.storeTileBeforeState(tile.id, tile.tx, tile.ty);
|
|
5173
|
-
const dx = tile.tx << tileShift;
|
|
5174
|
-
const dy = tile.ty << tileShift;
|
|
5175
|
-
opts.x = dx;
|
|
5176
|
-
opts.y = dy;
|
|
5177
|
-
opts.w = tile.w;
|
|
5178
|
-
opts.h = tile.h;
|
|
5179
|
-
didChange(blendColorPixelDataAlphaMaskFn(this.config.target, color, tile, opts));
|
|
5180
|
-
}
|
|
5181
|
-
}
|
|
5182
|
-
this.clear();
|
|
5183
|
-
}
|
|
5184
5153
|
clear() {
|
|
5185
5154
|
this.tilePool.releaseTiles(this.lookup);
|
|
5186
5155
|
}
|
|
5187
5156
|
};
|
|
5188
5157
|
|
|
5189
|
-
// src/Paint/AlphaMaskPaintBufferCanvasRenderer.ts
|
|
5190
|
-
function makeAlphaMaskPaintBufferCanvasRenderer(paintBuffer, offscreenCanvasClass = OffscreenCanvas) {
|
|
5191
|
-
const config = paintBuffer.config;
|
|
5192
|
-
const tileSize = config.tileSize;
|
|
5193
|
-
const tileShift = config.tileShift;
|
|
5194
|
-
const tileArea = config.tileArea;
|
|
5195
|
-
const lookup = paintBuffer.lookup;
|
|
5196
|
-
const canvas = new offscreenCanvasClass(tileSize, tileSize);
|
|
5197
|
-
const ctx = canvas.getContext("2d");
|
|
5198
|
-
if (!ctx) throw new Error(CANVAS_CTX_FAILED);
|
|
5199
|
-
ctx.imageSmoothingEnabled = false;
|
|
5200
|
-
const bridge = makePixelData(new ImageData(tileSize, tileSize));
|
|
5201
|
-
const view32 = bridge.data;
|
|
5202
|
-
return function drawPaintBuffer(targetCtx, color, alpha = 255, compOperation = "source-over") {
|
|
5203
|
-
if (alpha === 0) return;
|
|
5204
|
-
const baseSrcAlpha = color >>> 24;
|
|
5205
|
-
const colorRGB = color & 16777215;
|
|
5206
|
-
if (baseSrcAlpha === 0) return;
|
|
5207
|
-
targetCtx.globalAlpha = alpha / 255;
|
|
5208
|
-
targetCtx.globalCompositeOperation = compOperation;
|
|
5209
|
-
for (let i = 0; i < lookup.length; i++) {
|
|
5210
|
-
const tile = lookup[i];
|
|
5211
|
-
if (tile) {
|
|
5212
|
-
const data8 = tile.data;
|
|
5213
|
-
view32.fill(0);
|
|
5214
|
-
for (let p = 0; p < tileArea; p++) {
|
|
5215
|
-
const maskA = data8[p];
|
|
5216
|
-
if (maskA === 0) continue;
|
|
5217
|
-
if (maskA === 255) {
|
|
5218
|
-
view32[p] = color;
|
|
5219
|
-
} else {
|
|
5220
|
-
const t = baseSrcAlpha * maskA + 128;
|
|
5221
|
-
const finalA = t + (t >> 8) >> 8;
|
|
5222
|
-
view32[p] = (colorRGB | finalA << 24) >>> 0;
|
|
5223
|
-
}
|
|
5224
|
-
}
|
|
5225
|
-
const dx = tile.tx << tileShift;
|
|
5226
|
-
const dy = tile.ty << tileShift;
|
|
5227
|
-
ctx.putImageData(bridge.imageData, 0, 0);
|
|
5228
|
-
targetCtx.drawImage(canvas, dx, dy);
|
|
5229
|
-
}
|
|
5230
|
-
}
|
|
5231
|
-
targetCtx.globalAlpha = 1;
|
|
5232
|
-
targetCtx.globalCompositeOperation = "source-over";
|
|
5233
|
-
};
|
|
5234
|
-
}
|
|
5235
|
-
|
|
5236
5158
|
// src/Paint/BinaryMaskPaintBuffer.ts
|
|
5237
5159
|
var BinaryMaskPaintBuffer = class {
|
|
5238
5160
|
constructor(config, tilePool) {
|
|
@@ -5247,7 +5169,6 @@ var BinaryMaskPaintBuffer = class {
|
|
|
5247
5169
|
w: 0,
|
|
5248
5170
|
h: 0
|
|
5249
5171
|
};
|
|
5250
|
-
blendColorPixelDataBinaryMaskFn = blendColorPixelDataBinaryMask;
|
|
5251
5172
|
forEachLinePointFn = forEachLinePoint;
|
|
5252
5173
|
trimRectBoundsFn = trimRectBounds;
|
|
5253
5174
|
eachTileInBoundsFn = eachTileInBounds;
|
|
@@ -5338,87 +5259,16 @@ var BinaryMaskPaintBuffer = class {
|
|
|
5338
5259
|
});
|
|
5339
5260
|
return changed;
|
|
5340
5261
|
}
|
|
5341
|
-
opts = {
|
|
5342
|
-
alpha: 255,
|
|
5343
|
-
blendFn: sourceOverPerfect,
|
|
5344
|
-
x: 0,
|
|
5345
|
-
y: 0,
|
|
5346
|
-
w: 0,
|
|
5347
|
-
h: 0
|
|
5348
|
-
};
|
|
5349
|
-
commit(accumulator, color, alpha = 255, blendFn = sourceOverPerfect) {
|
|
5350
|
-
const blendColorPixelDataBinaryMaskFn = this.blendColorPixelDataBinaryMaskFn;
|
|
5351
|
-
const tileShift = this.config.tileShift;
|
|
5352
|
-
const lookup = this.lookup;
|
|
5353
|
-
const opts = this.opts;
|
|
5354
|
-
opts.alpha = alpha;
|
|
5355
|
-
opts.blendFn = blendFn;
|
|
5356
|
-
for (let i = 0; i < lookup.length; i++) {
|
|
5357
|
-
const tile = lookup[i];
|
|
5358
|
-
if (tile) {
|
|
5359
|
-
const didChange = accumulator.storeTileBeforeState(tile.id, tile.tx, tile.ty);
|
|
5360
|
-
const dx = tile.tx << tileShift;
|
|
5361
|
-
const dy = tile.ty << tileShift;
|
|
5362
|
-
opts.x = dx;
|
|
5363
|
-
opts.y = dy;
|
|
5364
|
-
opts.w = tile.w;
|
|
5365
|
-
opts.h = tile.h;
|
|
5366
|
-
didChange(blendColorPixelDataBinaryMaskFn(this.config.target, color, tile, opts));
|
|
5367
|
-
}
|
|
5368
|
-
}
|
|
5369
|
-
this.clear();
|
|
5370
|
-
}
|
|
5371
5262
|
clear() {
|
|
5372
5263
|
this.tilePool.releaseTiles(this.lookup);
|
|
5373
5264
|
}
|
|
5374
5265
|
};
|
|
5375
5266
|
|
|
5376
|
-
// src/Paint/BinaryMaskPaintBufferCanvasRenderer.ts
|
|
5377
|
-
function makeBinaryMaskPaintBufferCanvasRenderer(paintBuffer, offscreenCanvasClass = OffscreenCanvas) {
|
|
5378
|
-
const config = paintBuffer.config;
|
|
5379
|
-
const tileSize = config.tileSize;
|
|
5380
|
-
const tileShift = config.tileShift;
|
|
5381
|
-
const tileArea = config.tileArea;
|
|
5382
|
-
const lookup = paintBuffer.lookup;
|
|
5383
|
-
const canvas = new offscreenCanvasClass(tileSize, tileSize);
|
|
5384
|
-
const ctx = canvas.getContext("2d");
|
|
5385
|
-
if (!ctx) throw new Error(CANVAS_CTX_FAILED);
|
|
5386
|
-
ctx.imageSmoothingEnabled = false;
|
|
5387
|
-
const bridge = makePixelData(new ImageData(tileSize, tileSize));
|
|
5388
|
-
const view32 = bridge.data;
|
|
5389
|
-
return function drawPaintBuffer(targetCtx, color, alpha = 255, compOperation = "source-over") {
|
|
5390
|
-
if (alpha === 0) return;
|
|
5391
|
-
const baseSrcAlpha = color >>> 24;
|
|
5392
|
-
if (baseSrcAlpha === 0) return;
|
|
5393
|
-
targetCtx.globalAlpha = alpha / 255;
|
|
5394
|
-
targetCtx.globalCompositeOperation = compOperation;
|
|
5395
|
-
for (let i = 0; i < lookup.length; i++) {
|
|
5396
|
-
const tile = lookup[i];
|
|
5397
|
-
if (tile) {
|
|
5398
|
-
const data8 = tile.data;
|
|
5399
|
-
view32.fill(0);
|
|
5400
|
-
for (let p = 0; p < tileArea; p++) {
|
|
5401
|
-
if (data8[p] === 1) {
|
|
5402
|
-
view32[p] = color;
|
|
5403
|
-
}
|
|
5404
|
-
}
|
|
5405
|
-
const dx = tile.tx << tileShift;
|
|
5406
|
-
const dy = tile.ty << tileShift;
|
|
5407
|
-
ctx.putImageData(bridge.imageData, 0, 0);
|
|
5408
|
-
targetCtx.drawImage(canvas, dx, dy);
|
|
5409
|
-
}
|
|
5410
|
-
}
|
|
5411
|
-
targetCtx.globalAlpha = 1;
|
|
5412
|
-
targetCtx.globalCompositeOperation = "source-over";
|
|
5413
|
-
};
|
|
5414
|
-
}
|
|
5415
|
-
|
|
5416
5267
|
// src/Paint/ColorPaintBuffer.ts
|
|
5417
5268
|
var ColorPaintBuffer = class {
|
|
5418
|
-
constructor(config, tilePool
|
|
5269
|
+
constructor(config, tilePool) {
|
|
5419
5270
|
this.config = config;
|
|
5420
5271
|
this.tilePool = tilePool;
|
|
5421
|
-
this.blendPixelDataFn = blendPixelDataFn;
|
|
5422
5272
|
this.lookup = [];
|
|
5423
5273
|
}
|
|
5424
5274
|
lookup;
|
|
@@ -5569,48 +5419,246 @@ var ColorPaintBuffer = class {
|
|
|
5569
5419
|
});
|
|
5570
5420
|
return changed;
|
|
5571
5421
|
}
|
|
5572
|
-
|
|
5573
|
-
|
|
5574
|
-
|
|
5575
|
-
|
|
5576
|
-
|
|
5577
|
-
|
|
5578
|
-
|
|
5422
|
+
clear() {
|
|
5423
|
+
this.tilePool.releaseTiles(this.lookup);
|
|
5424
|
+
}
|
|
5425
|
+
};
|
|
5426
|
+
|
|
5427
|
+
// src/Paint/Commit/commitMaskPaintBuffer.ts
|
|
5428
|
+
var SCRATCH_OPTS = {
|
|
5429
|
+
alpha: 255,
|
|
5430
|
+
blendFn: sourceOverPerfect,
|
|
5431
|
+
x: 0,
|
|
5432
|
+
y: 0,
|
|
5433
|
+
w: 0,
|
|
5434
|
+
h: 0
|
|
5435
|
+
};
|
|
5436
|
+
function commitMaskPaintBuffer(accumulator, paintBuffer, color, alpha = 255, blendFn = sourceOverPerfect, blendColorPixelDataMaskFn) {
|
|
5437
|
+
const config = accumulator.config;
|
|
5438
|
+
const tileShift = config.tileShift;
|
|
5439
|
+
const lookup = paintBuffer.lookup;
|
|
5440
|
+
SCRATCH_OPTS.alpha = alpha;
|
|
5441
|
+
SCRATCH_OPTS.blendFn = blendFn;
|
|
5442
|
+
for (let i = 0; i < lookup.length; i++) {
|
|
5443
|
+
const tile = lookup[i];
|
|
5444
|
+
if (tile) {
|
|
5445
|
+
const didChange = accumulator.storeTileBeforeState(tile.id, tile.tx, tile.ty);
|
|
5446
|
+
const dx = tile.tx << tileShift;
|
|
5447
|
+
const dy = tile.ty << tileShift;
|
|
5448
|
+
SCRATCH_OPTS.x = dx;
|
|
5449
|
+
SCRATCH_OPTS.y = dy;
|
|
5450
|
+
SCRATCH_OPTS.w = tile.w;
|
|
5451
|
+
SCRATCH_OPTS.h = tile.h;
|
|
5452
|
+
didChange(blendColorPixelDataMaskFn(config.target, color, tile, SCRATCH_OPTS));
|
|
5453
|
+
}
|
|
5454
|
+
}
|
|
5455
|
+
paintBuffer.clear();
|
|
5456
|
+
}
|
|
5457
|
+
|
|
5458
|
+
// src/Paint/Commit/AlphaMaskPaintBufferCommitter.ts
|
|
5459
|
+
function makeAlphaMaskPaintBufferCommitter(accumulator, paintBuffer) {
|
|
5460
|
+
return function commitAlphaMaskPaintBufferToAccumulator(color, alpha = 255, blendFn = sourceOverPerfect) {
|
|
5461
|
+
return commitMaskPaintBuffer(accumulator, paintBuffer, color, alpha, blendFn, blendColorPixelDataAlphaMask);
|
|
5579
5462
|
};
|
|
5580
|
-
|
|
5581
|
-
|
|
5582
|
-
|
|
5583
|
-
|
|
5584
|
-
|
|
5585
|
-
|
|
5586
|
-
|
|
5463
|
+
}
|
|
5464
|
+
|
|
5465
|
+
// src/Internal/_constants.ts
|
|
5466
|
+
var DEFAULT_CANVAS_FACTORY = (w, h) => new OffscreenCanvas(w, h);
|
|
5467
|
+
|
|
5468
|
+
// src/Tile/MaskTile.ts
|
|
5469
|
+
var makeAlphaMaskTile = (id, tx, ty, tileSize, tileArea) => {
|
|
5470
|
+
return {
|
|
5471
|
+
tileType: 1 /* MASK */,
|
|
5472
|
+
type: 0 /* ALPHA */,
|
|
5473
|
+
data: new Uint8Array(tileArea),
|
|
5474
|
+
w: tileSize,
|
|
5475
|
+
h: tileSize,
|
|
5476
|
+
id,
|
|
5477
|
+
tx,
|
|
5478
|
+
ty
|
|
5479
|
+
};
|
|
5480
|
+
};
|
|
5481
|
+
var makeBinaryMaskTile = (id, tx, ty, tileSize, tileArea) => {
|
|
5482
|
+
return {
|
|
5483
|
+
tileType: 1 /* MASK */,
|
|
5484
|
+
type: 1 /* BINARY */,
|
|
5485
|
+
data: new Uint8Array(tileArea),
|
|
5486
|
+
w: tileSize,
|
|
5487
|
+
h: tileSize,
|
|
5488
|
+
id,
|
|
5489
|
+
tx,
|
|
5490
|
+
ty
|
|
5491
|
+
};
|
|
5492
|
+
};
|
|
5493
|
+
|
|
5494
|
+
// src/Paint/Render/AlphaMaskPaintBufferCanvasRenderer.ts
|
|
5495
|
+
function makeAlphaMaskPaintBufferCanvasRenderer(paintBuffer, canvasFactory = DEFAULT_CANVAS_FACTORY) {
|
|
5496
|
+
const config = paintBuffer.config;
|
|
5497
|
+
const tileSize = config.tileSize;
|
|
5498
|
+
const tileShift = config.tileShift;
|
|
5499
|
+
const tileArea = config.tileArea;
|
|
5500
|
+
const lookup = paintBuffer.lookup;
|
|
5501
|
+
const canvas = canvasFactory(tileSize, tileSize);
|
|
5502
|
+
const ctx = canvas.getContext("2d");
|
|
5503
|
+
if (!ctx) throw new Error(CANVAS_CTX_FAILED);
|
|
5504
|
+
ctx.imageSmoothingEnabled = false;
|
|
5505
|
+
const bridge = makePixelData(new ImageData(tileSize, tileSize));
|
|
5506
|
+
const view32 = bridge.data;
|
|
5507
|
+
return function drawPaintBuffer(targetCtx, color, alpha = 255, compOperation = "source-over") {
|
|
5508
|
+
if (alpha === 0) return;
|
|
5509
|
+
const baseSrcAlpha = color >>> 24;
|
|
5510
|
+
const colorRGB = color & 16777215;
|
|
5511
|
+
if (baseSrcAlpha === 0) return;
|
|
5512
|
+
targetCtx.globalAlpha = alpha / 255;
|
|
5513
|
+
targetCtx.globalCompositeOperation = compOperation;
|
|
5587
5514
|
for (let i = 0; i < lookup.length; i++) {
|
|
5588
5515
|
const tile = lookup[i];
|
|
5589
5516
|
if (tile) {
|
|
5590
|
-
const
|
|
5517
|
+
const data8 = tile.data;
|
|
5518
|
+
view32.fill(0);
|
|
5519
|
+
for (let p = 0; p < tileArea; p++) {
|
|
5520
|
+
const maskA = data8[p];
|
|
5521
|
+
if (maskA === 0) continue;
|
|
5522
|
+
if (maskA === 255) {
|
|
5523
|
+
view32[p] = color;
|
|
5524
|
+
} else {
|
|
5525
|
+
const t = baseSrcAlpha * maskA + 128;
|
|
5526
|
+
const finalA = t + (t >> 8) >> 8;
|
|
5527
|
+
view32[p] = (colorRGB | finalA << 24) >>> 0;
|
|
5528
|
+
}
|
|
5529
|
+
}
|
|
5591
5530
|
const dx = tile.tx << tileShift;
|
|
5592
5531
|
const dy = tile.ty << tileShift;
|
|
5593
|
-
|
|
5594
|
-
|
|
5595
|
-
opts.w = tile.w;
|
|
5596
|
-
opts.h = tile.h;
|
|
5597
|
-
didChange(blendPixelDataFn(this.config.target, tile, opts));
|
|
5532
|
+
ctx.putImageData(bridge.imageData, 0, 0);
|
|
5533
|
+
targetCtx.drawImage(canvas, dx, dy);
|
|
5598
5534
|
}
|
|
5599
5535
|
}
|
|
5600
|
-
|
|
5601
|
-
|
|
5602
|
-
|
|
5603
|
-
|
|
5604
|
-
|
|
5536
|
+
targetCtx.globalAlpha = 1;
|
|
5537
|
+
targetCtx.globalCompositeOperation = "source-over";
|
|
5538
|
+
};
|
|
5539
|
+
}
|
|
5540
|
+
|
|
5541
|
+
// src/Paint/Commit/AlphaMaskPaintBufferManager.ts
|
|
5542
|
+
function makeAlphaMaskPaintBufferManager(writer, canvasFactory = DEFAULT_CANVAS_FACTORY) {
|
|
5543
|
+
const pool = new TilePool(writer.config, makeAlphaMaskTile);
|
|
5544
|
+
const buffer = new AlphaMaskPaintBuffer(writer.config, pool);
|
|
5545
|
+
const draw = makeAlphaMaskPaintBufferCanvasRenderer(buffer, canvasFactory);
|
|
5546
|
+
return {
|
|
5547
|
+
clear: buffer.clear.bind(buffer),
|
|
5548
|
+
paintRect: buffer.paintRect.bind(buffer),
|
|
5549
|
+
paintAlphaMask: buffer.paintAlphaMask.bind(buffer),
|
|
5550
|
+
paintBinaryMask: buffer.paintBinaryMask.bind(buffer),
|
|
5551
|
+
commit: makeAlphaMaskPaintBufferCommitter(writer.accumulator, buffer),
|
|
5552
|
+
draw
|
|
5553
|
+
};
|
|
5554
|
+
}
|
|
5555
|
+
|
|
5556
|
+
// src/Paint/Commit/BinaryMaskPaintBufferCommitter.ts
|
|
5557
|
+
function makeBinaryMaskPaintBufferCommitter(accumulator, paintBuffer) {
|
|
5558
|
+
return function commitBinaryMaskPaintBufferToAccumulator(color, alpha = 255, blendFn = sourceOverPerfect) {
|
|
5559
|
+
return commitMaskPaintBuffer(accumulator, paintBuffer, color, alpha, blendFn, blendColorPixelDataBinaryMask);
|
|
5560
|
+
};
|
|
5561
|
+
}
|
|
5562
|
+
|
|
5563
|
+
// src/Paint/Render/BinaryMaskPaintBufferCanvasRenderer.ts
|
|
5564
|
+
function makeBinaryMaskPaintBufferCanvasRenderer(paintBuffer, canvasFactory = DEFAULT_CANVAS_FACTORY) {
|
|
5565
|
+
const config = paintBuffer.config;
|
|
5566
|
+
const tileSize = config.tileSize;
|
|
5567
|
+
const tileShift = config.tileShift;
|
|
5568
|
+
const tileArea = config.tileArea;
|
|
5569
|
+
const lookup = paintBuffer.lookup;
|
|
5570
|
+
const canvas = canvasFactory(tileSize, tileSize);
|
|
5571
|
+
const ctx = canvas.getContext("2d");
|
|
5572
|
+
if (!ctx) throw new Error(CANVAS_CTX_FAILED);
|
|
5573
|
+
ctx.imageSmoothingEnabled = false;
|
|
5574
|
+
const bridge = makePixelData(new ImageData(tileSize, tileSize));
|
|
5575
|
+
const view32 = bridge.data;
|
|
5576
|
+
return function drawPaintBuffer(targetCtx, color, alpha = 255, compOperation = "source-over") {
|
|
5577
|
+
if (alpha === 0) return;
|
|
5578
|
+
const baseSrcAlpha = color >>> 24;
|
|
5579
|
+
if (baseSrcAlpha === 0) return;
|
|
5580
|
+
targetCtx.globalAlpha = alpha / 255;
|
|
5581
|
+
targetCtx.globalCompositeOperation = compOperation;
|
|
5582
|
+
for (let i = 0; i < lookup.length; i++) {
|
|
5583
|
+
const tile = lookup[i];
|
|
5584
|
+
if (tile) {
|
|
5585
|
+
const data8 = tile.data;
|
|
5586
|
+
view32.fill(0);
|
|
5587
|
+
for (let p = 0; p < tileArea; p++) {
|
|
5588
|
+
if (data8[p] === 1) {
|
|
5589
|
+
view32[p] = color;
|
|
5590
|
+
}
|
|
5591
|
+
}
|
|
5592
|
+
const dx = tile.tx << tileShift;
|
|
5593
|
+
const dy = tile.ty << tileShift;
|
|
5594
|
+
ctx.putImageData(bridge.imageData, 0, 0);
|
|
5595
|
+
targetCtx.drawImage(canvas, dx, dy);
|
|
5596
|
+
}
|
|
5597
|
+
}
|
|
5598
|
+
targetCtx.globalAlpha = 1;
|
|
5599
|
+
targetCtx.globalCompositeOperation = "source-over";
|
|
5600
|
+
};
|
|
5601
|
+
}
|
|
5602
|
+
|
|
5603
|
+
// src/Paint/Commit/BinaryMaskPaintBufferManager.ts
|
|
5604
|
+
function makeBinaryMaskPaintBufferManager(writer, canvasFactory = DEFAULT_CANVAS_FACTORY) {
|
|
5605
|
+
const pool = new TilePool(writer.config, makeBinaryMaskTile);
|
|
5606
|
+
const buffer = new BinaryMaskPaintBuffer(writer.config, pool);
|
|
5607
|
+
const draw = makeBinaryMaskPaintBufferCanvasRenderer(buffer, canvasFactory);
|
|
5608
|
+
return {
|
|
5609
|
+
clear: buffer.clear.bind(buffer),
|
|
5610
|
+
paintRect: buffer.paintRect.bind(buffer),
|
|
5611
|
+
paintBinaryMask: buffer.paintBinaryMask.bind(buffer),
|
|
5612
|
+
commit: makeBinaryMaskPaintBufferCommitter(writer.accumulator, buffer),
|
|
5613
|
+
draw
|
|
5614
|
+
};
|
|
5615
|
+
}
|
|
5616
|
+
|
|
5617
|
+
// src/Paint/Commit/commitColorPaintBuffer.ts
|
|
5618
|
+
var SCRATCH_OPTS2 = {
|
|
5619
|
+
alpha: 255,
|
|
5620
|
+
blendFn: sourceOverPerfect,
|
|
5621
|
+
x: 0,
|
|
5622
|
+
y: 0,
|
|
5623
|
+
w: 0,
|
|
5624
|
+
h: 0
|
|
5605
5625
|
};
|
|
5626
|
+
function commitColorPaintBuffer(accumulator, paintBuffer, alpha = 255, blendFn = sourceOverPerfect, blendPixelDataFn = blendPixelData) {
|
|
5627
|
+
const config = accumulator.config;
|
|
5628
|
+
const tileShift = config.tileShift;
|
|
5629
|
+
const lookup = paintBuffer.lookup;
|
|
5630
|
+
SCRATCH_OPTS2.alpha = alpha;
|
|
5631
|
+
SCRATCH_OPTS2.blendFn = blendFn;
|
|
5632
|
+
for (let i = 0; i < lookup.length; i++) {
|
|
5633
|
+
const tile = lookup[i];
|
|
5634
|
+
if (tile) {
|
|
5635
|
+
const didChange = accumulator.storeTileBeforeState(tile.id, tile.tx, tile.ty);
|
|
5636
|
+
const dx = tile.tx << tileShift;
|
|
5637
|
+
const dy = tile.ty << tileShift;
|
|
5638
|
+
SCRATCH_OPTS2.x = dx;
|
|
5639
|
+
SCRATCH_OPTS2.y = dy;
|
|
5640
|
+
SCRATCH_OPTS2.w = tile.w;
|
|
5641
|
+
SCRATCH_OPTS2.h = tile.h;
|
|
5642
|
+
didChange(blendPixelDataFn(config.target, tile, SCRATCH_OPTS2));
|
|
5643
|
+
}
|
|
5644
|
+
}
|
|
5645
|
+
paintBuffer.clear();
|
|
5646
|
+
}
|
|
5606
5647
|
|
|
5607
|
-
// src/Paint/
|
|
5608
|
-
function
|
|
5648
|
+
// src/Paint/Commit/ColorPaintBufferCommitter.ts
|
|
5649
|
+
function makeColorPaintBufferCommitter(accumulator, paintBuffer) {
|
|
5650
|
+
return function commitColorPaintBufferToAccumulator(alpha = 255, blendFn = sourceOverPerfect) {
|
|
5651
|
+
return commitColorPaintBuffer(accumulator, paintBuffer, alpha, blendFn, blendPixelData);
|
|
5652
|
+
};
|
|
5653
|
+
}
|
|
5654
|
+
|
|
5655
|
+
// src/Paint/Render/ColorPaintBufferCanvasRenderer.ts
|
|
5656
|
+
function makeColorPaintBufferCanvasRenderer(paintBuffer, canvasFactory = DEFAULT_CANVAS_FACTORY) {
|
|
5609
5657
|
const config = paintBuffer.config;
|
|
5610
5658
|
const tileSize = config.tileSize;
|
|
5611
5659
|
const tileShift = config.tileShift;
|
|
5612
5660
|
const lookup = paintBuffer.lookup;
|
|
5613
|
-
const canvas =
|
|
5661
|
+
const canvas = canvasFactory(tileSize, tileSize);
|
|
5614
5662
|
const ctx = canvas.getContext("2d");
|
|
5615
5663
|
if (!ctx) throw new Error(CANVAS_CTX_FAILED);
|
|
5616
5664
|
ctx.imageSmoothingEnabled = false;
|
|
@@ -5631,6 +5679,21 @@ function makeColorPaintBufferCanvasRenderer(paintBuffer, offscreenCanvasClass =
|
|
|
5631
5679
|
};
|
|
5632
5680
|
}
|
|
5633
5681
|
|
|
5682
|
+
// src/Paint/Commit/ColorPaintBufferManager.ts
|
|
5683
|
+
function makeColorPaintBufferManager(writer, canvasFactory = DEFAULT_CANVAS_FACTORY) {
|
|
5684
|
+
const pool = new TilePool(writer.config, makePixelTile);
|
|
5685
|
+
const buffer = new ColorPaintBuffer(writer.config, pool);
|
|
5686
|
+
const draw = makeColorPaintBufferCanvasRenderer(buffer, canvasFactory);
|
|
5687
|
+
return {
|
|
5688
|
+
clear: buffer.clear.bind(buffer),
|
|
5689
|
+
paintRect: buffer.paintRect.bind(buffer),
|
|
5690
|
+
paintAlphaMask: buffer.paintAlphaMask.bind(buffer),
|
|
5691
|
+
paintBinaryMask: buffer.paintBinaryMask.bind(buffer),
|
|
5692
|
+
commit: makeColorPaintBufferCommitter(writer.accumulator, buffer),
|
|
5693
|
+
draw
|
|
5694
|
+
};
|
|
5695
|
+
}
|
|
5696
|
+
|
|
5634
5697
|
// src/Paint/makeCirclePaintMask.ts
|
|
5635
5698
|
function makeCirclePaintAlphaMask(size, fallOff = (d) => d) {
|
|
5636
5699
|
const area = size * size;
|
|
@@ -5768,12 +5831,14 @@ function makeReusablePixelData() {
|
|
|
5768
5831
|
};
|
|
5769
5832
|
}
|
|
5770
5833
|
|
|
5771
|
-
// src/Paint/PaintCursorRenderer.ts
|
|
5772
|
-
function makePaintCursorRenderer(
|
|
5773
|
-
const
|
|
5774
|
-
const
|
|
5775
|
-
|
|
5776
|
-
|
|
5834
|
+
// src/Paint/Render/PaintCursorRenderer.ts
|
|
5835
|
+
function makePaintCursorRenderer(reusableCanvasFactory) {
|
|
5836
|
+
const factory = reusableCanvasFactory ?? makeReusableOffscreenCanvas;
|
|
5837
|
+
const updateBuffer = factory();
|
|
5838
|
+
const {
|
|
5839
|
+
canvas,
|
|
5840
|
+
ctx
|
|
5841
|
+
} = updateBuffer(1, 1);
|
|
5777
5842
|
const getPixelData = makeReusablePixelData();
|
|
5778
5843
|
let _color = packColor(0, 255, 255, 255);
|
|
5779
5844
|
let _scale = 1;
|
|
@@ -5790,8 +5855,7 @@ function makePaintCursorRenderer(factory = (w, h) => new OffscreenCanvas(w, h))
|
|
|
5790
5855
|
currentMask = paintMask ?? currentMask;
|
|
5791
5856
|
_scale = scale ?? _scale;
|
|
5792
5857
|
_color = color ?? _color;
|
|
5793
|
-
|
|
5794
|
-
canvas.height = currentMask.h * _scale + 2 * _scale;
|
|
5858
|
+
updateBuffer(currentMask.w * _scale + 2 * _scale, currentMask.h * _scale + 2 * _scale);
|
|
5795
5859
|
if (currentMask.type === 1 /* BINARY */) {
|
|
5796
5860
|
if (currentMask.outlineType === 1 /* CIRCLE */) {
|
|
5797
5861
|
outline = makeCircleBinaryMaskOutline(currentMask.w, _scale);
|
|
@@ -5874,7 +5938,7 @@ function blendColorPixelDataMask(dst, color, mask, opts) {
|
|
|
5874
5938
|
}
|
|
5875
5939
|
|
|
5876
5940
|
// src/PixelData/blendColorPixelDataPaintAlphaMask.ts
|
|
5877
|
-
var
|
|
5941
|
+
var SCRATCH_OPTS3 = {
|
|
5878
5942
|
x: 0,
|
|
5879
5943
|
y: 0,
|
|
5880
5944
|
alpha: 255,
|
|
@@ -5883,15 +5947,15 @@ var SCRATCH_OPTS = {
|
|
|
5883
5947
|
function blendColorPixelDataPaintAlphaMask(dst, color, mask, x, y, alpha = 255, blendFn = sourceOverPerfect) {
|
|
5884
5948
|
const tx = x + mask.centerOffsetX;
|
|
5885
5949
|
const ty = y + mask.centerOffsetY;
|
|
5886
|
-
|
|
5887
|
-
|
|
5888
|
-
|
|
5889
|
-
|
|
5890
|
-
return blendColorPixelDataAlphaMask(dst, color, mask,
|
|
5950
|
+
SCRATCH_OPTS3.x = tx;
|
|
5951
|
+
SCRATCH_OPTS3.y = ty;
|
|
5952
|
+
SCRATCH_OPTS3.alpha = alpha;
|
|
5953
|
+
SCRATCH_OPTS3.blendFn = blendFn;
|
|
5954
|
+
return blendColorPixelDataAlphaMask(dst, color, mask, SCRATCH_OPTS3);
|
|
5891
5955
|
}
|
|
5892
5956
|
|
|
5893
5957
|
// src/PixelData/blendColorPixelDataPaintBinaryMask.ts
|
|
5894
|
-
var
|
|
5958
|
+
var SCRATCH_OPTS4 = {
|
|
5895
5959
|
x: 0,
|
|
5896
5960
|
y: 0,
|
|
5897
5961
|
alpha: 255,
|
|
@@ -5900,15 +5964,15 @@ var SCRATCH_OPTS2 = {
|
|
|
5900
5964
|
function blendColorPixelDataPaintBinaryMask(dst, color, mask, x, y, alpha = 255, blendFn = sourceOverPerfect) {
|
|
5901
5965
|
const tx = x + mask.centerOffsetX;
|
|
5902
5966
|
const ty = y + mask.centerOffsetY;
|
|
5903
|
-
|
|
5904
|
-
|
|
5905
|
-
|
|
5906
|
-
|
|
5907
|
-
return blendColorPixelDataBinaryMask(dst, color, mask,
|
|
5967
|
+
SCRATCH_OPTS4.x = tx;
|
|
5968
|
+
SCRATCH_OPTS4.y = ty;
|
|
5969
|
+
SCRATCH_OPTS4.alpha = alpha;
|
|
5970
|
+
SCRATCH_OPTS4.blendFn = blendFn;
|
|
5971
|
+
return blendColorPixelDataBinaryMask(dst, color, mask, SCRATCH_OPTS4);
|
|
5908
5972
|
}
|
|
5909
5973
|
|
|
5910
5974
|
// src/PixelData/blendColorPixelDataPaintMask.ts
|
|
5911
|
-
var
|
|
5975
|
+
var SCRATCH_OPTS5 = {
|
|
5912
5976
|
x: 0,
|
|
5913
5977
|
y: 0,
|
|
5914
5978
|
alpha: 255,
|
|
@@ -5917,14 +5981,14 @@ var SCRATCH_OPTS3 = {
|
|
|
5917
5981
|
function blendColorPixelDataPaintMask(dst, color, mask, x, y, alpha = 255, blendFn = sourceOverPerfect) {
|
|
5918
5982
|
const tx = x + mask.centerOffsetX;
|
|
5919
5983
|
const ty = y + mask.centerOffsetY;
|
|
5920
|
-
|
|
5921
|
-
|
|
5922
|
-
|
|
5923
|
-
|
|
5984
|
+
SCRATCH_OPTS5.x = tx;
|
|
5985
|
+
SCRATCH_OPTS5.y = ty;
|
|
5986
|
+
SCRATCH_OPTS5.alpha = alpha;
|
|
5987
|
+
SCRATCH_OPTS5.blendFn = blendFn;
|
|
5924
5988
|
if (mask.type === 1 /* BINARY */) {
|
|
5925
|
-
return blendColorPixelDataBinaryMask(dst, color, mask,
|
|
5989
|
+
return blendColorPixelDataBinaryMask(dst, color, mask, SCRATCH_OPTS5);
|
|
5926
5990
|
} else {
|
|
5927
|
-
return blendColorPixelDataAlphaMask(dst, color, mask,
|
|
5991
|
+
return blendColorPixelDataAlphaMask(dst, color, mask, SCRATCH_OPTS5);
|
|
5928
5992
|
}
|
|
5929
5993
|
}
|
|
5930
5994
|
|
|
@@ -5938,7 +6002,7 @@ function blendPixelDataMask(target, src, mask, opts) {
|
|
|
5938
6002
|
}
|
|
5939
6003
|
|
|
5940
6004
|
// src/PixelData/blendPixelDataPaintBuffer.ts
|
|
5941
|
-
var
|
|
6005
|
+
var SCRATCH_OPTS6 = {
|
|
5942
6006
|
x: 0,
|
|
5943
6007
|
y: 0,
|
|
5944
6008
|
alpha: 255,
|
|
@@ -5952,11 +6016,11 @@ function blendPixelDataPaintBuffer(target, paintBuffer, alpha = 255, blendFn, bl
|
|
|
5952
6016
|
if (tile) {
|
|
5953
6017
|
const x = tile.tx << tileShift;
|
|
5954
6018
|
const y = tile.ty << tileShift;
|
|
5955
|
-
|
|
5956
|
-
|
|
5957
|
-
|
|
5958
|
-
|
|
5959
|
-
blendPixelDataFn(target, tile,
|
|
6019
|
+
SCRATCH_OPTS6.x = x;
|
|
6020
|
+
SCRATCH_OPTS6.y = y;
|
|
6021
|
+
SCRATCH_OPTS6.alpha = alpha;
|
|
6022
|
+
SCRATCH_OPTS6.blendFn = blendFn;
|
|
6023
|
+
blendPixelDataFn(target, tile, SCRATCH_OPTS6);
|
|
5960
6024
|
}
|
|
5961
6025
|
}
|
|
5962
6026
|
}
|
|
@@ -6239,32 +6303,6 @@ function writePaintBufferToPixelData(target, paintBuffer, writePixelDataBufferFn
|
|
|
6239
6303
|
}
|
|
6240
6304
|
}
|
|
6241
6305
|
}
|
|
6242
|
-
|
|
6243
|
-
// src/Tile/MaskTile.ts
|
|
6244
|
-
var makeAlphaMaskTile = (id, tx, ty, tileSize, tileArea) => {
|
|
6245
|
-
return {
|
|
6246
|
-
tileType: 1 /* MASK */,
|
|
6247
|
-
type: 0 /* ALPHA */,
|
|
6248
|
-
data: new Uint8Array(tileArea),
|
|
6249
|
-
w: tileSize,
|
|
6250
|
-
h: tileSize,
|
|
6251
|
-
id,
|
|
6252
|
-
tx,
|
|
6253
|
-
ty
|
|
6254
|
-
};
|
|
6255
|
-
};
|
|
6256
|
-
var makeBinaryMaskTile = (id, tx, ty, tileSize, tileArea) => {
|
|
6257
|
-
return {
|
|
6258
|
-
tileType: 1 /* MASK */,
|
|
6259
|
-
type: 1 /* BINARY */,
|
|
6260
|
-
data: new Uint8Array(tileArea),
|
|
6261
|
-
w: tileSize,
|
|
6262
|
-
h: tileSize,
|
|
6263
|
-
id,
|
|
6264
|
-
tx,
|
|
6265
|
-
ty
|
|
6266
|
-
};
|
|
6267
|
-
};
|
|
6268
6306
|
export {
|
|
6269
6307
|
AlphaMaskPaintBuffer,
|
|
6270
6308
|
BASE_FAST_BLEND_MODE_FUNCTIONS,
|
|
@@ -6311,6 +6349,8 @@ export {
|
|
|
6311
6349
|
colorDistance,
|
|
6312
6350
|
colorDodgeFast,
|
|
6313
6351
|
colorDodgePerfect,
|
|
6352
|
+
commitColorPaintBuffer,
|
|
6353
|
+
commitMaskPaintBuffer,
|
|
6314
6354
|
copyImageData,
|
|
6315
6355
|
copyImageDataLike,
|
|
6316
6356
|
copyMask,
|
|
@@ -6383,11 +6423,15 @@ export {
|
|
|
6383
6423
|
linearLightPerfect,
|
|
6384
6424
|
makeAlphaMask,
|
|
6385
6425
|
makeAlphaMaskPaintBufferCanvasRenderer,
|
|
6426
|
+
makeAlphaMaskPaintBufferCommitter,
|
|
6427
|
+
makeAlphaMaskPaintBufferManager,
|
|
6386
6428
|
makeAlphaMaskTile,
|
|
6387
6429
|
makeBinaryMask,
|
|
6388
6430
|
makeBinaryMaskFromAlphaMask,
|
|
6389
6431
|
makeBinaryMaskOutline,
|
|
6390
6432
|
makeBinaryMaskPaintBufferCanvasRenderer,
|
|
6433
|
+
makeBinaryMaskPaintBufferCommitter,
|
|
6434
|
+
makeBinaryMaskPaintBufferManager,
|
|
6391
6435
|
makeBinaryMaskTile,
|
|
6392
6436
|
makeBlendModeRegistry,
|
|
6393
6437
|
makeCanvasFrameRenderer,
|
|
@@ -6398,6 +6442,8 @@ export {
|
|
|
6398
6442
|
makeClippedBlit,
|
|
6399
6443
|
makeClippedRect,
|
|
6400
6444
|
makeColorPaintBufferCanvasRenderer,
|
|
6445
|
+
makeColorPaintBufferCommitter,
|
|
6446
|
+
makeColorPaintBufferManager,
|
|
6401
6447
|
makeFastBlendModeRegistry,
|
|
6402
6448
|
makeFullPixelMutator,
|
|
6403
6449
|
makeHistoryAction,
|