annotate bfin/mpegvideo_bfin.c @ 5671:7dfd69f9af60 libavcodec

cosmetic
author michael
date Mon, 10 Sep 2007 00:31:27 +0000
parents 757efe20a3c8
children f7cbb7733146
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5131
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
1 /*
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
2 * BlackFin MPEGVIDEO OPTIMIZATIONS
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
3 *
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
4 * Copyright (C) 2007 Marc Hoffman <mmh@pleasantst.com>
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
5 *
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
6 * This file is part of FFmpeg.
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
7 *
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
8 * FFmpeg is free software; you can redistribute it and/or
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
9 * modify it under the terms of the GNU Lesser General Public
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
10 * License as published by the Free Software Foundation; either
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
11 * version 2.1 of the License, or (at your option) any later version.
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
12 *
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
13 * FFmpeg is distributed in the hope that it will be useful,
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
16 * Lesser General Public License for more details.
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
17 *
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
19 * License along with FFmpeg; if not, write to the Free Software
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
21 */
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
22
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
23 #include "dsputil.h"
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
24 #include "mpegvideo.h"
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
25 #include "avcodec.h"
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
26 #include "dsputil_bfin.h"
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
27
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
28
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
29 extern void ff_bfin_fdct (DCTELEM *block) attribute_l1_text;
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
30
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
31
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
32 static int dct_quantize_bfin (MpegEncContext *s,
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
33 DCTELEM *block, int n,
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
34 int qscale, int *overflow)
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
35 {
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
36 int last_non_zero, q, start_i;
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
37 const short *qmat;
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
38 short *bias;
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
39 const uint8_t *scantable= s->intra_scantable.scantable;
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
40 short dc;
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
41 int max=0;
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
42
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
43 PROF("fdct",0);
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
44 ff_bfin_fdct (block);
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
45 EPROF();
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
46
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
47 PROF("denoise",1);
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
48 if(s->dct_error_sum)
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
49 s->denoise_dct(s, block);
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
50 EPROF();
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
51
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
52 PROF("quant-init",2);
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
53 if (s->mb_intra) {
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
54 if (!s->h263_aic) {
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
55 if (n < 4)
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
56 q = s->y_dc_scale;
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
57 else
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
58 q = s->c_dc_scale;
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
59 q = q << 3;
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
60 } else
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
61 /* For AIC we skip quant/dequant of INTRADC */
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
62 q = 1 << 3;
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
63
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
64 /* note: block[0] is assumed to be positive */
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
65 dc = block[0] = (block[0] + (q >> 1)) / q;
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
66 start_i = 1;
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
67 last_non_zero = 0;
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
68 bias = s->q_intra_matrix16[qscale][1];
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
69 qmat = s->q_intra_matrix16[qscale][0];
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
70
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
71 } else {
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
72 start_i = 0;
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
73 last_non_zero = -1;
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
74 bias = s->q_inter_matrix16[qscale][1];
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
75 qmat = s->q_inter_matrix16[qscale][0];
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
76
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
77 }
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
78 EPROF();
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
79
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
80 PROF("quantize",4);
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
81
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
82 /* for(i=start_i; i<64; i++) { */
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
83 /* sign = (block[i]>>15)|1; */
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
84 /* level = ((abs(block[i])+bias[0])*qmat[i])>>16; */
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
85 /* if (level < 0) level = 0; */
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
86 /* max |= level; */
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
87 /* level = level * sign; */
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
88 /* block[i] = level; */
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
89 /* } */
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
90
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
91 asm volatile
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
92 ("i2=%1;\n\t"
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
93 "r1=[%1++]; \n\t"
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
94 "r0=r1>>>15 (v); \n\t"
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
95 "lsetup (0f,1f) lc0=%3; \n\t"
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
96 "0: r0=r0|%4; \n\t"
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
97 " r1=abs r1 (v) || r2=[%2++];\n\t"
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
98 " r1=r1+|+%5; \n\t"
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
99 " r1=max(r1,%6) (v); \n\t"
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
100 " r1.h=(a1 =r1.h*r2.h), r1.l=(a0 =r1.l*r2.l) (tfu); \n\t"
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
101 " %0=%0|r1; \n\t"
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
102 " r0.h=(a1 =r1.h*r0.h), r0.l=(a0 =r1.l*r0.l) (is) || r1=[%1++];\n\t"
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
103 "1: r0=r1>>>15 (v) || [i2++]=r0;\n\t"
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
104 "r1=%0>>16; \n\t"
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
105 "%0=%0|r1; \n\t"
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
106 "%0.h=0; \n\t"
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
107 : "=&d" (max)
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
108 : "b" (block), "b" (qmat), "a" (32), "d" (0x00010001), "d" (bias[0]*0x10001), "d" (0)
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
109 : "R0","R1","R2", "I2");
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
110 if (start_i == 1) block[0] = dc;
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
111
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
112 EPROF();
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
113
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
114
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
115 PROF("zzscan",5);
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
116
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
117 asm volatile
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
118 ("r0=b[%1--] (x); \n\t"
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
119 "lsetup (0f,1f) lc0=%3; \n\t" /* for(i=63; i>=start_i; i--) { */
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
120 "0: p0=r0; \n\t" /* j = scantable[i]; */
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
121 " p0=%2+(p0<<1); \n\t" /* if (block[j]) { */
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
122 " r0=w[p0]; \n\t" /* last_non_zero = i; */
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
123 " cc=r0==0; \n\t" /* break; */
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
124 " if !cc jump 2f; \n\t" /* } */
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
125 "1: r0=b[%1--] (x); \n\t" /* } */
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
126 " %0=%4; \n\t"
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
127 " jump 3f; \n\t"
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
128 "2: %0=lc0; \n\t"
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
129 "3:\n\t"
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
130
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
131 : "=d" (last_non_zero)
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
132 : "a" (scantable+63), "a" (block), "a" (63), "d" (last_non_zero)
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
133 : "P0","R0");
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
134
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
135 EPROF();
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
136
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
137 *overflow= s->max_qcoeff < max; //overflow might have happened
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
138
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
139 bfprof();
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
140
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
141 /* we need this permutation so that we correct the IDCT, we only permute the !=0 elements */
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
142 if (s->dsp.idct_permutation_type != FF_NO_IDCT_PERM)
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
143 ff_block_permute(block, s->dsp.idct_permutation, scantable, last_non_zero);
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
144
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
145 return last_non_zero;
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
146 }
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
147
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
148 void MPV_common_init_bfin (MpegEncContext *s)
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
149 {
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
150 s->dct_quantize= dct_quantize_bfin;
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
151 }
757efe20a3c8 Blackfin dct_quantize_bfin routine
mhoffman
parents:
diff changeset
152