Home | History | Annotate | Download | only in renderer
      1 #include "precompiled.h"
      2 //
      3 // Copyright (c) 0013 The ANGLE Project Authors. All rights reserved.
      4 // Use of this source code is governed by a BSD-style license that can be
      5 // found in the LICENSE file.
      6 //
      7 
      8 // loadimage.cpp: Defines image loading functions.
      9 
     10 #include "libGLESv2/renderer/loadimage.h"
     11 
     12 namespace rx
     13 {
     14 
     15 void loadAlphaDataToBGRA(int width, int height, int depth,
     16                          const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
     17                          void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
     18 {
     19     const unsigned char *source = NULL;
     20     unsigned char *dest = NULL;
     21 
     22     for (int z = 0; z < depth; z++)
     23     {
     24         for (int y = 0; y < height; y++)
     25         {
     26             source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch);
     27             dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
     28             for (int x = 0; x < width; x++)
     29             {
     30                 dest[4 * x + 0] = 0;
     31                 dest[4 * x + 1] = 0;
     32                 dest[4 * x + 2] = 0;
     33                 dest[4 * x + 3] = source[x];
     34             }
     35         }
     36     }
     37 }
     38 
     39 void loadAlphaDataToNative(int width, int height, int depth,
     40                            const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
     41                            void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
     42 {
     43     const unsigned char *source = NULL;
     44     unsigned char *dest = NULL;
     45 
     46     for (int z = 0; z < depth; z++)
     47     {
     48         for (int y = 0; y < height; y++)
     49         {
     50             source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch);
     51             dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
     52             memcpy(dest, source, width);
     53         }
     54     }
     55 }
     56 
     57 void loadAlphaFloatDataToRGBA(int width, int height, int depth,
     58                               const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
     59                               void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
     60 {
     61     const float *source = NULL;
     62     float *dest = NULL;
     63 
     64     for (int z = 0; z < depth; z++)
     65     {
     66         for (int y = 0; y < height; y++)
     67         {
     68             source = offsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch);
     69             dest = offsetDataPointer<float>(output, y, z, outputRowPitch, outputDepthPitch);
     70             for (int x = 0; x < width; x++)
     71             {
     72                 dest[4 * x + 0] = 0;
     73                 dest[4 * x + 1] = 0;
     74                 dest[4 * x + 2] = 0;
     75                 dest[4 * x + 3] = source[x];
     76             }
     77         }
     78     }
     79 }
     80 
     81 void loadAlphaHalfFloatDataToRGBA(int width, int height, int depth,
     82                                   const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
     83                                   void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
     84 {
     85     const unsigned short *source = NULL;
     86     unsigned short *dest = NULL;
     87 
     88     for (int z = 0; z < depth; z++)
     89     {
     90         for (int y = 0; y < height; y++)
     91         {
     92             source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch);
     93             dest = offsetDataPointer<unsigned short>(output, y, z, outputRowPitch, outputDepthPitch);
     94             for (int x = 0; x < width; x++)
     95             {
     96                 dest[4 * x + 0] = 0;
     97                 dest[4 * x + 1] = 0;
     98                 dest[4 * x + 2] = 0;
     99                 dest[4 * x + 3] = source[x];
    100             }
    101         }
    102     }
    103 }
    104 
    105 void loadLuminanceDataToNative(int width, int height, int depth,
    106                                const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
    107                                void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
    108 {
    109     const unsigned char *source = NULL;
    110     unsigned char *dest = NULL;
    111 
    112     for (int z = 0; z < depth; z++)
    113     {
    114         for (int y = 0; y < height; y++)
    115         {
    116             source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch);
    117             dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
    118             memcpy(dest, source, width);
    119         }
    120     }
    121 }
    122 
    123 void loadLuminanceDataToBGRA(int width, int height, int depth,
    124                              const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
    125                              void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
    126 {
    127     const unsigned char *source = NULL;
    128     unsigned char *dest = NULL;
    129 
    130     for (int z = 0; z < depth; z++)
    131     {
    132         for (int y = 0; y < height; y++)
    133         {
    134             source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch);
    135             dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
    136             for (int x = 0; x < width; x++)
    137             {
    138                 dest[4 * x + 0] = source[x];
    139                 dest[4 * x + 1] = source[x];
    140                 dest[4 * x + 2] = source[x];
    141                 dest[4 * x + 3] = 0xFF;
    142             }
    143         }
    144     }
    145 }
    146 
    147 void loadLuminanceFloatDataToRGBA(int width, int height, int depth,
    148                                   const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
    149                                   void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
    150 {
    151     const float *source = NULL;
    152     float *dest = NULL;
    153 
    154     for (int z = 0; z < depth; z++)
    155     {
    156         for (int y = 0; y < height; y++)
    157         {
    158             source = offsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch);
    159             dest = offsetDataPointer<float>(output, y, z, outputRowPitch, outputDepthPitch);
    160             for (int x = 0; x < width; x++)
    161             {
    162                 dest[4 * x + 0] = source[x];
    163                 dest[4 * x + 1] = source[x];
    164                 dest[4 * x + 2] = source[x];
    165                 dest[4 * x + 3] = 1.0f;
    166             }
    167         }
    168     }
    169 }
    170 
    171 void loadLuminanceFloatDataToRGB(int width, int height, int depth,
    172                                  const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
    173                                  void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
    174 {
    175     const float *source = NULL;
    176     float *dest = NULL;
    177 
    178     for (int z = 0; z < depth; z++)
    179     {
    180         for (int y = 0; y < height; y++)
    181         {
    182             source = offsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch);
    183             dest = offsetDataPointer<float>(output, y, z, outputRowPitch, outputDepthPitch);
    184             for (int x = 0; x < width; x++)
    185             {
    186                 dest[3 * x + 0] = source[x];
    187                 dest[3 * x + 1] = source[x];
    188                 dest[3 * x + 2] = source[x];
    189             }
    190         }
    191     }
    192 }
    193 
    194 void loadLuminanceHalfFloatDataToRGBA(int width, int height, int depth,
    195                                       const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
    196                                       void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
    197 {
    198     const unsigned short *source = NULL;
    199     unsigned short *dest = NULL;
    200 
    201     for (int z = 0; z < depth; z++)
    202     {
    203         for (int y = 0; y < height; y++)
    204         {
    205             source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch);
    206             dest = offsetDataPointer<unsigned short>(output, y, z, outputRowPitch, outputDepthPitch);
    207             for (int x = 0; x < width; x++)
    208             {
    209                 dest[4 * x + 0] = source[x];
    210                 dest[4 * x + 1] = source[x];
    211                 dest[4 * x + 2] = source[x];
    212                 dest[4 * x + 3] = gl::Float16One;
    213             }
    214         }
    215     }
    216 }
    217 
    218 void loadLuminanceAlphaDataToNative(int width, int height, int depth,
    219                                     const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
    220                                     void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
    221 {
    222     const unsigned char *source = NULL;
    223     unsigned char *dest = NULL;
    224 
    225     for (int z = 0; z < depth; z++)
    226     {
    227         for (int y = 0; y < height; y++)
    228         {
    229             source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch);
    230             dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
    231 
    232             memcpy(dest, source, width * 2);
    233         }
    234     }
    235 }
    236 
    237 void loadLuminanceAlphaDataToBGRA(int width, int height, int depth,
    238                                   const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
    239                                   void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
    240 {
    241     const unsigned char *source = NULL;
    242     unsigned char *dest = NULL;
    243 
    244     for (int z = 0; z < depth; z++)
    245     {
    246         for (int y = 0; y < height; y++)
    247         {
    248             source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch);
    249             dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
    250 
    251             for (int x = 0; x < width; x++)
    252             {
    253                 dest[4 * x + 0] = source[2*x+0];
    254                 dest[4 * x + 1] = source[2*x+0];
    255                 dest[4 * x + 2] = source[2*x+0];
    256                 dest[4 * x + 3] = source[2*x+1];
    257             }
    258         }
    259     }
    260 }
    261 
    262 void loadLuminanceAlphaFloatDataToRGBA(int width, int height, int depth,
    263                                        const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
    264                                        void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
    265 {
    266     const float *source = NULL;
    267     float *dest = NULL;
    268 
    269     for (int z = 0; z < depth; z++)
    270     {
    271         for (int y = 0; y < height; y++)
    272         {
    273             source = offsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch);
    274             dest = offsetDataPointer<float>(output, y, z, outputRowPitch, outputDepthPitch);
    275             for (int x = 0; x < width; x++)
    276             {
    277                 dest[4 * x + 0] = source[2*x+0];
    278                 dest[4 * x + 1] = source[2*x+0];
    279                 dest[4 * x + 2] = source[2*x+0];
    280                 dest[4 * x + 3] = source[2*x+1];
    281             }
    282         }
    283     }
    284 }
    285 
    286 void loadLuminanceAlphaHalfFloatDataToRGBA(int width, int height, int depth,
    287                                            const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
    288                                            void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
    289 {
    290     const unsigned short *source = NULL;
    291     unsigned short *dest = NULL;
    292 
    293     for (int z = 0; z < depth; z++)
    294     {
    295         for (int y = 0; y < height; y++)
    296         {
    297             source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch);
    298             dest = offsetDataPointer<unsigned short>(output, y, z, outputRowPitch, outputDepthPitch);
    299             for (int x = 0; x < width; x++)
    300             {
    301                 dest[4 * x + 0] = source[2*x+0];
    302                 dest[4 * x + 1] = source[2*x+0];
    303                 dest[4 * x + 2] = source[2*x+0];
    304                 dest[4 * x + 3] = source[2*x+1];
    305             }
    306         }
    307     }
    308 }
    309 
    310 void loadRGBUByteDataToBGRX(int width, int height, int depth,
    311                             const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
    312                             void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
    313 {
    314     const unsigned char *source = NULL;
    315     unsigned char *dest = NULL;
    316 
    317     for (int z = 0; z < depth; z++)
    318     {
    319         for (int y = 0; y < height; y++)
    320         {
    321             source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch);
    322             dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
    323             for (int x = 0; x < width; x++)
    324             {
    325                 dest[4 * x + 0] = source[x * 3 + 2];
    326                 dest[4 * x + 1] = source[x * 3 + 1];
    327                 dest[4 * x + 2] = source[x * 3 + 0];
    328                 dest[4 * x + 3] = 0xFF;
    329             }
    330         }
    331     }
    332 }
    333 
    334 void loadRGUByteDataToBGRX(int width, int height, int depth,
    335                            const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
    336                            void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
    337 {
    338     const unsigned char *source = NULL;
    339     unsigned char *dest = NULL;
    340 
    341     for (int z = 0; z < depth; z++)
    342     {
    343         for (int y = 0; y < height; y++)
    344         {
    345             source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch);
    346             dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
    347             for (int x = 0; x < width; x++)
    348             {
    349                 dest[4 * x + 0] = 0x00;
    350                 dest[4 * x + 1] = source[x * 2 + 1];
    351                 dest[4 * x + 2] = source[x * 2 + 0];
    352                 dest[4 * x + 3] = 0xFF;
    353             }
    354         }
    355     }
    356 }
    357 
    358 void loadRUByteDataToBGRX(int width, int height, int depth,
    359                           const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
    360                           void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
    361 {
    362     const unsigned char *source = NULL;
    363     unsigned char *dest = NULL;
    364 
    365     for (int z = 0; z < depth; z++)
    366     {
    367         for (int y = 0; y < height; y++)
    368         {
    369             source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch);
    370             dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
    371             for (int x = 0; x < width; x++)
    372             {
    373                 dest[4 * x + 0] = 0x00;
    374                 dest[4 * x + 1] = 0x00;
    375                 dest[4 * x + 2] = source[x];
    376                 dest[4 * x + 3] = 0xFF;
    377             }
    378         }
    379     }
    380 }
    381 
    382 void loadRGBUByteDataToRGBA(int width, int height, int depth,
    383                             const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
    384                             void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
    385 {
    386     const unsigned char *source = NULL;
    387     unsigned char *dest = NULL;
    388 
    389     for (int z = 0; z < depth; z++)
    390     {
    391         for (int y = 0; y < height; y++)
    392         {
    393             source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch);
    394             dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
    395             for (int x = 0; x < width; x++)
    396             {
    397                 dest[4 * x + 0] = source[x * 3 + 0];
    398                 dest[4 * x + 1] = source[x * 3 + 1];
    399                 dest[4 * x + 2] = source[x * 3 + 2];
    400                 dest[4 * x + 3] = 0xFF;
    401             }
    402         }
    403     }
    404 }
    405 
    406 void loadRGBSByteDataToRGBA(int width, int height, int depth,
    407                             const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
    408                             void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
    409 {
    410     const char *source = NULL;
    411     char *dest = NULL;
    412 
    413     for (int z = 0; z < depth; z++)
    414     {
    415         for (int y = 0; y < height; y++)
    416         {
    417             source = offsetDataPointer<char>(input, y, z, inputRowPitch, inputDepthPitch);
    418             dest = offsetDataPointer<char>(output, y, z, outputRowPitch, outputDepthPitch);
    419             for (int x = 0; x < width; x++)
    420             {
    421                 dest[4 * x + 0] = source[x * 3 + 0];
    422                 dest[4 * x + 1] = source[x * 3 + 1];
    423                 dest[4 * x + 2] = source[x * 3 + 2];
    424                 dest[4 * x + 3] = 0x7F;
    425             }
    426         }
    427     }
    428 }
    429 
    430 void loadRGB565DataToBGRA(int width, int height, int depth,
    431                           const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
    432                           void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
    433 {
    434     const unsigned short *source = NULL;
    435     unsigned char *dest = NULL;
    436 
    437     for (int z = 0; z < depth; z++)
    438     {
    439         for (int y = 0; y < height; y++)
    440         {
    441             source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch);
    442             dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
    443             for (int x = 0; x < width; x++)
    444             {
    445                 unsigned short rgba = source[x];
    446                 dest[4 * x + 0] = ((rgba & 0x001F) << 3) | ((rgba & 0x001F) >> 2);
    447                 dest[4 * x + 1] = ((rgba & 0x07E0) >> 3) | ((rgba & 0x07E0) >> 9);
    448                 dest[4 * x + 2] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13);
    449                 dest[4 * x + 3] = 0xFF;
    450             }
    451         }
    452     }
    453 }
    454 
    455 void loadRGB565DataToRGBA(int width, int height, int depth,
    456                           const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
    457                           void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
    458 {
    459     const unsigned short *source = NULL;
    460     unsigned char *dest = NULL;
    461 
    462     for (int z = 0; z < depth; z++)
    463     {
    464         for (int y = 0; y < height; y++)
    465         {
    466             source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch);
    467             dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
    468             for (int x = 0; x < width; x++)
    469             {
    470                 unsigned short rgba = source[x];
    471                 dest[4 * x + 0] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13);
    472                 dest[4 * x + 1] = ((rgba & 0x07E0) >> 3) | ((rgba & 0x07E0) >> 9);
    473                 dest[4 * x + 2] = ((rgba & 0x001F) << 3) | ((rgba & 0x001F) >> 2);
    474                 dest[4 * x + 3] = 0xFF;
    475             }
    476         }
    477     }
    478 }
    479 
    480 void loadRGBFloatDataToRGBA(int width, int height, int depth,
    481                             const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
    482                             void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
    483 {
    484     const float *source = NULL;
    485     float *dest = NULL;
    486 
    487     for (int z = 0; z < depth; z++)
    488     {
    489         for (int y = 0; y < height; y++)
    490         {
    491             source = offsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch);
    492             dest = offsetDataPointer<float>(output, y, z, outputRowPitch, outputDepthPitch);
    493             for (int x = 0; x < width; x++)
    494             {
    495                 dest[4 * x + 0] = source[x * 3 + 0];
    496                 dest[4 * x + 1] = source[x * 3 + 1];
    497                 dest[4 * x + 2] = source[x * 3 + 2];
    498                 dest[4 * x + 3] = 1.0f;
    499             }
    500         }
    501     }
    502 }
    503 
    504 void loadRGBFloatDataToNative(int width, int height, int depth,
    505                               const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
    506                               void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
    507 {
    508     const float *source = NULL;
    509     float *dest = NULL;
    510 
    511     for (int z = 0; z < depth; z++)
    512     {
    513         for (int y = 0; y < height; y++)
    514         {
    515             source = offsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch);
    516             dest = offsetDataPointer<float>(output, y, z, outputRowPitch, outputDepthPitch);
    517             memcpy(dest, source, width * 12);
    518         }
    519     }
    520 }
    521 
    522 void loadRGBHalfFloatDataToRGBA(int width, int height, int depth,
    523                                 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
    524                                 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
    525 {
    526     const unsigned short *source = NULL;
    527     unsigned short *dest = NULL;
    528 
    529     for (int z = 0; z < depth; z++)
    530     {
    531         for (int y = 0; y < height; y++)
    532         {
    533             source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch);
    534             dest = offsetDataPointer<unsigned short>(output, y, z, outputRowPitch, outputDepthPitch);
    535             for (int x = 0; x < width; x++)
    536             {
    537                 dest[4 * x + 0] = source[x * 3 + 0];
    538                 dest[4 * x + 1] = source[x * 3 + 1];
    539                 dest[4 * x + 2] = source[x * 3 + 2];
    540                 dest[4 * x + 3] = 0x3C00; // SEEEEEMMMMMMMMMM, S = 0, E = 15, M = 0: 16bit flpt representation of 1
    541             }
    542         }
    543     }
    544 }
    545 
    546 void loadRGBAUByteDataToBGRA(int width, int height, int depth,
    547                              const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
    548                              void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
    549 {
    550     const unsigned int *source = NULL;
    551     unsigned int *dest = NULL;
    552 
    553     for (int z = 0; z < depth; z++)
    554     {
    555         for (int y = 0; y < height; y++)
    556         {
    557             source = offsetDataPointer<unsigned int>(input, y, z, inputRowPitch, inputDepthPitch);
    558             dest = offsetDataPointer<unsigned int>(output, y, z, outputRowPitch, outputDepthPitch);
    559 
    560             for (int x = 0; x < width; x++)
    561             {
    562                 unsigned int rgba = source[x];
    563                 dest[x] = (_rotl(rgba, 16) & 0x00ff00ff) | (rgba & 0xff00ff00);
    564             }
    565         }
    566     }
    567 }
    568 
    569 void loadRGBAUByteDataToNative(int width, int height, int depth,
    570                                const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
    571                                void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
    572 {
    573     const unsigned int *source = NULL;
    574     unsigned int *dest = NULL;
    575 
    576     for (int z = 0; z < depth; z++)
    577     {
    578         for (int y = 0; y < height; y++)
    579         {
    580             source = offsetDataPointer<unsigned int>(input, y, z, inputRowPitch, inputDepthPitch);
    581             dest = offsetDataPointer<unsigned int>(output, y, z, outputRowPitch, outputDepthPitch);
    582 
    583             memcpy(dest, source, width * 4);
    584         }
    585     }
    586 }
    587 
    588 void loadRGBA4444DataToBGRA(int width, int height, int depth,
    589                             const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
    590                             void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
    591 {
    592     const unsigned short *source = NULL;
    593     unsigned char *dest = NULL;
    594 
    595     for (int z = 0; z < depth; z++)
    596     {
    597         for (int y = 0; y < height; y++)
    598         {
    599             source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch);
    600             dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
    601             for (int x = 0; x < width; x++)
    602             {
    603                 unsigned short rgba = source[x];
    604                 dest[4 * x + 0] = ((rgba & 0x00F0) << 0) | ((rgba & 0x00F0) >> 4);
    605                 dest[4 * x + 1] = ((rgba & 0x0F00) >> 4) | ((rgba & 0x0F00) >> 8);
    606                 dest[4 * x + 2] = ((rgba & 0xF000) >> 8) | ((rgba & 0xF000) >> 12);
    607                 dest[4 * x + 3] = ((rgba & 0x000F) << 4) | ((rgba & 0x000F) >> 0);
    608             }
    609         }
    610     }
    611 }
    612 
    613 void loadRGBA4444DataToRGBA(int width, int height, int depth,
    614                             const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
    615                             void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
    616 {
    617     const unsigned short *source = NULL;
    618     unsigned char *dest = NULL;
    619 
    620     for (int z = 0; z < depth; z++)
    621     {
    622         for (int y = 0; y < height; y++)
    623         {
    624             source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch);
    625             dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
    626             for (int x = 0; x < width; x++)
    627             {
    628                 unsigned short rgba = source[x];
    629                 dest[4 * x + 0] = ((rgba & 0xF000) >> 8) | ((rgba & 0xF000) >> 12);
    630                 dest[4 * x + 1] = ((rgba & 0x0F00) >> 4) | ((rgba & 0x0F00) >> 8);
    631                 dest[4 * x + 2] = ((rgba & 0x00F0) << 0) | ((rgba & 0x00F0) >> 4);
    632                 dest[4 * x + 3] = ((rgba & 0x000F) << 4) | ((rgba & 0x000F) >> 0);
    633             }
    634         }
    635     }
    636 }
    637 
    638 void loadRGBA5551DataToBGRA(int width, int height, int depth,
    639                             const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
    640                             void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
    641 {
    642     const unsigned short *source = NULL;
    643     unsigned char *dest = NULL;
    644 
    645     for (int z = 0; z < depth; z++)
    646     {
    647         for (int y = 0; y < height; y++)
    648         {
    649             source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch);
    650             dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
    651             for (int x = 0; x < width; x++)
    652             {
    653                 unsigned short rgba = source[x];
    654                 dest[4 * x + 0] = ((rgba & 0x003E) << 2) | ((rgba & 0x003E) >> 3);
    655                 dest[4 * x + 1] = ((rgba & 0x07C0) >> 3) | ((rgba & 0x07C0) >> 8);
    656                 dest[4 * x + 2] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13);
    657                 dest[4 * x + 3] = (rgba & 0x0001) ? 0xFF : 0;
    658             }
    659         }
    660     }
    661 }
    662 void loadRGBA5551DataToRGBA(int width, int height, int depth,
    663                             const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
    664                             void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
    665 {
    666     const unsigned short *source = NULL;
    667     unsigned char *dest = NULL;
    668 
    669     for (int z = 0; z < depth; z++)
    670     {
    671         for (int y = 0; y < height; y++)
    672         {
    673             source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch);
    674             dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
    675             for (int x = 0; x < width; x++)
    676             {
    677                 unsigned short rgba = source[x];
    678                 dest[4 * x + 0] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13);
    679                 dest[4 * x + 1] = ((rgba & 0x07C0) >> 3) | ((rgba & 0x07C0) >> 8);
    680                 dest[4 * x + 2] = ((rgba & 0x003E) << 2) | ((rgba & 0x003E) >> 3);
    681                 dest[4 * x + 3] = (rgba & 0x0001) ? 0xFF : 0;
    682             }
    683         }
    684     }
    685 }
    686 
    687 void loadRGBAFloatDataToRGBA(int width, int height, int depth,
    688                              const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
    689                              void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
    690 {
    691     const float *source = NULL;
    692     float *dest = NULL;
    693 
    694     for (int z = 0; z < depth; z++)
    695     {
    696         for (int y = 0; y < height; y++)
    697         {
    698             source = offsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch);
    699             dest = offsetDataPointer<float>(output, y, z, outputRowPitch, outputDepthPitch);
    700             memcpy(dest, source, width * 16);
    701         }
    702     }
    703 }
    704 
    705 void loadRGBAHalfFloatDataToRGBA(int width, int height, int depth,
    706                                  const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
    707                                  void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
    708 {
    709     const unsigned char *source = NULL;
    710     unsigned char *dest = NULL;
    711 
    712     for (int z = 0; z < depth; z++)
    713     {
    714         for (int y = 0; y < height; y++)
    715         {
    716             source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch);
    717             dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
    718             memcpy(dest, source, width * 8);
    719         }
    720     }
    721 }
    722 
    723 void loadBGRADataToBGRA(int width, int height, int depth,
    724                         const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
    725                         void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
    726 {
    727     const unsigned char *source = NULL;
    728     unsigned char *dest = NULL;
    729 
    730     for (int z = 0; z < depth; z++)
    731     {
    732         for (int y = 0; y < height; y++)
    733         {
    734             source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch);
    735             dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
    736             memcpy(dest, source, width*4);
    737         }
    738     }
    739 }
    740 
    741 void loadRGBA2101010ToNative(int width, int height, int depth,
    742                              const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
    743                              void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
    744 {
    745     const unsigned int *source = NULL;
    746     unsigned int *dest = NULL;
    747 
    748     for (int z = 0; z < depth; z++)
    749     {
    750         for (int y = 0; y < height; y++)
    751         {
    752             source = offsetDataPointer<unsigned int>(input, y, z, inputRowPitch, inputDepthPitch);
    753             dest = offsetDataPointer<unsigned int>(output, y, z, outputRowPitch, outputDepthPitch);
    754             memcpy(dest, source, width * sizeof(unsigned int));
    755         }
    756     }
    757 }
    758 
    759 void loadRGBA2101010ToRGBA(int width, int height, int depth,
    760                            const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
    761                            void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
    762 {
    763     const unsigned int *source = NULL;
    764     unsigned char *dest = NULL;
    765 
    766     for (int z = 0; z < depth; z++)
    767     {
    768         for (int y = 0; y < height; y++)
    769         {
    770             source = offsetDataPointer<unsigned int>(input, y, z, inputRowPitch, inputDepthPitch);
    771             dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
    772 
    773             for (int x = 0; x < width; x++)
    774             {
    775                 unsigned int rgba = source[x];
    776                 dest[4 * x + 0] = (rgba & 0x000003FF) >>  2;
    777                 dest[4 * x + 1] = (rgba & 0x000FFC00) >> 12;
    778                 dest[4 * x + 2] = (rgba & 0x3FF00000) >> 22;
    779                 dest[4 * x + 3] = ((rgba & 0xC0000000) >> 30) * 0x55;
    780             }
    781         }
    782     }
    783 }
    784 
    785 void loadRGBHalfFloatDataTo999E5(int width, int height, int depth,
    786                                  const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
    787                                  void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
    788 {
    789     const unsigned short *source = NULL;
    790     unsigned int *dest = NULL;
    791 
    792     for (int z = 0; z < depth; z++)
    793     {
    794         for (int y = 0; y < height; y++)
    795         {
    796             source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch);
    797             dest = offsetDataPointer<unsigned int>(output, y, z, outputRowPitch, outputDepthPitch);
    798 
    799             for (int x = 0; x < width; x++)
    800             {
    801                 dest[x] = gl::convertRGBFloatsTo999E5(gl::float16ToFloat32(source[x * 3 + 0]),
    802                                                       gl::float16ToFloat32(source[x * 3 + 1]),
    803                                                       gl::float16ToFloat32(source[x * 3 + 2]));
    804             }
    805         }
    806     }
    807 }
    808 
    809 void loadRGBFloatDataTo999E5(int width, int height, int depth,
    810                              const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
    811                              void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
    812 {
    813     const float *source = NULL;
    814     unsigned int *dest = NULL;
    815 
    816     for (int z = 0; z < depth; z++)
    817     {
    818         for (int y = 0; y < height; y++)
    819         {
    820             source = offsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch);
    821             dest = offsetDataPointer<unsigned int>(output, y, z, outputRowPitch, outputDepthPitch);
    822 
    823             for (int x = 0; x < width; x++)
    824             {
    825                 dest[x] = gl::convertRGBFloatsTo999E5(source[x * 3 + 0], source[x * 3 + 1], source[x * 3 + 2]);
    826             }
    827         }
    828     }
    829 }
    830 
    831 void loadRGBHalfFloatDataTo111110Float(int width, int height, int depth,
    832                                        const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
    833                                        void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
    834 {
    835     const unsigned short *source = NULL;
    836     unsigned int *dest = NULL;
    837 
    838     for (int z = 0; z < depth; z++)
    839     {
    840         for (int y = 0; y < height; y++)
    841         {
    842             source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch);
    843             dest = offsetDataPointer<unsigned int>(output, y, z, outputRowPitch, outputDepthPitch);
    844 
    845             for (int x = 0; x < width; x++)
    846             {
    847                 dest[x] = (gl::float32ToFloat11(gl::float16ToFloat32(source[x * 3 + 0])) <<  0) |
    848                           (gl::float32ToFloat11(gl::float16ToFloat32(source[x * 3 + 1])) << 11) |
    849                           (gl::float32ToFloat10(gl::float16ToFloat32(source[x * 3 + 2])) << 22);
    850             }
    851         }
    852     }
    853 }
    854 
    855 void loadRGBFloatDataTo111110Float(int width, int height, int depth,
    856                                    const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
    857                                    void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
    858 {
    859     const float *source = NULL;
    860     unsigned int *dest = NULL;
    861 
    862     for (int z = 0; z < depth; z++)
    863     {
    864         for (int y = 0; y < height; y++)
    865         {
    866             source = offsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch);
    867             dest = offsetDataPointer<unsigned int>(output, y, z, outputRowPitch, outputDepthPitch);
    868 
    869             for (int x = 0; x < width; x++)
    870             {
    871                 dest[x] = (gl::float32ToFloat11(source[x * 3 + 0]) <<  0) |
    872                           (gl::float32ToFloat11(source[x * 3 + 1]) << 11) |
    873                           (gl::float32ToFloat10(source[x * 3 + 2]) << 22);
    874             }
    875         }
    876     }
    877 }
    878 
    879 
    880 void loadG8R24DataToR24G8(int width, int height, int depth,
    881                           const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
    882                           void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
    883 {
    884     const unsigned int *source = NULL;
    885     unsigned int *dest = NULL;
    886 
    887     for (int z = 0; z < depth; z++)
    888     {
    889         for (int y = 0; y < height; y++)
    890         {
    891             source = offsetDataPointer<const unsigned int>(input, y, z, inputRowPitch, inputDepthPitch);
    892             dest = offsetDataPointer<unsigned int>(output, y, z, outputRowPitch, outputDepthPitch);
    893 
    894             for (int x = 0; x < width; x++)
    895             {
    896                 unsigned int d = source[x] >> 8;
    897                 unsigned int s = source[x] & 0xFF;
    898                 dest[x] = d | (s << 24);
    899             }
    900         }
    901     }
    902 }
    903 
    904 void loadFloatRGBDataToHalfFloatRGBA(int width, int height, int depth,
    905                                      const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
    906                                      void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
    907 {
    908     const float *source = NULL;
    909     unsigned short *dest = NULL;
    910 
    911     for (int z = 0; z < depth; z++)
    912     {
    913         for (int y = 0; y < height; y++)
    914         {
    915             source = offsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch);
    916             dest = offsetDataPointer<unsigned short>(output, y, z, outputRowPitch, outputDepthPitch);
    917 
    918             for (int x = 0; x < width; x++)
    919             {
    920                 dest[x * 4 + 0] = gl::float32ToFloat16(source[x * 3 + 0]);
    921                 dest[x * 4 + 1] = gl::float32ToFloat16(source[x * 3 + 1]);
    922                 dest[x * 4 + 2] = gl::float32ToFloat16(source[x * 3 + 2]);
    923                 dest[x * 4 + 3] = gl::Float16One;
    924             }
    925         }
    926     }
    927 }
    928 
    929 void loadUintDataToUshort(int width, int height, int depth,
    930                           const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
    931                           void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
    932 {
    933     const unsigned int *source = NULL;
    934     unsigned short *dest = NULL;
    935 
    936     for (int z = 0; z < depth; z++)
    937     {
    938         for (int y = 0; y < height; y++)
    939         {
    940             source = offsetDataPointer<unsigned int>(input, y, z, inputRowPitch, inputDepthPitch);
    941             dest = offsetDataPointer<unsigned short>(output, y, z, outputRowPitch, outputDepthPitch);
    942 
    943             for (int x = 0; x < width; x++)
    944             {
    945                 dest[x] = source[x] >> 16;
    946             }
    947         }
    948     }
    949 }
    950 
    951 }
    952