Merge commit '33c827f632f95ffe3399b695a5a0d47b366b6e20'
authorMichael Niedermayer <michaelni@gmx.at>
Sat, 6 Dec 2014 00:29:53 +0000 (01:29 +0100)
committerMichael Niedermayer <michaelni@gmx.at>
Sat, 6 Dec 2014 00:30:08 +0000 (01:30 +0100)
* commit '33c827f632f95ffe3399b695a5a0d47b366b6e20':
  swscale: Properly scale YUV

Conflicts:
libswscale/swscale_unscaled.c
tests/ref/fate/filter-pixdesc-yuv420p10be
tests/ref/fate/filter-pixdesc-yuv420p10le
tests/ref/fate/filter-pixdesc-yuv420p9be
tests/ref/fate/filter-pixdesc-yuv420p9le
tests/ref/fate/filter-pixdesc-yuva420p10be
tests/ref/fate/filter-pixdesc-yuva420p10le
tests/ref/fate/filter-pixdesc-yuva420p9be
tests/ref/fate/filter-pixdesc-yuva420p9le
tests/ref/fate/filter-pixfmts-copy
tests/ref/fate/filter-pixfmts-null
tests/ref/fate/filter-pixfmts-scale
tests/ref/fate/filter-pixfmts-vflip

See: abe0b8e9f378a0f8781c1a3da6714d20cfd19594
Merged-by: Michael Niedermayer <michaelni@gmx.at>
1  2 
libswscale/swscale_unscaled.c

@@@ -1397,12 -781,12 +1397,12 @@@ static int planarCopyWrapper(SwsContex
      const AVPixFmtDescriptor *desc_dst = av_pix_fmt_desc_get(c->dstFormat);
      int plane, i, j;
      for (plane = 0; plane < 4; plane++) {
 -        int length = (plane == 0 || plane == 3) ? c->srcW  : -((-c->srcW  ) >> c->chrDstHSubSample);
 -        int y =      (plane == 0 || plane == 3) ? srcSliceY: -((-srcSliceY) >> c->chrDstVSubSample);
 -        int height = (plane == 0 || plane == 3) ? srcSliceH: -((-srcSliceH) >> c->chrDstVSubSample);
 +        int length = (plane == 0 || plane == 3) ? c->srcW  : FF_CEIL_RSHIFT(c->srcW,   c->chrDstHSubSample);
 +        int y =      (plane == 0 || plane == 3) ? srcSliceY: FF_CEIL_RSHIFT(srcSliceY, c->chrDstVSubSample);
 +        int height = (plane == 0 || plane == 3) ? srcSliceH: FF_CEIL_RSHIFT(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);
+         int shiftonly = plane == 1 || plane == 2 || (!c->srcRange && plane == 0);
  
          if (!dst[plane])
              continue;
                  const int src_depth = desc_src->comp[plane].depth_minus1 + 1;
                  const int dst_depth = desc_dst->comp[plane].depth_minus1 + 1;
                  const uint16_t *srcPtr2 = (const uint16_t *) srcPtr;
 +                uint16_t *dstPtr2 = (uint16_t*)dstPtr;
  
 -                if (is16BPS(c->dstFormat)) {
 -                    uint16_t *dstPtr2 = (uint16_t *) dstPtr;
 -#define COPY9_OR_10TO16(rfunc, wfunc) \
 -                    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; \
 -                        } \
 +                if (dst_depth == 8) {
 +                    if(isBE(c->srcFormat) == HAVE_BIGENDIAN){
 +                        DITHER_COPY(dstPtr, dstStride[plane], srcPtr2, srcStride[plane]/2, , )
 +                    } else {
 +                        DITHER_COPY(dstPtr, dstStride[plane], srcPtr2, srcStride[plane]/2, av_bswap16, )
                      }
 -                    if (isBE(c->dstFormat)) {
 -                        if (isBE(c->srcFormat)) {
 -                            COPY9_OR_10TO16(AV_RB16, AV_WB16);
 -                        } else {
 -                            COPY9_OR_10TO16(AV_RL16, AV_WB16);
 +                } else if (src_depth == 8) {
 +                    for (i = 0; i < height; i++) {
 +                        #define COPY816(w)\
-                         if(shiftonly){\
++                        if (shiftonly) {\
 +                            for (j = 0; j < length; j++)\
 +                                w(&dstPtr2[j], srcPtr[j]<<(dst_depth-8));\
-                         }else{\
++                        } else {\
 +                            for (j = 0; j < length; j++)\
 +                                w(&dstPtr2[j], (srcPtr[j]<<(dst_depth-8)) |\
 +                                               (srcPtr[j]>>(2*8-dst_depth)));\
                          }
 -                    } else {
 -                        if (isBE(c->srcFormat)) {
 -                            COPY9_OR_10TO16(AV_RB16, AV_WL16);
 +                        if(isBE(c->dstFormat)){
 +                            COPY816(AV_WB16)
                          } else {
 -                            COPY9_OR_10TO16(AV_RL16, AV_WL16);
 +                            COPY816(AV_WL16)
                          }
 +                        dstPtr2 += dstStride[plane]/2;
 +                        srcPtr  += srcStride[plane];
                      }
 -                } else if (is9_OR_10BPS(c->dstFormat)) {
 -                    uint16_t *dstPtr2 = (uint16_t *) dstPtr;
 -#define COPY9_OR_10TO9_OR_10(loop) \
 -                    for (i = 0; i < height; i++) { \
 -                        for (j = 0; j < length; j++) { \
 -                            loop; \
 -                        } \
 -                        dstPtr2 += dstStride[plane] / 2; \
 -                        srcPtr2 += srcStride[plane] / 2; \
 -                    }
 -#define COPY9_OR_10TO9_OR_10_2(rfunc, wfunc) \
 -                    if (dst_depth > src_depth) { \
 -                        COPY9_OR_10TO9_OR_10(int srcpx = rfunc(&srcPtr2[j]); \
 -                            wfunc(&dstPtr2[j], (srcpx << 1) | (srcpx >> 9))); \
 -                    } else if (dst_depth < src_depth) { \
 -                        DITHER_COPY(dstPtr2, dstStride[plane] / 2, wfunc, \
 -                                    srcPtr2, srcStride[plane] / 2, rfunc, \
 -                                    dither_8x8_1, 1, clip9); \
 -                    } else { \
 -                        COPY9_OR_10TO9_OR_10(wfunc(&dstPtr2[j], rfunc(&srcPtr2[j]))); \
 -                    }
 -                    if (isBE(c->dstFormat)) {
 -                        if (isBE(c->srcFormat)) {
 -                            COPY9_OR_10TO9_OR_10_2(AV_RB16, AV_WB16);
 -                        } else {
 -                            COPY9_OR_10TO9_OR_10_2(AV_RL16, AV_WB16);
 +                } else if (src_depth <= dst_depth) {
 +                    for (i = 0; i < height; i++) {
 +                        j = 0;
 +                        if(isBE(c->srcFormat) == HAVE_BIGENDIAN &&
 +                           isBE(c->dstFormat) == HAVE_BIGENDIAN &&
 +                           shiftonly) {
 +                             unsigned shift = dst_depth - src_depth;
 +#if HAVE_FAST_64BIT
 +#define FAST_COPY_UP(shift) \
 +    for (; j < length - 3; j += 4) { \
 +        uint64_t v = AV_RN64A(srcPtr2 + j); \
 +        AV_WN64A(dstPtr2 + j, v << shift); \
 +    }
 +#else
 +#define FAST_COPY_UP(shift) \
 +    for (; j < length - 1; j += 2) { \
 +        uint32_t v = AV_RN32A(srcPtr2 + j); \
 +        AV_WN32A(dstPtr2 + j, v << shift); \
 +    }
 +#endif
 +                             switch (shift)
 +                             {
 +                             case 6: FAST_COPY_UP(6); break;
 +                             case 7: FAST_COPY_UP(7); break;
 +                             }
                          }
 -                    } else {
 -                        if (isBE(c->srcFormat)) {
 -                            COPY9_OR_10TO9_OR_10_2(AV_RB16, AV_WL16);
 +#define COPY_UP(r,w) \
 +    if(shiftonly){\
 +        for (; j < length; j++){ \
 +            unsigned int v= r(&srcPtr2[j]);\
 +            w(&dstPtr2[j], v<<(dst_depth-src_depth));\
 +        }\
 +    }else{\
 +        for (; j < length; j++){ \
 +            unsigned int v= r(&srcPtr2[j]);\
 +            w(&dstPtr2[j], (v<<(dst_depth-src_depth)) | \
 +                        (v>>(2*src_depth-dst_depth)));\
 +        }\
 +    }
 +                        if(isBE(c->srcFormat)){
 +                            if(isBE(c->dstFormat)){
 +                                COPY_UP(AV_RB16, AV_WB16)
 +                            } else {
 +                                COPY_UP(AV_RB16, AV_WL16)
 +                            }
                          } else {
 -                            COPY9_OR_10TO9_OR_10_2(AV_RL16, AV_WL16);
 +                            if(isBE(c->dstFormat)){
 +                                COPY_UP(AV_RL16, AV_WB16)
 +                            } else {
 +                                COPY_UP(AV_RL16, AV_WL16)
 +                            }
                          }
 +                        dstPtr2 += dstStride[plane]/2;
 +                        srcPtr2 += srcStride[plane]/2;
                      }
                  } else {
 -#define W8(a, b) { *(a) = (b); }
 -#define COPY9_OR_10TO8(rfunc) \
 -                    if (src_depth == 9) { \
 -                        DITHER_COPY(dstPtr,  dstStride[plane],   W8, \
 -                                    srcPtr2, srcStride[plane] / 2, rfunc, \
 -                                    dither_8x8_1, 1, av_clip_uint8); \
 -                    } else { \
 -                        DITHER_COPY(dstPtr,  dstStride[plane],   W8, \
 -                                    srcPtr2, srcStride[plane] / 2, rfunc, \
 -                                    dither_8x8_3, 2, av_clip_uint8); \
 -                    }
 -                    if (isBE(c->srcFormat)) {
 -                        COPY9_OR_10TO8(AV_RB16);
 -                    } else {
 -                        COPY9_OR_10TO8(AV_RL16);
 -                    }
 -                }
 -            } else if (is9_OR_10BPS(c->dstFormat)) {
 -                const int dst_depth = desc_dst->comp[plane].depth_minus1 + 1;
 -                uint16_t *dstPtr2 = (uint16_t *) dstPtr;
 -
 -                if (is16BPS(c->srcFormat)) {
 -                    const uint16_t *srcPtr2 = (const uint16_t *) srcPtr;
 -#define COPY16TO9_OR_10(rfunc, wfunc) \
 -                    if (dst_depth == 9) { \
 -                        DITHER_COPY(dstPtr2, dstStride[plane] / 2, wfunc, \
 -                                    srcPtr2, srcStride[plane] / 2, rfunc, \
 -                                    ff_dither_8x8_128, 7, clip9); \
 -                    } else { \
 -                        DITHER_COPY(dstPtr2, dstStride[plane] / 2, wfunc, \
 -                                    srcPtr2, srcStride[plane] / 2, rfunc, \
 -                                    dither_8x8_64, 6, clip10); \
 -                    }
 -                    if (isBE(c->dstFormat)) {
 -                        if (isBE(c->srcFormat)) {
 -                            COPY16TO9_OR_10(AV_RB16, AV_WB16);
 +                    if(isBE(c->srcFormat) == HAVE_BIGENDIAN){
 +                        if(isBE(c->dstFormat) == HAVE_BIGENDIAN){
 +                            DITHER_COPY(dstPtr2, dstStride[plane]/2, srcPtr2, srcStride[plane]/2, , )
                          } else {
 -                            COPY16TO9_OR_10(AV_RL16, AV_WB16);
 +                            DITHER_COPY(dstPtr2, dstStride[plane]/2, srcPtr2, srcStride[plane]/2, , av_bswap16)
                          }
 -                    } else {
 -                        if (isBE(c->srcFormat)) {
 -                            COPY16TO9_OR_10(AV_RB16, AV_WL16);
 +                    }else{
 +                        if(isBE(c->dstFormat) == HAVE_BIGENDIAN){
 +                            DITHER_COPY(dstPtr2, dstStride[plane]/2, srcPtr2, srcStride[plane]/2, av_bswap16, )
                          } else {
 -                            COPY16TO9_OR_10(AV_RL16, AV_WL16);
 +                            DITHER_COPY(dstPtr2, dstStride[plane]/2, srcPtr2, srcStride[plane]/2, av_bswap16, av_bswap16)
                          }
                      }
 -                } else /* 8bit */ {
 -#define COPY8TO9_OR_10(wfunc) \
 -                    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]; \
 -                        } \
 -                    }
 -                    if (isBE(c->dstFormat)) {
 -                        COPY8TO9_OR_10(AV_WB16);
 -                    } else {
 -                        COPY8TO9_OR_10(AV_WL16);
 -                    }
 -                }
 -            } else if (is16BPS(c->srcFormat) && !is16BPS(c->dstFormat)) {
 -                const uint16_t *srcPtr2 = (const uint16_t *) srcPtr;
 -#define COPY16TO8(rfunc) \
 -                    DITHER_COPY(dstPtr,  dstStride[plane],   W8, \
 -                                srcPtr2, srcStride[plane] / 2, rfunc, \
 -                                dither_8x8_256, 8, av_clip_uint8);
 -                if (isBE(c->srcFormat)) {
 -                    COPY16TO8(AV_RB16);
 -                } else {
 -                    COPY16TO8(AV_RL16);
 -                }
 -            } else if (!is16BPS(c->srcFormat) && is16BPS(c->dstFormat)) {
 -                for (i = 0; i < height; i++) {
 -                    for (j = 0; j < length; j++) {
 -                        dstPtr[ j << 1     ] = srcPtr[j];
 -                        dstPtr[(j << 1) + 1] = srcPtr[j];
 -                    }
 -                    srcPtr += srcStride[plane];
 -                    dstPtr += dstStride[plane];
                  }
              } else if (is16BPS(c->srcFormat) && is16BPS(c->dstFormat) &&
                        isBE(c->srcFormat) != isBE(c->dstFormat)) {