[Bf-blender-cvs] [454b7876ff1] master: Cleanup: remove unnecessary ImFileType.ftype callback

Campbell Barton noreply at git.blender.org
Fri Nov 13 01:30:49 CET 2020


Commit: 454b7876ff18c5103cad7d1ebc4e7bef5b1bff4b
Author: Campbell Barton
Date:   Fri Nov 13 11:24:02 2020 +1100
Branches: master
https://developer.blender.org/rB454b7876ff18c5103cad7d1ebc4e7bef5b1bff4b

Cleanup: remove unnecessary ImFileType.ftype callback

This callback made some sense before moving the file-type information
from a bit-flag to an enum: e142ae77cadf04103fbc643f21cf60891862f6a8

Since then, we can compare the type value directly.

Also replace loops over file types with IMB_file_type_from_{ibuf/ftype}.

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

M	source/blender/imbuf/intern/IMB_filetype.h
M	source/blender/imbuf/intern/colormanagement.c
M	source/blender/imbuf/intern/filetype.c
M	source/blender/imbuf/intern/readimage.c
M	source/blender/imbuf/intern/util.c
M	source/blender/imbuf/intern/writeimage.c

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

diff --git a/source/blender/imbuf/intern/IMB_filetype.h b/source/blender/imbuf/intern/IMB_filetype.h
index 7bdbbb03227..175d973de9a 100644
--- a/source/blender/imbuf/intern/IMB_filetype.h
+++ b/source/blender/imbuf/intern/IMB_filetype.h
@@ -33,7 +33,6 @@ typedef struct ImFileType {
   void (*exit)(void);
 
   bool (*is_a)(const unsigned char *buf, const size_t size);
-  int (*ftype)(const struct ImFileType *type, const struct ImBuf *ibuf);
   struct ImBuf *(*load)(const unsigned char *mem,
                         size_t size,
                         int flags,
@@ -55,6 +54,9 @@ typedef struct ImFileType {
 extern const ImFileType IMB_FILE_TYPES[];
 extern const ImFileType *IMB_FILE_TYPES_LAST;
 
+const ImFileType *IMB_file_type_from_ftype(int ftype);
+const ImFileType *IMB_file_type_from_ibuf(const struct ImBuf *ibuf);
+
 void imb_filetypes_init(void);
 void imb_filetypes_exit(void);
 
diff --git a/source/blender/imbuf/intern/colormanagement.c b/source/blender/imbuf/intern/colormanagement.c
index c169633fa3c..9dced926dcc 100644
--- a/source/blender/imbuf/intern/colormanagement.c
+++ b/source/blender/imbuf/intern/colormanagement.c
@@ -2616,7 +2616,6 @@ ImBuf *IMB_colormanagement_imbuf_for_write(ImBuf *ibuf,
 
   if (do_colormanagement) {
     bool make_byte = false;
-    const ImFileType *type;
 
     /* for proper check whether byte buffer is required by a format or not
      * should be pretty safe since this image buffer is supposed to be used for
@@ -2629,13 +2628,10 @@ ImBuf *IMB_colormanagement_imbuf_for_write(ImBuf *ibuf,
      * we need to allocate byte buffer and store color managed
      * image there
      */
-    for (type = IMB_FILE_TYPES; type < IMB_FILE_TYPES_LAST; type++) {
-      if (type->save && type->ftype(type, colormanaged_ibuf)) {
-        if ((type->flag & IM_FTYPE_FLOAT) == 0) {
-          make_byte = true;
-        }
-
-        break;
+    const ImFileType *type = IMB_file_type_from_ibuf(colormanaged_ibuf);
+    if (type != NULL) {
+      if ((type->save != NULL) && (type->flag & IM_FTYPE_FLOAT) == 0) {
+        make_byte = true;
       }
     }
 
@@ -3238,14 +3234,11 @@ void IMB_colormanagement_colorspace_from_ibuf_ftype(
   }
 
   /* Get color space from file type. */
-  const ImFileType *type;
-
-  for (type = IMB_FILE_TYPES; type < IMB_FILE_TYPES_LAST; type++) {
-    if (type->save && type->ftype(type, ibuf)) {
-      const char *role_colorspace;
-
-      role_colorspace = IMB_colormanagement_role_colorspace_name_get(type->default_save_role);
-
+  const ImFileType *type = IMB_file_type_from_ibuf(ibuf);
+  if (type != NULL) {
+    if (type->save != NULL) {
+      const char *role_colorspace = IMB_colormanagement_role_colorspace_name_get(
+          type->default_save_role);
       BLI_strncpy(colorspace_settings->name, role_colorspace, sizeof(colorspace_settings->name));
     }
   }
diff --git a/source/blender/imbuf/intern/filetype.c b/source/blender/imbuf/intern/filetype.c
index d952da2d351..b1fe557a9bf 100644
--- a/source/blender/imbuf/intern/filetype.c
+++ b/source/blender/imbuf/intern/filetype.c
@@ -40,22 +40,11 @@
 #  include "dds/dds_api.h"
 #endif
 
-static int imb_ftype_default(const ImFileType *type, const ImBuf *ibuf)
-{
-  return (ibuf->ftype == type->filetype);
-}
-static int imb_ftype_iris(const ImFileType *type, const ImBuf *ibuf)
-{
-  (void)type;
-  return (ibuf->ftype == IMB_FTYPE_IMAGIC);
-}
-
 const ImFileType IMB_FILE_TYPES[] = {
     {
         .init = NULL,
         .exit = NULL,
         .is_a = imb_is_a_jpeg,
-        .ftype = imb_ftype_default,
         .load = imb_load_jpeg,
         .load_filepath = NULL,
         .save = imb_savejpeg,
@@ -68,7 +57,6 @@ const ImFileType IMB_FILE_TYPES[] = {
         .init = NULL,
         .exit = NULL,
         .is_a = imb_is_a_png,
-        .ftype = imb_ftype_default,
         .load = imb_loadpng,
         .load_filepath = NULL,
         .save = imb_savepng,
@@ -81,7 +69,6 @@ const ImFileType IMB_FILE_TYPES[] = {
         .init = NULL,
         .exit = NULL,
         .is_a = imb_is_a_bmp,
-        .ftype = imb_ftype_default,
         .load = imb_bmp_decode,
         .load_filepath = NULL,
         .save = imb_savebmp,
@@ -94,7 +81,6 @@ const ImFileType IMB_FILE_TYPES[] = {
         .init = NULL,
         .exit = NULL,
         .is_a = imb_is_a_targa,
-        .ftype = imb_ftype_default,
         .load = imb_loadtarga,
         .load_filepath = NULL,
         .save = imb_savetarga,
@@ -107,7 +93,6 @@ const ImFileType IMB_FILE_TYPES[] = {
         .init = NULL,
         .exit = NULL,
         .is_a = imb_is_a_iris,
-        .ftype = imb_ftype_iris,
         .load = imb_loadiris,
         .load_filepath = NULL,
         .save = imb_saveiris,
@@ -121,7 +106,6 @@ const ImFileType IMB_FILE_TYPES[] = {
         .init = NULL,
         .exit = NULL,
         .is_a = imb_is_a_dpx,
-        .ftype = imb_ftype_default,
         .load = imb_load_dpx,
         .load_filepath = NULL,
         .save = imb_save_dpx,
@@ -134,7 +118,6 @@ const ImFileType IMB_FILE_TYPES[] = {
         .init = NULL,
         .exit = NULL,
         .is_a = imb_is_a_cineon,
-        .ftype = imb_ftype_default,
         .load = imb_load_cineon,
         .load_filepath = NULL,
         .save = imb_save_cineon,
@@ -149,7 +132,6 @@ const ImFileType IMB_FILE_TYPES[] = {
         .init = imb_inittiff,
         .exit = NULL,
         .is_a = imb_is_a_tiff,
-        .ftype = imb_ftype_default,
         .load = imb_loadtiff,
         .load_filepath = NULL,
         .save = imb_savetiff,
@@ -164,7 +146,6 @@ const ImFileType IMB_FILE_TYPES[] = {
         .init = NULL,
         .exit = NULL,
         .is_a = imb_is_a_hdr,
-        .ftype = imb_ftype_default,
         .load = imb_loadhdr,
         .load_filepath = NULL,
         .save = imb_savehdr,
@@ -179,7 +160,6 @@ const ImFileType IMB_FILE_TYPES[] = {
         .init = imb_initopenexr,
         .exit = imb_exitopenexr,
         .is_a = imb_is_a_openexr,
-        .ftype = imb_ftype_default,
         .load = imb_load_openexr,
         .load_filepath = NULL,
         .save = imb_save_openexr,
@@ -194,7 +174,6 @@ const ImFileType IMB_FILE_TYPES[] = {
         .init = NULL,
         .exit = NULL,
         .is_a = imb_is_a_jp2,
-        .ftype = imb_ftype_default,
         .load = imb_load_jp2,
         .load_filepath = NULL,
         .save = imb_save_jp2,
@@ -209,7 +188,6 @@ const ImFileType IMB_FILE_TYPES[] = {
         .init = NULL,
         .exit = NULL,
         .is_a = imb_is_a_dds,
-        .ftype = imb_ftype_default,
         .load = imb_load_dds,
         .load_filepath = NULL,
         .save = NULL,
@@ -224,7 +202,6 @@ const ImFileType IMB_FILE_TYPES[] = {
         .init = NULL,
         .exit = NULL,
         .is_a = imb_is_a_photoshop,
-        .ftype = imb_ftype_default,
         .load = NULL,
         .load_filepath = imb_load_photoshop,
         .save = NULL,
@@ -234,11 +211,26 @@ const ImFileType IMB_FILE_TYPES[] = {
         .default_save_role = COLOR_ROLE_DEFAULT_FLOAT,
     },
 #endif
-    {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 0},
+    {NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 0},
 };
 
 const ImFileType *IMB_FILE_TYPES_LAST = &IMB_FILE_TYPES[ARRAY_SIZE(IMB_FILE_TYPES) - 1];
 
+const ImFileType *IMB_file_type_from_ftype(int ftype)
+{
+  for (const ImFileType *type = IMB_FILE_TYPES; type < IMB_FILE_TYPES_LAST; type++) {
+    if (ftype == type->filetype) {
+      return type;
+    }
+  }
+  return NULL;
+}
+
+const ImFileType *IMB_file_type_from_ibuf(const ImBuf *ibuf)
+{
+  return IMB_file_type_from_ftype(ibuf->ftype);
+}
+
 void imb_filetypes_init(void)
 {
   const ImFileType *type;
diff --git a/source/blender/imbuf/intern/readimage.c b/source/blender/imbuf/intern/readimage.c
index 8b322eaf052..f0daa4543e1 100644
--- a/source/blender/imbuf/intern/readimage.c
+++ b/source/blender/imbuf/intern/readimage.c
@@ -282,7 +282,6 @@ ImBuf *IMB_testiffname(const char *filepath, int flags)
 
 static void imb_loadtilefile(ImBuf *ibuf, int file, int tx, int ty, unsigned int *rect)
 {
-  const ImFileType *type;
   unsigned char *mem;
   size_t size;
 
@@ -301,8 +300,9 @@ static void imb_loadtilefile(ImBuf *ibuf, int file, int tx, int ty, unsigned int
     return;
   }
 
-  for (type = IMB_FILE_TYPES; type < IMB_FILE_TYPES_LAST; type++) {
-    if (type->load_tile && type->ftype(type, ibuf)) {
+  const ImFileType *type = IMB_file_type_from_ibuf(ibuf);
+  if (type != NULL) {
+    if (type->load_tile != NULL) {
       type->load_tile(ibuf, mem, size, tx, ty, rect);
     }
   }
diff --git a/source/blender/imbuf/intern/util.c b/source/blender/imbuf/intern/util.c
index 5b9aa9ed88a..c18321ae2fe 100644
--- a/source/blender/imbuf/intern/util.c
+++ b/source/blender/imbuf/intern/util.c
@@ -180,14 +180,13 @@ bool IMB_ispic_type_matches(const char *filepath, int filetype)
     return false;
   }
 
-  for (const ImFileType *type = IMB_FILE_TYPES; type < IMB_FILE_TYPES_LAST; type++) {
-    if (type->filetype == filetype) {
-      /* Requesting to load a type that can't check it's own header doesn't make sense.
-       * Keep the check for developers. */
-      BLI_assert(type->is_a != NULL);
-      if (type->is_a != NULL) {
-        return type->is_a(buf, (size_t)buf_size);
-      }
+  const ImFileType *type = IMB_file_type_from_ftype(filetype);
+  if (type != NULL) {
+    /* Requesting to load a type that can't check it's own header doesn't make sense.
+     * Keep the check for developers. */
+    BLI_assert(type->is_a != NULL);
+    if (type->is_a != NULL) {
+      return type->is_a(buf, (size_t)buf_size);
     }
   }
   return false;
@@ -416,11 +415,10 @@ bool IMB_isanim(const char *filepath)
 
 bool IMB_isfloat(const ImBuf *ibuf)
 {
-  const ImFileType *type;
-
-  for (type = IMB_FILE_TYPES; type < IMB_FILE_TYPES_LAST; type++) {
-    if (type->ftype(type, ibuf)) {
-      return (type->flag & IM_FTYPE_FLOAT) != 0;
+  const ImFileType *type = IMB_file_type_from_ibuf(ibuf);
+  if (type != NULL) {
+    if (type->flag & IM_FTYPE_FLOAT) {
+      return true;
     }
   }
   return false;
diff --git a/source/blender/imbuf/intern/writeimage.c b/source/blender/imbuf/intern/writeimage.c
index 71ecc8b14ae..f21d274f8fd 100644
--- a/source/blender/imbuf/intern/

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list