コード例 #1
0
ファイル: rna_image_api.c プロジェクト: Walid-Shouman/Blender
static void rna_Image_save(Image *image, ReportList *reports)
{
	ImBuf *ibuf = BKE_image_acquire_ibuf(image, NULL, NULL);
	if (ibuf) {
		char filename[FILE_MAX];
		BLI_strncpy(filename, image->name, sizeof(filename));
		BLI_path_abs(filename, G.main->name);

		if (image->packedfile) {
			if (writePackedFile(reports, image->name, image->packedfile, 0) != RET_OK) {
				BKE_reportf(reports, RPT_ERROR, "Image '%s' could not save packed file to '%s'", image->id.name + 2, image->name);
			}
		}
		else if (IMB_saveiff(ibuf, filename, ibuf->flags)) {
			image->type = IMA_TYPE_IMAGE;

			if (image->source == IMA_SRC_GENERATED)
				image->source = IMA_SRC_FILE;

			IMB_colormanagment_colorspace_from_ibuf_ftype(&image->colorspace_settings, ibuf);

			ibuf->userflags &= ~IB_BITMAPDIRTY;
		}
		else {
			BKE_reportf(reports, RPT_ERROR, "Image '%s' could not be saved to '%s'", image->id.name + 2, image->name);
		}
	}
	else {
		BKE_reportf(reports, RPT_ERROR, "Image '%s' does not have any image data", image->id.name + 2);
	}

	BKE_image_release_ibuf(image, ibuf, NULL);
}
コード例 #2
0
ファイル: rna_image_api.c プロジェクト: pawkoz/dyplom
static void rna_Image_save(Image *image, Main *bmain, bContext *C, ReportList *reports)
{
	ImBuf *ibuf = BKE_image_acquire_ibuf(image, NULL, NULL);
	if (ibuf) {
		char filename[FILE_MAX];
		BLI_strncpy(filename, image->name, sizeof(filename));
		BLI_path_abs(filename, ID_BLEND_PATH(bmain, &image->id));

		/* note, we purposefully ignore packed files here,
		 * developers need to explicitly write them via 'packed_files' */

		if (IMB_saveiff(ibuf, filename, ibuf->flags)) {
			image->type = IMA_TYPE_IMAGE;

			if (image->source == IMA_SRC_GENERATED)
				image->source = IMA_SRC_FILE;

			IMB_colormanagment_colorspace_from_ibuf_ftype(&image->colorspace_settings, ibuf);

			ibuf->userflags &= ~IB_BITMAPDIRTY;
		}
		else {
			BKE_reportf(reports, RPT_ERROR, "Image '%s' could not be saved to '%s'", image->id.name + 2, image->name);
		}
	}
	else {
		BKE_reportf(reports, RPT_ERROR, "Image '%s' does not have any image data", image->id.name + 2);
	}

	BKE_image_release_ibuf(image, ibuf, NULL);
	WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, image);
}
コード例 #3
0
ファイル: rna_image_api.c プロジェクト: OldBrunet/BGERTPS
static void rna_Image_save(Image *image, ReportList *reports)
{
	ImBuf *ibuf= BKE_image_get_ibuf(image, NULL);
	if(ibuf) {
		char filename[FILE_MAXDIR + FILE_MAXFILE];
		BLI_strncpy(filename, image->name, sizeof(filename));
		BLI_path_abs(filename, G.main->name);

		if(image->packedfile) {
			if (writePackedFile(reports, image->name, image->packedfile, 0) != RET_OK) {
				BKE_reportf(reports, RPT_ERROR, "Image \"%s\" could saved packed file to \"%s\"", image->id.name+2, image->name);
			}
		}
		else if (IMB_saveiff(ibuf, filename, ibuf->flags)) {
			image->type= IMA_TYPE_IMAGE;

			if(image->source==IMA_SRC_GENERATED)
				image->source= IMA_SRC_FILE;

			ibuf->userflags &= ~IB_BITMAPDIRTY;
		}
		else {
			BKE_reportf(reports, RPT_ERROR, "Image \"%s\" could not be saved to \"%s\"", image->id.name+2, image->name);
		}
	}
	else {
		BKE_reportf(reports, RPT_ERROR, "Image \"%s\" does not have any image data", image->id.name+2);
	}
}
コード例 #4
0
ファイル: movieclip.c プロジェクト: nttputus/blensor
static void movieclip_build_proxy_ibuf(MovieClip *clip, ImBuf *ibuf, int cfra, int proxy_render_size, int undistorted)
{
    char name[FILE_MAX];
    int quality, rectx, recty;
    int size = rendersize_to_number(proxy_render_size);
    ImBuf *scaleibuf;

    get_proxy_fname(clip, proxy_render_size, undistorted, cfra, name);

    rectx = ibuf->x * size / 100.0f;
    recty = ibuf->y * size / 100.0f;

    scaleibuf = IMB_dupImBuf(ibuf);

    IMB_scaleImBuf(scaleibuf, (short)rectx, (short)recty);

    quality = clip->proxy.quality;
    scaleibuf->ftype = JPG | quality;

    /* unsupported feature only confuses other s/w */
    if (scaleibuf->planes == 32)
        scaleibuf->planes = 24;

    BLI_lock_thread(LOCK_MOVIECLIP);

    BLI_make_existing_file(name);
    if (IMB_saveiff(scaleibuf, name, IB_rect) == 0)
        perror(name);

    BLI_unlock_thread(LOCK_MOVIECLIP);

    IMB_freeImBuf(scaleibuf);
}
コード例 #5
0
ファイル: KX_BlenderGL.cpp プロジェクト: mik0001/Blender
/* based on screendump.c::screenshot_exec */
void BL_MakeScreenShot(ScrArea *curarea, const char* filename)
{
	char path[MAX_FILE_LENGTH];
	strcpy(path,filename);

	unsigned int *dumprect;
	int dumpsx, dumpsy;
	
	dumprect= screenshot(curarea, &dumpsx, &dumpsy);
	if(dumprect) {
		ImBuf *ibuf;
		BLI_path_abs(path, G.main->name);
		/* BKE_add_image_extension() checks for if extension was already set */
		BKE_add_image_extension(path, R_IMF_IMTYPE_PNG); /* scene->r.im_format.imtype */
		ibuf= IMB_allocImBuf(dumpsx, dumpsy, 24, 0);
		ibuf->rect= dumprect;
		ibuf->ftype= PNG;

		IMB_saveiff(ibuf, path, IB_rect);

		ibuf->rect= NULL;
		IMB_freeImBuf(ibuf);
		MEM_freeN(dumprect);
	}
}
コード例 #6
0
ファイル: movieclip.c プロジェクト: Walid-Shouman/Blender
static void movieclip_build_proxy_ibuf(MovieClip *clip, ImBuf *ibuf, int cfra, int proxy_render_size, bool undistorted, bool threaded)
{
	char name[FILE_MAX];
	int quality, rectx, recty;
	int size = rendersize_to_number(proxy_render_size);
	ImBuf *scaleibuf;

	get_proxy_fname(clip, proxy_render_size, undistorted, cfra, name);

	rectx = ibuf->x * size / 100.0f;
	recty = ibuf->y * size / 100.0f;

	scaleibuf = IMB_dupImBuf(ibuf);

	if (threaded)
		IMB_scaleImBuf_threaded(scaleibuf, (short)rectx, (short)recty);
	else
		IMB_scaleImBuf(scaleibuf, (short)rectx, (short)recty);

	quality = clip->proxy.quality;
	scaleibuf->ftype = JPG | quality;

	/* unsupported feature only confuses other s/w */
	if (scaleibuf->planes == 32)
		scaleibuf->planes = 24;

	/* TODO: currently the most weak part of multithreaded proxies,
	 *       could be solved in a way that thread only prepares memory
	 *       buffer and write to disk happens separately
	 */
	BLI_lock_thread(LOCK_MOVIECLIP);

	BLI_make_existing_file(name);
	if (IMB_saveiff(scaleibuf, name, IB_rect) == 0)
		perror(name);

	BLI_unlock_thread(LOCK_MOVIECLIP);

	IMB_freeImBuf(scaleibuf);
}
コード例 #7
0
ファイル: rna_image_api.c プロジェクト: bitfusionio/blender
static void rna_Image_save(Image *image, Main *bmain, bContext *C, ReportList *reports)
{
	ImBuf *ibuf = BKE_image_acquire_ibuf(image, NULL, NULL);
	if (ibuf) {
		char filename[FILE_MAX];
		BLI_strncpy(filename, image->name, sizeof(filename));
		BLI_path_abs(filename, ID_BLEND_PATH(bmain, &image->id));

		if (BKE_image_has_packedfile(image)) {
			ImagePackedFile *imapf;

			for (imapf = image->packedfiles.first; imapf; imapf = imapf->next) {
				if (writePackedFile(reports, imapf->filepath, imapf->packedfile, 0) != RET_OK) {
					BKE_reportf(reports, RPT_ERROR, "Image '%s' could not save packed file to '%s'",
					            image->id.name + 2, imapf->filepath);
				}
			}
		}
		else if (IMB_saveiff(ibuf, filename, ibuf->flags)) {
			image->type = IMA_TYPE_IMAGE;

			if (image->source == IMA_SRC_GENERATED)
				image->source = IMA_SRC_FILE;

			IMB_colormanagment_colorspace_from_ibuf_ftype(&image->colorspace_settings, ibuf);

			ibuf->userflags &= ~IB_BITMAPDIRTY;
		}
		else {
			BKE_reportf(reports, RPT_ERROR, "Image '%s' could not be saved to '%s'", image->id.name + 2, image->name);
		}
	}
	else {
		BKE_reportf(reports, RPT_ERROR, "Image '%s' does not have any image data", image->id.name + 2);
	}

	BKE_image_release_ibuf(image, ibuf, NULL);
	WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, image);
}
コード例 #8
0
ファイル: Canvas.cpp プロジェクト: 244xiao/blender
void Canvas::loadMap(const char *iFileName, const char *iMapName, unsigned int iNbLevels, float iSigma)
{
	// check whether this map was already loaded:
	if (!_maps.empty()) {
		mapsMap::iterator m = _maps.find(iMapName);
		if (m != _maps.end()) {
			// lazy check for size changes
			ImagePyramid *pyramid = (*m).second;
			if ((pyramid->width() != width()) || (pyramid->height() != height())) {
				delete pyramid;
			}
			else {
				return;
			}
		}
	}

	string filePath;
	if (_MapsPath) {
		filePath = _MapsPath;
		filePath += iFileName;
	}
	else {
		filePath = iFileName;
	}

#if 0 //soc
	QImage *qimg;
	QImage newMap(filePath.c_str());
	if (newMap.isNull()) {
		cerr << "Could not load image file " << filePath << endl;
		return;
	}
	qimg = &newMap;
#endif
	/* OCIO_TODO: support different input color space */
	ImBuf *qimg = IMB_loadiffname(filePath.c_str(), 0, NULL);
	if (qimg == 0) {
		cerr << "Could not load image file " << filePath << endl;
		return;
	}

#if 0 // soc
	// resize
	QImage scaledImg;
	if ((newMap.width() != width()) || (newMap.height() != height())) {
		scaledImg = newMap.scaled(width(), height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
		qimg = &scaledImg;
	}
#endif
	ImBuf *scaledImg;
	if ((qimg->x != width()) || (qimg->y != height())) {
		scaledImg = IMB_dupImBuf(qimg);
		IMB_scaleImBuf(scaledImg, width(), height());
	}


	// deal with color image
#if 0
	if (newMap->depth() != 8) {
		int w = newMap->width();
		int h = newMap->height();
		QImage *tmp = new QImage(w, h, 8);
		for (unsigned int y = 0; y < h; ++y) {
			for (unsigned int x = 0; x < w; ++x) {
				int c = qGray(newMap->pixel(x, y));
				tmp->setPixel(x, y, c);
			}
		}
		delete newMap;
		newMap = tmp;
	}
#endif

	int x, y;
	int w = qimg->x;
	int h = qimg->y;
	int rowbytes = w * 4;
	GrayImage tmp(w, h);
	char *pix;

	for (y = 0; y < h; ++y) {
		for (x = 0; x < w; ++x) {
			pix = (char *)qimg->rect + y * rowbytes + x * 4;
			float c = (pix[0] * 11 + pix[1] * 16 + pix[2] * 5) / 32;
			tmp.setPixel(x, y, c);
		}
	}

#if 0
	GrayImage blur(w, h);
	GaussianFilter gf(4.0f);
	//int bound = gf.getBound();
	for (y = 0; y < h; ++y) {
		for (x = 0; x < w; ++x) {
			int c = gf.getSmoothedPixel<GrayImage>(&tmp, x, y);
			blur.setPixel(x, y, c);
		}
	}
#endif

	GaussianPyramid *pyramid = new GaussianPyramid(tmp, iNbLevels, iSigma);
	int ow = pyramid->width(0);
	int oh = pyramid->height(0);
	string base(iMapName); //soc
	for (int i = 0; i < pyramid->getNumberOfLevels(); ++i) {
		// save each image:
#if 0
		w = pyramid.width(i);
		h = pyramid.height(i);
#endif

		//soc  QImage qtmp(ow, oh, QImage::Format_RGB32);
		ImBuf *qtmp = IMB_allocImBuf(ow, oh, 32, IB_rect);

		//int k = (1 << i);
		for (y = 0; y < oh; ++y) {
			for (x = 0; x < ow; ++x) {
				int c = pyramid->pixel(x, y, i); // 255 * pyramid->pixel(x, y, i);
				//soc qtmp.setPixel(x, y, qRgb(c, c, c));
				pix = (char *)qtmp->rect + y * rowbytes + x * 4;
				pix[0] = pix[1] = pix[2] = c;
			}
		}
		//soc qtmp.save(base + QString::number(i) + ".bmp", "BMP");
		stringstream filename;
		filename << base;
		filename << i << ".bmp";
		qtmp->ftype = BMP;
		IMB_saveiff(qtmp, const_cast<char *>(filename.str().c_str()), 0);
	}

#if 0
	QImage *qtmp = new QImage(w, h, 32);
	for (y = 0; y < h; ++y) {
		for (x = 0; x < w; ++x) {
			int c = (int)blur.pixel(x, y);
			qtmp->setPixel(x, y, qRgb(c, c, c));
		}
	}
	delete newMap;
	newMap = qtmp;
#endif

	_maps[iMapName] = pyramid;
	//newMap->save("toto.bmp", "BMP");
}
コード例 #9
0
ファイル: pluginapi.c プロジェクト: nttputus/blensor
LIBEXPORT short saveiff(struct ImBuf *ib,
                        char *c,
                        int i)
{
    return IMB_saveiff(ib, c, i);
}