Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AOM encoder: Expose control over Intra Block Copy (intrabc) #1408

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion libheif/plugins/encoder_aom.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ struct encoder_struct_aom
bool lossless;
bool lossless_alpha;
bool auto_tiles;
bool intra_block_copy;

#if defined(HAVE_AOM_CODEC_SET_OPTION)
std::vector<custom_option> custom_options;
Expand Down Expand Up @@ -162,6 +163,7 @@ static const char* kParam_alpha_min_q = "alpha-min-q";
static const char* kParam_alpha_max_q = "alpha-max-q";
static const char* kParam_lossless_alpha = "lossless-alpha";
static const char* kParam_auto_tiles = "auto-tiles";
static const char* kParam_intra_block_copy = "intra-block-copy";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to name this parameter "enable-intrabc" to match the name used in libaom. On the other hand, I am not sure if libheif has tried to make these parameter names match the names used in libaom, so this may not be worth the trouble.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I believe this makes sense. Parameters that correspond 1:1 to codec parameters should be identical to reduce the confusion and cognitive load.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the comment, Dirk. This will require a corresponding change to libvips (see libvips/libvips#4284) to use the new parameter name. During the transitional period libheif can support both the old and new parameter names.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I've notified them at libvips/libvips#4284.
One can also use heif_encoder_set_parameter_string(..., "aom:enable-intrabc", "0") which sets the parameter directly through aom_codec_set_option() and which works even for past versions of libheif.

static const char* kParam_threads = "threads";
static const char* kParam_realtime = "realtime";
static const char* kParam_speed = "speed";
Expand Down Expand Up @@ -200,7 +202,7 @@ static const char* aom_plugin_name()
}


#define MAX_NPARAMETERS 15
#define MAX_NPARAMETERS 16

static struct heif_encoder_parameter aom_encoder_params[MAX_NPARAMETERS];
static const struct heif_encoder_parameter* aom_encoder_parameter_ptrs[MAX_NPARAMETERS + 1];
Expand Down Expand Up @@ -373,6 +375,16 @@ static void aom_init_parameters()
p->has_default = true;
d[i++] = p++;

#if defined(AOM_CTRL_AV1E_SET_ENABLE_INTRABC)
assert(i < MAX_NPARAMETERS);
lovell marked this conversation as resolved.
Show resolved Hide resolved
p->version = 2;
p->name = kParam_intra_block_copy;
p->type = heif_encoder_parameter_type_boolean;
p->boolean.default_value = true;
p->has_default = true;
d[i++] = p++;
#endif

assert(i < MAX_NPARAMETERS + 1);
d[i++] = nullptr;
}
Expand Down Expand Up @@ -585,6 +597,11 @@ struct heif_error aom_set_parameter_boolean(void* encoder_raw, const char* name,
} else if (strcmp(name, kParam_auto_tiles) == 0) {
encoder->auto_tiles = value;
return heif_error_ok;
#if defined(AOM_CTRL_AV1E_SET_ENABLE_INTRABC)
} else if (strcmp(name, kParam_intra_block_copy) == 0) {
encoder->intra_block_copy = value;
return heif_error_ok;
#endif
}

set_value(kParam_realtime, realtime_mode);
Expand Down Expand Up @@ -1037,6 +1054,10 @@ struct heif_error aom_encode_image(void* encoder_raw, const struct heif_image* i
}
#endif

#if defined(AOM_CTRL_AV1E_SET_ENABLE_INTRABC)
aom_codec_control(&codec, AV1E_SET_ENABLE_INTRABC, encoder->intra_block_copy);
#endif

#if defined(HAVE_AOM_CODEC_SET_OPTION)
// Apply the custom AOM encoder options.
// These should always be applied last as they can override the values that were set above.
Expand Down
Loading