void OutputStereoOperation::deinitExecution()
{
	unsigned int width = this->getWidth();
	unsigned int height = this->getHeight();

	if (width != 0 && height != 0) {
		void *exrhandle;

		exrhandle = this->get_handle(this->m_path);
		float *buf = this->m_outputBuffer;

		/* populate single EXR channel with view data */
		IMB_exr_add_channel(exrhandle, NULL, this->m_name, this->m_viewName, 1, this->m_channels * width * height, buf);

		this->m_imageInput = NULL;
		this->m_outputBuffer = NULL;

		/* create stereo ibuf */
		if (BKE_scene_multiview_is_render_view_last(this->m_rd, this->m_viewName)) {
			ImBuf *ibuf[3] = {NULL};
			const char *names[2] = {STEREO_LEFT_NAME, STEREO_RIGHT_NAME};
			Main *bmain = G.main; /* TODO, have this passed along */
			char filename[FILE_MAX];
			int i;

			/* get rectf from EXR */
			for (i = 0; i < 2; i++) {
				float *rectf = IMB_exr_channel_rect(exrhandle, NULL, this->m_name, names[i]);
				ibuf[i] = IMB_allocImBuf(width, height, this->m_format->planes, 0);

				ibuf[i]->channels = this->m_channels;
				ibuf[i]->rect_float = rectf;
				ibuf[i]->mall |= IB_rectfloat;
				ibuf[i]->dither = this->m_rd->dither_intensity;

				/* do colormanagement in the individual views, so it doesn't need to do in the stereo */
				IMB_colormanagement_imbuf_for_write(ibuf[i], true, false, this->m_viewSettings,
				                                    this->m_displaySettings, this->m_format);
				IMB_prepare_write_ImBuf(IMB_isfloat(ibuf[i]), ibuf[i]);
			}

			/* create stereo buffer */
			ibuf[2] = IMB_stereo3d_ImBuf(this->m_format, ibuf[0], ibuf[1]);

			BKE_image_path_from_imformat(
			        filename, this->m_path, bmain->name, this->m_rd->cfra, this->m_format,
			        (this->m_rd->scemode & R_EXTENSION) != 0, true, NULL);

			BKE_imbuf_write(ibuf[2], filename, this->m_format);

			/* imbuf knows which rects are not part of ibuf */
			for (i = 0; i < 3; i++)
				IMB_freeImBuf(ibuf[i]);

			IMB_exr_close(exrhandle);
		}
	}
}
Ejemplo n.º 2
0
static void rna_SceneRender_get_frame_path(RenderData *rd, int frame, char *name)
{
	if (BKE_imtype_is_movie(rd->im_format.imtype)) {
		BKE_movie_filepath_get(name, rd);
	}
	else {
		BKE_image_path_from_imformat(
		        name, rd->pic, G.main->name, (frame == INT_MIN) ? rd->cfra : frame,
		        &rd->im_format, (rd->scemode & R_EXTENSION) != 0, true);
	}
}
Ejemplo n.º 3
0
static void screen_opengl_render_write(OGLRender *oglrender)
{
	Scene *scene = oglrender->scene;
	RenderResult *rr;
	bool ok;
	char name[FILE_MAX];
	Object *camera = RE_GetCamera(oglrender->re);

	rr = RE_AcquireResultRead(oglrender->re);

	BKE_image_path_from_imformat(
	        name, scene->r.pic, oglrender->bmain->name, scene->r.cfra,
	        &scene->r.im_format, (scene->r.scemode & R_EXTENSION) != 0, false, NULL);

	/* write images as individual images or stereo */
	ok = RE_WriteRenderViewsImage(oglrender->reports, rr, scene, camera, false, name);

	RE_ReleaseResultImage(oglrender->re);

	if (ok) printf("OpenGL Render written to '%s'\n", name);
	else printf("OpenGL Render failed to write '%s'\n", name);
}
Ejemplo n.º 4
0
/* only this runs inside thread */
static void screenshot_startjob(void *sjv, short *stop, short *do_update, float *UNUSED(progress))
{
    ScreenshotJob *sj = sjv;
    RenderData rd = sj->scene->r;
    bMovieHandle *mh = NULL;

    /* we need this as local variables for renderdata */
    rd.frs_sec = U.scrcastfps;
    rd.frs_sec_base = 1.0f;

    if (BKE_imtype_is_movie(rd.im_format.imtype)) {
        mh = BKE_movie_handle_get(sj->scene->r.im_format.imtype);
        if (mh == NULL) {
            printf("Movie format unsupported\n");
            return;
        }
        sj->movie_ctx = mh->context_create();
        sj->movie_handle = mh;

        if (!mh->start_movie(sj->movie_ctx, sj->scene, &rd, sj->dumpsx, sj->dumpsy, &sj->reports, false, "")) {
            printf("screencast job stopped\n");
            return;
        }
    }

    sj->stop = stop;
    sj->do_update = do_update;

    *do_update = true; /* wait for opengl rect */

    while (*stop == 0) {

        if (sj->dumprect) {

            if (mh) {
                if (mh->append_movie(sj->movie_ctx, &rd, rd.sfra, rd.cfra, (int *)sj->dumprect,
                                     sj->dumpsx, sj->dumpsy, "", &sj->reports))
                {
                    BKE_reportf(&sj->reports, RPT_INFO, "Appended frame: %d", rd.cfra);
                    printf("Appended frame %d\n", rd.cfra);
                }
                else {
                    break;
                }
            }
            else {
                ImBuf *ibuf = IMB_allocImBuf(sj->dumpsx, sj->dumpsy, rd.im_format.planes, 0);
                char name[FILE_MAX];
                int ok;

                BKE_image_path_from_imformat(
                    name, rd.pic, sj->bmain->name, rd.cfra,
                    &rd.im_format, (rd.scemode & R_EXTENSION) != 0, true, NULL);

                ibuf->rect = sj->dumprect;
                ok = BKE_imbuf_write(ibuf, name, &rd.im_format);

                if (ok == 0) {
                    printf("Write error: cannot save %s\n", name);
                    BKE_reportf(&sj->reports, RPT_INFO, "Write error: cannot save %s", name);
                    break;
                }
                else {
                    printf("Saved file: %s\n", name);
                    BKE_reportf(&sj->reports, RPT_INFO, "Saved file: %s", name);
                }

                /* imbuf knows which rects are not part of ibuf */
                IMB_freeImBuf(ibuf);
            }

            MEM_freeN(sj->dumprect);
            sj->dumprect = NULL;

            *do_update = true;

            rd.cfra++;

        }
        else
            PIL_sleep_ms(U.scrcastwait);
    }

    if (mh) {
        mh->end_movie(sj->movie_ctx);
        mh->context_free(sj->movie_ctx);
        sj->movie_handle = NULL;
    }

    BKE_report(&sj->reports, RPT_INFO, "Screencast job stopped");
}
Ejemplo n.º 5
0
static bool screen_opengl_render_anim_step(bContext *C, wmOperator *op)
{
	Main *bmain = CTX_data_main(C);
	OGLRender *oglrender = op->customdata;
	Scene *scene = oglrender->scene;
	char name[FILE_MAX];
	bool ok = false;
	const bool view_context = (oglrender->v3d != NULL);
	bool is_movie;
	RenderResult *rr;

	/* go to next frame */
	if (CFRA < oglrender->nfra)
		CFRA++;
	while (CFRA < oglrender->nfra) {
		unsigned int lay = screen_opengl_layers(oglrender);

		if (lay & 0xFF000000)
			lay &= 0xFF000000;

		BKE_scene_update_for_newframe(bmain->eval_ctx, bmain, scene, lay);
		CFRA++;
	}

	is_movie = BKE_imtype_is_movie(scene->r.im_format.imtype);

	if (!is_movie) {
		BKE_image_path_from_imformat(
		        name, scene->r.pic, oglrender->bmain->name, scene->r.cfra,
		        &scene->r.im_format, (scene->r.scemode & R_EXTENSION) != 0, true, NULL);

		if ((scene->r.mode & R_NO_OVERWRITE) && BLI_exists(name)) {
			BKE_reportf(op->reports, RPT_INFO, "Skipping existing frame \"%s\"", name);
			ok = true;
			goto finally;
		}
	}

	WM_cursor_time(oglrender->win, scene->r.cfra);

	BKE_scene_update_for_newframe(bmain->eval_ctx, bmain, scene, screen_opengl_layers(oglrender));

	if (view_context) {
		if (oglrender->rv3d->persp == RV3D_CAMOB && oglrender->v3d->camera && oglrender->v3d->scenelock) {
			/* since BKE_scene_update_for_newframe() is used rather
			 * then ED_update_for_newframe() the camera needs to be set */
			if (BKE_scene_camera_switch_update(scene)) {
				oglrender->v3d->camera = scene->camera;
			}
		}
	}
	else {
		BKE_scene_camera_switch_update(scene);
	}

	/* render into offscreen buffer */
	screen_opengl_render_apply(oglrender);

	/* save to disk */
	rr = RE_AcquireResultRead(oglrender->re);

	if (is_movie) {
		ok = RE_WriteRenderViewsMovie(oglrender->reports, rr, scene, &scene->r, oglrender->mh, oglrender->sizex,
		                              oglrender->sizey, oglrender->movie_ctx_arr, oglrender->totvideos, PRVRANGEON != 0);
		if (ok) {
			printf("Append frame %d", scene->r.cfra);
			BKE_reportf(op->reports, RPT_INFO, "Appended frame: %d", scene->r.cfra);
		}
	}
	else {
		ok = RE_WriteRenderViewsImage(op->reports, rr, scene, scene->camera, true, name);
		if (ok) {
			printf("Saved: %s", name);
			BKE_reportf(op->reports, RPT_INFO, "Saved file: %s", name);
		}
		else {
			printf("Write error: cannot save %s\n", name);
			BKE_reportf(op->reports, RPT_ERROR, "Write error: cannot save %s", name);
		}
	}

	RE_ReleaseResult(oglrender->re);


	/* movie stats prints have no line break */
	printf("\n");


finally:  /* Step the frame and bail early if needed */

	/* go to next frame */
	oglrender->nfra += scene->r.frame_step;

	/* stop at the end or on error */
	if (CFRA >= PEFRA || !ok) {
		screen_opengl_render_end(C, op->customdata);
		return 0;
	}

	return 1;
}