convert.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  1. /*
  2. * Copyright 2011 The LibYuv Project Authors. All rights reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef INCLUDE_LIBYUV_CONVERT_H_
  11. #define INCLUDE_LIBYUV_CONVERT_H_
  12. #include "libyuv/basic_types.h"
  13. #include "libyuv/rotate.h" // For enum RotationMode.
  14. // TODO(fbarchard): fix WebRTC source to include following libyuv headers:
  15. #include "libyuv/convert_argb.h" // For WebRTC I420ToARGB. b/620
  16. #include "libyuv/convert_from.h" // For WebRTC ConvertFromI420. b/620
  17. #include "libyuv/planar_functions.h" // For WebRTC I420Rect, CopyPlane. b/618
  18. #ifdef __cplusplus
  19. namespace libyuv {
  20. extern "C" {
  21. #endif
  22. // Convert I444 to I420.
  23. LIBYUV_API
  24. int I444ToI420(const uint8_t* src_y,
  25. int src_stride_y,
  26. const uint8_t* src_u,
  27. int src_stride_u,
  28. const uint8_t* src_v,
  29. int src_stride_v,
  30. uint8_t* dst_y,
  31. int dst_stride_y,
  32. uint8_t* dst_u,
  33. int dst_stride_u,
  34. uint8_t* dst_v,
  35. int dst_stride_v,
  36. int width,
  37. int height);
  38. // Convert I444 to NV21.
  39. LIBYUV_API
  40. int I444ToNV21(const uint8_t* src_y,
  41. int src_stride_y,
  42. const uint8_t* src_u,
  43. int src_stride_u,
  44. const uint8_t* src_v,
  45. int src_stride_v,
  46. uint8_t* dst_y,
  47. int dst_stride_y,
  48. uint8_t* dst_vu,
  49. int dst_stride_vu,
  50. int width,
  51. int height);
  52. // Convert I422 to I420.
  53. LIBYUV_API
  54. int I422ToI420(const uint8_t* src_y,
  55. int src_stride_y,
  56. const uint8_t* src_u,
  57. int src_stride_u,
  58. const uint8_t* src_v,
  59. int src_stride_v,
  60. uint8_t* dst_y,
  61. int dst_stride_y,
  62. uint8_t* dst_u,
  63. int dst_stride_u,
  64. uint8_t* dst_v,
  65. int dst_stride_v,
  66. int width,
  67. int height);
  68. // Convert I422 to NV21.
  69. LIBYUV_API
  70. int I422ToNV21(const uint8_t* src_y,
  71. int src_stride_y,
  72. const uint8_t* src_u,
  73. int src_stride_u,
  74. const uint8_t* src_v,
  75. int src_stride_v,
  76. uint8_t* dst_y,
  77. int dst_stride_y,
  78. uint8_t* dst_vu,
  79. int dst_stride_vu,
  80. int width,
  81. int height);
  82. // Copy I420 to I420.
  83. #define I420ToI420 I420Copy
  84. LIBYUV_API
  85. int I420Copy(const uint8_t* src_y,
  86. int src_stride_y,
  87. const uint8_t* src_u,
  88. int src_stride_u,
  89. const uint8_t* src_v,
  90. int src_stride_v,
  91. uint8_t* dst_y,
  92. int dst_stride_y,
  93. uint8_t* dst_u,
  94. int dst_stride_u,
  95. uint8_t* dst_v,
  96. int dst_stride_v,
  97. int width,
  98. int height);
  99. // Copy I010 to I010
  100. #define I010ToI010 I010Copy
  101. #define H010ToH010 I010Copy
  102. LIBYUV_API
  103. int I010Copy(const uint16_t* src_y,
  104. int src_stride_y,
  105. const uint16_t* src_u,
  106. int src_stride_u,
  107. const uint16_t* src_v,
  108. int src_stride_v,
  109. uint16_t* dst_y,
  110. int dst_stride_y,
  111. uint16_t* dst_u,
  112. int dst_stride_u,
  113. uint16_t* dst_v,
  114. int dst_stride_v,
  115. int width,
  116. int height);
  117. // Convert 10 bit YUV to 8 bit
  118. #define H010ToH420 I010ToI420
  119. LIBYUV_API
  120. int I010ToI420(const uint16_t* src_y,
  121. int src_stride_y,
  122. const uint16_t* src_u,
  123. int src_stride_u,
  124. const uint16_t* src_v,
  125. int src_stride_v,
  126. uint8_t* dst_y,
  127. int dst_stride_y,
  128. uint8_t* dst_u,
  129. int dst_stride_u,
  130. uint8_t* dst_v,
  131. int dst_stride_v,
  132. int width,
  133. int height);
  134. // Convert I400 (grey) to I420.
  135. LIBYUV_API
  136. int I400ToI420(const uint8_t* src_y,
  137. int src_stride_y,
  138. uint8_t* dst_y,
  139. int dst_stride_y,
  140. uint8_t* dst_u,
  141. int dst_stride_u,
  142. uint8_t* dst_v,
  143. int dst_stride_v,
  144. int width,
  145. int height);
  146. // Convert I400 (grey) to NV21.
  147. LIBYUV_API
  148. int I400ToNV21(const uint8_t* src_y,
  149. int src_stride_y,
  150. uint8_t* dst_y,
  151. int dst_stride_y,
  152. uint8_t* dst_vu,
  153. int dst_stride_vu,
  154. int width,
  155. int height);
  156. #define J400ToJ420 I400ToI420
  157. // Convert NV12 to I420.
  158. LIBYUV_API
  159. int NV12ToI420(const uint8_t* src_y,
  160. int src_stride_y,
  161. const uint8_t* src_uv,
  162. int src_stride_uv,
  163. uint8_t* dst_y,
  164. int dst_stride_y,
  165. uint8_t* dst_u,
  166. int dst_stride_u,
  167. uint8_t* dst_v,
  168. int dst_stride_v,
  169. int width,
  170. int height);
  171. // Convert NV21 to I420.
  172. LIBYUV_API
  173. int NV21ToI420(const uint8_t* src_y,
  174. int src_stride_y,
  175. const uint8_t* src_vu,
  176. int src_stride_vu,
  177. uint8_t* dst_y,
  178. int dst_stride_y,
  179. uint8_t* dst_u,
  180. int dst_stride_u,
  181. uint8_t* dst_v,
  182. int dst_stride_v,
  183. int width,
  184. int height);
  185. // Convert YUY2 to I420.
  186. LIBYUV_API
  187. int YUY2ToI420(const uint8_t* src_yuy2,
  188. int src_stride_yuy2,
  189. uint8_t* dst_y,
  190. int dst_stride_y,
  191. uint8_t* dst_u,
  192. int dst_stride_u,
  193. uint8_t* dst_v,
  194. int dst_stride_v,
  195. int width,
  196. int height);
  197. // Convert UYVY to I420.
  198. LIBYUV_API
  199. int UYVYToI420(const uint8_t* src_uyvy,
  200. int src_stride_uyvy,
  201. uint8_t* dst_y,
  202. int dst_stride_y,
  203. uint8_t* dst_u,
  204. int dst_stride_u,
  205. uint8_t* dst_v,
  206. int dst_stride_v,
  207. int width,
  208. int height);
  209. // Convert AYUV to NV12.
  210. LIBYUV_API
  211. int AYUVToNV12(const uint8_t* src_ayuv,
  212. int src_stride_ayuv,
  213. uint8_t* dst_y,
  214. int dst_stride_y,
  215. uint8_t* dst_uv,
  216. int dst_stride_uv,
  217. int width,
  218. int height);
  219. // Convert AYUV to NV21.
  220. LIBYUV_API
  221. int AYUVToNV21(const uint8_t* src_ayuv,
  222. int src_stride_ayuv,
  223. uint8_t* dst_y,
  224. int dst_stride_y,
  225. uint8_t* dst_vu,
  226. int dst_stride_vu,
  227. int width,
  228. int height);
  229. // Convert M420 to I420.
  230. LIBYUV_API
  231. int M420ToI420(const uint8_t* src_m420,
  232. int src_stride_m420,
  233. uint8_t* dst_y,
  234. int dst_stride_y,
  235. uint8_t* dst_u,
  236. int dst_stride_u,
  237. uint8_t* dst_v,
  238. int dst_stride_v,
  239. int width,
  240. int height);
  241. // Convert Android420 to I420.
  242. LIBYUV_API
  243. int Android420ToI420(const uint8_t* src_y,
  244. int src_stride_y,
  245. const uint8_t* src_u,
  246. int src_stride_u,
  247. const uint8_t* src_v,
  248. int src_stride_v,
  249. int src_pixel_stride_uv,
  250. uint8_t* dst_y,
  251. int dst_stride_y,
  252. uint8_t* dst_u,
  253. int dst_stride_u,
  254. uint8_t* dst_v,
  255. int dst_stride_v,
  256. int width,
  257. int height);
  258. // ARGB little endian (bgra in memory) to I420.
  259. LIBYUV_API
  260. int ARGBToI420(const uint8_t* src_argb,
  261. int src_stride_argb,
  262. uint8_t* dst_y,
  263. int dst_stride_y,
  264. uint8_t* dst_u,
  265. int dst_stride_u,
  266. uint8_t* dst_v,
  267. int dst_stride_v,
  268. int width,
  269. int height);
  270. // BGRA little endian (argb in memory) to I420.
  271. LIBYUV_API
  272. int BGRAToI420(const uint8_t* src_bgra,
  273. int src_stride_bgra,
  274. uint8_t* dst_y,
  275. int dst_stride_y,
  276. uint8_t* dst_u,
  277. int dst_stride_u,
  278. uint8_t* dst_v,
  279. int dst_stride_v,
  280. int width,
  281. int height);
  282. // ABGR little endian (rgba in memory) to I420.
  283. LIBYUV_API
  284. int ABGRToI420(const uint8_t* src_abgr,
  285. int src_stride_abgr,
  286. uint8_t* dst_y,
  287. int dst_stride_y,
  288. uint8_t* dst_u,
  289. int dst_stride_u,
  290. uint8_t* dst_v,
  291. int dst_stride_v,
  292. int width,
  293. int height);
  294. // RGBA little endian (abgr in memory) to I420.
  295. LIBYUV_API
  296. int RGBAToI420(const uint8_t* src_rgba,
  297. int src_stride_rgba,
  298. uint8_t* dst_y,
  299. int dst_stride_y,
  300. uint8_t* dst_u,
  301. int dst_stride_u,
  302. uint8_t* dst_v,
  303. int dst_stride_v,
  304. int width,
  305. int height);
  306. // RGB little endian (bgr in memory) to I420.
  307. LIBYUV_API
  308. int RGB24ToI420(const uint8_t* src_rgb24,
  309. int src_stride_rgb24,
  310. uint8_t* dst_y,
  311. int dst_stride_y,
  312. uint8_t* dst_u,
  313. int dst_stride_u,
  314. uint8_t* dst_v,
  315. int dst_stride_v,
  316. int width,
  317. int height);
  318. // RGB little endian (bgr in memory) to J420.
  319. LIBYUV_API
  320. int RGB24ToJ420(const uint8_t* src_rgb24,
  321. int src_stride_rgb24,
  322. uint8_t* dst_y,
  323. int dst_stride_y,
  324. uint8_t* dst_u,
  325. int dst_stride_u,
  326. uint8_t* dst_v,
  327. int dst_stride_v,
  328. int width,
  329. int height);
  330. // RGB big endian (rgb in memory) to I420.
  331. LIBYUV_API
  332. int RAWToI420(const uint8_t* src_raw,
  333. int src_stride_raw,
  334. uint8_t* dst_y,
  335. int dst_stride_y,
  336. uint8_t* dst_u,
  337. int dst_stride_u,
  338. uint8_t* dst_v,
  339. int dst_stride_v,
  340. int width,
  341. int height);
  342. // RGB16 (RGBP fourcc) little endian to I420.
  343. LIBYUV_API
  344. int RGB565ToI420(const uint8_t* src_rgb565,
  345. int src_stride_rgb565,
  346. uint8_t* dst_y,
  347. int dst_stride_y,
  348. uint8_t* dst_u,
  349. int dst_stride_u,
  350. uint8_t* dst_v,
  351. int dst_stride_v,
  352. int width,
  353. int height);
  354. // RGB15 (RGBO fourcc) little endian to I420.
  355. LIBYUV_API
  356. int ARGB1555ToI420(const uint8_t* src_argb1555,
  357. int src_stride_argb1555,
  358. uint8_t* dst_y,
  359. int dst_stride_y,
  360. uint8_t* dst_u,
  361. int dst_stride_u,
  362. uint8_t* dst_v,
  363. int dst_stride_v,
  364. int width,
  365. int height);
  366. // RGB12 (R444 fourcc) little endian to I420.
  367. LIBYUV_API
  368. int ARGB4444ToI420(const uint8_t* src_argb4444,
  369. int src_stride_argb4444,
  370. uint8_t* dst_y,
  371. int dst_stride_y,
  372. uint8_t* dst_u,
  373. int dst_stride_u,
  374. uint8_t* dst_v,
  375. int dst_stride_v,
  376. int width,
  377. int height);
  378. // RGB little endian (bgr in memory) to J400.
  379. LIBYUV_API
  380. int RGB24ToJ400(const uint8_t* src_rgb24,
  381. int src_stride_rgb24,
  382. uint8_t* dst_yj,
  383. int dst_stride_yj,
  384. int width,
  385. int height);
  386. // RGB big endian (rgb in memory) to J400.
  387. LIBYUV_API
  388. int RAWToJ400(const uint8_t* src_raw,
  389. int src_stride_raw,
  390. uint8_t* dst_yj,
  391. int dst_stride_yj,
  392. int width,
  393. int height);
  394. #ifdef HAVE_JPEG
  395. // src_width/height provided by capture.
  396. // dst_width/height for clipping determine final size.
  397. LIBYUV_API
  398. int MJPGToI420(const uint8_t* sample,
  399. size_t sample_size,
  400. uint8_t* dst_y,
  401. int dst_stride_y,
  402. uint8_t* dst_u,
  403. int dst_stride_u,
  404. uint8_t* dst_v,
  405. int dst_stride_v,
  406. int src_width,
  407. int src_height,
  408. int dst_width,
  409. int dst_height);
  410. // JPEG to NV21
  411. LIBYUV_API
  412. int MJPGToNV21(const uint8_t* sample,
  413. size_t sample_size,
  414. uint8_t* dst_y,
  415. int dst_stride_y,
  416. uint8_t* dst_vu,
  417. int dst_stride_vu,
  418. int src_width,
  419. int src_height,
  420. int dst_width,
  421. int dst_height);
  422. // Query size of MJPG in pixels.
  423. LIBYUV_API
  424. int MJPGSize(const uint8_t* sample,
  425. size_t sample_size,
  426. int* width,
  427. int* height);
  428. #endif
  429. // Convert camera sample to I420 with cropping, rotation and vertical flip.
  430. // "src_size" is needed to parse MJPG.
  431. // "dst_stride_y" number of bytes in a row of the dst_y plane.
  432. // Normally this would be the same as dst_width, with recommended alignment
  433. // to 16 bytes for better efficiency.
  434. // If rotation of 90 or 270 is used, stride is affected. The caller should
  435. // allocate the I420 buffer according to rotation.
  436. // "dst_stride_u" number of bytes in a row of the dst_u plane.
  437. // Normally this would be the same as (dst_width + 1) / 2, with
  438. // recommended alignment to 16 bytes for better efficiency.
  439. // If rotation of 90 or 270 is used, stride is affected.
  440. // "crop_x" and "crop_y" are starting position for cropping.
  441. // To center, crop_x = (src_width - dst_width) / 2
  442. // crop_y = (src_height - dst_height) / 2
  443. // "src_width" / "src_height" is size of src_frame in pixels.
  444. // "src_height" can be negative indicating a vertically flipped image source.
  445. // "crop_width" / "crop_height" is the size to crop the src to.
  446. // Must be less than or equal to src_width/src_height
  447. // Cropping parameters are pre-rotation.
  448. // "rotation" can be 0, 90, 180 or 270.
  449. // "fourcc" is a fourcc. ie 'I420', 'YUY2'
  450. // Returns 0 for successful; -1 for invalid parameter. Non-zero for failure.
  451. LIBYUV_API
  452. int ConvertToI420(const uint8_t* sample,
  453. size_t sample_size,
  454. uint8_t* dst_y,
  455. int dst_stride_y,
  456. uint8_t* dst_u,
  457. int dst_stride_u,
  458. uint8_t* dst_v,
  459. int dst_stride_v,
  460. int crop_x,
  461. int crop_y,
  462. int src_width,
  463. int src_height,
  464. int crop_width,
  465. int crop_height,
  466. enum RotationMode rotation,
  467. uint32_t fourcc);
  468. #ifdef __cplusplus
  469. } // extern "C"
  470. } // namespace libyuv
  471. #endif
  472. #endif // INCLUDE_LIBYUV_CONVERT_H_