mirror of
https://github.com/He4eT/browser-milje-2077.git
synced 2026-05-04 17:07:24 +00:00
Cleaup
This commit is contained in:
parent
7dcf6efdef
commit
5a8128c25f
5 changed files with 42 additions and 49 deletions
|
|
@ -179,20 +179,27 @@ function getCanvas(size) {
|
|||
|
||||
/** @see https://stackoverflow.com/questions/3448347/how-to-scale-an-imagedata-in-html-canvas */
|
||||
function scaleImageData(imageData, scale, ctx) {
|
||||
const scaled = ctx.createImageData(imageData.width * scale, imageData.height * scale)
|
||||
const scaled = ctx.createImageData(
|
||||
imageData.width * scale,
|
||||
imageData.height * scale,
|
||||
)
|
||||
const subLine = ctx.createImageData(scale, 1).data
|
||||
for (let row = 0; row < imageData.height; row++) {
|
||||
for (let col = 0; col < imageData.width; col++) {
|
||||
const sourcePixel = imageData.data.subarray(
|
||||
(row * imageData.width + col) * 4,
|
||||
(row * imageData.width + col) * 4 + 4)
|
||||
(row * imageData.width + col) * 4 + 4,
|
||||
)
|
||||
for (let x = 0; x < scale; x++) {
|
||||
subLine.set(sourcePixel, x * 4)
|
||||
}
|
||||
for (let y = 0; y < scale; y++) {
|
||||
const destRow = row * scale + y
|
||||
const destCol = col * scale
|
||||
scaled.data.set(subLine, (destRow * scaled.width + destCol) * 4)
|
||||
scaled.data.set(
|
||||
subLine,
|
||||
(destRow * scaled.width + destCol) * 4,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue