static int ReadImage (MG_RWops* area, MYBITMAP* bmp, IMAGEDESC* ImageDesc, GIFSCREEN* GifScreen, int ignore) { unsigned char c; int v; int xpos = 0, ypos = 0, pass = 0; /* * initialize the compression routines */ if (!ReadOK (area, &c, 1)) { _MG_PRINTF ("EX_CTRL>GIF89a: eof on image data\n"); return -1; } if (LWZReadByte (area, TRUE, c) < 0) { _MG_PRINTF ("EX_CTRL>GIF89a: error reading image\n"); return -1; } /* * if this is an "uninteresting picture" ignore it. */ if (ignore) { while (LWZReadByte (area, FALSE, c) >= 0); return 0; } bmp->w = ImageDesc->Width; bmp->h = ImageDesc->Height; bmp->flags = MYBMP_FLOW_DOWN; if (GifScreen->transparent >= 0) { bmp->flags |= MYBMP_TRANSPARENT; bmp->transparent = GifScreen->transparent; } bmp->frames = 1; bmp->depth = 8; bmpComputePitch (bmp->depth, bmp->w, &bmp->pitch, TRUE); bmp->bits = malloc (bmp->h * bmp->pitch); if(!bmp->bits) return -1; while ((v = LWZReadByte (area, FALSE, c)) >= 0) { bmp->bits[ypos * bmp->pitch + xpos] = v; ++xpos; if (xpos == ImageDesc->Width) { xpos = 0; if (ImageDesc->interlace) { switch (pass) { case 0: case 1: ypos += 8; break; case 2: ypos += 4; break; case 3: ypos += 2; break; } if (ypos >= ImageDesc->Height) { ++pass; switch (pass) { case 1: ypos = 4; break; case 2: ypos = 2; break; case 3: ypos = 1; break; default: goto fini; } } } else { ++ypos; } } if (ypos >= ImageDesc->Height) break; } fini: if (v >= 0) return 0; return -1; }
/*--------------------------------------------------------------------------*/ static SDL_Surface* ReadImage( gifdata* gd, int len, int height, int cmapSize, unsigned char cmap[3][MAXCOLORMAPSIZE], int interlace, int ignore ) { SDL_Surface* image; unsigned char c; int i, v; int xpos = 0, ypos = 0, pass = 0; /* Initialize the compression routines */ if ( !SDL_RWread(gd->src,&c,1,1) ) { SDL_SetError( "EOF / read error on image data" ); return NULL; } if ( LWZReadByte(gd,TRUE,c) < 0 ) { SDL_SetError( "error reading image" ); return NULL; } /* If this is an "uninteresting picture" ignore it. */ if ( ignore ) { while ( LWZReadByte(gd,FALSE,c) >= 0 ) ; return NULL; } image = SDL_AllocSurface( SDL_SWSURFACE, len, height, 8, 0, 0, 0, 0 ); for ( i = 0; i < cmapSize; i++ ) { image->format->palette->colors[i].r = cmap[CM_RED][i]; image->format->palette->colors[i].g = cmap[CM_GREEN][i]; image->format->palette->colors[i].b = cmap[CM_BLUE][i]; } while ( (v = LWZReadByte(gd,FALSE,c)) >= 0 ) { ((Uint8*)image->pixels)[xpos + ypos*image->pitch] = (Uint8)v; ++xpos; if ( xpos == len ) { xpos = 0; if ( interlace ) { switch ( pass ) { case 0: case 1: ypos += 8; break; case 2: ypos += 4; break; case 3: ypos += 2; break; } if ( ypos >= height ) { ++pass; switch ( pass ) { case 1: ypos = 4; break; case 2: ypos = 2; break; case 3: ypos = 1; break; default: goto fini; } } } else { ++ypos; } } if ( ypos >= height ) break; } fini: return image; }
static Image * ReadImage(SDL_RWops * src, int len, int height, int cmapSize, unsigned char cmap[3][MAXCOLORMAPSIZE], int gray, int interlace, int ignore) { Image *image; unsigned char c; int i, v; int xpos = 0, ypos = 0, pass = 0; /* ** Initialize the compression routines */ if (!ReadOK(src, &c, 1)) { RWSetMsg("EOF / read error on image data"); return NULL; } if (LWZReadByte(src, TRUE, c) < 0) { RWSetMsg("error reading image"); return NULL; } /* ** If this is an "uninteresting picture" ignore it. */ if (ignore) { while (LWZReadByte(src, FALSE, c) >= 0) ; return NULL; } image = ImageNewCmap(len, height, cmapSize); for (i = 0; i < cmapSize; i++) ImageSetCmap(image, i, cmap[CM_RED][i], cmap[CM_GREEN][i], cmap[CM_BLUE][i]); while ((v = LWZReadByte(src, FALSE, c)) >= 0) { #ifdef USED_BY_SDL ((Uint8 *)image->pixels)[xpos + ypos * image->pitch] = v; #else image->data[xpos + ypos * len] = v; #endif ++xpos; if (xpos == len) { xpos = 0; if (interlace) { switch (pass) { case 0: case 1: ypos += 8; break; case 2: ypos += 4; break; case 3: ypos += 2; break; } if (ypos >= height) { ++pass; switch (pass) { case 1: ypos = 4; break; case 2: ypos = 2; break; case 3: ypos = 1; break; default: goto fini; } } } else { ++ypos; } } if (ypos >= height) break; } fini: return image; }
static int ReadImage( IDirectFBVideoProvider_GIF_data *data, int left, int top, int width, int height, u8 cmap[3][MAXCOLORMAPSIZE], bool interlace, bool ignore ) { u8 c; int v; int xpos = 0, ypos = 0, pass = 0; u32 *image, *dst; /* ** Initialize the decompression routines */ if (FetchData( data->buffer, &c, 1 )) GIFERRORMSG("EOF / read error on image data"); if (LWZReadByte( data, true, c ) < 0) GIFERRORMSG("error reading image"); /* ** If this is an "uninteresting picture" ignore it. */ if (ignore) { GIFDEBUGMSG("skipping image..."); while (LWZReadByte( data, false, c ) >= 0) ; return 0; } switch (data->disposal) { case 2: GIFDEBUGMSG("restoring to background color..."); memset( data->image, 0, data->Width * data->Height * 4 ); break; case 3: GIFERRORMSG("restoring to previous frame is unsupported"); break; default: break; } dst = image = data->image + (top * data->Width + left); GIFDEBUGMSG("reading %dx%d at %dx%d %sGIF image", width, height, left, top, interlace ? " interlaced " : "" ); while ((v = LWZReadByte( data, false, c )) >= 0 ) { if (v != data->transparent) { dst[xpos] = (0xFF000000 | cmap[CM_RED][v] << 16 | cmap[CM_GREEN][v] << 8 | cmap[CM_BLUE][v]); } ++xpos; if (xpos == width) { xpos = 0; if (interlace) { switch (pass) { case 0: case 1: ypos += 8; break; case 2: ypos += 4; break; case 3: ypos += 2; break; } if (ypos >= height) { ++pass; switch (pass) { case 1: ypos = 4; break; case 2: ypos = 2; break; case 3: ypos = 1; break; default: goto fini; } } } else { ++ypos; } dst = image + ypos * data->Width; } if (ypos >= height) { break; } } fini: if (LWZReadByte( data, false, c ) >= 0) { GIFERRORMSG("too much input data, ignoring extra..."); //while (LWZReadByte( data, false, c ) >= 0); } return 0; }