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);
		}
	}
}
static ImBuf *prepare_write_imbuf(const ImFileType *type, ImBuf *ibuf)
{
	return IMB_prepare_write_ImBuf((type->flag & IM_FTYPE_FLOAT), ibuf);
}