summaryrefslogtreecommitdiff
path: root/libswscale
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2011-05-09 21:38:46 +0200
committerMichael Niedermayer <michaelni@gmx.at>2011-05-09 21:38:46 +0200
commit300e497b5fe4cd72031c175c74bcfa58239d991b (patch)
treeef0151e67a719987e82a9c80b6f5460b6265bd92 /libswscale
parent173544077316c448cefc79c7e595021b41249a1a (diff)
swscale: factorize DITHER_COPY()
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libswscale')
-rw-r--r--libswscale/swscale.c56
1 files changed, 22 insertions, 34 deletions
diff --git a/libswscale/swscale.c b/libswscale/swscale.c
index 591c7a4375..1f476ad5db 100644
--- a/libswscale/swscale.c
+++ b/libswscale/swscale.c
@@ -1857,6 +1857,26 @@ static int packedCopyWrapper(SwsContext *c, const uint8_t* src[], int srcStride[
return srcSliceH;
}
+#define DITHER_COPY(dst, dstStride, src, srcStride)\
+ for (i = 0; i < height; i++) {\
+ uint8_t *dither= dithers[src_depth-9][i&7];\
+ for (j = 0; j < length-7; j+=8){\
+ dst[j+0] = (src[j+0] + dither[0])>>(src_depth-dst_depth);\
+ dst[j+1] = (src[j+1] + dither[1])>>(src_depth-dst_depth);\
+ dst[j+2] = (src[j+2] + dither[2])>>(src_depth-dst_depth);\
+ dst[j+3] = (src[j+3] + dither[3])>>(src_depth-dst_depth);\
+ dst[j+4] = (src[j+4] + dither[4])>>(src_depth-dst_depth);\
+ dst[j+5] = (src[j+5] + dither[5])>>(src_depth-dst_depth);\
+ dst[j+6] = (src[j+6] + dither[6])>>(src_depth-dst_depth);\
+ dst[j+7] = (src[j+7] + dither[7])>>(src_depth-dst_depth);\
+ }\
+ for (; j < length; j++)\
+ dst[j] = (src[j] + dither[j&7])>>(src_depth-dst_depth);\
+ dst += dstStride;\
+ src += srcStride;\
+ }
+
+
static int planarCopyWrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY,
int srcSliceH, uint8_t* dst[], int dstStride[])
{
@@ -1883,23 +1903,7 @@ static int planarCopyWrapper(SwsContext *c, const uint8_t* src[], int srcStride[
uint16_t *dstPtr2 = (uint16_t*)dstPtr;
if (dst_depth == 8) {
- for (i = 0; i < height; i++) {
- uint8_t *dither= dithers[src_depth-9][i&7];
- for (j = 0; j < length-7; j+=8){
- dstPtr[j+0] = (srcPtr2[j+0] + dither[0])>>(src_depth-8);
- dstPtr[j+1] = (srcPtr2[j+1] + dither[1])>>(src_depth-8);
- dstPtr[j+2] = (srcPtr2[j+2] + dither[2])>>(src_depth-8);
- dstPtr[j+3] = (srcPtr2[j+3] + dither[3])>>(src_depth-8);
- dstPtr[j+4] = (srcPtr2[j+4] + dither[4])>>(src_depth-8);
- dstPtr[j+5] = (srcPtr2[j+5] + dither[5])>>(src_depth-8);
- dstPtr[j+6] = (srcPtr2[j+6] + dither[6])>>(src_depth-8);
- dstPtr[j+7] = (srcPtr2[j+7] + dither[7])>>(src_depth-8);
- }
- for (; j < length; j++)
- dstPtr[j] = (srcPtr2[j] + dither[j&7])>>(src_depth-8);
- dstPtr += dstStride[plane];
- srcPtr2 += srcStride[plane]/2;
- }
+ DITHER_COPY(dstPtr, dstStride[plane], srcPtr2, srcStride[plane]/2)
} else if (src_depth == 8) {
for (i = 0; i < height; i++) {
for (j = 0; j < length; j++)
@@ -1923,23 +1927,7 @@ static int planarCopyWrapper(SwsContext *c, const uint8_t* src[], int srcStride[
srcPtr2 += srcStride[plane]/2;
}
} else {
- for (i = 0; i < height; i++) {
- uint8_t *dither= dithers[src_depth-9][i&7];
- for (j = 0; j < length-7; j+=8){
- dstPtr2[j+0] = (srcPtr2[j+0] + dither[0])>>(src_depth-dst_depth);
- dstPtr2[j+1] = (srcPtr2[j+1] + dither[1])>>(src_depth-dst_depth);
- dstPtr2[j+2] = (srcPtr2[j+2] + dither[2])>>(src_depth-dst_depth);
- dstPtr2[j+3] = (srcPtr2[j+3] + dither[3])>>(src_depth-dst_depth);
- dstPtr2[j+4] = (srcPtr2[j+4] + dither[4])>>(src_depth-dst_depth);
- dstPtr2[j+5] = (srcPtr2[j+5] + dither[5])>>(src_depth-dst_depth);
- dstPtr2[j+6] = (srcPtr2[j+6] + dither[6])>>(src_depth-dst_depth);
- dstPtr2[j+7] = (srcPtr2[j+7] + dither[7])>>(src_depth-dst_depth);
- }
- for (; j < length; j++)
- dstPtr2[j] = (srcPtr2[j] + dither[j&7])>>(src_depth-dst_depth);
- dstPtr2 += dstStride[plane];
- srcPtr2 += srcStride[plane]/2;
- }
+ DITHER_COPY(dstPtr2, dstStride[plane]/2, srcPtr2, srcStride[plane]/2)
}
} else if(is16BPS(c->srcFormat) && !is16BPS(c->dstFormat)) {
//FIXME add dither