Logo Search packages:      
Sourcecode: sam2p version File versions

Image::Indexed * Image::Sampled::toIndexed0 (  )  [protected]

Calls copyRGBRow.

Returns:
an Image::Indexed version of (this) iff the number of colors<=256. Otherwise, returns NULLP.

Definition at line 216 of file image.cpp.

References copyRGBRow(), Hash46::walk(), and wd.

                                                 {
  unsigned char *crow=new unsigned char[wd*3], k[6], *p, *pend, *w;
  Image::Indexed *img=new Image::Indexed(wd, ht, 256, 8);
  dimen_t htc;
  unsigned char *pal=(unsigned char*)img->getHeadp(), *outp=(unsigned char*)img->getRowbeg();
  unsigned ncols=0;
  Hash46 h;
  k[0]=0;
  for (htc=0;htc<ht;htc++) {
    copyRGBRow((char*)crow, htc);
    for (p=crow,pend=crow+wd*3; p!=pend; p+=3) {
      memcpy(k+1, p, 3);
      w=h.walk(k);
      assert(w!=NULL); /* Hash cannot be full since h.M>=256. */
      /* fprintf(stderr, "w=%p\n", w); */
      if (*w==/*h.*/FREE) {
        if (ncols==256) { delete img; delete [] crow; return (Image::Indexed*)NULLP; }
        /* ^^^ too many colors; cannot convert image to indexed */
        memcpy(w,k,4);
        memcpy(pal,k+1,3);
        /* fprintf(stderr,"newcol=%02x #%02x%02x%02x\n", k[0], k[1], k[2], k[3]); */
        /* fprintf(stderr,"newcol=pal #%02x%02x%02x\n", pal[0], pal[1], pal[2]); */
        pal+=3;
        *outp++=w[4]=ncols++;
      } else { /* a color that we have already seen */
        *outp++=w[4];
      }
    }
  }
  img->setNcolsMove(ncols);
  delete [] crow;

  /* Now img is ready. The user should call packPal() to make it even tighter. */
  return img;
}


Generated by  Doxygen 1.6.0   Back to index