Ejemplo n.º 1
0
/* reading a stereo encoded ibuf (*left) and generating two ibufs from it (*left and *right) */
void IMB_ImBufFromStereo3d(
        Stereo3dFormat *s3d, ImBuf *ibuf_stereo3d,
        ImBuf **r_ibuf_left, ImBuf **r_ibuf_right)
{
	Stereo3DData s3d_data = {{NULL}};
	ImBuf *ibuf_left, *ibuf_right;
	size_t width, height;
	const bool is_float = (ibuf_stereo3d->rect_float != NULL);

	IMB_stereo3d_read_dimensions(
	        s3d->display_mode, ((s3d->flag & S3D_SQUEEZED_FRAME) == 0), ibuf_stereo3d->x, ibuf_stereo3d->y,
	        &width, &height);

	ibuf_left = IMB_allocImBuf(width, height, ibuf_stereo3d->planes, (is_float ? IB_rectfloat : IB_rect));
	ibuf_right = IMB_allocImBuf(width, height, ibuf_stereo3d->planes, (is_float ? IB_rectfloat : IB_rect));

	/* copy flags for IB_fields and other settings */
	ibuf_left->flags = ibuf_stereo3d->flags;
	ibuf_right->flags = ibuf_stereo3d->flags;

	/* we always work with unsqueezed formats */
	IMB_stereo3d_write_dimensions(
	        s3d->display_mode, ((s3d->flag & S3D_SQUEEZED_FRAME) == 0), ibuf_stereo3d->x, ibuf_stereo3d->y,
	        &width, &height);
	imb_stereo3d_unsqueeze_ImBuf(ibuf_stereo3d, s3d, width, height);

	imb_stereo3d_data_initialize(
	        &s3d_data, is_float, ibuf_left->x, ibuf_left->y, 4,
	        (int *)ibuf_left->rect, (int *)ibuf_right->rect, (int *)ibuf_stereo3d->rect,
	        ibuf_left->rect_float, ibuf_right->rect_float, ibuf_stereo3d->rect_float);

	imb_stereo3d_read_doit(&s3d_data, s3d);

	if (ibuf_stereo3d->flags & (IB_zbuf | IB_zbuffloat)) {
		if (is_float) {
			addzbuffloatImBuf(ibuf_left);
			addzbuffloatImBuf(ibuf_right);
		}
		else {
			addzbufImBuf(ibuf_left);
			addzbufImBuf(ibuf_right);
		}

		imb_stereo3d_data_initialize(
		        &s3d_data, is_float, ibuf_left->x, ibuf_left->y, 1,
		        (int *)ibuf_left->zbuf, (int *)ibuf_right->zbuf, (int *)ibuf_stereo3d->zbuf,
		        ibuf_left->zbuf_float, ibuf_right->zbuf_float, ibuf_stereo3d->zbuf_float);

		imb_stereo3d_read_doit(&s3d_data, s3d);
	}

	IMB_freeImBuf(ibuf_stereo3d);

	*r_ibuf_left = ibuf_left;
	*r_ibuf_right = ibuf_right;
}
Ejemplo n.º 2
0
void ViewerOperation::initImage()
{
	Image *ima = this->m_image;
	ImageUser iuser = *this->m_imageUser;
	void *lock;
	ImBuf *ibuf;

	/* make sure the image has the correct number of views */
	if (ima && BKE_scene_multiview_is_render_view_first(this->m_rd, this->m_viewName)) {
		BKE_image_verify_viewer_views(this->m_rd, ima, this->m_imageUser);
	}

	BLI_thread_lock(LOCK_DRAW_IMAGE);

	/* local changes to the original ImageUser */
	iuser.multi_index = BKE_scene_multiview_view_id_get(this->m_rd, this->m_viewName);
	ibuf = BKE_image_acquire_ibuf(ima, &iuser, &lock);

	if (!ibuf) {
		BLI_thread_unlock(LOCK_DRAW_IMAGE);
		return;
	}
	if (ibuf->x != (int)getWidth() || ibuf->y != (int)getHeight()) {

		imb_freerectImBuf(ibuf);
		imb_freerectfloatImBuf(ibuf);
		IMB_freezbuffloatImBuf(ibuf);
		ibuf->x = getWidth();
		ibuf->y = getHeight();
		/* zero size can happen if no image buffers exist to define a sensible resolution */
		if (ibuf->x > 0 && ibuf->y > 0)
			imb_addrectfloatImBuf(ibuf);
		ima->ok = IMA_OK_LOADED;

		ibuf->userflags |= IB_DISPLAY_BUFFER_INVALID;
	}

	if (m_doDepthBuffer) {
		addzbuffloatImBuf(ibuf);
	}

	/* now we combine the input with ibuf */
	this->m_outputBuffer = ibuf->rect_float;

	/* needed for display buffer update */
	this->m_ibuf = ibuf;

	if (m_doDepthBuffer) {
		this->m_depthBuffer = ibuf->zbuf_float;
	}

	BKE_image_release_ibuf(this->m_image, this->m_ibuf, lock);

	BLI_thread_unlock(LOCK_DRAW_IMAGE);
}
Ejemplo n.º 3
0
ImBuf *IMB_allocImBuf(unsigned int x, unsigned int y, uchar planes, unsigned int flags)
{
	ImBuf *ibuf;

	ibuf = MEM_callocN(sizeof(ImBuf), "ImBuf_struct");

	if (ibuf) {
		ibuf->x = x;
		ibuf->y = y;
		ibuf->planes = planes;
		ibuf->ftype = IMB_FTYPE_PNG;
		ibuf->foptions.quality = 15; /* the 15 means, set compression to low ratio but not time consuming */
		ibuf->channels = 4;  /* float option, is set to other values when buffers get assigned */
		ibuf->ppm[0] = ibuf->ppm[1] = IMB_DPI_DEFAULT / 0.0254f; /* IMB_DPI_DEFAULT -> pixels-per-meter */

		if (flags & IB_rect) {
			if (imb_addrectImBuf(ibuf) == false) {
				IMB_freeImBuf(ibuf);
				return NULL;
			}
		}
		
		if (flags & IB_rectfloat) {
			if (imb_addrectfloatImBuf(ibuf) == false) {
				IMB_freeImBuf(ibuf);
				return NULL;
			}
		}
		
		if (flags & IB_zbuf) {
			if (addzbufImBuf(ibuf) == false) {
				IMB_freeImBuf(ibuf);
				return NULL;
			}
		}
		
		if (flags & IB_zbuffloat) {
			if (addzbuffloatImBuf(ibuf) == false) {
				IMB_freeImBuf(ibuf);
				return NULL;
			}
		}

		/* assign default spaces */
		colormanage_imbuf_set_default_spaces(ibuf);
	}
	return (ibuf);
}
void ViewerOperation::initImage()
{
	Image *ima = this->m_image;
	void *lock;
	ImBuf *ibuf = BKE_image_acquire_ibuf(ima, this->m_imageUser, &lock);

	if (!ibuf) return;
	BLI_lock_thread(LOCK_DRAW_IMAGE);
	if (ibuf->x != (int)getWidth() || ibuf->y != (int)getHeight()) {

		imb_freerectImBuf(ibuf);
		imb_freerectfloatImBuf(ibuf);
		IMB_freezbuffloatImBuf(ibuf);
		ibuf->x = getWidth();
		ibuf->y = getHeight();
		imb_addrectfloatImBuf(ibuf);
		ima->ok = IMA_OK_LOADED;

		ibuf->userflags |= IB_DISPLAY_BUFFER_INVALID;
	}

	if (m_doDepthBuffer) {
		addzbuffloatImBuf(ibuf);
	}
	BLI_unlock_thread(LOCK_DRAW_IMAGE);

	/* now we combine the input with ibuf */
	this->m_outputBuffer = ibuf->rect_float;

	/* needed for display buffer update */
	this->m_ibuf = ibuf;

	if (m_doDepthBuffer) {
		this->m_depthBuffer = ibuf->zbuf_float;
	}

	BKE_image_release_ibuf(this->m_image, this->m_ibuf, lock);
}