home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 275 / DPCS0111DVD.ISO / Toolkit / Audio-Visual / VirtualDub / Source / VirtualDub-1.9.10-src.7z / src / h / vd2 / plugin / vdvideoutil.h < prev   
Encoding:
C/C++ Source or Header  |  2009-09-14  |  3.8 KB  |  122 lines

  1. #ifndef f_VD2_PLUGIN_VDVIDEOUTIL_H
  2. #define f_VD2_PLUGIN_VDVIDEOUTIL_H
  3.  
  4. template<class T>
  5. T *vd_ptroffset(T *p, ptrdiff_t diff) {
  6.     return (T *)((char *)p + diff);
  7. }
  8.  
  9. template<class T>
  10. class vd_row_iter {
  11. public:
  12.     vd_row_iter() {}
  13.     vd_row_iter(T *p, ptrdiff_t pitch) : mp(p), mpitch(pitch) {}
  14.     vd_row_iter(T *p, ptrdiff_t pitch, int y) : mp(vd_ptroffset(p, pitch*y)), mpitch(pitch) {}
  15.  
  16.     vd_row_iter(const VFBitmap& bm, int x = 0, int y = 0) : mp(vd_ptroffset((T*)bm.data, bm.pitch*(bm.h - 1 - y))+x), mpitch(-bm.pitch) {}
  17.  
  18.     operator T*() const { return mp; }
  19.     T& operator[](int x) const { return mp[x]; }
  20.  
  21.     void mulstep(int x) {
  22.         mpitch *= x;
  23.     }
  24.  
  25.     const vd_row_iter<T>& operator+=(int y) {
  26.         mp = vd_ptroffset(mp, mpitch * y);
  27.         return *this;
  28.     }
  29.  
  30.     const vd_row_iter<T>& operator-=(int y) {
  31.         mp = vd_ptroffset(mp, -(mpitch * y));
  32.         return *this;
  33.     }
  34.  
  35.     const vd_row_iter<T>& operator++() {
  36.         mp = vd_ptroffset(mp, mpitch);
  37.         return *this;
  38.     }
  39.  
  40.     const vd_row_iter<T> operator++(int) {
  41.         const vd_row_iter<T> temp(*this);
  42.         mp = vd_ptroffset(mp, mpitch);
  43.         return temp;
  44.     }
  45.  
  46.     const vd_row_iter<T>& operator--() {
  47.         mp = vd_ptroffset(mp, -mpitch);
  48.         return *this;
  49.     }
  50.  
  51.     const vd_row_iter<T> operator--(int) {
  52.         const vd_row_iter<T> temp(*this);
  53.         mp = vd_ptroffset(mp, -mpitch);
  54.         return temp;
  55.     }
  56.  
  57. protected:
  58.     T *mp;
  59.     ptrdiff_t mpitch;
  60. };
  61.  
  62. typedef vd_row_iter<uint32> vd_pixrow_iter;
  63.  
  64. inline uint32 vd_pixavg_down(uint32 x, uint32 y) {
  65.     return (x&y) + (((x^y)&0xfefefefe)>>1);
  66. }
  67.  
  68. inline uint32 vd_pixavg_up(uint32 x, uint32 y) {
  69.     return (x|y) - (((x^y)&0xfefefefe)>>1);
  70. }
  71.  
  72. inline void vd_pixunpack(uint32 px, int& r, int& g, int& b) {
  73.     r = (px>>16)&255;
  74.     g = (px>> 8)&255;
  75.     b = (px    )&255;
  76. }
  77.  
  78. inline uint32 vd_pixpack(int r, int g, int b) {
  79.     if ((unsigned)r >= 256) r = ~(r>>31) & 255;
  80.     if ((unsigned)g >= 256) g = ~(g>>31) & 255;
  81.     if ((unsigned)b >= 256) b = ~(b>>31) & 255;
  82.  
  83.     return (r<<16) + (g<<8) + b;
  84. }
  85.  
  86. inline uint32 vd_pixpackfast(int r, int g, int b) {
  87.     return (r<<16) + (g<<8) + b;
  88. }
  89.  
  90. struct vd_transform_pixmap_helper {
  91.     vd_transform_pixmap_helper(const VFBitmap& dst)
  92.         : p((uint32 *)dst.data)
  93.         , pitch(dst.pitch)
  94.         , w(dst.w)
  95.         , h(dst.h) {}
  96.  
  97.     operator bool() const { return false; }
  98.  
  99.     uint32 *p;
  100.     const ptrdiff_t pitch;
  101.     const int w, h;
  102. };
  103.  
  104. #define vd_transform_pixmap_blt(dst, src)        \
  105.     if(vd_transform_pixmap_helper dstinfo = dst);else                    \
  106.     if(vd_transform_pixmap_helper srcinfo = src);else                    \
  107.     for(int y = 0, h = dstinfo.h, w = dstinfo.w; y < h; ++y, dstinfo.p=vd_ptroffset(dstinfo.p, dstinfo.pitch), srcinfo.p=vd_ptroffset(srcinfo.p, srcinfo.pitch))    \
  108.     for(int x = 0; x < dstinfo.w; ++x)            \
  109.     switch(unsigned& out = dstinfo.p[x]) case 0: default:        \
  110.     switch(const unsigned& in = srcinfo.p[x]) case 0: default:
  111.  
  112. #define vd_transform_pixmap_inplace(dst)        \
  113.     if(vd_transform_pixmap_helper dstinfo = dst);else                    \
  114.     for(int y = 0, h = dstinfo.h, w = dstinfo.w; y < h; ++y, dstinfo.p=vd_ptroffset(dstinfo.p, dstinfo.pitch))    \
  115.     for(int x = 0; x < dstinfo.w; ++x)            \
  116.     switch(unsigned& px = dstinfo.p[x]) case 0: default:        \
  117.  
  118. #define vd_maketable256_16(x) formula((x+0)),formula((x+1)),formula((x+2)),formula((x+3)),formula((x+4)),formula((x+5)),formula((x+6)),formula((x+7)),formula((x+8)),formula((x+9)),formula((x+10)),formula((x+11)),formula((x+12)),formula((x+13)),formula((x+14)),formula((x+15))
  119. #define vd_maketable256 vd_maketable256_16(0x00),vd_maketable256_16(0x10),vd_maketable256_16(0x20),vd_maketable256_16(0x30),vd_maketable256_16(0x40),vd_maketable256_16(0x50),vd_maketable256_16(0x60),vd_maketable256_16(0x70),vd_maketable256_16(0x80),vd_maketable256_16(0x90),vd_maketable256_16(0xA0),vd_maketable256_16(0xB0),vd_maketable256_16(0xC0),vd_maketable256_16(0xD0),vd_maketable256_16(0xE0),vd_maketable256_16(0xF0),
  120.  
  121. #endif
  122.