webrtc/sdk/objc/Framework/Classes/Video
David Porter 25cc8ad198 Fixed issue with BGRA RTCCVPixelBuffer scale and crop
BGRA RTCCVPixelBuffers were cropped and scaled incorrectly. Libyuv’s
`ARGBScale` method is used in RTCCVPixelBuffer to scale and crop the
pixel buffer. To crop by `cropX` and `cropY` pixels, pointer
arithmetic is used to offset the src pointer of the original pixel
buffer bytes. There is a bug in how this offset is calculated.

The offset is done by `src += srcStride * _cropY + _cropX`. Libyuv
expects that the src pointer will point to the start of a new pixel.
However, if _cropX is a not a multiple of 4 (4 bytes for BGRA), the src
pointer will point to a byte in the middle of a pixel and thus libyuv
will incorrectly treat the data as the start of pixel (incorrectly
treating the first byte as red when it is actually green, etc...). To
fix this, the src pointer needs to be offset to always point to the
start of a new pixel.

Before this change:

Original Test Gradient image with a cropX of 2:
https://i.imgur.com/gSIgwGV.jpg

Scaled image (notice the colors are incorrect):
https://i.imgur.com/oPxbTEK.jpg

After this change:

Scaled image (notice the colors are correct):
https://i.imgur.com/dqBsmsH.jpg

A new unit test which tests scaling with cropX and cropY values has been
added. The test fails without this change and now passes with the
correct src pointer offsetting.

Bug: webrtc:9555
Change-Id: I87cbd7b91bc139d51fb4e11cc50ccb014cfa8051
Reviewed-on: https://webrtc-review.googlesource.com/89220
Commit-Queue: Kári Helgason <kthelgason@webrtc.org>
Reviewed-by: Kári Helgason <kthelgason@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#24076}
2018-07-24 08:23:26 +00:00
..
AVCaptureSession+DevicePosition.h Moving src/webrtc into src/. 2017-09-15 04:25:06 +00:00
AVCaptureSession+DevicePosition.mm Moving src/webrtc into src/. 2017-09-15 04:25:06 +00:00
RTCCVPixelBuffer.mm Fixed issue with BGRA RTCCVPixelBuffer scale and crop 2018-07-24 08:23:26 +00:00
RTCDefaultShader.h Moving src/webrtc into src/. 2017-09-15 04:25:06 +00:00
RTCDefaultShader.mm Replace rtc::Optional with absl::optional 2018-06-21 09:32:56 +00:00
RTCI420Buffer+Private.h Support RGB frames in RTCCVPixelBuffer 2017-10-23 15:34:28 +00:00
RTCI420Buffer.mm Add some more test cases for RTCCVPixelBuffer. 2018-04-24 14:43:26 +00:00
RTCI420TextureCache.h Moving src/webrtc into src/. 2017-09-15 04:25:06 +00:00
RTCI420TextureCache.mm Moving src/webrtc into src/. 2017-09-15 04:25:06 +00:00
RTCNV12TextureCache.h Moving src/webrtc into src/. 2017-09-15 04:25:06 +00:00
RTCNV12TextureCache.m Moving src/webrtc into src/. 2017-09-15 04:25:06 +00:00
RTCOpenGLDefines.h Moving src/webrtc into src/. 2017-09-15 04:25:06 +00:00
RTCShader.h Reformat the WebRTC code base 2018-06-19 14:00:39 +00:00
RTCShader.mm Stop using LOG macros in favor of RTC_ prefixed macros. 2017-11-09 11:56:32 +00:00
UIDevice+H264Profile.h Replace rtc::Optional with absl::optional 2018-06-21 09:32:56 +00:00
UIDevice+H264Profile.mm Replace rtc::Optional with absl::optional 2018-06-21 09:32:56 +00:00