annotate libmpcodecs/vf_pp.c @ 5939:65ee86f5a45f

avid mjpeg support (external huffman table)
author alex
date Thu, 02 May 2002 12:24:53 +0000
parents 1972c3475d93
children 255b150a75a5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5512
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
1 #include <stdio.h>
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
2 #include <stdlib.h>
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
3 #include <string.h>
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
4
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
5 #include "../config.h"
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
6 #include "../mp_msg.h"
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
7
5607
1972c3475d93 mp_image.h and img_format.h moved to libmpcodecs
arpi
parents: 5565
diff changeset
8 #include "img_format.h"
1972c3475d93 mp_image.h and img_format.h moved to libmpcodecs
arpi
parents: 5565
diff changeset
9 #include "mp_image.h"
5512
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
10 #include "vf.h"
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
11
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
12 #include "../postproc/postprocess.h"
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
13
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
14 struct vf_priv_s {
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
15 unsigned int pp;
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
16 mp_image_t *dmpi;
5565
0b301fec999a capabilities support -> automatic insertion of scale, expand, pp
arpi
parents: 5519
diff changeset
17 unsigned int outfmt;
5512
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
18 };
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
19
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
20 //===========================================================================//
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
21
5565
0b301fec999a capabilities support -> automatic insertion of scale, expand, pp
arpi
parents: 5519
diff changeset
22 static int config(struct vf_instance_s* vf,
0b301fec999a capabilities support -> automatic insertion of scale, expand, pp
arpi
parents: 5519
diff changeset
23 int width, int height, int d_width, int d_height,
0b301fec999a capabilities support -> automatic insertion of scale, expand, pp
arpi
parents: 5519
diff changeset
24 unsigned int voflags, unsigned int outfmt){
0b301fec999a capabilities support -> automatic insertion of scale, expand, pp
arpi
parents: 5519
diff changeset
25 return vf_next_config(vf,width,height,d_width,d_height,voflags,vf->priv->outfmt);
0b301fec999a capabilities support -> automatic insertion of scale, expand, pp
arpi
parents: 5519
diff changeset
26 }
0b301fec999a capabilities support -> automatic insertion of scale, expand, pp
arpi
parents: 5519
diff changeset
27
5518
04a40454bdbb accept only 4:2:0 planar yuv formats
arpi
parents: 5514
diff changeset
28 static int query_format(struct vf_instance_s* vf, unsigned int fmt){
04a40454bdbb accept only 4:2:0 planar yuv formats
arpi
parents: 5514
diff changeset
29 switch(fmt){
04a40454bdbb accept only 4:2:0 planar yuv formats
arpi
parents: 5514
diff changeset
30 case IMGFMT_YV12:
04a40454bdbb accept only 4:2:0 planar yuv formats
arpi
parents: 5514
diff changeset
31 case IMGFMT_I420:
04a40454bdbb accept only 4:2:0 planar yuv formats
arpi
parents: 5514
diff changeset
32 case IMGFMT_IYUV:
5565
0b301fec999a capabilities support -> automatic insertion of scale, expand, pp
arpi
parents: 5519
diff changeset
33 return vf_next_query_format(vf,vf->priv->outfmt);
5518
04a40454bdbb accept only 4:2:0 planar yuv formats
arpi
parents: 5514
diff changeset
34 }
04a40454bdbb accept only 4:2:0 planar yuv formats
arpi
parents: 5514
diff changeset
35 return 0;
04a40454bdbb accept only 4:2:0 planar yuv formats
arpi
parents: 5514
diff changeset
36 }
04a40454bdbb accept only 4:2:0 planar yuv formats
arpi
parents: 5514
diff changeset
37
5519
868c13f78f08 vf control codes added, autoq support
arpi
parents: 5518
diff changeset
38 static int control(struct vf_instance_s* vf, int request, void* data){
868c13f78f08 vf control codes added, autoq support
arpi
parents: 5518
diff changeset
39 switch(request){
868c13f78f08 vf control codes added, autoq support
arpi
parents: 5518
diff changeset
40 case VFCTRL_QUERY_MAX_PP_LEVEL:
868c13f78f08 vf control codes added, autoq support
arpi
parents: 5518
diff changeset
41 return GET_PP_QUALITY_MAX;
868c13f78f08 vf control codes added, autoq support
arpi
parents: 5518
diff changeset
42 case VFCTRL_SET_PP_LEVEL:
868c13f78f08 vf control codes added, autoq support
arpi
parents: 5518
diff changeset
43 vf->priv->pp=getPpModeForQuality(*((unsigned int*)data));
868c13f78f08 vf control codes added, autoq support
arpi
parents: 5518
diff changeset
44 return CONTROL_TRUE;
868c13f78f08 vf control codes added, autoq support
arpi
parents: 5518
diff changeset
45 }
868c13f78f08 vf control codes added, autoq support
arpi
parents: 5518
diff changeset
46 return vf_next_control(vf,request,data);
868c13f78f08 vf control codes added, autoq support
arpi
parents: 5518
diff changeset
47 }
868c13f78f08 vf control codes added, autoq support
arpi
parents: 5518
diff changeset
48
5512
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
49 static void get_image(struct vf_instance_s* vf, mp_image_t *mpi){
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
50 if(vf->priv->pp&0xFFFF) return; // non-local filters enabled
5513
73696051e3ce mpeg+pp0 fixed
arpi
parents: 5512
diff changeset
51 if((mpi->type==MP_IMGTYPE_IPB || vf->priv->pp) &&
73696051e3ce mpeg+pp0 fixed
arpi
parents: 5512
diff changeset
52 mpi->flags&MP_IMGFLAG_PRESERVE) return; // don't change
5565
0b301fec999a capabilities support -> automatic insertion of scale, expand, pp
arpi
parents: 5519
diff changeset
53 if(!(mpi->flags&MP_IMGFLAG_ACCEPT_STRIDE) && mpi->imgfmt!=vf->priv->outfmt)
0b301fec999a capabilities support -> automatic insertion of scale, expand, pp
arpi
parents: 5519
diff changeset
54 return; // colorspace differ
5512
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
55 // ok, we can do pp in-place (or pp disabled):
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
56 vf->priv->dmpi=vf_get_image(vf->next,mpi->imgfmt,
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
57 mpi->type, mpi->flags, mpi->w, mpi->h);
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
58 mpi->planes[0]=vf->priv->dmpi->planes[0];
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
59 mpi->stride[0]=vf->priv->dmpi->stride[0];
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
60 mpi->width=vf->priv->dmpi->width;
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
61 if(mpi->flags&MP_IMGFLAG_PLANAR){
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
62 mpi->planes[1]=vf->priv->dmpi->planes[1];
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
63 mpi->planes[2]=vf->priv->dmpi->planes[2];
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
64 mpi->stride[1]=vf->priv->dmpi->stride[1];
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
65 mpi->stride[2]=vf->priv->dmpi->stride[2];
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
66 }
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
67 mpi->flags|=MP_IMGFLAG_DIRECT;
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
68 }
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
69
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
70 static void put_image(struct vf_instance_s* vf, mp_image_t *mpi){
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
71 if(!(mpi->flags&MP_IMGFLAG_DIRECT)){
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
72 // no DR, so get a new image! hope we'll get DR buffer:
5565
0b301fec999a capabilities support -> automatic insertion of scale, expand, pp
arpi
parents: 5519
diff changeset
73 vf->priv->dmpi=vf_get_image(vf->next,vf->priv->outfmt,
5512
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
74 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_ALIGNED_STRIDE,
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
75 mpi->w,mpi->h);
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
76 }
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
77
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
78 if(vf->priv->pp || !(mpi->flags&MP_IMGFLAG_DIRECT)){
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
79 // do the postprocessing! (or copy if no DR)
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
80 postprocess(mpi->planes,mpi->stride[0],
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
81 vf->priv->dmpi->planes,vf->priv->dmpi->stride[0],
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
82 mpi->w,mpi->h,
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
83 mpi->qscale, mpi->qstride,
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
84 vf->priv->pp);
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
85 }
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
86
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
87 vf_next_put_image(vf,vf->priv->dmpi);
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
88 }
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
89
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
90 //===========================================================================//
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
91
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
92 extern int divx_quality;
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
93
5565
0b301fec999a capabilities support -> automatic insertion of scale, expand, pp
arpi
parents: 5519
diff changeset
94 static unsigned int fmt_list[]={
0b301fec999a capabilities support -> automatic insertion of scale, expand, pp
arpi
parents: 5519
diff changeset
95 IMGFMT_YV12,
0b301fec999a capabilities support -> automatic insertion of scale, expand, pp
arpi
parents: 5519
diff changeset
96 IMGFMT_I420,
0b301fec999a capabilities support -> automatic insertion of scale, expand, pp
arpi
parents: 5519
diff changeset
97 IMGFMT_IYUV,
0b301fec999a capabilities support -> automatic insertion of scale, expand, pp
arpi
parents: 5519
diff changeset
98 NULL
0b301fec999a capabilities support -> automatic insertion of scale, expand, pp
arpi
parents: 5519
diff changeset
99 };
0b301fec999a capabilities support -> automatic insertion of scale, expand, pp
arpi
parents: 5519
diff changeset
100
5512
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
101 static int open(vf_instance_t *vf, char* args){
5514
127f2a84e933 accept -pp value from args
arpi
parents: 5513
diff changeset
102 char *endptr;
5518
04a40454bdbb accept only 4:2:0 planar yuv formats
arpi
parents: 5514
diff changeset
103 vf->query_format=query_format;
5519
868c13f78f08 vf control codes added, autoq support
arpi
parents: 5518
diff changeset
104 vf->control=control;
5565
0b301fec999a capabilities support -> automatic insertion of scale, expand, pp
arpi
parents: 5519
diff changeset
105 vf->config=config;
5512
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
106 vf->get_image=get_image;
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
107 vf->put_image=put_image;
5565
0b301fec999a capabilities support -> automatic insertion of scale, expand, pp
arpi
parents: 5519
diff changeset
108 vf->default_caps=VFCAP_ACCEPT_STRIDE|VFCAP_POSTPROC;
5512
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
109 vf->priv=malloc(sizeof(struct vf_priv_s));
5565
0b301fec999a capabilities support -> automatic insertion of scale, expand, pp
arpi
parents: 5519
diff changeset
110
0b301fec999a capabilities support -> automatic insertion of scale, expand, pp
arpi
parents: 5519
diff changeset
111 // check csp:
0b301fec999a capabilities support -> automatic insertion of scale, expand, pp
arpi
parents: 5519
diff changeset
112 vf->priv->outfmt=vf_match_csp(&vf->next,fmt_list,IMGFMT_YV12);
0b301fec999a capabilities support -> automatic insertion of scale, expand, pp
arpi
parents: 5519
diff changeset
113 if(!vf->priv->outfmt) return 0; // no csp match :(
0b301fec999a capabilities support -> automatic insertion of scale, expand, pp
arpi
parents: 5519
diff changeset
114
5514
127f2a84e933 accept -pp value from args
arpi
parents: 5513
diff changeset
115 if(args){
127f2a84e933 accept -pp value from args
arpi
parents: 5513
diff changeset
116 vf->priv->pp=strtol(args, &endptr, 0);
127f2a84e933 accept -pp value from args
arpi
parents: 5513
diff changeset
117 if(!(*endptr)) return 1;
127f2a84e933 accept -pp value from args
arpi
parents: 5513
diff changeset
118 }
5512
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
119 vf->priv->pp=divx_quality;
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
120 return 1;
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
121 }
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
122
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
123 vf_info_t vf_info_pp = {
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
124 "postprocessing",
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
125 "pp",
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
126 "A'rpi",
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
127 "",
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
128 open
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
129 };
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
130
4ccfa77d8e86 postprocessing filter (fixme: -pp 0)
arpi
parents:
diff changeset
131 //===========================================================================//