Logo Search packages:      
Sourcecode: sam2p version File versions

void Image::Sampled::to8mul (  )  [protected]

Convert samples, make bpc=8, multiplication.

Definition at line 252 of file image.cpp.

References bpc, cpp, rlen, and wd.

                          {
  if (bpc==8) return;
  if (wd==0 || ht==0) { bpc=8; return; }

  unsigned oldBpc=bpc;
  slen_t wdcpp=wd*cpp;
  const char *oldBeg=beg;
  unsigned char *p=(unsigned char*)rowbeg;

  bpc=8;
  rlen=wd;
  beg=new char[len=rowbeg-oldBeg+rlen*ht+bpc];
  headp= const_cast<char*>(beg)+(headp-oldBeg);
  rowbeg=const_cast<char*>(beg)+(rowbeg-oldBeg);
  trail= const_cast<char*>(beg)+len-bpc;
  memcpy(const_cast<char*>(beg), oldBeg, rowbeg-beg);
  
  unsigned char *to=(unsigned char*)rowbeg, *toend;
  unsigned int i, j;
  Image::Sampled::dimen_t htc;
  if (oldBpc==1) {
    htc=ht; while (htc--!=0) {
      toend=to+((wdcpp)&~7);
      while (to!=toend) {
        i=*p++;
        *to++=(i>>7)*255;
        *to++=((i>>6)&1)*255;
        *to++=((i>>5)&1)*255;
        *to++=((i>>4)&1)*255;
        *to++=((i>>3)&1)*255;
        *to++=((i>>2)&1)*255;
        *to++=((i>>1)&1)*255;
        *to++=(     i&1)*255;
      }
      if (0!=(j=(wdcpp)&7)) {
        i=*p; /* No mem overrun, even if (wd&7)==0 */
        while (j--!=0) { *to++=(i>>7)*255; i<<=1; }
      }
    }
  } else if (oldBpc==2) {
    htc=ht; while (htc--!=0) {
      toend=to+((wdcpp)&~3);
      while (to!=toend) {
        i=*p++;
        *to++=(i>>6)*85;
        *to++=((i>>4)&3)*85;
        *to++=((i>>2)&3)*85;
        *to++=(     i&3)*85;
      }
      if (0!=(j=(wdcpp)&3)) {
        i=*p; /* No mem overrun, even if (wd&7)==0 */
        while (j--!=0) { *to++=(i>>6)*85; i<<=2; }
      }
    }
  } else if (oldBpc==4) {
    htc=ht; while (htc--!=0) {
      toend=to+((wdcpp)&~1);
      while (to!=toend) {
        i=*p++;
        *to++=(i>>4)*17;
        *to++=(     i&15)*17;
      }
      if (0!=((wdcpp)&1)) *to++=(*p++>>4)*17;
    }
  } else assert(0 && "invalid bpc");
  
  delete [] const_cast<char*>(oldBeg);
}


Generated by  Doxygen 1.6.0   Back to index