Logo Search packages:      
Sourcecode: sam2p version File versions

Image::Gray * Image::Sampled::toGray0 ( unsigned char  bpc_  )  [protected]

No averaging is done, only the red component is extracted

Definition at line 126 of file image.cpp.

References copyRGBRow(), ht, and wd.

                                                      {
  unsigned char *crow=new unsigned char[wd*3+7*3], *p, *pend;
  Image::Gray *img=new Image::Gray(wd, ht, bpc_);
  unsigned char *outp=(unsigned char*)img->getRowbeg();
  dimen_t htc;
  memset(crow+wd*3, '\0', 7*3); /* *3 BUGFIX at Tue Jan 18 17:04:15 CET 2005 */
  unsigned i;
  /* Dat: not optimising for minimal rounding error since caller should ensure
   *      that there is no such error at all.
   */
  if (bpc_==1) {
    assert(img->getBpc()==1);
    for (htc=0;htc<ht;htc++) {
      copyRGBRow((char*)crow, htc);
      for (p=crow-3,pend=p+wd*3; p<pend; ) {
        i =(*(p+=3)!=0)<<7; i|=(*(p+=3)!=0)<<6; i|=(*(p+=3)!=0)<<5; i|=(*(p+=3)!=0)<<4;
        i|=(*(p+=3)!=0)<<3; i|=(*(p+=3)!=0)<<2; i|=(*(p+=3)!=0)<<1; i|=(*(p+=3)!=0);
        *outp++=i;
      }
    }
  } else if (bpc_==2) {
    for (htc=0;htc<ht;htc++) {
      copyRGBRow((char*)crow, htc);
      for (p=crow-3,pend=p+wd*3; p<pend; ) {
        i =(*(p+=3)/85)<<6; i|=(*(p+=3)/85)<<4; i|=(*(p+=3)/85)<<2; i|=(*(p+=3)/85);
        *outp++=i;
      }
    }
  } else if (bpc_==4) {
    for (htc=0;htc<ht;htc++) {
      copyRGBRow((char*)crow, htc);
      for (p=crow-3,pend=p+wd*3; p<pend; ) {
        i =(*(p+=3)/17)<<4; i|=(*(p+=3)/17);
        *outp++=i;
      }
    }
  } else if (bpc_==8) {
    for (htc=0;htc<ht;htc++) {
      copyRGBRow((char*)crow, htc);
      for (p=crow-3,pend=p+wd*3; p!=pend; ) {
        *outp++=*(p+=3);
      }
    }
  } else assert(0);
  return img;
}


Generated by  Doxygen 1.6.0   Back to index