| 512 | |
| 513 | #if CONFIG_LCMS2 |
| 514 | static int detect_colorspace(AVCodecContext *avctx, AVFrame *frame) |
| 515 | { |
| 516 | AVCodecInternal *avci = avctx->internal; |
| 517 | enum AVColorTransferCharacteristic trc; |
| 518 | AVColorPrimariesDesc coeffs; |
| 519 | enum AVColorPrimaries prim; |
| 520 | cmsHPROFILE profile; |
| 521 | AVFrameSideData *sd; |
| 522 | int ret; |
| 523 | if (!(avctx->flags2 & AV_CODEC_FLAG2_ICC_PROFILES)) |
| 524 | return 0; |
| 525 | |
| 526 | sd = av_frame_get_side_data(frame, AV_FRAME_DATA_ICC_PROFILE); |
| 527 | if (!sd || !sd->size) |
| 528 | return 0; |
| 529 | |
| 530 | if (!avci->icc.avctx) { |
| 531 | ret = ff_icc_context_init(&avci->icc, avctx); |
| 532 | if (ret < 0) |
| 533 | return ret; |
| 534 | } |
| 535 | |
| 536 | profile = cmsOpenProfileFromMemTHR(avci->icc.ctx, sd->data, sd->size); |
| 537 | if (!profile) |
| 538 | return AVERROR_INVALIDDATA; |
| 539 | |
| 540 | ret = ff_icc_profile_sanitize(&avci->icc, profile); |
| 541 | if (!ret) |
| 542 | ret = ff_icc_profile_read_primaries(&avci->icc, profile, &coeffs); |
| 543 | if (!ret) |
| 544 | ret = ff_icc_profile_detect_transfer(&avci->icc, profile, &trc); |
| 545 | cmsCloseProfile(profile); |
| 546 | if (ret < 0) |
| 547 | return ret; |
| 548 | |
| 549 | prim = av_csp_primaries_id_from_desc(&coeffs); |
| 550 | if (prim != AVCOL_PRI_UNSPECIFIED) |
| 551 | frame->color_primaries = prim; |
| 552 | if (trc != AVCOL_TRC_UNSPECIFIED) |
| 553 | frame->color_trc = trc; |
| 554 | return 0; |
| 555 | } |
| 556 | #else /* !CONFIG_LCMS2 */ |
| 557 | static int detect_colorspace(av_unused AVCodecContext *c, av_unused AVFrame *f) |
| 558 | { |
no test coverage detected