vf_ciescope.c 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512
  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. av_frame_free(&out);
  1251. return ret;
  1252. }
  1253. s->background = 1;
  1254. }
  1255. for (y = 0; y < outlink->h; y++) {
  1256. memset(out->data[0] + y * out->linesize[0], 0, outlink->w * 8);
  1257. }
  1258. for (y = 0; y < in->height; y++) {
  1259. for (x = 0; x < in->width; x++) {
  1260. double cx, cy;
  1261. uint16_t *dst;
  1262. int wx, wy;
  1263. s->filter(ctx, in, &cx, &cy, x, y);
  1264. if (s->cie == LUV) {
  1265. double up, vp;
  1266. xy_to_upvp(cx, cy, &up, &vp);
  1267. cx = up;
  1268. cy = vp;
  1269. } else if (s->cie == UCS) {
  1270. double u, v;
  1271. xy_to_uv(cx, cy, &u, &v);
  1272. cx = u;
  1273. cy = v;
  1274. }
  1275. wx = (w - 1) * cx;
  1276. wy = (h - 1) - ((h - 1) * cy);
  1277. if (wx < 0 || wx >= w ||
  1278. wy < 0 || wy >= h)
  1279. continue;
  1280. dst = (uint16_t *)(out->data[0] + wy * out->linesize[0] + wx * 8 + 0);
  1281. dst[0] = FFMIN(dst[0] + i, 65535);
  1282. dst[1] = FFMIN(dst[1] + i, 65535);
  1283. dst[2] = FFMIN(dst[2] + i, 65535);
  1284. dst[3] = 65535;
  1285. }
  1286. }
  1287. for (y = 0; y < outlink->h; y++) {
  1288. uint16_t *dst = (uint16_t *)(out->data[0] + y * out->linesize[0]);
  1289. const uint16_t *src = (const uint16_t *)(s->f->data[0] + y * s->f->linesize[0]);
  1290. for (x = 0; x < outlink->w; x++) {
  1291. const int xx = x * 4;
  1292. if (dst[xx + 3] == 0) {
  1293. dst[xx + 0] = src[xx + 0];
  1294. dst[xx + 1] = src[xx + 1];
  1295. dst[xx + 2] = src[xx + 2];
  1296. dst[xx + 3] = src[xx + 3];
  1297. }
  1298. }
  1299. }
  1300. if (s->show_white)
  1301. plot_white_point((uint16_t *)out->data[0], out->linesize[0] / 2,
  1302. outlink->w, outlink->h, 65535,
  1303. s->color_system, s->cie);
  1304. plot_gamuts((uint16_t *)out->data[0], out->linesize[0] / 2,
  1305. outlink->w, outlink->h,
  1306. s->cie, s->gamuts);
  1307. av_frame_free(&in);
  1308. return ff_filter_frame(outlink, out);
  1309. }
  1310. static void av_cold uninit(AVFilterContext *ctx)
  1311. {
  1312. CiescopeContext *s = ctx->priv;
  1313. av_frame_free(&s->f);
  1314. }
  1315. static int config_input(AVFilterLink *inlink)
  1316. {
  1317. CiescopeContext *s = inlink->dst->priv;
  1318. int i;
  1319. get_rgb2xyz_matrix(color_systems[s->color_system], s->m);
  1320. invert_matrix3x3(s->m, s->i);
  1321. switch (inlink->format) {
  1322. case AV_PIX_FMT_RGB24:
  1323. s->filter = filter_rgb24;
  1324. break;
  1325. case AV_PIX_FMT_RGBA:
  1326. s->filter = filter_rgba;
  1327. break;
  1328. case AV_PIX_FMT_RGB48:
  1329. s->filter = filter_rgb48;
  1330. break;
  1331. case AV_PIX_FMT_RGBA64:
  1332. s->filter = filter_rgba64;
  1333. break;
  1334. case AV_PIX_FMT_XYZ12:
  1335. s->filter = filter_xyz;
  1336. for (i = 0; i < 65536; i++)
  1337. s->log2lin[i] = pow(i / 65535., s->igamma) * 65535.;
  1338. break;
  1339. default:
  1340. av_assert0(0);
  1341. }
  1342. return 0;
  1343. }
  1344. static const AVFilterPad inputs[] = {
  1345. {
  1346. .name = "default",
  1347. .type = AVMEDIA_TYPE_VIDEO,
  1348. .filter_frame = filter_frame,
  1349. .config_props = config_input,
  1350. },
  1351. { NULL }
  1352. };
  1353. static const AVFilterPad outputs[] = {
  1354. {
  1355. .name = "default",
  1356. .type = AVMEDIA_TYPE_VIDEO,
  1357. .config_props = config_output,
  1358. },
  1359. { NULL }
  1360. };
  1361. AVFilter ff_vf_ciescope = {
  1362. .name = "ciescope",
  1363. .description = NULL_IF_CONFIG_SMALL("Video CIE scope."),
  1364. .priv_size = sizeof(CiescopeContext),
  1365. .priv_class = &ciescope_class,
  1366. .query_formats = query_formats,
  1367. .uninit = uninit,
  1368. .inputs = inputs,
  1369. .outputs = outputs,
  1370. };