Logo Search packages:      
Sourcecode: sam2p version File versions

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

Convert samples, make bpc=8, no multiplication.

Definition at line 321 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);
        *to++=((i>>6)&1);
        *to++=((i>>5)&1);
        *to++=((i>>4)&1);
        *to++=((i>>3)&1);
        *to++=((i>>2)&1);
        *to++=((i>>1)&1);
        *to++=(     i&1);
      }
      if (0!=(j=(wdcpp)&7)) {
        i=*p++; /* No mem overrun, even if (wd&7)==0 */
        while (j--!=0) { *to++=(i>>7); i<<=1; }
      }
    }
  } else if (oldBpc==2) {
    // assert(0);
    htc=ht; while (htc--!=0) {
      toend=to+((wdcpp)&~3);
      while (to!=toend) {
        i=*p++;
        *to++=(i>>6);
        *to++=((i>>4)&3);
        *to++=((i>>2)&3);
        *to++=(     i&3);
      }
      if (0!=(j=(wdcpp)&3)) {
        i=*p++;
        // fprintf(stderr,"j=%d\n",j);
        while (j--!=0) { *to++=(i>>6); i<<=2; }
      }
    }
    assert((slen_t)((char*)to-rowbeg)==(slen_t)wd*cpp*ht);
  } else if (oldBpc==4) {
    htc=ht; while (htc--!=0) {
      toend=to+((wdcpp)&~1);
      while (to!=toend) {
        i=*p++;
        *to++=(i>>4);
        *to++=(     i&15);
      }
      if (0!=((wdcpp)&1)) *to++=(*p++>>4);
    }
  } else assert(0 && "invalid bpc");
  
  delete [] const_cast<char*>(oldBeg);
}


Generated by  Doxygen 1.6.0   Back to index