convert_argb.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. /*
  2. * Copyright 2012 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_ARGB_H_
  11. #define INCLUDE_LIBYUV_CONVERT_ARGB_H_
  12. #include "libyuv/basic_types.h"
  13. #include "libyuv/rotate.h" // For enum RotationMode.
  14. // TODO(fbarchard): This set of functions should exactly match convert.h
  15. // TODO(fbarchard): Add tests. Create random content of right size and convert
  16. // with C vs Opt and or to I420 and compare.
  17. // TODO(fbarchard): Some of these functions lack parameter setting.
  18. #ifdef __cplusplus
  19. namespace libyuv {
  20. extern "C" {
  21. #endif
  22. // Alias.
  23. #define ARGBToARGB ARGBCopy
  24. // Copy ARGB to ARGB.
  25. LIBYUV_API
  26. int ARGBCopy(const uint8* src_argb,
  27. int src_stride_argb,
  28. uint8* dst_argb,
  29. int dst_stride_argb,
  30. int width,
  31. int height);
  32. // Convert I420 to ARGB.
  33. LIBYUV_API
  34. int I420ToARGB(const uint8* src_y,
  35. int src_stride_y,
  36. const uint8* src_u,
  37. int src_stride_u,
  38. const uint8* src_v,
  39. int src_stride_v,
  40. uint8* dst_argb,
  41. int dst_stride_argb,
  42. int width,
  43. int height);
  44. // Duplicate prototype for function in convert_from.h for remoting.
  45. LIBYUV_API
  46. int I420ToABGR(const uint8* src_y,
  47. int src_stride_y,
  48. const uint8* src_u,
  49. int src_stride_u,
  50. const uint8* src_v,
  51. int src_stride_v,
  52. uint8* dst_argb,
  53. int dst_stride_argb,
  54. int width,
  55. int height);
  56. // Convert I422 to ARGB.
  57. LIBYUV_API
  58. int I422ToARGB(const uint8* src_y,
  59. int src_stride_y,
  60. const uint8* src_u,
  61. int src_stride_u,
  62. const uint8* src_v,
  63. int src_stride_v,
  64. uint8* dst_argb,
  65. int dst_stride_argb,
  66. int width,
  67. int height);
  68. // Convert I444 to ARGB.
  69. LIBYUV_API
  70. int I444ToARGB(const uint8* src_y,
  71. int src_stride_y,
  72. const uint8* src_u,
  73. int src_stride_u,
  74. const uint8* src_v,
  75. int src_stride_v,
  76. uint8* dst_argb,
  77. int dst_stride_argb,
  78. int width,
  79. int height);
  80. // Convert J444 to ARGB.
  81. LIBYUV_API
  82. int J444ToARGB(const uint8* src_y,
  83. int src_stride_y,
  84. const uint8* src_u,
  85. int src_stride_u,
  86. const uint8* src_v,
  87. int src_stride_v,
  88. uint8* dst_argb,
  89. int dst_stride_argb,
  90. int width,
  91. int height);
  92. // Convert I444 to ABGR.
  93. LIBYUV_API
  94. int I444ToABGR(const uint8* src_y,
  95. int src_stride_y,
  96. const uint8* src_u,
  97. int src_stride_u,
  98. const uint8* src_v,
  99. int src_stride_v,
  100. uint8* dst_abgr,
  101. int dst_stride_abgr,
  102. int width,
  103. int height);
  104. // Convert I420 with Alpha to preattenuated ARGB.
  105. LIBYUV_API
  106. int I420AlphaToARGB(const uint8* src_y,
  107. int src_stride_y,
  108. const uint8* src_u,
  109. int src_stride_u,
  110. const uint8* src_v,
  111. int src_stride_v,
  112. const uint8* src_a,
  113. int src_stride_a,
  114. uint8* dst_argb,
  115. int dst_stride_argb,
  116. int width,
  117. int height,
  118. int attenuate);
  119. // Convert I420 with Alpha to preattenuated ABGR.
  120. LIBYUV_API
  121. int I420AlphaToABGR(const uint8* src_y,
  122. int src_stride_y,
  123. const uint8* src_u,
  124. int src_stride_u,
  125. const uint8* src_v,
  126. int src_stride_v,
  127. const uint8* src_a,
  128. int src_stride_a,
  129. uint8* dst_abgr,
  130. int dst_stride_abgr,
  131. int width,
  132. int height,
  133. int attenuate);
  134. // Convert I400 (grey) to ARGB. Reverse of ARGBToI400.
  135. LIBYUV_API
  136. int I400ToARGB(const uint8* src_y,
  137. int src_stride_y,
  138. uint8* dst_argb,
  139. int dst_stride_argb,
  140. int width,
  141. int height);
  142. // Convert J400 (jpeg grey) to ARGB.
  143. LIBYUV_API
  144. int J400ToARGB(const uint8* src_y,
  145. int src_stride_y,
  146. uint8* dst_argb,
  147. int dst_stride_argb,
  148. int width,
  149. int height);
  150. // Alias.
  151. #define YToARGB I400ToARGB
  152. // Convert NV12 to ARGB.
  153. LIBYUV_API
  154. int NV12ToARGB(const uint8* src_y,
  155. int src_stride_y,
  156. const uint8* src_uv,
  157. int src_stride_uv,
  158. uint8* dst_argb,
  159. int dst_stride_argb,
  160. int width,
  161. int height);
  162. // Convert NV21 to ARGB.
  163. LIBYUV_API
  164. int NV21ToARGB(const uint8* src_y,
  165. int src_stride_y,
  166. const uint8* src_vu,
  167. int src_stride_vu,
  168. uint8* dst_argb,
  169. int dst_stride_argb,
  170. int width,
  171. int height);
  172. // Convert M420 to ARGB.
  173. LIBYUV_API
  174. int M420ToARGB(const uint8* src_m420,
  175. int src_stride_m420,
  176. uint8* dst_argb,
  177. int dst_stride_argb,
  178. int width,
  179. int height);
  180. // Convert YUY2 to ARGB.
  181. LIBYUV_API
  182. int YUY2ToARGB(const uint8* src_yuy2,
  183. int src_stride_yuy2,
  184. uint8* dst_argb,
  185. int dst_stride_argb,
  186. int width,
  187. int height);
  188. // Convert UYVY to ARGB.
  189. LIBYUV_API
  190. int UYVYToARGB(const uint8* src_uyvy,
  191. int src_stride_uyvy,
  192. uint8* dst_argb,
  193. int dst_stride_argb,
  194. int width,
  195. int height);
  196. // Convert J420 to ARGB.
  197. LIBYUV_API
  198. int J420ToARGB(const uint8* src_y,
  199. int src_stride_y,
  200. const uint8* src_u,
  201. int src_stride_u,
  202. const uint8* src_v,
  203. int src_stride_v,
  204. uint8* dst_argb,
  205. int dst_stride_argb,
  206. int width,
  207. int height);
  208. // Convert J422 to ARGB.
  209. LIBYUV_API
  210. int J422ToARGB(const uint8* src_y,
  211. int src_stride_y,
  212. const uint8* src_u,
  213. int src_stride_u,
  214. const uint8* src_v,
  215. int src_stride_v,
  216. uint8* dst_argb,
  217. int dst_stride_argb,
  218. int width,
  219. int height);
  220. // Convert J420 to ABGR.
  221. LIBYUV_API
  222. int J420ToABGR(const uint8* src_y,
  223. int src_stride_y,
  224. const uint8* src_u,
  225. int src_stride_u,
  226. const uint8* src_v,
  227. int src_stride_v,
  228. uint8* dst_abgr,
  229. int dst_stride_abgr,
  230. int width,
  231. int height);
  232. // Convert J422 to ABGR.
  233. LIBYUV_API
  234. int J422ToABGR(const uint8* src_y,
  235. int src_stride_y,
  236. const uint8* src_u,
  237. int src_stride_u,
  238. const uint8* src_v,
  239. int src_stride_v,
  240. uint8* dst_abgr,
  241. int dst_stride_abgr,
  242. int width,
  243. int height);
  244. // Convert H420 to ARGB.
  245. LIBYUV_API
  246. int H420ToARGB(const uint8* src_y,
  247. int src_stride_y,
  248. const uint8* src_u,
  249. int src_stride_u,
  250. const uint8* src_v,
  251. int src_stride_v,
  252. uint8* dst_argb,
  253. int dst_stride_argb,
  254. int width,
  255. int height);
  256. // Convert H422 to ARGB.
  257. LIBYUV_API
  258. int H422ToARGB(const uint8* src_y,
  259. int src_stride_y,
  260. const uint8* src_u,
  261. int src_stride_u,
  262. const uint8* src_v,
  263. int src_stride_v,
  264. uint8* dst_argb,
  265. int dst_stride_argb,
  266. int width,
  267. int height);
  268. // Convert H420 to ABGR.
  269. LIBYUV_API
  270. int H420ToABGR(const uint8* src_y,
  271. int src_stride_y,
  272. const uint8* src_u,
  273. int src_stride_u,
  274. const uint8* src_v,
  275. int src_stride_v,
  276. uint8* dst_abgr,
  277. int dst_stride_abgr,
  278. int width,
  279. int height);
  280. // Convert H422 to ABGR.
  281. LIBYUV_API
  282. int H422ToABGR(const uint8* src_y,
  283. int src_stride_y,
  284. const uint8* src_u,
  285. int src_stride_u,
  286. const uint8* src_v,
  287. int src_stride_v,
  288. uint8* dst_abgr,
  289. int dst_stride_abgr,
  290. int width,
  291. int height);
  292. // BGRA little endian (argb in memory) to ARGB.
  293. LIBYUV_API
  294. int BGRAToARGB(const uint8* src_frame,
  295. int src_stride_frame,
  296. uint8* dst_argb,
  297. int dst_stride_argb,
  298. int width,
  299. int height);
  300. // ABGR little endian (rgba in memory) to ARGB.
  301. LIBYUV_API
  302. int ABGRToARGB(const uint8* src_frame,
  303. int src_stride_frame,
  304. uint8* dst_argb,
  305. int dst_stride_argb,
  306. int width,
  307. int height);
  308. // RGBA little endian (abgr in memory) to ARGB.
  309. LIBYUV_API
  310. int RGBAToARGB(const uint8* src_frame,
  311. int src_stride_frame,
  312. uint8* dst_argb,
  313. int dst_stride_argb,
  314. int width,
  315. int height);
  316. // Deprecated function name.
  317. #define BG24ToARGB RGB24ToARGB
  318. // RGB little endian (bgr in memory) to ARGB.
  319. LIBYUV_API
  320. int RGB24ToARGB(const uint8* src_frame,
  321. int src_stride_frame,
  322. uint8* dst_argb,
  323. int dst_stride_argb,
  324. int width,
  325. int height);
  326. // RGB big endian (rgb in memory) to ARGB.
  327. LIBYUV_API
  328. int RAWToARGB(const uint8* src_frame,
  329. int src_stride_frame,
  330. uint8* dst_argb,
  331. int dst_stride_argb,
  332. int width,
  333. int height);
  334. // RGB16 (RGBP fourcc) little endian to ARGB.
  335. LIBYUV_API
  336. int RGB565ToARGB(const uint8* src_frame,
  337. int src_stride_frame,
  338. uint8* dst_argb,
  339. int dst_stride_argb,
  340. int width,
  341. int height);
  342. // RGB15 (RGBO fourcc) little endian to ARGB.
  343. LIBYUV_API
  344. int ARGB1555ToARGB(const uint8* src_frame,
  345. int src_stride_frame,
  346. uint8* dst_argb,
  347. int dst_stride_argb,
  348. int width,
  349. int height);
  350. // RGB12 (R444 fourcc) little endian to ARGB.
  351. LIBYUV_API
  352. int ARGB4444ToARGB(const uint8* src_frame,
  353. int src_stride_frame,
  354. uint8* dst_argb,
  355. int dst_stride_argb,
  356. int width,
  357. int height);
  358. #ifdef HAVE_JPEG
  359. // src_width/height provided by capture
  360. // dst_width/height for clipping determine final size.
  361. LIBYUV_API
  362. int MJPGToARGB(const uint8* sample,
  363. size_t sample_size,
  364. uint8* dst_argb,
  365. int dst_stride_argb,
  366. int src_width,
  367. int src_height,
  368. int dst_width,
  369. int dst_height);
  370. #endif
  371. // Convert camera sample to ARGB with cropping, rotation and vertical flip.
  372. // "src_size" is needed to parse MJPG.
  373. // "dst_stride_argb" number of bytes in a row of the dst_argb plane.
  374. // Normally this would be the same as dst_width, with recommended alignment
  375. // to 16 bytes for better efficiency.
  376. // If rotation of 90 or 270 is used, stride is affected. The caller should
  377. // allocate the I420 buffer according to rotation.
  378. // "dst_stride_u" number of bytes in a row of the dst_u plane.
  379. // Normally this would be the same as (dst_width + 1) / 2, with
  380. // recommended alignment to 16 bytes for better efficiency.
  381. // If rotation of 90 or 270 is used, stride is affected.
  382. // "crop_x" and "crop_y" are starting position for cropping.
  383. // To center, crop_x = (src_width - dst_width) / 2
  384. // crop_y = (src_height - dst_height) / 2
  385. // "src_width" / "src_height" is size of src_frame in pixels.
  386. // "src_height" can be negative indicating a vertically flipped image source.
  387. // "crop_width" / "crop_height" is the size to crop the src to.
  388. // Must be less than or equal to src_width/src_height
  389. // Cropping parameters are pre-rotation.
  390. // "rotation" can be 0, 90, 180 or 270.
  391. // "format" is a fourcc. ie 'I420', 'YUY2'
  392. // Returns 0 for successful; -1 for invalid parameter. Non-zero for failure.
  393. LIBYUV_API
  394. int ConvertToARGB(const uint8* src_frame,
  395. size_t src_size,
  396. uint8* dst_argb,
  397. int dst_stride_argb,
  398. int crop_x,
  399. int crop_y,
  400. int src_width,
  401. int src_height,
  402. int crop_width,
  403. int crop_height,
  404. enum RotationMode rotation,
  405. uint32 format);
  406. #ifdef __cplusplus
  407. } // extern "C"
  408. } // namespace libyuv
  409. #endif
  410. #endif // INCLUDE_LIBYUV_CONVERT_ARGB_H_