⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 277369 in webkit


Ignore:
Timestamp:
May 12, 2021, 7:51:31 AM (5 years ago)
Author:
weinig@apple.com
Message:

Factor copyImagePixels pixel conversion code into its own file
https://bugs.webkit.org/show_bug.cgi?id=225673

Reviewed by Darin Adler.

Removes virtual ImageBufferBackend::copyImagePixels() function and
moves functionality to new PixelBufferConversion.h/cpp.

Merge USE(ACCELERATE) code from ImageBufferCGBackend into the same
file and do some light cleanup.

  • Function renamed to covert convertImagePixels to convey that it is doing more than copying.
  • Add PixelBufferConversionView/ConstPixelBufferConversionView structs to hold parameters for the conversions, including a ColorSpace member that is not yet used but will be shortly.
  • Uses constexpr conditionals in unaccelerated cases to hoist branch checking for pixel format conversion requirements outside the main loop.
  • Sources.txt:
  • WebCore.xcodeproj/project.pbxproj:

Add new files.

  • platform/graphics/PixelBufferConversion.cpp: Added.

(WebCore::makeVImageBuffer):
(WebCore::convertImagePixelsAccelerated):
(WebCore::convertSinglePixelPremultipliedToPremultiplied):
(WebCore::convertSinglePixelPremultipliedToUnpremultiplied):
(WebCore::convertSinglePixelUnpremultipliedToPremultiplied):
(WebCore::convertSinglePixelUnpremultipliedToUnpremultiplied):
(WebCore::convertFunctor):
(WebCore::convertImagePixels):

  • platform/graphics/PixelBufferConversion.h: Added.

Move existing copyImagePixels implementations here.

  • platform/graphics/ImageBufferBackend.cpp:

(WebCore::ImageBufferBackend::toBGRAData const):
(WebCore::ImageBufferBackend::getPixelBuffer const):
(WebCore::ImageBufferBackend::putPixelBuffer):
(WebCore::copyPremultipliedToPremultiplied): Deleted.
(WebCore::copyPremultipliedToUnpremultiplied): Deleted.
(WebCore::copyUnpremultipliedToPremultiplied): Deleted.
(WebCore::copyUnpremultipliedToUnpremultiplied): Deleted.
(WebCore::copyFunctor): Deleted.
(WebCore::ImageBufferBackend::copyImagePixels const): Deleted.

  • platform/graphics/ImageBufferBackend.h:
  • platform/graphics/cg/ImageBufferCGBackend.cpp:

(WebCore::makeVImageBuffer): Deleted.
(WebCore::copyImagePixelsAccelerated): Deleted.
(WebCore::ImageBufferCGBackend::copyImagePixels const): Deleted.

  • platform/graphics/cg/ImageBufferCGBackend.h:

Remove existing copyImagePixels() implementation and call new
convertImagePixels() instead.

  • platform/graphics/filters/FilterEffect.cpp:

(WebCore::FilterEffect::copyUnmultipliedResult):
(WebCore::FilterEffect::copyPremultipliedResult):
(WebCore::FilterEffect::createUnmultipliedImageResult):
(WebCore::FilterEffect::createPremultipliedImageResult):
Fix pixel format for the PixelBuffers to match existing behaviors.
These are not being used at the moment but will in the future
and new assert in putPixelBuffer caught these being incorrect.

Location:
trunk/Source/WebCore
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r277367 r277369  
     12021-05-12  Sam Weinig  <weinig@apple.com>
     2
     3        Factor copyImagePixels pixel conversion code into its own file
     4        https://bugs.webkit.org/show_bug.cgi?id=225673
     5
     6        Reviewed by Darin Adler.
     7
     8        Removes virtual ImageBufferBackend::copyImagePixels() function and
     9        moves functionality to new PixelBufferConversion.h/cpp.
     10
     11        Merge USE(ACCELERATE) code from ImageBufferCGBackend into the same
     12        file and do some light cleanup.
     13       
     14        - Function renamed to covert convertImagePixels to convey that it is
     15          doing more than copying.
     16        - Add PixelBufferConversionView/ConstPixelBufferConversionView structs
     17          to hold parameters for the conversions, including a ColorSpace member
     18          that is not yet used but will be shortly.
     19        - Uses constexpr conditionals in unaccelerated cases to hoist branch
     20          checking for pixel format conversion requirements outside the main
     21          loop.
     22
     23        * Sources.txt:
     24        * WebCore.xcodeproj/project.pbxproj:
     25        Add new files.
     26
     27        * platform/graphics/PixelBufferConversion.cpp: Added.
     28        (WebCore::makeVImageBuffer):
     29        (WebCore::convertImagePixelsAccelerated):
     30        (WebCore::convertSinglePixelPremultipliedToPremultiplied):
     31        (WebCore::convertSinglePixelPremultipliedToUnpremultiplied):
     32        (WebCore::convertSinglePixelUnpremultipliedToPremultiplied):
     33        (WebCore::convertSinglePixelUnpremultipliedToUnpremultiplied):
     34        (WebCore::convertFunctor):
     35        (WebCore::convertImagePixels):
     36        * platform/graphics/PixelBufferConversion.h: Added.
     37        Move existing copyImagePixels implementations here.
     38
     39        * platform/graphics/ImageBufferBackend.cpp:
     40        (WebCore::ImageBufferBackend::toBGRAData const):
     41        (WebCore::ImageBufferBackend::getPixelBuffer const):
     42        (WebCore::ImageBufferBackend::putPixelBuffer):
     43        (WebCore::copyPremultipliedToPremultiplied): Deleted.
     44        (WebCore::copyPremultipliedToUnpremultiplied): Deleted.
     45        (WebCore::copyUnpremultipliedToPremultiplied): Deleted.
     46        (WebCore::copyUnpremultipliedToUnpremultiplied): Deleted.
     47        (WebCore::copyFunctor): Deleted.
     48        (WebCore::ImageBufferBackend::copyImagePixels const): Deleted.
     49        * platform/graphics/ImageBufferBackend.h:
     50        * platform/graphics/cg/ImageBufferCGBackend.cpp:
     51        (WebCore::makeVImageBuffer): Deleted.
     52        (WebCore::copyImagePixelsAccelerated): Deleted.
     53        (WebCore::ImageBufferCGBackend::copyImagePixels const): Deleted.
     54        * platform/graphics/cg/ImageBufferCGBackend.h:
     55        Remove existing copyImagePixels() implementation and call new
     56        convertImagePixels() instead.
     57       
     58        * platform/graphics/filters/FilterEffect.cpp:
     59        (WebCore::FilterEffect::copyUnmultipliedResult):
     60        (WebCore::FilterEffect::copyPremultipliedResult):
     61        (WebCore::FilterEffect::createUnmultipliedImageResult):
     62        (WebCore::FilterEffect::createPremultipliedImageResult):
     63        Fix pixel format for the PixelBuffers to match existing behaviors.
     64        These are not being used at the moment but will in the future
     65        and new assert in putPixelBuffer caught these being incorrect.
     66
    1672021-05-12  Commit Queue  <commit-queue@webkit.org>
    268
  • trunk/Source/WebCore/Sources.txt

    r277245 r277369  
    20142014platform/graphics/Pattern.cpp
    20152015platform/graphics/PixelBuffer.cpp
     2016platform/graphics/PixelBufferConversion.cpp
    20162017platform/graphics/PlatformTimeRanges.cpp
    20172018platform/graphics/Region.cpp
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r277364 r277369  
    1409314093                BC06F24D06D18A7E004A6FA3 /* XSLTProcessorLibxslt.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.cpp; path = XSLTProcessorLibxslt.cpp; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
    1409414094                BC073BA90C399B1F000F5979 /* FloatConversion.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = FloatConversion.h; sourceTree = "<group>"; };
     14095                BC0CA74C264AED0A004FDC62 /* PixelBufferConversion.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PixelBufferConversion.h; sourceTree = "<group>"; };
     14096                BC0CA74D264AED0A004FDC62 /* PixelBufferConversion.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = PixelBufferConversion.cpp; sourceTree = "<group>"; };
    1409514097                BC10137B25C3624B00DC773C /* ColorModels.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ColorModels.h; sourceTree = "<group>"; };
    1409614098                BC10137E25C3631600DC773C /* ColorTransferFunctions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ColorTransferFunctions.h; sourceTree = "<group>"; };
     
    2705427056                                BC4839BB2646181A00A28B62 /* PixelBuffer.cpp */,
    2705527057                                BC4839BA2646181A00A28B62 /* PixelBuffer.h */,
     27058                                BC0CA74D264AED0A004FDC62 /* PixelBufferConversion.cpp */,
     27059                                BC0CA74C264AED0A004FDC62 /* PixelBufferConversion.h */,
    2705627060                                BCA55912263DBD79007F19B3 /* PixelFormat.h */,
    2705727061                                726D56E1253AE0430002EF90 /* PlatformImage.h */,
  • trunk/Source/WebCore/platform/graphics/ImageBufferBackend.cpp

    r277313 r277369  
    2929#include "Image.h"
    3030#include "PixelBuffer.h"
     31#include "PixelBufferConversion.h"
    3132
    3233namespace WebCore {
     
    9495{
    9596    Vector<uint8_t> result(4 * logicalSize().area().unsafeGet());
    96     size_t destinationBytesPerRow = logicalSize().width() * 4;
    97     size_t sourceBytesPerRow = bytesPerRow();
    98 
    99     uint8_t* sourceRows = reinterpret_cast<uint8_t*>(data);
    100 
    101     copyImagePixels(
    102         AlphaPremultiplication::Premultiplied, pixelFormat(), sourceBytesPerRow, sourceRows,
    103         AlphaPremultiplication::Unpremultiplied, PixelFormat::BGRA8, destinationBytesPerRow, result.data(), logicalSize());
     97
     98    ConstPixelBufferConversionView source;
     99    source.alphaFormat = AlphaPremultiplication::Premultiplied;
     100    source.colorSpace = DestinationColorSpace::SRGB;
     101    source.pixelFormat = pixelFormat();
     102    source.bytesPerRow = bytesPerRow();
     103    source.rows = reinterpret_cast<const uint8_t*>(data);
     104   
     105    PixelBufferConversionView destination;
     106    destination.alphaFormat = AlphaPremultiplication::Unpremultiplied;
     107    destination.colorSpace = DestinationColorSpace::SRGB;
     108    destination.pixelFormat = PixelFormat::BGRA8;
     109    destination.bytesPerRow = logicalSize().width() * 4;
     110    destination.rows = result.data();
     111
     112    convertImagePixels(source, destination, logicalSize());
    104113
    105114    return result;
    106115}
    107116
    108 static inline void copyPremultipliedToPremultiplied(PixelFormat sourcePixelFormat, const uint8_t* sourcePixel, PixelFormat destinationPixelFormat, uint8_t* destinationPixel)
    109 {
    110     uint8_t alpha = sourcePixel[3];
    111     if (!alpha) {
    112         reinterpret_cast<uint32_t*>(destinationPixel)[0] = 0;
    113         return;
    114     }
    115 
    116     if (sourcePixelFormat == destinationPixelFormat) {
    117         reinterpret_cast<uint32_t*>(destinationPixel)[0] = reinterpret_cast<const uint32_t*>(sourcePixel)[0];
    118         return;
    119     }
    120 
    121     // Swap pixel channels BGRA <-> RGBA.
    122     destinationPixel[0] = sourcePixel[2];
    123     destinationPixel[1] = sourcePixel[1];
    124     destinationPixel[2] = sourcePixel[0];
    125     destinationPixel[3] = sourcePixel[3];
    126 }
    127 
    128 static inline void copyPremultipliedToUnpremultiplied(PixelFormat sourcePixelFormat, const uint8_t* sourcePixel, PixelFormat destinationPixelFormat, uint8_t* destinationPixel)
    129 {
    130     uint8_t alpha = sourcePixel[3];
    131     if (!alpha || alpha == 255) {
    132         copyPremultipliedToPremultiplied(sourcePixelFormat, sourcePixel, destinationPixelFormat, destinationPixel);
    133         return;
    134     }
    135 
    136     if (sourcePixelFormat == destinationPixelFormat) {
    137         destinationPixel[0] = (sourcePixel[0] * 255) / alpha;
    138         destinationPixel[1] = (sourcePixel[1] * 255) / alpha;
    139         destinationPixel[2] = (sourcePixel[2] * 255) / alpha;
    140         destinationPixel[3] = alpha;
    141         return;
    142     }
    143 
    144     // Swap pixel channels BGRA <-> RGBA.
    145     destinationPixel[0] = (sourcePixel[2] * 255) / alpha;
    146     destinationPixel[1] = (sourcePixel[1] * 255) / alpha;
    147     destinationPixel[2] = (sourcePixel[0] * 255) / alpha;
    148     destinationPixel[3] = alpha;
    149 }
    150 
    151 static inline void copyUnpremultipliedToPremultiplied(PixelFormat sourcePixelFormat, const uint8_t* sourcePixel, PixelFormat destinationPixelFormat, uint8_t* destinationPixel)
    152 {
    153     uint8_t alpha = sourcePixel[3];
    154     if (!alpha || alpha == 255) {
    155         copyPremultipliedToPremultiplied(sourcePixelFormat, sourcePixel, destinationPixelFormat, destinationPixel);
    156         return;
    157     }
    158 
    159     if (sourcePixelFormat == destinationPixelFormat) {
    160         destinationPixel[0] = (sourcePixel[0] * alpha + 254) / 255;
    161         destinationPixel[1] = (sourcePixel[1] * alpha + 254) / 255;
    162         destinationPixel[2] = (sourcePixel[2] * alpha + 254) / 255;
    163         destinationPixel[3] = alpha;
    164         return;
    165     }
    166 
    167     // Swap pixel channels BGRA <-> RGBA.
    168     destinationPixel[0] = (sourcePixel[2] * alpha + 254) / 255;
    169     destinationPixel[1] = (sourcePixel[1] * alpha + 254) / 255;
    170     destinationPixel[2] = (sourcePixel[0] * alpha + 254) / 255;
    171     destinationPixel[3] = alpha;
    172 }
    173 
    174 static inline void copyUnpremultipliedToUnpremultiplied(PixelFormat sourcePixelFormat, const uint8_t* sourcePixel, PixelFormat destinationPixelFormat, uint8_t* destinationPixel)
    175 {
    176     if (sourcePixelFormat == destinationPixelFormat) {
    177         reinterpret_cast<uint32_t*>(destinationPixel)[0] = reinterpret_cast<const uint32_t*>(sourcePixel)[0];
    178         return;
    179     }
    180 
    181     // Swap pixel channels BGRA <-> RGBA.
    182     destinationPixel[0] = sourcePixel[2];
    183     destinationPixel[1] = sourcePixel[1];
    184     destinationPixel[2] = sourcePixel[0];
    185     destinationPixel[3] = sourcePixel[3];
    186 }
    187 
    188 template<void (*copyFunctor)(PixelFormat, const uint8_t*, PixelFormat, uint8_t*)>
    189 static inline void copyImagePixelsUnaccelerated(
    190     PixelFormat sourcePixelFormat, unsigned sourceBytesPerRow, uint8_t* sourceRows,
    191     PixelFormat destinationPixelFormat, unsigned destinationBytesPerRow, uint8_t* destinationRows, const IntSize& size)
    192 {
    193     size_t bytesPerRow = size.width() * 4;
    194     for (int y = 0; y < size.height(); ++y) {
    195         for (size_t x = 0; x < bytesPerRow; x += 4)
    196             copyFunctor(sourcePixelFormat, &sourceRows[x], destinationPixelFormat, &destinationRows[x]);
    197         sourceRows += sourceBytesPerRow;
    198         destinationRows += destinationBytesPerRow;
    199     }
    200 }
    201 
    202 void ImageBufferBackend::copyImagePixels(
    203     AlphaPremultiplication sourceAlphaFormat, PixelFormat sourcePixelFormat, unsigned sourceBytesPerRow, uint8_t* sourceRows,
    204     AlphaPremultiplication destinationAlphaFormat, PixelFormat destinationPixelFormat, unsigned destinationBytesPerRow, uint8_t* destinationRows, const IntSize& size) const
    205 {
    206     // We don't currently support getting or putting pixel data with deep color buffers.
    207     ASSERT(sourcePixelFormat == PixelFormat::RGBA8 || sourcePixelFormat == PixelFormat::BGRA8);
    208     ASSERT(destinationPixelFormat == PixelFormat::RGBA8 || destinationPixelFormat == PixelFormat::BGRA8);
    209 
    210     if (sourceAlphaFormat == destinationAlphaFormat) {
    211         if (sourceAlphaFormat == AlphaPremultiplication::Premultiplied)
    212             copyImagePixelsUnaccelerated<copyPremultipliedToPremultiplied>(sourcePixelFormat, sourceBytesPerRow, sourceRows, destinationPixelFormat, destinationBytesPerRow, destinationRows, size);
    213         else
    214             copyImagePixelsUnaccelerated<copyUnpremultipliedToUnpremultiplied>(sourcePixelFormat, sourceBytesPerRow, sourceRows, destinationPixelFormat, destinationBytesPerRow, destinationRows, size);
    215         return;
    216     }
    217 
    218     if (destinationAlphaFormat == AlphaPremultiplication::Unpremultiplied) {
    219         copyImagePixelsUnaccelerated<copyPremultipliedToUnpremultiplied>(sourcePixelFormat, sourceBytesPerRow, sourceRows, destinationPixelFormat, destinationBytesPerRow, destinationRows, size);
    220         return;
    221     }
    222 
    223     copyImagePixelsUnaccelerated<copyUnpremultipliedToPremultiplied>(sourcePixelFormat, sourceBytesPerRow, sourceRows, destinationPixelFormat, destinationBytesPerRow, destinationRows, size);
    224 }
    225 
    226117Optional<PixelBuffer> ImageBufferBackend::getPixelBuffer(AlphaPremultiplication destinationAlphaFormat, const IntRect& sourceRect, void* data) const
    227118{
    228119    auto sourceRectScaled = toBackendCoordinates(sourceRect);
    229120
    230     auto pixelBuffer = PixelBuffer::tryCreate(DestinationColorSpace::SRGB, PixelFormat::RGBA8, sourceRectScaled.size());
     121    auto destinationPixelFormat = PixelFormat::RGBA8;
     122
     123    auto pixelBuffer = PixelBuffer::tryCreate(DestinationColorSpace::SRGB, destinationPixelFormat, sourceRectScaled.size());
    231124    if (!pixelBuffer)
    232125        return WTF::nullopt;
     
    244137        pixelBuffer->data().zeroFill();
    245138
     139    unsigned sourceBytesPerRow = bytesPerRow();
     140    const uint8_t* sourceRows = reinterpret_cast<uint8_t*>(data) + sourceRectClipped.y() * sourceBytesPerRow + sourceRectClipped.x() * 4;
     141
    246142    unsigned destinationBytesPerRow = 4 * sourceRectScaled.width();
    247143    uint8_t* destinationRows = pixelBuffer->data().data() + destinationRect.y() * destinationBytesPerRow + destinationRect.x() * 4;
    248144
    249     unsigned sourceBytesPerRow = bytesPerRow();
    250     uint8_t* sourceRows = reinterpret_cast<uint8_t*>(data) + sourceRectClipped.y() * sourceBytesPerRow + sourceRectClipped.x() * 4;
    251 
    252     copyImagePixels(
    253         AlphaPremultiplication::Premultiplied, pixelFormat(), sourceBytesPerRow, sourceRows,
    254         destinationAlphaFormat, PixelFormat::RGBA8, destinationBytesPerRow, destinationRows, destinationRect.size());
     145    ConstPixelBufferConversionView source;
     146    source.alphaFormat = AlphaPremultiplication::Premultiplied;
     147    source.colorSpace = DestinationColorSpace::SRGB;
     148    source.pixelFormat = pixelFormat();
     149    source.bytesPerRow = sourceBytesPerRow;
     150    source.rows = sourceRows;
     151   
     152    PixelBufferConversionView destination;
     153    destination.alphaFormat = destinationAlphaFormat;
     154    destination.colorSpace = DestinationColorSpace::SRGB;
     155    destination.pixelFormat = destinationPixelFormat;
     156    destination.bytesPerRow = destinationBytesPerRow;
     157    destination.rows = destinationRows;
     158
     159    convertImagePixels(source, destination, destinationRect.size());
    255160
    256161    return pixelBuffer;
     
    259164void ImageBufferBackend::putPixelBuffer(AlphaPremultiplication sourceAlphaFormat, const PixelBuffer& pixelBuffer, const IntRect& sourceRect, const IntPoint& destinationPoint, AlphaPremultiplication destinationAlphaFormat, void* data)
    260165{
     166    // FIXME: Add support for non-RGBA8 pixel formats.
     167    ASSERT(pixelBuffer.format() == PixelFormat::RGBA8);
     168
    261169    auto sourceRectScaled = toBackendCoordinates(sourceRect);
    262170    auto destinationPointScaled = toBackendCoordinates(destinationPoint);
     
    275183    sourceRectClipped.setSize(destinationRect.size());
    276184
     185    unsigned sourceBytesPerRow = 4 * pixelBuffer.size().width();
     186    const uint8_t* sourceRows = pixelBuffer.data().data() + sourceRectClipped.y() * sourceBytesPerRow + sourceRectClipped.x() * 4;
     187
    277188    unsigned destinationBytesPerRow = bytesPerRow();
    278189    uint8_t* destinationRows = reinterpret_cast<uint8_t*>(data) + destinationRect.y() * destinationBytesPerRow + destinationRect.x() * 4;
    279190
    280     unsigned sourceBytesPerRow = 4 * pixelBuffer.size().width();
    281     uint8_t* sourceRows = pixelBuffer.data().data() + sourceRectClipped.y() * sourceBytesPerRow + sourceRectClipped.x() * 4;
    282 
    283     copyImagePixels(
    284         sourceAlphaFormat, PixelFormat::RGBA8, sourceBytesPerRow, sourceRows,
    285         destinationAlphaFormat, pixelFormat(), destinationBytesPerRow, destinationRows, destinationRect.size());
     191    ConstPixelBufferConversionView source;
     192    source.alphaFormat = sourceAlphaFormat;
     193    source.colorSpace = DestinationColorSpace::SRGB;
     194    source.pixelFormat = PixelFormat::RGBA8;
     195    source.bytesPerRow = sourceBytesPerRow;
     196    source.rows = sourceRows;
     197   
     198    PixelBufferConversionView destination;
     199    destination.alphaFormat = destinationAlphaFormat;
     200    destination.colorSpace = DestinationColorSpace::SRGB;
     201    destination.pixelFormat = pixelFormat();
     202    destination.bytesPerRow = destinationBytesPerRow;
     203    destination.rows = destinationRows;
     204
     205    convertImagePixels(source, destination, destinationRect.size());
    286206}
    287207
  • trunk/Source/WebCore/platform/graphics/ImageBufferBackend.h

    r277313 r277369  
    149149    IntRect backendRect() const { return IntRect(IntPoint::zero(), backendSize()); };
    150150
    151     WEBCORE_EXPORT virtual void copyImagePixels(
    152         AlphaPremultiplication srcAlphaFormat, PixelFormat srcPixelFormat, unsigned srcBytesPerRow, uint8_t* srcRows,
    153         AlphaPremultiplication destAlphaFormat, PixelFormat destPixelFormat, unsigned destBytesPerRow, uint8_t* destRows, const IntSize&) const;
    154 
    155151    WEBCORE_EXPORT Vector<uint8_t> toBGRAData(void* data) const;
    156152
  • trunk/Source/WebCore/platform/graphics/cg/ImageBufferCGBackend.cpp

    r277313 r277369  
    3636#include "PixelBuffer.h"
    3737#include "RuntimeApplicationChecks.h"
    38 
    39 #if USE(ACCELERATE)
    40 #include <Accelerate/Accelerate.h>
    41 #endif
    4238#include <CoreGraphics/CoreGraphics.h>
    4339#include <pal/spi/cg/CoreGraphicsSPI.h>
     
    251247}
    252248
    253 #if USE(ACCELERATE)
    254 static inline vImage_Buffer makeVImageBuffer(unsigned bytesPerRow, uint8_t* rows, const IntSize& size)
    255 {
    256     vImage_Buffer vImageBuffer;
    257 
    258     vImageBuffer.height = static_cast<vImagePixelCount>(size.height());
    259     vImageBuffer.width = static_cast<vImagePixelCount>(size.width());
    260     vImageBuffer.rowBytes = bytesPerRow;
    261     vImageBuffer.data = rows;
    262     return vImageBuffer;
    263 }
    264 
    265 static inline void copyImagePixelsAccelerated(
    266     AlphaPremultiplication srcAlphaFormat, PixelFormat srcPixelFormat, vImage_Buffer& src,
    267     AlphaPremultiplication destAlphaFormat, PixelFormat destPixelFormat, vImage_Buffer& dest)
    268 {
    269     if (srcAlphaFormat == destAlphaFormat) {
    270         ASSERT(srcPixelFormat != destPixelFormat);
    271         // The destination alpha format can be unpremultiplied in the
    272         // case of an ImageBitmap created from an ImageData with
    273         // premultiplyAlpha=="none".
    274 
    275         // Swap pixel channels BGRA <-> RGBA.
    276         const uint8_t map[4] = { 2, 1, 0, 3 };
    277         vImagePermuteChannels_ARGB8888(&src, &dest, map, kvImageNoFlags);
    278         return;
    279     }
    280 
    281     if (destAlphaFormat == AlphaPremultiplication::Unpremultiplied) {
    282         if (srcPixelFormat == PixelFormat::RGBA8)
    283             vImageUnpremultiplyData_RGBA8888(&src, &dest, kvImageNoFlags);
    284         else
    285             vImageUnpremultiplyData_BGRA8888(&src, &dest, kvImageNoFlags);
    286     } else {
    287         if (srcPixelFormat == PixelFormat::RGBA8)
    288             vImagePremultiplyData_RGBA8888(&src, &dest, kvImageNoFlags);
    289         else
    290             vImagePremultiplyData_BGRA8888(&src, &dest, kvImageNoFlags);
    291     }
    292 
    293     if (srcPixelFormat != destPixelFormat) {
    294         // Swap pixel channels BGRA <-> RGBA.
    295         const uint8_t map[4] = { 2, 1, 0, 3 };
    296         vImagePermuteChannels_ARGB8888(&dest, &dest, map, kvImageNoFlags);
    297     }
    298 }
    299 
    300 void ImageBufferCGBackend::copyImagePixels(
    301     AlphaPremultiplication srcAlphaFormat, PixelFormat srcPixelFormat, unsigned srcBytesPerRow, uint8_t* srcRows,
    302     AlphaPremultiplication destAlphaFormat, PixelFormat destPixelFormat, unsigned destBytesPerRow, uint8_t* destRows, const IntSize& size) const
    303 {
    304     // We don't currently support getting or putting pixel data with deep color buffers.
    305     ASSERT(srcPixelFormat == PixelFormat::RGBA8 || srcPixelFormat == PixelFormat::BGRA8);
    306     ASSERT(destPixelFormat == PixelFormat::RGBA8 || destPixelFormat == PixelFormat::BGRA8);
    307 
    308     if (srcAlphaFormat == destAlphaFormat && srcPixelFormat == destPixelFormat) {
    309         ImageBufferBackend::copyImagePixels(srcAlphaFormat, srcPixelFormat, srcBytesPerRow, srcRows, destAlphaFormat, destPixelFormat, destBytesPerRow, destRows, size);
    310         return;
    311     }
    312 
    313     vImage_Buffer src = makeVImageBuffer(srcBytesPerRow, srcRows, size);
    314     vImage_Buffer dest = makeVImageBuffer(destBytesPerRow, destRows, size);
    315 
    316     copyImagePixelsAccelerated(srcAlphaFormat, srcPixelFormat, src, destAlphaFormat, destPixelFormat, dest);
    317 }
    318 #endif
    319 
    320249} // namespace WebCore
    321250
  • trunk/Source/WebCore/platform/graphics/cg/ImageBufferCGBackend.h

    r275905 r277369  
    5555    void setupContext() const;
    5656    virtual RetainPtr<CFDataRef> toCFData(const String& mimeType, Optional<double> quality, PreserveResolution) const;
    57 
    58 #if USE(ACCELERATE)
    59     void copyImagePixels(
    60         AlphaPremultiplication srcAlphaFormat, PixelFormat srcPixelFormat, unsigned srcBytesPerRow, uint8_t* srcRows,
    61         AlphaPremultiplication destAlphaFormat, PixelFormat destPixelFormat, unsigned destBytesPerRow, uint8_t* destRows, const IntSize&) const override;
    62 #endif
    6357};
    6458
  • trunk/Source/WebCore/platform/graphics/filters/FilterEffect.cpp

    r277313 r277369  
    506506            ASSERT(!ImageBuffer::sizeNeedsClamping(inputSize));
    507507            inputSize.scale(m_filter.filterScale());
    508             m_unmultipliedImageResult = PixelBuffer::tryCreate(DestinationColorSpace::SRGB, PixelFormat::BGRA8, inputSize);
     508            m_unmultipliedImageResult = PixelBuffer::tryCreate(DestinationColorSpace::SRGB, PixelFormat::RGBA8, inputSize);
    509509            if (!m_unmultipliedImageResult)
    510510                return;
     
    539539            ASSERT(!ImageBuffer::sizeNeedsClamping(inputSize));
    540540            inputSize.scale(m_filter.filterScale());
    541             m_premultipliedImageResult = PixelBuffer::tryCreate(DestinationColorSpace::SRGB, PixelFormat::BGRA8, inputSize);
     541            m_premultipliedImageResult = PixelBuffer::tryCreate(DestinationColorSpace::SRGB, PixelFormat::RGBA8, inputSize);
    542542            if (!m_premultipliedImageResult)
    543543                return;
     
    581581    ASSERT(!ImageBuffer::sizeNeedsClamping(resultSize));
    582582    resultSize.scale(m_filter.filterScale());
    583     m_unmultipliedImageResult = PixelBuffer::tryCreate(DestinationColorSpace::SRGB, PixelFormat::BGRA8, resultSize);
     583    m_unmultipliedImageResult = PixelBuffer::tryCreate(DestinationColorSpace::SRGB, PixelFormat::RGBA8, resultSize);
    584584    return m_unmultipliedImageResult;
    585585}
     
    599599    ASSERT(!ImageBuffer::sizeNeedsClamping(resultSize));
    600600    resultSize.scale(m_filter.filterScale());
    601     m_premultipliedImageResult = PixelBuffer::tryCreate(DestinationColorSpace::SRGB, PixelFormat::BGRA8, resultSize);
     601    m_premultipliedImageResult = PixelBuffer::tryCreate(DestinationColorSpace::SRGB, PixelFormat::RGBA8, resultSize);
    602602    return m_premultipliedImageResult;
    603603}
Note: See TracChangeset for help on using the changeset viewer.