convert_argb.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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_ // NOLINT
  11. #define INCLUDE_LIBYUV_CONVERT_ARGB_H_
  12. #include "basic_types.h"
  13. // TODO(fbarchard): Remove the following headers includes
  14. #include "convert_from.h"
  15. #include "planar_functions.h"
  16. #include "rotate.h"
  17. // TODO(fbarchard): This set of functions should exactly match convert.h
  18. // TODO(fbarchard): Add tests. Create random content of right size and convert
  19. // with C vs Opt and or to I420 and compare.
  20. // TODO(fbarchard): Some of these functions lack parameter setting.
  21. #ifdef __cplusplus
  22. namespace libyuv {
  23. extern "C" {
  24. #endif
  25. // Alias.
  26. #define ARGBToARGB ARGBCopy
  27. // Copy ARGB to ARGB.
  28. LIBYUV_API
  29. int ARGBCopy(const uint8* src_argb, int src_stride_argb,
  30. uint8* dst_argb, int dst_stride_argb,
  31. int width, int height);
  32. // Convert I420 to ARGB.
  33. LIBYUV_API
  34. int I420ToARGB(const uint8* src_y, int src_stride_y,
  35. const uint8* src_u, int src_stride_u,
  36. const uint8* src_v, int src_stride_v,
  37. uint8* dst_argb, int dst_stride_argb,
  38. int width, int height);
  39. // Convert I422 to ARGB.
  40. LIBYUV_API
  41. int I422ToARGB(const uint8* src_y, int src_stride_y,
  42. const uint8* src_u, int src_stride_u,
  43. const uint8* src_v, int src_stride_v,
  44. uint8* dst_argb, int dst_stride_argb,
  45. int width, int height);
  46. // Convert I444 to ARGB.
  47. LIBYUV_API
  48. int I444ToARGB(const uint8* src_y, int src_stride_y,
  49. const uint8* src_u, int src_stride_u,
  50. const uint8* src_v, int src_stride_v,
  51. uint8* dst_argb, int dst_stride_argb,
  52. int width, int height);
  53. // Convert J444 to ARGB.
  54. LIBYUV_API
  55. int J444ToARGB(const uint8* src_y, int src_stride_y,
  56. const uint8* src_u, int src_stride_u,
  57. const uint8* src_v, int src_stride_v,
  58. uint8* dst_argb, int dst_stride_argb,
  59. int width, int height);
  60. // Convert I444 to ABGR.
  61. LIBYUV_API
  62. int I444ToABGR(const uint8* src_y, int src_stride_y,
  63. const uint8* src_u, int src_stride_u,
  64. const uint8* src_v, int src_stride_v,
  65. uint8* dst_abgr, int dst_stride_abgr,
  66. int width, int height);
  67. // Convert I411 to ARGB.
  68. LIBYUV_API
  69. int I411ToARGB(const uint8* src_y, int src_stride_y,
  70. const uint8* src_u, int src_stride_u,
  71. const uint8* src_v, int src_stride_v,
  72. uint8* dst_argb, int dst_stride_argb,
  73. int width, int height);
  74. // Convert I420 with Alpha to preattenuated ARGB.
  75. LIBYUV_API
  76. int I420AlphaToARGB(const uint8* src_y, int src_stride_y,
  77. const uint8* src_u, int src_stride_u,
  78. const uint8* src_v, int src_stride_v,
  79. const uint8* src_a, int src_stride_a,
  80. uint8* dst_argb, int dst_stride_argb,
  81. int width, int height, int attenuate);
  82. // Convert I420 with Alpha to preattenuated ABGR.
  83. LIBYUV_API
  84. int I420AlphaToABGR(const uint8* src_y, int src_stride_y,
  85. const uint8* src_u, int src_stride_u,
  86. const uint8* src_v, int src_stride_v,
  87. const uint8* src_a, int src_stride_a,
  88. uint8* dst_abgr, int dst_stride_abgr,
  89. int width, int height, int attenuate);
  90. // Convert I400 (grey) to ARGB. Reverse of ARGBToI400.
  91. LIBYUV_API
  92. int I400ToARGB(const uint8* src_y, int src_stride_y,
  93. uint8* dst_argb, int dst_stride_argb,
  94. int width, int height);
  95. // Convert J400 (jpeg grey) to ARGB.
  96. LIBYUV_API
  97. int J400ToARGB(const uint8* src_y, int src_stride_y,
  98. uint8* dst_argb, int dst_stride_argb,
  99. int width, int height);
  100. // Alias.
  101. #define YToARGB I400ToARGB
  102. // Convert NV12 to ARGB.
  103. LIBYUV_API
  104. int NV12ToARGB(const uint8* src_y, int src_stride_y,
  105. const uint8* src_uv, int src_stride_uv,
  106. uint8* dst_argb, int dst_stride_argb,
  107. int width, int height);
  108. // Convert NV21 to ARGB.
  109. LIBYUV_API
  110. int NV21ToARGB(const uint8* src_y, int src_stride_y,
  111. const uint8* src_vu, int src_stride_vu,
  112. uint8* dst_argb, int dst_stride_argb,
  113. int width, int height);
  114. // Convert M420 to ARGB.
  115. LIBYUV_API
  116. int M420ToARGB(const uint8* src_m420, int src_stride_m420,
  117. uint8* dst_argb, int dst_stride_argb,
  118. int width, int height);
  119. // Convert YUY2 to ARGB.
  120. LIBYUV_API
  121. int YUY2ToARGB(const uint8* src_yuy2, int src_stride_yuy2,
  122. uint8* dst_argb, int dst_stride_argb,
  123. int width, int height);
  124. // Convert UYVY to ARGB.
  125. LIBYUV_API
  126. int UYVYToARGB(const uint8* src_uyvy, int src_stride_uyvy,
  127. uint8* dst_argb, int dst_stride_argb,
  128. int width, int height);
  129. // Convert J420 to ARGB.
  130. LIBYUV_API
  131. int J420ToARGB(const uint8* src_y, int src_stride_y,
  132. const uint8* src_u, int src_stride_u,
  133. const uint8* src_v, int src_stride_v,
  134. uint8* dst_argb, int dst_stride_argb,
  135. int width, int height);
  136. // Convert J422 to ARGB.
  137. LIBYUV_API
  138. int J422ToARGB(const uint8* src_y, int src_stride_y,
  139. const uint8* src_u, int src_stride_u,
  140. const uint8* src_v, int src_stride_v,
  141. uint8* dst_argb, int dst_stride_argb,
  142. int width, int height);
  143. // Convert J420 to ABGR.
  144. LIBYUV_API
  145. int J420ToABGR(const uint8* src_y, int src_stride_y,
  146. const uint8* src_u, int src_stride_u,
  147. const uint8* src_v, int src_stride_v,
  148. uint8* dst_abgr, int dst_stride_abgr,
  149. int width, int height);
  150. // Convert J422 to ABGR.
  151. LIBYUV_API
  152. int J422ToABGR(const uint8* src_y, int src_stride_y,
  153. const uint8* src_u, int src_stride_u,
  154. const uint8* src_v, int src_stride_v,
  155. uint8* dst_abgr, int dst_stride_abgr,
  156. int width, int height);
  157. // Convert H420 to ARGB.
  158. LIBYUV_API
  159. int H420ToARGB(const uint8* src_y, int src_stride_y,
  160. const uint8* src_u, int src_stride_u,
  161. const uint8* src_v, int src_stride_v,
  162. uint8* dst_argb, int dst_stride_argb,
  163. int width, int height);
  164. // Convert H422 to ARGB.
  165. LIBYUV_API
  166. int H422ToARGB(const uint8* src_y, int src_stride_y,
  167. const uint8* src_u, int src_stride_u,
  168. const uint8* src_v, int src_stride_v,
  169. uint8* dst_argb, int dst_stride_argb,
  170. int width, int height);
  171. // Convert H420 to ABGR.
  172. LIBYUV_API
  173. int H420ToABGR(const uint8* src_y, int src_stride_y,
  174. const uint8* src_u, int src_stride_u,
  175. const uint8* src_v, int src_stride_v,
  176. uint8* dst_abgr, int dst_stride_abgr,
  177. int width, int height);
  178. // Convert H422 to ABGR.
  179. LIBYUV_API
  180. int H422ToABGR(const uint8* src_y, int src_stride_y,
  181. const uint8* src_u, int src_stride_u,
  182. const uint8* src_v, int src_stride_v,
  183. uint8* dst_abgr, int dst_stride_abgr,
  184. int width, int height);
  185. // BGRA little endian (argb in memory) to ARGB.
  186. LIBYUV_API
  187. int BGRAToARGB(const uint8* src_frame, int src_stride_frame,
  188. uint8* dst_argb, int dst_stride_argb,
  189. int width, int height);
  190. // ABGR little endian (rgba in memory) to ARGB.
  191. LIBYUV_API
  192. int ABGRToARGB(const uint8* src_frame, int src_stride_frame,
  193. uint8* dst_argb, int dst_stride_argb,
  194. int width, int height);
  195. // RGBA little endian (abgr in memory) to ARGB.
  196. LIBYUV_API
  197. int RGBAToARGB(const uint8* src_frame, int src_stride_frame,
  198. uint8* dst_argb, int dst_stride_argb,
  199. int width, int height);
  200. // Deprecated function name.
  201. #define BG24ToARGB RGB24ToARGB
  202. // RGB little endian (bgr in memory) to ARGB.
  203. LIBYUV_API
  204. int RGB24ToARGB(const uint8* src_frame, int src_stride_frame,
  205. uint8* dst_argb, int dst_stride_argb,
  206. int width, int height);
  207. // RGB big endian (rgb in memory) to ARGB.
  208. LIBYUV_API
  209. int RAWToARGB(const uint8* src_frame, int src_stride_frame,
  210. uint8* dst_argb, int dst_stride_argb,
  211. int width, int height);
  212. // RGB16 (RGBP fourcc) little endian to ARGB.
  213. LIBYUV_API
  214. int RGB565ToARGB(const uint8* src_frame, int src_stride_frame,
  215. uint8* dst_argb, int dst_stride_argb,
  216. int width, int height);
  217. // RGB15 (RGBO fourcc) little endian to ARGB.
  218. LIBYUV_API
  219. int ARGB1555ToARGB(const uint8* src_frame, int src_stride_frame,
  220. uint8* dst_argb, int dst_stride_argb,
  221. int width, int height);
  222. // RGB12 (R444 fourcc) little endian to ARGB.
  223. LIBYUV_API
  224. int ARGB4444ToARGB(const uint8* src_frame, int src_stride_frame,
  225. uint8* dst_argb, int dst_stride_argb,
  226. int width, int height);
  227. #ifdef HAVE_JPEG
  228. // src_width/height provided by capture
  229. // dst_width/height for clipping determine final size.
  230. LIBYUV_API
  231. int MJPGToARGB(const uint8* sample, size_t sample_size,
  232. uint8* dst_argb, int dst_stride_argb,
  233. int src_width, int src_height,
  234. int dst_width, int dst_height);
  235. #endif
  236. // Convert camera sample to ARGB with cropping, rotation and vertical flip.
  237. // "src_size" is needed to parse MJPG.
  238. // "dst_stride_argb" number of bytes in a row of the dst_argb plane.
  239. // Normally this would be the same as dst_width, with recommended alignment
  240. // to 16 bytes for better efficiency.
  241. // If rotation of 90 or 270 is used, stride is affected. The caller should
  242. // allocate the I420 buffer according to rotation.
  243. // "dst_stride_u" number of bytes in a row of the dst_u plane.
  244. // Normally this would be the same as (dst_width + 1) / 2, with
  245. // recommended alignment to 16 bytes for better efficiency.
  246. // If rotation of 90 or 270 is used, stride is affected.
  247. // "crop_x" and "crop_y" are starting position for cropping.
  248. // To center, crop_x = (src_width - dst_width) / 2
  249. // crop_y = (src_height - dst_height) / 2
  250. // "src_width" / "src_height" is size of src_frame in pixels.
  251. // "src_height" can be negative indicating a vertically flipped image source.
  252. // "crop_width" / "crop_height" is the size to crop the src to.
  253. // Must be less than or equal to src_width/src_height
  254. // Cropping parameters are pre-rotation.
  255. // "rotation" can be 0, 90, 180 or 270.
  256. // "format" is a fourcc. ie 'I420', 'YUY2'
  257. // Returns 0 for successful; -1 for invalid parameter. Non-zero for failure.
  258. LIBYUV_API
  259. int ConvertToARGB(const uint8* src_frame, size_t src_size,
  260. uint8* dst_argb, int dst_stride_argb,
  261. int crop_x, int crop_y,
  262. int src_width, int src_height,
  263. int crop_width, int crop_height,
  264. enum RotationMode rotation,
  265. uint32 format);
  266. #ifdef __cplusplus
  267. } // extern "C"
  268. } // namespace libyuv
  269. #endif
  270. #endif // INCLUDE_LIBYUV_CONVERT_ARGB_H_ NOLINT