annotate libmpcodecs/vf_spp.c @ 11296:86916e46d445

different / faster / simpler "quantization" filtered images look like with the old quantization (to me at least) if anyone notices a difference then tell me ASAP
author michael
date Mon, 27 Oct 2003 21:12:29 +0000
parents 8b9ae87aff0f
children 14dbc88adaf0
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 int bias= 0; //FIXME
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
90 unsigned int threshold1, threshold2;
11296
86916e46d445 different / faster / simpler "quantization"
michael
parents: 11295
diff changeset
91
86916e46d445 different / faster / simpler "quantization"
michael
parents: 11295
diff changeset
92 threshold1= qmul*((1<<3) - bias) - 1;
11277
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
93 threshold2= (threshold1<<1);
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
94
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
95 memset(dst, 0, 64*sizeof(DCTELEM));
11296
86916e46d445 different / faster / simpler "quantization"
michael
parents: 11295
diff changeset
96 dst[0]= (src[0] + 4)>>3;
11277
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
97
11296
86916e46d445 different / faster / simpler "quantization"
michael
parents: 11295
diff changeset
98 for(i=1; i<64; i++){
86916e46d445 different / faster / simpler "quantization"
michael
parents: 11295
diff changeset
99 int level= src[i];
11277
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
100 if(((unsigned)(level+threshold1))>threshold2){
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
101 const int j= permutation[i];
11296
86916e46d445 different / faster / simpler "quantization"
michael
parents: 11295
diff changeset
102 dst[j]= (level + 4)>>3;
11277
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
103 }
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
104 }
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
105 }
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
106
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
107 static inline void add_block(int16_t *dst, int stride, DCTELEM block[64]){
11280
b677102fa650 10l and minor optimization
michael
parents: 11277
diff changeset
108 int y;
11277
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
109
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
110 for(y=0; y<8; y++){
11280
b677102fa650 10l and minor optimization
michael
parents: 11277
diff changeset
111 *(uint32_t*)&dst[0 + y*stride]+= *(uint32_t*)&block[0 + y*8];
b677102fa650 10l and minor optimization
michael
parents: 11277
diff changeset
112 *(uint32_t*)&dst[2 + y*stride]+= *(uint32_t*)&block[2 + y*8];
b677102fa650 10l and minor optimization
michael
parents: 11277
diff changeset
113 *(uint32_t*)&dst[4 + y*stride]+= *(uint32_t*)&block[4 + y*8];
b677102fa650 10l and minor optimization
michael
parents: 11277
diff changeset
114 *(uint32_t*)&dst[6 + y*stride]+= *(uint32_t*)&block[6 + y*8];
11277
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
115 }
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
116 }
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
117
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
118 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
119 int x, y, i;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
120 const int count= 1<<p->log2_count;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
121 const int log2_scale= 6-p->log2_count;
11281
michael
parents: 11280
diff changeset
122 const int stride= p->temp_stride; //FIXME
11277
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
123 uint64_t block_align[32];
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
124 DCTELEM *block = (DCTELEM *)block_align;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
125 DCTELEM *block2= (DCTELEM *)(block_align+16);
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
126
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
127 for(y=0; y<height; y++){
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
128 memcpy(p->src + 8 + 8*stride + y*stride, src + y*src_stride, width);
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
129 memset(p->temp + 8*stride + y*stride, 0, stride*sizeof(int16_t));
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
130 for(x=0; x<8; x++){
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
131 int index= 8 + 8*stride + y*stride;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
132 p->src[index - x - 1]= p->src[index + x ];
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
133 p->src[index + width + x ]= p->src[index + width - x - 1];
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
134 }
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
135 }
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
136 for(y=0; y<8; y++){
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
137 memcpy(p->src + ( 7-y)*stride, p->src + ( y+8)*stride, stride);
11281
michael
parents: 11280
diff changeset
138 memcpy(p->src + (height+8+y)*stride, p->src + (height-y+7)*stride, stride);
11277
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
139 }
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
140 //FIXME (try edge emu)
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
141
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
142 for(y=0; y<height+8; y+=8){
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
143 for(x=0; x<width+8; x+=8){
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
144 const int qps= 3 + is_luma;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
145 int qp;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
146
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
147 if(p->qp)
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
148 qp= p->qp;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
149 else{
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
150 qp= qp_store[ (XMIN(x, width-1)>>qps) + (XMIN(y, height-1)>>qps) * qp_stride];
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
151 if(p->mpeg2) qp>>=1;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
152 }
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
153 for(i=0; i<count; i++){
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
154 const int x1= x + offset[i][0];
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
155 const int y1= y + offset[i][1];
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
156 const int index= x1 + y1*stride;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
157 p->dsp.get_pixels(block, p->src + index, stride);
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
158 p->dsp.fdct(block);
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
159 requantize(block2, block, qp, p->dsp.idct_permutation);
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
160 p->dsp.idct(block2);
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
161 add_block(p->temp + index, stride, block2);
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
162 }
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
163 }
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
164 }
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
165
11295
michael
parents: 11281
diff changeset
166 #define STORE(pos) \
michael
parents: 11281
diff changeset
167 temp= ((p->temp[index + pos]<<log2_scale) + d[pos])>>6;\
michael
parents: 11281
diff changeset
168 if(temp & 0x100) temp= ~(temp>>31);\
michael
parents: 11281
diff changeset
169 dst[x + y*dst_stride + pos]= temp;
michael
parents: 11281
diff changeset
170
11277
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
171 for(y=0; y<height; y++){
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
172 uint8_t *d= dither[y&7];
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
173 for(x=0; x<width; x+=8){
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
174 const int index= 8 + 8*stride + x + y*stride;
11295
michael
parents: 11281
diff changeset
175 int temp;
michael
parents: 11281
diff changeset
176 STORE(0);
michael
parents: 11281
diff changeset
177 STORE(1);
michael
parents: 11281
diff changeset
178 STORE(2);
michael
parents: 11281
diff changeset
179 STORE(3);
michael
parents: 11281
diff changeset
180 STORE(4);
michael
parents: 11281
diff changeset
181 STORE(5);
michael
parents: 11281
diff changeset
182 STORE(6);
michael
parents: 11281
diff changeset
183 STORE(7);
11277
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
184 }
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
185 }
11295
michael
parents: 11281
diff changeset
186 #if 0
michael
parents: 11281
diff changeset
187 for(y=0; y<height; y++){
michael
parents: 11281
diff changeset
188 for(x=0; x<width; x++){
michael
parents: 11281
diff changeset
189 if((((x>>6) ^ (y>>6)) & 1) == 0)
michael
parents: 11281
diff changeset
190 dst[x + y*dst_stride]= p->src[8 + 8*stride + x + y*stride];
michael
parents: 11281
diff changeset
191 if((x&63) == 0 || (y&63)==0)
michael
parents: 11281
diff changeset
192 dst[x + y*dst_stride] += 128;
michael
parents: 11281
diff changeset
193 }
michael
parents: 11281
diff changeset
194 }
michael
parents: 11281
diff changeset
195 #endif
11277
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
196 //FIXME reorder for better caching
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
197 }
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
198
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
199 static int config(struct vf_instance_s* vf,
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
200 int width, int height, int d_width, int d_height,
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
201 unsigned int flags, unsigned int outfmt){
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
202
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
203 vf->priv->temp_stride= (width+16+15)&(~15);
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
204 vf->priv->temp= malloc(vf->priv->temp_stride*(height+16)*sizeof(int16_t));
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
205 vf->priv->src = malloc(vf->priv->temp_stride*(height+16)*sizeof(uint8_t));
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
206
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
207 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
208 }
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
209
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
210 static void get_image(struct vf_instance_s* vf, mp_image_t *mpi){
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
211 if(mpi->flags&MP_IMGFLAG_PRESERVE) return; // don't change
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
212 if(mpi->imgfmt!=vf->priv->outfmt) return; // colorspace differ
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
213 // ok, we can do pp in-place (or pp disabled):
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
214 vf->dmpi=vf_get_image(vf->next,mpi->imgfmt,
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
215 mpi->type, mpi->flags, mpi->w, mpi->h);
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
216 mpi->planes[0]=vf->dmpi->planes[0];
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
217 mpi->stride[0]=vf->dmpi->stride[0];
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
218 mpi->width=vf->dmpi->width;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
219 if(mpi->flags&MP_IMGFLAG_PLANAR){
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
220 mpi->planes[1]=vf->dmpi->planes[1];
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
221 mpi->planes[2]=vf->dmpi->planes[2];
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
222 mpi->stride[1]=vf->dmpi->stride[1];
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
223 mpi->stride[2]=vf->dmpi->stride[2];
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
224 }
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
225 mpi->flags|=MP_IMGFLAG_DIRECT;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
226 }
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
227
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
228 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi){
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
229 mp_image_t *dmpi;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
230
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
231 if(!(mpi->flags&MP_IMGFLAG_DIRECT)){
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
232 // no DR, so get a new image! hope we'll get DR buffer:
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
233 vf->dmpi=vf_get_image(vf->next,vf->priv->outfmt,
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
234 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
235 mpi->w,mpi->h);
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
236 }
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
237
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
238 dmpi= vf->dmpi;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
239
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
240 vf->priv->mpeg2= mpi->qscale_type;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
241
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
242 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
243 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
244 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
245
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
246 vf_clone_mpi_attributes(dmpi, mpi);
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
247
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
248 #ifdef HAVE_MMX
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
249 if(gCpuCaps.hasMMX) asm volatile ("emms\n\t");
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
250 #endif
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
251 #ifdef HAVE_MMX2
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
252 if(gCpuCaps.hasMMX2) asm volatile ("sfence\n\t");
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
253 #endif
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
254
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
255 return vf_next_put_image(vf,dmpi);
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
256 }
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
257
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
258 static void uninit(struct vf_instance_s* vf){
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
259 if(!vf->priv) return;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
260
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
261 if(vf->priv->temp) free(vf->priv->temp);
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
262 vf->priv->temp= NULL;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
263 if(vf->priv->src) free(vf->priv->src);
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
264 vf->priv->src= NULL;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
265 if(vf->priv->avctx) free(vf->priv->avctx);
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
266 vf->priv->avctx= NULL;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
267
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
268 free(vf->priv);
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
269 vf->priv=NULL;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
270 }
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
271
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
272 //===========================================================================//
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
273
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
274 static int query_format(struct vf_instance_s* vf, unsigned int fmt){
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
275 switch(fmt)
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
276 {
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
277 case IMGFMT_YV12:
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
278 case IMGFMT_I420:
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
279 case IMGFMT_IYUV:
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
280 return vf_next_query_format(vf,vf->priv->outfmt);
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
281 }
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
282 return 0;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
283 }
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
284
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
285 static unsigned int fmt_list[]={
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
286 IMGFMT_YV12,
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
287 IMGFMT_I420,
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
288 IMGFMT_IYUV,
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
289 0
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
290 };
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
291
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
292 static int open(vf_instance_t *vf, char* args){
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
293 vf->config=config;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
294 vf->put_image=put_image;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
295 vf->get_image=get_image;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
296 vf->query_format=query_format;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
297 vf->uninit=uninit;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
298 vf->priv=malloc(sizeof(struct vf_priv_s));
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
299 memset(vf->priv, 0, sizeof(struct vf_priv_s));
11280
b677102fa650 10l and minor optimization
michael
parents: 11277
diff changeset
300
b677102fa650 10l and minor optimization
michael
parents: 11277
diff changeset
301 avcodec_init();
b677102fa650 10l and minor optimization
michael
parents: 11277
diff changeset
302
11277
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
303 vf->priv->avctx= avcodec_alloc_context();
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
304 dsputil_init(&vf->priv->dsp, vf->priv->avctx);
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
305
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
306 vf->priv->log2_count= 6;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
307
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
308 if (args) sscanf(args, "%d:%d", &vf->priv->log2_count, &vf->priv->qp);
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
309
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
310 // check csp:
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
311 vf->priv->outfmt=vf_match_csp(&vf->next,fmt_list,IMGFMT_YV12);
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
312 if(!vf->priv->outfmt)
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
313 {
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
314 uninit(vf);
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
315 return 0; // no csp match :(
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
316 }
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
317
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
318 return 1;
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
319 }
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
320
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
321 vf_info_t vf_info_spp = {
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
322 "simple postprocess",
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
323 "spp",
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
324 "Michael Niedermayer",
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
325 "",
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
326 open,
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
327 NULL
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
328 };
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
329
fffd200d81a7 simple alternative postprocessing filter
michael
parents:
diff changeset
330 //===========================================================================//