Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Guetzkow <gitcommit@outlook.de>2020-11-13 01:57:55 +0300
committerCampbell Barton <ideasman42@gmail.com>2020-11-13 02:11:00 +0300
commit9a73417337f5dffa08f893382acc29191d8405f6 (patch)
tree36e28a1f83cf62891fb42e5bf64ddc07d3679c51 /source/blender/blenkernel/intern/packedFile.c
parentcd49afc596a0b24ce9e0045afb03906aca481b9a (diff)
Fix T82349: file extension not added to unpacked images
Ensure the appropriate extension is set when unpacking generated images that don't have a filepath set. Ref D9500
Diffstat (limited to 'source/blender/blenkernel/intern/packedFile.c')
-rw-r--r--source/blender/blenkernel/intern/packedFile.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/source/blender/blenkernel/intern/packedFile.c b/source/blender/blenkernel/intern/packedFile.c
index ac3686a021b..e99dd77005b 100644
--- a/source/blender/blenkernel/intern/packedFile.c
+++ b/source/blender/blenkernel/intern/packedFile.c
@@ -51,6 +51,9 @@
#include "BKE_sound.h"
#include "BKE_volume.h"
+#include "IMB_imbuf.h"
+#include "IMB_imbuf_types.h"
+
#include "BLO_read_write.h"
int BKE_packedfile_seek(PackedFile *pf, int offset, int whence)
@@ -517,15 +520,30 @@ static void unpack_generate_paths(const char *name,
size_t abspathlen,
size_t relpathlen)
{
+ const short id_type = GS(id->name);
char tempname[FILE_MAX];
char tempdir[FILE_MAXDIR];
BLI_split_dirfile(name, tempdir, tempname, sizeof(tempdir), sizeof(tempname));
if (tempname[0] == '\0') {
- /* Note: we do not have any real way to re-create extension out of data... */
+ /* Note: we generally do not have any real way to re-create extension out of data. */
BLI_strncpy(tempname, id->name + 2, sizeof(tempname));
printf("%s\n", tempname);
+
+ /* For images we can add the file extension based on the file magic. */
+ if (id_type == ID_IM) {
+ ImagePackedFile *imapf = ((Image *)id)->packedfiles.last;
+ if (imapf != NULL && imapf->packedfile != NULL) {
+ const PackedFile *pf = imapf->packedfile;
+ const int ftype = IMB_ispic_type_from_memory((const uchar *)pf->data, pf->size);
+ if (ftype != 0) {
+ const int imtype = BKE_image_ftype_to_imtype(ftype, NULL);
+ BKE_image_path_ensure_ext_from_imtype(tempname, imtype);
+ }
+ }
+ }
+
BLI_filename_make_safe(tempname);
printf("%s\n", tempname);
}
@@ -535,7 +553,7 @@ static void unpack_generate_paths(const char *name,
BLI_strncpy(tempdir, "//", sizeof(tempdir));
}
- switch (GS(id->name)) {
+ switch (id_type) {
case ID_VF:
BLI_snprintf(r_relpath, relpathlen, "//fonts/%s", tempname);
break;