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