diff --git a/libswscale/swscale_internal.h b/libswscale/swscale_internal.h index ec696e932d..9a125f72c2 100644 --- a/libswscale/swscale_internal.h +++ b/libswscale/swscale_internal.h @@ -273,6 +273,10 @@ typedef struct SwsContext { int xInc, const int16_t *filter, const int16_t *filterPos, long filterSize); + int lumSrcOffset; ///< Offset given to luma src pointers passed to horizontal input functions. + int chrSrcOffset; ///< Offset given to chroma src pointers passed to horizontal input functions. + int alpSrcOffset; ///< Offset given to alpha src pointers passed to horizontal input functions. + } SwsContext; //FIXME check init (where 0) diff --git a/libswscale/swscale_template.c b/libswscale/swscale_template.c index 675db6aa3f..0a024372af 100644 --- a/libswscale/swscale_template.c +++ b/libswscale/swscale_template.c @@ -2254,16 +2254,7 @@ static inline void RENAME(hyscale)(SwsContext *c, uint16_t *dst, long dstWidth, void av_unused *mmx2FilterCode= c->lumMmx2FilterCode; void (*internal_func)(uint8_t *, const uint8_t *, long, uint32_t *) = isAlpha ? c->hascale_internal : c->hyscale_internal; - if (isAlpha) { - if (srcFormat == PIX_FMT_RGB32 || srcFormat == PIX_FMT_BGR32 ) - src += 3; - } else { - if (srcFormat == PIX_FMT_RGB32_1 || srcFormat == PIX_FMT_BGR32_1) - src += ALT32_CORR; - } - - if (srcFormat == PIX_FMT_RGB48LE) - src++; + src += isAlpha ? c->alpSrcOffset : c->lumSrcOffset; if (internal_func) { internal_func(formatConvBuffer, src, srcW, pal); @@ -2433,15 +2424,8 @@ inline static void RENAME(hcscale)(SwsContext *c, uint16_t *dst, long dstWidth, if (isGray(srcFormat) || srcFormat==PIX_FMT_MONOBLACK || srcFormat==PIX_FMT_MONOWHITE) return; - if (srcFormat==PIX_FMT_RGB32_1 || srcFormat==PIX_FMT_BGR32_1) { - src1 += ALT32_CORR; - src2 += ALT32_CORR; - } - - if (srcFormat==PIX_FMT_RGB48LE) { - src1++; - src2++; - } + src1 += c->chrSrcOffset; + src2 += c->chrSrcOffset; if (c->hcscale_internal) { c->hcscale_internal(formatConvBuffer, formatConvBuffer+VOFW, src1, src2, srcW, pal); @@ -3049,4 +3033,21 @@ static void RENAME(sws_init_swScale)(SwsContext *c) case PIX_FMT_BGR32_1: c->hascale_internal = abgrToA; break; } } + + switch (srcFormat) { + case PIX_FMT_RGB32 : + case PIX_FMT_BGR32 : + c->alpSrcOffset = 3; + break; + case PIX_FMT_RGB32_1: + case PIX_FMT_BGR32_1: + c->lumSrcOffset = ALT32_CORR; + c->chrSrcOffset = ALT32_CORR; + break; + case PIX_FMT_RGB48LE: + c->lumSrcOffset = 1; + c->chrSrcOffset = 1; + c->alpSrcOffset = 1; + break; + } }