Beispiel #1
0
static int screenshot_exec(bContext *C, wmOperator *op)
{
  ScreenshotData *scd = op->customdata;
  bool ok = false;

  if (scd == NULL) {
    /* when running exec directly */
    screenshot_data_create(C, op);
    scd = op->customdata;
  }

  if (scd) {
    if (scd->dumprect) {
      ImBuf *ibuf;
      char path[FILE_MAX];

      RNA_string_get(op->ptr, "filepath", path);
      BLI_path_abs(path, BKE_main_blendfile_path_from_global());

      /* operator ensures the extension */
      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);
      }

      if (scd->im_format.planes == R_IMF_PLANES_BW) {
        /* bw screenshot? - users will notice if it fails! */
        IMB_color_to_bw(ibuf);
      }
      if (BKE_imbuf_write(ibuf, path, &scd->im_format)) {
        ok = true;
      }
      else {
        BKE_reportf(op->reports, RPT_ERROR, "Could not write image: %s", strerror(errno));
      }

      IMB_freeImBuf(ibuf);
    }
  }

  screenshot_data_free(op);

  return ok ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
}
Beispiel #2
0
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;
}
Beispiel #3
0
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) {
            ImBuf *ibuf;
            char path[FILE_MAX];

            RNA_string_get(op->ptr, "filepath", path);
            BLI_path_abs(path, G.main->name);

            /* operator ensures the extension */
            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);

            if (scd->im_format.planes == R_IMF_PLANES_BW) {
                /* bw screenshot? - users will notice if it fails! */
                IMB_color_to_bw(ibuf);
            }
            BKE_imbuf_write(ibuf, path, &scd->im_format);

            IMB_freeImBuf(ibuf);
        }
    }

    screenshot_data_free(op);
    return OPERATOR_FINISHED;
}