mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-11-04 01:47:47 +03:00 
			
		
		
		
	Remove support for libavif < 1.0.0
This commit is contained in:
		
							parent
							
								
									0732554e5a
								
							
						
					
					
						commit
						9ea5e3dc66
					
				| 
						 | 
					@ -63,20 +63,17 @@ The :py:meth:`~PIL.Image.Image.save` method supports the following options:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
**tile_rows** / **tile_cols**
 | 
					**tile_rows** / **tile_cols**
 | 
				
			||||||
    For tile encoding, the (log 2) number of tile rows and columns to use.
 | 
					    For tile encoding, the (log 2) number of tile rows and columns to use.
 | 
				
			||||||
    Valid values are 0-6, default 0. Ignored if "autotiling" is set to true in libavif
 | 
					    Valid values are 0-6, default 0. Ignored if "autotiling" is set to true.
 | 
				
			||||||
    version **0.11.0** or greater.
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
**autotiling**
 | 
					**autotiling**
 | 
				
			||||||
    Split the image up to allow parallelization. Enabled automatically if "tile_rows"
 | 
					    Split the image up to allow parallelization. Enabled automatically if "tile_rows"
 | 
				
			||||||
    and "tile_cols" both have their default values of zero. Requires libavif version
 | 
					    and "tile_cols" both have their default values of zero.
 | 
				
			||||||
    **0.11.0** or greater.
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
**alpha_premultiplied**
 | 
					**alpha_premultiplied**
 | 
				
			||||||
    Encode the image with premultiplied alpha. Defaults to ``False``. Requires libavif
 | 
					    Encode the image with premultiplied alpha. Defaults to ``False``.
 | 
				
			||||||
    version **0.9.0** or greater.
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
**advanced**
 | 
					**advanced**
 | 
				
			||||||
    Codec specific options. Requires libavif version **0.8.2** or greater.
 | 
					    Codec specific options.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
**icc_profile**
 | 
					**icc_profile**
 | 
				
			||||||
    The ICC Profile to include in the saved file.
 | 
					    The ICC Profile to include in the saved file.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -91,8 +91,7 @@ Many of Pillow's features require external libraries:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
* **libavif** provides support for the AVIF format.
 | 
					* **libavif** provides support for the AVIF format.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  * Pillow requires libavif version **0.8.0** or greater, which is when
 | 
					  * Pillow requires libavif version **1.0.0** or greater.
 | 
				
			||||||
    AVIF image sequence support was added.
 | 
					 | 
				
			||||||
  * libavif is merely an API that wraps AVIF codecs. If you are compiling
 | 
					  * libavif is merely an API that wraps AVIF codecs. If you are compiling
 | 
				
			||||||
    libavif from source, you will also need to install both an AVIF encoder
 | 
					    libavif from source, you will also need to install both an AVIF encoder
 | 
				
			||||||
    and decoder, such as rav1e and dav1d, or libaom, which both encodes and
 | 
					    and decoder, such as rav1e and dav1d, or libaom, which both encodes and
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										56
									
								
								src/_avif.c
									
									
									
									
									
								
							
							
						
						
									
										56
									
								
								src/_avif.c
									
									
									
									
									
								
							| 
						 | 
					@ -20,19 +20,6 @@ typedef struct {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static PyTypeObject AvifDecoder_Type;
 | 
					static PyTypeObject AvifDecoder_Type;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if AVIF_VERSION < 1000000  // 1.0.0
 | 
					 | 
				
			||||||
static int
 | 
					 | 
				
			||||||
normalize_quantize_value(int qvalue) {
 | 
					 | 
				
			||||||
    if (qvalue < AVIF_QUANTIZER_BEST_QUALITY) {
 | 
					 | 
				
			||||||
        return AVIF_QUANTIZER_BEST_QUALITY;
 | 
					 | 
				
			||||||
    } else if (qvalue > AVIF_QUANTIZER_WORST_QUALITY) {
 | 
					 | 
				
			||||||
        return AVIF_QUANTIZER_WORST_QUALITY;
 | 
					 | 
				
			||||||
    } else {
 | 
					 | 
				
			||||||
        return qvalue;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static int
 | 
					static int
 | 
				
			||||||
normalize_tiles_log2(int value) {
 | 
					normalize_tiles_log2(int value) {
 | 
				
			||||||
    if (value < 0) {
 | 
					    if (value < 0) {
 | 
				
			||||||
| 
						 | 
					@ -62,12 +49,7 @@ exc_type_for_avif_result(avifResult result) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static uint8_t
 | 
					static uint8_t
 | 
				
			||||||
irot_imir_to_exif_orientation(const avifImage *image) {
 | 
					irot_imir_to_exif_orientation(const avifImage *image) {
 | 
				
			||||||
    uint8_t axis;
 | 
					    uint8_t axis = image->imir.axis;
 | 
				
			||||||
#if AVIF_VERSION_MAJOR >= 1
 | 
					 | 
				
			||||||
    axis = image->imir.axis;
 | 
					 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
    axis = image->imir.mode;
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
    int imir = image->transformFlags & AVIF_TRANSFORM_IMIR;
 | 
					    int imir = image->transformFlags & AVIF_TRANSFORM_IMIR;
 | 
				
			||||||
    int irot = image->transformFlags & AVIF_TRANSFORM_IROT;
 | 
					    int irot = image->transformFlags & AVIF_TRANSFORM_IROT;
 | 
				
			||||||
    if (irot) {
 | 
					    if (irot) {
 | 
				
			||||||
| 
						 | 
					@ -112,11 +94,7 @@ exif_orientation_to_irot_imir(avifImage *image, int orientation) {
 | 
				
			||||||
        case 2:  // The 0th row is at the visual top of the image, and the 0th column is
 | 
					        case 2:  // The 0th row is at the visual top of the image, and the 0th column is
 | 
				
			||||||
                 // the visual right-hand side.
 | 
					                 // the visual right-hand side.
 | 
				
			||||||
            image->transformFlags |= AVIF_TRANSFORM_IMIR;
 | 
					            image->transformFlags |= AVIF_TRANSFORM_IMIR;
 | 
				
			||||||
#if AVIF_VERSION_MAJOR >= 1
 | 
					 | 
				
			||||||
            image->imir.axis = 1;
 | 
					            image->imir.axis = 1;
 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
            image->imir.mode = 1;
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
        case 3:  // The 0th row is at the visual bottom of the image, and the 0th column
 | 
					        case 3:  // The 0th row is at the visual bottom of the image, and the 0th column
 | 
				
			||||||
                 // is the visual right-hand side.
 | 
					                 // is the visual right-hand side.
 | 
				
			||||||
| 
						 | 
					@ -182,7 +160,6 @@ _encoder_codec_available(PyObject *self, PyObject *args) {
 | 
				
			||||||
    return PyBool_FromLong(is_available);
 | 
					    return PyBool_FromLong(is_available);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if AVIF_VERSION >= 80200  // 0.8.2
 | 
					 | 
				
			||||||
static int
 | 
					static int
 | 
				
			||||||
_add_codec_specific_options(avifEncoder *encoder, PyObject *opts) {
 | 
					_add_codec_specific_options(avifEncoder *encoder, PyObject *opts) {
 | 
				
			||||||
    Py_ssize_t i, size;
 | 
					    Py_ssize_t i, size;
 | 
				
			||||||
| 
						 | 
					@ -224,7 +201,6 @@ _add_codec_specific_options(avifEncoder *encoder, PyObject *opts) {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    return 0;
 | 
					    return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Encoder functions
 | 
					// Encoder functions
 | 
				
			||||||
PyObject *
 | 
					PyObject *
 | 
				
			||||||
| 
						 | 
					@ -318,9 +294,7 @@ AvifEncoderNew(PyObject *self_, PyObject *args) {
 | 
				
			||||||
    image->height = height;
 | 
					    image->height = height;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    image->depth = 8;
 | 
					    image->depth = 8;
 | 
				
			||||||
#if AVIF_VERSION >= 90000  // 0.9.0
 | 
					 | 
				
			||||||
    image->alphaPremultiplied = alpha_premultiplied ? AVIF_TRUE : AVIF_FALSE;
 | 
					    image->alphaPremultiplied = alpha_premultiplied ? AVIF_TRUE : AVIF_FALSE;
 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    encoder = avifEncoderCreate();
 | 
					    encoder = avifEncoderCreate();
 | 
				
			||||||
    if (!encoder) {
 | 
					    if (!encoder) {
 | 
				
			||||||
| 
						 | 
					@ -334,12 +308,7 @@ AvifEncoderNew(PyObject *self_, PyObject *args) {
 | 
				
			||||||
                         _codec_available("aom", AVIF_CODEC_FLAG_CAN_ENCODE));
 | 
					                         _codec_available("aom", AVIF_CODEC_FLAG_CAN_ENCODE));
 | 
				
			||||||
    encoder->maxThreads = is_aom_encode && max_threads > 64 ? 64 : max_threads;
 | 
					    encoder->maxThreads = is_aom_encode && max_threads > 64 ? 64 : max_threads;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if AVIF_VERSION >= 1000000  // 1.0.0
 | 
					 | 
				
			||||||
    encoder->quality = quality;
 | 
					    encoder->quality = quality;
 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
    encoder->minQuantizer = normalize_quantize_value(64 - quality);
 | 
					 | 
				
			||||||
    encoder->maxQuantizer = normalize_quantize_value(100 - quality);
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (strcmp(codec, "auto") == 0) {
 | 
					    if (strcmp(codec, "auto") == 0) {
 | 
				
			||||||
        encoder->codecChoice = AVIF_CODEC_CHOICE_AUTO;
 | 
					        encoder->codecChoice = AVIF_CODEC_CHOICE_AUTO;
 | 
				
			||||||
| 
						 | 
					@ -354,31 +323,16 @@ AvifEncoderNew(PyObject *self_, PyObject *args) {
 | 
				
			||||||
    encoder->speed = speed;
 | 
					    encoder->speed = speed;
 | 
				
			||||||
    encoder->timescale = (uint64_t)1000;
 | 
					    encoder->timescale = (uint64_t)1000;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if AVIF_VERSION >= 110000  // 0.11.0
 | 
					 | 
				
			||||||
    encoder->autoTiling = autotiling ? AVIF_TRUE : AVIF_FALSE;
 | 
					    encoder->autoTiling = autotiling ? AVIF_TRUE : AVIF_FALSE;
 | 
				
			||||||
    if (!autotiling) {
 | 
					    if (!autotiling) {
 | 
				
			||||||
        encoder->tileRowsLog2 = normalize_tiles_log2(tile_rows_log2);
 | 
					        encoder->tileRowsLog2 = normalize_tiles_log2(tile_rows_log2);
 | 
				
			||||||
        encoder->tileColsLog2 = normalize_tiles_log2(tile_cols_log2);
 | 
					        encoder->tileColsLog2 = normalize_tiles_log2(tile_cols_log2);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
    encoder->tileRowsLog2 = normalize_tiles_log2(tile_rows_log2);
 | 
					 | 
				
			||||||
    encoder->tileColsLog2 = normalize_tiles_log2(tile_cols_log2);
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (advanced != Py_None) {
 | 
					    if (advanced != Py_None && _add_codec_specific_options(encoder, advanced)) {
 | 
				
			||||||
#if AVIF_VERSION >= 80200  // 0.8.2
 | 
					 | 
				
			||||||
        if (_add_codec_specific_options(encoder, advanced)) {
 | 
					 | 
				
			||||||
        error = 1;
 | 
					        error = 1;
 | 
				
			||||||
        goto end;
 | 
					        goto end;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
        PyErr_SetString(
 | 
					 | 
				
			||||||
            PyExc_ValueError, "Advanced codec options require libavif >= 0.8.2"
 | 
					 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
        error = 1;
 | 
					 | 
				
			||||||
        goto end;
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    self = PyObject_New(AvifEncoderObject, &AvifEncoder_Type);
 | 
					    self = PyObject_New(AvifEncoderObject, &AvifEncoder_Type);
 | 
				
			||||||
    if (!self) {
 | 
					    if (!self) {
 | 
				
			||||||
| 
						 | 
					@ -537,9 +491,7 @@ _encoder_add(AvifEncoderObject *self, PyObject *args) {
 | 
				
			||||||
        frame->yuvRange = image->yuvRange;
 | 
					        frame->yuvRange = image->yuvRange;
 | 
				
			||||||
        frame->yuvFormat = image->yuvFormat;
 | 
					        frame->yuvFormat = image->yuvFormat;
 | 
				
			||||||
        frame->depth = image->depth;
 | 
					        frame->depth = image->depth;
 | 
				
			||||||
#if AVIF_VERSION >= 90000  // 0.9.0
 | 
					 | 
				
			||||||
        frame->alphaPremultiplied = image->alphaPremultiplied;
 | 
					        frame->alphaPremultiplied = image->alphaPremultiplied;
 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    avifRGBImageSetDefaults(&rgb, frame);
 | 
					    avifRGBImageSetDefaults(&rgb, frame);
 | 
				
			||||||
| 
						 | 
					@ -689,17 +641,13 @@ AvifDecoderNew(PyObject *self_, PyObject *args) {
 | 
				
			||||||
        PyObject_Del(self);
 | 
					        PyObject_Del(self);
 | 
				
			||||||
        return NULL;
 | 
					        return NULL;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
#if AVIF_VERSION >= 80400  // 0.8.4
 | 
					 | 
				
			||||||
    decoder->maxThreads = max_threads;
 | 
					    decoder->maxThreads = max_threads;
 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
#if AVIF_VERSION >= 90200  // 0.9.2
 | 
					 | 
				
			||||||
    // Turn off libavif's 'clap' (clean aperture) property validation.
 | 
					    // Turn off libavif's 'clap' (clean aperture) property validation.
 | 
				
			||||||
    decoder->strictFlags &= ~AVIF_STRICT_CLAP_VALID;
 | 
					    decoder->strictFlags &= ~AVIF_STRICT_CLAP_VALID;
 | 
				
			||||||
    // Allow the PixelInformationProperty ('pixi') to be missing in AV1 image
 | 
					    // Allow the PixelInformationProperty ('pixi') to be missing in AV1 image
 | 
				
			||||||
    // items. libheif v1.11.0 and older does not add the 'pixi' item property to
 | 
					    // items. libheif v1.11.0 and older does not add the 'pixi' item property to
 | 
				
			||||||
    // AV1 image items.
 | 
					    // AV1 image items.
 | 
				
			||||||
    decoder->strictFlags &= ~AVIF_STRICT_PIXI_REQUIRED;
 | 
					    decoder->strictFlags &= ~AVIF_STRICT_PIXI_REQUIRED;
 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
    decoder->codecChoice = codec;
 | 
					    decoder->codecChoice = codec;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    result = avifDecoderSetIOMemory(decoder, buffer.buf, buffer.len);
 | 
					    result = avifDecoderSetIOMemory(decoder, buffer.buf, buffer.len);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user