Skip to content

Commit b5805ca

Browse files
Merge pull request mozilla#18965 from Snuffleupagus/_goodSquareLength-static
Re-factor the `ImageResizer._goodSquareLength` definition
2 parents 0d42e56 + 8a2b954 commit b5805ca

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

src/core/image_resizer.js

+10-15
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,15 @@ const MAX_ERROR = 128;
3232
// should be a way faster to create the bitmap.
3333

3434
class ImageResizer {
35+
static #goodSquareLength = MIN_IMAGE_DIM;
36+
3537
constructor(imgData, isMask) {
3638
this._imgData = imgData;
3739
this._isMask = isMask;
3840
}
3941

4042
static needsToBeResized(width, height) {
41-
if (width <= this._goodSquareLength && height <= this._goodSquareLength) {
43+
if (width <= this.#goodSquareLength && height <= this.#goodSquareLength) {
4244
return false;
4345
}
4446

@@ -52,14 +54,14 @@ class ImageResizer {
5254
return area > this.MAX_AREA;
5355
}
5456

55-
if (area < this._goodSquareLength ** 2) {
57+
if (area < this.#goodSquareLength ** 2) {
5658
return false;
5759
}
5860

5961
// We try as much as possible to avoid to compute the max area.
6062
if (this._areGoodDims(width, height)) {
61-
this._goodSquareLength = Math.max(
62-
this._goodSquareLength,
63+
this.#goodSquareLength = Math.max(
64+
this.#goodSquareLength,
6365
Math.floor(Math.sqrt(width * height))
6466
);
6567
return false;
@@ -69,13 +71,13 @@ class ImageResizer {
6971
// some large canvas, so in the Firefox case this value (and MAX_DIM) can be
7072
// infered from prefs (MAX_AREA = gfx.max-alloc-size / 4, 4 is because of
7173
// RGBA).
72-
this._goodSquareLength = this._guessMax(
73-
this._goodSquareLength,
74+
this.#goodSquareLength = this._guessMax(
75+
this.#goodSquareLength,
7476
MAX_DIM,
7577
MAX_ERROR,
7678
0
7779
);
78-
const maxArea = (this.MAX_AREA = this._goodSquareLength ** 2);
80+
const maxArea = (this.MAX_AREA = this.#goodSquareLength ** 2);
7981

8082
return area > maxArea;
8183
}
@@ -93,12 +95,7 @@ class ImageResizer {
9395
return shadow(
9496
this,
9597
"MAX_AREA",
96-
this._guessMax(
97-
ImageResizer._goodSquareLength,
98-
this.MAX_DIM,
99-
MAX_ERROR,
100-
0
101-
) ** 2
98+
this._guessMax(this.#goodSquareLength, this.MAX_DIM, MAX_ERROR, 0) ** 2
10299
);
103100
}
104101

@@ -393,6 +390,4 @@ class ImageResizer {
393390
}
394391
}
395392

396-
ImageResizer._goodSquareLength = MIN_IMAGE_DIM;
397-
398393
export { ImageResizer };

0 commit comments

Comments
 (0)