gchar *name_buf;
static gint32 load_image (gchar *filename){ 	FILE *fp;	gint32 shape_size;	gint32 hdr_size;	guchar *pixptr;	gint32 frame_offset;	gint16  slice;	gint32 image_ID = -1;	gint32 layer_ID = -1;	gint16 slice_type;	gint16 slice_length;	gint16 block_type;	gint16 block_length;	gint32 max_width;	gint32 max_height;	gint16 offsetX;	gint16 offsetY;	gchar *name_buf;	gchar *framename;	guchar block;	guchar pix;	GDrawable *drawable;	GPixelRgn pixel_rgn;	int i;	int j;	struct u7shape shape;	struct u7frame *frame;  	fp = fopen (filename, "rb");	if (!fp) {		g_message ("SHP: can't open \"%s\"\n", filename);		return -1;	}	if (run_mode != RUN_NONINTERACTIVE) {		name_buf = g_strdup_printf ("Loading %s:", filename);		gimp_progress_init (name_buf);		g_free (name_buf);	}	shape_size = read4(fp);	hdr_size = read4(fp);	shape.num_frames = (hdr_size-4)/4;	shape.frames = (struct u7frame *)malloc(sizeof(struct u7frame)*shape.num_frames);	max_width = -1;	max_height = -1;		for(i=0; i<shape.num_frames; i++) {		frame = &shape.frames[i];		// Go to where frame offset is stored		fseek(fp, (i+1)*4, SEEK_SET);		frame_offset = read4(fp);		fseek(fp, frame_offset, SEEK_SET);		frame->rightX = read2(fp);		frame->leftX = read2(fp);		frame->leftY = read2(fp);		frame->rightY = read2(fp);		frame->width = frame->leftX+frame->rightX+1;		if(frame->width>max_width)			max_width = frame->width;		frame->height = frame->leftY+frame->rightY+1;		if(frame->height>max_height)			max_height = frame->height;		frame->pixels = (char *)malloc(frame->width*frame->height*2);		memset(frame->pixels, 0, frame->width*frame->height*2);		while((slice=read2(fp))!=0) {			slice_type = slice & 0x1;			slice_length = slice >> 1;			offsetX = read2(fp);			offsetY = read2(fp);			pixptr = frame->pixels+(offsetY*frame->width+offsetX)*2;			if(slice_type) {	// Compressed				while(slice_length>0) {					block = read1(fp);					block_type = block & 0x1;					block_length = block >> 1;					if(block_type) {						pix = read1(fp);						for(j=0;j<block_length;j++) {							*pixptr++ = pix;							*pixptr++ = 255;						}					} else {						for(j=0;j<block_length;j++) {							pix = read1(fp);							*pixptr++ = pix;							*pixptr++ = 255;						}					}					slice_length -= block_length;				}			} else {		// Uncompressed				// Just read the pixels				for(j=0;j<slice_length;j++) {					pix = read1(fp);					*pixptr++ = pix;					*pixptr++ = 255;				}			}		}	}	for(i=0;i<256;i++) {		gimp_cmap[i*3]=i;		gimp_cmap[i*3+1]=i;		gimp_cmap[i*3+2]=i;	}	image_ID = gimp_image_new (max_width, max_height, INDEXED);	gimp_image_set_filename (image_ID, filename);	gimp_image_set_cmap (image_ID, gimp_cmap, 256);	for(i=0; i<shape.num_frames; i++) {		frame = &shape.frames[i];		framename = g_strdup_printf ("Frame %d", i);		layer_ID = gimp_layer_new (image_ID, framename,			frame->width, frame->height,			INDEXEDA_IMAGE, 100, NORMAL_MODE);		g_free (framename);		gimp_image_add_layer (image_ID, layer_ID, 0);		gimp_layer_translate (layer_ID, (gint)frame->leftX, (gint)frame->leftY);		drawable = gimp_drawable_get (layer_ID);				gimp_pixel_rgn_init (&pixel_rgn, drawable, 0, 0, drawable->width, drawable->height, TRUE, FALSE);		gimp_pixel_rgn_set_rect (&pixel_rgn, frame->pixels, 0, 0, drawable->width, drawable->height);		gimp_drawable_flush (drawable);		gimp_drawable_detach (drawable);	}	fclose(fp);		for(i=0; i<shape.num_frames; i++) {		free(shape.frames[i].pixels);	}	free(shape.frames);	return 0;}