⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 img2raw.cc

📁 PIXIL is a small footprint operating environment, complete with PDA PIM applications, a browser and
💻 CC
📖 第 1 页 / 共 2 页
字号:
/* *  img2raw.cc */#include <iostream.h>#include "img2raw.hh"#include "yuv2rgb16.hh"#if ENABLE_MMX#include "yuv2rgb16mmx.hh"#include "yuv2rgb32mmx.hh"#include "grey2rgb32mmx.hh"#include "grey2rgb16mmx.hh"#endif#define SHOWLINE(x,y) cout << #x ": " << x << yvoid RawImageSpec_RGB::Debug_ShowParam() const{  SHOWLINE(bytes_per_line,endl);  SHOWLINE(bits_per_pixel,endl);  cout << "little_endian: " << (little_endian ? "little" : "big") << endl;  SHOWLINE(r_mask," "); SHOWLINE(r_bits," "); SHOWLINE(r_shift,endl);  SHOWLINE(g_mask," "); SHOWLINE(g_bits," "); SHOWLINE(g_shift,endl);  SHOWLINE(b_mask," "); SHOWLINE(b_bits," "); SHOWLINE(b_shift,endl);  if (resize_to_fixed) { cout << "resize to fixed: " << final_width << "x" << final_height << endl; }  if (resize_with_factor) { cout << "resize with factor: " << resize_factor << endl; }  if (force_to_greyscale) cout << "force to greyscale\n";}// --------------------------------------------------------------------------------------------/* Convert greyscale to RGB components in 32bit entities in arbitrary order. */class i2r_grey_32bit : public Image2Raw_TransformYUV{public:  virtual ~i2r_grey_32bit() { }  virtual void Transform(const Image_YUV<Pixel>&,uint8* mem,int firstline,int lastline);  static bool s_CanConvert(const Image_YUV<Pixel>&,const RawImageSpec_RGB&);  virtual bool CanConvert(const Image_YUV<Pixel>& i,const RawImageSpec_RGB& s) { return s_CanConvert(i,s); }  virtual const char* TransformationName() { return "scalar grey to 32bit RGB"; }};bool i2r_grey_32bit::s_CanConvert(const Image_YUV<Pixel>& img,const RawImageSpec_RGB& spec){  if (spec.resize_to_fixed || spec.resize_with_factor) return false;  if (spec.bits_per_pixel != 32) return false;  if (spec.r_bits != 8 || spec.g_bits != 8 || spec.b_bits != 8) return false;  if (spec.r_shift%8   || spec.g_shift%8   || spec.b_shift%8)   return false;  ImageParam_YUV param;  img.GetParam(param);  if (param.nocolor==false) return false;  return true;}void i2r_grey_32bit::Transform(const Image_YUV<Pixel>& img,uint8* mem,int firstline,int lastline){  ImageParam_YUV param;  img.GetParam(param);  const Pixel*const * pix_y = img.AskFrameY_const();  for (int y=firstline;y<=lastline;y++)    {      uint32* membuf = (uint32*)(mem + d_spec.bytes_per_line*(y-firstline));      for (int x=0;x<param.width;x++)        {	  uint32 val = pix_y[y][x];	  val |= val<<16;	  val |= val<< 8;          *membuf++ = val;        }    }}// --------------------------------------------------------------------------------------------/* Convert YUV 4:2:0 and place RGB components in 32bit entities in arbitrary order. */class i2r_yuv_32bit : public Image2Raw_TransformYUV{public:  virtual ~i2r_yuv_32bit() { }  virtual void Transform(const Image_YUV<Pixel>&,uint8* mem,int firstline,int lastline);  static bool s_CanConvert(const Image_YUV<Pixel>&,const RawImageSpec_RGB&);  virtual bool CanConvert(const Image_YUV<Pixel>& i,const RawImageSpec_RGB& s) { return s_CanConvert(i,s); }  virtual const char* TransformationName() { return "scalar YUV to 32bit RGB"; }};bool i2r_yuv_32bit::s_CanConvert(const Image_YUV<Pixel>& img,const RawImageSpec_RGB& spec){  if (spec.resize_to_fixed || spec.resize_with_factor) return false;  if (spec.bits_per_pixel != 32 && spec.bits_per_pixel != 24) return false;  if (spec.r_bits != 8 || spec.g_bits != 8 || spec.b_bits != 8) return false;  if (spec.r_shift%8   || spec.g_shift%8   || spec.b_shift%8)   return false;  ImageParam_YUV param;  img.GetParam(param);  if (param.nocolor==true) return false;  if (param.chroma !=Chroma420) return false;  return true;}static int* clip_0_255=NULL;static int s_clip[1024];static struct InitClip{  InitClip()    {      clip_0_255 = &s_clip[512];      for (int i=-512;i<512;i++)        {          if (i<0)            {              clip_0_255[i]=0;            }          else if (i>255)            {              clip_0_255[i]=255;            }          else            {              clip_0_255[i]=i;            }        }    }} dummy_23874678;void i2r_yuv_32bit::Transform(const Image_YUV<Pixel>& img,uint8* mem,int firstline,int lastline){  int rpos,gpos,bpos;  const int bytes_per_pixel = d_spec.bits_per_pixel/8;  const int lastidx = bytes_per_pixel-1;  rpos = lastidx-d_spec.r_shift/8;  gpos = lastidx-d_spec.g_shift/8;  bpos = lastidx-d_spec.b_shift/8;  if (d_spec.little_endian)    {      rpos = lastidx-rpos;      gpos = lastidx-gpos;      bpos = lastidx-bpos;    }  ImageParam_YUV param;  img.GetParam(param);  assert(param.chroma==Chroma420);  const Pixel*const * pix_y = img.AskFrameY_const();  const Pixel*const * pix_u = img.AskFrameU_const();  const Pixel*const * pix_v = img.AskFrameV_const();  for (int y=firstline;y<=lastline;y+=2)    {      uint8* membuf8a = mem + d_spec.bytes_per_line*(y-firstline);      uint8* membuf8b = mem + d_spec.bytes_per_line*y +d_spec.bytes_per_line;      const Pixel* cbp = pix_u[y/2];      const Pixel* crp = pix_v[y/2];      const Pixel* y0p = pix_y[y  ];      const Pixel* y1p = pix_y[y+1];      for (int x=0;x<param.width;x+=2)        {          int cb=((int)*cbp++) -128;          int cr=((int)*crp++) -128;          int r0 = (int)(          + 409*cr);          int g0 = (int)( - 100*cb - 208*cr);          int b0 = (int)( + 516*cb         );                    int yy=(((int)*y0p++) -16)*298;          int red   = (r0+yy)>>8; red  = clip_0_255[red];          int green = (g0+yy)>>8; green= clip_0_255[green];          int blue  = (b0+yy)>>8; blue = clip_0_255[blue];          membuf8a[rpos] = red;          membuf8a[gpos] = green;          membuf8a[bpos] = blue;          membuf8a+=bytes_per_pixel;          yy=(((int)*y0p++) -16)*298;          red   = (r0+yy)>>8; red  = clip_0_255[red];          green = (g0+yy)>>8; green= clip_0_255[green];          blue  = (b0+yy)>>8; blue = clip_0_255[blue];          membuf8a[rpos] = red;          membuf8a[gpos] = green;          membuf8a[bpos] = blue;          membuf8a+=bytes_per_pixel;                    yy=(((int)*y1p++) -16)*298;          red   = (r0+yy)>>8; red  = clip_0_255[red];          green = (g0+yy)>>8; green= clip_0_255[green];          blue  = (b0+yy)>>8; blue = clip_0_255[blue];          membuf8b[rpos] = red;          membuf8b[gpos] = green;          membuf8b[bpos] = blue;          membuf8b+=bytes_per_pixel;                    yy=(((int)*y1p++) -16)*298;          red   = (r0+yy)>>8; red  = clip_0_255[red];          green = (g0+yy)>>8; green= clip_0_255[green];          blue  = (b0+yy)>>8; blue = clip_0_255[blue];          membuf8b[rpos] = red;          membuf8b[gpos] = green;          membuf8b[bpos] = blue;          membuf8b+=bytes_per_pixel;        }    }}// --------------------------------------------------------------------------------------------/* Convert YUV 4:2:2 and place RGB components in 32bit entities in arbitrary order. */class i2r_yuv422_32bit : public Image2Raw_TransformYUV{public:  virtual ~i2r_yuv422_32bit() { }  virtual void Transform(const Image_YUV<Pixel>&,uint8* mem,int firstline,int lastline);  static bool s_CanConvert(const Image_YUV<Pixel>&,const RawImageSpec_RGB&);  virtual bool CanConvert(const Image_YUV<Pixel>& i,const RawImageSpec_RGB& s) { return s_CanConvert(i,s); }  virtual const char* TransformationName() { return "scalar 4:2:2-YUV to 32bit RGB"; }};bool i2r_yuv422_32bit::s_CanConvert(const Image_YUV<Pixel>& img,const RawImageSpec_RGB& spec){  if (spec.resize_to_fixed || spec.resize_with_factor) return false;  if (spec.bits_per_pixel != 32) return false;  if (spec.r_bits != 8 || spec.g_bits != 8 || spec.b_bits != 8) return false;  if (spec.r_shift%8   || spec.g_shift%8   || spec.b_shift%8)   return false;  ImageParam_YUV param;  img.GetParam(param);  if (param.nocolor==true) return false;  if (param.chroma !=Chroma422) return false;  return true;}void i2r_yuv422_32bit::Transform(const Image_YUV<Pixel>& img,uint8* mem,int firstline,int lastline){  int rpos,gpos,bpos;  rpos = 3-d_spec.r_shift/8;  gpos = 3-d_spec.g_shift/8;  bpos = 3-d_spec.b_shift/8;  if (d_spec.little_endian)    {      rpos = 3-rpos;      gpos = 3-gpos;      bpos = 3-bpos;    }  ImageParam_YUV param;  img.GetParam(param);  assert(param.chroma==Chroma422);  const Pixel*const * pix_y = img.AskFrameY_const();  const Pixel*const * pix_u = img.AskFrameU_const();  const Pixel*const * pix_v = img.AskFrameV_const();  for (int y=firstline;y<=lastline;y++)    {      uint8* membuf8a = mem + d_spec.bytes_per_line*(y-firstline);      const Pixel* cbp = pix_u[y];      const Pixel* crp = pix_v[y];      const Pixel* y0p = pix_y[y];      for (int x=0;x<param.width;x+=2)        {          int cb=((int)*cbp++) -128;          int cr=((int)*crp++) -128;          int r0 = (int)(          + 409*cr);          int g0 = (int)( - 100*cb - 208*cr);          int b0 = (int)( + 516*cb         );                    int yy=(((int)*y0p++) -16)*298;          int red   = (r0+yy)>>8; red  = clip_0_255[red];          int green = (g0+yy)>>8; green= clip_0_255[green];          int blue  = (b0+yy)>>8; blue = clip_0_255[blue];          membuf8a[rpos] = red;          membuf8a[gpos] = green;          membuf8a[bpos] = blue;          membuf8a+=4;          yy=(((int)*y0p++) -16)*298;          red   = (r0+yy)>>8; red  = clip_0_255[red];          green = (g0+yy)>>8; green= clip_0_255[green];          blue  = (b0+yy)>>8; blue = clip_0_255[blue];          membuf8a[rpos] = red;          membuf8a[gpos] = green;          membuf8a[bpos] = blue;          membuf8a+=4;        }    }}// --------------------------------------------------------------------------------------------/* Convert YUV 4:4:4 and place RGB components in 32bit entities in arbitrary order. */class i2r_yuv444_32bit : public Image2Raw_TransformYUV{public:  virtual ~i2r_yuv444_32bit() { }  virtual void Transform(const Image_YUV<Pixel>&,uint8* mem,int firstline,int lastline);  static bool s_CanConvert(const Image_YUV<Pixel>&,const RawImageSpec_RGB&);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -