Skip to content

Commit 59d00e5

Browse files
authored
Add backward compatibility for AVIF chroma subsampling feature (#19698)
* AVIF export: add legacy_params for backward compatibility Increment module version to 2 and add legacy_params function to handle migration from version 1 (without subsample field) to version 2 (with subsample field). This ensures that existing AVIF export presets created before the chroma subsampling feature continue to work after upgrade. Old presets are automatically migrated with subsample set to AUTO, preserving the original quality-based behavior. Changes: - Increment DT_MODULE from 1 to 2 - Add legacy_params() function to migrate v1 parameters to v2 - Old presets default to AVIF_SUBSAMPLE_AUTO for backward compatibility
1 parent e5b6fbe commit 59d00e5

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

src/imageio/format/avif.c

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
#define AVIF_MAX_TILE_SIZE 3072
3838
#define AVIF_DEFAULT_TILE_SIZE AVIF_MIN_TILE_SIZE * 2
3939

40-
DT_MODULE(1)
40+
DT_MODULE(2)
4141

4242
enum avif_compression_type_e
4343
{
@@ -724,6 +724,48 @@ size_t params_size(dt_imageio_module_format_t *self)
724724
return sizeof(dt_imageio_avif_t);
725725
}
726726

727+
void *legacy_params(dt_imageio_module_format_t *self,
728+
const void *const old_params,
729+
const size_t old_params_size,
730+
const int old_version,
731+
int *new_version,
732+
size_t *new_size)
733+
{
734+
if(old_version == 1)
735+
{
736+
typedef struct dt_imageio_avif_v1_t
737+
{
738+
dt_imageio_module_data_t global;
739+
uint32_t bit_depth;
740+
uint32_t color_mode;
741+
uint32_t compression_type;
742+
uint32_t quality;
743+
uint32_t tiling;
744+
} dt_imageio_avif_v1_t;
745+
746+
if(old_params_size != sizeof(dt_imageio_avif_v1_t)) return NULL;
747+
748+
const dt_imageio_avif_v1_t *o = (dt_imageio_avif_v1_t *)old_params;
749+
dt_imageio_avif_t *n = (dt_imageio_avif_t *)malloc(sizeof(dt_imageio_avif_t));
750+
751+
if(!n) return NULL;
752+
753+
n->global = o->global;
754+
n->bit_depth = o->bit_depth;
755+
n->color_mode = o->color_mode;
756+
n->compression_type = o->compression_type;
757+
n->quality = o->quality;
758+
n->tiling = o->tiling;
759+
n->subsample = AVIF_SUBSAMPLE_AUTO; // Default to auto mode for old presets
760+
761+
*new_version = 2;
762+
*new_size = sizeof(dt_imageio_avif_t);
763+
return n;
764+
}
765+
766+
return NULL;
767+
}
768+
727769
void *get_params(dt_imageio_module_format_t *self)
728770
{
729771
dt_imageio_avif_t *d = calloc(1, sizeof(dt_imageio_avif_t));

0 commit comments

Comments
 (0)