annotate libmpcodecs/vf_spp.c @ 11295:8b9ae87aff0f

10l
author michael
date Mon, 27 Oct 2003 19:14:38 +0000
parents 47b69dcf384d
children 86916e46d445
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11277
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
1 /*
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
2 Copyright (C) 2003 Michael Niedermayer <michaelni@gmx.at>
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
3
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
4 This program is free software; you can redistribute it and/or modify
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
6 the Free Software Foundation; either version 2 of the License, or
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
7 (at your option) any later version.
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
8
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
12 GNU General Public License for more details.
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
13
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
15 along with this program; if not, write to the Free Software
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
17 */
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
18
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
19 /*
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
20 * This implementation is based on an algorithm described in
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
21 * "Aria Nosratinia Embedded Post-Processing for
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
22 * Enhancement of Compressed Images (1999)"
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
23 * (http://citeseer.nj.nec.com/nosratinia99embedded.html)
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
24 */
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
25
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
26 #include <stdio.h>
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
27 #include <stdlib.h>
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
28 #include <string.h>
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
29 #include <inttypes.h>
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
30 #include <math.h>
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
31
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
32 #include "../config.h"
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
33 #include "../mp_msg.h"
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
34 #include "../cpudetect.h"
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
35 #include "../libavcodec/avcodec.h"
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
36 #include "../libavcodec/dsputil.h"
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
37
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
38 #ifdef HAVE_MALLOC_H
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
39 #include <malloc.h>
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
40 #endif
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
41
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
42 #include "img_format.h"
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
43 #include "mp_image.h"
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
44 #include "vf.h"
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
45 #include "../libvo/fastmemcpy.h"
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
46
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
47 #define XMIN(a,b) ((a) < (b) ? (a) : (b))
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
48
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
49 //===========================================================================//
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
50 const uint8_t __attribute__((aligned(8))) dither[8][8]={
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
51 { 0, 48, 12, 60, 3, 51, 15, 63, },
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
52 { 32, 16, 44, 28, 35, 19, 47, 31, },
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
53 { 8, 56, 4, 52, 11, 59, 7, 55, },
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
54 { 40, 24, 36, 20, 43, 27, 39, 23, },
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
55 { 2, 50, 14, 62, 1, 49, 13, 61, },
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
56 { 34, 18, 46, 30, 33, 17, 45, 29, },
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
57 { 10, 58, 6, 54, 9, 57, 5, 53, },
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
58 { 42, 26, 38, 22, 41, 25, 37, 21, },
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
59 };
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
60
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
61 const uint8_t offset[64][2]= {
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
62 {0,0}, {4,4}, {0,4}, {4,0}, {2,2}, {6,6}, {2,6}, {6,2},
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
63 {0,2}, {4,6}, {0,6}, {4,2}, {2,0}, {6,4}, {2,4}, {6,0},
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
64 {1,1}, {5,5}, {1,5}, {5,1}, {3,3}, {7,7}, {3,7}, {7,3},
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
65 {1,3}, {5,7}, {1,7}, {5,3}, {3,1}, {7,5}, {3,5}, {7,1},
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
66 {0,1}, {4,5}, {0,5}, {4,1}, {2,3}, {6,7}, {2,7}, {6,3},
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
67 {0,3}, {4,7}, {0,7}, {4,3}, {2,1}, {6,5}, {2,5}, {6,1},
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
68 {1,0}, {5,4}, {1,4}, {5,0}, {3,2}, {7,6}, {3,6}, {7,2},
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
69 {1,2}, {5,6}, {1,6}, {5,2}, {3,0}, {7,4}, {3,4}, {7,0},
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
70 };
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
71
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
72 struct vf_priv_s {
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
73 int log2_count;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
74 int qp;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
75 int mpeg2;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
76 unsigned int outfmt;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
77 int temp_stride;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
78 uint8_t *src;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
79 int16_t *temp;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
80 AVCodecContext *avctx;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
81 DSPContext dsp;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
82 };
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
83
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
84 #define SHIFT 22
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
85
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
86 static inline void requantize(DCTELEM dst[64], DCTELEM src[64], int qp, uint8_t *permutation){
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
87 int i;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
88 const int qmul= qp<<1;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
89 const int qadd= (qp-1)|1;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
90 const int qinv= ((1<<(SHIFT-3)) + qmul/2)/ qmul;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
91 int bias= 0; //FIXME
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
92 unsigned int threshold1, threshold2;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
93
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
94 threshold1= (1<<SHIFT) - bias - 1;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
95 threshold2= (threshold1<<1);
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
96
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
97 memset(dst, 0, 64*sizeof(DCTELEM));
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
98 dst[0]= (src[0] + 4)>>3;;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
99
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
100 for(i=1; i<64; i++){
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
101 int level= qinv*src[i];
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
102 if(((unsigned)(level+threshold1))>threshold2){
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
103 const int j= permutation[i];
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
104 if(level>0){
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
105 level= (bias + level)>>SHIFT;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
106 dst[j]= level*qmul + qadd;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
107 }else{
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
108 level= (bias - level)>>SHIFT;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
109 dst[j]= -level*qmul - qadd;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
110 }
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
111 }
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
112 }
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
113 }
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
114
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
115 static inline void add_block(int16_t *dst, int stride, DCTELEM block[64]){
11280
b677102fa650 10l and minor optimization
michael
parents: 11277
diff changeset
116 int y;
11277
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
117
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
118 for(y=0; y<8; y++){
11280
b677102fa650 10l and minor optimization
michael
parents: 11277
diff changeset
119 *(uint32_t*)&dst[0 + y*stride]+= *(uint32_t*)&block[0 + y*8];
b677102fa650 10l and minor optimization
michael
parents: 11277
diff changeset
120 *(uint32_t*)&dst[2 + y*stride]+= *(uint32_t*)&block[2 + y*8];
b677102fa650 10l and minor optimization
michael
parents: 11277
diff changeset
121 *(uint32_t*)&dst[4 + y*stride]+= *(uint32_t*)&block[4 + y*8];
b677102fa650 10l and minor optimization
michael
parents: 11277
diff changeset
122 *(uint32_t*)&dst[6 + y*stride]+= *(uint32_t*)&block[6 + y*8];
11277
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
123 }
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
124 }
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
125
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
126 static void filter(struct vf_priv_s *p, uint8_t *dst, uint8_t *src, int dst_stride, int src_stride, int width, int height, uint8_t *qp_store, int qp_stride, int is_luma){
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
127 int x, y, i;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
128 const int count= 1<<p->log2_count;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
129 const int log2_scale= 6-p->log2_count;
11281
michael
parents: 11280
diff changeset
130 const int stride= p->temp_stride; //FIXME
11277
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
131 uint64_t block_align[32];
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
132 DCTELEM *block = (DCTELEM *)block_align;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
133 DCTELEM *block2= (DCTELEM *)(block_align+16);
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
134
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
135 for(y=0; y<height; y++){
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
136 memcpy(p->src + 8 + 8*stride + y*stride, src + y*src_stride, width);
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
137 memset(p->temp + 8*stride + y*stride, 0, stride*sizeof(int16_t));
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
138 for(x=0; x<8; x++){
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
139 int index= 8 + 8*stride + y*stride;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
140 p->src[index - x - 1]= p->src[index + x ];
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
141 p->src[index + width + x ]= p->src[index + width - x - 1];
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
142 }
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
143 }
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
144 for(y=0; y<8; y++){
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
145 memcpy(p->src + ( 7-y)*stride, p->src + ( y+8)*stride, stride);
11281
michael
parents: 11280
diff changeset
146 memcpy(p->src + (height+8+y)*stride, p->src + (height-y+7)*stride, stride);
11277
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
147 }
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
148 //FIXME (try edge emu)
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
149
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
150 for(y=0; y<height+8; y+=8){
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
151 for(x=0; x<width+8; x+=8){
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
152 const int qps= 3 + is_luma;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
153 int qp;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
154
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
155 if(p->qp)
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
156 qp= p->qp;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
157 else{
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
158 qp= qp_store[ (XMIN(x, width-1)>>qps) + (XMIN(y, height-1)>>qps) * qp_stride];
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
159 if(p->mpeg2) qp>>=1;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
160 }
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
161 for(i=0; i<count; i++){
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
162 const int x1= x + offset[i][0];
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
163 const int y1= y + offset[i][1];
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
164 const int index= x1 + y1*stride;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
165 p->dsp.get_pixels(block, p->src + index, stride);
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
166 p->dsp.fdct(block);
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
167 requantize(block2, block, qp, p->dsp.idct_permutation);
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
168 p->dsp.idct(block2);
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
169 add_block(p->temp + index, stride, block2);
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
170 }
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
171 }
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
172 }
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
173
11295
michael
parents: 11281
diff changeset
174 #define STORE(pos) \
michael
parents: 11281
diff changeset
175 temp= ((p->temp[index + pos]<<log2_scale) + d[pos])>>6;\
michael
parents: 11281
diff changeset
176 if(temp & 0x100) temp= ~(temp>>31);\
michael
parents: 11281
diff changeset
177 dst[x + y*dst_stride + pos]= temp;
michael
parents: 11281
diff changeset
178
11277
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
179 for(y=0; y<height; y++){
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
180 uint8_t *d= dither[y&7];
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
181 for(x=0; x<width; x+=8){
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
182 const int index= 8 + 8*stride + x + y*stride;
11295
michael
parents: 11281
diff changeset
183 int temp;
michael
parents: 11281
diff changeset
184 STORE(0);
michael
parents: 11281
diff changeset
185 STORE(1);
michael
parents: 11281
diff changeset
186 STORE(2);
michael
parents: 11281
diff changeset
187 STORE(3);
michael
parents: 11281
diff changeset
188 STORE(4);
michael
parents: 11281
diff changeset
189 STORE(5);
michael
parents: 11281
diff changeset
190 STORE(6);
michael
parents: 11281
diff changeset
191 STORE(7);
11277
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
192 }
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
193 }
11295
michael
parents: 11281
diff changeset
194 #if 0
michael
parents: 11281
diff changeset
195 for(y=0; y<height; y++){
michael
parents: 11281
diff changeset
196 for(x=0; x<width; x++){
michael
parents: 11281
diff changeset
197 if((((x>>6) ^ (y>>6)) & 1) == 0)
michael
parents: 11281
diff changeset
198 dst[x + y*dst_stride]= p->src[8 + 8*stride + x + y*stride];
michael
parents: 11281
diff changeset
199 if((x&63) == 0 || (y&63)==0)
michael
parents: 11281
diff changeset
200 dst[x + y*dst_stride] += 128;
michael
parents: 11281
diff changeset
201 }
michael
parents: 11281
diff changeset
202 }
michael
parents: 11281
diff changeset
203 #endif
11277
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
204 //FIXME reorder for better caching
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
205 }
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
206
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
207 static int config(struct vf_instance_s* vf,
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
208 int width, int height, int d_width, int d_height,
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
209 unsigned int flags, unsigned int outfmt){
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
210
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
211 vf->priv->temp_stride= (width+16+15)&(~15);
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
212 vf->priv->temp= malloc(vf->priv->temp_stride*(height+16)*sizeof(int16_t));
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
213 vf->priv->src = malloc(vf->priv->temp_stride*(height+16)*sizeof(uint8_t));
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
214
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
215 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
216 }
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
217
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
218 static void get_image(struct vf_instance_s* vf, mp_image_t *mpi){
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
219 if(mpi->flags&MP_IMGFLAG_PRESERVE) return; // don't change
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
220 if(mpi->imgfmt!=vf->priv->outfmt) return; // colorspace differ
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
221 // ok, we can do pp in-place (or pp disabled):
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
222 vf->dmpi=vf_get_image(vf->next,mpi->imgfmt,
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
223 mpi->type, mpi->flags, mpi->w, mpi->h);
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
224 mpi->planes[0]=vf->dmpi->planes[0];
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
225 mpi->stride[0]=vf->dmpi->stride[0];
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
226 mpi->width=vf->dmpi->width;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
227 if(mpi->flags&MP_IMGFLAG_PLANAR){
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
228 mpi->planes[1]=vf->dmpi->planes[1];
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
229 mpi->planes[2]=vf->dmpi->planes[2];
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
230 mpi->stride[1]=vf->dmpi->stride[1];
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
231 mpi->stride[2]=vf->dmpi->stride[2];
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
232 }
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
233 mpi->flags|=MP_IMGFLAG_DIRECT;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
234 }
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
235
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
236 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi){
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
237 mp_image_t *dmpi;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
238
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
239 if(!(mpi->flags&MP_IMGFLAG_DIRECT)){
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
240 // no DR, so get a new image! hope we'll get DR buffer:
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
241 vf->dmpi=vf_get_image(vf->next,vf->priv->outfmt,
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
242 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
243 mpi->w,mpi->h);
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
244 }
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
245
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
246 dmpi= vf->dmpi;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
247
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
248 vf->priv->mpeg2= mpi->qscale_type;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
249
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
250 filter(vf->priv, dmpi->planes[0], mpi->planes[0], dmpi->stride[0], mpi->stride[0], mpi->w, mpi->h, mpi->qscale, mpi->qstride, 1);
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
251 filter(vf->priv, dmpi->planes[1], mpi->planes[1], dmpi->stride[1], mpi->stride[1], mpi->w>>1, mpi->h>>1, mpi->qscale, mpi->qstride, 0);
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
252 filter(vf->priv, dmpi->planes[2], mpi->planes[2], dmpi->stride[2], mpi->stride[2], mpi->w>>1, mpi->h>>1, mpi->qscale, mpi->qstride, 0);
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
253
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
254 vf_clone_mpi_attributes(dmpi, mpi);
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
255
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
256 #ifdef HAVE_MMX
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
257 if(gCpuCaps.hasMMX) asm volatile ("emms\n\t");
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
258 #endif
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
259 #ifdef HAVE_MMX2
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
260 if(gCpuCaps.hasMMX2) asm volatile ("sfence\n\t");
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
261 #endif
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
262
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
263 return vf_next_put_image(vf,dmpi);
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
264 }
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
265
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
266 static void uninit(struct vf_instance_s* vf){
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
267 if(!vf->priv) return;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
268
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
269 if(vf->priv->temp) free(vf->priv->temp);
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
270 vf->priv->temp= NULL;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
271 if(vf->priv->src) free(vf->priv->src);
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
272 vf->priv->src= NULL;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
273 if(vf->priv->avctx) free(vf->priv->avctx);
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
274 vf->priv->avctx= NULL;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
275
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
276 free(vf->priv);
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
277 vf->priv=NULL;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
278 }
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
279
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
280 //===========================================================================//
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
281
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
282 static int query_format(struct vf_instance_s* vf, unsigned int fmt){
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
283 switch(fmt)
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
284 {
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
285 case IMGFMT_YV12:
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
286 case IMGFMT_I420:
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
287 case IMGFMT_IYUV:
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
288 return vf_next_query_format(vf,vf->priv->outfmt);
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
289 }
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
290 return 0;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
291 }
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
292
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
293 static unsigned int fmt_list[]={
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
294 IMGFMT_YV12,
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
295 IMGFMT_I420,
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
296 IMGFMT_IYUV,
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
297 0
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
298 };
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
299
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
300 static int open(vf_instance_t *vf, char* args){
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
301 vf->config=config;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
302 vf->put_image=put_image;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
303 vf->get_image=get_image;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
304 vf->query_format=query_format;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
305 vf->uninit=uninit;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
306 vf->priv=malloc(sizeof(struct vf_priv_s));
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
307 memset(vf->priv, 0, sizeof(struct vf_priv_s));
11280
b677102fa650 10l and minor optimization
michael
parents: 11277
diff changeset
308
b677102fa650 10l and minor optimization
michael
parents: 11277
diff changeset
309 avcodec_init();
b677102fa650 10l and minor optimization
michael
parents: 11277
diff changeset
310
11277
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
311 vf->priv->avctx= avcodec_alloc_context();
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
312 dsputil_init(&vf->priv->dsp, vf->priv->avctx);
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
313
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
314 vf->priv->log2_count= 6;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
315
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
316 if (args) sscanf(args, "%d:%d", &vf->priv->log2_count, &vf->priv->qp);
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
317
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
318 // check csp:
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
319 vf->priv->outfmt=vf_match_csp(&vf->next,fmt_list,IMGFMT_YV12);
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
320 if(!vf->priv->outfmt)
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
321 {
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
322 uninit(vf);
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
323 return 0; // no csp match :(
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
324 }
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
325
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
326 return 1;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
327 }
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
328
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
329 vf_info_t vf_info_spp = {
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
330 "simple postprocess",
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
331 "spp",
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
332 "Michael Niedermayer",
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
333 "",
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
334 open,
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
335 NULL
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
336 };
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
337
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
338 //===========================================================================//