1 /* 2 * Copyright (c) 2022 Niklas Haas 3 * This file is part of FFmpeg. 4 * 5 * FFmpeg is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Lesser General Public 7 * License as published by the Free Software Foundation; either 8 * version 2.1 of the License, or (at your option) any later version. 9 * 10 * FFmpeg is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public 16 * License along with FFmpeg; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 */ 19 20 /** 21 * @file 22 * Various functions for dealing with ICC profiles 23 */ 24 25 #ifndef AVFILTER_FFLCMS2_H 26 #define AVFILTER_FFLCMS2_H 27 28 #include "libavutil/csp.h" 29 #include "libavutil/frame.h" 30 #include "libavutil/pixfmt.h" 31 32 #include <lcms2.h> 33 34 typedef struct FFIccContext { 35 void *avctx; 36 cmsContext ctx; 37 cmsToneCurve *curves[AVCOL_TRC_NB]; /* tone curve cache */ 38 } FFIccContext; 39 40 /** 41 * Initializes an FFIccContext. This must be done prior to using it. 42 * 43 * Returns 0 on success, or a negative error code. 44 */ 45 int ff_icc_context_init(FFIccContext *s, void *avctx); 46 void ff_icc_context_uninit(FFIccContext *s); 47 48 /** 49 * Generate an ICC profile for a given combination of color primaries and 50 * transfer function. Both values must be set to valid entries (not 51 * "undefined") for this function to work. 52 * 53 * Returns 0 on success, or a negative error code. 54 */ 55 int ff_icc_profile_generate(FFIccContext *s, 56 enum AVColorPrimaries color_prim, 57 enum AVColorTransferCharacteristic color_trc, 58 cmsHPROFILE *out_profile); 59 60 /** 61 * Attach an ICC profile to a frame. Helper wrapper around cmsSaveProfileToMem 62 * and av_frame_new_side_data_from_buf. 63 * 64 * Returns 0 on success, or a negative error code. 65 */ 66 int ff_icc_profile_attach(FFIccContext *s, cmsHPROFILE profile, AVFrame *frame); 67 68 /** 69 * Read the color primaries and white point coefficients encoded by an ICC 70 * profile, and return the raw values in `out_primaries`. 71 * 72 * Returns 0 on success, or a negative error code. 73 */ 74 int ff_icc_profile_read_primaries(FFIccContext *s, cmsHPROFILE profile, 75 AVColorPrimariesDesc *out_primaries); 76 77 /** 78 * Attempt detecting the transfer characteristic that best approximates the 79 * transfer function encoded by an ICC profile. Sets `out_trc` to 80 * AVCOL_TRC_UNSPECIFIED if no clear match can be identified. 81 * 82 * Returns 0 on success (including no match), or a negative error code. 83 */ 84 int ff_icc_profile_detect_transfer(FFIccContext *s, cmsHPROFILE profile, 85 enum AVColorTransferCharacteristic *out_trc); 86 87 #endif /* AVFILTER_FFLCMS2_H */ 88