Skip to content

Commit df541b6

Browse files
committed
Use getImagePixels
1 parent f69cee3 commit df541b6

File tree

2 files changed

+4
-18
lines changed

2 files changed

+4
-18
lines changed

Source/Core/Resource.js

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import DeveloperError from "./DeveloperError.js";
1010
import getAbsoluteUri from "./getAbsoluteUri.js";
1111
import getBaseUri from "./getBaseUri.js";
1212
import getExtensionFromUri from "./getExtensionFromUri.js";
13+
import getImagePixels from "./getImagePixels.js";
1314
import isBlobUri from "./isBlobUri.js";
1415
import isCrossOriginUrl from "./isCrossOriginUrl.js";
1516
import isDataUri from "./isDataUri.js";
@@ -349,21 +350,6 @@ Resource.createIfNeeded = function (resource) {
349350
});
350351
};
351352

352-
function getColorOfFirstPixel(imageBitmap) {
353-
const canvas = document.createElement("canvas");
354-
const context = canvas.getContext("2d");
355-
canvas.width = 1;
356-
canvas.height = 1;
357-
context.drawImage(imageBitmap, 0, 0, 1, 1);
358-
const imageData = context.getImageData(0, 0, 1, 1);
359-
return [
360-
imageData.data[0],
361-
imageData.data[1],
362-
imageData.data[2],
363-
imageData.data[3],
364-
];
365-
}
366-
367353
let supportsImageBitmapOptionsPromise;
368354
/**
369355
* A helper function to check whether createImageBitmap supports passing ImageBitmapOptions.
@@ -411,8 +397,8 @@ Resource.supportsImageBitmapOptions = function () {
411397
})
412398
.then(function (imageBitmaps) {
413399
// Check whether the colorSpaceConversion option had any effect on the green channel
414-
const colorWithOptions = getColorOfFirstPixel(imageBitmaps[0]);
415-
const colorWithDefaults = getColorOfFirstPixel(imageBitmaps[1]);
400+
const colorWithOptions = getImagePixels(imageBitmaps[0]);
401+
const colorWithDefaults = getImagePixels(imageBitmaps[1]);
416402
return colorWithOptions[1] !== colorWithDefaults[1];
417403
})
418404
.otherwise(function () {

Source/Core/getImagePixels.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const context2DsByWidthAndHeight = {};
88
*
99
* @function getImagePixels
1010
*
11-
* @param {HTMLImageElement} image The image to extract pixels from.
11+
* @param {HTMLImageElement|ImageBitmap} image The image to extract pixels from.
1212
* @param {Number} width The width of the image. If not defined, then image.width is assigned.
1313
* @param {Number} height The height of the image. If not defined, then image.height is assigned.
1414
* @returns {ImageData} The pixels of the image.

0 commit comments

Comments
 (0)