summaryrefslogtreecommitdiff
path: root/libswscale
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2011-05-06 15:19:27 +0200
committerMichael Niedermayer <michaelni@gmx.at>2011-05-06 15:19:27 +0200
commit95f163b33b4f13cfe650f53ee2c3746788122def (patch)
treeb44c4bada967e3f068891afa89ebff73dc897361 /libswscale
parent7915e038c6ff70fd7b109a68c0064755648b0d14 (diff)
swscale: Dither for unscaled 10->8bit per channel
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libswscale')
-rw-r--r--libswscale/swscale.c92
1 files changed, 89 insertions, 3 deletions
diff --git a/libswscale/swscale.c b/libswscale/swscale.c
index dff8e2ae83..7be3344b4f 100644
--- a/libswscale/swscale.c
+++ b/libswscale/swscale.c
@@ -266,6 +266,81 @@ DECLARE_ALIGNED(8, const uint8_t, dither_8x8_220)[8][8]={
};
#endif
+DECLARE_ALIGNED(8, const uint8_t, dithers)[8][8][8]={
+{
+ { 0, 1, 0, 1, 0, 1, 0, 1,},
+ { 1, 0, 1, 0, 1, 0, 1, 0,},
+ { 0, 1, 0, 1, 0, 1, 0, 1,},
+ { 1, 0, 1, 0, 1, 0, 1, 0,},
+ { 0, 1, 0, 1, 0, 1, 0, 1,},
+ { 1, 0, 1, 0, 1, 0, 1, 0,},
+ { 0, 1, 0, 1, 0, 1, 0, 1,},
+ { 1, 0, 1, 0, 1, 0, 1, 0,},
+},{
+ { 1, 2, 1, 2, 1, 2, 1, 2,},
+ { 3, 0, 3, 0, 3, 0, 3, 0,},
+ { 1, 2, 1, 2, 1, 2, 1, 2,},
+ { 3, 0, 3, 0, 3, 0, 3, 0,},
+ { 1, 2, 1, 2, 1, 2, 1, 2,},
+ { 3, 0, 3, 0, 3, 0, 3, 0,},
+ { 1, 2, 1, 2, 1, 2, 1, 2,},
+ { 3, 0, 3, 0, 3, 0, 3, 0,},
+},{
+ { 2, 4, 3, 5, 2, 4, 3, 5,},
+ { 6, 0, 7, 1, 6, 0, 7, 1,},
+ { 3, 5, 2, 4, 3, 5, 2, 4,},
+ { 7, 1, 6, 0, 7, 1, 6, 0,},
+ { 2, 4, 3, 5, 2, 4, 3, 5,},
+ { 6, 0, 7, 1, 6, 0, 7, 1,},
+ { 3, 5, 2, 4, 3, 5, 2, 4,},
+ { 7, 1, 6, 0, 7, 1, 6, 0,},
+},{
+ { 4, 8, 7, 11, 4, 8, 7, 11,},
+ { 12, 0, 15, 3, 12, 0, 15, 3,},
+ { 6, 10, 5, 9, 6, 10, 5, 9,},
+ { 14, 2, 13, 1, 14, 2, 13, 1,},
+ { 4, 8, 7, 11, 4, 8, 7, 11,},
+ { 12, 0, 15, 3, 12, 0, 15, 3,},
+ { 6, 10, 5, 9, 6, 10, 5, 9,},
+ { 14, 2, 13, 1, 14, 2, 13, 1,},
+},{
+ { 9, 17, 15, 23, 8, 16, 14, 22,},
+ { 25, 1, 31, 7, 24, 0, 30, 6,},
+ { 13, 21, 11, 19, 12, 20, 10, 18,},
+ { 29, 5, 27, 3, 28, 4, 26, 2,},
+ { 8, 16, 14, 22, 9, 17, 15, 23,},
+ { 24, 0, 30, 6, 25, 1, 31, 7,},
+ { 12, 20, 10, 18, 13, 21, 11, 19,},
+ { 28, 4, 26, 2, 29, 5, 27, 3,},
+},{
+ { 18, 34, 30, 46, 17, 33, 29, 45,},
+ { 50, 2, 62, 14, 49, 1, 61, 13,},
+ { 26, 42, 22, 38, 25, 41, 21, 37,},
+ { 58, 10, 54, 6, 57, 9, 53, 5,},
+ { 16, 32, 28, 44, 19, 35, 31, 47,},
+ { 48, 0, 60, 12, 51, 3, 63, 15,},
+ { 24, 40, 20, 36, 27, 43, 23, 39,},
+ { 56, 8, 52, 4, 59, 11, 55, 7,},
+},{
+ { 18, 34, 30, 46, 17, 33, 29, 45,},
+ { 50, 2, 62, 14, 49, 1, 61, 13,},
+ { 26, 42, 22, 38, 25, 41, 21, 37,},
+ { 58, 10, 54, 6, 57, 9, 53, 5,},
+ { 16, 32, 28, 44, 19, 35, 31, 47,},
+ { 48, 0, 60, 12, 51, 3, 63, 15,},
+ { 24, 40, 20, 36, 27, 43, 23, 39,},
+ { 56, 8, 52, 4, 59, 11, 55, 7,},
+},{
+ { 36, 68, 60, 92, 34, 66, 58, 90,},
+ { 100, 4,124, 28, 98, 2,122, 26,},
+ { 52, 84, 44, 76, 50, 82, 42, 74,},
+ { 116, 20,108, 12,114, 18,106, 10,},
+ { 32, 64, 56, 88, 38, 70, 62, 94,},
+ { 96, 0,120, 24,102, 6,126, 30,},
+ { 48, 80, 40, 72, 54, 86, 46, 78,},
+ { 112, 16,104, 8,118, 22,110, 14,},
+}};
+
static av_always_inline void yuv2yuvX16inC_template(const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize,
const int16_t *chrFilter, const int16_t **chrSrc, int chrFilterSize,
const int16_t **alpSrc, uint16_t *dest, uint16_t *uDest, uint16_t *vDest, uint16_t *aDest,
@@ -1761,15 +1836,26 @@ static int planarCopyWrapper(SwsContext *c, const uint8_t* src[], int srcStride[
srcPtr2 += srcStride[plane]/2;
}
} else {
- // FIXME Maybe dither instead.
for (i = 0; i < height; i++) {
- for (j = 0; j < length; j++)
- dstPtr[j] = srcPtr2[j]>>(depth-8);
+ uint8_t *dither= dithers[depth-9][i&7];
+ for (j = 0; j < length-7; j+=8){
+ dstPtr[j+0] = (srcPtr2[j+0] + dither[0])>>(depth-8);
+ dstPtr[j+1] = (srcPtr2[j+1] + dither[1])>>(depth-8);
+ dstPtr[j+2] = (srcPtr2[j+2] + dither[2])>>(depth-8);
+ dstPtr[j+3] = (srcPtr2[j+3] + dither[3])>>(depth-8);
+ dstPtr[j+4] = (srcPtr2[j+4] + dither[4])>>(depth-8);
+ dstPtr[j+5] = (srcPtr2[j+5] + dither[5])>>(depth-8);
+ dstPtr[j+6] = (srcPtr2[j+6] + dither[6])>>(depth-8);
+ dstPtr[j+7] = (srcPtr2[j+7] + dither[7])>>(depth-8);
+ }
+ for (; j < length; j++)
+ dstPtr[j] = (srcPtr2[j] + dither[j&7])>>(depth-8);
dstPtr += dstStride[plane];
srcPtr2 += srcStride[plane]/2;
}
}
} else if(is16BPS(c->srcFormat) && !is16BPS(c->dstFormat)) {
+ //FIXME add dither
if (!isBE(c->srcFormat)) srcPtr++;
for (i=0; i<height; i++) {
for (j=0; j<length; j++) dstPtr[j] = srcPtr[j<<1];