vf_ciescope.c 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510
  1. /*
  2. * Copyright (c) 2000 John Walker
  3. * Copyright (c) 2016 Paul B Mahol
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include "libavutil/avassert.h"
  22. #include "libavutil/intreadwrite.h"
  23. #include "libavutil/opt.h"
  24. #include "libavutil/parseutils.h"
  25. #include "libavutil/pixdesc.h"
  26. #include "avfilter.h"
  27. #include "formats.h"
  28. #include "internal.h"
  29. #include "video.h"
  30. enum CieSystem {
  31. XYY,
  32. UCS,
  33. LUV,
  34. NB_CIE
  35. };
  36. enum ColorsSystems {
  37. NTSCsystem,
  38. EBUsystem,
  39. SMPTEsystem,
  40. SMPTE240Msystem,
  41. APPLEsystem,
  42. wRGBsystem,
  43. CIE1931system,
  44. Rec709system,
  45. Rec2020system,
  46. NB_CS
  47. };
  48. typedef struct CiescopeContext {
  49. const AVClass *class;
  50. int color_system;
  51. unsigned gamuts;
  52. int size;
  53. int show_white;
  54. int correct_gamma;
  55. int cie;
  56. float intensity;
  57. float contrast;
  58. int background;
  59. double log2lin[65536];
  60. double igamma;
  61. double i[3][3];
  62. double m[3][3];
  63. AVFrame *f;
  64. void (*filter)(AVFilterContext *ctx, AVFrame *in, double *cx, double *cy, int x, int y);
  65. } CiescopeContext;
  66. #define OFFSET(x) offsetof(CiescopeContext, x)
  67. #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
  68. static const AVOption ciescope_options[] = {
  69. { "system", "set color system", OFFSET(color_system), AV_OPT_TYPE_INT, {.i64=Rec709system}, 0, NB_CS-1, FLAGS, "system" },
  70. { "ntsc", "NTSC 1953 Y'I'O' (ITU-R BT.470 System M)", 0, AV_OPT_TYPE_CONST, {.i64=NTSCsystem}, 0, 0, FLAGS, "system" },
  71. { "470m", "NTSC 1953 Y'I'O' (ITU-R BT.470 System M)", 0, AV_OPT_TYPE_CONST, {.i64=NTSCsystem}, 0, 0, FLAGS, "system" },
  72. { "ebu", "EBU Y'U'V' (PAL/SECAM) (ITU-R BT.470 System B, G)", 0, AV_OPT_TYPE_CONST, {.i64=EBUsystem}, 0, 0, FLAGS, "system" },
  73. { "470bg", "EBU Y'U'V' (PAL/SECAM) (ITU-R BT.470 System B, G)", 0, AV_OPT_TYPE_CONST, {.i64=EBUsystem}, 0, 0, FLAGS, "system" },
  74. { "smpte", "SMPTE-C RGB", 0, AV_OPT_TYPE_CONST, {.i64=SMPTEsystem}, 0, 0, FLAGS, "system" },
  75. { "240m", "SMPTE-240M Y'PbPr", 0, AV_OPT_TYPE_CONST, {.i64=SMPTE240Msystem},0, 0, FLAGS, "system" },
  76. { "apple", "Apple RGB", 0, AV_OPT_TYPE_CONST, {.i64=APPLEsystem}, 0, 0, FLAGS, "system" },
  77. { "widergb", "Adobe Wide Gamut RGB", 0, AV_OPT_TYPE_CONST, {.i64=wRGBsystem}, 0, 0, FLAGS, "system" },
  78. { "cie1931", "CIE 1931 RGB", 0, AV_OPT_TYPE_CONST, {.i64=CIE1931system}, 0, 0, FLAGS, "system" },
  79. { "hdtv", "ITU.BT-709 Y'CbCr", 0, AV_OPT_TYPE_CONST, {.i64=Rec709system}, 0, 0, FLAGS, "system" },
  80. { "rec709", "ITU.BT-709 Y'CbCr", 0, AV_OPT_TYPE_CONST, {.i64=Rec709system}, 0, 0, FLAGS, "system" },
  81. { "uhdtv", "ITU-R.BT-2020", 0, AV_OPT_TYPE_CONST, {.i64=Rec2020system}, 0, 0, FLAGS, "system" },
  82. { "rec2020", "ITU-R.BT-2020", 0, AV_OPT_TYPE_CONST, {.i64=Rec2020system}, 0, 0, FLAGS, "system" },
  83. { "cie", "set cie system", OFFSET(cie), AV_OPT_TYPE_INT, {.i64=XYY}, 0, NB_CIE-1, FLAGS, "cie" },
  84. { "xyy", "CIE 1931 xyY", 0, AV_OPT_TYPE_CONST, {.i64=XYY}, 0, 0, FLAGS, "cie" },
  85. { "ucs", "CIE 1960 UCS", 0, AV_OPT_TYPE_CONST, {.i64=UCS}, 0, 0, FLAGS, "cie" },
  86. { "luv", "CIE 1976 Luv", 0, AV_OPT_TYPE_CONST, {.i64=LUV}, 0, 0, FLAGS, "cie" },
  87. { "gamuts", "set what gamuts to draw", OFFSET(gamuts), AV_OPT_TYPE_FLAGS, {.i64=0}, 0, 0xFFF, FLAGS, "gamuts" },
  88. { "ntsc", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1<<NTSCsystem}, 0, 0, FLAGS, "gamuts" },
  89. { "470m", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1<<NTSCsystem}, 0, 0, FLAGS, "gamuts" },
  90. { "ebu", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1<<EBUsystem}, 0, 0, FLAGS, "gamuts" },
  91. { "470bg", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1<<EBUsystem}, 0, 0, FLAGS, "gamuts" },
  92. { "smpte", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1<<SMPTEsystem}, 0, 0, FLAGS, "gamuts" },
  93. { "240m", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1<<SMPTE240Msystem}, 0, 0, FLAGS, "gamuts" },
  94. { "apple", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1<<APPLEsystem}, 0, 0, FLAGS, "gamuts" },
  95. { "widergb", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1<<wRGBsystem}, 0, 0, FLAGS, "gamuts" },
  96. { "cie1931", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1<<CIE1931system}, 0, 0, FLAGS, "gamuts" },
  97. { "hdtv", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1<<Rec709system}, 0, 0, FLAGS, "gamuts" },
  98. { "rec709", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1<<Rec709system}, 0, 0, FLAGS, "gamuts" },
  99. { "uhdtv", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1<<Rec2020system}, 0, 0, FLAGS, "gamuts" },
  100. { "rec2020", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1<<Rec2020system}, 0, 0, FLAGS, "gamuts" },
  101. { "size", "set ciescope size", OFFSET(size), AV_OPT_TYPE_INT, {.i64=512}, 256, 8192, FLAGS },
  102. { "s", "set ciescope size", OFFSET(size), AV_OPT_TYPE_INT, {.i64=512}, 256, 8192, FLAGS },
  103. { "intensity", "set ciescope intensity", OFFSET(intensity), AV_OPT_TYPE_FLOAT, {.dbl=0.001}, 0, 1, FLAGS },
  104. { "i", "set ciescope intensity", OFFSET(intensity), AV_OPT_TYPE_FLOAT, {.dbl=0.001}, 0, 1, FLAGS },
  105. { "contrast", NULL, OFFSET(contrast), AV_OPT_TYPE_FLOAT, {.dbl=0.75}, 0, 1, FLAGS },
  106. { "corrgamma", NULL, OFFSET(correct_gamma), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGS },
  107. { "showwhite", NULL, OFFSET(show_white), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS },
  108. { "gamma", NULL, OFFSET(igamma), AV_OPT_TYPE_DOUBLE, {.dbl=2.6}, 0.1, 6, FLAGS },
  109. { NULL }
  110. };
  111. AVFILTER_DEFINE_CLASS(ciescope);
  112. static const enum AVPixelFormat in_pix_fmts[] = {
  113. AV_PIX_FMT_RGB24,
  114. AV_PIX_FMT_RGBA,
  115. AV_PIX_FMT_RGB48,
  116. AV_PIX_FMT_RGBA64,
  117. AV_PIX_FMT_XYZ12,
  118. AV_PIX_FMT_NONE
  119. };
  120. static const enum AVPixelFormat out_pix_fmts[] = {
  121. AV_PIX_FMT_RGBA64,
  122. AV_PIX_FMT_NONE
  123. };
  124. static int query_formats(AVFilterContext *ctx)
  125. {
  126. int ret;
  127. if ((ret = ff_formats_ref(ff_make_format_list(in_pix_fmts), &ctx->inputs[0]->out_formats)) < 0)
  128. return ret;
  129. if ((ret = ff_formats_ref(ff_make_format_list(out_pix_fmts), &ctx->outputs[0]->in_formats)) < 0)
  130. return ret;
  131. return 0;
  132. }
  133. static int config_output(AVFilterLink *outlink)
  134. {
  135. CiescopeContext *s = outlink->src->priv;
  136. outlink->h = outlink->w = s->size;
  137. outlink->sample_aspect_ratio = (AVRational){1,1};
  138. return 0;
  139. }
  140. /* A color system is defined by the CIE x and y coordinates of its
  141. three primary illuminants and the x and y coordinates of the white
  142. point. */
  143. struct ColorSystem {
  144. double xRed, yRed, /* Red primary illuminant */
  145. xGreen, yGreen, /* Green primary illuminant */
  146. xBlue, yBlue, /* Blue primary illuminant */
  147. xWhite, yWhite, /* White point */
  148. gamma; /* gamma of nonlinear correction */
  149. };
  150. static float const spectral_chromaticity[][3] = {
  151. { 0.175560, 0.005294, 0.819146 },
  152. { 0.175483, 0.005286, 0.819231 },
  153. { 0.175400, 0.005279, 0.819321 },
  154. { 0.175317, 0.005271, 0.819412 },
  155. { 0.175237, 0.005263, 0.819500 },
  156. { 0.175161, 0.005256, 0.819582 },
  157. { 0.175088, 0.005247, 0.819665 },
  158. { 0.175015, 0.005236, 0.819749 },
  159. { 0.174945, 0.005226, 0.819829 },
  160. { 0.174880, 0.005221, 0.819899 },
  161. { 0.174821, 0.005221, 0.819959 },
  162. { 0.174770, 0.005229, 0.820001 },
  163. { 0.174722, 0.005238, 0.820040 },
  164. { 0.174665, 0.005236, 0.820098 },
  165. { 0.174595, 0.005218, 0.820187 },
  166. { 0.174510, 0.005182, 0.820309 },
  167. { 0.174409, 0.005127, 0.820464 },
  168. { 0.174308, 0.005068, 0.820624 },
  169. { 0.174222, 0.005017, 0.820761 },
  170. { 0.174156, 0.004981, 0.820863 },
  171. { 0.174112, 0.004964, 0.820924 },
  172. { 0.174088, 0.004964, 0.820948 },
  173. { 0.174073, 0.004973, 0.820955 },
  174. { 0.174057, 0.004982, 0.820961 },
  175. { 0.174036, 0.004986, 0.820978 },
  176. { 0.174008, 0.004981, 0.821012 },
  177. { 0.173972, 0.004964, 0.821064 },
  178. { 0.173932, 0.004943, 0.821125 },
  179. { 0.173889, 0.004926, 0.821185 },
  180. { 0.173845, 0.004916, 0.821239 },
  181. { 0.173801, 0.004915, 0.821284 },
  182. { 0.173754, 0.004925, 0.821321 },
  183. { 0.173705, 0.004937, 0.821358 },
  184. { 0.173655, 0.004944, 0.821401 },
  185. { 0.173606, 0.004940, 0.821454 },
  186. { 0.173560, 0.004923, 0.821517 },
  187. { 0.173514, 0.004895, 0.821590 },
  188. { 0.173468, 0.004865, 0.821667 },
  189. { 0.173424, 0.004836, 0.821740 },
  190. { 0.173380, 0.004813, 0.821807 },
  191. { 0.173337, 0.004797, 0.821866 },
  192. { 0.173291, 0.004786, 0.821923 },
  193. { 0.173238, 0.004779, 0.821983 },
  194. { 0.173174, 0.004775, 0.822051 },
  195. { 0.173101, 0.004774, 0.822125 },
  196. { 0.173021, 0.004775, 0.822204 },
  197. { 0.172934, 0.004781, 0.822285 },
  198. { 0.172843, 0.004791, 0.822366 },
  199. { 0.172751, 0.004799, 0.822450 },
  200. { 0.172662, 0.004802, 0.822536 },
  201. { 0.172577, 0.004799, 0.822624 },
  202. { 0.172489, 0.004795, 0.822715 },
  203. { 0.172396, 0.004796, 0.822808 },
  204. { 0.172296, 0.004803, 0.822901 },
  205. { 0.172192, 0.004815, 0.822993 },
  206. { 0.172087, 0.004833, 0.823081 },
  207. { 0.171982, 0.004855, 0.823163 },
  208. { 0.171871, 0.004889, 0.823240 },
  209. { 0.171741, 0.004939, 0.823319 },
  210. { 0.171587, 0.005010, 0.823402 },
  211. { 0.171407, 0.005102, 0.823490 },
  212. { 0.171206, 0.005211, 0.823583 },
  213. { 0.170993, 0.005334, 0.823674 },
  214. { 0.170771, 0.005470, 0.823759 },
  215. { 0.170541, 0.005621, 0.823838 },
  216. { 0.170301, 0.005789, 0.823911 },
  217. { 0.170050, 0.005974, 0.823976 },
  218. { 0.169786, 0.006177, 0.824037 },
  219. { 0.169505, 0.006398, 0.824097 },
  220. { 0.169203, 0.006639, 0.824158 },
  221. { 0.168878, 0.006900, 0.824222 },
  222. { 0.168525, 0.007184, 0.824291 },
  223. { 0.168146, 0.007491, 0.824363 },
  224. { 0.167746, 0.007821, 0.824433 },
  225. { 0.167328, 0.008175, 0.824496 },
  226. { 0.166895, 0.008556, 0.824549 },
  227. { 0.166446, 0.008964, 0.824589 },
  228. { 0.165977, 0.009402, 0.824622 },
  229. { 0.165483, 0.009865, 0.824652 },
  230. { 0.164963, 0.010351, 0.824687 },
  231. { 0.164412, 0.010858, 0.824731 },
  232. { 0.163828, 0.011385, 0.824787 },
  233. { 0.163210, 0.011937, 0.824853 },
  234. { 0.162552, 0.012520, 0.824928 },
  235. { 0.161851, 0.013137, 0.825011 },
  236. { 0.161105, 0.013793, 0.825102 },
  237. { 0.160310, 0.014491, 0.825199 },
  238. { 0.159466, 0.015232, 0.825302 },
  239. { 0.158573, 0.016015, 0.825412 },
  240. { 0.157631, 0.016840, 0.825529 },
  241. { 0.156641, 0.017705, 0.825654 },
  242. { 0.155605, 0.018609, 0.825786 },
  243. { 0.154525, 0.019556, 0.825920 },
  244. { 0.153397, 0.020554, 0.826049 },
  245. { 0.152219, 0.021612, 0.826169 },
  246. { 0.150985, 0.022740, 0.826274 },
  247. { 0.149691, 0.023950, 0.826359 },
  248. { 0.148337, 0.025247, 0.826416 },
  249. { 0.146928, 0.026635, 0.826437 },
  250. { 0.145468, 0.028118, 0.826413 },
  251. { 0.143960, 0.029703, 0.826337 },
  252. { 0.142405, 0.031394, 0.826201 },
  253. { 0.140796, 0.033213, 0.825991 },
  254. { 0.139121, 0.035201, 0.825679 },
  255. { 0.137364, 0.037403, 0.825233 },
  256. { 0.135503, 0.039879, 0.824618 },
  257. { 0.133509, 0.042692, 0.823798 },
  258. { 0.131371, 0.045876, 0.822753 },
  259. { 0.129086, 0.049450, 0.821464 },
  260. { 0.126662, 0.053426, 0.819912 },
  261. { 0.124118, 0.057803, 0.818079 },
  262. { 0.121469, 0.062588, 0.815944 },
  263. { 0.118701, 0.067830, 0.813468 },
  264. { 0.115807, 0.073581, 0.810612 },
  265. { 0.112776, 0.079896, 0.807328 },
  266. { 0.109594, 0.086843, 0.803563 },
  267. { 0.106261, 0.094486, 0.799253 },
  268. { 0.102776, 0.102864, 0.794360 },
  269. { 0.099128, 0.112007, 0.788865 },
  270. { 0.095304, 0.121945, 0.782751 },
  271. { 0.091294, 0.132702, 0.776004 },
  272. { 0.087082, 0.144317, 0.768601 },
  273. { 0.082680, 0.156866, 0.760455 },
  274. { 0.078116, 0.170420, 0.751464 },
  275. { 0.073437, 0.185032, 0.741531 },
  276. { 0.068706, 0.200723, 0.730571 },
  277. { 0.063993, 0.217468, 0.718539 },
  278. { 0.059316, 0.235254, 0.705430 },
  279. { 0.054667, 0.254096, 0.691238 },
  280. { 0.050031, 0.274002, 0.675967 },
  281. { 0.045391, 0.294976, 0.659633 },
  282. { 0.040757, 0.316981, 0.642262 },
  283. { 0.036195, 0.339900, 0.623905 },
  284. { 0.031756, 0.363598, 0.604646 },
  285. { 0.027494, 0.387921, 0.584584 },
  286. { 0.023460, 0.412703, 0.563837 },
  287. { 0.019705, 0.437756, 0.542539 },
  288. { 0.016268, 0.462955, 0.520777 },
  289. { 0.013183, 0.488207, 0.498610 },
  290. { 0.010476, 0.513404, 0.476120 },
  291. { 0.008168, 0.538423, 0.453409 },
  292. { 0.006285, 0.563068, 0.430647 },
  293. { 0.004875, 0.587116, 0.408008 },
  294. { 0.003982, 0.610447, 0.385570 },
  295. { 0.003636, 0.633011, 0.363352 },
  296. { 0.003859, 0.654823, 0.341318 },
  297. { 0.004646, 0.675898, 0.319456 },
  298. { 0.006011, 0.696120, 0.297869 },
  299. { 0.007988, 0.715342, 0.276670 },
  300. { 0.010603, 0.733413, 0.255984 },
  301. { 0.013870, 0.750186, 0.235943 },
  302. { 0.017766, 0.765612, 0.216622 },
  303. { 0.022244, 0.779630, 0.198126 },
  304. { 0.027273, 0.792104, 0.180623 },
  305. { 0.032820, 0.802926, 0.164254 },
  306. { 0.038852, 0.812016, 0.149132 },
  307. { 0.045328, 0.819391, 0.135281 },
  308. { 0.052177, 0.825164, 0.122660 },
  309. { 0.059326, 0.829426, 0.111249 },
  310. { 0.066716, 0.832274, 0.101010 },
  311. { 0.074302, 0.833803, 0.091894 },
  312. { 0.082053, 0.834090, 0.083856 },
  313. { 0.089942, 0.833289, 0.076769 },
  314. { 0.097940, 0.831593, 0.070468 },
  315. { 0.106021, 0.829178, 0.064801 },
  316. { 0.114161, 0.826207, 0.059632 },
  317. { 0.122347, 0.822770, 0.054882 },
  318. { 0.130546, 0.818928, 0.050526 },
  319. { 0.138702, 0.814774, 0.046523 },
  320. { 0.146773, 0.810395, 0.042832 },
  321. { 0.154722, 0.805864, 0.039414 },
  322. { 0.162535, 0.801238, 0.036226 },
  323. { 0.170237, 0.796519, 0.033244 },
  324. { 0.177850, 0.791687, 0.030464 },
  325. { 0.185391, 0.786728, 0.027881 },
  326. { 0.192876, 0.781629, 0.025495 },
  327. { 0.200309, 0.776399, 0.023292 },
  328. { 0.207690, 0.771055, 0.021255 },
  329. { 0.215030, 0.765595, 0.019375 },
  330. { 0.222337, 0.760020, 0.017643 },
  331. { 0.229620, 0.754329, 0.016051 },
  332. { 0.236885, 0.748524, 0.014591 },
  333. { 0.244133, 0.742614, 0.013253 },
  334. { 0.251363, 0.736606, 0.012031 },
  335. { 0.258578, 0.730507, 0.010916 },
  336. { 0.265775, 0.724324, 0.009901 },
  337. { 0.272958, 0.718062, 0.008980 },
  338. { 0.280129, 0.711725, 0.008146 },
  339. { 0.287292, 0.705316, 0.007391 },
  340. { 0.294450, 0.698842, 0.006708 },
  341. { 0.301604, 0.692308, 0.006088 },
  342. { 0.308760, 0.685712, 0.005528 },
  343. { 0.315914, 0.679063, 0.005022 },
  344. { 0.323066, 0.672367, 0.004566 },
  345. { 0.330216, 0.665628, 0.004156 },
  346. { 0.337363, 0.658848, 0.003788 },
  347. { 0.344513, 0.652028, 0.003459 },
  348. { 0.351664, 0.645172, 0.003163 },
  349. { 0.358814, 0.638287, 0.002899 },
  350. { 0.365959, 0.631379, 0.002662 },
  351. { 0.373102, 0.624451, 0.002448 },
  352. { 0.380244, 0.617502, 0.002254 },
  353. { 0.387379, 0.610542, 0.002079 },
  354. { 0.394507, 0.603571, 0.001922 },
  355. { 0.401626, 0.596592, 0.001782 },
  356. { 0.408736, 0.589607, 0.001657 },
  357. { 0.415836, 0.582618, 0.001546 },
  358. { 0.422921, 0.575631, 0.001448 },
  359. { 0.429989, 0.568649, 0.001362 },
  360. { 0.437036, 0.561676, 0.001288 },
  361. { 0.444062, 0.554714, 0.001224 },
  362. { 0.451065, 0.547766, 0.001169 },
  363. { 0.458041, 0.540837, 0.001123 },
  364. { 0.464986, 0.533930, 0.001084 },
  365. { 0.471899, 0.527051, 0.001051 },
  366. { 0.478775, 0.520202, 0.001023 },
  367. { 0.485612, 0.513389, 0.001000 },
  368. { 0.492405, 0.506615, 0.000980 },
  369. { 0.499151, 0.499887, 0.000962 },
  370. { 0.505845, 0.493211, 0.000944 },
  371. { 0.512486, 0.486591, 0.000923 },
  372. { 0.519073, 0.480029, 0.000899 },
  373. { 0.525600, 0.473527, 0.000872 },
  374. { 0.532066, 0.467091, 0.000843 },
  375. { 0.538463, 0.460725, 0.000812 },
  376. { 0.544787, 0.454434, 0.000779 },
  377. { 0.551031, 0.448225, 0.000744 },
  378. { 0.557193, 0.442099, 0.000708 },
  379. { 0.563269, 0.436058, 0.000673 },
  380. { 0.569257, 0.430102, 0.000641 },
  381. { 0.575151, 0.424232, 0.000616 },
  382. { 0.580953, 0.418447, 0.000601 },
  383. { 0.586650, 0.412758, 0.000591 },
  384. { 0.592225, 0.407190, 0.000586 },
  385. { 0.597658, 0.401762, 0.000580 },
  386. { 0.602933, 0.396497, 0.000571 },
  387. { 0.608035, 0.391409, 0.000556 },
  388. { 0.612977, 0.386486, 0.000537 },
  389. { 0.617779, 0.381706, 0.000516 },
  390. { 0.622459, 0.377047, 0.000493 },
  391. { 0.627037, 0.372491, 0.000472 },
  392. { 0.631521, 0.368026, 0.000453 },
  393. { 0.635900, 0.363665, 0.000435 },
  394. { 0.640156, 0.359428, 0.000416 },
  395. { 0.644273, 0.355331, 0.000396 },
  396. { 0.648233, 0.351395, 0.000372 },
  397. { 0.652028, 0.347628, 0.000344 },
  398. { 0.655669, 0.344018, 0.000313 },
  399. { 0.659166, 0.340553, 0.000281 },
  400. { 0.662528, 0.337221, 0.000251 },
  401. { 0.665764, 0.334011, 0.000226 },
  402. { 0.668874, 0.330919, 0.000207 },
  403. { 0.671859, 0.327947, 0.000194 },
  404. { 0.674720, 0.325095, 0.000185 },
  405. { 0.677459, 0.322362, 0.000179 },
  406. { 0.680079, 0.319747, 0.000174 },
  407. { 0.682582, 0.317249, 0.000170 },
  408. { 0.684971, 0.314863, 0.000167 },
  409. { 0.687250, 0.312586, 0.000164 },
  410. { 0.689426, 0.310414, 0.000160 },
  411. { 0.691504, 0.308342, 0.000154 },
  412. { 0.693490, 0.306366, 0.000145 },
  413. { 0.695389, 0.304479, 0.000133 },
  414. { 0.697206, 0.302675, 0.000119 },
  415. { 0.698944, 0.300950, 0.000106 },
  416. { 0.700606, 0.299301, 0.000093 },
  417. { 0.702193, 0.297725, 0.000083 },
  418. { 0.703709, 0.296217, 0.000074 },
  419. { 0.705163, 0.294770, 0.000067 },
  420. { 0.706563, 0.293376, 0.000061 },
  421. { 0.707918, 0.292027, 0.000055 },
  422. { 0.709231, 0.290719, 0.000050 },
  423. { 0.710500, 0.289453, 0.000047 },
  424. { 0.711724, 0.288232, 0.000044 },
  425. { 0.712901, 0.287057, 0.000041 },
  426. { 0.714032, 0.285929, 0.000040 },
  427. { 0.715117, 0.284845, 0.000038 },
  428. { 0.716159, 0.283804, 0.000036 },
  429. { 0.717159, 0.282806, 0.000035 },
  430. { 0.718116, 0.281850, 0.000034 },
  431. { 0.719033, 0.280935, 0.000032 },
  432. { 0.719912, 0.280058, 0.000030 },
  433. { 0.720753, 0.279219, 0.000028 },
  434. { 0.721555, 0.278420, 0.000026 },
  435. { 0.722315, 0.277662, 0.000023 },
  436. { 0.723032, 0.276948, 0.000020 },
  437. { 0.723702, 0.276282, 0.000016 },
  438. { 0.724328, 0.275660, 0.000012 },
  439. { 0.724914, 0.275078, 0.000007 },
  440. { 0.725467, 0.274530, 0.000003 },
  441. { 0.725992, 0.274008, 0.000000 },
  442. { 0.726495, 0.273505, 0.000000 },
  443. { 0.726975, 0.273025, 0.000000 },
  444. { 0.727432, 0.272568, 0.000000 },
  445. { 0.727864, 0.272136, 0.000000 },
  446. { 0.728272, 0.271728, 0.000000 },
  447. { 0.728656, 0.271344, 0.000000 },
  448. { 0.729020, 0.270980, 0.000000 },
  449. { 0.729361, 0.270639, 0.000000 },
  450. { 0.729678, 0.270322, 0.000000 },
  451. { 0.729969, 0.270031, 0.000000 },
  452. { 0.730234, 0.269766, 0.000000 },
  453. { 0.730474, 0.269526, 0.000000 },
  454. { 0.730693, 0.269307, 0.000000 },
  455. { 0.730896, 0.269104, 0.000000 },
  456. { 0.731089, 0.268911, 0.000000 },
  457. { 0.731280, 0.268720, 0.000000 },
  458. { 0.731467, 0.268533, 0.000000 },
  459. { 0.731650, 0.268350, 0.000000 },
  460. { 0.731826, 0.268174, 0.000000 },
  461. { 0.731993, 0.268007, 0.000000 },
  462. { 0.732150, 0.267850, 0.000000 },
  463. { 0.732300, 0.267700, 0.000000 },
  464. { 0.732443, 0.267557, 0.000000 },
  465. { 0.732581, 0.267419, 0.000000 },
  466. { 0.732719, 0.267281, 0.000000 },
  467. { 0.732859, 0.267141, 0.000000 },
  468. { 0.733000, 0.267000, 0.000000 },
  469. { 0.733142, 0.266858, 0.000000 },
  470. { 0.733281, 0.266719, 0.000000 },
  471. { 0.733417, 0.266583, 0.000000 },
  472. { 0.733551, 0.266449, 0.000000 },
  473. { 0.733683, 0.266317, 0.000000 },
  474. { 0.733813, 0.266187, 0.000000 },
  475. { 0.733936, 0.266064, 0.000000 },
  476. { 0.734047, 0.265953, 0.000000 },
  477. { 0.734143, 0.265857, 0.000000 },
  478. { 0.734221, 0.265779, 0.000000 },
  479. { 0.734286, 0.265714, 0.000000 },
  480. { 0.734341, 0.265659, 0.000000 },
  481. { 0.734390, 0.265610, 0.000000 },
  482. { 0.734438, 0.265562, 0.000000 },
  483. { 0.734482, 0.265518, 0.000000 },
  484. { 0.734523, 0.265477, 0.000000 },
  485. { 0.734560, 0.265440, 0.000000 },
  486. { 0.734592, 0.265408, 0.000000 },
  487. { 0.734621, 0.265379, 0.000000 },
  488. { 0.734649, 0.265351, 0.000000 },
  489. { 0.734673, 0.265327, 0.000000 },
  490. { 0.734690, 0.265310, 0.000000 },
  491. { 0.734690, 0.265310, 0.000000 },
  492. { 0.734690, 0.265310, 0.000000 },
  493. { 0.734690, 0.265310, 0.000000 },
  494. { 0.734690, 0.265310, 0.000000 },
  495. { 0.734690, 0.265310, 0.000000 },
  496. { 0.734690, 0.265310, 0.000000 },
  497. { 0.734690, 0.265310, 0.000000 },
  498. { 0.734690, 0.265310, 0.000000 },
  499. { 0.734690, 0.265310, 0.000000 },
  500. { 0.734690, 0.265310, 0.000000 },
  501. { 0.734690, 0.265310, 0.000000 },
  502. { 0.734690, 0.265310, 0.000000 },
  503. { 0.734690, 0.265310, 0.000000 },
  504. { 0.734690, 0.265310, 0.000000 },
  505. { 0.734690, 0.265310, 0.000000 },
  506. { 0.734690, 0.265310, 0.000000 },
  507. { 0.734690, 0.265310, 0.000000 },
  508. { 0.734690, 0.265310, 0.000000 },
  509. { 0.734690, 0.265310, 0.000000 },
  510. { 0.734690, 0.265310, 0.000000 },
  511. { 0.734690, 0.265310, 0.000000 },
  512. { 0.734690, 0.265310, 0.000000 },
  513. { 0.734690, 0.265310, 0.000000 },
  514. { 0.734690, 0.265310, 0.000000 },
  515. { 0.734690, 0.265310, 0.000000 },
  516. { 0.734690, 0.265310, 0.000000 },
  517. { 0.734690, 0.265310, 0.000000 },
  518. { 0.734690, 0.265310, 0.000000 },
  519. { 0.734690, 0.265310, 0.000000 },
  520. { 0.734690, 0.265310, 0.000000 },
  521. { 0.734690, 0.265310, 0.000000 },
  522. { 0.734690, 0.265310, 0.000000 },
  523. { 0.734690, 0.265310, 0.000000 },
  524. { 0.734690, 0.265310, 0.000000 },
  525. { 0.734690, 0.265310, 0.000000 },
  526. { 0.734690, 0.265310, 0.000000 },
  527. { 0.734690, 0.265310, 0.000000 },
  528. { 0.734690, 0.265310, 0.000000 },
  529. { 0.734690, 0.265310, 0.000000 },
  530. { 0.734690, 0.265310, 0.000000 },
  531. { 0.734690, 0.265310, 0.000000 },
  532. { 0.734690, 0.265310, 0.000000 },
  533. { 0.734690, 0.265310, 0.000000 },
  534. { 0.734690, 0.265310, 0.000000 },
  535. { 0.734690, 0.265310, 0.000000 },
  536. { 0.734690, 0.265310, 0.000000 },
  537. { 0.734690, 0.265310, 0.000000 },
  538. { 0.734690, 0.265310, 0.000000 },
  539. { 0.734690, 0.265310, 0.000000 },
  540. { 0.734690, 0.265310, 0.000000 },
  541. { 0.734690, 0.265310, 0.000000 },
  542. { 0.734690, 0.265310, 0.000000 },
  543. { 0.734690, 0.265310, 0.000000 },
  544. { 0.734690, 0.265310, 0.000000 },
  545. { 0.734690, 0.265310, 0.000000 },
  546. { 0.734690, 0.265310, 0.000000 },
  547. { 0.734690, 0.265310, 0.000000 },
  548. { 0.734690, 0.265310, 0.000000 },
  549. { 0.734690, 0.265310, 0.000000 },
  550. { 0.734690, 0.265310, 0.000000 },
  551. { 0.734690, 0.265310, 0.000000 },
  552. { 0.734690, 0.265310, 0.000000 },
  553. { 0.734690, 0.265310, 0.000000 },
  554. { 0.734690, 0.265310, 0.000000 },
  555. { 0.734690, 0.265310, 0.000000 },
  556. { 0.734690, 0.265310, 0.000000 },
  557. { 0.734690, 0.265310, 0.000000 },
  558. { 0.734690, 0.265310, 0.000000 },
  559. { 0.734690, 0.265310, 0.000000 },
  560. { 0.734690, 0.265310, 0.000000 },
  561. { 0.734690, 0.265310, 0.000000 },
  562. { 0.734690, 0.265310, 0.000000 },
  563. { 0.734690, 0.265310, 0.000000 },
  564. { 0.734690, 0.265310, 0.000000 },
  565. { 0.734690, 0.265310, 0.000000 },
  566. { 0.734690, 0.265310, 0.000000 },
  567. { 0.734690, 0.265310, 0.000000 },
  568. { 0.734690, 0.265310, 0.000000 },
  569. { 0.734690, 0.265310, 0.000000 },
  570. { 0.734690, 0.265310, 0.000000 },
  571. { 0.734690, 0.265310, 0.000000 },
  572. { 0.734690, 0.265310, 0.000000 },
  573. { 0.734690, 0.265310, 0.000000 },
  574. { 0.734690, 0.265310, 0.000000 },
  575. { 0.734690, 0.265310, 0.000000 },
  576. { 0.734690, 0.265310, 0.000000 },
  577. { 0.734690, 0.265310, 0.000000 },
  578. { 0.734690, 0.265310, 0.000000 },
  579. { 0.734690, 0.265310, 0.000000 },
  580. { 0.734690, 0.265310, 0.000000 },
  581. { 0.734690, 0.265310, 0.000000 },
  582. { 0.734690, 0.265310, 0.000000 },
  583. { 0.734690, 0.265310, 0.000000 },
  584. { 0.734690, 0.265310, 0.000000 },
  585. { 0.734690, 0.265310, 0.000000 },
  586. { 0.734690, 0.265310, 0.000000 },
  587. { 0.734690, 0.265310, 0.000000 },
  588. { 0.734690, 0.265310, 0.000000 },
  589. { 0.734690, 0.265310, 0.000000 },
  590. { 0.734690, 0.265310, 0.000000 },
  591. { 0.734690, 0.265310, 0.000000 },
  592. { 0.734690, 0.265310, 0.000000 },
  593. { 0.734690, 0.265310, 0.000000 },
  594. { 0.734690, 0.265310, 0.000000 },
  595. { 0.734690, 0.265310, 0.000000 },
  596. { 0.734690, 0.265310, 0.000000 },
  597. { 0.734690, 0.265310, 0.000000 },
  598. { 0.734690, 0.265310, 0.000000 },
  599. { 0.734690, 0.265310, 0.000000 },
  600. { 0.734690, 0.265310, 0.000000 },
  601. { 0.734690, 0.265310, 0.000000 },
  602. { 0.734690, 0.265310, 0.000000 },
  603. { 0.734690, 0.265310, 0.000000 },
  604. { 0.734690, 0.265310, 0.000000 },
  605. { 0.734690, 0.265310, 0.000000 },
  606. { 0.734690, 0.265310, 0.000000 },
  607. { 0.734690, 0.265310, 0.000000 },
  608. { 0.734690, 0.265310, 0.000000 },
  609. { 0.734690, 0.265310, 0.000000 },
  610. { 0.734690, 0.265310, 0.000000 },
  611. { 0.734690, 0.265310, 0.000000 },
  612. { 0.734690, 0.265310, 0.000000 },
  613. { 0.734690, 0.265310, 0.000000 },
  614. { 0.734690, 0.265310, 0.000000 },
  615. { 0.734690, 0.265310, 0.000000 },
  616. { 0.734690, 0.265310, 0.000000 },
  617. { 0.734690, 0.265310, 0.000000 },
  618. { 0.734690, 0.265310, 0.000000 },
  619. { 0.734690, 0.265310, 0.000000 },
  620. { 0.734690, 0.265310, 0.000000 },
  621. { 0.734690, 0.265310, 0.000000 },
  622. };
  623. /* Standard white point chromaticities. */
  624. #define C 0.310063, 0.316158
  625. #define E 1.0/3.0, 1.0/3.0
  626. #define D50 0.34570, 0.3585
  627. #define D65 0.312713, 0.329016
  628. /* Gamma of nonlinear correction.
  629. See Charles Poynton's ColorFAQ Item 45 and GammaFAQ Item 6 at
  630. http://www.inforamp.net/~poynton/ColorFAQ.html
  631. http://www.inforamp.net/~poynton/GammaFAQ.html
  632. */
  633. #define GAMMA_REC709 0. /* Rec. 709 */
  634. static const struct ColorSystem color_systems[] = {
  635. [NTSCsystem] = {
  636. 0.67, 0.33, 0.21, 0.71, 0.14, 0.08,
  637. C, GAMMA_REC709
  638. },
  639. [EBUsystem] = {
  640. 0.64, 0.33, 0.29, 0.60, 0.15, 0.06,
  641. D65, GAMMA_REC709
  642. },
  643. [SMPTEsystem] = {
  644. 0.630, 0.340, 0.310, 0.595, 0.155, 0.070,
  645. D65, GAMMA_REC709
  646. },
  647. [SMPTE240Msystem] = {
  648. 0.670, 0.330, 0.210, 0.710, 0.150, 0.060,
  649. D65, GAMMA_REC709
  650. },
  651. [APPLEsystem] = {
  652. 0.625, 0.340, 0.280, 0.595, 0.115, 0.070,
  653. D65, GAMMA_REC709
  654. },
  655. [wRGBsystem] = {
  656. 0.7347, 0.2653, 0.1152, 0.8264, 0.1566, 0.0177,
  657. D50, GAMMA_REC709
  658. },
  659. [CIE1931system] = {
  660. 0.7347, 0.2653, 0.2738, 0.7174, 0.1666, 0.0089,
  661. E, GAMMA_REC709
  662. },
  663. [Rec709system] = {
  664. 0.64, 0.33, 0.30, 0.60, 0.15, 0.06,
  665. D65, GAMMA_REC709
  666. },
  667. [Rec2020system] = {
  668. 0.708, 0.292, 0.170, 0.797, 0.131, 0.046,
  669. D65, GAMMA_REC709
  670. },
  671. };
  672. /*
  673. static struct ColorSystem CustomSystem = {
  674. "Custom",
  675. 0.64, 0.33, 0.30, 0.60, 0.15, 0.06,
  676. D65, GAMMA_REC709
  677. };
  678. */
  679. static void
  680. uv_to_xy(double const u,
  681. double const v,
  682. double * const xc,
  683. double * const yc)
  684. {
  685. /*
  686. Given 1970 coordinates u, v, determine 1931 chromaticities x, y
  687. */
  688. *xc = 3*u / (2*u - 8*v + 4);
  689. *yc = 2*v / (2*u - 8*v + 4);
  690. }
  691. static void
  692. upvp_to_xy(double const up,
  693. double const vp,
  694. double * const xc,
  695. double * const yc)
  696. {
  697. /*
  698. Given 1976 coordinates u', v', determine 1931 chromaticities x, y
  699. */
  700. *xc = 9*up / (6*up - 16*vp + 12);
  701. *yc = 4*vp / (6*up - 16*vp + 12);
  702. }
  703. static void
  704. xy_to_upvp(double xc,
  705. double yc,
  706. double * const up,
  707. double * const vp)
  708. {
  709. /*
  710. Given 1931 chromaticities x, y, determine 1976 coordinates u', v'
  711. */
  712. *up = 4*xc / (- 2*xc + 12*yc + 3);
  713. *vp = 9*yc / (- 2*xc + 12*yc + 3);
  714. }
  715. static void
  716. xy_to_uv(double xc,
  717. double yc,
  718. double * const u,
  719. double * const v)
  720. {
  721. /*
  722. Given 1931 chromaticities x, y, determine 1960 coordinates u, v
  723. */
  724. *u = 4*xc / (- 2*xc + 12*yc + 3);
  725. *v = 6*yc / (- 2*xc + 12*yc + 3);
  726. }
  727. static void
  728. xyz_to_rgb(const double m[3][3],
  729. double xc, double yc, double zc,
  730. double * const r, double * const g, double * const b)
  731. {
  732. *r = m[0][0]*xc + m[0][1]*yc + m[0][2]*zc;
  733. *g = m[1][0]*xc + m[1][1]*yc + m[1][2]*zc;
  734. *b = m[2][0]*xc + m[2][1]*yc + m[2][2]*zc;
  735. }
  736. static void invert_matrix3x3(double in[3][3], double out[3][3])
  737. {
  738. double m00 = in[0][0], m01 = in[0][1], m02 = in[0][2],
  739. m10 = in[1][0], m11 = in[1][1], m12 = in[1][2],
  740. m20 = in[2][0], m21 = in[2][1], m22 = in[2][2];
  741. int i, j;
  742. double det;
  743. out[0][0] = (m11 * m22 - m21 * m12);
  744. out[0][1] = -(m01 * m22 - m21 * m02);
  745. out[0][2] = (m01 * m12 - m11 * m02);
  746. out[1][0] = -(m10 * m22 - m20 * m12);
  747. out[1][1] = (m00 * m22 - m20 * m02);
  748. out[1][2] = -(m00 * m12 - m10 * m02);
  749. out[2][0] = (m10 * m21 - m20 * m11);
  750. out[2][1] = -(m00 * m21 - m20 * m01);
  751. out[2][2] = (m00 * m11 - m10 * m01);
  752. det = m00 * out[0][0] + m10 * out[0][1] + m20 * out[0][2];
  753. det = 1.0 / det;
  754. for (i = 0; i < 3; i++) {
  755. for (j = 0; j < 3; j++)
  756. out[i][j] *= det;
  757. }
  758. }
  759. static void get_rgb2xyz_matrix(struct ColorSystem system, double m[3][3])
  760. {
  761. double S[3], X[4], Z[4];
  762. int i;
  763. X[0] = system.xRed / system.yRed;
  764. X[1] = system.xGreen / system.yGreen;
  765. X[2] = system.xBlue / system.yBlue;
  766. X[3] = system.xWhite / system.yWhite;
  767. Z[0] = (1 - system.xRed - system.yRed) / system.yRed;
  768. Z[1] = (1 - system.xGreen - system.yGreen) / system.yGreen;
  769. Z[2] = (1 - system.xBlue - system.yBlue) / system.yBlue;
  770. Z[3] = (1 - system.xWhite - system.yWhite) / system.yWhite;
  771. for (i = 0; i < 3; i++) {
  772. m[0][i] = X[i];
  773. m[1][i] = 1;
  774. m[2][i] = Z[i];
  775. }
  776. invert_matrix3x3(m, m);
  777. for (i = 0; i < 3; i++)
  778. S[i] = m[i][0] * X[3] + m[i][1] * 1 + m[i][2] * Z[3];
  779. for (i = 0; i < 3; i++) {
  780. m[0][i] = S[i] * X[i];
  781. m[1][i] = S[i] * 1;
  782. m[2][i] = S[i] * Z[i];
  783. }
  784. }
  785. static void
  786. rgb_to_xy(double rc,
  787. double gc,
  788. double bc,
  789. double * const x,
  790. double * const y,
  791. double * const z,
  792. const double m[3][3])
  793. {
  794. double sum;
  795. *x = m[0][0] * rc + m[0][1] * gc + m[0][2] * bc;
  796. *y = m[1][0] * rc + m[1][1] * gc + m[1][2] * bc;
  797. *z = m[2][0] * rc + m[2][1] * gc + m[2][2] * bc;
  798. sum = *x + *y + *z;
  799. *x = *x / sum;
  800. *y = *y / sum;
  801. }
  802. static int
  803. constrain_rgb(double * const r,
  804. double * const g,
  805. double * const b)
  806. {
  807. /*----------------------------------------------------------------------------
  808. If the requested RGB shade contains a negative weight for one of
  809. the primaries, it lies outside the color gamut accessible from
  810. the given triple of primaries. Desaturate it by adding white,
  811. equal quantities of R, G, and B, enough to make RGB all positive.
  812. -----------------------------------------------------------------------------*/
  813. double w;
  814. /* Amount of white needed is w = - min(0, *r, *g, *b) */
  815. w = (0 < *r) ? 0 : *r;
  816. w = (w < *g) ? w : *g;
  817. w = (w < *b) ? w : *b;
  818. w = - w;
  819. /* Add just enough white to make r, g, b all positive. */
  820. if (w > 0) {
  821. *r += w; *g += w; *b += w;
  822. return 1; /* Color modified to fit RGB gamut */
  823. }
  824. return 0; /* Color within RGB gamut */
  825. }
  826. static void
  827. gamma_correct(const struct ColorSystem * const cs,
  828. double * const c)
  829. {
  830. /*----------------------------------------------------------------------------
  831. Transform linear RGB values to nonlinear RGB values.
  832. Rec. 709 is ITU-R Recommendation BT. 709 (1990)
  833. ``Basic Parameter Values for the HDTV Standard for the Studio and for
  834. International Programme Exchange'', formerly CCIR Rec. 709.
  835. For details see
  836. http://www.inforamp.net/~poynton/ColorFAQ.html
  837. http://www.inforamp.net/~poynton/GammaFAQ.html
  838. -----------------------------------------------------------------------------*/
  839. double gamma;
  840. double cc;
  841. gamma = cs->gamma;
  842. if (gamma == 0.) {
  843. /* Rec. 709 gamma correction. */
  844. cc = 0.018;
  845. if (*c < cc) {
  846. *c *= (1.099 * pow(cc, 0.45) - 0.099) / cc;
  847. } else {
  848. *c = 1.099 * pow(*c, 0.45) - 0.099;
  849. }
  850. } else {
  851. /* Nonlinear color = (Linear color)^(1/gamma) */
  852. *c = pow(*c, 1./gamma);
  853. }
  854. }
  855. static void
  856. gamma_correct_rgb(const struct ColorSystem * const cs,
  857. double * const r,
  858. double * const g,
  859. double * const b)
  860. {
  861. gamma_correct(cs, r);
  862. gamma_correct(cs, g);
  863. gamma_correct(cs, b);
  864. }
  865. /* Sz(X) is the displacement in pixels of a displacement of X normalized
  866. distance units. (A normalized distance unit is 1/512 of the smaller
  867. dimension of the canvas)
  868. */
  869. #define Sz(x) (((x) * (int)FFMIN(w, h)) / 512)
  870. static void
  871. monochrome_color_location(double waveLength, int w, int h,
  872. int cie, int *xP, int *yP)
  873. {
  874. const int ix = waveLength - 360;
  875. const double pX = spectral_chromaticity[ix][0];
  876. const double pY = spectral_chromaticity[ix][1];
  877. const double pZ = spectral_chromaticity[ix][2];
  878. const double px = pX / (pX + pY + pZ);
  879. const double py = pY / (pX + pY + pZ);
  880. if (cie == LUV) {
  881. double up, vp;
  882. xy_to_upvp(px, py, &up, &vp);
  883. *xP = up * (w - 1);
  884. *yP = (h - 1) - vp * (h - 1);
  885. } else if (cie == UCS) {
  886. double u, v;
  887. xy_to_uv(px, py, &u, &v);
  888. *xP = u * (w - 1);
  889. *yP = (h - 1) - v * (h - 1);
  890. } else if (cie == XYY) {
  891. *xP = px * (w - 1);
  892. *yP = (h - 1) - py * (h - 1);
  893. } else {
  894. av_assert0(0);
  895. }
  896. }
  897. static void
  898. find_tongue(uint16_t* const pixels,
  899. int const w,
  900. int const linesize,
  901. int const row,
  902. int * const presentP,
  903. int * const leftEdgeP,
  904. int * const rightEdgeP)
  905. {
  906. int i;
  907. for (i = 0; i < w && pixels[row * linesize + i * 4 + 0] == 0; i++)
  908. ;
  909. if (i >= w) {
  910. *presentP = 0;
  911. } else {
  912. int j;
  913. int const leftEdge = i;
  914. *presentP = 1;
  915. for (j = w - 1; j >= leftEdge && pixels[row * linesize + j * 4 + 0] == 0; j--)
  916. ;
  917. *rightEdgeP = j;
  918. *leftEdgeP = leftEdge;
  919. }
  920. }
  921. static void draw_line(uint16_t *const pixels, int linesize,
  922. int x0, int y0, int x1, int y1,
  923. int w, int h,
  924. const uint16_t *const rgbcolor)
  925. {
  926. int dx = FFABS(x1 - x0), sx = x0 < x1 ? 1 : -1;
  927. int dy = FFABS(y1 - y0), sy = y0 < y1 ? 1 : -1;
  928. int err = (dx > dy ? dx : -dy) / 2, e2;
  929. for (;;) {
  930. pixels[y0 * linesize + x0 * 4 + 0] = rgbcolor[0];
  931. pixels[y0 * linesize + x0 * 4 + 1] = rgbcolor[1];
  932. pixels[y0 * linesize + x0 * 4 + 2] = rgbcolor[2];
  933. pixels[y0 * linesize + x0 * 4 + 3] = rgbcolor[3];
  934. if (x0 == x1 && y0 == y1)
  935. break;
  936. e2 = err;
  937. if (e2 >-dx) {
  938. err -= dy;
  939. x0 += sx;
  940. }
  941. if (e2 < dy) {
  942. err += dx;
  943. y0 += sy;
  944. }
  945. }
  946. }
  947. static void draw_rline(uint16_t *const pixels, int linesize,
  948. int x0, int y0, int x1, int y1,
  949. int w, int h)
  950. {
  951. int dx = FFABS(x1 - x0), sx = x0 < x1 ? 1 : -1;
  952. int dy = FFABS(y1 - y0), sy = y0 < y1 ? 1 : -1;
  953. int err = (dx > dy ? dx : -dy) / 2, e2;
  954. for (;;) {
  955. pixels[y0 * linesize + x0 * 4 + 0] = 65535 - pixels[y0 * linesize + x0 * 4 + 0];
  956. pixels[y0 * linesize + x0 * 4 + 1] = 65535 - pixels[y0 * linesize + x0 * 4 + 1];
  957. pixels[y0 * linesize + x0 * 4 + 2] = 65535 - pixels[y0 * linesize + x0 * 4 + 2];
  958. pixels[y0 * linesize + x0 * 4 + 3] = 65535;
  959. if (x0 == x1 && y0 == y1)
  960. break;
  961. e2 = err;
  962. if (e2 >-dx) {
  963. err -= dy;
  964. x0 += sx;
  965. }
  966. if (e2 < dy) {
  967. err += dx;
  968. y0 += sy;
  969. }
  970. }
  971. }
  972. static void
  973. tongue_outline(uint16_t* const pixels,
  974. int const linesize,
  975. int const w,
  976. int const h,
  977. uint16_t const maxval,
  978. int const cie)
  979. {
  980. const uint16_t rgbcolor[4] = { maxval, maxval, maxval, maxval };
  981. int wavelength;
  982. int lx, ly;
  983. int fx, fy;
  984. for (wavelength = 360; wavelength <= 830; wavelength++) {
  985. int icx, icy;
  986. monochrome_color_location(wavelength, w, h, cie,
  987. &icx, &icy);
  988. if (wavelength > 360)
  989. draw_line(pixels, linesize, lx, ly, icx, icy, w, h, rgbcolor);
  990. else {
  991. fx = icx;
  992. fy = icy;
  993. }
  994. lx = icx;
  995. ly = icy;
  996. }
  997. draw_line(pixels, linesize, lx, ly, fx, fy, w, h, rgbcolor);
  998. }
  999. static void
  1000. fill_in_tongue(uint16_t* const pixels,
  1001. int const linesize,
  1002. int const w,
  1003. int const h,
  1004. uint16_t const maxval,
  1005. const struct ColorSystem * const cs,
  1006. double const m[3][3],
  1007. int const cie,
  1008. int const correct_gamma,
  1009. float const contrast)
  1010. {
  1011. int y;
  1012. /* Scan the image line by line and fill the tongue outline
  1013. with the RGB values determined by the color system for the x-y
  1014. co-ordinates within the tongue.
  1015. */
  1016. for (y = 0; y < h; ++y) {
  1017. int present; /* There is some tongue on this line */
  1018. int leftEdge; /* x position of leftmost pixel in tongue on this line */
  1019. int rightEdge; /* same, but rightmost */
  1020. find_tongue(pixels, w, linesize, y, &present, &leftEdge, &rightEdge);
  1021. if (present) {
  1022. int x;
  1023. for (x = leftEdge; x <= rightEdge; ++x) {
  1024. double cx, cy, cz, jr, jg, jb, jmax;
  1025. int r, g, b, mx = maxval;
  1026. if (cie == LUV) {
  1027. double up, vp;
  1028. up = ((double) x) / (w - 1);
  1029. vp = 1.0 - ((double) y) / (h - 1);
  1030. upvp_to_xy(up, vp, &cx, &cy);
  1031. cz = 1.0 - (cx + cy);
  1032. } else if (cie == UCS) {
  1033. double u, v;
  1034. u = ((double) x) / (w - 1);
  1035. v = 1.0 - ((double) y) / (h - 1);
  1036. uv_to_xy(u, v, &cx, &cy);
  1037. cz = 1.0 - (cx + cy);
  1038. } else if (cie == XYY) {
  1039. cx = ((double) x) / (w - 1);
  1040. cy = 1.0 - ((double) y) / (h - 1);
  1041. cz = 1.0 - (cx + cy);
  1042. } else {
  1043. av_assert0(0);
  1044. }
  1045. xyz_to_rgb(m, cx, cy, cz, &jr, &jg, &jb);
  1046. /* Check whether the requested color is within the
  1047. gamut achievable with the given color system. If
  1048. not, draw it in a reduced intensity, interpolated
  1049. by desaturation to the closest within-gamut color. */
  1050. if (constrain_rgb(&jr, &jg, &jb))
  1051. mx *= contrast;
  1052. jmax = FFMAX3(jr, jg, jb);
  1053. if (jmax > 0) {
  1054. jr = jr / jmax;
  1055. jg = jg / jmax;
  1056. jb = jb / jmax;
  1057. }
  1058. /* gamma correct from linear rgb to nonlinear rgb. */
  1059. if (correct_gamma)
  1060. gamma_correct_rgb(cs, &jr, &jg, &jb);
  1061. r = mx * jr;
  1062. g = mx * jg;
  1063. b = mx * jb;
  1064. pixels[y * linesize + x * 4 + 0] = r;
  1065. pixels[y * linesize + x * 4 + 1] = g;
  1066. pixels[y * linesize + x * 4 + 2] = b;
  1067. pixels[y * linesize + x * 4 + 3] = 65535;
  1068. }
  1069. }
  1070. }
  1071. }
  1072. static void
  1073. plot_white_point(uint16_t* pixels,
  1074. int const linesize,
  1075. int const w,
  1076. int const h,
  1077. int const maxval,
  1078. int const color_system,
  1079. int const cie)
  1080. {
  1081. const struct ColorSystem *cs = &color_systems[color_system];
  1082. int wx, wy;
  1083. if (cie == LUV) {
  1084. double wup, wvp;
  1085. xy_to_upvp(cs->xWhite, cs->yWhite, &wup, &wvp);
  1086. wx = wup;
  1087. wy = wvp;
  1088. wx = (w - 1) * wup;
  1089. wy = (h - 1) - ((int) ((h - 1) * wvp));
  1090. } else if (cie == UCS) {
  1091. double wu, wv;
  1092. xy_to_uv(cs->xWhite, cs->yWhite, &wu, &wv);
  1093. wx = wu;
  1094. wy = wv;
  1095. wx = (w - 1) * wu;
  1096. wy = (h - 1) - ((int) ((h - 1) * wv));
  1097. } else if (cie == XYY) {
  1098. wx = (w - 1) * cs->xWhite;
  1099. wy = (h - 1) - ((int) ((h - 1) * cs->yWhite));
  1100. } else {
  1101. av_assert0(0);
  1102. }
  1103. draw_rline(pixels, linesize,
  1104. wx + Sz(3), wy, wx + Sz(10), wy,
  1105. w, h);
  1106. draw_rline(pixels, linesize,
  1107. wx - Sz(3), wy, wx - Sz(10), wy,
  1108. w, h);
  1109. draw_rline(pixels, linesize,
  1110. wx, wy + Sz(3), wx, wy + Sz(10),
  1111. w, h);
  1112. draw_rline(pixels, linesize,
  1113. wx, wy - Sz(3), wx, wy - Sz(10),
  1114. w, h);
  1115. }
  1116. static int draw_background(AVFilterContext *ctx)
  1117. {
  1118. CiescopeContext *s = ctx->priv;
  1119. const struct ColorSystem *cs = &color_systems[s->color_system];
  1120. AVFilterLink *outlink = ctx->outputs[0];
  1121. int w = s->size;
  1122. int h = s->size;
  1123. uint16_t *pixels;
  1124. if ((s->f = ff_get_video_buffer(outlink, outlink->w, outlink->h)) == NULL)
  1125. return AVERROR(ENOMEM);
  1126. pixels = (uint16_t *)s->f->data[0];
  1127. tongue_outline(pixels, s->f->linesize[0] / 2, w, h, 65535, s->cie);
  1128. fill_in_tongue(pixels, s->f->linesize[0] / 2, w, h, 65535, cs, (const double (*)[3])s->i, s->cie,
  1129. s->correct_gamma, s->contrast);
  1130. return 0;
  1131. }
  1132. static void filter_rgb48(AVFilterContext *ctx, AVFrame *in, double *cx, double *cy, int x, int y)
  1133. {
  1134. CiescopeContext *s = ctx->priv;
  1135. const uint16_t* src = (const uint16_t*)(in->data[0] + in->linesize[0] * y + x * 6);
  1136. double r = src[0] / 65535.;
  1137. double g = src[1] / 65535.;
  1138. double b = src[2] / 65535.;
  1139. double cz;
  1140. rgb_to_xy(r, g, b, cx, cy, &cz, (const double (*)[3])s->m);
  1141. }
  1142. static void filter_rgba64(AVFilterContext *ctx, AVFrame *in, double *cx, double *cy, int x, int y)
  1143. {
  1144. CiescopeContext *s = ctx->priv;
  1145. const uint16_t* src = (const uint16_t*)(in->data[0] + in->linesize[0] * y + x * 8);
  1146. double r = src[0] / 65535.;
  1147. double g = src[1] / 65535.;
  1148. double b = src[2] / 65535.;
  1149. double cz;
  1150. rgb_to_xy(r, g, b, cx, cy, &cz, (const double (*)[3])s->m);
  1151. }
  1152. static void filter_rgb24(AVFilterContext *ctx, AVFrame *in, double *cx, double *cy, int x, int y)
  1153. {
  1154. CiescopeContext *s = ctx->priv;
  1155. const uint8_t* src = in->data[0] + in->linesize[0] * y + x * 3;
  1156. double r = src[0] / 255.;
  1157. double g = src[1] / 255.;
  1158. double b = src[2] / 255.;
  1159. double cz;
  1160. rgb_to_xy(r, g, b, cx, cy, &cz, (const double (*)[3])s->m);
  1161. }
  1162. static void filter_rgba(AVFilterContext *ctx, AVFrame *in, double *cx, double *cy, int x, int y)
  1163. {
  1164. CiescopeContext *s = ctx->priv;
  1165. const uint8_t* src = in->data[0] + in->linesize[0] * y + x * 4;
  1166. double r = src[0] / 255.;
  1167. double g = src[1] / 255.;
  1168. double b = src[2] / 255.;
  1169. double cz;
  1170. rgb_to_xy(r, g, b, cx, cy, &cz, (const double (*)[3])s->m);
  1171. }
  1172. static void filter_xyz(AVFilterContext *ctx, AVFrame *in, double *cx, double *cy, int x, int y)
  1173. {
  1174. CiescopeContext *s = ctx->priv;
  1175. const uint16_t* src = (uint16_t *)(in->data[0] + in->linesize[0] * y + x * 6);
  1176. double lx = s->log2lin[src[0]];
  1177. double ly = s->log2lin[src[1]];
  1178. double lz = s->log2lin[src[2]];
  1179. double sum = lx + ly + lz;
  1180. if (sum == 0)
  1181. sum = 1;
  1182. *cx = lx / sum;
  1183. *cy = ly / sum;
  1184. }
  1185. static void plot_gamuts(uint16_t *pixels, int linesize, int w, int h,
  1186. int cie, int gamuts)
  1187. {
  1188. int i;
  1189. for (i = 0; i < NB_CS; i++) {
  1190. const struct ColorSystem *cs = &color_systems[i];
  1191. int rx, ry, gx, gy, bx, by;
  1192. if (!((1 << i) & gamuts))
  1193. continue;
  1194. if (cie == LUV) {
  1195. double wup, wvp;
  1196. xy_to_upvp(cs->xRed, cs->yRed, &wup, &wvp);
  1197. rx = (w - 1) * wup;
  1198. ry = (h - 1) - ((int) ((h - 1) * wvp));
  1199. xy_to_upvp(cs->xGreen, cs->yGreen, &wup, &wvp);
  1200. gx = (w - 1) * wup;
  1201. gy = (h - 1) - ((int) ((h - 1) * wvp));
  1202. xy_to_upvp(cs->xBlue, cs->yBlue, &wup, &wvp);
  1203. bx = (w - 1) * wup;
  1204. by = (h - 1) - ((int) ((h - 1) * wvp));
  1205. } else if (cie == UCS) {
  1206. double wu, wv;
  1207. xy_to_uv(cs->xRed, cs->yRed, &wu, &wv);
  1208. rx = (w - 1) * wu;
  1209. ry = (h - 1) - ((int) ((h - 1) * wv));
  1210. xy_to_uv(cs->xGreen, cs->yGreen, &wu, &wv);
  1211. gx = (w - 1) * wu;
  1212. gy = (h - 1) - ((int) ((h - 1) * wv));
  1213. xy_to_uv(cs->xBlue, cs->yBlue, &wu, &wv);
  1214. bx = (w - 1) * wu;
  1215. by = (h - 1) - ((int) ((h - 1) * wv));
  1216. } else if (cie == XYY) {
  1217. rx = (w - 1) * cs->xRed;
  1218. ry = (h - 1) - ((int) ((h - 1) * cs->yRed));
  1219. gx = (w - 1) * cs->xGreen;
  1220. gy = (h - 1) - ((int) ((h - 1) * cs->yGreen));
  1221. bx = (w - 1) * cs->xBlue;
  1222. by = (h - 1) - ((int) ((h - 1) * cs->yBlue));
  1223. } else {
  1224. av_assert0(0);
  1225. }
  1226. draw_rline(pixels, linesize, rx, ry, gx, gy, w, h);
  1227. draw_rline(pixels, linesize, gx, gy, bx, by, w, h);
  1228. draw_rline(pixels, linesize, bx, by, rx, ry, w, h);
  1229. }
  1230. }
  1231. static int filter_frame(AVFilterLink *inlink, AVFrame *in)
  1232. {
  1233. AVFilterContext *ctx = inlink->dst;
  1234. CiescopeContext *s = ctx->priv;
  1235. AVFilterLink *outlink = ctx->outputs[0];
  1236. int i = s->intensity * 65535;
  1237. int w = outlink->w;
  1238. int h = outlink->h;
  1239. AVFrame *out;
  1240. int ret, x, y;
  1241. out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
  1242. if (!out) {
  1243. av_frame_free(&in);
  1244. return AVERROR(ENOMEM);
  1245. }
  1246. out->pts = in->pts;
  1247. if (!s->background) {
  1248. ret = draw_background(ctx);
  1249. if (ret < 0)
  1250. return ret;
  1251. s->background = 1;
  1252. }
  1253. for (y = 0; y < outlink->h; y++) {
  1254. memset(out->data[0] + y * out->linesize[0], 0, outlink->w * 8);
  1255. }
  1256. for (y = 0; y < in->height; y++) {
  1257. for (x = 0; x < in->width; x++) {
  1258. double cx, cy;
  1259. uint16_t *dst;
  1260. int wx, wy;
  1261. s->filter(ctx, in, &cx, &cy, x, y);
  1262. if (s->cie == LUV) {
  1263. double up, vp;
  1264. xy_to_upvp(cx, cy, &up, &vp);
  1265. cx = up;
  1266. cy = vp;
  1267. } else if (s->cie == UCS) {
  1268. double u, v;
  1269. xy_to_uv(cx, cy, &u, &v);
  1270. cx = u;
  1271. cy = v;
  1272. }
  1273. wx = (w - 1) * cx;
  1274. wy = (h - 1) - ((h - 1) * cy);
  1275. if (wx < 0 || wx >= w ||
  1276. wy < 0 || wy >= h)
  1277. continue;
  1278. dst = (uint16_t *)(out->data[0] + wy * out->linesize[0] + wx * 8 + 0);
  1279. dst[0] = FFMIN(dst[0] + i, 65535);
  1280. dst[1] = FFMIN(dst[1] + i, 65535);
  1281. dst[2] = FFMIN(dst[2] + i, 65535);
  1282. dst[3] = 65535;
  1283. }
  1284. }
  1285. for (y = 0; y < outlink->h; y++) {
  1286. uint16_t *dst = (uint16_t *)(out->data[0] + y * out->linesize[0]);
  1287. const uint16_t *src = (const uint16_t *)(s->f->data[0] + y * s->f->linesize[0]);
  1288. for (x = 0; x < outlink->w; x++) {
  1289. const int xx = x * 4;
  1290. if (dst[xx + 3] == 0) {
  1291. dst[xx + 0] = src[xx + 0];
  1292. dst[xx + 1] = src[xx + 1];
  1293. dst[xx + 2] = src[xx + 2];
  1294. dst[xx + 3] = src[xx + 3];
  1295. }
  1296. }
  1297. }
  1298. if (s->show_white)
  1299. plot_white_point((uint16_t *)out->data[0], out->linesize[0] / 2,
  1300. outlink->w, outlink->h, 65535,
  1301. s->color_system, s->cie);
  1302. plot_gamuts((uint16_t *)out->data[0], out->linesize[0] / 2,
  1303. outlink->w, outlink->h,
  1304. s->cie, s->gamuts);
  1305. av_frame_free(&in);
  1306. return ff_filter_frame(outlink, out);
  1307. }
  1308. static void av_cold uninit(AVFilterContext *ctx)
  1309. {
  1310. CiescopeContext *s = ctx->priv;
  1311. av_frame_free(&s->f);
  1312. }
  1313. static int config_input(AVFilterLink *inlink)
  1314. {
  1315. CiescopeContext *s = inlink->dst->priv;
  1316. int i;
  1317. get_rgb2xyz_matrix(color_systems[s->color_system], s->m);
  1318. invert_matrix3x3(s->m, s->i);
  1319. switch (inlink->format) {
  1320. case AV_PIX_FMT_RGB24:
  1321. s->filter = filter_rgb24;
  1322. break;
  1323. case AV_PIX_FMT_RGBA:
  1324. s->filter = filter_rgba;
  1325. break;
  1326. case AV_PIX_FMT_RGB48:
  1327. s->filter = filter_rgb48;
  1328. break;
  1329. case AV_PIX_FMT_RGBA64:
  1330. s->filter = filter_rgba64;
  1331. break;
  1332. case AV_PIX_FMT_XYZ12:
  1333. s->filter = filter_xyz;
  1334. for (i = 0; i < 65536; i++)
  1335. s->log2lin[i] = pow(i / 65535., s->igamma) * 65535.;
  1336. break;
  1337. default:
  1338. av_assert0(0);
  1339. }
  1340. return 0;
  1341. }
  1342. static const AVFilterPad inputs[] = {
  1343. {
  1344. .name = "default",
  1345. .type = AVMEDIA_TYPE_VIDEO,
  1346. .filter_frame = filter_frame,
  1347. .config_props = config_input,
  1348. },
  1349. { NULL }
  1350. };
  1351. static const AVFilterPad outputs[] = {
  1352. {
  1353. .name = "default",
  1354. .type = AVMEDIA_TYPE_VIDEO,
  1355. .config_props = config_output,
  1356. },
  1357. { NULL }
  1358. };
  1359. AVFilter ff_vf_ciescope = {
  1360. .name = "ciescope",
  1361. .description = NULL_IF_CONFIG_SMALL("Video CIE scope."),
  1362. .priv_size = sizeof(CiescopeContext),
  1363. .priv_class = &ciescope_class,
  1364. .query_formats = query_formats,
  1365. .uninit = uninit,
  1366. .inputs = inputs,
  1367. .outputs = outputs,
  1368. };