Ejemplo n.º 1
0
void BKE_sound_free(bSound *sound)
{
	if (sound->packedfile) {
		freePackedFile(sound->packedfile);
		sound->packedfile = NULL;
	}

#ifdef WITH_AUDASPACE
	if (sound->handle) {
		AUD_Sound_free(sound->handle);
		sound->handle = NULL;
		sound->playback_handle = NULL;
	}

	if (sound->cache) {
		AUD_Sound_free(sound->cache);
		sound->cache = NULL;
	}

	BKE_sound_free_waveform(sound);
	
	if (sound->spinlock) {
		BLI_spin_end(sound->spinlock);
		MEM_freeN(sound->spinlock);
		sound->spinlock = NULL;
	}
	
#endif  /* WITH_AUDASPACE */
}
Ejemplo n.º 2
0
static void rna_Image_pack(
        Image *image, Main *bmain, bContext *C, ReportList *reports,
        int as_png, const char *data, int data_len)
{
	ImBuf *ibuf = BKE_image_acquire_ibuf(image, NULL, NULL);

	if (!as_png && (ibuf && (ibuf->userflags & IB_BITMAPDIRTY))) {
		BKE_report(reports, RPT_ERROR, "Cannot pack edited image from disk, only as internal PNG");
	}
	else {
		if (image->packedfile) {
			freePackedFile(image->packedfile);
			image->packedfile = NULL;
		}
		if (as_png) {
			BKE_image_memorypack(image);
		}
		else if (data) {
			char *data_dup = MEM_mallocN(sizeof(*data_dup) * (size_t)data_len, __func__);
			memcpy(data_dup, data, (size_t)data_len);
			image->packedfile = newPackedFileMemory(data_dup, data_len);
		}
		else {
			image->packedfile = newPackedFile(reports, image->name, ID_BLEND_PATH(bmain, &image->id));
		}
	}

	BKE_image_release_ibuf(image, ibuf, NULL);
	WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, image);
}
Ejemplo n.º 3
0
int unpackSound(Main *bmain, ReportList *reports, bSound *sound, int how)
{
	char localname[FILE_MAXDIR + FILE_MAX], fi[FILE_MAX];
	char *newname;
	int ret_value = RET_ERROR;

	if (sound != NULL) {
		BLI_strncpy(localname, sound->name, sizeof(localname));
		BLI_splitdirstring(localname, fi);
		BLI_snprintf(localname, sizeof(localname), "//sounds/%s", fi);

		newname = unpackFile(reports, sound->name, localname, sound->packedfile, how);
		if (newname != NULL) {
			BLI_strncpy(sound->name, newname, sizeof(sound->name));
			MEM_freeN(newname);

			freePackedFile(sound->packedfile);
			sound->packedfile = NULL;

			sound_load(bmain, sound);

			ret_value = RET_OK;
		}
	}
	
	return(ret_value);
}
Ejemplo n.º 4
0
int unpackLibraries(Main *bmain, ReportList *reports)
{
	Library *lib;
	char *newname;
	int ret_value = RET_ERROR;
	
	for (lib = bmain->library.first; lib; lib = lib->id.next) {
		if (lib->packedfile && lib->name[0]) {
			
			newname = unpackFile(reports, lib->filepath, lib->filepath, lib->packedfile, PF_WRITE_ORIGINAL);
			if (newname != NULL) {
				ret_value = RET_OK;
				
				printf("Unpacked .blend library: %s\n", newname);
				
				freePackedFile(lib->packedfile);
				lib->packedfile = NULL;

				MEM_freeN(newname);
			}
		}
	}
	
	return(ret_value);
}
Ejemplo n.º 5
0
/* The vfont code */
void free_vfont(struct VFont *vf)
{
	if (vf == NULL) return;

	if (vf->data) {
		while (vf->data->characters.first)
		{
			VChar *che = vf->data->characters.first;
			
			while (che->nurbsbase.first) {
				Nurb *nu = che->nurbsbase.first;
				if (nu->bezt) MEM_freeN(nu->bezt);
				BLI_freelinkN(&che->nurbsbase, nu);
			}
	
			BLI_freelinkN(&vf->data->characters, che);
		}

		MEM_freeN(vf->data);
		vf->data = NULL;
	}
	
	if (vf->packedfile) {
		freePackedFile(vf->packedfile);
		vf->packedfile = NULL;
	}
}
Ejemplo n.º 6
0
VFont *BKE_vfont_load(Main *bmain, const char *name)
{
	char filename[FILE_MAXFILE];
	VFont *vfont = NULL;
	PackedFile *pf;
	PackedFile *temp_pf = NULL;
	int is_builtin;
	
	if (STREQ(name, FO_BUILTIN_NAME)) {
		BLI_strncpy(filename, name, sizeof(filename));
		
		pf = get_builtin_packedfile();
		is_builtin = TRUE;
	}
	else {
		BLI_split_file_part(name, filename, sizeof(filename));
		pf = newPackedFile(NULL, name, bmain->name);
		temp_pf = newPackedFile(NULL, name, bmain->name);
		
		is_builtin = FALSE;
	}

	if (pf) {
		VFontData *vfd;

		vfd = BLI_vfontdata_from_freetypefont(pf);
		if (vfd) {
			vfont = BKE_libblock_alloc(&bmain->vfont, ID_VF, filename);
			vfont->data = vfd;

			/* if there's a font name, use it for the ID name */
			if (vfd->name[0] != '\0') {
				BLI_strncpy(vfont->id.name + 2, vfd->name, sizeof(vfont->id.name) - 2);
			}
			BLI_strncpy(vfont->name, name, sizeof(vfont->name));

			/* if autopack is on store the packedfile in de font structure */
			if (!is_builtin && (G.fileflags & G_AUTOPACK)) {
				vfont->packedfile = pf;
			}

			/* Do not add FO_BUILTIN_NAME to temporary listbase */
			if (strcmp(filename, FO_BUILTIN_NAME)) {
				vfont->temp_pf = temp_pf;
			}
		}

		/* Free the packed file */
		if (!vfont || vfont->packedfile != pf) {
			freePackedFile(pf);
		}
	}
	
	return vfont;
}
Ejemplo n.º 7
0
void free_ttfont(void)
{
	struct TmpFont *tf;

	for (tf= ttfdata.first; tf; tf= tf->next) {
		if (tf->pf) freePackedFile(tf->pf); /* NULL when the font file can't be found on disk */
		tf->pf= NULL;
		tf->vfont= NULL;
	}
	BLI_freelistN(&ttfdata);
}
Ejemplo n.º 8
0
void BKE_vfont_free(struct VFont *vf)
{
	if (vf == NULL) return;

	BKE_vfont_free_data(vf);

	if (vf->packedfile) {
		freePackedFile(vf->packedfile);
		vf->packedfile = NULL;
	}
}
Ejemplo n.º 9
0
static VFontData *vfont_get_data(Main *bmain, VFont *vfont)
{
	if (vfont == NULL) {
		return NULL;
	}

	/* And then set the data */
	if (!vfont->data) {
		PackedFile *pf;

		if (BKE_vfont_is_builtin(vfont)) {
			pf = get_builtin_packedfile();
		}
		else {
			if (vfont->packedfile) {
				pf = vfont->packedfile;

				/* We need to copy a tmp font to memory unless it is already there */
				if (vfont->temp_pf == NULL) {
					vfont->temp_pf = dupPackedFile(pf);
				}
			}
			else {
				pf = newPackedFile(NULL, vfont->name, ID_BLEND_PATH(bmain, &vfont->id));

				if (vfont->temp_pf == NULL) {
					vfont->temp_pf = newPackedFile(NULL, vfont->name, ID_BLEND_PATH(bmain, &vfont->id));
				}
			}
			if (!pf) {
				printf("Font file doesn't exist: %s\n", vfont->name);

				/* DON'T DO THIS
				 * missing file shouldn't modifty path! - campbell */
#if 0
				strcpy(vfont->name, FO_BUILTIN_NAME);
#endif
				pf = get_builtin_packedfile();
			}
		}
		
		if (pf) {
			vfont->data = BLI_vfontdata_from_freetypefont(pf);
			if (pf != vfont->packedfile) {
				freePackedFile(pf);
			}
		}
	}
	
	return vfont->data;
}
Ejemplo n.º 10
0
int unpackImage(ReportList *reports, Image *ima, int how)
{
	int ret_value = RET_ERROR;

	if (ima != NULL) {
		while (ima->packedfiles.last) {
			char localname[FILE_MAX], absname[FILE_MAX];
			char *newname;
			ImagePackedFile *imapf = ima->packedfiles.last;

			unpack_generate_paths(imapf->filepath, (ID *)ima, absname, localname, sizeof(absname), sizeof(localname));
			newname = unpackFile(reports, absname, localname, imapf->packedfile, how);

			if (newname != NULL) {
				ImageView *iv;

				ret_value = ret_value == RET_ERROR ? RET_ERROR : RET_OK;
				freePackedFile(imapf->packedfile);
				imapf->packedfile = NULL;

				/* update the new corresponding view filepath */
				iv = BLI_findstring(&ima->views, imapf->filepath, offsetof(ImageView, filepath));
				if (iv) {
					BLI_strncpy(iv->filepath, newname, sizeof(imapf->filepath));
				}

				/* keep the new name in the image for non-pack specific reasons */
				if (how != PF_REMOVE) {
					BLI_strncpy(ima->name, newname, sizeof(imapf->filepath));
				}
				MEM_freeN(newname);
			}
			else {
				ret_value = RET_ERROR;
			}

			BLI_remlink(&ima->packedfiles, imapf);
			MEM_freeN(imapf);
		}
	}

	if (ret_value == RET_OK) {
		BKE_image_signal(ima, NULL, IMA_SIGNAL_RELOAD);
	}

	return(ret_value);
}
Ejemplo n.º 11
0
int unpackVFont(ReportList *reports, VFont *vfont, int how)
{
	char localname[FILE_MAX], absname[FILE_MAX];
	char *newname;
	int ret_value = RET_ERROR;
	
	if (vfont != NULL) {
		unpack_generate_paths(vfont->name, (ID *)vfont, absname, localname, sizeof(absname), sizeof(localname));
		newname = unpackFile(reports, absname, localname, vfont->packedfile, how);
		if (newname != NULL) {
			ret_value = RET_OK;
			freePackedFile(vfont->packedfile);
			vfont->packedfile = NULL;
			BLI_strncpy(vfont->name, newname, sizeof(vfont->name));
			MEM_freeN(newname);
		}
	}
	
	return (ret_value);
}
Ejemplo n.º 12
0
int unpackImage(ReportList *reports, Image *ima, int how)
{
	char localname[FILE_MAX], absname[FILE_MAX];
	char *newname;
	int ret_value = RET_ERROR;
	
	if (ima != NULL && ima->name[0]) {
		unpack_generate_paths(ima->name, (ID *)ima, absname, localname, sizeof(absname), sizeof(localname));
		newname = unpackFile(reports, absname, localname, ima->packedfile, how);
		if (newname != NULL) {
			ret_value = RET_OK;
			freePackedFile(ima->packedfile);
			ima->packedfile = NULL;
			BLI_strncpy(ima->name, newname, sizeof(ima->name));
			MEM_freeN(newname);
			BKE_image_signal(ima, NULL, IMA_SIGNAL_RELOAD);
		}
	}
	
	return(ret_value);
}
Ejemplo n.º 13
0
int unpackVFont(ReportList *reports, VFont *vfont, int how)
{
    char localname[FILE_MAX], fi[FILE_MAXFILE];
    char *newname;
    int ret_value = RET_ERROR;

    if (vfont != NULL) {
        BLI_split_file_part(vfont->name, fi, sizeof(fi));
        BLI_snprintf(localname, sizeof(localname), "//fonts/%s", fi);
        newname = unpackFile(reports, vfont->name, localname, vfont->packedfile, how);
        if (newname != NULL) {
            ret_value = RET_OK;
            freePackedFile(vfont->packedfile);
            vfont->packedfile = NULL;
            BLI_strncpy(vfont->name, newname, sizeof(vfont->name));
            MEM_freeN(newname);
        }
    }

    return (ret_value);
}
Ejemplo n.º 14
0
void BKE_sound_free(bSound *sound)
{
	if (sound->packedfile) {
		freePackedFile(sound->packedfile);
		sound->packedfile = NULL;
	}

#ifdef WITH_AUDASPACE
	if (sound->handle) {
		AUD_unload(sound->handle);
		sound->handle = NULL;
		sound->playback_handle = NULL;
	}

	if (sound->cache) {
		AUD_unload(sound->cache);
		sound->cache = NULL;
	}

	sound_free_waveform(sound);
#endif  /* WITH_AUDASPACE */
}
Ejemplo n.º 15
0
int unpackImage(ReportList *reports, Image *ima, int how)
{
    char localname[FILE_MAXDIR + FILE_MAX], fi[FILE_MAX];
    char *newname;
    int ret_value = RET_ERROR;

    if (ima != NULL && ima->name[0]) {
        BLI_split_file_part(ima->name, fi, sizeof(fi));
        BLI_snprintf(localname, sizeof(localname), "//textures/%s", fi);
        newname = unpackFile(reports, ima->name, localname, ima->packedfile, how);
        if (newname != NULL) {
            ret_value = RET_OK;
            freePackedFile(ima->packedfile);
            ima->packedfile = NULL;
            BLI_strncpy(ima->name, newname, sizeof(ima->name));
            MEM_freeN(newname);
            BKE_image_signal(ima, NULL, IMA_SIGNAL_RELOAD);
        }
    }

    return(ret_value);
}
Ejemplo n.º 16
0
/* The vfont code */
void BKE_vfont_free_data(struct VFont *vfont)
{
	if (vfont->data) {
		while (vfont->data->characters.first) {
			VChar *che = vfont->data->characters.first;

			while (che->nurbsbase.first) {
				Nurb *nu = che->nurbsbase.first;
				if (nu->bezt) MEM_freeN(nu->bezt);
				BLI_freelinkN(&che->nurbsbase, nu);
			}

			BLI_freelinkN(&vfont->data->characters, che);
		}

		MEM_freeN(vfont->data);
		vfont->data = NULL;
	}

	if (vfont->temp_pf) {
		freePackedFile(vfont->temp_pf);  /* NULL when the font file can't be found on disk */
		vfont->temp_pf = NULL;
	}
}
Ejemplo n.º 17
0
int unpackSound(Main *bmain, ReportList *reports, bSound *sound, int how)
{
	char localname[FILE_MAX], absname[FILE_MAX];
	char *newname;
	int ret_value = RET_ERROR;

	if (sound != NULL) {
		unpack_generate_paths(sound->name, (ID *)sound, absname, localname, sizeof(absname), sizeof(localname));
		newname = unpackFile(reports, absname, localname, sound->packedfile, how);
		if (newname != NULL) {
			BLI_strncpy(sound->name, newname, sizeof(sound->name));
			MEM_freeN(newname);

			freePackedFile(sound->packedfile);
			sound->packedfile = NULL;

			BKE_sound_load(bmain, sound);

			ret_value = RET_OK;
		}
	}
	
	return(ret_value);
}
Ejemplo n.º 18
0
int unpackVFont(ReportList *reports, VFont *vfont, int how)
{
	char localname[FILE_MAXDIR + FILE_MAXFILE], fi[FILE_MAXFILE];
	char *newname;
	int ret_value = RET_ERROR;
	
	if (vfont != NULL) {
		strcpy(localname, vfont->name);
		BLI_splitdirstring(localname, fi);
		
		sprintf(localname, "//fonts/%s", fi);
		
		newname = unpackFile(reports, vfont->name, localname, vfont->packedfile, how);
		if (newname != NULL) {
			ret_value = RET_OK;
			freePackedFile(vfont->packedfile);
			vfont->packedfile = NULL;
			strcpy(vfont->name, newname);
			MEM_freeN(newname);
		}
	}
	
	return (ret_value);
}
Ejemplo n.º 19
0
static VFontData *vfont_get_data(Main *bmain, VFont *vfont)
{
	if (vfont == NULL) {
		return NULL;
	}

	/* And then set the data */
	if (!vfont->data) {
		PackedFile *pf;

		BLI_mutex_lock(&vfont_mutex);

		if (vfont->data) {
			/* Check data again, since it might have been already
			 * initialized from other thread (previous check is
			 * not accurate or threading, just prevents unneeded
			 * lock if all the data is here for sure).
			 */
			BLI_mutex_unlock(&vfont_mutex);
			return vfont->data;
		}

		if (BKE_vfont_is_builtin(vfont)) {
			pf = get_builtin_packedfile();
		}
		else {
			if (vfont->packedfile) {
				pf = vfont->packedfile;

				/* We need to copy a tmp font to memory unless it is already there */
				if (vfont->temp_pf == NULL) {
					vfont->temp_pf = dupPackedFile(pf);
				}
			}
			else {
				pf = newPackedFile(NULL, vfont->name, ID_BLEND_PATH(bmain, &vfont->id));

				if (vfont->temp_pf == NULL) {
					vfont->temp_pf = newPackedFile(NULL, vfont->name, ID_BLEND_PATH(bmain, &vfont->id));
				}
			}
			if (!pf) {
				printf("Font file doesn't exist: %s\n", vfont->name);

				/* DON'T DO THIS
				 * missing file shouldn't modifty path! - campbell */
#if 0
				strcpy(vfont->name, FO_BUILTIN_NAME);
#endif
				pf = get_builtin_packedfile();
			}
		}
		
		if (pf) {
			vfont->data = BLI_vfontdata_from_freetypefont(pf);
			if (pf != vfont->packedfile) {
				freePackedFile(pf);
			}
		}

		BLI_mutex_unlock(&vfont_mutex);
	}

	return vfont->data;
}
Ejemplo n.º 20
0
static VFontData *vfont_get_data(Main *bmain, VFont *vfont)
{
	struct TmpFont *tmpfnt = NULL;
	PackedFile *tpf;
	
	if (vfont==NULL) return NULL;
	
	// Try finding the font from font list
	tmpfnt = vfont_find_tmpfont(vfont);
	
	// And then set the data	
	if (!vfont->data) {
		PackedFile *pf;
		
		if (strcmp(vfont->name, FO_BUILTIN_NAME)==0) {
			pf= get_builtin_packedfile();
		}
		else {
			if (vfont->packedfile) {
				pf= vfont->packedfile;
				
				// We need to copy a tmp font to memory unless it is already there
				if (!tmpfnt) {
					tpf= MEM_callocN(sizeof(*tpf), "PackedFile");
					tpf->data= MEM_mallocN(pf->size, "packFile");
					tpf->size= pf->size;
					memcpy(tpf->data, pf->data, pf->size);
					
					// Add temporary packed file to globals
					tmpfnt= (struct TmpFont *) MEM_callocN(sizeof(struct TmpFont), "temp_font");
					tmpfnt->pf= tpf;
					tmpfnt->vfont= vfont;
					BLI_addtail(&ttfdata, tmpfnt);
				}
			}
			else {
				pf= newPackedFile(NULL, vfont->name, ID_BLEND_PATH(bmain, &vfont->id));

				if (!tmpfnt) {
					tpf= newPackedFile(NULL, vfont->name, ID_BLEND_PATH(bmain, &vfont->id));
					
					// Add temporary packed file to globals
					tmpfnt= (struct TmpFont *) MEM_callocN(sizeof(struct TmpFont), "temp_font");
					tmpfnt->pf= tpf;
					tmpfnt->vfont= vfont;
					BLI_addtail(&ttfdata, tmpfnt);
				}
			}
			if (!pf) {
				printf("Font file doesn't exist: %s\n", vfont->name);

				strcpy(vfont->name, FO_BUILTIN_NAME);
				pf= get_builtin_packedfile();
			}
		}
		
		if (pf) {
			vfont->data= BLI_vfontdata_from_freetypefont(pf);
			if (pf != vfont->packedfile) {
				freePackedFile(pf);
			}
		}
	}
	
	return vfont->data;	
}
Ejemplo n.º 21
0
static void BKE_library_free(Library *lib)
{
	if (lib->packedfile)
		freePackedFile(lib->packedfile);
}
Ejemplo n.º 22
0
VFont *load_vfont(Main *bmain, const char *name)
{
	char filename[FILE_MAXFILE];
	VFont *vfont= NULL;
	PackedFile *pf;
	PackedFile *tpf = NULL;	
	int is_builtin;
	struct TmpFont *tmpfnt;
	
	if (strcmp(name, FO_BUILTIN_NAME)==0) {
		BLI_strncpy(filename, name, sizeof(filename));
		
		pf= get_builtin_packedfile();
		is_builtin= 1;
	}
	else {
		char dir[FILE_MAXDIR];
		
		BLI_strncpy(dir, name, sizeof(dir));
		BLI_splitdirstring(dir, filename);

		pf= newPackedFile(NULL, name, bmain->name);
		tpf= newPackedFile(NULL, name, bmain->name);
		
		is_builtin= 0;
	}

	if (pf) {
		VFontData *vfd;

		vfd= BLI_vfontdata_from_freetypefont(pf);
		if (vfd) {
			vfont = alloc_libblock(&bmain->vfont, ID_VF, filename);
			vfont->data = vfd;

			/* if there's a font name, use it for the ID name */
			if (vfd->name[0] != '\0') {
				BLI_strncpy(vfont->id.name+2, vfd->name, sizeof(vfont->id.name)-2);
			}
			BLI_strncpy(vfont->name, name, sizeof(vfont->name));

			// if autopack is on store the packedfile in de font structure
			if (!is_builtin && (G.fileflags & G_AUTOPACK)) {
				vfont->packedfile = pf;
			}
			
			// Do not add FO_BUILTIN_NAME to temporary listbase
			if (strcmp(filename, FO_BUILTIN_NAME)) {
				tmpfnt= (struct TmpFont *) MEM_callocN(sizeof(struct TmpFont), "temp_font");
				tmpfnt->pf= tpf;
				tmpfnt->vfont= vfont;
				BLI_addtail(&ttfdata, tmpfnt);
			}			
		}
		
		// Free the packed file
		if (!vfont || vfont->packedfile != pf) {
			freePackedFile(pf);
		}
	
		//XXX waitcursor(0);
	}
	
	return vfont;
}