diff options
author | Derek Buitenhuis <derek.buitenhuis@gmail.com> | 2014-12-02 17:08:24 +0000 |
---|---|---|
committer | Vittorio Giovara <vittorio.giovara@gmail.com> | 2014-12-05 13:03:49 +0000 |
commit | 33c827f632f95ffe3399b695a5a0d47b366b6e20 (patch) | |
tree | b03de4a2e8709c03a102eff20e3bd40a8225e9b1 /libswscale | |
parent | 8c0a865ad96b9e8542051f75b0edc424cb73994e (diff) | |
download | ffmpeg-streaming-33c827f632f95ffe3399b695a5a0d47b366b6e20.zip ffmpeg-streaming-33c827f632f95ffe3399b695a5a0d47b366b6e20.tar.gz |
swscale: Properly scale YUV
Only shift limited range luma, and always only shift chroma
for upconversion.
Based off a patch by Michael Niedermayer.
Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
Diffstat (limited to 'libswscale')
-rw-r--r-- | libswscale/swscale_unscaled.c | 47 |
1 files changed, 35 insertions, 12 deletions
diff --git a/libswscale/swscale_unscaled.c b/libswscale/swscale_unscaled.c index ffc813e..ddf177a 100644 --- a/libswscale/swscale_unscaled.c +++ b/libswscale/swscale_unscaled.c @@ -786,6 +786,7 @@ static int planarCopyWrapper(SwsContext *c, const uint8_t *src[], int height = (plane == 0 || plane == 3) ? srcSliceH: -((-srcSliceH) >> c->chrDstVSubSample); const uint8_t *srcPtr = src[plane]; uint8_t *dstPtr = dst[plane] + dstStride[plane] * y; + int shiftonly = plane == 1 || plane == 2 || (!c->srcRange && plane == 0); if (!dst[plane]) continue; @@ -812,13 +813,24 @@ static int planarCopyWrapper(SwsContext *c, const uint8_t *src[], if (is16BPS(c->dstFormat)) { uint16_t *dstPtr2 = (uint16_t *) dstPtr; #define COPY9_OR_10TO16(rfunc, wfunc) \ - for (i = 0; i < height; i++) { \ - for (j = 0; j < length; j++) { \ - int srcpx = rfunc(&srcPtr2[j]); \ - wfunc(&dstPtr2[j], (srcpx << (16 - src_depth)) | (srcpx >> (2 * src_depth - 16))); \ + if (shiftonly) { \ + for (i = 0; i < height; i++) { \ + for (j = 0; j < length; j++) { \ + int srcpx = rfunc(&srcPtr2[j]); \ + wfunc(&dstPtr2[j], srcpx << (16 - src_depth)); \ + } \ + dstPtr2 += dstStride[plane] / 2; \ + srcPtr2 += srcStride[plane] / 2; \ + } \ + } else { \ + for (i = 0; i < height; i++) { \ + for (j = 0; j < length; j++) { \ + int srcpx = rfunc(&srcPtr2[j]); \ + wfunc(&dstPtr2[j], (srcpx << (16 - src_depth)) | (srcpx >> (2 * src_depth - 16))); \ + } \ + dstPtr2 += dstStride[plane] / 2; \ + srcPtr2 += srcStride[plane] / 2; \ } \ - dstPtr2 += dstStride[plane] / 2; \ - srcPtr2 += srcStride[plane] / 2; \ } if (isBE(c->dstFormat)) { if (isBE(c->srcFormat)) { @@ -916,13 +928,24 @@ static int planarCopyWrapper(SwsContext *c, const uint8_t *src[], } } else /* 8bit */ { #define COPY8TO9_OR_10(wfunc) \ - for (i = 0; i < height; i++) { \ - for (j = 0; j < length; j++) { \ - const int srcpx = srcPtr[j]; \ - wfunc(&dstPtr2[j], (srcpx << (dst_depth - 8)) | (srcpx >> (16 - dst_depth))); \ + if (shiftonly) { \ + for (i = 0; i < height; i++) { \ + for (j = 0; j < length; j++) { \ + const int srcpx = srcPtr[j]; \ + wfunc(&dstPtr2[j], srcpx << (dst_depth - 8)); \ + } \ + dstPtr2 += dstStride[plane] / 2; \ + srcPtr += srcStride[plane]; \ + } \ + } else { \ + for (i = 0; i < height; i++) { \ + for (j = 0; j < length; j++) { \ + const int srcpx = srcPtr[j]; \ + wfunc(&dstPtr2[j], (srcpx << (dst_depth - 8)) | (srcpx >> (16 - dst_depth))); \ + } \ + dstPtr2 += dstStride[plane] / 2; \ + srcPtr += srcStride[plane]; \ } \ - dstPtr2 += dstStride[plane] / 2; \ - srcPtr += srcStride[plane]; \ } if (isBE(c->dstFormat)) { COPY8TO9_OR_10(AV_WB16); |