home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 275 / DPCS0111DVD.ISO / Toolkit / Audio-Visual / VirtualDub / Source / VirtualDub-1.9.10-src.7z / src / Meia / source / predict_reference.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2009-09-14  |  5.0 KB  |  127 lines

  1. #include <vd2/Meia/MPEGPredict.h>
  2.  
  3. ///////////////////////////////////////////////////////////////////////////
  4.  
  5. namespace nsVDMPEGPredictReference {
  6.     static void predict_Y_normal(unsigned char *dst, unsigned char *src, ptrdiff_t pitch) {
  7.         for(int j=0; j<16; ++j)
  8.             for(int i=0; i<16; ++i)
  9.                 dst[j*pitch+i] = src[j*pitch+i];
  10.     }
  11.  
  12.     static void predict_Y_halfpelX(unsigned char *dst, unsigned char *src, ptrdiff_t pitch) {
  13.         for(int j=0; j<16; ++j)
  14.             for(int i=0; i<16; ++i)
  15.                 dst[j*pitch+i] = ((unsigned)src[j*pitch+i] + (unsigned)src[j*pitch+i+1] + 1)>>1;
  16.     }
  17.  
  18.     static void predict_Y_halfpelY(unsigned char *dst, unsigned char *src, ptrdiff_t pitch) {
  19.         for(int j=0; j<16; ++j)
  20.             for(int i=0; i<16; ++i)
  21.                 dst[j*pitch+i] = ((unsigned)src[j*pitch+i] + (unsigned)src[(j+1)*pitch+i] + 1)>>1;
  22.     }
  23.  
  24.     static void predict_Y_quadpel(unsigned char *dst, unsigned char *src, ptrdiff_t pitch) {
  25.         for(int j=0; j<16; ++j)
  26.             for(int i=0; i<16; ++i)
  27.                 dst[j*pitch+i] = ((unsigned)src[j*pitch+i] + (unsigned)src[j*pitch+i+1] +
  28.                             (unsigned)src[(j+1)*pitch+i] + (unsigned)src[(j+1)*pitch+i+1] + 2)>>2;
  29.     }
  30.  
  31.     static void predict_C_normal(unsigned char *dst, unsigned char *src, ptrdiff_t pitch) {
  32.         for(int j=0; j<8; ++j)
  33.             for(int i=0; i<8; ++i)
  34.                 dst[j*pitch+i] = src[j*pitch+i];
  35.     }
  36.  
  37.     static void predict_C_halfpelX(unsigned char *dst, unsigned char *src, ptrdiff_t pitch) {
  38.         for(int j=0; j<8; ++j)
  39.             for(int i=0; i<8; ++i)
  40.                 dst[j*pitch+i] = ((unsigned)src[j*pitch+i] + (unsigned)src[j*pitch+i+1] + 1)>>1;
  41.     }
  42.  
  43.     static void predict_C_halfpelY(unsigned char *dst, unsigned char *src, ptrdiff_t pitch) {
  44.         for(int j=0; j<8; ++j)
  45.             for(int i=0; i<8; ++i)
  46.                 dst[j*pitch+i] = ((unsigned)src[j*pitch+i] + (unsigned)src[(j+1)*pitch+i] + 1)>>1;
  47.     }
  48.  
  49.     static void predict_C_quadpel(unsigned char *dst, unsigned char *src, ptrdiff_t pitch) {
  50.         for(int j=0; j<8; ++j)
  51.             for(int i=0; i<8; ++i)
  52.                 dst[j*pitch+i] = ((unsigned)src[j*pitch+i] + (unsigned)src[j*pitch+i+1] +
  53.                             (unsigned)src[(j+1)*pitch+i] + (unsigned)src[(j+1)*pitch+i+1] + 2)>>2;
  54.     }
  55.  
  56.     static void add_Y_normal(unsigned char *dst, unsigned char *src, ptrdiff_t pitch) {
  57.         for(int j=0; j<16; ++j)
  58.             for(int i=0; i<16; ++i)
  59.                 dst[j*pitch+i] = (dst[j*pitch+i] + src[j*pitch+i] + 1)>>1;
  60.     }
  61.  
  62.     static void add_Y_halfpelX(unsigned char *dst, unsigned char *src, ptrdiff_t pitch) {
  63.         for(int j=0; j<16; ++j)
  64.             for(int i=0; i<16; ++i)
  65.                 dst[j*pitch+i] = (dst[j*pitch+i] + (((unsigned)src[j*pitch+i] + (unsigned)src[j*pitch+i+1] + 1)>>1) + 1)>>1;
  66.     }
  67.  
  68.     static void add_Y_halfpelY(unsigned char *dst, unsigned char *src, ptrdiff_t pitch) {
  69.         for(int j=0; j<16; ++j)
  70.             for(int i=0; i<16; ++i)
  71.                 dst[j*pitch+i] = (dst[j*pitch+i] + (((unsigned)src[j*pitch+i] + (unsigned)src[(j+1)*pitch+i] + 1)>>1) + 1)>>1;
  72.     }
  73.  
  74.     static void add_Y_quadpel(unsigned char *dst, unsigned char *src, ptrdiff_t pitch) {
  75.         for(int j=0; j<16; ++j)
  76.             for(int i=0; i<16; ++i)
  77.                 dst[j*pitch+i] = (dst[j*pitch+i] + (((unsigned)src[j*pitch+i] + (unsigned)src[j*pitch+i+1] +
  78.                             (unsigned)src[(j+1)*pitch+i] + (unsigned)src[(j+1)*pitch+i+1] + 2)>>2) + 1)>>1;
  79.     }
  80.  
  81.     static void add_C_normal(unsigned char *dst, unsigned char *src, ptrdiff_t pitch) {
  82.         for(int j=0; j<8; ++j)
  83.             for(int i=0; i<8; ++i)
  84.                 dst[j*pitch+i] = (dst[j*pitch+i] + src[j*pitch+i] + 1)>>1;
  85.     }
  86.  
  87.     static void add_C_halfpelX(unsigned char *dst, unsigned char *src, ptrdiff_t pitch) {
  88.         for(int j=0; j<8; ++j)
  89.             for(int i=0; i<8; ++i)
  90.                 dst[j*pitch+i] = (dst[j*pitch+i] + (((unsigned)src[j*pitch+i] + (unsigned)src[j*pitch+i+1] + 1)>>1) + 1)>>1;
  91.     }
  92.  
  93.     static void add_C_halfpelY(unsigned char *dst, unsigned char *src, ptrdiff_t pitch) {
  94.         for(int j=0; j<8; ++j)
  95.             for(int i=0; i<8; ++i)
  96.                 dst[j*pitch+i] = (dst[j*pitch+i] + (((unsigned)src[j*pitch+i] + (unsigned)src[(j+1)*pitch+i] + 1)>>1) + 1)>>1;
  97.     }
  98.  
  99.     static void add_C_quadpel(unsigned char *dst, unsigned char *src, ptrdiff_t pitch) {
  100.         for(int j=0; j<8; ++j)
  101.             for(int i=0; i<8; ++i)
  102.                 dst[j*pitch+i] = (dst[j*pitch+i] + (((unsigned)src[j*pitch+i] + (unsigned)src[j*pitch+i+1] +
  103.                             (unsigned)src[(j+1)*pitch+i] + (unsigned)src[(j+1)*pitch+i+1] + 2)>>2) + 1)>>1;
  104.     }
  105. }
  106. ///////////////////////////////////////////////////////////////////////////
  107.  
  108. const struct VDMPEGPredictorSet g_VDMPEGPredict_reference = {
  109.     nsVDMPEGPredictReference::predict_Y_normal,
  110.     nsVDMPEGPredictReference::predict_Y_halfpelX,
  111.     nsVDMPEGPredictReference::predict_Y_halfpelY,
  112.     nsVDMPEGPredictReference::predict_Y_quadpel,
  113.     nsVDMPEGPredictReference::predict_C_normal,
  114.     nsVDMPEGPredictReference::predict_C_halfpelX,
  115.     nsVDMPEGPredictReference::predict_C_halfpelY,
  116.     nsVDMPEGPredictReference::predict_C_quadpel,
  117.     nsVDMPEGPredictReference::add_Y_normal,
  118.     nsVDMPEGPredictReference::add_Y_halfpelX,
  119.     nsVDMPEGPredictReference::add_Y_halfpelY,
  120.     nsVDMPEGPredictReference::add_Y_quadpel,
  121.     nsVDMPEGPredictReference::add_C_normal,
  122.     nsVDMPEGPredictReference::add_C_halfpelX,
  123.     nsVDMPEGPredictReference::add_C_halfpelY,
  124.     nsVDMPEGPredictReference::add_C_quadpel,
  125. };
  126.  
  127.