annotate libmpcodecs/vf_qp.c @ 12830:b177cc8afdc0

Fixed typo
author nplourde
date Fri, 16 Jul 2004 10:13:26 +0000
parents e9ab21c4db24
children 044b85964c05
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11921
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
1 /*
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
2 Copyright (C) 2004 Michael Niedermayer <michaelni@gmx.at>
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
3
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
4 This program is free software; you can redistribute it and/or modify
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
6 the Free Software Foundation; either version 2 of the License, or
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
7 (at your option) any later version.
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
8
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
12 GNU General Public License for more details.
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
13
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
15 along with this program; if not, write to the Free Software
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
17 */
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
18
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
19 #include <stdio.h>
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
20 #include <stdlib.h>
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
21 #include <string.h>
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
22 #include <math.h>
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
23 #include <inttypes.h>
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
24
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
25 #include "../config.h"
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
26
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
27 #ifdef USE_LIBAVCODEC
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
28
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
29 #include "../mp_msg.h"
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
30 #include "../cpudetect.h"
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
31
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
32 #if 1
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
33 double ff_eval(char *s, double *const_value, const char **const_name,
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
34 double (**func1)(void *, double), const char **func1_name,
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
35 double (**func2)(void *, double, double), char **func2_name,
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
36 void *opaque);
11923
e9ab21c4db24 #include dsputil.h as it contains the lrintf emu code
michael
parents: 11921
diff changeset
37 #endif
e9ab21c4db24 #include dsputil.h as it contains the lrintf emu code
michael
parents: 11921
diff changeset
38
11921
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
39 #ifdef USE_LIBAVCODEC_SO
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
40 #include <ffmpeg/avcodec.h>
11923
e9ab21c4db24 #include dsputil.h as it contains the lrintf emu code
michael
parents: 11921
diff changeset
41 #include <ffmpeg/dsputil.h>
11921
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
42 #else
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
43 #include "../libavcodec/avcodec.h"
11923
e9ab21c4db24 #include dsputil.h as it contains the lrintf emu code
michael
parents: 11921
diff changeset
44 #include "../libavcodec/dsputil.h"
11921
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
45 #endif
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
46
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
47 #ifdef HAVE_MALLOC_H
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
48 #include <malloc.h>
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
49 #endif
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
50
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
51 #include "img_format.h"
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
52 #include "mp_image.h"
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
53 #include "vf.h"
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
54 #include "../libvo/fastmemcpy.h"
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
55
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
56
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
57 struct vf_priv_s {
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
58 char eq[200];
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
59 int8_t *qp;
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
60 int8_t lut[257];
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
61 int qp_stride;
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
62 };
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
63
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
64 static int config(struct vf_instance_s* vf,
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
65 int width, int height, int d_width, int d_height,
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
66 unsigned int flags, unsigned int outfmt){
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
67 int h= (height+15)>>4;
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
68 int i;
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
69
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
70 vf->priv->qp_stride= (width+15)>>4;
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
71 vf->priv->qp= malloc(vf->priv->qp_stride*h*sizeof(int8_t));
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
72
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
73 for(i=-129; i<128; i++){
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
74 double const_values[]={
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
75 M_PI,
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
76 M_E,
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
77 i != -129,
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
78 i,
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
79 0
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
80 };
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
81 static const char *const_names[]={
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
82 "PI",
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
83 "E",
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
84 "known",
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
85 "qp",
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
86 NULL
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
87 };
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
88
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
89 vf->priv->lut[i+129]= lrintf(ff_eval(vf->priv->eq, const_values, const_names, NULL, NULL, NULL, NULL, NULL));
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
90 }
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
91
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
92 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
93 }
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
94
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
95 static void get_image(struct vf_instance_s* vf, mp_image_t *mpi){
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
96 if(mpi->flags&MP_IMGFLAG_PRESERVE) return; // don't change
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
97 // ok, we can do pp in-place (or pp disabled):
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
98 vf->dmpi=vf_get_image(vf->next,mpi->imgfmt,
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
99 mpi->type, mpi->flags, mpi->w, mpi->h);
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
100 mpi->planes[0]=vf->dmpi->planes[0];
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
101 mpi->stride[0]=vf->dmpi->stride[0];
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
102 mpi->width=vf->dmpi->width;
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
103 if(mpi->flags&MP_IMGFLAG_PLANAR){
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
104 mpi->planes[1]=vf->dmpi->planes[1];
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
105 mpi->planes[2]=vf->dmpi->planes[2];
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
106 mpi->stride[1]=vf->dmpi->stride[1];
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
107 mpi->stride[2]=vf->dmpi->stride[2];
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
108 }
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
109 mpi->flags|=MP_IMGFLAG_DIRECT;
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
110 }
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
111
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
112 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi){
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
113 mp_image_t *dmpi;
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
114 int x,y;
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
115
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
116 if(!(mpi->flags&MP_IMGFLAG_DIRECT)){
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
117 // no DR, so get a new image! hope we'll get DR buffer:
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
118 vf->dmpi=vf_get_image(vf->next,mpi->imgfmt,
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
119 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_PREFER_ALIGNED_STRIDE,
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
120 mpi->w,mpi->h);
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
121 }
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
122
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
123 dmpi= vf->dmpi;
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
124
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
125 if(!(mpi->flags&MP_IMGFLAG_DIRECT)){
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
126 memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h, dmpi->stride[0], mpi->stride[0]);
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
127 if(mpi->flags&MP_IMGFLAG_PLANAR){
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
128 memcpy_pic(dmpi->planes[1], mpi->planes[1], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, dmpi->stride[1], mpi->stride[1]);
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
129 memcpy_pic(dmpi->planes[2], mpi->planes[2], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, dmpi->stride[2], mpi->stride[2]);
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
130 }
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
131 }
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
132 vf_clone_mpi_attributes(dmpi, mpi);
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
133
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
134 dmpi->qscale = vf->priv->qp;
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
135 dmpi->qstride= vf->priv->qp_stride;
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
136 if(mpi->qscale){
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
137 for(y=0; y<((dmpi->h+15)>>4); y++){
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
138 for(x=0; x<vf->priv->qp_stride; x++){
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
139 dmpi->qscale[x + dmpi->qstride*y]=
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
140 vf->priv->lut[ 129 + ((int8_t)mpi->qscale[x + mpi->qstride*y]) ];
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
141 }
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
142 }
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
143 }else{
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
144 int qp= vf->priv->lut[0];
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
145 for(y=0; y<((dmpi->h+15)>>4); y++){
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
146 for(x=0; x<vf->priv->qp_stride; x++){
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
147 dmpi->qscale[x + dmpi->qstride*y]= qp;
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
148 }
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
149 }
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
150 }
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
151
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
152 return vf_next_put_image(vf,dmpi);
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
153 }
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
154
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
155 static void uninit(struct vf_instance_s* vf){
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
156 if(!vf->priv) return;
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
157
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
158 if(vf->priv->qp) free(vf->priv->qp);
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
159 vf->priv->qp= NULL;
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
160
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
161 free(vf->priv);
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
162 vf->priv=NULL;
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
163 }
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
164
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
165 //===========================================================================//
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
166 static int open(vf_instance_t *vf, char* args){
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
167 vf->config=config;
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
168 vf->put_image=put_image;
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
169 vf->get_image=get_image;
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
170 vf->uninit=uninit;
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
171 vf->priv=malloc(sizeof(struct vf_priv_s));
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
172 memset(vf->priv, 0, sizeof(struct vf_priv_s));
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
173
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
174 // avcodec_init();
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
175
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
176 if (args) strncpy(vf->priv->eq, args, 199);
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
177
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
178 return 1;
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
179 }
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
180
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
181 vf_info_t vf_info_qp = {
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
182 "QP changer",
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
183 "qp",
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
184 "Michael Niedermayer",
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
185 "",
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
186 open,
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
187 NULL
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
188 };
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
189
dd3ac91a86b5 qp change filter
michael
parents:
diff changeset
190 #endif //USE_LIBAVCODEC