annotate libmpcodecs/vf_rgb2bgr.c @ 30154:772664b337f6

Add a few definitions used by FFmpeg to config.h: CONFIG_IPV6, HAVE_SETMODE, HAVE_SYS_SELECT_H
author diego
date Mon, 04 Jan 2010 11:13:49 +0000
parents 0f1b5b68af32
children bbb6ebec87a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5594
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
1 #include <stdio.h>
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
2 #include <stdlib.h>
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
3 #include <string.h>
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
4 #include <inttypes.h>
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
5
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 9593
diff changeset
6 #include "config.h"
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 9593
diff changeset
7 #include "mp_msg.h"
5594
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
8
5607
1972c3475d93 mp_image.h and img_format.h moved to libmpcodecs
arpi
parents: 5596
diff changeset
9 #include "img_format.h"
1972c3475d93 mp_image.h and img_format.h moved to libmpcodecs
arpi
parents: 5596
diff changeset
10 #include "mp_image.h"
5594
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
11 #include "vf.h"
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
12
18861
8579acff875e Move postproc ---> libswscale
lucabe
parents: 17906
diff changeset
13 #include "libswscale/rgb2rgb.h"
5594
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
14
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
15 //===========================================================================//
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
16
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
17 struct vf_priv_s {
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
18 unsigned int fmt;
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
19 int forced;
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
20 };
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
21
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
22 static unsigned int getfmt(unsigned int outfmt,int forced){
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
23 if(forced) switch(outfmt){
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
24 case IMGFMT_RGB24:
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
25 case IMGFMT_RGB32:
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
26 case IMGFMT_BGR24:
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
27 case IMGFMT_BGR32:
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
28 return outfmt;
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
29 }
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
30 switch(outfmt){
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
31 case IMGFMT_RGB24: return IMGFMT_BGR24;
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
32 case IMGFMT_RGB32: return IMGFMT_BGR32;
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
33 case IMGFMT_BGR24: return IMGFMT_RGB24;
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
34 case IMGFMT_BGR32: return IMGFMT_RGB32;
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
35 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 25221
diff changeset
36 return 0;
5594
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
37 }
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
38
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
39 static int config(struct vf_instance_s* vf,
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
40 int width, int height, int d_width, int d_height,
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
41 unsigned int flags, unsigned int outfmt){
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
42 vf->priv->fmt=getfmt(outfmt,vf->priv->forced);
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
43 return vf_next_config(vf,width,height,d_width,d_height,flags,vf->priv->fmt);
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
44 }
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
45
17906
20aca9baf5d8 passing pts through the filter layer (lets see if pts or cola comes out at the end)
michael
parents: 17012
diff changeset
46 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts){
5594
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
47 mp_image_t *dmpi;
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
48
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
49 // hope we'll get DR buffer:
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
50 dmpi=vf_get_image(vf->next,vf->priv->fmt,
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
51 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
52 mpi->w, mpi->h);
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
53
5596
70e88ec799b4 handle width*bpp!=stride
arpi
parents: 5595
diff changeset
54 if(mpi->stride[0]!=dmpi->stride[0] || mpi->stride[0]!=mpi->w*(mpi->bpp/8)){
5594
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
55 int y;
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
56 unsigned char* src=mpi->planes[0];
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
57 unsigned char* dst=dmpi->planes[0];
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
58 int srcsize=mpi->w*mpi->bpp/8;
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
59 for(y=0;y<mpi->h;y++){
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
60 if(mpi->bpp==32)
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
61 rgb32tobgr32(src,dst,srcsize);
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
62 else
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
63 rgb24tobgr24(src,dst,srcsize);
5595
arpi
parents: 5594
diff changeset
64 src+=mpi->stride[0];
arpi
parents: 5594
diff changeset
65 dst+=dmpi->stride[0];
5594
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
66 }
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
67 } else {
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
68 if(mpi->bpp==32)
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
69 rgb32tobgr32(mpi->planes[0],dmpi->planes[0],mpi->w*mpi->h*4);
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
70 else
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
71 rgb24tobgr24(mpi->planes[0],dmpi->planes[0],mpi->w*mpi->h*3);
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
72 }
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
73
17906
20aca9baf5d8 passing pts through the filter layer (lets see if pts or cola comes out at the end)
michael
parents: 17012
diff changeset
74 return vf_next_put_image(vf,dmpi, pts);
5594
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
75 }
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
76
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
77 //===========================================================================//
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
78
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
79 static int query_format(struct vf_instance_s* vf, unsigned int outfmt){
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
80 unsigned int fmt=getfmt(outfmt,vf->priv->forced);
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
81 if(!fmt) return 0;
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
82 return vf_next_query_format(vf,fmt) & (~VFCAP_CSP_SUPPORTED_BY_HW);
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
83 }
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
84
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
85 static int open(vf_instance_t *vf, char* args){
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
86 vf->config=config;
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
87 vf->put_image=put_image;
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
88 vf->query_format=query_format;
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
89 vf->priv=malloc(sizeof(struct vf_priv_s));
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
90 vf->priv->forced=args && !strcasecmp(args,"swap");
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
91 return 1;
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
92 }
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
93
25221
00fff9a3b735 Make all vf_info_t structs const
reimar
parents: 23373
diff changeset
94 const vf_info_t vf_info_rgb2bgr = {
5594
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
95 "fast 24/32bpp RGB<->BGR conversion",
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
96 "rgb2bgr",
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
97 "A'rpi",
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
98 "",
9593
e9a2af584986 Add the new -vf option wich is the same as vop in reverse order.
albeu
parents: 7368
diff changeset
99 open,
e9a2af584986 Add the new -vf option wich is the same as vop in reverse order.
albeu
parents: 7368
diff changeset
100 NULL
5594
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
101 };
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
102
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
103 //===========================================================================//