static int gif_parse_next_image(GifState *s, AVFrame *frame) { while (bytestream2_get_bytes_left(&s->gb) > 0) { int code = bytestream2_get_byte(&s->gb); int ret; av_log(s->avctx, AV_LOG_DEBUG, "code=%02x '%c'\n", code, code); switch (code) { case GIF_IMAGE_SEPARATOR: return gif_read_image(s, frame); case GIF_EXTENSION_INTRODUCER: if ((ret = gif_read_extension(s)) < 0) return ret; break; case GIF_TRAILER: /* end of image */ return AVERROR_EOF; default: /* erroneous block label */ return AVERROR_INVALIDDATA; } } return AVERROR_EOF; }
static int gif_parse_next_image(GifState *s) { int ret, code; for (;;) { code = bytestream_get_byte(&s->bytestream); #ifdef DEBUG dprintf("gif: code=%02x '%c'\n", code, code); #endif switch (code) { case ',': if (gif_read_image(s) < 0) return -1; ret = 0; goto the_end; case ';': /* end of image */ ret = -1; goto the_end; case '!': if (gif_read_extension(s) < 0) return -1; break; case EOF: default: /* error or errneous EOF */ ret = -1; goto the_end; } } the_end: return ret; }
static int gif_parse_next_image(GifState *s, int *got_picture) { int ret; *got_picture = sizeof(AVPicture); while (s->bytestream < s->bytestream_end) { int code = bytestream_get_byte(&s->bytestream); av_dlog(s->avctx, "code=%02x '%c'\n", code, code); switch (code) { case GIF_IMAGE_SEPARATOR: return gif_read_image(s); case GIF_EXTENSION_INTRODUCER: if ((ret = gif_read_extension(s)) < 0) return ret; break; case GIF_TRAILER: /* end of image */ *got_picture = 0; return 0; default: /* erroneous block label */ return AVERROR_INVALIDDATA; } } return AVERROR_EOF; }
fz_pixmap * fz_load_gif(fz_context *ctx, unsigned char *p, size_t total) { fz_pixmap *image; struct info gif; image = gif_read_image(ctx, &gif, p, total, 0); image->xres = gif.xres; image->yres = gif.yres; return image; }
void fz_load_gif_info(fz_context *ctx, const unsigned char *p, size_t total, int *wp, int *hp, int *xresp, int *yresp, fz_colorspace **cspacep) { struct info gif; gif_read_image(ctx, &gif, p, total, 1); *cspacep = fz_keep_colorspace(ctx, fz_device_rgb(ctx)); *wp = gif.width; *hp = gif.height; *xresp = gif.xres; *yresp = gif.yres; }
static int gif_parse_next_image(GifState *s) { while (s->bytestream < s->bytestream_end) { int code = bytestream_get_byte(&s->bytestream); #ifdef DEBUG dprintf(s->avctx, "gif: code=%02x '%c'\n", code, code); #endif switch (code) { case ',': return gif_read_image(s); case '!': if (gif_read_extension(s) < 0) return -1; break; case ';': /* end of image */ default: /* error or erroneous EOF */ return -1; } } return -1; }
static int gif_parse_next_image(GifState *s, AVFrame *frame) { while (bytestream2_get_bytes_left(&s->gb) > 0) { int code = bytestream2_get_byte(&s->gb); int ret; av_dlog(s->avctx, "gif: code=%02x '%c'\n", code, code); switch (code) { case ',': return gif_read_image(s, frame); case '!': if ((ret = gif_read_extension(s)) < 0) return ret; break; case ';': /* end of image */ default: /* error or erroneous EOF */ return AVERROR_INVALIDDATA; } } return AVERROR_INVALIDDATA; }
int /* O - Read status */ _cupsImageReadGIF( cups_image_t *img, /* IO - cupsImage */ FILE *fp, /* I - cupsImage file */ cups_icspace_t primary, /* I - Primary choice for colorspace */ cups_icspace_t secondary, /* I - Secondary choice for colorspace */ int saturation, /* I - Color saturation (%) */ int hue, /* I - Color hue (degrees) */ const cups_ib_t *lut) /* I - Lookup table for gamma/brightness */ { unsigned char buf[1024]; /* Input buffer */ gif_cmap_t cmap; /* Colormap */ int i, /* Looping var */ bpp, /* Bytes per pixel */ gray, /* Grayscale image? */ ncolors, /* Bits per pixel */ transparent; /* Transparent color index */ /* * GIF files are either grayscale or RGB - no CMYK... */ if (primary == CUPS_IMAGE_RGB_CMYK) primary = CUPS_IMAGE_RGB; /* * Read the header; we already know it is a GIF file... */ fread(buf, 13, 1, fp); img->xsize = (buf[7] << 8) | buf[6]; img->ysize = (buf[9] << 8) | buf[8]; ncolors = 2 << (buf[10] & 0x07); gray = primary == CUPS_IMAGE_BLACK || primary == CUPS_IMAGE_WHITE; if (buf[10] & GIF_COLORMAP) if (gif_read_cmap(fp, ncolors, cmap, &gray)) { fclose(fp); return (-1); } transparent = -1; for (;;) { switch (getc(fp)) { case ';' : /* End of image */ fclose(fp); return (-1); /* Early end of file */ case '!' : /* Extension record */ buf[0] = getc(fp); if (buf[0] == 0xf9) /* Graphic Control Extension */ { gif_get_block(fp, buf); if (buf[0] & 1) /* Get transparent color index */ transparent = buf[3]; } while (gif_get_block(fp, buf) != 0); break; case ',' : /* cupsImage data */ fread(buf, 9, 1, fp); if (buf[8] & GIF_COLORMAP) { ncolors = 2 << (buf[8] & 0x07); gray = primary == CUPS_IMAGE_BLACK || primary == CUPS_IMAGE_WHITE; if (gif_read_cmap(fp, ncolors, cmap, &gray)) { fclose(fp); return (-1); } } if (transparent >= 0) { /* * Make transparent color white... */ cmap[transparent][0] = 255; cmap[transparent][1] = 255; cmap[transparent][2] = 255; } if (gray) { switch (secondary) { case CUPS_IMAGE_CMYK : for (i = ncolors - 1; i >= 0; i --) cupsImageWhiteToCMYK(cmap[i], cmap[i], 1); break; case CUPS_IMAGE_CMY : for (i = ncolors - 1; i >= 0; i --) cupsImageWhiteToCMY(cmap[i], cmap[i], 1); break; case CUPS_IMAGE_BLACK : for (i = ncolors - 1; i >= 0; i --) cupsImageWhiteToBlack(cmap[i], cmap[i], 1); break; case CUPS_IMAGE_WHITE : break; case CUPS_IMAGE_RGB : case CUPS_IMAGE_RGB_CMYK : for (i = ncolors - 1; i >= 0; i --) cupsImageWhiteToRGB(cmap[i], cmap[i], 1); break; } img->colorspace = secondary; } else { if (hue != 0 || saturation != 100) for (i = ncolors - 1; i >= 0; i --) cupsImageRGBAdjust(cmap[i], 1, saturation, hue); switch (primary) { case CUPS_IMAGE_CMYK : for (i = ncolors - 1; i >= 0; i --) cupsImageRGBToCMYK(cmap[i], cmap[i], 1); break; case CUPS_IMAGE_CMY : for (i = ncolors - 1; i >= 0; i --) cupsImageRGBToCMY(cmap[i], cmap[i], 1); break; case CUPS_IMAGE_BLACK : for (i = ncolors - 1; i >= 0; i --) cupsImageRGBToBlack(cmap[i], cmap[i], 1); break; case CUPS_IMAGE_WHITE : for (i = ncolors - 1; i >= 0; i --) cupsImageRGBToWhite(cmap[i], cmap[i], 1); break; case CUPS_IMAGE_RGB : case CUPS_IMAGE_RGB_CMYK : for (i = ncolors - 1; i >= 0; i --) cupsImageRGBToRGB(cmap[i], cmap[i], 1); break; } img->colorspace = primary; } if (lut) { bpp = cupsImageGetDepth(img); for (i = ncolors - 1; i >= 0; i --) cupsImageLut(cmap[i], bpp, lut); } img->xsize = (buf[5] << 8) | buf[4]; img->ysize = (buf[7] << 8) | buf[6]; /* * Check the dimensions of the image; since the dimensions are * a 16-bit integer we just need to check for 0... */ if (img->xsize == 0 || img->ysize == 0) { fprintf(stderr, "DEBUG: Bad GIF image dimensions: %dx%d\n", img->xsize, img->ysize); fclose(fp); return (1); } i = gif_read_image(fp, img, cmap, buf[8] & GIF_INTERLACE); fclose(fp); return (i); } } }