Statistics
| Branch: | Revision:

ffmpeg / libavcodec / h264idct.c @ 7a886063

History | View | Annotate | Download (5.92 KB)

1 0fa8158d Michael Niedermayer
/*
2
 * H.264 IDCT
3
 * Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
4
 *
5 b78e7197 Diego Biurrun
 * This file is part of FFmpeg.
6
 *
7
 * FFmpeg is free software; you can redistribute it and/or
8 0fa8158d Michael Niedermayer
 * modify it under the terms of the GNU Lesser General Public
9
 * License as published by the Free Software Foundation; either
10 b78e7197 Diego Biurrun
 * version 2.1 of the License, or (at your option) any later version.
11 0fa8158d Michael Niedermayer
 *
12 b78e7197 Diego Biurrun
 * FFmpeg is distributed in the hope that it will be useful,
13 0fa8158d Michael Niedermayer
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 * Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public
18 b78e7197 Diego Biurrun
 * License along with FFmpeg; if not, write to the Free Software
19 5509bffa Diego Biurrun
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 0fa8158d Michael Niedermayer
 *
21
 */
22 115329f1 Diego Biurrun
23 0fa8158d Michael Niedermayer
/**
24
 * @file h264-idct.c
25
 * H.264 IDCT.
26
 * @author Michael Niedermayer <michaelni@gmx.at>
27
 */
28 115329f1 Diego Biurrun
29 0fa8158d Michael Niedermayer
#include "dsputil.h"
30
31 849f1035 Måns Rullgård
static av_always_inline void idct_internal(uint8_t *dst, DCTELEM *block, int stride, int block_stride, int shift, int add){
32 0fa8158d Michael Niedermayer
    int i;
33 55fde95e Måns Rullgård
    uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
34 0fa8158d Michael Niedermayer
35
    block[0] += 1<<(shift-1);
36
37
    for(i=0; i<4; i++){
38
        const int z0=  block[0 + block_stride*i]     +  block[2 + block_stride*i];
39
        const int z1=  block[0 + block_stride*i]     -  block[2 + block_stride*i];
40
        const int z2= (block[1 + block_stride*i]>>1) -  block[3 + block_stride*i];
41
        const int z3=  block[1 + block_stride*i]     + (block[3 + block_stride*i]>>1);
42
43
        block[0 + block_stride*i]= z0 + z3;
44
        block[1 + block_stride*i]= z1 + z2;
45
        block[2 + block_stride*i]= z1 - z2;
46
        block[3 + block_stride*i]= z0 - z3;
47
    }
48
49
    for(i=0; i<4; i++){
50
        const int z0=  block[i + block_stride*0]     +  block[i + block_stride*2];
51
        const int z1=  block[i + block_stride*0]     -  block[i + block_stride*2];
52
        const int z2= (block[i + block_stride*1]>>1) -  block[i + block_stride*3];
53
        const int z3=  block[i + block_stride*1]     + (block[i + block_stride*3]>>1);
54
55
        dst[i + 0*stride]= cm[ add*dst[i + 0*stride] + ((z0 + z3) >> shift) ];
56
        dst[i + 1*stride]= cm[ add*dst[i + 1*stride] + ((z1 + z2) >> shift) ];
57
        dst[i + 2*stride]= cm[ add*dst[i + 2*stride] + ((z1 - z2) >> shift) ];
58
        dst[i + 3*stride]= cm[ add*dst[i + 3*stride] + ((z0 - z3) >> shift) ];
59
    }
60
}
61
62
void ff_h264_idct_add_c(uint8_t *dst, DCTELEM *block, int stride){
63
    idct_internal(dst, block, stride, 4, 6, 1);
64
}
65
66
void ff_h264_lowres_idct_add_c(uint8_t *dst, int stride, DCTELEM *block){
67
    idct_internal(dst, block, stride, 8, 3, 1);
68
}
69
70
void ff_h264_lowres_idct_put_c(uint8_t *dst, int stride, DCTELEM *block){
71
    idct_internal(dst, block, stride, 8, 3, 0);
72
}
73 43efd19a Loren Merritt
74
void ff_h264_idct8_add_c(uint8_t *dst, DCTELEM *block, int stride){
75
    int i;
76
    DCTELEM (*src)[8] = (DCTELEM(*)[8])block;
77 55fde95e Måns Rullgård
    uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
78 43efd19a Loren Merritt
79
    block[0] += 32;
80
81
    for( i = 0; i < 8; i++ )
82
    {
83
        const int a0 =  src[i][0] + src[i][4];
84
        const int a2 =  src[i][0] - src[i][4];
85
        const int a4 = (src[i][2]>>1) - src[i][6];
86
        const int a6 = (src[i][6]>>1) + src[i][2];
87
88
        const int b0 = a0 + a6;
89
        const int b2 = a2 + a4;
90
        const int b4 = a2 - a4;
91
        const int b6 = a0 - a6;
92
93
        const int a1 = -src[i][3] + src[i][5] - src[i][7] - (src[i][7]>>1);
94
        const int a3 =  src[i][1] + src[i][7] - src[i][3] - (src[i][3]>>1);
95
        const int a5 = -src[i][1] + src[i][7] + src[i][5] + (src[i][5]>>1);
96
        const int a7 =  src[i][3] + src[i][5] + src[i][1] + (src[i][1]>>1);
97
98
        const int b1 = (a7>>2) + a1;
99
        const int b3 =  a3 + (a5>>2);
100
        const int b5 = (a3>>2) - a5;
101
        const int b7 =  a7 - (a1>>2);
102
103
        src[i][0] = b0 + b7;
104
        src[i][7] = b0 - b7;
105
        src[i][1] = b2 + b5;
106
        src[i][6] = b2 - b5;
107
        src[i][2] = b4 + b3;
108
        src[i][5] = b4 - b3;
109
        src[i][3] = b6 + b1;
110
        src[i][4] = b6 - b1;
111
    }
112
    for( i = 0; i < 8; i++ )
113
    {
114
        const int a0 =  src[0][i] + src[4][i];
115
        const int a2 =  src[0][i] - src[4][i];
116
        const int a4 = (src[2][i]>>1) - src[6][i];
117
        const int a6 = (src[6][i]>>1) + src[2][i];
118
119
        const int b0 = a0 + a6;
120
        const int b2 = a2 + a4;
121
        const int b4 = a2 - a4;
122
        const int b6 = a0 - a6;
123
124
        const int a1 = -src[3][i] + src[5][i] - src[7][i] - (src[7][i]>>1);
125
        const int a3 =  src[1][i] + src[7][i] - src[3][i] - (src[3][i]>>1);
126
        const int a5 = -src[1][i] + src[7][i] + src[5][i] + (src[5][i]>>1);
127
        const int a7 =  src[3][i] + src[5][i] + src[1][i] + (src[1][i]>>1);
128
129
        const int b1 = (a7>>2) + a1;
130
        const int b3 =  a3 + (a5>>2);
131
        const int b5 = (a3>>2) - a5;
132
        const int b7 =  a7 - (a1>>2);
133
134
        dst[i + 0*stride] = cm[ dst[i + 0*stride] + ((b0 + b7) >> 6) ];
135
        dst[i + 1*stride] = cm[ dst[i + 1*stride] + ((b2 + b5) >> 6) ];
136
        dst[i + 2*stride] = cm[ dst[i + 2*stride] + ((b4 + b3) >> 6) ];
137
        dst[i + 3*stride] = cm[ dst[i + 3*stride] + ((b6 + b1) >> 6) ];
138
        dst[i + 4*stride] = cm[ dst[i + 4*stride] + ((b6 - b1) >> 6) ];
139
        dst[i + 5*stride] = cm[ dst[i + 5*stride] + ((b4 - b3) >> 6) ];
140
        dst[i + 6*stride] = cm[ dst[i + 6*stride] + ((b2 - b5) >> 6) ];
141
        dst[i + 7*stride] = cm[ dst[i + 7*stride] + ((b0 - b7) >> 6) ];
142
    }
143
}
144 ef9d1d15 Loren Merritt
145
// assumes all AC coefs are 0
146
void ff_h264_idct_dc_add_c(uint8_t *dst, DCTELEM *block, int stride){
147
    int i, j;
148 55fde95e Måns Rullgård
    uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
149 ef9d1d15 Loren Merritt
    int dc = (block[0] + 32) >> 6;
150
    for( j = 0; j < 4; j++ )
151
    {
152
        for( i = 0; i < 4; i++ )
153
            dst[i] = cm[ dst[i] + dc ];
154
        dst += stride;
155
    }
156
}
157
158
void ff_h264_idct8_dc_add_c(uint8_t *dst, DCTELEM *block, int stride){
159
    int i, j;
160 55fde95e Måns Rullgård
    uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
161 ef9d1d15 Loren Merritt
    int dc = (block[0] + 32) >> 6;
162
    for( j = 0; j < 8; j++ )
163
    {
164
        for( i = 0; i < 8; i++ )
165
            dst[i] = cm[ dst[i] + dc ];
166
        dst += stride;
167
    }
168
}