Re-factor the ImageResizer._goodSquareLength definition
Move the `ImageResizer._goodSquareLength` definition into the class itself, since the current position shouldn't be necessary, and also convert it into an actually private field.
This commit is contained in:
parent
bde36f28be
commit
8a2b95418a
@ -32,13 +32,15 @@ const MAX_ERROR = 128;
|
|||||||
// should be a way faster to create the bitmap.
|
// should be a way faster to create the bitmap.
|
||||||
|
|
||||||
class ImageResizer {
|
class ImageResizer {
|
||||||
|
static #goodSquareLength = MIN_IMAGE_DIM;
|
||||||
|
|
||||||
constructor(imgData, isMask) {
|
constructor(imgData, isMask) {
|
||||||
this._imgData = imgData;
|
this._imgData = imgData;
|
||||||
this._isMask = isMask;
|
this._isMask = isMask;
|
||||||
}
|
}
|
||||||
|
|
||||||
static needsToBeResized(width, height) {
|
static needsToBeResized(width, height) {
|
||||||
if (width <= this._goodSquareLength && height <= this._goodSquareLength) {
|
if (width <= this.#goodSquareLength && height <= this.#goodSquareLength) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,14 +54,14 @@ class ImageResizer {
|
|||||||
return area > this.MAX_AREA;
|
return area > this.MAX_AREA;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (area < this._goodSquareLength ** 2) {
|
if (area < this.#goodSquareLength ** 2) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We try as much as possible to avoid to compute the max area.
|
// We try as much as possible to avoid to compute the max area.
|
||||||
if (this._areGoodDims(width, height)) {
|
if (this._areGoodDims(width, height)) {
|
||||||
this._goodSquareLength = Math.max(
|
this.#goodSquareLength = Math.max(
|
||||||
this._goodSquareLength,
|
this.#goodSquareLength,
|
||||||
Math.floor(Math.sqrt(width * height))
|
Math.floor(Math.sqrt(width * height))
|
||||||
);
|
);
|
||||||
return false;
|
return false;
|
||||||
@ -69,13 +71,13 @@ class ImageResizer {
|
|||||||
// some large canvas, so in the Firefox case this value (and MAX_DIM) can be
|
// some large canvas, so in the Firefox case this value (and MAX_DIM) can be
|
||||||
// infered from prefs (MAX_AREA = gfx.max-alloc-size / 4, 4 is because of
|
// infered from prefs (MAX_AREA = gfx.max-alloc-size / 4, 4 is because of
|
||||||
// RGBA).
|
// RGBA).
|
||||||
this._goodSquareLength = this._guessMax(
|
this.#goodSquareLength = this._guessMax(
|
||||||
this._goodSquareLength,
|
this.#goodSquareLength,
|
||||||
MAX_DIM,
|
MAX_DIM,
|
||||||
MAX_ERROR,
|
MAX_ERROR,
|
||||||
0
|
0
|
||||||
);
|
);
|
||||||
const maxArea = (this.MAX_AREA = this._goodSquareLength ** 2);
|
const maxArea = (this.MAX_AREA = this.#goodSquareLength ** 2);
|
||||||
|
|
||||||
return area > maxArea;
|
return area > maxArea;
|
||||||
}
|
}
|
||||||
@ -93,12 +95,7 @@ class ImageResizer {
|
|||||||
return shadow(
|
return shadow(
|
||||||
this,
|
this,
|
||||||
"MAX_AREA",
|
"MAX_AREA",
|
||||||
this._guessMax(
|
this._guessMax(this.#goodSquareLength, this.MAX_DIM, MAX_ERROR, 0) ** 2
|
||||||
ImageResizer._goodSquareLength,
|
|
||||||
this.MAX_DIM,
|
|
||||||
MAX_ERROR,
|
|
||||||
0
|
|
||||||
) ** 2
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -393,6 +390,4 @@ class ImageResizer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageResizer._goodSquareLength = MIN_IMAGE_DIM;
|
|
||||||
|
|
||||||
export { ImageResizer };
|
export { ImageResizer };
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user