X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Fgif.c;h=bf3f5fc73d2d5d2411e6311ffcf806ba366aa227;hp=2462e1395500336e5c79de394232afbd78ca39ba;hb=40a487dcc5d3028343ff9123a72b8b3839a42861;hpb=4b0f1eb4220d2dbe4cffb288f745661b32c96a5b diff --git a/src/gif.c b/src/gif.c index 2462e139..bf3f5fc7 100644 --- a/src/gif.c +++ b/src/gif.c @@ -1,23 +1,10 @@ -/* gif.c: - * - * adapted from code by kirk johnson (tuna@athena.mit.edu). most of this - * code is unchanged. -- jim frost 12.31.89 - * - * gifin.c - * kirk johnson - * november 1989 - * - * routines for reading GIF files - * - * Copyright 1989 Kirk L. Johnson (see the included file - * "kljcpyrght.h" for complete copyright information) - */ +/* gif.c */ #define GIF_C -#include "xli.h" #include "gif.h" +#include "image.h" #define PUSH_PIXEL(p) \ { \ @@ -150,7 +137,7 @@ static int gifin_open_file(FILE *s) buf[GIF_SIG_LEN] = '\0'; if (strcmp((char *) buf, GIF_SIG) == 0) gifin_version = GIF87a; - else if(strcmp((char *) buf, GIF_SIG_89) == 0) + else if (strcmp((char *) buf, GIF_SIG_89) == 0) gifin_version = GIF89a; else return GIFIN_ERR_BAD_SIG; @@ -364,7 +351,7 @@ static int gifin_get_pixel(pel) pstk[place] = first; } - if((errno = gifin_add_string(prev_code, first)) != GIFIN_SUCCESS) + if ((errno = gifin_add_string(prev_code, first)) != GIFIN_SUCCESS) return errno; prev_code = code; } @@ -481,75 +468,69 @@ static int gifin_add_string(int p, int e) return GIFIN_SUCCESS; } -/* these are the routines added for interfacing to xli - */ - -/* tell someone what the image we're loading is. this could be a little more - * descriptive but I don't care - */ - -static void tellAboutImage(char *name) -{ - printf("\n%s:\n %dx%d %s%s image with %d colors\n", - name, gifin_img_width, gifin_img_height, - (gifin_interlace_flag ? "interlaced " : ""), - gif_version_name[gifin_version], - (gifin_l_cmap_flag ? gifin_l_ncolors : gifin_g_ncolors)); -} - -Image *gifLoad(char *fullname) +Image *Read_GIF_to_Image(char *fullname) { - FILE *zf; + FILE *f; Image *image; int x, y, pixel, pass, scanlen; byte *pixptr, *pixline; int errno; - if (!(zf = fopen(fullname,"r"))) + if (!(f = fopen(fullname,"r"))) { perror("gifLoad"); return(NULL); } - if ((gifin_open_file(zf) != GIFIN_SUCCESS) || /* read GIF header */ - (gifin_open_image() != GIFIN_SUCCESS)) /* read image header */ + if ((gifin_open_file(f) != GIFIN_SUCCESS) || /* read GIF header */ + (gifin_open_image() != GIFIN_SUCCESS)) /* read image header */ { printf("gifin_open_file or gifin_open_image failed!\n"); gifin_close_file(); - fclose(zf); + fclose(f); return(NULL); } - tellAboutImage(fullname); - image= newRGBImage(gifin_img_width, gifin_img_height, (gifin_l_cmap_flag ? - gifin_l_pixel_bits : - gifin_g_pixel_bits)); - image->title= dupString(fullname); + + /* + printf("%s:\n %dx%d %s%s image with %d colors at depth %d\n", + fullname, gifin_img_width, gifin_img_height, + (gifin_interlace_flag ? "interlaced " : ""), + gif_version_name[gifin_version], + (gifin_l_cmap_flag ? gifin_l_ncolors : gifin_g_ncolors), + (gifin_l_cmap_flag ? gifin_l_pixel_bits : gifin_g_pixel_bits)); + */ + + + + image = newRGBImage(gifin_img_width, gifin_img_height, (gifin_l_cmap_flag ? + gifin_l_pixel_bits : + gifin_g_pixel_bits)); /* if image has a local colormap, override global colormap */ if (gifin_l_cmap_flag) { - for (x= 0; x < gifin_l_ncolors; x++) + for (x=0; xrgb.red[x]= gifin_l_cmap[GIF_RED][x] << 8; - image->rgb.green[x]= gifin_l_cmap[GIF_GRN][x] << 8; - image->rgb.blue[x]= gifin_l_cmap[GIF_BLU][x] << 8; + image->rgb.red[x] = gifin_l_cmap[GIF_RED][x] << 8; + image->rgb.green[x] = gifin_l_cmap[GIF_GRN][x] << 8; + image->rgb.blue[x] = gifin_l_cmap[GIF_BLU][x] << 8; } - image->rgb.used= gifin_l_ncolors; + image->rgb.used = gifin_l_ncolors; } else { - for (x= 0; x < gifin_g_ncolors; x++) + for (x=0; xrgb.red[x]= gifin_g_cmap[GIF_RED][x] << 8; - image->rgb.green[x]= gifin_g_cmap[GIF_GRN][x] << 8; - image->rgb.blue[x]= gifin_g_cmap[GIF_BLU][x] << 8; + image->rgb.red[x] = gifin_g_cmap[GIF_RED][x] << 8; + image->rgb.green[x] = gifin_g_cmap[GIF_GRN][x] << 8; + image->rgb.blue[x] = gifin_g_cmap[GIF_BLU][x] << 8; } - image->rgb.used= gifin_g_ncolors; + image->rgb.used = gifin_g_ncolors; } /* interlaced image -- futz with the vertical trace. i wish i knew what @@ -559,26 +540,27 @@ Image *gifLoad(char *fullname) if (gifin_interlace_flag) { - scanlen= image->height * image->pixlen; + scanlen = image->height * image->pixlen; /* interlacing takes four passes to read, each starting at a different * vertical point. */ - for (pass= 0; pass < 4; pass++) + for (pass=0; pass<4; pass++) { - y= interlace_start[pass]; - scanlen= image->width * image->pixlen * interlace_rate[pass]; - pixline= image->data + (y * image->width * image->pixlen); + y = interlace_start[pass]; + scanlen = image->width * image->pixlen * interlace_rate[pass]; + pixline = image->data + (y * image->width * image->pixlen); while (y < gifin_img_height) { - pixptr= pixline; - for (x= 0; x < gifin_img_width; x++) + pixptr = pixline; + for (x=0; xpixlen); pixptr += image->pixlen; @@ -593,16 +575,17 @@ Image *gifLoad(char *fullname) /* not an interlaced image, just read in sequentially */ - if(image->pixlen == 1) /* the usual case */ + if (image->pixlen == 1) /* the usual case */ { - pixptr= image->data; - for (y= 0; y < gifin_img_height; y++) - for (x= 0; x < gifin_img_width; x++) + pixptr = image->data; + for (y=0; ydata; - for (y= 0; y < gifin_img_height; y++) - for (x= 0; x < gifin_img_width; x++) + pixptr = image->data; + for (y=0; ypixlen); pixptr += image->pixlen; @@ -626,7 +610,7 @@ Image *gifLoad(char *fullname) } gifin_close_file(); - fclose(zf); + fclose(f); return(image); }