+ ctx->params->bEnablePsnr = !!(avctx->flags & AV_CODEC_FLAG_PSNR);
+
+ /* Tune the CTU size based on input resolution. */
+ if (ctx->params->sourceWidth < 64 || ctx->params->sourceHeight < 64)
+ ctx->params->maxCUSize = 32;
+ if (ctx->params->sourceWidth < 32 || ctx->params->sourceHeight < 32)
+ ctx->params->maxCUSize = 16;
+ if (ctx->params->sourceWidth < 16 || ctx->params->sourceHeight < 16) {
+ av_log(avctx, AV_LOG_ERROR, "Image size is too small (%dx%d).\n",
+ ctx->params->sourceWidth, ctx->params->sourceHeight);
+ return AVERROR(EINVAL);
+ }
+
+ if ((avctx->color_primaries <= AVCOL_PRI_BT2020 &&
+ avctx->color_primaries != AVCOL_PRI_UNSPECIFIED) ||
+ (avctx->color_trc <= AVCOL_TRC_BT2020_12 &&
+ avctx->color_trc != AVCOL_TRC_UNSPECIFIED) ||
+ (avctx->colorspace <= AVCOL_SPC_BT2020_CL &&
+ avctx->colorspace != AVCOL_SPC_UNSPECIFIED)) {
+
+ ctx->params->vui.bEnableVideoSignalTypePresentFlag = 1;
+ ctx->params->vui.bEnableColorDescriptionPresentFlag = 1;
+
+ // x265 validates the parameters internally
+ ctx->params->vui.colorPrimaries = avctx->color_primaries;
+ ctx->params->vui.transferCharacteristics = avctx->color_trc;
+ ctx->params->vui.matrixCoeffs = avctx->colorspace;
+ }