tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

copyimage.cpp (2235B)


      1 //
      2 // Copyright 2013 The ANGLE Project Authors. All rights reserved.
      3 // Use of this source code is governed by a BSD-style license that can be
      4 // found in the LICENSE file.
      5 //
      6 
      7 // copyimage.cpp: Defines image copying functions
      8 
      9 #include "image_util/copyimage.h"
     10 
     11 namespace angle
     12 {
     13 
     14 namespace
     15 {
     16 inline uint32_t SwizzleBGRAToRGBA(uint32_t argb)
     17 {
     18    return ((argb & 0x000000FF) << 16) |  // Move BGRA blue to RGBA blue
     19           ((argb & 0x00FF0000) >> 16) |  // Move BGRA red to RGBA red
     20           ((argb & 0xFF00FF00));         // Keep alpha and green
     21 }
     22 
     23 void CopyBGRA8ToRGBA8Fast(const uint8_t *source,
     24                          int srcYAxisPitch,
     25                          uint8_t *dest,
     26                          int destYAxisPitch,
     27                          int destWidth,
     28                          int destHeight)
     29 {
     30    for (int y = 0; y < destHeight; ++y)
     31    {
     32        const uint32_t *src32 = reinterpret_cast<const uint32_t *>(source + y * srcYAxisPitch);
     33        uint32_t *dest32      = reinterpret_cast<uint32_t *>(dest + y * destYAxisPitch);
     34        const uint32_t *end32 = src32 + destWidth;
     35        while (src32 != end32)
     36        {
     37            *dest32++ = SwizzleBGRAToRGBA(*src32++);
     38        }
     39    }
     40 }
     41 }  // namespace
     42 
     43 void CopyBGRA8ToRGBA8(const uint8_t *source,
     44                      int srcXAxisPitch,
     45                      int srcYAxisPitch,
     46                      uint8_t *dest,
     47                      int destXAxisPitch,
     48                      int destYAxisPitch,
     49                      int destWidth,
     50                      int destHeight)
     51 {
     52    if (srcXAxisPitch == 4 && destXAxisPitch == 4)
     53    {
     54        CopyBGRA8ToRGBA8Fast(source, srcYAxisPitch, dest, destYAxisPitch, destWidth, destHeight);
     55        return;
     56    }
     57 
     58    for (int y = 0; y < destHeight; ++y)
     59    {
     60        uint8_t *dst       = dest + y * destYAxisPitch;
     61        const uint8_t *src = source + y * srcYAxisPitch;
     62        const uint8_t *end = src + destWidth * srcXAxisPitch;
     63 
     64        while (src != end)
     65        {
     66            *reinterpret_cast<uint32_t *>(dst) =
     67                SwizzleBGRAToRGBA(*reinterpret_cast<const uint32_t *>(src));
     68            src += srcXAxisPitch;
     69            dst += destXAxisPitch;
     70        }
     71    }
     72 }
     73 
     74 }  // namespace angle