pixdesc.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011
  1. /*
  2. * pixel format descriptor
  3. * Copyright (c) 2009 Michael Niedermayer <michaelni@gmx.at>
  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 <stdio.h>
  22. #include <string.h>
  23. #include "pixfmt.h"
  24. #include "pixdesc.h"
  25. #include "intreadwrite.h"
  26. void av_read_image_line(uint16_t *dst, const uint8_t *data[4], const int linesize[4],
  27. const AVPixFmtDescriptor *desc, int x, int y, int c, int w, int read_pal_component)
  28. {
  29. AVComponentDescriptor comp= desc->comp[c];
  30. int plane= comp.plane;
  31. int depth= comp.depth_minus1+1;
  32. int mask = (1<<depth)-1;
  33. int shift= comp.shift;
  34. int step = comp.step_minus1+1;
  35. int flags= desc->flags;
  36. if (flags & PIX_FMT_BITSTREAM){
  37. int skip = x*step + comp.offset_plus1-1;
  38. const uint8_t *p = data[plane] + y*linesize[plane] + (skip>>3);
  39. int shift = 8 - depth - (skip&7);
  40. while(w--){
  41. int val = (*p >> shift) & mask;
  42. if(read_pal_component)
  43. val= data[1][4*val + c];
  44. shift -= step;
  45. p -= shift>>3;
  46. shift &= 7;
  47. *dst++= val;
  48. }
  49. } else {
  50. const uint8_t *p = data[plane]+ y*linesize[plane] + x*step + comp.offset_plus1-1;
  51. int is_8bit = shift + depth <= 8;
  52. if (is_8bit)
  53. p += !!(flags & PIX_FMT_BE);
  54. while(w--){
  55. int val = is_8bit ? *p :
  56. flags & PIX_FMT_BE ? AV_RB16(p) : AV_RL16(p);
  57. val = (val>>shift) & mask;
  58. if(read_pal_component)
  59. val= data[1][4*val + c];
  60. p+= step;
  61. *dst++= val;
  62. }
  63. }
  64. }
  65. void av_write_image_line(const uint16_t *src, uint8_t *data[4], const int linesize[4],
  66. const AVPixFmtDescriptor *desc, int x, int y, int c, int w)
  67. {
  68. AVComponentDescriptor comp = desc->comp[c];
  69. int plane = comp.plane;
  70. int depth = comp.depth_minus1+1;
  71. int step = comp.step_minus1+1;
  72. int flags = desc->flags;
  73. if (flags & PIX_FMT_BITSTREAM) {
  74. int skip = x*step + comp.offset_plus1-1;
  75. uint8_t *p = data[plane] + y*linesize[plane] + (skip>>3);
  76. int shift = 8 - depth - (skip&7);
  77. while (w--) {
  78. *p |= *src++ << shift;
  79. shift -= step;
  80. p -= shift>>3;
  81. shift &= 7;
  82. }
  83. } else {
  84. int shift = comp.shift;
  85. uint8_t *p = data[plane]+ y*linesize[plane] + x*step + comp.offset_plus1-1;
  86. if (shift + depth <= 8) {
  87. p += !!(flags & PIX_FMT_BE);
  88. while (w--) {
  89. *p |= (*src++<<shift);
  90. p += step;
  91. }
  92. } else {
  93. while (w--) {
  94. if (flags & PIX_FMT_BE) {
  95. uint16_t val = AV_RB16(p) | (*src++<<shift);
  96. AV_WB16(p, val);
  97. } else {
  98. uint16_t val = AV_RL16(p) | (*src++<<shift);
  99. AV_WL16(p, val);
  100. }
  101. p+= step;
  102. }
  103. }
  104. }
  105. }
  106. const AVPixFmtDescriptor av_pix_fmt_descriptors[PIX_FMT_NB] = {
  107. [PIX_FMT_YUV420P] = {
  108. .name = "yuv420p",
  109. .nb_components= 3,
  110. .log2_chroma_w= 1,
  111. .log2_chroma_h= 1,
  112. .comp = {
  113. {0,0,1,0,7}, /* Y */
  114. {1,0,1,0,7}, /* U */
  115. {2,0,1,0,7}, /* V */
  116. },
  117. },
  118. [PIX_FMT_YUYV422] = {
  119. .name = "yuyv422",
  120. .nb_components= 3,
  121. .log2_chroma_w= 1,
  122. .log2_chroma_h= 0,
  123. .comp = {
  124. {0,1,1,0,7}, /* Y */
  125. {0,3,2,0,7}, /* U */
  126. {0,3,4,0,7}, /* V */
  127. },
  128. },
  129. [PIX_FMT_RGB24] = {
  130. .name = "rgb24",
  131. .nb_components= 3,
  132. .log2_chroma_w= 0,
  133. .log2_chroma_h= 0,
  134. .comp = {
  135. {0,2,1,0,7}, /* R */
  136. {0,2,2,0,7}, /* G */
  137. {0,2,3,0,7}, /* B */
  138. },
  139. },
  140. [PIX_FMT_BGR24] = {
  141. .name = "bgr24",
  142. .nb_components= 3,
  143. .log2_chroma_w= 0,
  144. .log2_chroma_h= 0,
  145. .comp = {
  146. {0,2,1,0,7}, /* B */
  147. {0,2,2,0,7}, /* G */
  148. {0,2,3,0,7}, /* R */
  149. },
  150. },
  151. [PIX_FMT_YUV422P] = {
  152. .name = "yuv422p",
  153. .nb_components= 3,
  154. .log2_chroma_w= 1,
  155. .log2_chroma_h= 0,
  156. .comp = {
  157. {0,0,1,0,7}, /* Y */
  158. {1,0,1,0,7}, /* U */
  159. {2,0,1,0,7}, /* V */
  160. },
  161. },
  162. [PIX_FMT_YUV444P] = {
  163. .name = "yuv444p",
  164. .nb_components= 3,
  165. .log2_chroma_w= 0,
  166. .log2_chroma_h= 0,
  167. .comp = {
  168. {0,0,1,0,7}, /* Y */
  169. {1,0,1,0,7}, /* U */
  170. {2,0,1,0,7}, /* V */
  171. },
  172. },
  173. [PIX_FMT_YUV410P] = {
  174. .name = "yuv410p",
  175. .nb_components= 3,
  176. .log2_chroma_w= 2,
  177. .log2_chroma_h= 2,
  178. .comp = {
  179. {0,0,1,0,7}, /* Y */
  180. {1,0,1,0,7}, /* U */
  181. {2,0,1,0,7}, /* V */
  182. },
  183. },
  184. [PIX_FMT_YUV411P] = {
  185. .name = "yuv411p",
  186. .nb_components= 3,
  187. .log2_chroma_w= 2,
  188. .log2_chroma_h= 0,
  189. .comp = {
  190. {0,0,1,0,7}, /* Y */
  191. {1,0,1,0,7}, /* U */
  192. {2,0,1,0,7}, /* V */
  193. },
  194. },
  195. [PIX_FMT_GRAY8] = {
  196. .name = "gray",
  197. .nb_components= 1,
  198. .log2_chroma_w= 0,
  199. .log2_chroma_h= 0,
  200. .comp = {
  201. {0,0,1,0,7}, /* Y */
  202. },
  203. .flags = PIX_FMT_PAL,
  204. },
  205. [PIX_FMT_MONOWHITE] = {
  206. .name = "monow",
  207. .nb_components= 1,
  208. .log2_chroma_w= 0,
  209. .log2_chroma_h= 0,
  210. .comp = {
  211. {0,0,1,0,0}, /* Y */
  212. },
  213. .flags = PIX_FMT_BITSTREAM,
  214. },
  215. [PIX_FMT_MONOBLACK] = {
  216. .name = "monob",
  217. .nb_components= 1,
  218. .log2_chroma_w= 0,
  219. .log2_chroma_h= 0,
  220. .comp = {
  221. {0,0,1,7,0}, /* Y */
  222. },
  223. .flags = PIX_FMT_BITSTREAM,
  224. },
  225. [PIX_FMT_PAL8] = {
  226. .name = "pal8",
  227. .nb_components= 1,
  228. .log2_chroma_w= 0,
  229. .log2_chroma_h= 0,
  230. .comp = {
  231. {0,0,1,0,7},
  232. },
  233. .flags = PIX_FMT_PAL,
  234. },
  235. [PIX_FMT_YUVJ420P] = {
  236. .name = "yuvj420p",
  237. .nb_components= 3,
  238. .log2_chroma_w= 1,
  239. .log2_chroma_h= 1,
  240. .comp = {
  241. {0,0,1,0,7}, /* Y */
  242. {1,0,1,0,7}, /* U */
  243. {2,0,1,0,7}, /* V */
  244. },
  245. },
  246. [PIX_FMT_YUVJ422P] = {
  247. .name = "yuvj422p",
  248. .nb_components= 3,
  249. .log2_chroma_w= 1,
  250. .log2_chroma_h= 0,
  251. .comp = {
  252. {0,0,1,0,7}, /* Y */
  253. {1,0,1,0,7}, /* U */
  254. {2,0,1,0,7}, /* V */
  255. },
  256. },
  257. [PIX_FMT_YUVJ444P] = {
  258. .name = "yuvj444p",
  259. .nb_components= 3,
  260. .log2_chroma_w= 0,
  261. .log2_chroma_h= 0,
  262. .comp = {
  263. {0,0,1,0,7}, /* Y */
  264. {1,0,1,0,7}, /* U */
  265. {2,0,1,0,7}, /* V */
  266. },
  267. },
  268. [PIX_FMT_XVMC_MPEG2_MC] = {
  269. .name = "xvmcmc",
  270. .flags = PIX_FMT_HWACCEL,
  271. },
  272. [PIX_FMT_XVMC_MPEG2_IDCT] = {
  273. .name = "xvmcidct",
  274. .flags = PIX_FMT_HWACCEL,
  275. },
  276. [PIX_FMT_UYVY422] = {
  277. .name = "uyvy422",
  278. .nb_components= 3,
  279. .log2_chroma_w= 1,
  280. .log2_chroma_h= 0,
  281. .comp = {
  282. {0,1,2,0,7}, /* Y */
  283. {0,3,1,0,7}, /* U */
  284. {0,3,3,0,7}, /* V */
  285. },
  286. },
  287. [PIX_FMT_UYYVYY411] = {
  288. .name = "uyyvyy411",
  289. .nb_components= 3,
  290. .log2_chroma_w= 2,
  291. .log2_chroma_h= 0,
  292. .comp = {
  293. {0,3,2,0,7}, /* Y */
  294. {0,5,1,0,7}, /* U */
  295. {0,5,4,0,7}, /* V */
  296. },
  297. },
  298. [PIX_FMT_BGR8] = {
  299. .name = "bgr8",
  300. .nb_components= 3,
  301. .log2_chroma_w= 0,
  302. .log2_chroma_h= 0,
  303. .comp = {
  304. {0,0,1,6,1}, /* B */
  305. {0,0,1,3,2}, /* G */
  306. {0,0,1,0,2}, /* R */
  307. },
  308. .flags = PIX_FMT_PAL,
  309. },
  310. [PIX_FMT_BGR4] = {
  311. .name = "bgr4",
  312. .nb_components= 3,
  313. .log2_chroma_w= 0,
  314. .log2_chroma_h= 0,
  315. .comp = {
  316. {0,3,1,0,0}, /* B */
  317. {0,3,2,0,1}, /* G */
  318. {0,3,4,0,0}, /* R */
  319. },
  320. .flags = PIX_FMT_BITSTREAM,
  321. },
  322. [PIX_FMT_BGR4_BYTE] = {
  323. .name = "bgr4_byte",
  324. .nb_components= 3,
  325. .log2_chroma_w= 0,
  326. .log2_chroma_h= 0,
  327. .comp = {
  328. {0,0,1,3,0}, /* B */
  329. {0,0,1,1,1}, /* G */
  330. {0,0,1,0,0}, /* R */
  331. },
  332. .flags = PIX_FMT_PAL,
  333. },
  334. [PIX_FMT_RGB8] = {
  335. .name = "rgb8",
  336. .nb_components= 3,
  337. .log2_chroma_w= 0,
  338. .log2_chroma_h= 0,
  339. .comp = {
  340. {0,0,1,6,1}, /* R */
  341. {0,0,1,3,2}, /* G */
  342. {0,0,1,0,2}, /* B */
  343. },
  344. .flags = PIX_FMT_PAL,
  345. },
  346. [PIX_FMT_RGB4] = {
  347. .name = "rgb4",
  348. .nb_components= 3,
  349. .log2_chroma_w= 0,
  350. .log2_chroma_h= 0,
  351. .comp = {
  352. {0,3,1,0,0}, /* R */
  353. {0,3,2,0,1}, /* G */
  354. {0,3,4,0,0}, /* B */
  355. },
  356. .flags = PIX_FMT_BITSTREAM,
  357. },
  358. [PIX_FMT_RGB4_BYTE] = {
  359. .name = "rgb4_byte",
  360. .nb_components= 3,
  361. .log2_chroma_w= 0,
  362. .log2_chroma_h= 0,
  363. .comp = {
  364. {0,0,1,3,0}, /* R */
  365. {0,0,1,1,1}, /* G */
  366. {0,0,1,0,0}, /* B */
  367. },
  368. .flags = PIX_FMT_PAL,
  369. },
  370. [PIX_FMT_NV12] = {
  371. .name = "nv12",
  372. .nb_components= 3,
  373. .log2_chroma_w= 1,
  374. .log2_chroma_h= 1,
  375. .comp = {
  376. {0,0,1,0,7}, /* Y */
  377. {1,1,1,0,7}, /* U */
  378. {1,1,2,0,7}, /* V */
  379. },
  380. },
  381. [PIX_FMT_NV21] = {
  382. .name = "nv21",
  383. .nb_components= 3,
  384. .log2_chroma_w= 1,
  385. .log2_chroma_h= 1,
  386. .comp = {
  387. {0,0,1,0,7}, /* Y */
  388. {1,1,1,0,7}, /* V */
  389. {1,1,2,0,7}, /* U */
  390. },
  391. },
  392. [PIX_FMT_ARGB] = {
  393. .name = "argb",
  394. .nb_components= 4,
  395. .log2_chroma_w= 0,
  396. .log2_chroma_h= 0,
  397. .comp = {
  398. {0,3,1,0,7}, /* A */
  399. {0,3,2,0,7}, /* R */
  400. {0,3,3,0,7}, /* G */
  401. {0,3,4,0,7}, /* B */
  402. },
  403. },
  404. [PIX_FMT_RGBA] = {
  405. .name = "rgba",
  406. .nb_components= 4,
  407. .log2_chroma_w= 0,
  408. .log2_chroma_h= 0,
  409. .comp = {
  410. {0,3,1,0,7}, /* R */
  411. {0,3,2,0,7}, /* G */
  412. {0,3,3,0,7}, /* B */
  413. {0,3,4,0,7}, /* A */
  414. },
  415. },
  416. [PIX_FMT_ABGR] = {
  417. .name = "abgr",
  418. .nb_components= 4,
  419. .log2_chroma_w= 0,
  420. .log2_chroma_h= 0,
  421. .comp = {
  422. {0,3,1,0,7}, /* A */
  423. {0,3,2,0,7}, /* B */
  424. {0,3,3,0,7}, /* G */
  425. {0,3,4,0,7}, /* R */
  426. },
  427. },
  428. [PIX_FMT_BGRA] = {
  429. .name = "bgra",
  430. .nb_components= 4,
  431. .log2_chroma_w= 0,
  432. .log2_chroma_h= 0,
  433. .comp = {
  434. {0,3,1,0,7}, /* B */
  435. {0,3,2,0,7}, /* G */
  436. {0,3,3,0,7}, /* R */
  437. {0,3,4,0,7}, /* A */
  438. },
  439. },
  440. [PIX_FMT_GRAY16BE] = {
  441. .name = "gray16be",
  442. .nb_components= 1,
  443. .log2_chroma_w= 0,
  444. .log2_chroma_h= 0,
  445. .comp = {
  446. {0,1,1,0,15}, /* Y */
  447. },
  448. .flags = PIX_FMT_BE,
  449. },
  450. [PIX_FMT_GRAY16LE] = {
  451. .name = "gray16le",
  452. .nb_components= 1,
  453. .log2_chroma_w= 0,
  454. .log2_chroma_h= 0,
  455. .comp = {
  456. {0,1,1,0,15}, /* Y */
  457. },
  458. },
  459. [PIX_FMT_YUV440P] = {
  460. .name = "yuv440p",
  461. .nb_components= 3,
  462. .log2_chroma_w= 0,
  463. .log2_chroma_h= 1,
  464. .comp = {
  465. {0,0,1,0,7}, /* Y */
  466. {1,0,1,0,7}, /* U */
  467. {2,0,1,0,7}, /* V */
  468. },
  469. },
  470. [PIX_FMT_YUVJ440P] = {
  471. .name = "yuvj440p",
  472. .nb_components= 3,
  473. .log2_chroma_w= 0,
  474. .log2_chroma_h= 1,
  475. .comp = {
  476. {0,0,1,0,7}, /* Y */
  477. {1,0,1,0,7}, /* U */
  478. {2,0,1,0,7}, /* V */
  479. },
  480. },
  481. [PIX_FMT_YUVA420P] = {
  482. .name = "yuva420p",
  483. .nb_components= 4,
  484. .log2_chroma_w= 1,
  485. .log2_chroma_h= 1,
  486. .comp = {
  487. {0,0,1,0,7}, /* Y */
  488. {1,0,1,0,7}, /* U */
  489. {2,0,1,0,7}, /* V */
  490. {3,0,1,0,7}, /* A */
  491. },
  492. },
  493. [PIX_FMT_VDPAU_H264] = {
  494. .name = "vdpau_h264",
  495. .log2_chroma_w = 1,
  496. .log2_chroma_h = 1,
  497. .flags = PIX_FMT_HWACCEL,
  498. },
  499. [PIX_FMT_VDPAU_MPEG1] = {
  500. .name = "vdpau_mpeg1",
  501. .log2_chroma_w = 1,
  502. .log2_chroma_h = 1,
  503. .flags = PIX_FMT_HWACCEL,
  504. },
  505. [PIX_FMT_VDPAU_MPEG2] = {
  506. .name = "vdpau_mpeg2",
  507. .log2_chroma_w = 1,
  508. .log2_chroma_h = 1,
  509. .flags = PIX_FMT_HWACCEL,
  510. },
  511. [PIX_FMT_VDPAU_WMV3] = {
  512. .name = "vdpau_wmv3",
  513. .log2_chroma_w = 1,
  514. .log2_chroma_h = 1,
  515. .flags = PIX_FMT_HWACCEL,
  516. },
  517. [PIX_FMT_VDPAU_VC1] = {
  518. .name = "vdpau_vc1",
  519. .log2_chroma_w = 1,
  520. .log2_chroma_h = 1,
  521. .flags = PIX_FMT_HWACCEL,
  522. },
  523. [PIX_FMT_VDPAU_MPEG4] = {
  524. .name = "vdpau_mpeg4",
  525. .log2_chroma_w = 1,
  526. .log2_chroma_h = 1,
  527. .flags = PIX_FMT_HWACCEL,
  528. },
  529. [PIX_FMT_RGB48BE] = {
  530. .name = "rgb48be",
  531. .nb_components= 3,
  532. .log2_chroma_w= 0,
  533. .log2_chroma_h= 0,
  534. .comp = {
  535. {0,5,1,0,15}, /* R */
  536. {0,5,3,0,15}, /* G */
  537. {0,5,5,0,15}, /* B */
  538. },
  539. .flags = PIX_FMT_BE,
  540. },
  541. [PIX_FMT_RGB48LE] = {
  542. .name = "rgb48le",
  543. .nb_components= 3,
  544. .log2_chroma_w= 0,
  545. .log2_chroma_h= 0,
  546. .comp = {
  547. {0,5,1,0,15}, /* R */
  548. {0,5,3,0,15}, /* G */
  549. {0,5,5,0,15}, /* B */
  550. },
  551. },
  552. [PIX_FMT_RGB565BE] = {
  553. .name = "rgb565be",
  554. .nb_components= 3,
  555. .log2_chroma_w= 0,
  556. .log2_chroma_h= 0,
  557. .comp = {
  558. {0,1,0,3,4}, /* R */
  559. {0,1,1,5,5}, /* G */
  560. {0,1,1,0,4}, /* B */
  561. },
  562. .flags = PIX_FMT_BE,
  563. },
  564. [PIX_FMT_RGB565LE] = {
  565. .name = "rgb565le",
  566. .nb_components= 3,
  567. .log2_chroma_w= 0,
  568. .log2_chroma_h= 0,
  569. .comp = {
  570. {0,1,2,3,4}, /* R */
  571. {0,1,1,5,5}, /* G */
  572. {0,1,1,0,4}, /* B */
  573. },
  574. },
  575. [PIX_FMT_RGB555BE] = {
  576. .name = "rgb555be",
  577. .nb_components= 3,
  578. .log2_chroma_w= 0,
  579. .log2_chroma_h= 0,
  580. .comp = {
  581. {0,1,0,2,4}, /* R */
  582. {0,1,1,5,4}, /* G */
  583. {0,1,1,0,4}, /* B */
  584. },
  585. .flags = PIX_FMT_BE,
  586. },
  587. [PIX_FMT_RGB555LE] = {
  588. .name = "rgb555le",
  589. .nb_components= 3,
  590. .log2_chroma_w= 0,
  591. .log2_chroma_h= 0,
  592. .comp = {
  593. {0,1,2,2,4}, /* R */
  594. {0,1,1,5,4}, /* G */
  595. {0,1,1,0,4}, /* B */
  596. },
  597. },
  598. [PIX_FMT_RGB444BE] = {
  599. .name = "rgb444be",
  600. .nb_components= 3,
  601. .log2_chroma_w= 0,
  602. .log2_chroma_h= 0,
  603. .comp = {
  604. {0,1,0,0,3}, /* R */
  605. {0,1,1,4,3}, /* G */
  606. {0,1,1,0,3}, /* B */
  607. },
  608. .flags = PIX_FMT_BE,
  609. },
  610. [PIX_FMT_RGB444LE] = {
  611. .name = "rgb444le",
  612. .nb_components= 3,
  613. .log2_chroma_w= 0,
  614. .log2_chroma_h= 0,
  615. .comp = {
  616. {0,1,2,0,3}, /* R */
  617. {0,1,1,4,3}, /* G */
  618. {0,1,1,0,3}, /* B */
  619. },
  620. },
  621. [PIX_FMT_BGR48BE] = {
  622. .name = "bgr48be",
  623. .nb_components= 3,
  624. .log2_chroma_w= 0,
  625. .log2_chroma_h= 0,
  626. .comp = {
  627. {0,5,1,0,15}, /* B */
  628. {0,5,3,0,15}, /* G */
  629. {0,5,5,0,15}, /* R */
  630. },
  631. .flags = PIX_FMT_BE,
  632. },
  633. [PIX_FMT_BGR48LE] = {
  634. .name = "bgr48le",
  635. .nb_components= 3,
  636. .log2_chroma_w= 0,
  637. .log2_chroma_h= 0,
  638. .comp = {
  639. {0,5,1,0,15}, /* B */
  640. {0,5,3,0,15}, /* G */
  641. {0,5,5,0,15}, /* R */
  642. },
  643. },
  644. [PIX_FMT_BGR565BE] = {
  645. .name = "bgr565be",
  646. .nb_components= 3,
  647. .log2_chroma_w= 0,
  648. .log2_chroma_h= 0,
  649. .comp = {
  650. {0,1,0,3,4}, /* B */
  651. {0,1,1,5,5}, /* G */
  652. {0,1,1,0,4}, /* R */
  653. },
  654. .flags = PIX_FMT_BE,
  655. },
  656. [PIX_FMT_BGR565LE] = {
  657. .name = "bgr565le",
  658. .nb_components= 3,
  659. .log2_chroma_w= 0,
  660. .log2_chroma_h= 0,
  661. .comp = {
  662. {0,1,2,3,4}, /* B */
  663. {0,1,1,5,5}, /* G */
  664. {0,1,1,0,4}, /* R */
  665. },
  666. },
  667. [PIX_FMT_BGR555BE] = {
  668. .name = "bgr555be",
  669. .nb_components= 3,
  670. .log2_chroma_w= 0,
  671. .log2_chroma_h= 0,
  672. .comp = {
  673. {0,1,0,2,4}, /* B */
  674. {0,1,1,5,4}, /* G */
  675. {0,1,1,0,4}, /* R */
  676. },
  677. .flags = PIX_FMT_BE,
  678. },
  679. [PIX_FMT_BGR555LE] = {
  680. .name = "bgr555le",
  681. .nb_components= 3,
  682. .log2_chroma_w= 0,
  683. .log2_chroma_h= 0,
  684. .comp = {
  685. {0,1,2,2,4}, /* B */
  686. {0,1,1,5,4}, /* G */
  687. {0,1,1,0,4}, /* R */
  688. },
  689. },
  690. [PIX_FMT_BGR444BE] = {
  691. .name = "bgr444be",
  692. .nb_components= 3,
  693. .log2_chroma_w= 0,
  694. .log2_chroma_h= 0,
  695. .comp = {
  696. {0,1,0,0,3}, /* B */
  697. {0,1,1,4,3}, /* G */
  698. {0,1,1,0,3}, /* R */
  699. },
  700. .flags = PIX_FMT_BE,
  701. },
  702. [PIX_FMT_BGR444LE] = {
  703. .name = "bgr444le",
  704. .nb_components= 3,
  705. .log2_chroma_w= 0,
  706. .log2_chroma_h= 0,
  707. .comp = {
  708. {0,1,2,0,3}, /* B */
  709. {0,1,1,4,3}, /* G */
  710. {0,1,1,0,3}, /* R */
  711. },
  712. },
  713. [PIX_FMT_VAAPI_MOCO] = {
  714. .name = "vaapi_moco",
  715. .log2_chroma_w = 1,
  716. .log2_chroma_h = 1,
  717. .flags = PIX_FMT_HWACCEL,
  718. },
  719. [PIX_FMT_VAAPI_IDCT] = {
  720. .name = "vaapi_idct",
  721. .log2_chroma_w = 1,
  722. .log2_chroma_h = 1,
  723. .flags = PIX_FMT_HWACCEL,
  724. },
  725. [PIX_FMT_VAAPI_VLD] = {
  726. .name = "vaapi_vld",
  727. .log2_chroma_w = 1,
  728. .log2_chroma_h = 1,
  729. .flags = PIX_FMT_HWACCEL,
  730. },
  731. [PIX_FMT_YUV420P9LE] = {
  732. .name = "yuv420p9le",
  733. .nb_components= 3,
  734. .log2_chroma_w= 1,
  735. .log2_chroma_h= 1,
  736. .comp = {
  737. {0,1,1,0,8}, /* Y */
  738. {1,1,1,0,8}, /* U */
  739. {2,1,1,0,8}, /* V */
  740. },
  741. },
  742. [PIX_FMT_YUV420P9BE] = {
  743. .name = "yuv420p9be",
  744. .nb_components= 3,
  745. .log2_chroma_w= 1,
  746. .log2_chroma_h= 1,
  747. .comp = {
  748. {0,1,1,0,8}, /* Y */
  749. {1,1,1,0,8}, /* U */
  750. {2,1,1,0,8}, /* V */
  751. },
  752. .flags = PIX_FMT_BE,
  753. },
  754. [PIX_FMT_YUV420P10LE] = {
  755. .name = "yuv420p10le",
  756. .nb_components= 3,
  757. .log2_chroma_w= 1,
  758. .log2_chroma_h= 1,
  759. .comp = {
  760. {0,1,1,0,9}, /* Y */
  761. {1,1,1,0,9}, /* U */
  762. {2,1,1,0,9}, /* V */
  763. },
  764. },
  765. [PIX_FMT_YUV420P10BE] = {
  766. .name = "yuv420p10be",
  767. .nb_components= 3,
  768. .log2_chroma_w= 1,
  769. .log2_chroma_h= 1,
  770. .comp = {
  771. {0,1,1,0,9}, /* Y */
  772. {1,1,1,0,9}, /* U */
  773. {2,1,1,0,9}, /* V */
  774. },
  775. .flags = PIX_FMT_BE,
  776. },
  777. [PIX_FMT_YUV420P16LE] = {
  778. .name = "yuv420p16le",
  779. .nb_components= 3,
  780. .log2_chroma_w= 1,
  781. .log2_chroma_h= 1,
  782. .comp = {
  783. {0,1,1,0,15}, /* Y */
  784. {1,1,1,0,15}, /* U */
  785. {2,1,1,0,15}, /* V */
  786. },
  787. },
  788. [PIX_FMT_YUV420P16BE] = {
  789. .name = "yuv420p16be",
  790. .nb_components= 3,
  791. .log2_chroma_w= 1,
  792. .log2_chroma_h= 1,
  793. .comp = {
  794. {0,1,1,0,15}, /* Y */
  795. {1,1,1,0,15}, /* U */
  796. {2,1,1,0,15}, /* V */
  797. },
  798. .flags = PIX_FMT_BE,
  799. },
  800. [PIX_FMT_YUV422P10LE] = {
  801. .name = "yuv422p10le",
  802. .nb_components= 3,
  803. .log2_chroma_w= 1,
  804. .log2_chroma_h= 0,
  805. .comp = {
  806. {0,1,1,0,9}, /* Y */
  807. {1,1,1,0,9}, /* U */
  808. {2,1,1,0,9}, /* V */
  809. },
  810. },
  811. [PIX_FMT_YUV422P10BE] = {
  812. .name = "yuv422p10be",
  813. .nb_components= 3,
  814. .log2_chroma_w= 1,
  815. .log2_chroma_h= 0,
  816. .comp = {
  817. {0,1,1,0,9}, /* Y */
  818. {1,1,1,0,9}, /* U */
  819. {2,1,1,0,9}, /* V */
  820. },
  821. .flags = PIX_FMT_BE,
  822. },
  823. [PIX_FMT_YUV422P16LE] = {
  824. .name = "yuv422p16le",
  825. .nb_components= 3,
  826. .log2_chroma_w= 1,
  827. .log2_chroma_h= 0,
  828. .comp = {
  829. {0,1,1,0,15}, /* Y */
  830. {1,1,1,0,15}, /* U */
  831. {2,1,1,0,15}, /* V */
  832. },
  833. },
  834. [PIX_FMT_YUV422P16BE] = {
  835. .name = "yuv422p16be",
  836. .nb_components= 3,
  837. .log2_chroma_w= 1,
  838. .log2_chroma_h= 0,
  839. .comp = {
  840. {0,1,1,0,15}, /* Y */
  841. {1,1,1,0,15}, /* U */
  842. {2,1,1,0,15}, /* V */
  843. },
  844. .flags = PIX_FMT_BE,
  845. },
  846. [PIX_FMT_YUV444P16LE] = {
  847. .name = "yuv444p16le",
  848. .nb_components= 3,
  849. .log2_chroma_w= 0,
  850. .log2_chroma_h= 0,
  851. .comp = {
  852. {0,1,1,0,15}, /* Y */
  853. {1,1,1,0,15}, /* U */
  854. {2,1,1,0,15}, /* V */
  855. },
  856. },
  857. [PIX_FMT_YUV444P16BE] = {
  858. .name = "yuv444p16be",
  859. .nb_components= 3,
  860. .log2_chroma_w= 0,
  861. .log2_chroma_h= 0,
  862. .comp = {
  863. {0,1,1,0,15}, /* Y */
  864. {1,1,1,0,15}, /* U */
  865. {2,1,1,0,15}, /* V */
  866. },
  867. .flags = PIX_FMT_BE,
  868. },
  869. [PIX_FMT_YUV444P10LE] = {
  870. .name = "yuv444p10le",
  871. .nb_components= 3,
  872. .log2_chroma_w= 0,
  873. .log2_chroma_h= 0,
  874. .comp = {
  875. {0,1,1,0,9}, /* Y */
  876. {1,1,1,0,9}, /* U */
  877. {2,1,1,0,9}, /* V */
  878. },
  879. },
  880. [PIX_FMT_YUV444P10BE] = {
  881. .name = "yuv444p10be",
  882. .nb_components= 3,
  883. .log2_chroma_w= 0,
  884. .log2_chroma_h= 0,
  885. .comp = {
  886. {0,1,1,0,9}, /* Y */
  887. {1,1,1,0,9}, /* U */
  888. {2,1,1,0,9}, /* V */
  889. },
  890. .flags = PIX_FMT_BE,
  891. },
  892. [PIX_FMT_YUV444P9LE] = {
  893. .name = "yuv444p9le",
  894. .nb_components= 3,
  895. .log2_chroma_w= 0,
  896. .log2_chroma_h= 0,
  897. .comp = {
  898. {0,1,1,0,8}, /* Y */
  899. {1,1,1,0,8}, /* U */
  900. {2,1,1,0,8}, /* V */
  901. },
  902. },
  903. [PIX_FMT_YUV444P9BE] = {
  904. .name = "yuv444p9be",
  905. .nb_components= 3,
  906. .log2_chroma_w= 0,
  907. .log2_chroma_h= 0,
  908. .comp = {
  909. {0,1,1,0,8}, /* Y */
  910. {1,1,1,0,8}, /* U */
  911. {2,1,1,0,8}, /* V */
  912. },
  913. .flags = PIX_FMT_BE,
  914. },
  915. [PIX_FMT_DXVA2_VLD] = {
  916. .name = "dxva2_vld",
  917. .log2_chroma_w = 1,
  918. .log2_chroma_h = 1,
  919. .flags = PIX_FMT_HWACCEL,
  920. },
  921. [PIX_FMT_GRAY8A] = {
  922. .name = "gray8a",
  923. .nb_components= 2,
  924. .comp = {
  925. {0,1,1,0,7}, /* Y */
  926. {0,1,2,0,7}, /* A */
  927. },
  928. },
  929. };
  930. static enum PixelFormat get_pix_fmt_internal(const char *name)
  931. {
  932. enum PixelFormat pix_fmt;
  933. for (pix_fmt = 0; pix_fmt < PIX_FMT_NB; pix_fmt++)
  934. if (av_pix_fmt_descriptors[pix_fmt].name &&
  935. !strcmp(av_pix_fmt_descriptors[pix_fmt].name, name))
  936. return pix_fmt;
  937. return PIX_FMT_NONE;
  938. }
  939. const char *av_get_pix_fmt_name(enum PixelFormat pix_fmt)
  940. {
  941. return (unsigned)pix_fmt < PIX_FMT_NB ?
  942. av_pix_fmt_descriptors[pix_fmt].name : NULL;
  943. }
  944. #if HAVE_BIGENDIAN
  945. # define X_NE(be, le) be
  946. #else
  947. # define X_NE(be, le) le
  948. #endif
  949. enum PixelFormat av_get_pix_fmt(const char *name)
  950. {
  951. enum PixelFormat pix_fmt;
  952. if (!strcmp(name, "rgb32"))
  953. name = X_NE("argb", "bgra");
  954. else if (!strcmp(name, "bgr32"))
  955. name = X_NE("abgr", "rgba");
  956. pix_fmt = get_pix_fmt_internal(name);
  957. if (pix_fmt == PIX_FMT_NONE) {
  958. char name2[32];
  959. snprintf(name2, sizeof(name2), "%s%s", name, X_NE("be", "le"));
  960. pix_fmt = get_pix_fmt_internal(name2);
  961. }
  962. return pix_fmt;
  963. }
  964. int av_get_bits_per_pixel(const AVPixFmtDescriptor *pixdesc)
  965. {
  966. int c, bits = 0;
  967. int log2_pixels = pixdesc->log2_chroma_w + pixdesc->log2_chroma_h;
  968. for (c = 0; c < pixdesc->nb_components; c++) {
  969. int s = c==1 || c==2 ? 0 : log2_pixels;
  970. bits += (pixdesc->comp[c].depth_minus1+1) << s;
  971. }
  972. return bits >> log2_pixels;
  973. }
  974. char *av_get_pix_fmt_string (char *buf, int buf_size, enum PixelFormat pix_fmt)
  975. {
  976. /* print header */
  977. if (pix_fmt < 0) {
  978. snprintf (buf, buf_size, "name " " nb_components" " nb_bits");
  979. } else {
  980. const AVPixFmtDescriptor *pixdesc = &av_pix_fmt_descriptors[pix_fmt];
  981. snprintf(buf, buf_size, "%-11s %7d %10d",
  982. pixdesc->name, pixdesc->nb_components, av_get_bits_per_pixel(pixdesc));
  983. }
  984. return buf;
  985. }