static int screenshot_exec(bContext *C, wmOperator *op) { ScreenshotData *scd= op->customdata; if(scd == NULL) { /* when running exec directly */ screenshot_data_create(C, op); scd= op->customdata; } if(scd) { if(scd->dumprect) { Scene *scene= CTX_data_scene(C); ImBuf *ibuf; char path[FILE_MAX]; RNA_string_get(op->ptr, "filepath", path); BLI_strncpy(G.ima, path, sizeof(G.ima)); BLI_path_abs(path, G.main->name); /* BKE_add_image_extension() checks for if extension was already set */ if(scene->r.scemode & R_EXTENSION) if(strlen(path)<FILE_MAX-5) BKE_add_image_extension(path, scene->r.im_format.imtype); ibuf= IMB_allocImBuf(scd->dumpsx, scd->dumpsy, 24, 0); ibuf->rect= scd->dumprect; /* crop to show only single editor */ if(!RNA_boolean_get(op->ptr, "full")) screenshot_crop(ibuf, scd->crop); BKE_write_ibuf(ibuf, path, &scene->r.im_format); IMB_freeImBuf(ibuf); } } screenshot_data_free(op); return OPERATOR_FINISHED; }
static void rna_Image_save_render(Image *image, bContext *C, ReportList *reports, const char *path, Scene *scene) { ImBuf *ibuf; if (scene == NULL) { scene = CTX_data_scene(C); } if (scene) { ImageUser iuser; void *lock; iuser.scene = scene; iuser.ok = 1; ibuf = BKE_image_acquire_ibuf(image, &iuser, &lock); if (ibuf == NULL) { BKE_reportf(reports, RPT_ERROR, "Couldn't acquire buffer from image"); } else { /* temp swap out the color */ const unsigned char imb_depth_back= ibuf->depth; const float dither_back= ibuf->dither; ibuf->depth= scene->r.planes; ibuf->dither= scene->r.dither_intensity; if (!BKE_write_ibuf(ibuf, path, scene->r.imtype, scene->r.subimtype, scene->r.quality)) { BKE_reportf(reports, RPT_ERROR, "Couldn't write image: %s", path); } ibuf->depth= imb_depth_back; ibuf->dither= dither_back; } BKE_image_release_ibuf(image, lock); } else { BKE_reportf(reports, RPT_ERROR, "Scene not in context, couldn't get save parameters"); } }
/* 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= BKE_get_movie_handle(sj->scene->r.im_format.imtype); /* 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)) { if(!mh->start_movie(sj->scene, &rd, sj->dumpsx, sj->dumpsy, &sj->reports)) { printf("screencast job stopped\n"); return; } } else mh= NULL; sj->stop= stop; sj->do_update= do_update; *do_update= 1; // wait for opengl rect while(*stop==0) { if(sj->dumprect) { if(mh) { if(mh->append_movie(&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_makepicstring(name, rd.pic, sj->bmain->name, rd.cfra, rd.im_format.imtype, rd.scemode & R_EXTENSION, TRUE); ibuf->rect= sj->dumprect; ok= BKE_write_ibuf(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\n", 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= 1; rd.cfra++; } else PIL_sleep_ms(U.scrcastwait); } if(mh) mh->end_movie(); BKE_report(&sj->reports, RPT_INFO, "Screencast job stopped"); }