annotate libmpcodecs/vf_rgb2bgr.c @ 6083:6aa4fc282fc7

added support for codec selection
author alex
date Mon, 13 May 2002 21:18:52 +0000
parents 1972c3475d93
children a894e99c1e51
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
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
6 #include "../config.h"
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
7 #include "../mp_msg.h"
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
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
13 #include "../libvo/fastmemcpy.h"
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
14 #include "../postproc/rgb2rgb.h"
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
15
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
16 //===========================================================================//
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
17
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
18 struct vf_priv_s {
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
19 unsigned int fmt;
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
20 int forced;
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
21 };
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
22
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
23 static unsigned int getfmt(unsigned int outfmt,int forced){
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
24 if(forced) switch(outfmt){
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
25 case IMGFMT_RGB24:
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
26 case IMGFMT_RGB32:
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
27 case IMGFMT_BGR24:
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
28 case IMGFMT_BGR32:
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
29 return outfmt;
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
30 }
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
31 switch(outfmt){
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
32 case IMGFMT_RGB24: return IMGFMT_BGR24;
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
33 case IMGFMT_RGB32: return IMGFMT_BGR32;
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
34 case IMGFMT_BGR24: return IMGFMT_RGB24;
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
35 case IMGFMT_BGR32: return IMGFMT_RGB32;
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
36 }
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
37 return 0;
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
38 }
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
39
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
40 static int config(struct vf_instance_s* vf,
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
41 int width, int height, int d_width, int d_height,
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
42 unsigned int flags, unsigned int outfmt){
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
43 vf->priv->fmt=getfmt(outfmt,vf->priv->forced);
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
44 return vf_next_config(vf,width,height,d_width,d_height,flags,vf->priv->fmt);
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
45 }
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
46
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
47 static void put_image(struct vf_instance_s* vf, mp_image_t *mpi){
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
48 mp_image_t *dmpi;
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
49
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
50 // hope we'll get DR buffer:
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
51 dmpi=vf_get_image(vf->next,vf->priv->fmt,
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
52 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
53 mpi->w, mpi->h);
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
54
5596
70e88ec799b4 handle width*bpp!=stride
arpi
parents: 5595
diff changeset
55 if(mpi->stride[0]!=dmpi->stride[0] || mpi->stride[0]!=mpi->w*(mpi->bpp/8)){
5594
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
56 int y;
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
57 unsigned char* src=mpi->planes[0];
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
58 unsigned char* dst=dmpi->planes[0];
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
59 int srcsize=mpi->w*mpi->bpp/8;
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
60 for(y=0;y<mpi->h;y++){
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
61 if(mpi->bpp==32)
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
62 rgb32tobgr32(src,dst,srcsize);
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
63 else
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
64 rgb24tobgr24(src,dst,srcsize);
5595
arpi
parents: 5594
diff changeset
65 src+=mpi->stride[0];
arpi
parents: 5594
diff changeset
66 dst+=dmpi->stride[0];
5594
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
67 }
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
68 } else {
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
69 if(mpi->bpp==32)
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
70 rgb32tobgr32(mpi->planes[0],dmpi->planes[0],mpi->w*mpi->h*4);
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
71 else
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
72 rgb24tobgr24(mpi->planes[0],dmpi->planes[0],mpi->w*mpi->h*3);
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
73 }
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
74
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
75 vf_next_put_image(vf,dmpi);
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
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
80 static int query_format(struct vf_instance_s* vf, unsigned int outfmt){
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
81 unsigned int fmt=getfmt(outfmt,vf->priv->forced);
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
82 if(!fmt) return 0;
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
83 return vf_next_query_format(vf,fmt) & (~VFCAP_CSP_SUPPORTED_BY_HW);
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
84 }
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
85
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
86 static int open(vf_instance_t *vf, char* args){
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
87 vf->config=config;
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
88 vf->put_image=put_image;
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
89 vf->query_format=query_format;
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
90 vf->priv=malloc(sizeof(struct vf_priv_s));
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
91 vf->priv->forced=args && !strcasecmp(args,"swap");
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
92 return 1;
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
93 }
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
94
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
95 vf_info_t vf_info_rgb2bgr = {
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
96 "fast 24/32bpp RGB<->BGR conversion",
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
97 "rgb2bgr",
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
98 "A'rpi",
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
99 "",
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
100 open
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
101 };
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
102
dc8ebd9736f4 rgb2bgr converter
arpi
parents:
diff changeset
103 //===========================================================================//