Mercurial > mplayer.hg
annotate libmpcodecs/vf_qp.c @ 35077:c9d302e5e4be
Fix translation of mouse coordinates when panscan is used.
author | reimar |
---|---|
date | Wed, 12 Sep 2012 21:03:45 +0000 |
parents | 9a5da0f0c0f6 |
children | d206960484fe |
rev | line source |
---|---|
11921 | 1 /* |
26727 | 2 * Copyright (C) 2004 Michael Niedermayer <michaelni@gmx.at> |
3 * | |
4 * This file is part of MPlayer. | |
5 * | |
6 * MPlayer is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
11 * MPlayer is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License along | |
17 * with MPlayer; if not, write to the Free Software Foundation, Inc., | |
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
19 */ | |
11921 | 20 |
21 #include <stdio.h> | |
22 #include <stdlib.h> | |
23 #include <string.h> | |
24 #include <math.h> | |
25 #include <inttypes.h> | |
26 | |
17012 | 27 #include "mp_msg.h" |
28 #include "cpudetect.h" | |
24974
6f05850b5fd1
Rearrange headers to get rid of an #undef and remove unnecessary headers.
diego
parents:
24972
diff
changeset
|
29 #include "img_format.h" |
6f05850b5fd1
Rearrange headers to get rid of an #undef and remove unnecessary headers.
diego
parents:
24972
diff
changeset
|
30 #include "mp_image.h" |
6f05850b5fd1
Rearrange headers to get rid of an #undef and remove unnecessary headers.
diego
parents:
24972
diff
changeset
|
31 #include "vf.h" |
6f05850b5fd1
Rearrange headers to get rid of an #undef and remove unnecessary headers.
diego
parents:
24972
diff
changeset
|
32 #include "libvo/fastmemcpy.h" |
11921 | 33 |
17012 | 34 #include "libavcodec/avcodec.h" |
31256 | 35 #include "libavutil/eval.h" |
16677
044b85964c05
Compilation fix for systems lacking lrintf like e.g. NetBSD.
diego
parents:
11923
diff
changeset
|
36 |
11921 | 37 |
38 struct vf_priv_s { | |
32702
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
39 char eq[200]; |
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
40 int8_t *qp; |
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
41 int8_t lut[257]; |
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
42 int qp_stride; |
11921 | 43 }; |
44 | |
30642
a972c1a4a012
cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents:
30638
diff
changeset
|
45 static int config(struct vf_instance *vf, |
11921 | 46 int width, int height, int d_width, int d_height, |
32702
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
47 unsigned int flags, unsigned int outfmt){ |
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
48 int h= (height+15)>>4; |
11921 | 49 int i; |
50 | |
32702
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
51 vf->priv->qp_stride= (width+15)>>4; |
16677
044b85964c05
Compilation fix for systems lacking lrintf like e.g. NetBSD.
diego
parents:
11923
diff
changeset
|
52 vf->priv->qp= av_malloc(vf->priv->qp_stride*h*sizeof(int8_t)); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29087
diff
changeset
|
53 |
11921 | 54 for(i=-129; i<128; i++){ |
55 double const_values[]={ | |
56 M_PI, | |
57 M_E, | |
58 i != -129, | |
59 i, | |
60 0 | |
61 }; | |
62 static const char *const_names[]={ | |
63 "PI", | |
64 "E", | |
65 "known", | |
66 "qp", | |
67 NULL | |
68 }; | |
31130
d1f5069bef25
Fix compilation broken by FFmpeg-r23201 that changed the api of error logging.
iive
parents:
30989
diff
changeset
|
69 double temp_val; |
32702
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
70 int res; |
11921 | 71 |
33232 | 72 res= av_expr_parse_and_eval(&temp_val, vf->priv->eq, const_names, const_values, NULL, NULL, NULL, NULL, NULL, 0, NULL); |
31130
d1f5069bef25
Fix compilation broken by FFmpeg-r23201 that changed the api of error logging.
iive
parents:
30989
diff
changeset
|
73 |
31233 | 74 if (res < 0){ |
31130
d1f5069bef25
Fix compilation broken by FFmpeg-r23201 that changed the api of error logging.
iive
parents:
30989
diff
changeset
|
75 mp_msg(MSGT_VFILTER, MSGL_ERR, "qp: Error evaluating \"%s\" \n", vf->priv->eq); |
d1f5069bef25
Fix compilation broken by FFmpeg-r23201 that changed the api of error logging.
iive
parents:
30989
diff
changeset
|
76 return 0; |
d1f5069bef25
Fix compilation broken by FFmpeg-r23201 that changed the api of error logging.
iive
parents:
30989
diff
changeset
|
77 } |
d1f5069bef25
Fix compilation broken by FFmpeg-r23201 that changed the api of error logging.
iive
parents:
30989
diff
changeset
|
78 vf->priv->lut[i+129]= lrintf(temp_val); |
11921 | 79 } |
80 | |
32702
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
81 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); |
11921 | 82 } |
83 | |
30642
a972c1a4a012
cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents:
30638
diff
changeset
|
84 static void get_image(struct vf_instance *vf, mp_image_t *mpi){ |
11921 | 85 if(mpi->flags&MP_IMGFLAG_PRESERVE) return; // don't change |
86 // ok, we can do pp in-place (or pp disabled): | |
87 vf->dmpi=vf_get_image(vf->next,mpi->imgfmt, | |
88 mpi->type, mpi->flags, mpi->w, mpi->h); | |
89 mpi->planes[0]=vf->dmpi->planes[0]; | |
90 mpi->stride[0]=vf->dmpi->stride[0]; | |
91 mpi->width=vf->dmpi->width; | |
92 if(mpi->flags&MP_IMGFLAG_PLANAR){ | |
93 mpi->planes[1]=vf->dmpi->planes[1]; | |
94 mpi->planes[2]=vf->dmpi->planes[2]; | |
32702
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
95 mpi->stride[1]=vf->dmpi->stride[1]; |
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
96 mpi->stride[2]=vf->dmpi->stride[2]; |
11921 | 97 } |
98 mpi->flags|=MP_IMGFLAG_DIRECT; | |
99 } | |
100 | |
30642
a972c1a4a012
cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents:
30638
diff
changeset
|
101 static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){ |
32702
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
102 mp_image_t *dmpi; |
11921 | 103 int x,y; |
104 | |
32702
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
105 if(!(mpi->flags&MP_IMGFLAG_DIRECT)){ |
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
106 // no DR, so get a new image! hope we'll get DR buffer: |
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
107 vf->dmpi=vf_get_image(vf->next,mpi->imgfmt, |
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
108 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_PREFER_ALIGNED_STRIDE, |
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
109 mpi->w,mpi->h); |
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
110 } |
11921 | 111 |
32702
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
112 dmpi= vf->dmpi; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29087
diff
changeset
|
113 |
32702
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
114 if(!(mpi->flags&MP_IMGFLAG_DIRECT)){ |
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
115 memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h, dmpi->stride[0], mpi->stride[0]); |
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
116 if(mpi->flags&MP_IMGFLAG_PLANAR){ |
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
117 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]); |
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
118 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]); |
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
119 } |
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
120 } |
11921 | 121 vf_clone_mpi_attributes(dmpi, mpi); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29087
diff
changeset
|
122 |
11921 | 123 dmpi->qscale = vf->priv->qp; |
124 dmpi->qstride= vf->priv->qp_stride; | |
125 if(mpi->qscale){ | |
126 for(y=0; y<((dmpi->h+15)>>4); y++){ | |
127 for(x=0; x<vf->priv->qp_stride; x++){ | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29087
diff
changeset
|
128 dmpi->qscale[x + dmpi->qstride*y]= |
11921 | 129 vf->priv->lut[ 129 + ((int8_t)mpi->qscale[x + mpi->qstride*y]) ]; |
130 } | |
131 } | |
132 }else{ | |
133 int qp= vf->priv->lut[0]; | |
134 for(y=0; y<((dmpi->h+15)>>4); y++){ | |
135 for(x=0; x<vf->priv->qp_stride; x++){ | |
136 dmpi->qscale[x + dmpi->qstride*y]= qp; | |
137 } | |
138 } | |
139 } | |
140 | |
32702
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
141 return vf_next_put_image(vf,dmpi, pts); |
11921 | 142 } |
143 | |
30642
a972c1a4a012
cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents:
30638
diff
changeset
|
144 static void uninit(struct vf_instance *vf){ |
32702
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
145 if(!vf->priv) return; |
11921 | 146 |
32702
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
147 av_free(vf->priv->qp); |
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
148 vf->priv->qp= NULL; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29087
diff
changeset
|
149 |
32702
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
150 av_free(vf->priv); |
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
151 vf->priv=NULL; |
11921 | 152 } |
153 | |
154 //===========================================================================// | |
30638
a7b908875c14
Rename open() vf initialization function to vf_open().
diego
parents:
29263
diff
changeset
|
155 static int vf_open(vf_instance_t *vf, char *args){ |
11921 | 156 vf->config=config; |
157 vf->put_image=put_image; | |
158 vf->get_image=get_image; | |
159 vf->uninit=uninit; | |
16677
044b85964c05
Compilation fix for systems lacking lrintf like e.g. NetBSD.
diego
parents:
11923
diff
changeset
|
160 vf->priv=av_malloc(sizeof(struct vf_priv_s)); |
11921 | 161 memset(vf->priv, 0, sizeof(struct vf_priv_s)); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29087
diff
changeset
|
162 |
11921 | 163 // avcodec_init(); |
164 | |
165 if (args) strncpy(vf->priv->eq, args, 199); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29087
diff
changeset
|
166 |
11921 | 167 return 1; |
168 } | |
169 | |
25221 | 170 const vf_info_t vf_info_qp = { |
11921 | 171 "QP changer", |
172 "qp", | |
173 "Michael Niedermayer", | |
174 "", | |
30638
a7b908875c14
Rename open() vf initialization function to vf_open().
diego
parents:
29263
diff
changeset
|
175 vf_open, |
11921 | 176 NULL |
177 }; |