ditherer_lkbw.cc
上传用户:aoeyumen
上传日期:2007-01-06
资源大小:3329k
文件大小:2k
源码类别:

DVD

开发平台:

Unix_Linux

  1. #include "ditherer_lkbw.hh"
  2. #include <iostream>
  3. short unsigned int * DitherLK16BW::lookUpTable=0;
  4. DitherLK16BW::DitherLK16BW() {
  5.    _pixelSize=2;_bpp=16;
  6.    int i;
  7.    
  8.    if (lookUpTable==0) {
  9.       lookUpTable=new unsigned short[1<<8];
  10.       
  11.       for (i=0;i<256;++i) {
  12.          lookUpTable[i]=(i>>3)|((i>>2)<<5)|((i>>3)<<11);
  13.          //fprintf(stdout,"%d=%02x ",i, look_up_table[i]);
  14.       }
  15.    }
  16. }
  17. DitherLK16BW::~DitherLK16BW() {
  18. }
  19. void DitherLK16BW::dither(unsigned char * tY,
  20.                         unsigned char * tCr,
  21.                         unsigned char * tCb,
  22.                         unsigned char * imgDst,
  23.                         int imgWidth,
  24.                         int imgHeight,
  25.                         int viewWidth,
  26.                         int viewHeight,
  27.                         int screenWidth) {
  28.    int i,j;
  29.    int shift=screenWidth-viewWidth;
  30.    int realX,realY;
  31.    unsigned short * ditheredImage=(unsigned short *)imgDst;
  32.    unsigned char * tY_l;
  33.    
  34. #if 0
  35.    cerr<<"imgWidth="<<imgWidth<<" "
  36.        <<"imgHeight="<<imgHeight<<" "
  37.        <<"viewWidth="<<viewWidth<<" "
  38.        <<"viewHeight="<<viewHeight<<" "
  39.        <<"screenWidth="<<screenWidth
  40.        <<endl;
  41. #endif
  42.    
  43.    for (j=0;j<viewHeight;j++) {
  44.       realY=j*imgHeight/viewHeight;
  45.       //cerr<< "j=" << j << " realY="<<realY<<"     ";
  46.       tY_l=tY+(realY*imgWidth);
  47.       for (i=0;i<viewWidth;i++) {
  48.          realX=i*imgWidth/viewWidth;
  49.          *ditheredImage++ =             
  50.             lookUpTable[tY_l[realX]];
  51.       }
  52.       ditheredImage+=shift;
  53.    }
  54. }
  55.   
  56.