2 * Copyright (C) 2004 Michael Niedermayer <michaelni@gmx.at>
4 * This file is part of MPlayer.
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.
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.
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.
30 #include "cpudetect.h"
31 #include "img_format.h"
34 #include "libvo/fastmemcpy.h"
36 #include "libavcodec/avcodec.h"
37 #include "libavcodec/eval.h"
51 static int config(struct vf_instance_s
* vf
,
52 int width
, int height
, int d_width
, int d_height
,
53 unsigned int flags
, unsigned int outfmt
){
54 int h
= (height
+15)>>4;
57 vf
->priv
->qp_stride
= (width
+15)>>4;
58 vf
->priv
->qp
= av_malloc(vf
->priv
->qp_stride
*h
*sizeof(int8_t));
60 for(i
=-129; i
<128; i
++){
61 double const_values
[]={
68 static const char *const_names
[]={
76 const char *error
= NULL
;
77 vf
->priv
->lut
[i
+129]= lrintf(ff_eval2(vf
->priv
->eq
, const_values
, const_names
, NULL
, NULL
, NULL
, NULL
, NULL
, &error
));
79 mp_msg(MSGT_VFILTER
, MSGL_ERR
, "qp: Error evaluating \"%s\": %s\n", vf
->priv
->eq
, error
);
82 return vf_next_config(vf
,width
,height
,d_width
,d_height
,flags
,outfmt
);
85 static void get_image(struct vf_instance_s
* vf
, mp_image_t
*mpi
){
86 if(mpi
->flags
&MP_IMGFLAG_PRESERVE
) return; // don't change
87 // ok, we can do pp in-place (or pp disabled):
88 vf
->dmpi
=vf_get_image(vf
->next
,mpi
->imgfmt
,
89 mpi
->type
, mpi
->flags
, mpi
->w
, mpi
->h
);
90 mpi
->planes
[0]=vf
->dmpi
->planes
[0];
91 mpi
->stride
[0]=vf
->dmpi
->stride
[0];
92 mpi
->width
=vf
->dmpi
->width
;
93 if(mpi
->flags
&MP_IMGFLAG_PLANAR
){
94 mpi
->planes
[1]=vf
->dmpi
->planes
[1];
95 mpi
->planes
[2]=vf
->dmpi
->planes
[2];
96 mpi
->stride
[1]=vf
->dmpi
->stride
[1];
97 mpi
->stride
[2]=vf
->dmpi
->stride
[2];
99 mpi
->flags
|=MP_IMGFLAG_DIRECT
;
102 static int put_image(struct vf_instance_s
* vf
, mp_image_t
*mpi
, double pts
){
106 if(!(mpi
->flags
&MP_IMGFLAG_DIRECT
)){
107 // no DR, so get a new image! hope we'll get DR buffer:
108 vf
->dmpi
=vf_get_image(vf
->next
,mpi
->imgfmt
,
109 MP_IMGTYPE_TEMP
, MP_IMGFLAG_ACCEPT_STRIDE
|MP_IMGFLAG_PREFER_ALIGNED_STRIDE
,
115 if(!(mpi
->flags
&MP_IMGFLAG_DIRECT
)){
116 memcpy_pic(dmpi
->planes
[0], mpi
->planes
[0], mpi
->w
, mpi
->h
, dmpi
->stride
[0], mpi
->stride
[0]);
117 if(mpi
->flags
&MP_IMGFLAG_PLANAR
){
118 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]);
119 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]);
122 vf_clone_mpi_attributes(dmpi
, mpi
);
124 dmpi
->qscale
= vf
->priv
->qp
;
125 dmpi
->qstride
= vf
->priv
->qp_stride
;
127 for(y
=0; y
<((dmpi
->h
+15)>>4); y
++){
128 for(x
=0; x
<vf
->priv
->qp_stride
; x
++){
129 dmpi
->qscale
[x
+ dmpi
->qstride
*y
]=
130 vf
->priv
->lut
[ 129 + ((int8_t)mpi
->qscale
[x
+ mpi
->qstride
*y
]) ];
134 int qp
= vf
->priv
->lut
[0];
135 for(y
=0; y
<((dmpi
->h
+15)>>4); y
++){
136 for(x
=0; x
<vf
->priv
->qp_stride
; x
++){
137 dmpi
->qscale
[x
+ dmpi
->qstride
*y
]= qp
;
142 return vf_next_put_image(vf
,dmpi
, pts
);
145 static void uninit(struct vf_instance_s
* vf
){
146 if(!vf
->priv
) return;
148 if(vf
->priv
->qp
) av_free(vf
->priv
->qp
);
155 //===========================================================================//
156 static int open(vf_instance_t
*vf
, char* args
){
158 vf
->put_image
=put_image
;
159 vf
->get_image
=get_image
;
161 vf
->priv
=av_malloc(sizeof(struct vf_priv_s
));
162 memset(vf
->priv
, 0, sizeof(struct vf_priv_s
));
166 if (args
) strncpy(vf
->priv
->eq
, args
, 199);
171 const vf_info_t vf_info_qp
= {
174 "Michael Niedermayer",