Home | History | Annotate | Download | only in libyuv
      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 
     11 #ifndef INCLUDE_LIBYUV_CONVERT_ARGB_H_
     12 #define INCLUDE_LIBYUV_CONVERT_ARGB_H_
     13 
     14 #include "libyuv/basic_types.h"
     15 
     16 #include "libyuv/rotate.h"  // For enum RotationMode.
     17 
     18 // TODO(fbarchard): This set of functions should exactly match convert.h
     19 // TODO(fbarchard): Add tests. Create random content of right size and convert
     20 // with C vs Opt and or to I420 and compare.
     21 // TODO(fbarchard): Some of these functions lack parameter setting.
     22 
     23 #ifdef __cplusplus
     24 namespace libyuv {
     25 extern "C" {
     26 #endif
     27 
     28 // Alias.
     29 #define ARGBToARGB ARGBCopy
     30 
     31 // Copy ARGB to ARGB.
     32 LIBYUV_API
     33 int ARGBCopy(const uint8_t* src_argb,
     34              int src_stride_argb,
     35              uint8_t* dst_argb,
     36              int dst_stride_argb,
     37              int width,
     38              int height);
     39 
     40 // Convert I420 to ARGB.
     41 LIBYUV_API
     42 int I420ToARGB(const uint8_t* src_y,
     43                int src_stride_y,
     44                const uint8_t* src_u,
     45                int src_stride_u,
     46                const uint8_t* src_v,
     47                int src_stride_v,
     48                uint8_t* dst_argb,
     49                int dst_stride_argb,
     50                int width,
     51                int height);
     52 
     53 // Duplicate prototype for function in convert_from.h for remoting.
     54 LIBYUV_API
     55 int I420ToABGR(const uint8_t* src_y,
     56                int src_stride_y,
     57                const uint8_t* src_u,
     58                int src_stride_u,
     59                const uint8_t* src_v,
     60                int src_stride_v,
     61                uint8_t* dst_abgr,
     62                int dst_stride_abgr,
     63                int width,
     64                int height);
     65 
     66 // Convert I010 to ARGB.
     67 LIBYUV_API
     68 int I010ToARGB(const uint16_t* src_y,
     69                int src_stride_y,
     70                const uint16_t* src_u,
     71                int src_stride_u,
     72                const uint16_t* src_v,
     73                int src_stride_v,
     74                uint8_t* dst_argb,
     75                int dst_stride_argb,
     76                int width,
     77                int height);
     78 
     79 // Convert I010 to ARGB.
     80 LIBYUV_API
     81 int I010ToARGB(const uint16_t* src_y,
     82                int src_stride_y,
     83                const uint16_t* src_u,
     84                int src_stride_u,
     85                const uint16_t* src_v,
     86                int src_stride_v,
     87                uint8_t* dst_argb,
     88                int dst_stride_argb,
     89                int width,
     90                int height);
     91 
     92 // Convert I010 to ABGR.
     93 LIBYUV_API
     94 int I010ToABGR(const uint16_t* src_y,
     95                int src_stride_y,
     96                const uint16_t* src_u,
     97                int src_stride_u,
     98                const uint16_t* src_v,
     99                int src_stride_v,
    100                uint8_t* dst_abgr,
    101                int dst_stride_abgr,
    102                int width,
    103                int height);
    104 
    105 // Convert H010 to ARGB.
    106 LIBYUV_API
    107 int H010ToARGB(const uint16_t* src_y,
    108                int src_stride_y,
    109                const uint16_t* src_u,
    110                int src_stride_u,
    111                const uint16_t* src_v,
    112                int src_stride_v,
    113                uint8_t* dst_argb,
    114                int dst_stride_argb,
    115                int width,
    116                int height);
    117 
    118 // Convert H010 to ABGR.
    119 LIBYUV_API
    120 int H010ToABGR(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_abgr,
    127                int dst_stride_abgr,
    128                int width,
    129                int height);
    130 
    131 // Convert I422 to ARGB.
    132 LIBYUV_API
    133 int I422ToARGB(const uint8_t* src_y,
    134                int src_stride_y,
    135                const uint8_t* src_u,
    136                int src_stride_u,
    137                const uint8_t* src_v,
    138                int src_stride_v,
    139                uint8_t* dst_argb,
    140                int dst_stride_argb,
    141                int width,
    142                int height);
    143 
    144 // Convert I444 to ARGB.
    145 LIBYUV_API
    146 int I444ToARGB(const uint8_t* src_y,
    147                int src_stride_y,
    148                const uint8_t* src_u,
    149                int src_stride_u,
    150                const uint8_t* src_v,
    151                int src_stride_v,
    152                uint8_t* dst_argb,
    153                int dst_stride_argb,
    154                int width,
    155                int height);
    156 
    157 // Convert J444 to ARGB.
    158 LIBYUV_API
    159 int J444ToARGB(const uint8_t* src_y,
    160                int src_stride_y,
    161                const uint8_t* src_u,
    162                int src_stride_u,
    163                const uint8_t* src_v,
    164                int src_stride_v,
    165                uint8_t* dst_argb,
    166                int dst_stride_argb,
    167                int width,
    168                int height);
    169 
    170 // Convert I444 to ABGR.
    171 LIBYUV_API
    172 int I444ToABGR(const uint8_t* src_y,
    173                int src_stride_y,
    174                const uint8_t* src_u,
    175                int src_stride_u,
    176                const uint8_t* src_v,
    177                int src_stride_v,
    178                uint8_t* dst_abgr,
    179                int dst_stride_abgr,
    180                int width,
    181                int height);
    182 
    183 // Convert I420 with Alpha to preattenuated ARGB.
    184 LIBYUV_API
    185 int I420AlphaToARGB(const uint8_t* src_y,
    186                     int src_stride_y,
    187                     const uint8_t* src_u,
    188                     int src_stride_u,
    189                     const uint8_t* src_v,
    190                     int src_stride_v,
    191                     const uint8_t* src_a,
    192                     int src_stride_a,
    193                     uint8_t* dst_argb,
    194                     int dst_stride_argb,
    195                     int width,
    196                     int height,
    197                     int attenuate);
    198 
    199 // Convert I420 with Alpha to preattenuated ABGR.
    200 LIBYUV_API
    201 int I420AlphaToABGR(const uint8_t* src_y,
    202                     int src_stride_y,
    203                     const uint8_t* src_u,
    204                     int src_stride_u,
    205                     const uint8_t* src_v,
    206                     int src_stride_v,
    207                     const uint8_t* src_a,
    208                     int src_stride_a,
    209                     uint8_t* dst_abgr,
    210                     int dst_stride_abgr,
    211                     int width,
    212                     int height,
    213                     int attenuate);
    214 
    215 // Convert I400 (grey) to ARGB.  Reverse of ARGBToI400.
    216 LIBYUV_API
    217 int I400ToARGB(const uint8_t* src_y,
    218                int src_stride_y,
    219                uint8_t* dst_argb,
    220                int dst_stride_argb,
    221                int width,
    222                int height);
    223 
    224 // Convert J400 (jpeg grey) to ARGB.
    225 LIBYUV_API
    226 int J400ToARGB(const uint8_t* src_y,
    227                int src_stride_y,
    228                uint8_t* dst_argb,
    229                int dst_stride_argb,
    230                int width,
    231                int height);
    232 
    233 // Alias.
    234 #define YToARGB I400ToARGB
    235 
    236 // Convert NV12 to ARGB.
    237 LIBYUV_API
    238 int NV12ToARGB(const uint8_t* src_y,
    239                int src_stride_y,
    240                const uint8_t* src_uv,
    241                int src_stride_uv,
    242                uint8_t* dst_argb,
    243                int dst_stride_argb,
    244                int width,
    245                int height);
    246 
    247 // Convert NV21 to ARGB.
    248 LIBYUV_API
    249 int NV21ToARGB(const uint8_t* src_y,
    250                int src_stride_y,
    251                const uint8_t* src_vu,
    252                int src_stride_vu,
    253                uint8_t* dst_argb,
    254                int dst_stride_argb,
    255                int width,
    256                int height);
    257 
    258 // Convert NV12 to ABGR.
    259 int NV12ToABGR(const uint8_t* src_y,
    260                int src_stride_y,
    261                const uint8_t* src_uv,
    262                int src_stride_uv,
    263                uint8_t* dst_abgr,
    264                int dst_stride_abgr,
    265                int width,
    266                int height);
    267 
    268 // Convert NV21 to ABGR.
    269 LIBYUV_API
    270 int NV21ToABGR(const uint8_t* src_y,
    271                int src_stride_y,
    272                const uint8_t* src_vu,
    273                int src_stride_vu,
    274                uint8_t* dst_abgr,
    275                int dst_stride_abgr,
    276                int width,
    277                int height);
    278 
    279 // Convert NV12 to RGB24.
    280 LIBYUV_API
    281 int NV12ToRGB24(const uint8_t* src_y,
    282                 int src_stride_y,
    283                 const uint8_t* src_uv,
    284                 int src_stride_uv,
    285                 uint8_t* dst_rgb24,
    286                 int dst_stride_rgb24,
    287                 int width,
    288                 int height);
    289 
    290 // Convert NV21 to RGB24.
    291 LIBYUV_API
    292 int NV21ToRGB24(const uint8_t* src_y,
    293                 int src_stride_y,
    294                 const uint8_t* src_vu,
    295                 int src_stride_vu,
    296                 uint8_t* dst_rgb24,
    297                 int dst_stride_rgb24,
    298                 int width,
    299                 int height);
    300 
    301 // Convert M420 to ARGB.
    302 LIBYUV_API
    303 int M420ToARGB(const uint8_t* src_m420,
    304                int src_stride_m420,
    305                uint8_t* dst_argb,
    306                int dst_stride_argb,
    307                int width,
    308                int height);
    309 
    310 // Convert YUY2 to ARGB.
    311 LIBYUV_API
    312 int YUY2ToARGB(const uint8_t* src_yuy2,
    313                int src_stride_yuy2,
    314                uint8_t* dst_argb,
    315                int dst_stride_argb,
    316                int width,
    317                int height);
    318 
    319 // Convert UYVY to ARGB.
    320 LIBYUV_API
    321 int UYVYToARGB(const uint8_t* src_uyvy,
    322                int src_stride_uyvy,
    323                uint8_t* dst_argb,
    324                int dst_stride_argb,
    325                int width,
    326                int height);
    327 
    328 // Convert J420 to ARGB.
    329 LIBYUV_API
    330 int J420ToARGB(const uint8_t* src_y,
    331                int src_stride_y,
    332                const uint8_t* src_u,
    333                int src_stride_u,
    334                const uint8_t* src_v,
    335                int src_stride_v,
    336                uint8_t* dst_argb,
    337                int dst_stride_argb,
    338                int width,
    339                int height);
    340 
    341 // Convert J422 to ARGB.
    342 LIBYUV_API
    343 int J422ToARGB(const uint8_t* src_y,
    344                int src_stride_y,
    345                const uint8_t* src_u,
    346                int src_stride_u,
    347                const uint8_t* src_v,
    348                int src_stride_v,
    349                uint8_t* dst_argb,
    350                int dst_stride_argb,
    351                int width,
    352                int height);
    353 
    354 // Convert J420 to ABGR.
    355 LIBYUV_API
    356 int J420ToABGR(const uint8_t* src_y,
    357                int src_stride_y,
    358                const uint8_t* src_u,
    359                int src_stride_u,
    360                const uint8_t* src_v,
    361                int src_stride_v,
    362                uint8_t* dst_abgr,
    363                int dst_stride_abgr,
    364                int width,
    365                int height);
    366 
    367 // Convert J422 to ABGR.
    368 LIBYUV_API
    369 int J422ToABGR(const uint8_t* src_y,
    370                int src_stride_y,
    371                const uint8_t* src_u,
    372                int src_stride_u,
    373                const uint8_t* src_v,
    374                int src_stride_v,
    375                uint8_t* dst_abgr,
    376                int dst_stride_abgr,
    377                int width,
    378                int height);
    379 
    380 // Convert H420 to ARGB.
    381 LIBYUV_API
    382 int H420ToARGB(const uint8_t* src_y,
    383                int src_stride_y,
    384                const uint8_t* src_u,
    385                int src_stride_u,
    386                const uint8_t* src_v,
    387                int src_stride_v,
    388                uint8_t* dst_argb,
    389                int dst_stride_argb,
    390                int width,
    391                int height);
    392 
    393 // Convert H422 to ARGB.
    394 LIBYUV_API
    395 int H422ToARGB(const uint8_t* src_y,
    396                int src_stride_y,
    397                const uint8_t* src_u,
    398                int src_stride_u,
    399                const uint8_t* src_v,
    400                int src_stride_v,
    401                uint8_t* dst_argb,
    402                int dst_stride_argb,
    403                int width,
    404                int height);
    405 
    406 // Convert H420 to ABGR.
    407 LIBYUV_API
    408 int H420ToABGR(const uint8_t* src_y,
    409                int src_stride_y,
    410                const uint8_t* src_u,
    411                int src_stride_u,
    412                const uint8_t* src_v,
    413                int src_stride_v,
    414                uint8_t* dst_abgr,
    415                int dst_stride_abgr,
    416                int width,
    417                int height);
    418 
    419 // Convert H422 to ABGR.
    420 LIBYUV_API
    421 int H422ToABGR(const uint8_t* src_y,
    422                int src_stride_y,
    423                const uint8_t* src_u,
    424                int src_stride_u,
    425                const uint8_t* src_v,
    426                int src_stride_v,
    427                uint8_t* dst_abgr,
    428                int dst_stride_abgr,
    429                int width,
    430                int height);
    431 
    432 // Convert H010 to ARGB.
    433 LIBYUV_API
    434 int H010ToARGB(const uint16_t* src_y,
    435                int src_stride_y,
    436                const uint16_t* src_u,
    437                int src_stride_u,
    438                const uint16_t* src_v,
    439                int src_stride_v,
    440                uint8_t* dst_argb,
    441                int dst_stride_argb,
    442                int width,
    443                int height);
    444 
    445 // Convert I010 to AR30.
    446 LIBYUV_API
    447 int I010ToAR30(const uint16_t* src_y,
    448                int src_stride_y,
    449                const uint16_t* src_u,
    450                int src_stride_u,
    451                const uint16_t* src_v,
    452                int src_stride_v,
    453                uint8_t* dst_ar30,
    454                int dst_stride_ar30,
    455                int width,
    456                int height);
    457 
    458 // Convert H010 to AR30.
    459 LIBYUV_API
    460 int H010ToAR30(const uint16_t* src_y,
    461                int src_stride_y,
    462                const uint16_t* src_u,
    463                int src_stride_u,
    464                const uint16_t* src_v,
    465                int src_stride_v,
    466                uint8_t* dst_ar30,
    467                int dst_stride_ar30,
    468                int width,
    469                int height);
    470 
    471 // Convert I010 to AB30.
    472 LIBYUV_API
    473 int I010ToAB30(const uint16_t* src_y,
    474                int src_stride_y,
    475                const uint16_t* src_u,
    476                int src_stride_u,
    477                const uint16_t* src_v,
    478                int src_stride_v,
    479                uint8_t* dst_ab30,
    480                int dst_stride_ab30,
    481                int width,
    482                int height);
    483 
    484 // Convert H010 to AB30.
    485 LIBYUV_API
    486 int H010ToAB30(const uint16_t* src_y,
    487                int src_stride_y,
    488                const uint16_t* src_u,
    489                int src_stride_u,
    490                const uint16_t* src_v,
    491                int src_stride_v,
    492                uint8_t* dst_ab30,
    493                int dst_stride_ab30,
    494                int width,
    495                int height);
    496 
    497 // BGRA little endian (argb in memory) to ARGB.
    498 LIBYUV_API
    499 int BGRAToARGB(const uint8_t* src_bgra,
    500                int src_stride_bgra,
    501                uint8_t* dst_argb,
    502                int dst_stride_argb,
    503                int width,
    504                int height);
    505 
    506 // ABGR little endian (rgba in memory) to ARGB.
    507 LIBYUV_API
    508 int ABGRToARGB(const uint8_t* src_abgr,
    509                int src_stride_abgr,
    510                uint8_t* dst_argb,
    511                int dst_stride_argb,
    512                int width,
    513                int height);
    514 
    515 // RGBA little endian (abgr in memory) to ARGB.
    516 LIBYUV_API
    517 int RGBAToARGB(const uint8_t* src_rgba,
    518                int src_stride_rgba,
    519                uint8_t* dst_argb,
    520                int dst_stride_argb,
    521                int width,
    522                int height);
    523 
    524 // Deprecated function name.
    525 #define BG24ToARGB RGB24ToARGB
    526 
    527 // RGB little endian (bgr in memory) to ARGB.
    528 LIBYUV_API
    529 int RGB24ToARGB(const uint8_t* src_rgb24,
    530                 int src_stride_rgb24,
    531                 uint8_t* dst_argb,
    532                 int dst_stride_argb,
    533                 int width,
    534                 int height);
    535 
    536 // RGB big endian (rgb in memory) to ARGB.
    537 LIBYUV_API
    538 int RAWToARGB(const uint8_t* src_raw,
    539               int src_stride_raw,
    540               uint8_t* dst_argb,
    541               int dst_stride_argb,
    542               int width,
    543               int height);
    544 
    545 // RGB16 (RGBP fourcc) little endian to ARGB.
    546 LIBYUV_API
    547 int RGB565ToARGB(const uint8_t* src_rgb565,
    548                  int src_stride_rgb565,
    549                  uint8_t* dst_argb,
    550                  int dst_stride_argb,
    551                  int width,
    552                  int height);
    553 
    554 // RGB15 (RGBO fourcc) little endian to ARGB.
    555 LIBYUV_API
    556 int ARGB1555ToARGB(const uint8_t* src_argb1555,
    557                    int src_stride_argb1555,
    558                    uint8_t* dst_argb,
    559                    int dst_stride_argb,
    560                    int width,
    561                    int height);
    562 
    563 // RGB12 (R444 fourcc) little endian to ARGB.
    564 LIBYUV_API
    565 int ARGB4444ToARGB(const uint8_t* src_argb4444,
    566                    int src_stride_argb4444,
    567                    uint8_t* dst_argb,
    568                    int dst_stride_argb,
    569                    int width,
    570                    int height);
    571 
    572 // Aliases
    573 #define AB30ToARGB AR30ToABGR
    574 #define AB30ToABGR AR30ToARGB
    575 #define AB30ToAR30 AR30ToAB30
    576 
    577 // Convert AR30 To ARGB.
    578 LIBYUV_API
    579 int AR30ToARGB(const uint8_t* src_ar30,
    580                int src_stride_ar30,
    581                uint8_t* dst_argb,
    582                int dst_stride_argb,
    583                int width,
    584                int height);
    585 
    586 // Convert AR30 To ABGR.
    587 LIBYUV_API
    588 int AR30ToABGR(const uint8_t* src_ar30,
    589                int src_stride_ar30,
    590                uint8_t* dst_abgr,
    591                int dst_stride_abgr,
    592                int width,
    593                int height);
    594 
    595 // Convert AR30 To AB30.
    596 LIBYUV_API
    597 int AR30ToAB30(const uint8_t* src_ar30,
    598                int src_stride_ar30,
    599                uint8_t* dst_ab30,
    600                int dst_stride_ab30,
    601                int width,
    602                int height);
    603 
    604 #ifdef HAVE_JPEG
    605 // src_width/height provided by capture
    606 // dst_width/height for clipping determine final size.
    607 LIBYUV_API
    608 int MJPGToARGB(const uint8_t* sample,
    609                size_t sample_size,
    610                uint8_t* dst_argb,
    611                int dst_stride_argb,
    612                int src_width,
    613                int src_height,
    614                int dst_width,
    615                int dst_height);
    616 #endif
    617 
    618 // Convert Android420 to ARGB.
    619 LIBYUV_API
    620 int Android420ToARGB(const uint8_t* src_y,
    621                      int src_stride_y,
    622                      const uint8_t* src_u,
    623                      int src_stride_u,
    624                      const uint8_t* src_v,
    625                      int src_stride_v,
    626                      int src_pixel_stride_uv,
    627                      uint8_t* dst_argb,
    628                      int dst_stride_argb,
    629                      int width,
    630                      int height);
    631 
    632 // Convert Android420 to ABGR.
    633 LIBYUV_API
    634 int Android420ToABGR(const uint8_t* src_y,
    635                      int src_stride_y,
    636                      const uint8_t* src_u,
    637                      int src_stride_u,
    638                      const uint8_t* src_v,
    639                      int src_stride_v,
    640                      int src_pixel_stride_uv,
    641                      uint8_t* dst_abgr,
    642                      int dst_stride_abgr,
    643                      int width,
    644                      int height);
    645 
    646 // Convert camera sample to ARGB with cropping, rotation and vertical flip.
    647 // "sample_size" is needed to parse MJPG.
    648 // "dst_stride_argb" number of bytes in a row of the dst_argb plane.
    649 //   Normally this would be the same as dst_width, with recommended alignment
    650 //   to 16 bytes for better efficiency.
    651 //   If rotation of 90 or 270 is used, stride is affected. The caller should
    652 //   allocate the I420 buffer according to rotation.
    653 // "dst_stride_u" number of bytes in a row of the dst_u plane.
    654 //   Normally this would be the same as (dst_width + 1) / 2, with
    655 //   recommended alignment to 16 bytes for better efficiency.
    656 //   If rotation of 90 or 270 is used, stride is affected.
    657 // "crop_x" and "crop_y" are starting position for cropping.
    658 //   To center, crop_x = (src_width - dst_width) / 2
    659 //              crop_y = (src_height - dst_height) / 2
    660 // "src_width" / "src_height" is size of src_frame in pixels.
    661 //   "src_height" can be negative indicating a vertically flipped image source.
    662 // "crop_width" / "crop_height" is the size to crop the src to.
    663 //    Must be less than or equal to src_width/src_height
    664 //    Cropping parameters are pre-rotation.
    665 // "rotation" can be 0, 90, 180 or 270.
    666 // "fourcc" is a fourcc. ie 'I420', 'YUY2'
    667 // Returns 0 for successful; -1 for invalid parameter. Non-zero for failure.
    668 LIBYUV_API
    669 int ConvertToARGB(const uint8_t* sample,
    670                   size_t sample_size,
    671                   uint8_t* dst_argb,
    672                   int dst_stride_argb,
    673                   int crop_x,
    674                   int crop_y,
    675                   int src_width,
    676                   int src_height,
    677                   int crop_width,
    678                   int crop_height,
    679                   enum RotationMode rotation,
    680                   uint32_t fourcc);
    681 
    682 #ifdef __cplusplus
    683 }  // extern "C"
    684 }  // namespace libyuv
    685 #endif
    686 
    687 #endif  // INCLUDE_LIBYUV_CONVERT_ARGB_H_
    688