[Bf-blender-cvs] [9a73417337f] master: Fix T82349: file extension not added to unpacked images

Robert Guetzkow noreply at git.blender.org
Fri Nov 13 00:17:54 CET 2020


Commit: 9a73417337f5dffa08f893382acc29191d8405f6
Author: Robert Guetzkow
Date:   Fri Nov 13 09:57:55 2020 +1100
Branches: master
https://developer.blender.org/rB9a73417337f5dffa08f893382acc29191d8405f6

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

===================================================================

M	source/blender/blenkernel/intern/packedFile.c

===================================================================

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;



More information about the Bf-blender-cvs mailing list