refacto ts + ajout de dessin simple + ajout pinceau
WIP lib graphique
This commit is contained in:
@@ -58,9 +58,9 @@ async function readImgFile(filepath) {
|
||||
/**
|
||||
* @param { number } x
|
||||
* @param { number } y
|
||||
* @param { import('@jimp/core').Bitmap } bitmap
|
||||
* @param { import('@jimp/core').Bitmap | Pencil } bitmap
|
||||
*/
|
||||
function drawBitmap(x, y, bitmap) {
|
||||
function drawBitmap(x, y, bitmap, handleTransparency = true) {
|
||||
for(let dy = 0; dy < bitmap.height; dy++) {
|
||||
let bitmapLineEnd = bitmap.width * screen.byteDepth * (dy + 1)
|
||||
let bitmapLineStart = bitmap.width * screen.byteDepth * dy
|
||||
@@ -94,7 +94,25 @@ function drawBitmap(x, y, bitmap) {
|
||||
|
||||
|
||||
const line = bitmap.data.subarray(bitmapLineStart, bitmapLineEnd)
|
||||
buffer.set(Array.from(line), dx * screen.byteDepth + screen.width * (dy + y) * screen.byteDepth)
|
||||
|
||||
const bufferPlacement = dx * screen.byteDepth + screen.width * (dy + y) * screen.byteDepth
|
||||
|
||||
if(handleTransparency) {
|
||||
const currentLine = buffer.subarray(bufferPlacement, bufferPlacement + line.length)
|
||||
for(let i=0; i < line.length; i += 4) {
|
||||
const transparency = line.readUInt8(i+3) / 255
|
||||
if(transparency < 1) {
|
||||
/** @type { Uint8Array } */
|
||||
const newLine = new Uint8Array(3)
|
||||
for(let j=0; j < 3; j++) {
|
||||
newLine[j] = (currentLine.readUInt8(j+i)*1-transparency + line.readUInt8(j+i)*transparency)
|
||||
}
|
||||
line.set(newLine, i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
buffer.set(Array.from(line), bufferPlacement)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user