decord/beta/source/modules/media_uploads/ImageEncodingLadder.tsx

100 lines
3.6 KiB
TypeScript
Raw Normal View History

2026-10-07 22:43:51 +00:00
// Module ID: 7297
// Function ID: 7298
// Name: ImageEncodingLadder
2026-10-07 22:43:51 +00:00
// Dependencies: [1085, 2]
2026-10-07 22:43:51 +00:00
// Module 7297 (ImageEncodingLadder)
import Constants from "Constants" /* 1085 */;
2026-10-01 14:13:23 +00:00
import size_mod from "module_2" /* 2 */;
function getAdaptiveImageCompressionQuality(size, ADAPTIVE_COMPRESSION_CONFIG) {
if (ADAPTIVE_COMPRESSION_CONFIG.useAdaptiveCompression) {
if (null != size.width) {
if (null != size.height) {
2026-10-01 14:13:23 +00:00
let HIGH;
const result = size.width * size.height;
if (result <= obj.SMALL) {
let HIGH5 = ADAPTIVE_COMPRESSION_CONFIG.veryHighQuality;
if (HIGH5 == null) {
HIGH5 = CompressionQuality.HIGH;
}
2026-10-01 14:13:23 +00:00
HIGH = HIGH5;
} else if (result <= obj.MEDIUM) {
let HIGH4 = ADAPTIVE_COMPRESSION_CONFIG.highQuality;
if (HIGH4 == null) {
HIGH4 = CompressionQuality.HIGH;
}
HIGH = HIGH4;
2026-10-01 14:13:23 +00:00
} else if (result <= obj.LARGE) {
let HIGH3 = ADAPTIVE_COMPRESSION_CONFIG.mediumQuality;
if (HIGH3 == null) {
HIGH3 = CompressionQuality.HIGH;
}
HIGH = HIGH3;
2026-10-01 14:13:23 +00:00
} else if (result <= obj.VERY_LARGE) {
let HIGH2 = ADAPTIVE_COMPRESSION_CONFIG.lowQuality;
if (HIGH2 == null) {
HIGH2 = CompressionQuality.HIGH;
}
HIGH = HIGH2;
} else {
HIGH = ADAPTIVE_COMPRESSION_CONFIG.veryLowQuality;
if (HIGH == null) {
HIGH = CompressionQuality.HIGH;
}
}
return HIGH;
}
}
return CompressionQuality.HIGH;
} else {
return CompressionQuality.HIGH;
}
}
const CompressionQuality = Constants.CompressionQuality;
const IMAGE_COMPRESSION_THRESHOLDS = { SMALL: 921600, MEDIUM: 2073600, LARGE: 3686400, VERY_LARGE: 8294400 };
let obj2 = { useAdaptiveCompression: true, veryHighQuality: 0.8, highQuality: 0.7, mediumQuality: 0.6, lowQuality: 0.5, veryLowQuality: 0.4, useOriginalIfSmaller: true };
2026-10-01 14:13:23 +00:00
class ImageEncodingLadder {
static selectEncodingConfig(size1) {
let targetHeight;
let targetWidth;
({ targetWidth, targetHeight } = ImageEncodingLadder.clampDimensions(size1.width, size1.height, 3840, 2160));
ImageEncodingLadder.clampDimensions(size1.width, size1.height, 3840, 2160);
if (size1.width === targetWidth) {
let obj;
if (size1.height === targetHeight) {
obj2 = { compressionQuality: 100 * getAdaptiveImageCompressionQuality(size, obj2), targetWidth, targetHeight };
size = { width: targetWidth, height: targetHeight };
obj = obj2;
}
return obj;
}
2026-10-01 14:13:23 +00:00
let num = obj2.lowQuality;
if (num == null) {
num = 0.5;
}
obj = { compressionQuality: 100 * num, targetWidth, targetHeight };
}
2026-10-01 14:13:23 +00:00
static 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) {
return { targetWidth: width, targetHeight: height };
}
}
2026-10-01 14:13:23 +00:00
const bound4 = Math.min(bound2 / bound, bound3 / bound1);
const obj = { targetWidth: Math.max(1, Math.round(width * bound4)), targetHeight: Math.max(1, Math.round(height * bound4)) };
return obj;
}
2026-10-01 14:13:23 +00:00
}
let size = size_mod;
let result = size.fileFinishedImporting("modules/media_uploads/ImageEncodingLadder.tsx");
export { IMAGE_COMPRESSION_THRESHOLDS };
export const ADAPTIVE_COMPRESSION_CONFIG = obj2;
export { getAdaptiveImageCompressionQuality };
2026-10-01 14:13:23 +00:00
export { ImageEncodingLadder };