convert.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  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* src_y,
  25. int src_stride_y,
  26. const uint8* src_u,
  27. int src_stride_u,
  28. const uint8* src_v,
  29. int src_stride_v,
  30. uint8* dst_y,
  31. int dst_stride_y,
  32. uint8* dst_u,
  33. int dst_stride_u,
  34. uint8* dst_v,
  35. int dst_stride_v,
  36. int width,
  37. int height);
  38. // Convert I422 to I420.
  39. LIBYUV_API
  40. int I422ToI420(const uint8* src_y,
  41. int src_stride_y,
  42. const uint8* src_u,
  43. int src_stride_u,
  44. const uint8* src_v,
  45. int src_stride_v,
  46. uint8* dst_y,
  47. int dst_stride_y,
  48. uint8* dst_u,
  49. int dst_stride_u,
  50. uint8* dst_v,
  51. int dst_stride_v,
  52. int width,
  53. int height);
  54. // Copy I420 to I420.
  55. #define I420ToI420 I420Copy
  56. LIBYUV_API
  57. int I420Copy(const uint8* src_y,
  58. int src_stride_y,
  59. const uint8* src_u,
  60. int src_stride_u,
  61. const uint8* src_v,
  62. int src_stride_v,
  63. uint8* dst_y,
  64. int dst_stride_y,
  65. uint8* dst_u,
  66. int dst_stride_u,
  67. uint8* dst_v,
  68. int dst_stride_v,
  69. int width,
  70. int height);
  71. // Convert I400 (grey) to I420.
  72. LIBYUV_API
  73. int I400ToI420(const uint8* src_y,
  74. int src_stride_y,
  75. uint8* dst_y,
  76. int dst_stride_y,
  77. uint8* dst_u,
  78. int dst_stride_u,
  79. uint8* dst_v,
  80. int dst_stride_v,
  81. int width,
  82. int height);
  83. #define J400ToJ420 I400ToI420
  84. // Convert NV12 to I420.
  85. LIBYUV_API
  86. int NV12ToI420(const uint8* src_y,
  87. int src_stride_y,
  88. const uint8* src_uv,
  89. int src_stride_uv,
  90. uint8* dst_y,
  91. int dst_stride_y,
  92. uint8* dst_u,
  93. int dst_stride_u,
  94. uint8* dst_v,
  95. int dst_stride_v,
  96. int width,
  97. int height);
  98. // Convert NV21 to I420.
  99. LIBYUV_API
  100. int NV21ToI420(const uint8* src_y,
  101. int src_stride_y,
  102. const uint8* src_vu,
  103. int src_stride_vu,
  104. uint8* dst_y,
  105. int dst_stride_y,
  106. uint8* dst_u,
  107. int dst_stride_u,
  108. uint8* dst_v,
  109. int dst_stride_v,
  110. int width,
  111. int height);
  112. // Convert YUY2 to I420.
  113. LIBYUV_API
  114. int YUY2ToI420(const uint8* src_yuy2,
  115. int src_stride_yuy2,
  116. uint8* dst_y,
  117. int dst_stride_y,
  118. uint8* dst_u,
  119. int dst_stride_u,
  120. uint8* dst_v,
  121. int dst_stride_v,
  122. int width,
  123. int height);
  124. // Convert UYVY to I420.
  125. LIBYUV_API
  126. int UYVYToI420(const uint8* src_uyvy,
  127. int src_stride_uyvy,
  128. uint8* dst_y,
  129. int dst_stride_y,
  130. uint8* dst_u,
  131. int dst_stride_u,
  132. uint8* dst_v,
  133. int dst_stride_v,
  134. int width,
  135. int height);
  136. // Convert M420 to I420.
  137. LIBYUV_API
  138. int M420ToI420(const uint8* src_m420,
  139. int src_stride_m420,
  140. uint8* dst_y,
  141. int dst_stride_y,
  142. uint8* dst_u,
  143. int dst_stride_u,
  144. uint8* dst_v,
  145. int dst_stride_v,
  146. int width,
  147. int height);
  148. // Convert Android420 to I420.
  149. LIBYUV_API
  150. int Android420ToI420(const uint8* src_y,
  151. int src_stride_y,
  152. const uint8* src_u,
  153. int src_stride_u,
  154. const uint8* src_v,
  155. int src_stride_v,
  156. int pixel_stride_uv,
  157. uint8* dst_y,
  158. int dst_stride_y,
  159. uint8* dst_u,
  160. int dst_stride_u,
  161. uint8* dst_v,
  162. int dst_stride_v,
  163. int width,
  164. int height);
  165. // ARGB little endian (bgra in memory) to I420.
  166. LIBYUV_API
  167. int ARGBToI420(const uint8* src_frame,
  168. int src_stride_frame,
  169. uint8* dst_y,
  170. int dst_stride_y,
  171. uint8* dst_u,
  172. int dst_stride_u,
  173. uint8* dst_v,
  174. int dst_stride_v,
  175. int width,
  176. int height);
  177. // BGRA little endian (argb in memory) to I420.
  178. LIBYUV_API
  179. int BGRAToI420(const uint8* src_frame,
  180. int src_stride_frame,
  181. uint8* dst_y,
  182. int dst_stride_y,
  183. uint8* dst_u,
  184. int dst_stride_u,
  185. uint8* dst_v,
  186. int dst_stride_v,
  187. int width,
  188. int height);
  189. // ABGR little endian (rgba in memory) to I420.
  190. LIBYUV_API
  191. int ABGRToI420(const uint8* src_frame,
  192. int src_stride_frame,
  193. uint8* dst_y,
  194. int dst_stride_y,
  195. uint8* dst_u,
  196. int dst_stride_u,
  197. uint8* dst_v,
  198. int dst_stride_v,
  199. int width,
  200. int height);
  201. // RGBA little endian (abgr in memory) to I420.
  202. LIBYUV_API
  203. int RGBAToI420(const uint8* src_frame,
  204. int src_stride_frame,
  205. uint8* dst_y,
  206. int dst_stride_y,
  207. uint8* dst_u,
  208. int dst_stride_u,
  209. uint8* dst_v,
  210. int dst_stride_v,
  211. int width,
  212. int height);
  213. // RGB little endian (bgr in memory) to I420.
  214. LIBYUV_API
  215. int RGB24ToI420(const uint8* src_frame,
  216. int src_stride_frame,
  217. uint8* dst_y,
  218. int dst_stride_y,
  219. uint8* dst_u,
  220. int dst_stride_u,
  221. uint8* dst_v,
  222. int dst_stride_v,
  223. int width,
  224. int height);
  225. // RGB big endian (rgb in memory) to I420.
  226. LIBYUV_API
  227. int RAWToI420(const uint8* src_frame,
  228. int src_stride_frame,
  229. uint8* dst_y,
  230. int dst_stride_y,
  231. uint8* dst_u,
  232. int dst_stride_u,
  233. uint8* dst_v,
  234. int dst_stride_v,
  235. int width,
  236. int height);
  237. // RGB16 (RGBP fourcc) little endian to I420.
  238. LIBYUV_API
  239. int RGB565ToI420(const uint8* src_frame,
  240. int src_stride_frame,
  241. uint8* dst_y,
  242. int dst_stride_y,
  243. uint8* dst_u,
  244. int dst_stride_u,
  245. uint8* dst_v,
  246. int dst_stride_v,
  247. int width,
  248. int height);
  249. // RGB15 (RGBO fourcc) little endian to I420.
  250. LIBYUV_API
  251. int ARGB1555ToI420(const uint8* src_frame,
  252. int src_stride_frame,
  253. uint8* dst_y,
  254. int dst_stride_y,
  255. uint8* dst_u,
  256. int dst_stride_u,
  257. uint8* dst_v,
  258. int dst_stride_v,
  259. int width,
  260. int height);
  261. // RGB12 (R444 fourcc) little endian to I420.
  262. LIBYUV_API
  263. int ARGB4444ToI420(const uint8* src_frame,
  264. int src_stride_frame,
  265. uint8* dst_y,
  266. int dst_stride_y,
  267. uint8* dst_u,
  268. int dst_stride_u,
  269. uint8* dst_v,
  270. int dst_stride_v,
  271. int width,
  272. int height);
  273. #ifdef HAVE_JPEG
  274. // src_width/height provided by capture.
  275. // dst_width/height for clipping determine final size.
  276. LIBYUV_API
  277. int MJPGToI420(const uint8* sample,
  278. size_t sample_size,
  279. uint8* dst_y,
  280. int dst_stride_y,
  281. uint8* dst_u,
  282. int dst_stride_u,
  283. uint8* dst_v,
  284. int dst_stride_v,
  285. int src_width,
  286. int src_height,
  287. int dst_width,
  288. int dst_height);
  289. // Query size of MJPG in pixels.
  290. LIBYUV_API
  291. int MJPGSize(const uint8* sample, size_t sample_size, int* width, int* height);
  292. #endif
  293. // Convert camera sample to I420 with cropping, rotation and vertical flip.
  294. // "src_size" is needed to parse MJPG.
  295. // "dst_stride_y" number of bytes in a row of the dst_y plane.
  296. // Normally this would be the same as dst_width, with recommended alignment
  297. // to 16 bytes for better efficiency.
  298. // If rotation of 90 or 270 is used, stride is affected. The caller should
  299. // allocate the I420 buffer according to rotation.
  300. // "dst_stride_u" number of bytes in a row of the dst_u plane.
  301. // Normally this would be the same as (dst_width + 1) / 2, with
  302. // recommended alignment to 16 bytes for better efficiency.
  303. // If rotation of 90 or 270 is used, stride is affected.
  304. // "crop_x" and "crop_y" are starting position for cropping.
  305. // To center, crop_x = (src_width - dst_width) / 2
  306. // crop_y = (src_height - dst_height) / 2
  307. // "src_width" / "src_height" is size of src_frame in pixels.
  308. // "src_height" can be negative indicating a vertically flipped image source.
  309. // "crop_width" / "crop_height" is the size to crop the src to.
  310. // Must be less than or equal to src_width/src_height
  311. // Cropping parameters are pre-rotation.
  312. // "rotation" can be 0, 90, 180 or 270.
  313. // "format" is a fourcc. ie 'I420', 'YUY2'
  314. // Returns 0 for successful; -1 for invalid parameter. Non-zero for failure.
  315. LIBYUV_API
  316. int ConvertToI420(const uint8* src_frame,
  317. size_t src_size,
  318. uint8* dst_y,
  319. int dst_stride_y,
  320. uint8* dst_u,
  321. int dst_stride_u,
  322. uint8* dst_v,
  323. int dst_stride_v,
  324. int crop_x,
  325. int crop_y,
  326. int src_width,
  327. int src_height,
  328. int crop_width,
  329. int crop_height,
  330. enum RotationMode rotation,
  331. uint32 format);
  332. #ifdef __cplusplus
  333. } // extern "C"
  334. } // namespace libyuv
  335. #endif
  336. #endif // INCLUDE_LIBYUV_CONVERT_H_