5774
|
1 #include <stdio.h>
|
|
2 #include <stdlib.h>
|
|
3 #include <string.h>
|
|
4 #include <inttypes.h>
|
|
5
|
|
6 #include "../config.h"
|
|
7 #include "../mp_msg.h"
|
|
8
|
|
9 #include "img_format.h"
|
|
10 #include "mp_image.h"
|
|
11 #include "vf.h"
|
|
12
|
|
13 #include "../postproc/rgb2rgb.h"
|
|
14
|
|
15 //===========================================================================//
|
|
16
|
|
17 static unsigned int bgr_list[]={
|
|
18 IMGFMT_BGR32,
|
|
19 IMGFMT_BGR24,
|
|
20 IMGFMT_BGR16,
|
|
21 IMGFMT_BGR15,
|
6188
|
22 0
|
5774
|
23 };
|
|
24 static unsigned int rgb_list[]={
|
|
25 IMGFMT_RGB32,
|
|
26 IMGFMT_RGB24,
|
|
27 IMGFMT_RGB16,
|
|
28 IMGFMT_RGB15,
|
6188
|
29 0
|
5774
|
30 };
|
|
31
|
6232
|
32 static unsigned int gray_pal[256];
|
|
33
|
5774
|
34 static unsigned int find_best(struct vf_instance_s* vf, unsigned int fmt){
|
|
35 unsigned int best=0;
|
|
36 int ret;
|
|
37 unsigned int* p;
|
|
38 if(fmt==IMGFMT_BGR8) p=bgr_list;
|
|
39 else if(fmt==IMGFMT_RGB8) p=rgb_list;
|
|
40 else return 0;
|
|
41 while(*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);
|
|
44 if(ret&2){ best=*p; break;} // no conversion -> bingo!
|
|
45 if(ret&1 && !best) best=*p; // best with conversion
|
|
46 ++p;
|
|
47 }
|
|
48 return best;
|
|
49 }
|
|
50
|
|
51 //===========================================================================//
|
|
52
|
|
53 struct vf_priv_s {
|
|
54 unsigned int fmt;
|
|
55 };
|
|
56
|
|
57 static int config(struct vf_instance_s* vf,
|
|
58 int width, int height, int d_width, int d_height,
|
|
59 unsigned int flags, unsigned int outfmt){
|
|
60 vf->priv->fmt=find_best(vf,outfmt);
|
|
61 if(!vf->priv->fmt){
|
|
62 // no matching fmt, so force one...
|
|
63 if(outfmt==IMGFMT_RGB8) vf->priv->fmt=IMGFMT_RGB32;
|
|
64 else if(outfmt==IMGFMT_BGR8) vf->priv->fmt=IMGFMT_BGR32;
|
|
65 else return 0;
|
|
66 }
|
|
67 return vf_next_config(vf,width,height,d_width,d_height,flags,vf->priv->fmt);
|
|
68 }
|
|
69
|
|
70 static void put_image(struct vf_instance_s* vf, mp_image_t *mpi){
|
|
71 mp_image_t *dmpi;
|
6481
|
72
|
|
73 if (!mpi->planes[1])
|
|
74 {
|
|
75 mp_msg(MSGT_VFILTER,MSGL_V,"[%s] no palette given\n",vf->info->name);
|
|
76 return;
|
|
77 }
|
5774
|
78
|
|
79 // hope we'll get DR buffer:
|
|
80 dmpi=vf_get_image(vf->next,vf->priv->fmt,
|
|
81 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
|
|
82 mpi->w, mpi->h);
|
|
83
|
7127
|
84 if(!mpi->planes[1]) mpi->planes[1]=(unsigned char*)gray_pal;
|
6232
|
85
|
5774
|
86 if(mpi->w==mpi->stride[0] && dmpi->w*(dmpi->bpp>>3)==dmpi->stride[0]){
|
|
87 // no stride conversion needed
|
|
88 switch(dmpi->imgfmt&255){
|
|
89 case 15:
|
|
90 palette8torgb15(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]);
|
|
91 break;
|
|
92 case 16:
|
|
93 palette8torgb16(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]);
|
|
94 break;
|
|
95 case 24:
|
|
96 palette8torgb24(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]);
|
|
97 break;
|
|
98 case 32:
|
|
99 palette8torgb32(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]);
|
|
100 break;
|
|
101 }
|
|
102 } else {
|
|
103 int y;
|
|
104 for(y=0;y<mpi->h;y++){
|
|
105 unsigned char* src=mpi->planes[0]+y*mpi->stride[0];
|
|
106 unsigned char* dst=dmpi->planes[0]+y*dmpi->stride[0];
|
|
107 switch(dmpi->imgfmt&255){
|
|
108 case 15:
|
|
109 palette8torgb15(src,dst,mpi->w,mpi->planes[1]);break;
|
|
110 case 16:
|
|
111 palette8torgb16(src,dst,mpi->w,mpi->planes[1]);break;
|
|
112 case 24:
|
|
113 palette8torgb24(src,dst,mpi->w,mpi->planes[1]);break;
|
|
114 case 32:
|
|
115 palette8torgb32(src,dst,mpi->w,mpi->planes[1]);break;
|
|
116 }
|
|
117 }
|
|
118 }
|
|
119
|
|
120 vf_next_put_image(vf,dmpi);
|
|
121 }
|
|
122
|
|
123 //===========================================================================//
|
|
124
|
|
125 static int query_format(struct vf_instance_s* vf, unsigned int fmt){
|
|
126 int best=find_best(vf,fmt);
|
|
127 if(!best) return 0; // no match
|
|
128 return vf->next->query_format(vf->next,best);
|
|
129 }
|
|
130
|
|
131 static int open(vf_instance_t *vf, char* args){
|
6232
|
132 unsigned int i;
|
5774
|
133 vf->config=config;
|
|
134 vf->put_image=put_image;
|
|
135 vf->query_format=query_format;
|
|
136 vf->priv=malloc(sizeof(struct vf_priv_s));
|
6232
|
137 for(i=0;i<256;i++) gray_pal[i]=0x01010101*i;
|
5774
|
138 return 1;
|
|
139 }
|
|
140
|
|
141 vf_info_t vf_info_palette = {
|
|
142 "8bpp indexed (using palette) -> BGR 15/16/24/32 conversion",
|
|
143 "palette",
|
|
144 "A'rpi",
|
|
145 "",
|
|
146 open
|
|
147 };
|
|
148
|
|
149 //===========================================================================//
|