Mercurial > mplayer.hg
comparison libmpcodecs/vf_palette.c @ 7160:447066802e64
added bgr support and support for forcing output format
author | alex |
---|---|
date | Fri, 30 Aug 2002 11:18:20 +0000 |
parents | 1e47c2e7aa8e |
children | e7ddd1923b67 |
comparison
equal
deleted
inserted
replaced
7159:1df24fd752d0 | 7160:447066802e64 |
---|---|
39 else if(fmt==IMGFMT_RGB8) p=rgb_list; | 39 else if(fmt==IMGFMT_RGB8) p=rgb_list; |
40 else return 0; | 40 else return 0; |
41 while(*p){ | 41 while(*p){ |
42 ret=vf->next->query_format(vf->next,*p); | 42 ret=vf->next->query_format(vf->next,*p); |
43 mp_msg(MSGT_VFILTER,MSGL_V,"[%s] query(%s) -> %d\n",vf->info->name,vo_format_name(*p),ret&3); | 43 mp_msg(MSGT_VFILTER,MSGL_V,"[%s] query(%s) -> %d\n",vf->info->name,vo_format_name(*p),ret&3); |
44 if(ret&2){ best=*p; break;} // no conversion -> bingo! | 44 if(ret&VFCAP_CSP_SUPPORTED_BY_HW){ best=*p; break;} // no conversion -> bingo! |
45 if(ret&1 && !best) best=*p; // best with conversion | 45 if(ret&VFCAP_CSP_SUPPORTED && !best) best=*p; // best with conversion |
46 ++p; | 46 ++p; |
47 } | 47 } |
48 return best; | 48 return best; |
49 } | 49 } |
50 | 50 |
55 }; | 55 }; |
56 | 56 |
57 static int config(struct vf_instance_s* vf, | 57 static int config(struct vf_instance_s* vf, |
58 int width, int height, int d_width, int d_height, | 58 int width, int height, int d_width, int d_height, |
59 unsigned int flags, unsigned int outfmt){ | 59 unsigned int flags, unsigned int outfmt){ |
60 vf->priv->fmt=find_best(vf,outfmt); | 60 if (!vf->priv->fmt) |
61 vf->priv->fmt=find_best(vf,outfmt); | |
61 if(!vf->priv->fmt){ | 62 if(!vf->priv->fmt){ |
62 // no matching fmt, so force one... | 63 // no matching fmt, so force one... |
63 if(outfmt==IMGFMT_RGB8) vf->priv->fmt=IMGFMT_RGB32; | 64 if(outfmt==IMGFMT_RGB8) vf->priv->fmt=IMGFMT_RGB32; |
64 else if(outfmt==IMGFMT_BGR8) vf->priv->fmt=IMGFMT_BGR32; | 65 else if(outfmt==IMGFMT_BGR8) vf->priv->fmt=IMGFMT_BGR32; |
65 else return 0; | 66 else return 0; |
68 } | 69 } |
69 | 70 |
70 static void put_image(struct vf_instance_s* vf, mp_image_t *mpi){ | 71 static void put_image(struct vf_instance_s* vf, mp_image_t *mpi){ |
71 mp_image_t *dmpi; | 72 mp_image_t *dmpi; |
72 | 73 |
73 if (!mpi->planes[1]) | |
74 { | |
75 mp_msg(MSGT_VFILTER,MSGL_V,"[%s] no palette given\n",vf->info->name); | |
76 return; | |
77 } | |
78 | |
79 // hope we'll get DR buffer: | 74 // hope we'll get DR buffer: |
80 dmpi=vf_get_image(vf->next,vf->priv->fmt, | 75 dmpi=vf_get_image(vf->next,vf->priv->fmt, |
81 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, | 76 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, |
82 mpi->w, mpi->h); | 77 mpi->w, mpi->h); |
83 | 78 |
84 if(!mpi->planes[1]) mpi->planes[1]=(unsigned char*)gray_pal; | 79 if (!mpi->planes[1]) |
80 { | |
81 mp_msg(MSGT_VFILTER,MSGL_V,"[%s] no palette given, assuming builtin grayscale one\n",vf->info->name); | |
82 mpi->planes[1] = (unsigned char*)gray_pal; | |
83 } | |
85 | 84 |
86 if(mpi->w==mpi->stride[0] && dmpi->w*(dmpi->bpp>>3)==dmpi->stride[0]){ | 85 if(mpi->w==mpi->stride[0] && dmpi->w*(dmpi->bpp>>3)==dmpi->stride[0]){ |
87 // no stride conversion needed | 86 // no stride conversion needed |
88 switch(dmpi->imgfmt&255){ | 87 switch(dmpi->imgfmt&255){ |
89 case 15: | 88 case 15: |
90 palette8torgb15(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]); | 89 if (mpi->flags & MP_IMGFLAG_SWAPPED) |
90 palette8tobgr15(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]); | |
91 else | |
92 palette8torgb15(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]); | |
91 break; | 93 break; |
92 case 16: | 94 case 16: |
93 palette8torgb16(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]); | 95 if (mpi->flags & MP_IMGFLAG_SWAPPED) |
96 palette8tobgr16(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]); | |
97 else | |
98 palette8torgb16(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]); | |
94 break; | 99 break; |
95 case 24: | 100 case 24: |
96 palette8torgb24(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]); | 101 if (mpi->flags & MP_IMGFLAG_SWAPPED) |
102 palette8tobgr24(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]); | |
103 else | |
104 palette8torgb24(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]); | |
97 break; | 105 break; |
98 case 32: | 106 case 32: |
99 palette8torgb32(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]); | 107 if (mpi->flags & MP_IMGFLAG_SWAPPED) |
108 palette8tobgr32(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]); | |
109 else | |
110 palette8torgb32(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]); | |
100 break; | 111 break; |
101 } | 112 } |
102 } else { | 113 } else { |
103 int y; | 114 int y; |
104 for(y=0;y<mpi->h;y++){ | 115 for(y=0;y<mpi->h;y++){ |
105 unsigned char* src=mpi->planes[0]+y*mpi->stride[0]; | 116 unsigned char* src=mpi->planes[0]+y*mpi->stride[0]; |
106 unsigned char* dst=dmpi->planes[0]+y*dmpi->stride[0]; | 117 unsigned char* dst=dmpi->planes[0]+y*dmpi->stride[0]; |
107 switch(dmpi->imgfmt&255){ | 118 switch(dmpi->imgfmt&255){ |
108 case 15: | 119 case 15: |
109 palette8torgb15(src,dst,mpi->w,mpi->planes[1]);break; | 120 if (mpi->flags & MP_IMGFLAG_SWAPPED) |
121 palette8tobgr15(src,dst,mpi->w,mpi->planes[1]); | |
122 else | |
123 palette8torgb15(src,dst,mpi->w,mpi->planes[1]); | |
124 break; | |
110 case 16: | 125 case 16: |
111 palette8torgb16(src,dst,mpi->w,mpi->planes[1]);break; | 126 if (mpi->flags & MP_IMGFLAG_SWAPPED) |
127 palette8tobgr16(src,dst,mpi->w,mpi->planes[1]); | |
128 else | |
129 palette8torgb16(src,dst,mpi->w,mpi->planes[1]); | |
130 break; | |
112 case 24: | 131 case 24: |
113 palette8torgb24(src,dst,mpi->w,mpi->planes[1]);break; | 132 if (mpi->flags & MP_IMGFLAG_SWAPPED) |
133 palette8tobgr24(src,dst,mpi->w,mpi->planes[1]); | |
134 else | |
135 palette8torgb24(src,dst,mpi->w,mpi->planes[1]); | |
136 break; | |
114 case 32: | 137 case 32: |
115 palette8torgb32(src,dst,mpi->w,mpi->planes[1]);break; | 138 if (mpi->flags & MP_IMGFLAG_SWAPPED) |
139 palette8tobgr32(src,dst,mpi->w,mpi->planes[1]); | |
140 else | |
141 palette8torgb32(src,dst,mpi->w,mpi->planes[1]); | |
142 break; | |
116 } | 143 } |
117 } | 144 } |
118 } | 145 } |
119 | 146 |
120 vf_next_put_image(vf,dmpi); | 147 vf_next_put_image(vf,dmpi); |
132 unsigned int i; | 159 unsigned int i; |
133 vf->config=config; | 160 vf->config=config; |
134 vf->put_image=put_image; | 161 vf->put_image=put_image; |
135 vf->query_format=query_format; | 162 vf->query_format=query_format; |
136 vf->priv=malloc(sizeof(struct vf_priv_s)); | 163 vf->priv=malloc(sizeof(struct vf_priv_s)); |
164 memset(vf->priv, 0, sizeof(struct vf_priv_s)); | |
137 for(i=0;i<256;i++) gray_pal[i]=0x01010101*i; | 165 for(i=0;i<256;i++) gray_pal[i]=0x01010101*i; |
166 if (args) | |
167 { | |
168 if (!strcasecmp(args,"rgb15")) vf->priv->fmt=IMGFMT_RGB15; else | |
169 if (!strcasecmp(args,"rgb16")) vf->priv->fmt=IMGFMT_RGB16; else | |
170 if (!strcasecmp(args,"rgb24")) vf->priv->fmt=IMGFMT_RGB24; else | |
171 if (!strcasecmp(args,"rgb32")) vf->priv->fmt=IMGFMT_RGB32; else | |
172 if (!strcasecmp(args,"bgr15")) vf->priv->fmt=IMGFMT_BGR15; else | |
173 if (!strcasecmp(args,"bgr16")) vf->priv->fmt=IMGFMT_BGR16; else | |
174 if (!strcasecmp(args,"bgr24")) vf->priv->fmt=IMGFMT_BGR24; else | |
175 if (!strcasecmp(args,"bgr32")) vf->priv->fmt=IMGFMT_BGR32; else | |
176 { | |
177 printf("Unknown forced format name: '%s'\n", args); | |
178 return(0); | |
179 } | |
180 } | |
138 return 1; | 181 return 1; |
139 } | 182 } |
140 | 183 |
141 vf_info_t vf_info_palette = { | 184 vf_info_t vf_info_palette = { |
142 "8bpp indexed (using palette) -> BGR 15/16/24/32 conversion", | 185 "8bpp indexed (using palette) -> BGR 15/16/24/32 conversion", |
143 "palette", | 186 "palette", |
144 "A'rpi", | 187 "A'rpi & Alex", |
145 "", | 188 "", |
146 open | 189 open |
147 }; | 190 }; |
148 | 191 |
149 //===========================================================================// | 192 //===========================================================================// |