Skip to content
Permalink
Browse files
Ensure CA adjusts video color space consistently when drawing videos …
…to a canvas

https://bugs.webkit.org/show_bug.cgi?id=249446
rdar://88804270

Reviewed by Simon Fraser.

* Source/WebCore/PAL/pal/spi/cg/CoreGraphicsSPI.h:
* Source/WebCore/platform/graphics/cv/PixelBufferConformerCV.cpp:
(WebCore::PixelBufferConformerCV::imageFrom32BGRAPixelBuffer):

Canonical link: https://commits.webkit.org/258030@main
  • Loading branch information
heycam committed Dec 17, 2022
1 parent 90112a7 commit 07a9869a62aa3ddcaf190de43ee99e51de657040
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
@@ -290,6 +290,7 @@ void CGFontSetShouldUseMulticache(bool);

void CGImageSetCachingFlags(CGImageRef, CGImageCachingFlags);
CGImageCachingFlags CGImageGetCachingFlags(CGImageRef);
void CGImageSetProperty(CGImageRef, CFStringRef, CFTypeRef);

CGDataProviderRef CGPDFDocumentGetDataProvider(CGPDFDocumentRef);

@@ -30,6 +30,7 @@
#include "GraphicsContextCG.h"
#include "ImageBufferUtilitiesCG.h"
#include "Logging.h"
#include <pal/spi/cg/CoreGraphicsSPI.h>

#include "CoreVideoSoftLink.h"
#include "VideoToolboxSoftLink.h"
@@ -186,7 +187,18 @@ RetainPtr<CGImageRef> PixelBufferConformerCV::imageFrom32BGRAPixelBuffer(RetainP
CGDataProviderDirectCallbacks providerCallbacks = { 0, CVPixelBufferGetBytePointerCallback, CVPixelBufferReleaseBytePointerCallback, 0, CVPixelBufferReleaseInfoCallback };
RetainPtr<CGDataProviderRef> provider = adoptCF(CGDataProviderCreateDirect(info, byteLength, &providerCallbacks));

return adoptCF(CGImageCreate(width, height, 8, 32, bytesPerRow, colorSpace, bitmapInfo, provider.get(), nullptr, false, kCGRenderingIntentDefault));
RetainPtr<CGImageRef> image = adoptCF(CGImageCreate(width, height, 8, 32, bytesPerRow, colorSpace, bitmapInfo, provider.get(), nullptr, false, kCGRenderingIntentDefault));

// For historical reasons, CoreAnimation will adjust certain video color
// spaces when displaying the video. If the video frame derived image we
// create here is drawn to an accelerated image buffer (e.g. for a canvas),
// CA may not do this same adjustment, resulting in the canvas pixels not
// matching the source video. Setting this CGImage property (despite the
// image not being IOSurface backed), avoids this non-adjustment of the
// image color space. <rdar://88804270>
CGImageSetProperty(image.get(), CFSTR("CA_IOSURFACE_IMAGE"), kCFBooleanTrue);

return image;
}

}

0 comments on commit 07a9869

Please sign in to comment.