History

lavfi: add ff_detect_color_primaries helper

Related to #9673, this helper exists to facilitate "guessing" the right primary tags from a given set of raw primary coefficients. The cutoff value of 0.001 was chosen by experimentation. The smallest "false positive" delta observed in practice was 0.023329, while the largest "false negative" delta was 0.00016. So, a value of 0.001 sits comfortably in the middle.

Niklas Haas committed 4 years ago

Commit 072dd041 parent 6d830362 files · +28 −0Browse files

Unified · Split

2 files
  1. libavfilter/colorspace.c +25 −0
  2. libavfilter/colorspace.h +3 −0
libavfilter/colorspace.c+25−0
@@ -170,6 +170,31 @@ const struct ColorPrimaries *ff_get_color_primaries(enum AVColorPrimaries prm) · 169 unmodified lines
170 return p;170 return p;
171}171}
172 172
173enum AVColorPrimaries ff_detect_color_primaries(const struct ColorPrimaries *prm)
174{
175 double delta;
176
177 for (enum AVColorPrimaries p = 0; p < AVCOL_PRI_NB; p++) {
178 const struct ColorPrimaries *ref = &color_primaries[p];
179 if (!ref->prim.xr)
180 continue;
181
182 delta = fabs(prm->prim.xr - ref->prim.xr) +
183 fabs(prm->prim.yr - ref->prim.yr) +
184 fabs(prm->prim.yg - ref->prim.yg) +
185 fabs(prm->prim.yg - ref->prim.yg) +
186 fabs(prm->prim.yb - ref->prim.yb) +
187 fabs(prm->prim.yb - ref->prim.yb) +
188 fabs(prm->wp.xw - ref->wp.xw) +
189 fabs(prm->wp.yw - ref->wp.yw);
190
191 if (delta < 0.001)
192 return p;
193 }
194
195 return AVCOL_PRI_UNSPECIFIED;
196}
197
173void ff_fill_rgb2yuv_table(const struct LumaCoefficients *coeffs,198void ff_fill_rgb2yuv_table(const struct LumaCoefficients *coeffs,
174 double rgb2yuv[3][3])199 double rgb2yuv[3][3])
175{200{
libavfilter/colorspace.h+3−0
@@ -49,6 +49,9 @@ void ff_fill_rgb2xyz_table(const struct PrimaryCoefficients *coeffs, · 48 unmodified lines
49 const struct WhitepointCoefficients *wp,49 const struct WhitepointCoefficients *wp,
50 double rgb2xyz[3][3]);50 double rgb2xyz[3][3]);
51 51
52/* Returns AVCOL_PRI_UNSPECIFIED if no clear match can be identified */
53enum AVColorPrimaries ff_detect_color_primaries(const struct ColorPrimaries *prm);
54
52const struct ColorPrimaries *ff_get_color_primaries(enum AVColorPrimaries prm);55const struct ColorPrimaries *ff_get_color_primaries(enum AVColorPrimaries prm);
53const struct LumaCoefficients *ff_get_luma_coefficients(enum AVColorSpace csp);56const struct LumaCoefficients *ff_get_luma_coefficients(enum AVColorSpace csp);
54void ff_fill_rgb2yuv_table(const struct LumaCoefficients *coeffs,57void ff_fill_rgb2yuv_table(const struct LumaCoefficients *coeffs,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t