diff options
author | Michael Niedermayer <michael@niedermayer.cc> | 2016-09-02 16:35:36 +0200 |
---|---|---|
committer | Michael Niedermayer <michael@niedermayer.cc> | 2016-09-02 21:53:53 +0200 |
commit | f580719b1a24a311ef9e38efce214fd77373dbc2 (patch) | |
tree | 9902ffd79f15a86759d0ca41d7d0e11686eb625f | |
parent | 5dcd913ab51f8ec96e01ef4cc651727b96dd6780 (diff) | |
download | ffmpeg-f580719b1a24a311ef9e38efce214fd77373dbc2.tar.gz |
swscale/swscale: Factor bottom to top handling
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
-rw-r--r-- | libswscale/swscale.c | 51 |
1 files changed, 19 insertions, 32 deletions
diff --git a/libswscale/swscale.c b/libswscale/swscale.c index bbea0feeab..63d16bd669 100644 --- a/libswscale/swscale.c +++ b/libswscale/swscale.c @@ -761,6 +761,12 @@ int attribute_align_arg sws_scale(struct SwsContext *c, uint8_t *dst2[4]; uint8_t *rgb0_tmp = NULL; int macro_height = isBayer(c->srcFormat) ? 2 : (1 << c->chrSrcVSubSample); + // copy strides, so they can safely be modified + int srcStride2[4] = { srcStride[0], srcStride[1], srcStride[2], + srcStride[3] }; + int dstStride2[4] = { dstStride[0], dstStride[1], dstStride[2], + dstStride[3] }; + int srcSliceY_internal = srcSliceY; if (!srcStride || !dstStride || !dst || !srcSlice) { av_log(c, AV_LOG_ERROR, "One of the input parameters to sws_scale() is NULL, please check the calling code\n"); @@ -943,30 +949,12 @@ int attribute_align_arg sws_scale(struct SwsContext *c, for (i = 0; i < 4; i++) memset(c->dither_error[i], 0, sizeof(c->dither_error[0][0]) * (c->dstW+2)); - - // copy strides, so they can safely be modified - if (c->sliceDir == 1) { - // slices go from top to bottom - int srcStride2[4] = { srcStride[0], srcStride[1], srcStride[2], - srcStride[3] }; - int dstStride2[4] = { dstStride[0], dstStride[1], dstStride[2], - dstStride[3] }; - - reset_ptr(src2, c->srcFormat); - reset_ptr((void*)dst2, c->dstFormat); - - /* reset slice direction at end of frame */ - if (srcSliceY + srcSliceH == c->srcH) - c->sliceDir = 0; - - ret = c->swscale(c, src2, srcStride2, srcSliceY, srcSliceH, dst2, - dstStride2); - } else { + if (c->sliceDir != 1) { // slices go from bottom to top => we flip the image internally - int srcStride2[4] = { -srcStride[0], -srcStride[1], -srcStride[2], - -srcStride[3] }; - int dstStride2[4] = { -dstStride[0], -dstStride[1], -dstStride[2], - -dstStride[3] }; + for (i=0; i<4; i++) { + srcStride2[i] *= -1; + dstStride2[i] *= -1; + } src2[0] += (srcSliceH - 1) * srcStride[0]; if (!usePal(c->srcFormat)) @@ -978,16 +966,15 @@ int attribute_align_arg sws_scale(struct SwsContext *c, dst2[2] += ((c->dstH >> c->chrDstVSubSample) - 1) * dstStride[2]; dst2[3] += ( c->dstH - 1) * dstStride[3]; - reset_ptr(src2, c->srcFormat); - reset_ptr((void*)dst2, c->dstFormat); - - /* reset slice direction at end of frame */ - if (!srcSliceY) - c->sliceDir = 0; - - ret = c->swscale(c, src2, srcStride2, c->srcH-srcSliceY-srcSliceH, - srcSliceH, dst2, dstStride2); + srcSliceY_internal = c->srcH-srcSliceY-srcSliceH; } + reset_ptr(src2, c->srcFormat); + reset_ptr((void*)dst2, c->dstFormat); + + /* reset slice direction at end of frame */ + if (srcSliceY_internal + srcSliceH == c->srcH) + c->sliceDir = 0; + ret = c->swscale(c, src2, srcStride2, srcSliceY_internal, srcSliceH, dst2, dstStride2); if (c->dstXYZ && !(c->srcXYZ && c->srcW==c->dstW && c->srcH==c->dstH)) { |