|
楼主 |
发表于 2009-12-9 11:38:50
|
显示全部楼层
- static void
- decode_row(GifFileType * giffile,
- unsigned char * buffer,
- unsigned char * rowdata,
- int x, int y, int len,
- int transparent)
- {
- GifColorType * cmentry;
- ColorMapObject * colormap;
- int colormapsize;
- unsigned char col;
- unsigned char * ptr;
- y = giffile->SHeight - (y+1);
- ptr = buffer + (giffile->SWidth * y + x) * 4;
- colormap = (giffile->Image.ColorMap
- ? giffile->Image.ColorMap
- : giffile->SColorMap);
- colormapsize = colormap ? colormap->ColorCount : 255;
- while (len--)
- {
- col = *rowdata++;
- /* just in case */
- if (col >= colormapsize) col = 0;
- if ( col == transparent )
- {
- // keep pixels of last image if transparent mode is on
- // this is necessary for GIF animating
- ptr += 3;
- }
- else
- {
- cmentry = colormap ? &colormap->Colors[col] : NULL;
- if (cmentry)
- {
- *ptr++ = cmentry->Red;
- *ptr++ = cmentry->Green;
- *ptr++ = cmentry->Blue;
- }
- else
- {
- *ptr++ = col;
- *ptr++ = col;
- *ptr++ = col;
- }
- }
- *ptr++ = (col == transparent ? 0x00 : 0xff);
- }
- }
复制代码 最后一句是对像素alpha分量赋值,这样就有不透和全透两种情况
而transparent参数来自于gif文件-
- case EXTENSION_RECORD_TYPE:
- /* Skip any extension blocks in file: */
- if (DGifGetExtension(giffile, &extcode, &extension) == GIF_ERROR)
- {
- giferror = ERR_READ;
- delete [] buffer;
- delete [] rowdata;
- return NULL;
- }
- /* transparent test from the gimp gif-plugin. Open Source rulez! */
- else if (extcode == 0xf9)
- {
- if (extension[0] >= 4 && extension[1] & 0x1) transparent = extension[4];
- else transparent = -1;
- delaytime = (extension[3]<<8)+extension[2]; // minimum unit 1/100s, so 8 here means 8/100s
- }
复制代码 以上是osgdb_gif工程(2.8.2)中的代码,我不知道GIF89是否有存储alpha值,但从这段代码来看,应该是每帧图像有一个字段存储了透明色,代码中正是根据这个“透明色”来为alpha通道赋值的 |
|