Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

never use Uint8ClampedArray with texSubImage2D #8199

Merged
merged 1 commit into from
Apr 25, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/util/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ type Point = {
function createImage(image: *, {width, height}: Size, channels: number, data?: Uint8Array | Uint8ClampedArray) {
if (!data) {
data = new Uint8Array(width * height * channels);
} else if (data instanceof Uint8ClampedArray) {
data = new Uint8Array(data.buffer);
} else if (data.length !== width * height * channels) {
throw new RangeError('mismatched image size');
}
Expand Down Expand Up @@ -81,7 +83,7 @@ function copyImage(srcImg: *, dstImg: *, srcPt: Point, dstPt: Point, size: Size,
export class AlphaImage {
width: number;
height: number;
data: Uint8Array | Uint8ClampedArray;
data: Uint8Array;

constructor(size: Size, data?: Uint8Array | Uint8ClampedArray) {
createImage(this, size, 1, data);
Expand All @@ -105,7 +107,10 @@ export class AlphaImage {
export class RGBAImage {
width: number;
height: number;
data: Uint8Array | Uint8ClampedArray;

// data must be a Uint8Array instead of Uint8ClampedArray because texImage2D does not
// support Uint8ClampedArray in all browsers
data: Uint8Array;

constructor(size: Size, data?: Uint8Array | Uint8ClampedArray) {
createImage(this, size, 4, data);
Expand All @@ -118,6 +123,8 @@ export class RGBAImage {
replace(data: Uint8Array | Uint8ClampedArray, copy?: boolean) {
if (copy) {
this.data.set(data);
} else if (data instanceof Uint8ClampedArray) {
this.data = new Uint8Array(data.buffer);
} else {
this.data = data;
}
Expand Down