Skip to content

enable-chroma-deltaq enabled by default in libavif 1.4.0? #3088

@radarhere

Description

@radarhere

In libavif 1.3.0 and libavif 1.4.0, enable-chroma-deltaq is supposed to be disabled by default

printf(" enable-chroma-deltaq=B : Enable delta quantization in chroma planes. 0=disable (default), 1=enable\n");

printf(" enable-chroma-deltaq=B : Enable delta quantization in chroma planes. 0=disable (default), 1=enable\n");

However, when I try libavif 1.4.0, I find that it is enabled by default in some circumstances.

I looked through the release notes and the diff, but I'm not seeing anything that could have led to this. Do you have any explanation for why this would be?

Here is the simplified C code that I've put together to trigger the issue.

avifEncoder *encoder = avifEncoderCreate();
if (!encoder) {
	PyErr_SetString(PyExc_MemoryError, "Can't allocate encoder");
	return NULL;
}

int advanced;
if (!PyArg_ParseTuple(args, "I", &advanced)) {
	return NULL;
}
if (advanced != -1) {
	avifResult result = avifEncoderSetCodecSpecificOption(encoder, "enable-chroma-deltaq", advanced == 0 ? "0" : "1");
	printf("Set enable-chroma-deltaq to %d\n", advanced);
	if (result != AVIF_RESULT_OK) {
		PyErr_Format(exc_type_for_avif_result(result), "Setting advanced codec options failed: %s", avifResultToString(result));
		return NULL;
	}
} else {
	printf("Do not set enable-chroma-deltaq\n");
}

avifImage *image = avifImageCreateEmpty();
if (image == NULL) {
	PyErr_SetString(PyExc_ValueError, "Image creation failed");
	return NULL;
}

image->yuvRange = AVIF_RANGE_LIMITED;
image->yuvFormat = AVIF_PIXEL_FORMAT_YUV420;
image->width = 128;
image->height = 128;
image->depth = 8;

image->matrixCoefficients = AVIF_MATRIX_COEFFICIENTS_BT601;

avifRGBImage rgb;
avifRGBImageSetDefaults(&rgb, image);

rgb.format = AVIF_RGB_FORMAT_RGB;

avifResult result = avifRGBImageAllocatePixels(&rgb);
if (result != AVIF_RESULT_OK) {
	PyErr_Format(exc_type_for_avif_result(result), "Pixel allocation failed: %s", avifResultToString(result));
	return NULL;
}

memset(rgb.pixels, 255, rgb.rowBytes * image->height);

result = avifImageRGBToYUV(image, &rgb);
if (result != AVIF_RESULT_OK) {
	PyErr_Format(exc_type_for_avif_result(result), "Conversion to YUV failed: %s", avifResultToString(result));
	return NULL;
}

result = avifEncoderAddImage(encoder, image, 0, AVIF_ADD_IMAGE_FLAG_SINGLE);
if (result != AVIF_RESULT_OK) {
	PyErr_Format(exc_type_for_avif_result(result), "Failed to encode image: %s", avifResultToString(result));
	return NULL;
}

avifRWData raw = AVIF_DATA_EMPTY;
result = avifEncoderFinish(encoder, &raw);

if (result != AVIF_RESULT_OK) {
	PyErr_Format(exc_type_for_avif_result(result), "Failed to finish encoding: %s", avifResultToString(result));
	avifRWDataFree(&raw);
	return NULL;
}

If I run this code with libavif 1.3.0, using Python to compare the output when not specifying enable-chroma-deltaq and when specifying enable-chroma-deltaq as 0, I find that it matches.
If I run this code with libavif 1.4.0, I find that not specifying enable-chroma-deltaq doesn't match 0, but instead matches 1.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions