int fh_gif_load(char *name, unsigned char *buf, unsigned char ** alpha, int x, int y) { Log(LOG_DEBUG, "function:%s --- paralist:name=%s,x=%d,y=%d\n", __func__, name, x, y); int in_nextrow[4] = { 8, 8, 4, 2 }; //interlaced jump to the row current+in_nextrow int in_beginrow[4] = { 0, 4, 2, 1 }; //begin pass j from that row number int transparency = -1; //-1 means not transparency present int px, py, i, j; int cmaps; int extcode; char *fbptr; char *lb; char *slb; GifFileType *gft; GifByteType *extension; GifRecordType rt; ColorMapObject *cmap; int delay = 0; //int error = 0; struct image *img = NULL; unsigned char *buffer = NULL; //if(NULL == (gft=DGifOpenFileName(name, &error))){ if (NULL == (gft = DGifOpenFileName(name))) { Log(LOG_WARN, "function:%s --- gif file open failed!\n", __func__); gflush; } if (NULL == (img = (struct image *) malloc(sizeof(struct image)))) { Log(LOG_WARN, "function:%s --- gif malloc failed!\n", __func__); grflush; } do { if (DGifGetRecordType(gft, &rt) == GIF_ERROR) { Log(LOG_WARN, "function:%s --- gif get record type failed!\n", __func__); grflush } switch (rt) { case IMAGE_DESC_RECORD_TYPE: if (DGifGetImageDesc(gft) == GIF_ERROR) { Log(LOG_WARN, "function:%s --- gif get desc failed!\n", __func__); grflush } px = gft->Image.Width; py = gft->Image.Height; Log(LOG_INFO, "function:%s --- paralist:name=%s,x=%d,y=%d\n", __func__, name, px, py); lb = (char*) malloc(px * 3); slb = (char*) malloc(px); buffer = (unsigned char *) malloc(px * py * 3); if (lb != NULL && slb != NULL && buffer != NULL) { unsigned char *alphaptr = NULL; cmap = (gft->Image.ColorMap ? gft->Image.ColorMap : gft->SColorMap); cmaps = cmap->ColorCount; fbptr = (char*) buffer; if (transparency != -1) { if (NULL == (alphaptr = malloc(px * py))) { Log(LOG_WARN, "function:%s --- alphaptr malloc failed!\n", __func__); } *alpha = alphaptr; } if (!(gft->Image.Interlace)) { for (i = 0; i < py; i++, fbptr += px * 3) { int j; if (DGifGetLine(gft, (GifPixelType*) slb, px) == GIF_ERROR) { Log(LOG_WARN, "function:%s --- gif get line failed!\n", __func__); mgrflush; } m_rend_gif_decodecolormap((unsigned char*) slb, (unsigned char*) lb, cmap, cmaps, px, transparency); memcpy(fbptr, lb, px * 3); if (alphaptr) for (j = 0; j < px; j++) { *(alphaptr++) = (((unsigned char*) slb)[j] == transparency) ? 0x00 : 0xff; } } } else { unsigned char * aptr = NULL; for (j = 0; j < 4; j++) { int k; if (alphaptr) aptr = alphaptr + (in_beginrow[j] * px); fbptr = (char*) buffer + (in_beginrow[j] * px * 3); for (i = in_beginrow[j]; i < py; i += in_nextrow[j], fbptr += px * 3 * in_nextrow[j], aptr += px * in_nextrow[j]) { if (DGifGetLine(gft, (GifPixelType*) slb, px) == GIF_ERROR) { Log(LOG_WARN, "function:%s --- gif get line failed!\n", __func__); mgrflush } m_rend_gif_decodecolormap((unsigned char*) slb, (unsigned char*) lb, cmap, cmaps, px, transparency); memcpy(fbptr, lb, px * 3); if (alphaptr) for (k = 0; k < px; k++) { aptr[k] = (((unsigned char*) slb)[k] == transparency) ? 0x00 : 0xff; } } } }
//int fh_gif_load(char *name,unsigned char *buffer, unsigned char ** alpha, int x,int y) int fh_gif_load(aml_dec_para_t* para , aml_image_info_t* image) { int in_nextrow[4]={8,8,4,2}; //interlaced jump to the row current+in_nextrow int in_beginrow[4]={0,4,2,1}; //begin pass j from that row number int transparency=-1; //-1 means not transparency present int px,py,i,ibxs; int j; char *fbptr; char *lb; char *slb; GifFileType *gft; GifByteType *extension; int extcode; GifRecordType rt; ColorMapObject *cmap; int cmaps; char *p,*q; int buf_len; char* name; char* buffer; char* alpha = NULL; int x,y; name = para->fn; buffer = (unsigned char*) malloc(para->iwidth * para->iheight * 4); buf_len = para->iwidth * para->iheight; x = para->iwidth; y = para->iheight; gft=DGifOpenFileName(name); if(gft==NULL){printf("err5\n"); gflush;} ////////// do { if(DGifGetRecordType(gft,&rt) == GIF_ERROR) grflush; switch(rt) { case IMAGE_DESC_RECORD_TYPE: if(DGifGetImageDesc(gft)==GIF_ERROR) grflush; px=gft->Image.Width; py=gft->Image.Height; lb=(char*)malloc(px*3); slb=(char*) malloc(px); // printf("reading...\n"); if(lb!=NULL && slb!=NULL) { unsigned char *alphaptr = NULL; cmap=(gft->Image.ColorMap ? gft->Image.ColorMap : gft->SColorMap); cmaps=cmap->ColorCount; ibxs=ibxs*3; fbptr=(char*)buffer; if(transparency != -1) { alphaptr = malloc(px * py); alpha = alphaptr; } if(!(gft->Image.Interlace)) { for(i=0;i<py;i++,fbptr+=px*3) { int j; if(DGifGetLine(gft,(GifPixelType*)slb,px)==GIF_ERROR) mgrflush; m_rend_gif_decodecolormap((unsigned char*)slb,(unsigned char*)lb,cmap,cmaps,px,transparency); memcpy(fbptr,lb,px*3); if(alphaptr) for(j = 0; j<px; j++) *(alphaptr++) = (((unsigned char*) slb)[j] == transparency) ? 0x00 : 0xff; } } else { unsigned char * aptr = NULL; for(j=0;j<4;j++) { int k; if(alphaptr) aptr = alphaptr + (in_beginrow[j] * px); fbptr=(char*)buffer + (in_beginrow[j] * px * 3); for(i = in_beginrow[j]; i<py; i += in_nextrow[j], fbptr += px * 3 * in_nextrow[j], aptr += px * in_nextrow[j]) { if(DGifGetLine(gft,(GifPixelType*)slb,px)==GIF_ERROR) mgrflush; ///////////// m_rend_gif_decodecolormap((unsigned char*)slb,(unsigned char*)lb,cmap,cmaps,px,transparency); memcpy(fbptr,lb,px*3); if(alphaptr) for(k = 0; k<px; k++) aptr[k] = (((unsigned char*) slb)[k] == transparency) ? 0x00 : 0xff; } } } } if(lb) free(lb); if(slb) free(slb); break; case EXTENSION_RECORD_TYPE: if(DGifGetExtension(gft,&extcode,&extension)==GIF_ERROR) grflush; ////////// if(extcode==0xf9) //look image transparency in graph ctr extension { if(extension[1] & 1) { transparency = extension[4]; } // tran_off=(int)*extension; // transparency=(int)*(extension+tran_off); // printf("transparency: %d\n", transparency); } while(extension!=NULL) if(DGifGetExtensionNext(gft,&extension) == GIF_ERROR) grflush break; default: break; } } while( rt!= TERMINATE_RECORD_TYPE ); DGifCloseFile(gft); p = buffer; q = alpha ; for(i = buf_len ; i >0 ;i--){ if(!q){ p[4*i - 1] = 0xff; }else{ p[4*i - 1] = q[i-1]; //a } p[4*i - 2] = p[3*i - 3]; //r p[4*i - 3] = p[3*i - 2]; //g p[4*i - 4] = p[3*i - 1]; //b } image->data = buffer; image->width = x; image->height = y; image->depth = 32; image->bytes_per_line = x << 2 ; image->nbytes = image->bytes_per_line * y; return(FH_ERROR_OK); }
int fh_gif_load(const char *name,unsigned char **buffer,int* /*xp*/,int* /*yp*/) { int px,py,i/*,ibxs*/; int j; unsigned char *fbptr; unsigned char *lb; unsigned char *slb; GifFileType *gft; GifByteType *extension; int extcode; GifRecordType rt; ColorMapObject *cmap; int cmaps; #if GIFLIB_MAJOR >= 5 int error; gft=DGifOpenFileName(name, &error); #else gft=DGifOpenFileName(name); #endif if(gft==NULL) gflush; do { if(DGifGetRecordType(gft,&rt) == GIF_ERROR) grflush; switch(rt) { case IMAGE_DESC_RECORD_TYPE: if(DGifGetImageDesc(gft)==GIF_ERROR) grflush; px=gft->Image.Width; py=gft->Image.Height; lb=(unsigned char*)malloc(px*3); slb=(unsigned char*) malloc(px); // printf("reading...\n"); if(lb!=NULL && slb!=NULL) { cmap=(gft->Image.ColorMap ? gft->Image.ColorMap : gft->SColorMap); cmaps=cmap->ColorCount; // ibxs=ibxs*3; fbptr=*buffer; if(!(gft->Image.Interlace)) { for(i=0;i<py;i++,fbptr+=px*3) { if(DGifGetLine(gft,slb,px)==GIF_ERROR) mgrflush; m_rend_gif_decodecolormap(slb,lb,cmap,cmaps,px); memmove(fbptr,lb,px*3); } } else { for(j=0;j<4;j++) { fbptr=*buffer; for(i=0;i<py;i++,fbptr+=px*3) { if(DGifGetLine(gft,slb,px)==GIF_ERROR) mgrflush; m_rend_gif_decodecolormap(slb,lb,cmap,cmaps,px); memmove(fbptr,lb,px*3); } } } } if(lb) free(lb); if(slb) free(slb); break; case EXTENSION_RECORD_TYPE: if(DGifGetExtension(gft,&extcode,&extension)==GIF_ERROR) grflush; while(extension!=NULL) if(DGifGetExtensionNext(gft,&extension)==GIF_ERROR) grflush; break; default: break; } } while( rt!= TERMINATE_RECORD_TYPE ); DGIFCLOSEFILE(gft); return(FH_ERROR_OK); }