mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-14 17:49:52 +00:00
Rename variables for readability
Changes `cqlevel` to `quality`, and `cqAlphaLevel` to `qualityAlpha`
This commit is contained in:
@@ -16,9 +16,9 @@ struct AvifOptions {
|
||||
// [0 - 100]
|
||||
// 0 = worst quality
|
||||
// 100 = lossless
|
||||
int cqLevel;
|
||||
// As above, but -1 means 'use cqLevel'
|
||||
int cqAlphaLevel;
|
||||
int quality;
|
||||
// As above, but -1 means 'use quality'
|
||||
int qualityAlpha;
|
||||
// [0 - 6]
|
||||
// Creates 2^n tiles in that dimension
|
||||
int tileRowsLog2;
|
||||
@@ -67,8 +67,8 @@ val encode(std::string buffer, int width, int height, AvifOptions options) {
|
||||
break;
|
||||
}
|
||||
|
||||
bool lossless = options.cqLevel == AVIF_QUANTIZER_LOSSLESS &&
|
||||
options.cqAlphaLevel <= AVIF_QUANTIZER_LOSSLESS &&
|
||||
bool lossless = options.quality == AVIF_QUANTIZER_LOSSLESS &&
|
||||
options.qualityAlpha <= AVIF_QUANTIZER_LOSSLESS &&
|
||||
format == AVIF_PIXEL_FORMAT_YUV444;
|
||||
|
||||
avifImage* image = avifImageCreate(width, height, depth, format);
|
||||
@@ -100,12 +100,12 @@ val encode(std::string buffer, int width, int height, AvifOptions options) {
|
||||
std::to_string(options.sharpness).c_str());
|
||||
RETURN_NULL_IF_NOT_EQUALS(status, AVIF_RESULT_OK);
|
||||
|
||||
encoder->quality = options.cqLevel;
|
||||
if (options.cqAlphaLevel != -1) {
|
||||
encoder->qualityAlpha = options.cqAlphaLevel;
|
||||
encoder->quality = options.quality;
|
||||
if (options.qualityAlpha != -1) {
|
||||
encoder->qualityAlpha = options.qualityAlpha;
|
||||
}
|
||||
|
||||
if (options.tune == 2 || (options.tune == 0 && options.cqLevel <= 32)) {
|
||||
if (options.tune == 2 || (options.tune == 0 && options.quality <= 32)) {
|
||||
status = avifEncoderSetCodecSpecificOption(encoder, "tune", "ssim");
|
||||
RETURN_NULL_IF_NOT_EQUALS(status, AVIF_RESULT_OK);
|
||||
}
|
||||
@@ -139,8 +139,8 @@ val encode(std::string buffer, int width, int height, AvifOptions options) {
|
||||
|
||||
EMSCRIPTEN_BINDINGS(my_module) {
|
||||
value_object<AvifOptions>("AvifOptions")
|
||||
.field("cqLevel", &AvifOptions::cqLevel)
|
||||
.field("cqAlphaLevel", &AvifOptions::cqAlphaLevel)
|
||||
.field("quality", &AvifOptions::quality)
|
||||
.field("qualityAlpha", &AvifOptions::qualityAlpha)
|
||||
.field("tileRowsLog2", &AvifOptions::tileRowsLog2)
|
||||
.field("tileColsLog2", &AvifOptions::tileColsLog2)
|
||||
.field("speed", &AvifOptions::speed)
|
||||
|
||||
4
codecs/avif/enc/avif_enc.d.ts
vendored
4
codecs/avif/enc/avif_enc.d.ts
vendored
@@ -5,9 +5,9 @@ export const enum AVIFTune {
|
||||
}
|
||||
|
||||
export interface EncodeOptions {
|
||||
cqLevel: number;
|
||||
quality: number;
|
||||
qualityAlpha: number;
|
||||
denoiseLevel: number;
|
||||
cqAlphaLevel: number;
|
||||
tileRowsLog2: number;
|
||||
tileColsLog2: number;
|
||||
speed: number;
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -63,23 +63,23 @@ export class Options extends Component<Props, State> {
|
||||
const { options } = props;
|
||||
|
||||
const lossless =
|
||||
options.cqLevel === 0 &&
|
||||
options.cqAlphaLevel <= 0 &&
|
||||
options.quality === 0 &&
|
||||
options.qualityAlpha <= 0 &&
|
||||
options.subsample == 3;
|
||||
|
||||
const separateAlpha = options.cqAlphaLevel !== -1;
|
||||
const separateAlpha = options.qualityAlpha !== -1;
|
||||
|
||||
const cqLevel = lossless ? defaultOptions.cqLevel : options.cqLevel;
|
||||
const quality = lossless ? defaultOptions.quality : options.quality;
|
||||
|
||||
// Create default form state from options
|
||||
return {
|
||||
options,
|
||||
lossless,
|
||||
quality: cqLevel,
|
||||
quality: quality,
|
||||
separateAlpha,
|
||||
alphaQuality: separateAlpha
|
||||
? options.cqAlphaLevel
|
||||
: defaultOptions.cqLevel,
|
||||
? options.qualityAlpha
|
||||
: defaultOptions.quality,
|
||||
subsample:
|
||||
options.subsample === 0 || lossless
|
||||
? defaultOptions.subsample
|
||||
@@ -128,8 +128,8 @@ export class Options extends Component<Props, State> {
|
||||
};
|
||||
|
||||
const newOptions: EncodeOptions = {
|
||||
cqLevel: optionState.lossless ? MAX_QUALITY : optionState.quality,
|
||||
cqAlphaLevel:
|
||||
quality: optionState.lossless ? MAX_QUALITY : optionState.quality,
|
||||
qualityAlpha:
|
||||
optionState.lossless || !optionState.separateAlpha
|
||||
? -1 // default AVIF alphaLevel
|
||||
: optionState.alphaQuality,
|
||||
|
||||
@@ -18,8 +18,8 @@ export const label = 'AVIF';
|
||||
export const mimeType = 'image/avif';
|
||||
export const extension = 'avif';
|
||||
export const defaultOptions: EncodeOptions = {
|
||||
cqLevel: 50,
|
||||
cqAlphaLevel: -1,
|
||||
quality: 50,
|
||||
qualityAlpha: -1,
|
||||
denoiseLevel: 0,
|
||||
tileColsLog2: 0,
|
||||
tileRowsLog2: 0,
|
||||
|
||||
Reference in New Issue
Block a user