if(i==0) {	 if(frame->leftY>0) { gimp_image_add_hguide(image_ID, frame->leftY); printf("Added hguide=%d\n", frame->leftY); } if(frame->leftX>0) { gimp_image_add_vguide(image_ID, frame->leftX); printf("Added vguide=%d\n", frame->leftX); } }
static gint32 load_image (gchar *filename){ 	FILE *fp;	gint32 file_size;	gint32 shape_size;	gint32 hdr_size;	guchar *pixptr, *eod;	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;	signed int offsetX;	signed int offsetY;	gchar *framename;	guchar block;	guchar pix;	GimpDrawable *drawable;	GimpPixelRgn pixel_rgn;	GimpImageType image_type;	int i;	int j;        /* Flauschepelz */        signed int temp_int;	struct u7shape shape;	struct u7frame *frame;  	fp = fopen (filename, "rb");	if (!fp) {		g_message ("SHP: can't open \"%s\"\n", filename);		return -1;	}	fseek(fp, 0, SEEK_END);	file_size = ftell(fp);	fseek(fp, 0, SEEK_SET);		shape_size = read4(fp);		if(file_size!=shape_size) {	/* 8x8 tile */		image_type = GIMP_INDEXED_IMAGE;		shape.num_frames = file_size/64;		fseek(fp, 0, SEEK_SET);		/* Return to start of file */		printf("num_frames = %d\n", shape.num_frames);		shape.frames = g_new(struct u7frame, shape.num_frames);		max_width = 8;		max_height = 8;		for(i=0; i<shape.num_frames; i++) {			frame = &shape.frames[i];			frame->width = 8;			frame->height = 8;			frame->leftX = 0;			frame->leftY = 0;			frame->pixels = (char *)g_malloc(64);			fread(frame->pixels, 1, 64, fp);		}	} else {		image_type = GIMP_INDEXEDA_IMAGE;		hdr_size = read4(fp);		shape.num_frames = (hdr_size-4)/4;		max_width = -1;		max_height = -1;		printf("num_frames = %d\n", shape.num_frames);		shape.frames = g_new(struct u7frame, shape.num_frames);			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;			pixptr = frame->pixels = g_new0(char, frame->width*frame->height*2);			eod = frame->pixels+frame->width*frame->height*2;			while((slice=read2(fp))!=0) {				slice_type = slice & 0x1;				slice_length = slice >> 1;                                /* Flauschepelz */				offsetX = read2signed(fp);				offsetY = read2signed(fp);                                temp_int = (frame->leftY + offsetY)*frame->width*2 +                                           (frame->leftX + offsetX)*2;                                pixptr = frame->pixels;                                pixptr = pixptr + temp_int;                                /*				pixptr = frame->pixels+(offsetY*frame->width+offsetX)*2;                                */				if(pixptr<frame->pixels)					pixptr = frame->pixels;				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;					}				}			}		}	}	image_ID = gimp_image_new (max_width, max_height, GIMP_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++) {		framename = g_strdup_printf ("Frame %d", i);		frame = &shape.frames[i];		layer_ID = gimp_layer_new (image_ID, framename,			frame->width, frame->height,			image_type, 100, GIMP_NORMAL_MODE);		g_free (framename);		gimp_image_add_layer (image_ID, layer_ID, 0);		gimp_layer_translate (layer_ID, (gint)0, (gint)0);		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);				if(i==0) {	/* FIXME: Do this for first frame only... */			if(frame->leftY>0) {				gimp_image_add_hguide(image_ID, frame->leftY);				printf("Added hguide=%d\n", frame->leftY);			}			if(frame->leftX>0) {				gimp_image_add_vguide(image_ID, frame->leftX);				printf("Added vguide=%d\n", frame->leftX);			}		}	}	fclose(fp);		for(i=0; i<shape.num_frames; i++) {		g_free(shape.frames[i].pixels);	}	g_free(shape.frames);	return image_ID;}