예제 #1
0
static void load_frame_image_sequence(VoxelData *vd, Tex *tex)
{
	ImBuf *ibuf;
	Image *ima = tex->ima;
	ImageUser *tiuser = &tex->iuser;
	ImageUser iuser = *(tiuser);
	int x = 0, y = 0, z = 0;
	const float *rf;

	if (!ima) return;
	if (iuser.frames == 0) return;
	
	ima->source = IMA_SRC_SEQUENCE;
	iuser.framenr = 1 + iuser.offset;

	/* find the first valid ibuf and use it to initialize the resolution of the data set */
	/* need to do this in advance so we know how much memory to allocate */
	ibuf = BKE_image_acquire_ibuf(ima, &iuser, NULL);
	while (!ibuf && (iuser.framenr < iuser.frames)) {
		iuser.framenr++;
		ibuf = BKE_image_acquire_ibuf(ima, &iuser, NULL);
	}
	if (!ibuf) return;
	if (!ibuf->rect_float) IMB_float_from_rect(ibuf);
	
	vd->flag |= TEX_VD_STILL;
	vd->resol[0] = ibuf->x;
	vd->resol[1] = ibuf->y;
	vd->resol[2] = iuser.frames;
	vd->dataset = MEM_mapallocN(sizeof(float) * vd_resol_size(vd), "voxel dataset");
	
	for (z = 0; z < iuser.frames; z++) {
		/* get a new ibuf for each frame */
		if (z > 0) {
			iuser.framenr++;
			BKE_image_release_ibuf(ima, ibuf, NULL);
			ibuf = BKE_image_acquire_ibuf(ima, &iuser, NULL);
			if (!ibuf) break;
			if (!ibuf->rect_float) IMB_float_from_rect(ibuf);
		}
		rf = ibuf->rect_float;
		
		for (y = 0; y < ibuf->y; y++) {
			for (x = 0; x < ibuf->x; x++) {
				/* currently averaged to monchrome */
				vd->dataset[BLI_VOXEL_INDEX(x, y, z, vd->resol)] = (rf[0] + rf[1] + rf[2]) / 3.0f;
				rf += 4;
			}
		}
		
		BKE_image_free_anim_ibufs(ima, iuser.framenr);
	}

	BKE_image_release_ibuf(ima, ibuf, NULL);

	vd->ok = 1;
	return;
}
예제 #2
0
static void image_freecache_cb(bContext *C, void *ima_v, void *unused) 
{
	Scene *scene = CTX_data_scene(C);
	BKE_image_free_anim_ibufs(ima_v, scene->r.cfra);
	WM_event_add_notifier(C, NC_IMAGE, ima_v);
}