minor cleanup, minimal functional change.
authorCampbell Barton <ideasman42@gmail.com>
Tue, 3 Aug 2010 12:34:42 +0000 (12:34 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 3 Aug 2010 12:34:42 +0000 (12:34 +0000)
replace some long duplicated, ifdef'd if statements for image extension.
- new function: BLI_testextensie_array(), can take an array of extensions.
- define extension arrays: imb_ext_image, imb_ext_movie, imb_ext_sound - we could have more of these.
- removed amiga extensions iff and lbm

source/blender/blenlib/BLI_path_util.h
source/blender/blenlib/intern/path_util.c
source/blender/editors/space_file/filelist.c
source/blender/imbuf/IMB_imbuf_types.h
source/blender/imbuf/intern/util.c

index 07e0da5e46113b301f8939d98756e442b02f9664..b8c886d95a935ef0b3dca7f31243d9f64c1891b2 100644 (file)
@@ -99,6 +99,7 @@ char *BLI_path_basename(char *path);
 int BKE_rebase_path(char *abs, int abs_size, char *rel, int rel_size, const char *base_dir, const char *src_dir, const char *dest_dir);
 void BLI_getlastdir(const char* dir, char *last, int maxlen);
 int BLI_testextensie(const char *str, const char *ext);
+int BLI_testextensie_array(const char *str, const char **ext_array);
 int BLI_replace_extension(char *path, int maxlen, const char *ext);
 void BLI_uniquename(struct ListBase *list, void *vlink, const char defname[], char delim, short name_offs, short len);
 void BLI_newname(char * name, int add);
index d3e2b8f83e5c9dd9977acaeed49687cfa770f627..9a56722b5d91764fa551e439b9e6768442ae95a1 100644 (file)
@@ -1263,6 +1263,19 @@ int BLI_testextensie(const char *str, const char *ext)
        return (retval);
 }
 
+int BLI_testextensie_array(const char *str, const char **ext_array)
+{
+       int i=0;
+       while(ext_array[i]) {
+               if(BLI_testextensie(str, ext_array[i])) {
+                       return 1;
+               }
+
+               i++;
+       }
+       return 0;
+}
+
 int BLI_replace_extension(char *path, int maxlen, const char *ext)
 {
        int a;
index a6668d9a5fef7f1556c241322b64d20306480055..310e3d49bd903556c271b3405e98e9415d971745 100644 (file)
@@ -828,153 +828,13 @@ void filelist_setfiletypes(struct FileList* filelist, short has_quicktime)
                                file->flags |= BTXFILE;
                } else if(BLI_testextensie(file->relname, ".dae")) {
                        file->flags |= COLLADAFILE;
-               } else if (has_quicktime){
-                       if(             BLI_testextensie(file->relname, ".int")
-                               ||  BLI_testextensie(file->relname, ".inta")
-                               ||  BLI_testextensie(file->relname, ".jpg")
-#ifdef WITH_OPENJPEG
-                               ||  BLI_testextensie(file->relname, ".jp2")
-#endif
-                               ||      BLI_testextensie(file->relname, ".jpeg")
-                               ||      BLI_testextensie(file->relname, ".tga")
-                               ||      BLI_testextensie(file->relname, ".rgb")
-                               ||      BLI_testextensie(file->relname, ".rgba")
-                               ||      BLI_testextensie(file->relname, ".bmp")
-                               ||      BLI_testextensie(file->relname, ".png")
-                               ||      BLI_testextensie(file->relname, ".iff")
-                               ||      BLI_testextensie(file->relname, ".lbm")
-                               ||      BLI_testextensie(file->relname, ".gif")
-                               ||      BLI_testextensie(file->relname, ".psd")
-                               ||      BLI_testextensie(file->relname, ".tif")
-                               ||      BLI_testextensie(file->relname, ".tiff")
-                               ||      BLI_testextensie(file->relname, ".tx")
-                               ||      BLI_testextensie(file->relname, ".pct")
-                               ||      BLI_testextensie(file->relname, ".pict")
-                               ||      BLI_testextensie(file->relname, ".pntg") //macpaint
-                               ||      BLI_testextensie(file->relname, ".qtif")
-                               ||      BLI_testextensie(file->relname, ".sgi")
-#ifdef WITH_HDR
-                               ||      BLI_testextensie(file->relname, ".hdr")
-#endif
-#ifdef WITH_CINEON
-                               ||      BLI_testextensie(file->relname, ".cin")
-                               ||      BLI_testextensie(file->relname, ".dpx")
-#endif
-#ifdef WITH_DDS
-                               ||      BLI_testextensie(file->relname, ".dds")
-#endif
-#ifdef WITH_OPENEXR
-                               ||      BLI_testextensie(file->relname, ".exr")
-#endif
-                               ) {
+               } else if(BLI_testextensie_array(file->relname, imb_ext_image)
+                                       || (has_quicktime && BLI_testextensie_array(file->relname, imb_ext_image_qt))) {
                                file->flags |= IMAGEFILE;                       
-                       }
-                       else if(BLI_testextensie(file->relname, ".avi")
-                               ||      BLI_testextensie(file->relname, ".flc")
-                               ||      BLI_testextensie(file->relname, ".mov")
-                               ||      BLI_testextensie(file->relname, ".movie")
-                               ||      BLI_testextensie(file->relname, ".mp4")
-                               ||      BLI_testextensie(file->relname, ".m4v")
-                               ||      BLI_testextensie(file->relname, ".m2v")
-                               ||      BLI_testextensie(file->relname, ".m2t")
-                               ||      BLI_testextensie(file->relname, ".mts")
-                               ||      BLI_testextensie(file->relname, ".mv")
-                               ||      BLI_testextensie(file->relname, ".avs")
-                               ||      BLI_testextensie(file->relname, ".wmv")
-                               ||      BLI_testextensie(file->relname, ".ogv")
-                               ||      BLI_testextensie(file->relname, ".dv")
-                               ||      BLI_testextensie(file->relname, ".mpeg")
-                               ||      BLI_testextensie(file->relname, ".mpg")
-                               ||      BLI_testextensie(file->relname, ".mpg2")
-                               ||      BLI_testextensie(file->relname, ".vob")
-                               ||      BLI_testextensie(file->relname, ".mkv")
-                               ||      BLI_testextensie(file->relname, ".flv")
-                               ||      BLI_testextensie(file->relname, ".divx")
-                               ||      BLI_testextensie(file->relname, ".xvid")) {
-                               file->flags |= MOVIEFILE;                       
-                       }
-                       else if(BLI_testextensie(file->relname, ".wav")
-                               ||      BLI_testextensie(file->relname, ".ogg")
-                               ||      BLI_testextensie(file->relname, ".oga")
-                               ||      BLI_testextensie(file->relname, ".mp3")
-                               ||      BLI_testextensie(file->relname, ".mp2")
-                               ||      BLI_testextensie(file->relname, ".ac3")
-                               ||      BLI_testextensie(file->relname, ".aac")
-                               ||      BLI_testextensie(file->relname, ".flac")
-                               ||      BLI_testextensie(file->relname, ".wma")
-                               ||      BLI_testextensie(file->relname, ".eac3")) {
-                               file->flags |= SOUNDFILE;
-                       }
-               } else { // no quicktime
-                       if(BLI_testextensie(file->relname, ".int")
-                               ||      BLI_testextensie(file->relname, ".inta")
-                               ||      BLI_testextensie(file->relname, ".jpg")
-                               ||  BLI_testextensie(file->relname, ".jpeg")
-#ifdef WITH_OPENJPEG
-                               ||  BLI_testextensie(file->relname, ".jp2")
-#endif
-                               ||      BLI_testextensie(file->relname, ".tga")
-                               ||      BLI_testextensie(file->relname, ".rgb")
-                               ||      BLI_testextensie(file->relname, ".rgba")
-                               ||      BLI_testextensie(file->relname, ".bmp")
-                               ||      BLI_testextensie(file->relname, ".png")
-                               ||      BLI_testextensie(file->relname, ".iff")
-                               ||      BLI_testextensie(file->relname, ".tif")
-                               ||      BLI_testextensie(file->relname, ".tiff")
-                               ||      BLI_testextensie(file->relname, ".tx")
-#ifdef WITH_HDR
-                               ||      BLI_testextensie(file->relname, ".hdr")
-#endif
-#ifdef WITH_CINEON                             
-                               ||      BLI_testextensie(file->relname, ".cin")
-                               ||      BLI_testextensie(file->relname, ".dpx")
-#endif
-#ifdef WITH_DDS
-                               ||      BLI_testextensie(file->relname, ".dds")
-#endif
-#ifdef WITH_OPENEXR
-                               ||      BLI_testextensie(file->relname, ".exr")
-#endif
-                               ||      BLI_testextensie(file->relname, ".lbm")
-                               ||      BLI_testextensie(file->relname, ".sgi")) {
-                               file->flags |= IMAGEFILE;                       
-                       }
-                       else if(BLI_testextensie(file->relname, ".avi")
-                               ||      BLI_testextensie(file->relname, ".flc")
-                               ||      BLI_testextensie(file->relname, ".mov")
-                               ||      BLI_testextensie(file->relname, ".movie")
-                               ||      BLI_testextensie(file->relname, ".mp4")
-                               ||      BLI_testextensie(file->relname, ".m4v")
-                               ||      BLI_testextensie(file->relname, ".m2v")
-                               ||      BLI_testextensie(file->relname, ".m2t")
-                               ||      BLI_testextensie(file->relname, ".mts")
-                               ||      BLI_testextensie(file->relname, ".mv")
-                               ||      BLI_testextensie(file->relname, ".avs")
-                               ||      BLI_testextensie(file->relname, ".wmv")
-                               ||      BLI_testextensie(file->relname, ".ogv")
-                               ||      BLI_testextensie(file->relname, ".dv")
-                               ||      BLI_testextensie(file->relname, ".mpeg")
-                               ||      BLI_testextensie(file->relname, ".mpg")
-                               ||      BLI_testextensie(file->relname, ".mpg2")
-                               ||      BLI_testextensie(file->relname, ".vob")
-                               ||      BLI_testextensie(file->relname, ".mkv")
-                               ||      BLI_testextensie(file->relname, ".flv")
-                               ||      BLI_testextensie(file->relname, ".divx")
-                               ||      BLI_testextensie(file->relname, ".xvid")) {
-                               file->flags |= MOVIEFILE;                       
-                       }
-                       else if(BLI_testextensie(file->relname, ".wav")
-                               ||      BLI_testextensie(file->relname, ".ogg")
-                               ||      BLI_testextensie(file->relname, ".oga")
-                               ||      BLI_testextensie(file->relname, ".mp3")
-                               ||      BLI_testextensie(file->relname, ".mp2")
-                               ||      BLI_testextensie(file->relname, ".ac3")
-                               ||      BLI_testextensie(file->relname, ".aac")
-                               ||      BLI_testextensie(file->relname, ".flac")
-                               ||      BLI_testextensie(file->relname, ".wma")
-                               ||      BLI_testextensie(file->relname, ".eac3")) {
-                               file->flags |= SOUNDFILE;
-                       }
+               } else if(BLI_testextensie_array(file->relname, imb_ext_movie)) {
+                       file->flags |= MOVIEFILE;                       
+               } else if(BLI_testextensie_array(file->relname, imb_ext_audio)) {
+                       file->flags |= SOUNDFILE;
                }
        }
 }
index 7408a43ee651940522a1af3684a93c5e6c17d389..203a7268581d914d079b9aa9ef6e0f4e6e339d28 100644 (file)
@@ -222,5 +222,9 @@ typedef struct ImBuf {
 #define IB_PROFILE_SRGB                        2
 #define IB_PROFILE_CUSTOM              3
 
-#endif
+extern const char *imb_ext_image[];
+extern const char *imb_ext_image_qt[];
+extern const char *imb_ext_movie[];
+extern const char *imb_ext_audio[];
 
+#endif
index 726a8fe2f3623349a49ab3175ff52e85ef555957..13ffa504fec596af5a9cdd00c8b89b3ac83b170b 100644 (file)
 
 #define UTIL_DEBUG 0
 
+const char *imb_ext_image[] = {
+       ".png"
+       ".tga",
+       ".bmp",
+       ".jpg", ".jpeg",
+       ".sgi", ".rgb", ".rgba",
+#ifdef WITH_TIFF
+       ".tif", ".tiff", ".tx",
+#endif
+#ifdef WITH_BF_OPENJPEG
+       ".jp2",
+#endif
+#ifdef WITH_HDR
+       ".hdr",
+#endif
+#ifdef WITH_DDS
+       ".dds",
+#endif
+#ifdef WITH_CINEON
+       ".dpx",
+       ".cin",
+#endif
+#ifdef WITH_BF_OPENEXR
+       ".exr",
+#endif
+       NULL};
+
+const char *imb_ext_image_qt[] = {
+       ".gif",
+       ".psd",
+       ".pct", ".pict",
+       ".pntg",
+       ".qtif",
+       NULL};
+
+const char *imb_ext_movie[] = {
+       ".avi",
+       ".flc",
+       ".mov",
+       ".movie",
+       ".mp4",
+       ".m4v",
+       ".m2v",
+       ".m2t",
+       ".mts",
+       ".mv",
+       ".avs",
+       ".wmv",
+       ".ogv",
+       ".dv",
+       ".mpeg",
+       ".mpg",
+       ".mpg2",
+       ".vob",
+       ".mkv",
+       ".flv",
+       ".divx",
+       ".xvid",
+       NULL};
+
+/* sort of wrong being here... */
+const char *imb_ext_audio[] = {
+       ".wav",
+       ".ogg",
+       ".oga",
+       ".mp3",
+       ".mp2",
+       ".ac3",
+       ".aac",
+       ".flac",
+       ".wma",
+       ".eac3",
+       NULL};
+
 static int IMB_ispic_name(char *name)
 {
        ImFileType *type;
@@ -105,90 +179,16 @@ static int IMB_ispic_name(char *name)
 int IMB_ispic(char *filename)
 {
        if(U.uiflag & USER_FILTERFILEEXTS) {
-               if (BLI_testextensie(filename, ".tif")
-                               ||      BLI_testextensie(filename, ".tiff")
-                               ||      BLI_testextensie(filename, ".tx")) {
-                               return IMB_ispic_name(filename);
+               if(     (BLI_testextensie_array(filename, imb_ext_image)) ||
+                       (G.have_quicktime && BLI_testextensie_array(filename, imb_ext_image_qt))
+               ) {
+                       return IMB_ispic_name(filename);
                }
-               if (G.have_quicktime){
-                       if(             BLI_testextensie(filename, ".jpg")
-                               ||      BLI_testextensie(filename, ".jpeg")
-#ifdef WITH_TIFF
-                               ||      BLI_testextensie(filename, ".tif")
-                               ||      BLI_testextensie(filename, ".tiff")
-                               ||      BLI_testextensie(filename, ".tx")
-#endif
-#ifdef WITH_HDR
-                               ||      BLI_testextensie(filename, ".hdr")
-#endif
-                               ||      BLI_testextensie(filename, ".tga")
-                               ||      BLI_testextensie(filename, ".rgb")
-                               ||      BLI_testextensie(filename, ".bmp")
-                               ||      BLI_testextensie(filename, ".png")
-#ifdef WITH_DDS
-                               ||      BLI_testextensie(filename, ".dds")
-#endif
-                               ||      BLI_testextensie(filename, ".iff")
-                               ||      BLI_testextensie(filename, ".lbm")
-                               ||      BLI_testextensie(filename, ".gif")
-                               ||      BLI_testextensie(filename, ".psd")
-                               ||      BLI_testextensie(filename, ".pct")
-                               ||      BLI_testextensie(filename, ".pict")
-                               ||      BLI_testextensie(filename, ".pntg") //macpaint
-                               ||      BLI_testextensie(filename, ".qtif")
-#ifdef WITH_CINEON                             
-                               ||      BLI_testextensie(filename, ".dpx")
-                               ||      BLI_testextensie(filename, ".cin")
-#endif
-#ifdef WITH_BF_OPENEXR
-                               ||      BLI_testextensie(filename, ".exr")
-#endif
-#ifdef WITH_BF_OPENJPEG
-                               ||      BLI_testextensie(filename, ".jp2")
-#endif
-                               ||      BLI_testextensie(filename, ".sgi")) {
-                               return IMB_ispic_name(filename);
-                       } else {
-                               return(FALSE);                  
-                       }
-               } else { /* no quicktime */
-                       if(             BLI_testextensie(filename, ".jpg")
-                               ||      BLI_testextensie(filename, ".jpeg")
-#ifdef WITH_TIFF
-                               ||      BLI_testextensie(filename, ".tif")
-                               ||      BLI_testextensie(filename, ".tiff")
-                               ||      BLI_testextensie(filename, ".tx")
-#endif
-#ifdef WITH_HDR
-                               ||      BLI_testextensie(filename, ".hdr")
-#endif
-                               ||      BLI_testextensie(filename, ".tga")
-                               ||      BLI_testextensie(filename, ".rgb")
-                               ||      BLI_testextensie(filename, ".bmp")
-                               ||      BLI_testextensie(filename, ".png")
-#ifdef WITH_CINEON
-                               ||      BLI_testextensie(filename, ".cin")
-                               ||      BLI_testextensie(filename, ".dpx")
-#endif
-#ifdef WITH_DDS
-                               ||      BLI_testextensie(filename, ".dds")
-#endif
-#ifdef WITH_BF_OPENEXR
-                               ||      BLI_testextensie(filename, ".exr")
-#endif
-#ifdef WITH_BF_OPENJPEG
-                               ||      BLI_testextensie(filename, ".jp2")
-#endif
-                               ||      BLI_testextensie(filename, ".iff")
-                               ||      BLI_testextensie(filename, ".lbm")
-                               ||      BLI_testextensie(filename, ".sgi")) {
-                               return IMB_ispic_name(filename);
-                       }
-                       else  {
-                               return(FALSE);
-                       }
+               else  {
+                       return FALSE;
                }
-       } else { /* no FILTERFILEEXTS */
+       }
+       else { /* no FILTERFILEEXTS */
                return IMB_ispic_name(filename);
        }
 }