[cvs] / xvidcore / src / utils / mbtransquant.c Repository:
ViewVC logotype

Diff of /xvidcore/src/utils/mbtransquant.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.11, Wed Sep 4 06:24:37 2002 UTC revision 1.11.2.6, Mon Dec 9 10:47:05 2002 UTC
# Line 65  Line 65 
65  #include "../quant/quant_h263.h"  #include "../quant/quant_h263.h"
66  #include "../encoder.h"  #include "../encoder.h"
67    
68    #include "../image/reduced.h"
69    
70    MBFIELDTEST_PTR MBFieldTest;
71    
72  #define MIN(X, Y) ((X)<(Y)?(X):(Y))  #define MIN(X, Y) ((X)<(Y)?(X):(Y))
73  #define MAX(X, Y) ((X)>(Y)?(X):(Y))  #define MAX(X, Y) ((X)>(Y)?(X):(Y))
74    
75  #define TOOSMALL_LIMIT 3                /* skip blocks having a coefficient sum below this value */  #define TOOSMALL_LIMIT  1       /* skip blocks having a coefficient sum below this value */
   
 /* this isnt pretty, but its better than 20 ifdefs */  
76    
77  void  void
78  MBTransQuantIntra(const MBParam * pParam,  MBTransQuantIntra(const MBParam * pParam,
# Line 84  Line 86 
86    
87          uint32_t stride = pParam->edged_width;          uint32_t stride = pParam->edged_width;
88          uint32_t stride2 = stride / 2;          uint32_t stride2 = stride / 2;
89          uint32_t next_block = stride * 8;          uint32_t next_block = stride * ((frame->global_flags & XVID_REDUCED)?16:8);
90          uint32_t i;          uint32_t i;
91          uint32_t iQuant = frame->quant;          uint32_t iQuant = frame->quant;
92          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
93          IMAGE *pCurrent = &frame->image;          IMAGE *pCurrent = &frame->image;
94    
95            start_timer();
96            if ((frame->global_flags & XVID_REDUCED))
97            {
98                    pY_Cur = pCurrent->y + (y_pos << 5) * stride + (x_pos << 5);
99                    pU_Cur = pCurrent->u + (y_pos << 4) * stride2 + (x_pos << 4);
100                    pV_Cur = pCurrent->v + (y_pos << 4) * stride2 + (x_pos << 4);
101    
102                    filter_18x18_to_8x8(&data[0 * 64], pY_Cur, stride);
103                    filter_18x18_to_8x8(&data[1 * 64], pY_Cur + 16, stride);
104                    filter_18x18_to_8x8(&data[2 * 64], pY_Cur + next_block, stride);
105                    filter_18x18_to_8x8(&data[3 * 64], pY_Cur + next_block + 16, stride);
106                    filter_18x18_to_8x8(&data[4 * 64], pU_Cur, stride2);
107                    filter_18x18_to_8x8(&data[5 * 64], pV_Cur, stride2);
108            }else{
109          pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4);          pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4);
110          pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3);          pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3);
111          pV_Cur = pCurrent->v + (y_pos << 3) * stride2 + (x_pos << 3);          pV_Cur = pCurrent->v + (y_pos << 3) * stride2 + (x_pos << 3);
112    
         start_timer();  
113          transfer_8to16copy(&data[0 * 64], pY_Cur, stride);          transfer_8to16copy(&data[0 * 64], pY_Cur, stride);
114          transfer_8to16copy(&data[1 * 64], pY_Cur + 8, stride);          transfer_8to16copy(&data[1 * 64], pY_Cur + 8, stride);
115          transfer_8to16copy(&data[2 * 64], pY_Cur + next_block, stride);          transfer_8to16copy(&data[2 * 64], pY_Cur + next_block, stride);
116          transfer_8to16copy(&data[3 * 64], pY_Cur + next_block + 8, stride);          transfer_8to16copy(&data[3 * 64], pY_Cur + next_block + 8, stride);
117          transfer_8to16copy(&data[4 * 64], pU_Cur, stride2);          transfer_8to16copy(&data[4 * 64], pU_Cur, stride2);
118          transfer_8to16copy(&data[5 * 64], pV_Cur, stride2);          transfer_8to16copy(&data[5 * 64], pV_Cur, stride2);
119            }
120          stop_transfer_timer();          stop_transfer_timer();
121    
122            /* XXX: rrv+interlacing is buggy */
123          start_timer();          start_timer();
124          pMB->field_dct = 0;          pMB->field_dct = 0;
125          if ((frame->global_flags & XVID_INTERLACING) &&          if ((frame->global_flags & XVID_INTERLACING) &&
# Line 123  Line 140 
140                          start_timer();                          start_timer();
141                          quant_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler);                          quant_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler);
142                          stop_quant_timer();                          stop_quant_timer();
   
                         start_timer();  
                         dequant_intra(&data[i * 64], &qcoeff[i * 64], iQuant, iDcScaler);  
                         stop_iquant_timer();  
143                  } else {                  } else {
144                          start_timer();                          start_timer();
145                          quant4_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler);                          quant4_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler);
146                          stop_quant_timer();                          stop_quant_timer();
147                    }
148    
149                    /* speedup: dont decode when encoding only ivops */
150                    if (pParam->iMaxKeyInterval != 1 || pParam->max_bframes > 0)
151                    {
152                            if (pParam->m_quant_type == H263_QUANT) {
153                                    start_timer();
154                                    dequant_intra(&data[i * 64], &qcoeff[i * 64], iQuant, iDcScaler);
155                                    stop_iquant_timer();
156                            } else {
157                          start_timer();                          start_timer();
158                          dequant4_intra(&data[i * 64], &qcoeff[i * 64], iQuant, iDcScaler);                          dequant4_intra(&data[i * 64], &qcoeff[i * 64], iQuant, iDcScaler);
159                          stop_iquant_timer();                          stop_iquant_timer();
# Line 141  Line 163 
163                  idct(&data[i * 64]);                  idct(&data[i * 64]);
164                  stop_idct_timer();                  stop_idct_timer();
165          }          }
166            }
167    
168            /* speedup: dont decode when encoding only ivops */
169            if (pParam->iMaxKeyInterval != 1 || pParam->max_bframes > 0)
170            {
171    
172          if (pMB->field_dct) {          if (pMB->field_dct) {
173                  next_block = stride;                  next_block = stride;
# Line 148  Line 175 
175          }          }
176    
177          start_timer();          start_timer();
178                    if ((frame->global_flags & XVID_REDUCED))
179                    {
180                            copy_upsampled_8x8_16to8(pY_Cur, &data[0 * 64], stride);
181                            copy_upsampled_8x8_16to8(pY_Cur + 16, &data[1 * 64], stride);
182                            copy_upsampled_8x8_16to8(pY_Cur + next_block, &data[2 * 64], stride);
183                            copy_upsampled_8x8_16to8(pY_Cur + next_block + 16, &data[3 * 64], stride);
184                            copy_upsampled_8x8_16to8(pU_Cur, &data[4 * 64], stride2);
185                            copy_upsampled_8x8_16to8(pV_Cur, &data[5 * 64], stride2);
186    
187                    }else{
188          transfer_16to8copy(pY_Cur, &data[0 * 64], stride);          transfer_16to8copy(pY_Cur, &data[0 * 64], stride);
189          transfer_16to8copy(pY_Cur + 8, &data[1 * 64], stride);          transfer_16to8copy(pY_Cur + 8, &data[1 * 64], stride);
190          transfer_16to8copy(pY_Cur + next_block, &data[2 * 64], stride);          transfer_16to8copy(pY_Cur + next_block, &data[2 * 64], stride);
191          transfer_16to8copy(pY_Cur + next_block + 8, &data[3 * 64], stride);          transfer_16to8copy(pY_Cur + next_block + 8, &data[3 * 64], stride);
192          transfer_16to8copy(pU_Cur, &data[4 * 64], stride2);          transfer_16to8copy(pU_Cur, &data[4 * 64], stride2);
193          transfer_16to8copy(pV_Cur, &data[5 * 64], stride2);          transfer_16to8copy(pV_Cur, &data[5 * 64], stride2);
194                    }
195          stop_transfer_timer();          stop_transfer_timer();
196            }
197    
198  }  }
199    
# Line 171  Line 210 
210    
211          uint32_t stride = pParam->edged_width;          uint32_t stride = pParam->edged_width;
212          uint32_t stride2 = stride / 2;          uint32_t stride2 = stride / 2;
213          uint32_t next_block = stride * 8;          uint32_t next_block = stride * ((frame->global_flags & XVID_REDUCED)?16:8);
214          uint32_t i;          uint32_t i;
215          uint32_t iQuant = frame->quant;          uint32_t iQuant = frame->quant;
216          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
# Line 179  Line 218 
218          uint32_t sum;          uint32_t sum;
219          IMAGE *pCurrent = &frame->image;          IMAGE *pCurrent = &frame->image;
220    
221            if ((frame->global_flags & XVID_REDUCED))
222            {
223                    pY_Cur = pCurrent->y + (y_pos << 5) * stride + (x_pos << 5);
224                    pU_Cur = pCurrent->u + (y_pos << 4) * stride2 + (x_pos << 4);
225                    pV_Cur = pCurrent->v + (y_pos << 4) * stride2 + (x_pos << 4);
226            }else{
227          pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4);          pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4);
228          pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3);          pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3);
229          pV_Cur = pCurrent->v + (y_pos << 3) * stride2 + (x_pos << 3);          pV_Cur = pCurrent->v + (y_pos << 3) * stride2 + (x_pos << 3);
230            }
231    
232          start_timer();          start_timer();
233          pMB->field_dct = 0;          pMB->field_dct = 0;
# Line 193  Line 239 
239          stop_interlacing_timer();          stop_interlacing_timer();
240    
241          for (i = 0; i < 6; i++) {          for (i = 0; i < 6; i++) {
242                    uint32_t increase_limit = (iQuant == 1) ? 1 : 0;
243    
244                  /*                  /*
245                   *  no need to transfer 8->16-bit                   *  no need to transfer 8->16-bit
246                   * (this is performed already in motion compensation)                   * (this is performed already in motion compensation)
# Line 211  Line 259 
259                          stop_quant_timer();                          stop_quant_timer();
260                  }                  }
261    
262                  if ((sum >= TOOSMALL_LIMIT) || (qcoeff[i*64] != 0) ||                  if ((sum >= TOOSMALL_LIMIT + increase_limit) || (qcoeff[i*64] != 0) ||
263                          (qcoeff[i*64+1] != 0) || (qcoeff[i*64+8] != 0)) {                          (qcoeff[i*64+1] != 0) || (qcoeff[i*64+8] != 0)) {
264    
265                          if (pParam->m_quant_type == H263_QUANT) {                          if (pParam->m_quant_type == H263_QUANT) {
# Line 238  Line 286 
286          }          }
287    
288          start_timer();          start_timer();
289            if ((frame->global_flags & XVID_REDUCED))
290            {
291                    if (cbp & 32)
292                            add_upsampled_8x8_16to8(pY_Cur, &data[0 * 64], stride);
293                    if (cbp & 16)
294                            add_upsampled_8x8_16to8(pY_Cur + 16, &data[1 * 64], stride);
295                    if (cbp & 8)
296                            add_upsampled_8x8_16to8(pY_Cur + next_block, &data[2 * 64], stride);
297                    if (cbp & 4)
298                            add_upsampled_8x8_16to8(pY_Cur + 16 + next_block, &data[3 * 64], stride);
299                    if (cbp & 2)
300                            add_upsampled_8x8_16to8(pU_Cur, &data[4 * 64], stride2);
301                    if (cbp & 1)
302                            add_upsampled_8x8_16to8(pV_Cur, &data[5 * 64], stride2);
303            }else{
304          if (cbp & 32)          if (cbp & 32)
305                  transfer_16to8add(pY_Cur, &data[0 * 64], stride);                  transfer_16to8add(pY_Cur, &data[0 * 64], stride);
306          if (cbp & 16)          if (cbp & 16)
# Line 250  Line 313 
313                  transfer_16to8add(pU_Cur, &data[4 * 64], stride2);                  transfer_16to8add(pU_Cur, &data[4 * 64], stride2);
314          if (cbp & 1)          if (cbp & 1)
315                  transfer_16to8add(pV_Cur, &data[5 * 64], stride2);                  transfer_16to8add(pV_Cur, &data[5 * 64], stride2);
316            }
317          stop_transfer_timer();          stop_transfer_timer();
318    
319          return cbp;          return cbp;
# Line 576  Line 640 
640    
641    
642    
643  /* if sum(diff between field lines) < sum(diff between frame lines), use field dct */  /* permute block and return field dct choice */
644    
645    
646  uint32_t  uint32_t
647  MBDecideFieldDCT(int16_t data[6 * 64])  MBDecideFieldDCT(int16_t data[6 * 64])
648  {  {
649            uint32_t field = MBFieldTest(data);
650    
651            if (field) {
652                    MBFrameToField(data);
653            }
654    
655            return field;
656    }
657    
658    
659    /* if sum(diff between field lines) < sum(diff between frame lines), use field dct */
660    
661    uint32_t
662    MBFieldTest_c(int16_t data[6 * 64])
663    {
664          const uint8_t blocks[] =          const uint8_t blocks[] =
665                  { 0 * 64, 0 * 64, 0 * 64, 0 * 64, 2 * 64, 2 * 64, 2 * 64, 2 * 64 };                  { 0 * 64, 0 * 64, 0 * 64, 0 * 64, 2 * 64, 2 * 64, 2 * 64, 2 * 64 };
666          const uint8_t lines[] = { 0, 16, 32, 48, 0, 16, 32, 48 };          const uint8_t lines[] = { 0, 16, 32, 48, 0, 16, 32, 48 };
# Line 616  Line 694 
694                  }                  }
695          }          }
696    
697          if (frame > field) {          return (frame >= (field + 350));
                 MBFrameToField(data);  
         }  
   
         return (frame > field);  
698  }  }
699    
700    

Legend:
Removed from v.1.11  
changed lines
  Added in v.1.11.2.6

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4