Skip to content
This repository was archived by the owner on Jul 26, 2025. It is now read-only.

Commit e78e8d2

Browse files
committed
feat wip use setBlended pixel for drawing lines
1 parent ec04a57 commit e78e8d2

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

src/Image.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,9 @@ export class Image {
437437
channel: number,
438438
value: number,
439439
): void {
440-
this.data[(row * this.width + column) * this.channels + channel] = value;
440+
if (column >= 0 && column < this.width && row >= 0 && row < this.height) {
441+
this.data[(row * this.width + column) * this.channels + channel] = value;
442+
}
441443
}
442444

443445
/**

src/draw/drawLineOnImage.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Image } from '../Image';
44
import { Point } from '../utils/geometry/points';
55
import { getDefaultColor } from '../utils/getDefaultColor';
66
import { getOutputImage } from '../utils/getOutputImage';
7+
import { setBlendedPixel } from '../utils/setBlendedPixel';
78
import checkProcessable from '../utils/validators/checkProcessable';
89
import { validateColor } from '../utils/validators/validators';
910

@@ -56,7 +57,7 @@ export function drawLineOnImage(
5657
Math.round(origin.column + to.column),
5758
Math.round(origin.row + to.row),
5859
(column: number, row: number) => {
59-
newImage.setVisiblePixel(column, row, color);
60+
setBlendedPixel(newImage, column, row, { color });
6061
},
6162
);
6263
return newImage;

src/utils/setBlendedPixel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ export function setBlendedPixel(
2828
const { color = getDefaultColor(image) } = options;
2929

3030
if (!image.alpha) {
31-
image.setPixel(column, row, color);
31+
image.setVisiblePixel(column, row, color);
3232
} else {
3333
assert(image instanceof Image);
3434

3535
const sourceAlpha = color.at(-1) as number;
3636

3737
if (sourceAlpha === image.maxValue) {
38-
image.setPixel(column, row, color);
38+
image.setVisiblePixel(column, row, color);
3939
return;
4040
}
4141

0 commit comments

Comments
 (0)