Skip to content

Commit a42c31c

Browse files
committed
mutate the energy array instead of allocating a new one in removeSeam
1 parent e6b1808 commit a42c31c

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

Diff for: index.ts

+3-6
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,13 @@ function dbgEnergySum(energySum: Uint32Array) {
111111
}
112112

113113
// remove seams in remove from data, returning a new array.
114-
// TODO mutate data instead of allocating a new array
115114
function removeSeam(
116115
data: Uint8ClampedArray,
117116
width: number,
118117
height: number,
119118
remove: Uint32Array,
120119
): Uint8ClampedArray {
121120
const data32 = new Uint32Array(data.buffer);
122-
const newData = new Uint8ClampedArray((width - 1) * height * 4);
123-
const buf32 = new Uint32Array(newData.buffer);
124121

125122
let offset = 0;
126123
for (let y = 0; y < height; y++) {
@@ -130,13 +127,13 @@ function removeSeam(
130127
// pixels been removed, skip over it
131128
offset++;
132129
}
133-
if (x < width) {
134-
buf32[y * (width - 1) + x] = data32[y * (width - 1) + x + offset];
130+
if (x < width && offset > 0) {
131+
data32[y * (width - 1) + x] = data32[y * (width - 1) + x + offset];
135132
}
136133
}
137134
}
138135

139-
return newData;
136+
return data;
140137
}
141138

142139
function diff(pixel1: number, pixel2: number): number {

0 commit comments

Comments
 (0)