(texture, width, height)
| 307 | } |
| 308 | |
| 309 | function normalizeTexture (texture, width, height) { |
| 310 | let result = new Uint8Array(texture.length); |
| 311 | let id = 0; |
| 312 | for (let i = height - 1; i >= 0; i--) { |
| 313 | for (let j = 0; j < width; j++) { |
| 314 | let nid = i * width * 4 + j * 4; |
| 315 | result[nid + 0] = clamp01(texture[id + 0]) * 255; |
| 316 | result[nid + 1] = clamp01(texture[id + 1]) * 255; |
| 317 | result[nid + 2] = clamp01(texture[id + 2]) * 255; |
| 318 | result[nid + 3] = clamp01(texture[id + 3]) * 255; |
| 319 | id += 4; |
| 320 | } |
| 321 | } |
| 322 | return result; |
| 323 | } |
| 324 | |
| 325 | function clamp01 (input) { |
| 326 | return Math.min(Math.max(input, 0), 1); |
no test coverage detected