Exemple #1
0
void ED_space_image_get_size(SpaceImage *sima, int *width, int *height)
{
	Scene *scene = sima->iuser.scene;
	ImBuf *ibuf;
	void *lock;

	ibuf = ED_space_image_acquire_buffer(sima, &lock);

	if (ibuf && ibuf->x > 0 && ibuf->y > 0) {
		*width = ibuf->x;
		*height = ibuf->y;
	}
	else if (sima->image && sima->image->type == IMA_TYPE_R_RESULT && scene) {
		/* not very important, just nice */
		*width = (scene->r.xsch * scene->r.size) / 100;
		*height = (scene->r.ysch * scene->r.size) / 100;

		if ((scene->r.mode & R_BORDER) && (scene->r.mode & R_CROP)) {
			*width  *= BLI_rctf_size_x(&scene->r.border);
			*height *= BLI_rctf_size_y(&scene->r.border);
		}

	}
	/* I know a bit weak... but preview uses not actual image size */
	// XXX else if (image_preview_active(sima, width, height));
	else {
		*width  = IMG_SIZE_FALLBACK;
		*height = IMG_SIZE_FALLBACK;
	}

	ED_space_image_release_buffer(sima, ibuf, lock);
}
Exemple #2
0
bool ED_space_image_has_buffer(SpaceImage *sima)
{
	ImBuf *ibuf;
	void *lock;
	bool has_buffer;

	ibuf = ED_space_image_acquire_buffer(sima, &lock);
	has_buffer = (ibuf != NULL);
	ED_space_image_release_buffer(sima, ibuf, lock);

	return has_buffer;
}
Exemple #3
0
static int image_panel_poll(const bContext *C, PanelType *UNUSED(pt))
{
	SpaceImage *sima = CTX_wm_space_image(C);
	ImBuf *ibuf;
	void *lock;
	int result;

	ibuf = ED_space_image_acquire_buffer(sima, &lock);
	result = ibuf && ibuf->rect_float;
	ED_space_image_release_buffer(sima, lock);
	
	return result;
}
Exemple #4
0
static void image_panel_curves(const bContext *C, Panel *pa)
{
	bScreen *sc = CTX_wm_screen(C);
	SpaceImage *sima = CTX_wm_space_image(C);
	ImBuf *ibuf;
	PointerRNA simaptr;
	int levels;
	void *lock;
	
	ibuf = ED_space_image_acquire_buffer(sima, &lock);
	
	if (ibuf) {
		if (sima->cumap == NULL)
			sima->cumap = curvemapping_add(4, 0.0f, 0.0f, 1.0f, 1.0f);

		/* curvemap black/white levels only works for RGBA */
		levels = (ibuf->channels == 4);

		RNA_pointer_create(&sc->id, &RNA_SpaceImageEditor, sima, &simaptr);
		uiTemplateCurveMapping(pa->layout, &simaptr, "curve", 'c', levels, 0);
	}

	ED_space_image_release_buffer(sima, lock);
}
Exemple #5
0
/* draw grease pencil */
void draw_image_grease_pencil(bContext *C, short onlyv2d)
{
	/* draw in View2D space? */
	if (onlyv2d) {
		/* assume that UI_view2d_ortho(C) has been called... */
		SpaceImage *sima= (SpaceImage *)CTX_wm_space_data(C);
		void *lock;
		ImBuf *ibuf= ED_space_image_acquire_buffer(sima, &lock);
		
		/* draw grease-pencil ('image' strokes) */
		//if (sima->flag & SI_DISPGP)
			draw_gpencil_2dimage(C, ibuf);

		ED_space_image_release_buffer(sima, lock);
	}
	else {
		/* assume that UI_view2d_restore(C) has been called... */
		//SpaceImage *sima= (SpaceImage *)CTX_wm_space_data(C);
		
		/* draw grease-pencil ('screen' strokes) */
		//if (sima->flag & SI_DISPGP)
			draw_gpencil_view2d(C, 0);
	}
}
Exemple #6
0
void draw_image_main(const bContext *C, ARegion *ar)
{
	SpaceImage *sima = CTX_wm_space_image(C);
	Scene *scene = CTX_data_scene(C);
	Image *ima;
	ImBuf *ibuf;
	float zoomx, zoomy;
	bool show_viewer, show_render, show_paint, show_stereo3d, show_multilayer;
	void *lock;

	/* XXX can we do this in refresh? */
#if 0
	what_image(sima);
	
	if (sima->image) {
		ED_image_get_aspect(sima->image, &xuser_asp, &yuser_asp);
		
		/* UGLY hack? until now iusers worked fine... but for flipbook viewer we need this */
		if (sima->image->type == IMA_TYPE_COMPOSITE) {
			ImageUser *iuser = ntree_get_active_iuser(scene->nodetree);
			if (iuser) {
				BKE_image_user_calc_imanr(iuser, scene->r.cfra, 0);
				sima->iuser = *iuser;
			}
		}
		/* and we check for spare */
		ibuf = ED_space_image_buffer(sima);
	}
#endif

	/* retrieve the image and information about it */
	ima = ED_space_image(sima);
	ED_space_image_get_zoom(sima, ar, &zoomx, &zoomy);

	show_viewer = (ima && ima->source == IMA_SRC_VIEWER) != 0;
	show_render = (show_viewer && ima->type == IMA_TYPE_R_RESULT) != 0;
	show_paint = (ima && (sima->mode == SI_MODE_PAINT) && (show_viewer == false) && (show_render == false));
	show_stereo3d = (ima && (ima->flag & IMA_IS_STEREO) && (sima->iuser.flag & IMA_SHOW_STEREO));
	show_multilayer = ima && BKE_image_is_multilayer(ima);

	if (show_viewer) {
		/* use locked draw for drawing viewer image buffer since the compositor
		 * is running in separated thread and compositor could free this buffers.
		 * other images are not modifying in such a way so they does not require
		 * lock (sergey)
		 */
		BLI_lock_thread(LOCK_DRAW_IMAGE);
	}

	if (show_stereo3d) {
		if (show_multilayer)
			/* update multiindex and pass for the current eye */
			BKE_image_multilayer_index(ima->rr, &sima->iuser);
		else
			BKE_image_multiview_index(ima, &sima->iuser);
	}

	ibuf = ED_space_image_acquire_buffer(sima, &lock);

	/* draw the image or grid */
	if (ibuf == NULL)
		ED_region_grid_draw(ar, zoomx, zoomy);
	else if (sima->flag & SI_DRAW_TILE)
		draw_image_buffer_repeated(C, sima, ar, scene, ima, ibuf, zoomx, zoomy);
	else if (ima && (ima->tpageflag & IMA_TILES))
		draw_image_buffer_tiled(sima, ar, scene, ima, ibuf, 0.0f, 0.0, zoomx, zoomy);
	else
		draw_image_buffer(C, sima, ar, scene, ibuf, 0.0f, 0.0f, zoomx, zoomy);

	/* paint helpers */
	if (show_paint)
		draw_image_paint_helpers(C, ar, scene, zoomx, zoomy);

	/* XXX integrate this code */
#if 0
	if (ibuf) {
		float xoffs = 0.0f, yoffs = 0.0f;
		
		if (image_preview_active(sa, &xim, &yim)) {
			xoffs = scene->r.disprect.xmin;
			yoffs = scene->r.disprect.ymin;
			glColor3ub(0, 0, 0);
			calc_image_view(sima, 'f');
			myortho2(G.v2d->cur.xmin, G.v2d->cur.xmax, G.v2d->cur.ymin, G.v2d->cur.ymax);
			glRectf(0.0f, 0.0f, 1.0f, 1.0f);
			glLoadIdentity();
		}
	}
#endif

	ED_space_image_release_buffer(sima, ibuf, lock);

	if (show_viewer) {
		BLI_unlock_thread(LOCK_DRAW_IMAGE);
	}

	/* render info */
	if (ima && show_render)
		draw_render_info(C, sima->iuser.scene, ima, ar, zoomx, zoomy);
}
Exemple #7
0
void draw_image_main(SpaceImage *sima, ARegion *ar, Scene *scene)
{
	Image *ima;
	ImBuf *ibuf;
	float zoomx, zoomy;
	int show_viewer, show_render;
	void *lock;

	/* XXX can we do this in refresh? */
#if 0
	what_image(sima);
	
	if(sima->image) {
		ED_image_aspect(sima->image, &xuser_asp, &yuser_asp);
		
		/* UGLY hack? until now iusers worked fine... but for flipbook viewer we need this */
		if(sima->image->type==IMA_TYPE_COMPOSITE) {
			ImageUser *iuser= ntree_get_active_iuser(scene->nodetree);
			if(iuser) {
				BKE_image_user_calc_imanr(iuser, scene->r.cfra, 0);
				sima->iuser= *iuser;
			}
		}
		/* and we check for spare */
		ibuf= ED_space_image_buffer(sima);
	}
#endif

	/* retrieve the image and information about it */
	ima= ED_space_image(sima);
	ED_space_image_zoom(sima, ar, &zoomx, &zoomy);
	ibuf= ED_space_image_acquire_buffer(sima, &lock);

	show_viewer= (ima && ima->source == IMA_SRC_VIEWER);
	show_render= (show_viewer && ima->type == IMA_TYPE_R_RESULT);

	/* draw the image or grid */
	if(ibuf==NULL)
		draw_image_grid(ar, zoomx, zoomy);
	else if(sima->flag & SI_DRAW_TILE)
		draw_image_buffer_repeated(sima, ar, scene, ima, ibuf, zoomx, zoomy);
	else if(ima && (ima->tpageflag & IMA_TILES))
		draw_image_buffer_tiled(sima, ar, scene, ima, ibuf, 0.0f, 0.0, zoomx, zoomy);
	else
		draw_image_buffer(sima, ar, scene, ima, ibuf, 0.0f, 0.0f, zoomx, zoomy);

	/* paint helpers */
	if(sima->flag & SI_DRAWTOOL)
		draw_image_paint_helpers(ar, scene, zoomx, zoomy);


	/* XXX integrate this code */
#if 0
	if(ibuf) {
		float xoffs=0.0f, yoffs= 0.0f;
		
		if(image_preview_active(sa, &xim, &yim)) {
			xoffs= scene->r.disprect.xmin;
			yoffs= scene->r.disprect.ymin;
			glColor3ub(0,0,0);
			calc_image_view(sima, 'f');	
			myortho2(G.v2d->cur.xmin, G.v2d->cur.xmax, G.v2d->cur.ymin, G.v2d->cur.ymax);
			glRectf(0.0f, 0.0f, 1.0f, 1.0f);
			glLoadIdentity();
		}
	}
#endif

	ED_space_image_release_buffer(sima, lock);

	/* render info */
	if(ima && show_render)
		draw_render_info(scene, ima, ar);
}