示例#1
0
/* ID should be not NULL */
void BKE_unpack_id(Main *bmain, ID *id, ReportList *reports, int how)
{
	switch (GS(id->name)) {
		case ID_IM:
		{
			Image *ima = (Image *)id;
			if (BKE_image_has_packedfile(ima)) {
				unpackImage(reports, ima, how);
			}
			break;
		}
		case ID_VF:
		{
			VFont *vf = (VFont *)id;
			if (vf->packedfile) {
				unpackVFont(reports, vf, how);
			}
			break;
		}
		case ID_SO:
		{
			bSound *snd = (bSound *)id;
			if (snd->packedfile) {
				unpackSound(bmain, reports, snd, how);
			}
			break;
		}
		case ID_LI:
		{
			Library *li = (Library *)id;
			BKE_reportf(reports, RPT_ERROR, "Cannot unpack individual Library file, '%s'", li->name);
			break;
		}
	}
}
示例#2
0
/* ID should be not NULL, return 1 if there's a packed file */
bool BKE_pack_check(ID *id)
{
	switch (GS(id->name)) {
		case ID_IM:
		{
			Image *ima = (Image *)id;
			return BKE_image_has_packedfile(ima);
		}
		case ID_VF:
		{
			VFont *vf = (VFont *)id;
			return vf->packedfile != NULL;
		}
		case ID_SO:
		{
			bSound *snd = (bSound *)id;
			return snd->packedfile != NULL;
		}
		case ID_LI:
		{
			Library *li = (Library *)id;
			return li->packedfile != NULL;
		}
	}
	return false;
}
示例#3
0
static PointerRNA rna_Image_packed_file_get(PointerRNA *ptr)
{
  Image *ima = (Image *)ptr->id.data;

  if (BKE_image_has_packedfile(ima)) {
    ImagePackedFile *imapf = ima->packedfiles.first;
    return rna_pointer_inherit_refine(ptr, &RNA_PackedFile, imapf->packedfile);
  }
  else {
    return PointerRNA_NULL;
  }
}
示例#4
0
static void rna_Image_unpack(Image *image, ReportList *reports, int method)
{
	if (!BKE_image_has_packedfile(image)) {
		BKE_report(reports, RPT_ERROR, "Image not packed");
	}
	else if (BKE_image_is_animated(image)) {
		BKE_report(reports, RPT_ERROR, "Unpacking movies or image sequences not supported");
		return;
	}
	else {
		/* reports its own error on failure */
		unpackImage(reports, image, method);
	}
}
示例#5
0
static int paint_2d_canvas_set(ImagePaintState *s, Image *ima)
{
	ImBuf *ibuf = BKE_image_acquire_ibuf(ima, s->sima ? &s->sima->iuser : NULL, NULL);

	/* verify that we can paint and set canvas */
	if (ima == NULL) {
		return 0;
	}
	else if (BKE_image_has_packedfile(ima) && ima->rr) {
		s->warnpackedfile = ima->id.name + 2;
		return 0;
	}
	else if (ibuf && ibuf->channels != 4) {
		s->warnmultifile = ima->id.name + 2;
		return 0;
	}
	else if (!ibuf || !(ibuf->rect || ibuf->rect_float))
		return 0;

	s->image = ima;
	s->canvas = ibuf;

	/* set clone canvas */
	if (s->tool == PAINT_TOOL_CLONE) {
		ima = s->brush->clone.image;
		ibuf = BKE_image_acquire_ibuf(ima, s->sima ? &s->sima->iuser : NULL, NULL);

		if (!ima || !ibuf || !(ibuf->rect || ibuf->rect_float)) {
			BKE_image_release_ibuf(ima, ibuf, NULL);
			BKE_image_release_ibuf(s->image, s->canvas, NULL);
			return 0;
		}

		s->clonecanvas = ibuf;

		/* temporarily add float rect for cloning */
		if (s->canvas->rect_float && !s->clonecanvas->rect_float) {
			IMB_float_from_rect(s->clonecanvas);
		}
		else if (!s->canvas->rect_float && !s->clonecanvas->rect)
			IMB_rect_from_float(s->clonecanvas);
	}

	/* set masking */
	s->do_masking = paint_use_opacity_masking(s->brush);
	
	return 1;
}
示例#6
0
void unpackAll(Main *bmain, ReportList *reports, int how)
{
	Image *ima;
	VFont *vf;
	bSound *sound;

	for (ima = bmain->image.first; ima; ima = ima->id.next)
		if (BKE_image_has_packedfile(ima))
			unpackImage(reports, ima, how);

	for (vf = bmain->vfont.first; vf; vf = vf->id.next)
		if (vf->packedfile)
			unpackVFont(reports, vf, how);

	for (sound = bmain->sound.first; sound; sound = sound->id.next)
		if (sound->packedfile)
			unpackSound(bmain, reports, sound, how);
}
示例#7
0
/* no libraries for now */
void packAll(Main *bmain, ReportList *reports, bool verbose)
{
	Image *ima;
	VFont *vfont;
	bSound *sound;
	int tot = 0;
	
	for (ima = bmain->image.first; ima; ima = ima->id.next) {
		if (BKE_image_has_packedfile(ima) == false && ima->id.lib == NULL) {
			if (ima->source == IMA_SRC_FILE) {
				BKE_image_packfiles(reports, ima, ID_BLEND_PATH(bmain, &ima->id));
				tot ++;
			}
			else if (BKE_image_is_animated(ima) && verbose) {
				BKE_reportf(reports, RPT_WARNING, "Image '%s' skipped, movies and image sequences not supported",
				            ima->id.name + 2);
			}
		}
	}

	for (vfont = bmain->vfont.first; vfont; vfont = vfont->id.next) {
		if (vfont->packedfile == NULL && vfont->id.lib == NULL && BKE_vfont_is_builtin(vfont) == false) {
			vfont->packedfile = newPackedFile(reports, vfont->name, bmain->name);
			tot ++;
		}
	}

	for (sound = bmain->sound.first; sound; sound = sound->id.next) {
		if (sound->packedfile == NULL && sound->id.lib == NULL) {
			sound->packedfile = newPackedFile(reports, sound->name, bmain->name);
			tot++;
		}
	}
	
	if (tot > 0)
		BKE_reportf(reports, RPT_INFO, "Packed %d files", tot);
	else if (verbose)
		BKE_report(reports, RPT_INFO, "No new files have been packed");


}
示例#8
0
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);
}
示例#9
0
int countPackedFiles(Main *bmain)
{
	Image *ima;
	VFont *vf;
	bSound *sound;
	int count = 0;
	
	/* let's check if there are packed files... */
	for (ima = bmain->image.first; ima; ima = ima->id.next)
		if (BKE_image_has_packedfile(ima))
			count ++;

	for (vf = bmain->vfont.first; vf; vf = vf->id.next)
		if (vf->packedfile)
			count++;

	for (sound = bmain->sound.first; sound; sound = sound->id.next)
		if (sound->packedfile)
			count++;

	return count;
}
void ImagesExporter::export_UV_Image(Image *image, bool use_copies) 
{
	std::string name(id_name(image));
	std::string translated_name(translate_id(name));
	bool not_yet_exported = find(mImages.begin(), mImages.end(), translated_name) == mImages.end();

	if (not_yet_exported) {

		ImBuf *imbuf       = BKE_image_acquire_ibuf(image, NULL, NULL);
		if (!imbuf) {
			fprintf(stderr, "Collada export: image does not exist:\n%s\n", image->name);
			return;
		}

		bool  is_dirty     = (imbuf->userflags & IB_BITMAPDIRTY) != 0;

		ImageFormatData imageFormat;
		BKE_imbuf_to_image_format(&imageFormat, imbuf);

		short image_source = image->source;
		bool  is_generated = image_source == IMA_SRC_GENERATED;
		bool  is_packed    = BKE_image_has_packedfile(image);

		char export_path[FILE_MAX];
		char source_path[FILE_MAX];
		char export_dir[FILE_MAX];
		char export_file[FILE_MAX];

		// Destination folder for exported assets
		BLI_split_dir_part(this->export_settings->filepath, export_dir, sizeof(export_dir));

		if (is_generated || is_dirty || use_copies || is_packed) {

			// make absolute destination path

			BLI_strncpy(export_file, name.c_str(), sizeof(export_file));
			BKE_image_path_ensure_ext_from_imformat(export_file, &imageFormat);

			BLI_join_dirfile(export_path, sizeof(export_path), export_dir, export_file);

			// make dest directory if it doesn't exist
			BLI_make_existing_file(export_path);
		}

		if (is_generated || is_dirty || is_packed) {

			// This image in its current state only exists in Blender memory.
			// So we have to export it. The export will keep the image state intact,
			// so the exported file will not be associated with the image.

			if (BKE_imbuf_write_as(imbuf, export_path, &imageFormat, true) == 0) {
				fprintf(stderr, "Collada export: Cannot export image to:\n%s\n", export_path);
				return;
			}
			BLI_strncpy(export_path, export_file, sizeof(export_path));
		}
		else {

			// make absolute source path
			BLI_strncpy(source_path, image->name, sizeof(source_path));
			BLI_path_abs(source_path, G.main->name);
			BLI_cleanup_path(NULL, source_path);

			if (use_copies) {
			
				// This image is already located on the file system.
				// But we want to create copies here.
				// To move images into the same export directory.
				// Note: If an image is already located in the export folder,
				// then skip the copy (as it would result in a file copy error).

				if (BLI_path_cmp(source_path, export_path) != 0) {
					if (BLI_copy(source_path, export_path) != 0) {
						fprintf(stderr, "Collada export: Cannot copy image:\n source:%s\ndest :%s\n", source_path, export_path);
						return;
					}
				}

				BLI_strncpy(export_path, export_file, sizeof(export_path));

			}
			else {

				// Do not make any copies, but use the source path directly as reference
				// to the original image

				BLI_strncpy(export_path, source_path, sizeof(export_path));
			}
		}

		COLLADASW::Image img(COLLADABU::URI(COLLADABU::URI::nativePathToUri(export_path)), translated_name, translated_name); /* set name also to mNameNC. This helps other viewers import files exported from Blender better */
		img.add(mSW);
		fprintf(stdout, "Collada export: Added image: %s\n", export_file);
		mImages.push_back(translated_name);

		BKE_image_release_ibuf(image, imbuf, NULL);
	}
}