Logo Search packages:      
Sourcecode: blender version File versions

short IMB_converttocmap ( struct ImBuf ibuf  ) 

Attention:
Defined in cmap.c

Definition at line 408 of file cmap.c.

References ImBuf::cbits, ImBuf::cmap, IMB_converttocmap(), IMB_dit0(), IMB_dupImBuf(), IMB_freeImBuf(), ImBuf::maxcol, ImBuf::mincol, ImBuf::rect, ImBuf::x, and ImBuf::y.

Referenced by IMB_converttocmap(), and IMB_saveiff().

{
      unsigned int *coltab;
      short *deltab=0, cbits;
      int i;
      int mincol, mask = 0;
      struct ImBuf * abuf = 0;
      unsigned int * rect, * arect;
      
      cbits = 5;
      if (ibuf->cmap == 0) return(0);
      
      if ((ibuf->cbits > 0) && (ibuf->cbits <8)) cbits = ibuf->cbits;

      coltab = calloc(ibuf->maxcol, sizeof(unsigned int));
      if (coltab == 0) return(0);
      memcpy(coltab, ibuf->cmap, ibuf->maxcol * sizeof(unsigned int));
      
      mincol = ibuf->mincol;  
      if (alpha_col0) {
            if (mincol == 0) mincol = 1;
            abuf = IMB_dupImBuf(ibuf);
      }
      
      imb_losecmapbits(ibuf, coltab);
      deltab = imb_coldeltatab((uchar *) coltab, mincol ,ibuf->maxcol, cbits);
      
      if (deltab == 0) {
            free(coltab);
            if (abuf) IMB_freeImBuf(abuf);
            return(0);
      }


      IMB_dit0(ibuf,1,cbits);
      IMB_dit0(ibuf,2,cbits);
      IMB_dit0(ibuf,3,cbits);
      convcmap(ibuf, deltab, cbits);
      
      if (abuf) {
            /* convert alpha to color 0 */
            rect = ibuf->rect;
            arect = abuf->rect;
            
            if (alpha_col0 == 1) mask = 0xff000000; /* alpha ==  0 -> 0 */
            if (alpha_col0 == 2) mask = 0x80000000; /* alpha < 128 -> 0 */
            
            for (i = ibuf->x * ibuf->y; i > 0; i--) {
                  if ((*arect++ & mask) == 0) rect[0] = 0;
                  rect++;
            }
            
            IMB_freeImBuf(abuf);
      }

      free(coltab);
      
      return (TRUE);
}


Generated by  Doxygen 1.6.0   Back to index