decord/source/modules/media_uploads/ImageEncodingLadder.tsx

103 lines
3.6 KiB
TypeScript
Raw Normal View History

2026-09-03 10:05:34 +00:00
// Module ID: 5116
// Function ID: 5117
2026-07-20 16:05:17 +00:00
// Name: getAdaptiveImageCompressionQuality
2026-09-02 09:53:35 +00:00
// Dependencies: [673, 2]
2026-07-23 10:11:24 +00:00
2026-09-03 10:05:34 +00:00
// Module 5116 (getAdaptiveImageCompressionQuality)
2026-08-24 06:08:38 +00:00
import set from "set" /* 2 */;
2026-09-02 09:53:35 +00:00
import ME from "ME" /* 673 */;
2026-07-20 16:05:17 +00:00
2026-08-24 06:08:38 +00:00
function getAdaptiveImageCompressionQuality(width, ADAPTIVE_COMPRESSION_CONFIG) {
2026-07-20 16:05:17 +00:00
if (ADAPTIVE_COMPRESSION_CONFIG.useAdaptiveCompression) {
2026-08-24 06:08:38 +00:00
if (null != width.width) {
if (null != width.height) {
const result = width.width * width.height;
2026-07-20 16:05:17 +00:00
if (result <= obj.SMALL) {
let HIGH5 = ADAPTIVE_COMPRESSION_CONFIG.veryHighQuality;
2026-07-29 08:29:29 +00:00
if (HIGH5 == null) {
2026-07-20 16:05:17 +00:00
HIGH5 = CompressionQuality.HIGH;
}
let HIGH = HIGH5;
2026-07-29 08:29:29 +00:00
} else if (result <= tmp11.MEDIUM) {
2026-07-20 16:05:17 +00:00
let HIGH4 = ADAPTIVE_COMPRESSION_CONFIG.highQuality;
2026-07-29 08:29:29 +00:00
if (HIGH4 == null) {
2026-07-20 16:05:17 +00:00
HIGH4 = CompressionQuality.HIGH;
}
HIGH = HIGH4;
2026-07-29 08:29:29 +00:00
} else if (result <= tmp11.LARGE) {
2026-07-20 16:05:17 +00:00
let HIGH3 = ADAPTIVE_COMPRESSION_CONFIG.mediumQuality;
2026-07-29 08:29:29 +00:00
if (HIGH3 == null) {
2026-07-20 16:05:17 +00:00
HIGH3 = CompressionQuality.HIGH;
}
HIGH = HIGH3;
2026-07-29 08:29:29 +00:00
} else if (result <= tmp11.VERY_LARGE) {
2026-07-20 16:05:17 +00:00
let HIGH2 = ADAPTIVE_COMPRESSION_CONFIG.lowQuality;
2026-07-29 08:29:29 +00:00
if (HIGH2 == null) {
2026-07-20 16:05:17 +00:00
HIGH2 = CompressionQuality.HIGH;
}
HIGH = HIGH2;
} else {
HIGH = ADAPTIVE_COMPRESSION_CONFIG.veryLowQuality;
2026-07-29 08:29:29 +00:00
if (HIGH == null) {
2026-07-20 16:05:17 +00:00
HIGH = CompressionQuality.HIGH;
}
}
return HIGH;
}
}
return CompressionQuality.HIGH;
} else {
return CompressionQuality.HIGH;
}
}
2026-08-24 06:08:38 +00:00
const CompressionQuality = ME.CompressionQuality;
2026-07-23 10:11:24 +00:00
let obj = { SMALL: 921600, MEDIUM: 2073600, LARGE: 3686400, VERY_LARGE: 8294400 };
obj = { useAdaptiveCompression: true, veryHighQuality: 0.8, highQuality: 0.7, mediumQuality: 0.6, lowQuality: 0.5, veryLowQuality: 0.4, useOriginalIfSmaller: true };
2026-07-29 08:29:29 +00:00
let prototype;
prototype = function ImageEncodingLadder() {
return Object.create(new.target.prototype);
}.prototype;
prototype["selectEncodingConfig"] = function selectEncodingConfig(width) {
({ targetWidth, targetHeight } = prototype.clampDimensions(width.width, width.height, 3840, 2160));
if (width.width === targetWidth) {
if (width.height === targetHeight) {
2026-08-24 06:08:38 +00:00
obj = { compressionQuality: null, targetWidth: null, targetHeight: null };
2026-07-29 08:29:29 +00:00
obj = { width: null, height: null };
obj[0] = targetWidth;
obj[1] = targetHeight;
obj[0] = 100 * getAdaptiveImageCompressionQuality(obj, obj);
obj[1] = targetWidth;
obj[2] = targetHeight;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
return obj;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
let num = obj.lowQuality;
if (num == null) {
num = 0.5;
}
obj = { compressionQuality: 100 * num, targetWidth, targetHeight };
};
prototype["clampDimensions"] = function clampDimensions(width, height, arg2, arg3) {
const bound = Math.max(width, height);
const bound1 = Math.min(width, height);
const bound2 = Math.max(arg2, arg3);
const bound3 = Math.min(arg2, arg3);
if (bound <= bound2) {
if (bound1 <= bound3) {
2026-08-24 06:08:38 +00:00
obj = { targetWidth: null, targetHeight: null };
2026-07-29 08:29:29 +00:00
obj[0] = width;
obj[1] = height;
2026-07-20 16:05:17 +00:00
return obj;
}
2026-07-29 08:29:29 +00:00
}
const bound4 = Math.min(bound2 / bound, bound3 / bound1);
obj = { targetWidth: Math.max(1, Math.round(width * bound4)), targetHeight: Math.max(1, Math.round(height * bound4)) };
return obj;
};
2026-08-24 06:08:38 +00:00
let result = set.fileFinishedImporting("modules/media_uploads/ImageEncodingLadder.tsx");
2026-07-21 06:55:02 +00:00
export const IMAGE_COMPRESSION_THRESHOLDS = obj;
export const ADAPTIVE_COMPRESSION_CONFIG = obj;
export { getAdaptiveImageCompressionQuality };
2026-07-29 08:29:29 +00:00
export const ImageEncodingLadder = prototype;