Ejemplo n.º 1
0
/* call from both exec and invoke */
static int screenshot_data_create(bContext *C, wmOperator *op)
{
    unsigned int *dumprect;
    int dumpsx, dumpsy;

    /* do redraw so we don't show popups/menus */
    WM_redraw_windows(C);

    dumprect = screenshot(C, &dumpsx, &dumpsy);

    if (dumprect) {
        ScreenshotData *scd = MEM_callocN(sizeof(ScreenshotData), "screenshot");
        ScrArea *sa = CTX_wm_area(C);

        scd->dumpsx = dumpsx;
        scd->dumpsy = dumpsy;
        scd->dumprect = dumprect;
        if (sa) {
            scd->crop = sa->totrct;
        }

        BKE_imformat_defaults(&scd->im_format);

        op->customdata = scd;

        return true;
    }
    else {
        op->customdata = NULL;
        return false;
    }
}
Ejemplo n.º 2
0
void KX_BlenderCanvas::MakeScreenShot(const char *filename)
{
	ScrArea area_dummy= {0};
	bScreen *screen = m_win->screen;
	unsigned int *dumprect;
	int dumpsx, dumpsy;

	area_dummy.totrct.xmin = m_frame_rect.GetLeft();
	area_dummy.totrct.xmax = m_frame_rect.GetRight();
	area_dummy.totrct.ymin = m_frame_rect.GetBottom();
	area_dummy.totrct.ymax = m_frame_rect.GetTop();

	dumprect = screenshot(&area_dummy, &dumpsx, &dumpsy);
	if (!dumprect) {
		std::cerr << "KX_BlenderCanvas: Unable to take screenshot!" << std::endl;
		return;
	}

	/* initialize image file format data */
	Scene *scene = (screen)? screen->scene: NULL;
	ImageFormatData *im_format = (ImageFormatData *)MEM_mallocN(sizeof(ImageFormatData), "im_format");

	if (scene)
		*im_format = scene->r.im_format;
	else
		BKE_imformat_defaults(im_format);

	/* save_screenshot() frees dumprect and im_format */
	save_screenshot(filename, dumpsx, dumpsy, dumprect, im_format);
}
bNodeSocket *ntreeCompositOutputFileAddSocket(bNodeTree *ntree, bNode *node, const char *name, ImageFormatData *im_format)
{
	NodeImageMultiFile *nimf = node->storage;
	bNodeSocket *sock = nodeAddSocket(ntree, node, SOCK_IN, "", SOCK_RGBA);
	
	/* create format data for the input socket */
	NodeImageMultiFileSocket *sockdata = MEM_callocN(sizeof(NodeImageMultiFileSocket), "socket image format");
	sock->storage = sockdata;
	
	BLI_strncpy_utf8(sockdata->path, name, sizeof(sockdata->path));
	ntreeCompositOutputFileUniquePath(&node->inputs, sock, name, '_');
	BLI_strncpy_utf8(sockdata->layer, name, sizeof(sockdata->layer));
	ntreeCompositOutputFileUniqueLayer(&node->inputs, sock, name, '_');
	
	if (im_format) {
		sockdata->format= *im_format;
		if (BKE_imtype_is_movie(sockdata->format.imtype)) {
			sockdata->format.imtype= R_IMF_IMTYPE_OPENEXR;
		}
	}
	else
		BKE_imformat_defaults(&sockdata->format);
	/* use node data format by default */
	sockdata->use_node_format = TRUE;
	
	nimf->active_input = BLI_findindex(&node->inputs, sock);
	
	return sock;
}
Ejemplo n.º 4
0
/* XXX uses initfunc_api callback, regular initfunc does not support context yet */
static void init_output_file(const bContext *C, PointerRNA *ptr)
{
	Scene *scene = CTX_data_scene(C);
	bNodeTree *ntree = ptr->id.data;
	bNode *node = ptr->data;
	NodeImageMultiFile *nimf = MEM_callocN(sizeof(NodeImageMultiFile), "node image multi file");
	ImageFormatData *format = NULL;
	node->storage = nimf;
	
	node->id = &scene->id;
	
	if (scene) {
		RenderData *rd = &scene->r;

		BLI_strncpy(nimf->base_path, rd->pic, sizeof(nimf->base_path));
		nimf->format = rd->im_format;
		if (BKE_imtype_is_movie(nimf->format.imtype)) {
			nimf->format.imtype = R_IMF_IMTYPE_OPENEXR;
		}
		
		format = &nimf->format;
	}
	else
		BKE_imformat_defaults(&nimf->format);
	
	/* add one socket by default */
	ntreeCompositOutputFileAddSocket(ntree, node, "Image", format);
}
Ejemplo n.º 5
0
/* based on screendump.c::screenshot_exec */
void BL_MakeScreenShot(bScreen *screen, ScrArea *curarea, const char *filename)
{
	unsigned int *dumprect;
	int dumpsx, dumpsy;
	
	dumprect = screenshot(curarea, &dumpsx, &dumpsy);

	if (dumprect) {
		/* initialize image file format data */
		Scene *scene = (screen)? screen->scene: NULL;
		ImageFormatData im_format;

		if (scene)
			im_format = scene->r.im_format;
		else
			BKE_imformat_defaults(&im_format);

		/* create file path */
		char path[FILE_MAX];
		BLI_strncpy(path, filename, sizeof(path));
		BLI_path_abs(path, G.main->name);
		BKE_add_image_extension_from_type(path, im_format.imtype);

		/* create and save imbuf */
		ImBuf *ibuf = IMB_allocImBuf(dumpsx, dumpsy, 24, 0);
		ibuf->rect = dumprect;

		BKE_imbuf_write_as(ibuf, path, &im_format, false);

		ibuf->rect = NULL;
		IMB_freeImBuf(ibuf);
		MEM_freeN(dumprect);
	}
}
static void init_output_file(bNodeTree *ntree, bNode* node, bNodeTemplate *ntemp)
{
	NodeImageMultiFile *nimf= MEM_callocN(sizeof(NodeImageMultiFile), "node image multi file");
	ImageFormatData *format = NULL;
	node->storage= nimf;

	if (ntemp->scene) {
		RenderData *rd = &ntemp->scene->r;
		BLI_strncpy(nimf->base_path, rd->pic, sizeof(nimf->base_path));
		nimf->format = rd->im_format;
		if (BKE_imtype_is_movie(nimf->format.imtype)) {
			nimf->format.imtype= R_IMF_IMTYPE_OPENEXR;
		}
		
		format = &nimf->format;
	}
	else
		BKE_imformat_defaults(&nimf->format);
	
	/* add one socket by default */
	ntreeCompositOutputFileAddSocket(ntree, node, "Image", format);
}
Ejemplo n.º 7
0
	void
GPC_Canvas::
MakeScreenShot(
	const char* filename
) {
	// copy image data
	unsigned char *pixels = new unsigned char[GetWidth() * GetHeight() * 4];

	if (!pixels) {
		std::cout << "Cannot allocate pixels array" << std::endl;
		return;
	}

	glReadPixels(0, 0, GetWidth(), GetHeight(), GL_RGBA, GL_UNSIGNED_BYTE, pixels);

	// initialize image file format data
	ImageFormatData im_format;
	BKE_imformat_defaults(&im_format);

	// create file path 
	char path[FILE_MAX];
	BLI_strncpy(path, filename, sizeof(path));
	BLI_path_abs(path, G.main->name);
	BLI_path_frame(path, m_frame, 0);
	m_frame++;
	BKE_image_path_ensure_ext_from_imtype(path, im_format.imtype);

	// create and save imbuf 
	ImBuf *ibuf = IMB_allocImBuf(GetWidth(), GetHeight(), 24, 0);
	ibuf->rect = (unsigned int*)pixels;

	BKE_imbuf_write_as(ibuf, path, &im_format, false);

	ibuf->rect = NULL;
	IMB_freeImBuf(ibuf);

	// clean up
	delete [] (pixels);
}