From 6b83c2dad2307fc49e18b015a907cff5f42672fc Mon Sep 17 00:00:00 2001 From: Alexandre Rousseau Date: Sat, 8 Apr 2023 14:39:28 +0200 Subject: [PATCH] chore: use `Uint8ClampedArray` --- src/color-thief-node.js | 2 +- src/color-thief.js | 2 +- src/core.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/color-thief-node.js b/src/color-thief-node.js index efc73b3..cb1f1c6 100644 --- a/src/color-thief-node.js +++ b/src/color-thief-node.js @@ -15,7 +15,7 @@ function createPixelArray(imgData, pixelCount, quality) { // If pixel is mostly opaque and not white if (typeof a === 'undefined' || a >= 125) { if (!(r > 250 && g > 250 && b > 250)) { - pixelArray.push([r, g, b]); + pixelArray.push(new Uint8ClampedArray([r, g, b])); } } } diff --git a/src/color-thief.js b/src/color-thief.js index 82c14bc..c85deb2 100644 --- a/src/color-thief.js +++ b/src/color-thief.js @@ -116,7 +116,7 @@ ColorThief.prototype.getImageData = function(imageUrl, callback) { xhr.responseType = 'arraybuffer'; xhr.onload = function() { if (this.status == 200) { - let uInt8Array = new Uint8Array(this.response); + let uInt8Array = new Uint8ClampedArray(this.response); i = uInt8Array.length; let binaryString = new Array(i); for (let i = 0; i < uInt8Array.length; i++){ diff --git a/src/core.js b/src/core.js index f5fe976..75a8ccf 100644 --- a/src/core.js +++ b/src/core.js @@ -12,7 +12,7 @@ function createPixelArray(imgData, pixelCount, quality) { // If pixel is mostly opaque and not white if (typeof a === 'undefined' || a >= 125) { if (!(r > 250 && g > 250 && b > 250)) { - pixelArray.push([r, g, b]); + pixelArray.push(new Uint8ClampedArray([r, g, b])); } } }