c_color_space.cpp
资源名称:视频会议系统.rar [点击查看]
上传用户:popouu88
上传日期:2013-02-11
资源大小:2894k
文件大小:11k
源码类别:
IP电话/视频会议
开发平台:
Visual C++
- // c_color_space.cpp: implementation of the c_color_space class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "..stdafx.h"
- #include "c_color_space.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- c_color_space::c_color_space()
- {
- }
- c_color_space::~c_color_space()
- {
- }
- /************************************************************************************************/
- void __stdcall c_color_space::rgb555_to_rgb555(void* d,void* s,unsigned int l)
- {
- c_color_space::memory_copy(d,s,l);
- }
- void __stdcall c_color_space::rgb555_to_bgr555(void* d,void* s,unsigned int l)
- {
- WORD* ps=(WORD*)s;
- WORD* pd=(WORD*)d;
- WORD r,g,b;
- for(unsigned int i=0;i<l/2;i++)
- {
- r=g=b=*ps;ps++;
- r=(r<<10) & 0x7C00;
- g=g & 0x3E0;
- b=(b>>10) & 0x1F;
- *pd=r|g|b;pd++;
- }
- }
- void __stdcall c_color_space::rgb555_to_rgb565(void* d,void* s,unsigned int l)
- {
- WORD* ps=(WORD*)s;
- WORD* pd=(WORD*)d;
- WORD r,g,b;
- for(unsigned int i=0;i<l/2;i++)
- {
- r=g=b=*ps;ps++;
- r=r & 0x1F;
- g=(g<<1) & 0x7E0;
- b=(b<<1) & 0xF800;
- *pd=r|g|b;pd++;
- }
- }
- void __stdcall c_color_space::rgb555_to_bgr565(void* d,void* s,unsigned int l)
- {
- WORD* ps=(WORD*)s;
- WORD* pd=(WORD*)d;
- WORD r,g,b;
- for(unsigned int i=0;i<l/2;i++)
- {
- r=g=b=*ps;ps++;
- r=(r<<11) & 0xF800;
- g=(g<<1) & 0x7E0;
- b=(b>>10) & 0x1F;
- *pd=r|g|b;pd++;
- }
- }
- void __stdcall c_color_space::rgb555_to_rgb888(void* d,void* s,unsigned int l)
- {
- WORD* ps=(WORD*)s;
- BYTE* pd=(BYTE*)d;
- WORD r,g,b,alpha=0xFF;
- for(unsigned int i=0;i<l/2;i++)
- {
- r=g=b=*ps;ps++;
- *pd=(r<<3) & 0xFF;pd++;
- *pd=(g>>2) & 0xFF;pd++;
- *pd=(b>>7) & 0xFF;pd++;
- }
- }
- void __stdcall c_color_space::rgb555_to_bgr888(void* d,void* s,unsigned int l)
- {
- WORD* ps=(WORD*)s;
- BYTE* pd=(BYTE*)d;
- WORD r,g,b,alpha=0xFF;
- for(unsigned int i=0;i<l/2;i++)
- {
- r=g=b=*ps;ps++;
- *pd=(b>>7) & 0xFF;pd++;
- *pd=(g>>2) & 0xFF;pd++;
- *pd=(r<<3) & 0xFF;pd++;
- }
- }
- void __stdcall c_color_space::rgb555_to_rgb8888(void* d,void* s,unsigned int l)
- {
- WORD* ps=(WORD*)s;
- BYTE* pd=(BYTE*)d;
- WORD r,g,b,alpha=0xFF;
- for(unsigned int i=0;i<l/2;i++)
- {
- r=g=b=*ps;ps++;
- *pd=(r<<3) & 0xFF;pd++;
- *pd=(g>>2) & 0xFF;pd++;
- *pd=(b>>7) & 0xFF;pd++;
- *pd=(BYTE)alpha; pd++;
- }
- }
- void __stdcall c_color_space::rgb555_to_bgr8888(void* d,void* s,unsigned int l)
- {
- WORD* ps=(WORD*)s;
- BYTE* pd=(BYTE*)d;
- WORD r,g,b,alpha=0xFF;
- for(unsigned int i=0;i<l/2;i++)
- {
- r=g=b=*ps;ps++;
- *pd=(b>>7) & 0xFF;pd++;
- *pd=(g>>2) & 0xFF;pd++;
- *pd=(r<<3) & 0xFF;pd++;
- *pd=(BYTE)alpha; pd++;
- }
- }
- /*RGB565*/
- void __stdcall c_color_space::rgb565_to_rgb565(void* d,void* s,unsigned int l)
- {
- c_color_space::memory_copy(d,s,l);
- }
- void __stdcall c_color_space::rgb565_to_bgr565(void* d,void* s,unsigned int l)
- {
- WORD* ps=(WORD*)s;
- WORD* pd=(WORD*)d;
- WORD r,g,b;
- for(unsigned int i=0;i<l/2;i++)
- {
- r=g=b=*ps;ps++;
- r=(r<<11) & 0xF800;
- g=g & 0x7E0;
- b=(b>>11) &0x1F;
- *pd=r|g|b;pd++;
- }
- }
- void __stdcall c_color_space::rgb565_to_rgb555(void* d,void* s,unsigned int l)
- {
- WORD* ps=(WORD*)s;
- WORD* pd=(WORD*)d;
- WORD r,g,b;
- for(unsigned int i=0;i<l/2;i++)
- {
- r=g=b=*ps;ps++;
- r=r & 0x1F;
- g=(g>>1 ) & 0x3E0;
- b=(b>>1) & 0x7C00;
- *pd=r|g|b;pd++;
- }
- }
- void __stdcall c_color_space::rgb565_to_bgr555(void* d,void* s,unsigned int l)
- {
- WORD* ps=(WORD*)s;
- WORD* pd=(WORD*)d;
- WORD r,g,b;
- for(unsigned int i=0;i<l/2;i++)
- {
- r=g=b=*ps;ps++;
- r=(r<<10) & 0x7C00;
- g=(g>>1 ) & 0x3E0;
- b=(b>>11) & 0x1F;
- *pd=r|g|b;pd++;
- }
- }
- void __stdcall c_color_space::rgb565_to_rgb888(void* d,void* s,unsigned int l)
- {
- WORD* ps=(WORD*)s;
- BYTE* pd=(BYTE*)d;
- WORD r,g,b,alpha=0xFF;
- for(unsigned int i=0;i<l/2;i++)
- {
- r=g=b=*ps;ps++;
- *pd=(r<<3) & 0xFF;pd++;
- *pd=(g>>3) & 0xFF;pd++;
- *pd=(b>>8) & 0xFF;pd++;
- }
- }
- void __stdcall c_color_space::rgb565_to_bgr888(void* d,void* s,unsigned int l)
- {
- WORD* ps=(WORD*)s;
- BYTE* pd=(BYTE*)d;
- WORD r,g,b,alpha=0xFF;
- for(unsigned int i=0;i<l/2;i++)
- {
- r=g=b=*ps;ps++;
- *pd=(b>>8) & 0xFF;pd++;
- *pd=(g>>3) & 0xFF;pd++;
- *pd=(r<<3) & 0xFF;pd++;
- }
- }
- void __stdcall c_color_space::rgb565_to_rgb8888(void* d,void* s,unsigned int l)
- {
- WORD* ps=(WORD*)s;
- BYTE* pd=(BYTE*)d;
- WORD r,g,b,alpha=0xFF;
- for(unsigned int i=0;i<l/2;i++)
- {
- r=g=b=*ps;ps++;
- *pd=(r<<3) & 0xFF;pd++;
- *pd=(g>>3) & 0xFF;pd++;
- *pd=(b>>8) & 0xFF;pd++;
- *pd=(BYTE)alpha; pd++;
- }
- }
- void __stdcall c_color_space::rgb565_to_bgr8888(void* d,void* s,unsigned int l)
- {
- WORD* ps=(WORD*)s;
- BYTE* pd=(BYTE*)d;
- WORD r,g,b,alpha=0xFF;
- for(unsigned int i=0;i<l/2;i++)
- {
- r=g=b=*ps;ps++;
- *pd=(b>>8) & 0xFF;pd++;
- *pd=(g>>3) & 0xFF;pd++;
- *pd=(r<<3) & 0xFF;pd++;
- *pd=(BYTE)alpha; pd++;
- }
- }
- /*RGB888*/
- void __stdcall c_color_space::rgb888_to_rgb555(void* d,void* s,unsigned int l)
- {
- BYTE* ps=(BYTE*)s;
- WORD* pd=(WORD*)d;
- WORD r,g,b;
- for(unsigned int i=0;i<l/3;i++)
- {
- r=(WORD)*ps;ps++;
- g=(WORD)*ps;ps++;
- b=(WORD)*ps;ps++;
- r=(r>>3) & 0x1F;
- g=(g<<2) & 0x3E0;
- b=(b<<7) & 0x7C00;
- *pd=r|g|b;pd++;
- }
- }
- void __stdcall c_color_space::rgb888_to_bgr555(void* d,void* s,unsigned int l)
- {
- BYTE* ps=(BYTE*)s;
- WORD* pd=(WORD*)d;
- WORD r,g,b;
- for(unsigned int i=0;i<l/3;i++)
- {
- b=(WORD)*ps;ps++;
- g=(WORD)*ps;ps++;
- r=(WORD)*ps;ps++;
- r=(r>>3) & 0x1F;
- g=(g<<2) & 0x3E0;
- b=(b<<7) & 0x7C00;
- *pd=r|g|b;pd++;
- }
- }
- void __stdcall c_color_space::rgb888_to_rgb565(void* d,void* s,unsigned int l)
- {
- BYTE* ps=(BYTE*)s;
- WORD* pd=(WORD*)d;
- WORD r,g,b;
- for(unsigned int i=0;i<l/3;i++)
- {
- r=(WORD)*ps;ps++;
- g=(WORD)*ps;ps++;
- b=(WORD)*ps;ps++;
- r=(r>>3) & 0x1F;
- g=(g<<3) & 0x7E0;
- b=(b<<8) & 0xF800;
- *pd=r|g|b;pd++;
- }
- }
- void __stdcall c_color_space::rgb888_to_bgr565(void* d,void* s,unsigned int l)
- {
- BYTE* ps=(BYTE*)s;
- WORD* pd=(WORD*)d;
- WORD r,g,b;
- for(unsigned int i=0;i<l/3;i++)
- {
- b=(WORD)*ps;ps++;
- g=(WORD)*ps;ps++;
- r=(WORD)*ps;ps++;
- r=(r>>3) & 0x1F;
- g=(g<<3) & 0x7E0;
- b=(b<<8) & 0xF800;
- *pd=r|g|b;pd++;
- }
- }
- void __stdcall c_color_space::rgb888_to_rgb888(void* d,void* s,unsigned int l)
- {
- c_color_space::memory_copy(d,s,l);
- }
- void __stdcall c_color_space::rgb888_to_bgr888(void* d,void* s,unsigned int l)
- {
- BYTE* ps=(BYTE*)s;
- BYTE* pd=(BYTE*)d;
- BYTE r,g,b;
- for(unsigned int i=0;i<l/3;i++)
- {
- r=*ps;ps++;
- g=*ps;ps++;
- b=*ps;ps++;
- *pd=b;pd++;
- *pd=g;pd++;
- *pd=r;pd++;
- }
- }
- void __stdcall c_color_space::rgb888_to_rgb8888(void* d,void* s,unsigned int l)
- {
- BYTE* ps=(BYTE*)s;
- BYTE* pd=(BYTE*)d;
- for(unsigned int i=0;i<l/3;i++)
- {
- *pd=*ps;ps++;pd++;
- *pd=*ps;ps++;pd++;
- *pd=*ps;ps++;pd++;
- *pd=0xFF;pd++;//alpha
- }
- }
- void __stdcall c_color_space::rgb888_to_bgr8888(void* d,void* s,unsigned int l)
- {
- BYTE* ps=(BYTE*)s;
- BYTE* pd=(BYTE*)d;
- BYTE r,g,b;
- for(unsigned int i=0;i<l/3;i++)
- {
- r=*ps;ps++;
- g=*ps;ps++;
- b=*ps;ps++;
- *pd=b;pd++;
- *pd=g;pd++;
- *pd=r;pd++;
- *pd=0xFF;pd++;//alpha
- }
- }
- /*RGB8888*/
- void __stdcall c_color_space::rgb8888_to_rgb555(void* d,void* s,unsigned int l)
- {
- BYTE* ps=(BYTE*)s;
- WORD* pd=(WORD*)d;
- WORD r,g,b;
- for(unsigned int i=0;i<l/4;i++)
- {
- r=(WORD)*ps;ps++;
- g=(WORD)*ps;ps++;
- b=(WORD)*ps;ps++;
- ps++;//for alpha;
- r=(r>>3) & 0x1F;
- g=(g<<2) & 0x3E0;
- b=(b<<7) & 0x7C00;
- *pd=r|g|b;pd++;
- }
- }
- void __stdcall c_color_space::rgb8888_to_bgr555(void* d,void* s,unsigned int l)
- {
- BYTE* ps=(BYTE*)s;
- WORD* pd=(WORD*)d;
- WORD r,g,b;
- for(unsigned int i=0;i<l/4;i++)
- {
- b=(WORD)*ps;ps++;
- g=(WORD)*ps;ps++;
- r=(WORD)*ps;ps++;
- ps++;//for alpha;
- r=(r>>3) & 0x1F;
- g=(g<<2) & 0x3E0;
- b=(b<<7) & 0x7C00;
- *pd=r|g|b;pd++;
- }
- }
- void __stdcall c_color_space::rgb8888_to_rgb565(void* d,void* s,unsigned int l)
- {
- BYTE* ps=(BYTE*)s;
- WORD* pd=(WORD*)d;
- WORD r,g,b;
- for(unsigned int i=0;i<l/4;i++)
- {
- r=(WORD)*ps;ps++;
- g=(WORD)*ps;ps++;
- b=(WORD)*ps;ps++;
- ps++;//for alpha;
- r=(r>>3) & 0x1F;
- g=(g<<3) & 0x7E0;
- b=(b<<8) & 0xF800;
- *pd=r|g|b;pd++;
- }
- }
- void __stdcall c_color_space::rgb8888_to_bgr565(void* d,void* s,unsigned int l)
- {
- BYTE* ps=(BYTE*)s;
- WORD* pd=(WORD*)d;
- WORD r,g,b;
- for(unsigned int i=0;i<l/4;i++)
- {
- b=(WORD)*ps;ps++;
- g=(WORD)*ps;ps++;
- r=(WORD)*ps;ps++;
- ps++;//for alpha;
- r=(r>>3) & 0x1F;
- g=(g<<3) & 0x7E0;
- b=(b<<8) & 0xF800;
- *pd=r|g|b;pd++;
- }
- }
- void __stdcall c_color_space::rgb8888_to_rgb888(void* d,void* s,unsigned int l)
- {
- BYTE* ps=(BYTE*)s;
- BYTE* pd=(BYTE*)d;
- for(unsigned int i=0;i<l/4;i++)
- {
- *pd=*ps;ps++;pd++;
- *pd=*ps;ps++;pd++;
- *pd=*ps;ps++;pd++;
- ps++;//for alpha;
- }
- }
- void __stdcall c_color_space::rgb8888_to_bgr888(void* d,void* s,unsigned int l)
- {
- BYTE* ps=(BYTE*)s;
- BYTE* pd=(BYTE*)d;
- BYTE r,g,b;
- for(unsigned int i=0;i<l/4;i++)
- {
- r=*ps;ps++;
- g=*ps;ps++;
- b=*ps;ps++;
- ps++;//for alpha;
- *pd=b;pd++;
- *pd=g;pd++;
- *pd=r;pd++;
- }
- }
- void __stdcall c_color_space::rgb8888_to_rgb8888(void* d,void* s,unsigned int l)
- {
- c_color_space::memory_copy(d,s,l);
- }
- void __stdcall c_color_space::rgb8888_to_bgr8888(void* d,void* s,unsigned int l)
- {
- BYTE* ps=(BYTE*)s;
- BYTE* pd=(BYTE*)d;
- BYTE r,g,b,a;
- for(unsigned int i=0;i<l/4;i++)
- {
- r=*ps;ps++;
- g=*ps;ps++;
- b=*ps;ps++;
- a=*ps;ps++;//for alpha;
- *pd=b;pd++;
- *pd=g;pd++;
- *pd=r;pd++;
- *pd=a;pd++;
- }
- }
- /*YUV*/
- //wait!!
- /*YUV2*/
- //wait!!
- /*HSV*/
- //wait!!
- /*others*/
- void __stdcall c_color_space::zero_memory(void* d,unsigned int l)
- {
- memset(d,0,l);
- }
- void __stdcall c_color_space::memory_copy(void* d,void* s,unsigned int l)
- {
- memcpy(d,s,l);
- }
- void __stdcall c_color_space::flip_bmp(void* s,int w,int h,int c)
- {
- int width=w*c/8;
- int len=w*h*c/8;
- if(c==16)
- {
- WORD* ph=(WORD*)s;
- WORD* pt=(WORD*)(((DWORD)s)+len-width);
- WORD tmp=0;
- while(ph<pt)
- {
- for(int i=0;i<w;i++)
- {
- tmp=ph[i];
- ph[i]=pt[i];
- pt[i]=tmp;
- }
- ph+=w;
- pt-=w;
- }
- }
- else if(c==24)
- {
- BYTE* ph=(BYTE*)s;
- BYTE* pt=(BYTE*)(((DWORD)s)+len-width);
- BYTE tmp=0;
- while(ph<pt)
- {
- for(int i=0;i<width;i++)
- {
- tmp=ph[i];
- ph[i]=pt[i];
- pt[i]=tmp;
- }
- ph+=width;
- pt-=width;
- }
- }
- else if(c=32)
- {
- DWORD* ph=(DWORD*)s;
- DWORD* pt=(DWORD*)(((DWORD)s)+len-width);
- DWORD tmp=0;
- while(ph<pt)
- {
- for(int i=0;i<w;i++)
- {
- tmp=ph[i];
- ph[i]=pt[i];
- pt[i]=tmp;
- }
- ph+=w;
- pt-=w;
- }
- }
- }
- void __stdcall c_color_space::mirror_bmp(void* s,int w,int h,int c)
- {
- }