Code cleanup: use r_ prefix for return args
[blender.git] / source / blender / blenkernel / intern / image.c
index db4a639d91c67bf6c9d7da9086a66baab30b68f6..aaeead431b947560bb6b8f80a7c0a23f666bd579 100644 (file)
@@ -68,6 +68,7 @@
 
 #include "BLI_blenlib.h"
 #include "BLI_threads.h"
+#include "BLI_timecode.h"  /* for stamp timecode format */
 #include "BLI_utildefines.h"
 
 #include "BKE_bmfont.h"
@@ -560,7 +561,7 @@ void BKE_image_merge(Image *dest, Image *source)
 }
 
 /* note, we could be clever and scale all imbuf's but since some are mipmaps its not so simple */
-int BKE_image_scale(Image *image, int width, int height)
+bool BKE_image_scale(Image *image, int width, int height)
 {
        ImBuf *ibuf;
        void *lock;
@@ -597,20 +598,21 @@ static void image_init_color_management(Image *ima)
        }
 }
 
-void BKE_image_alpha_mode_from_extension(Image *image)
+char BKE_image_alpha_mode_from_extension_ex(const char *filepath)
 {
-       if (BLI_testextensie(image->name, ".exr") ||
-           BLI_testextensie(image->name, ".cin") ||
-           BLI_testextensie(image->name, ".dpx") ||
-           BLI_testextensie(image->name, ".hdr"))
-       {
-               image->alpha_mode = IMA_ALPHA_PREMUL;
+       if (BLI_testextensie_n(filepath, ".exr", ".cin", ".dpx", ".hdr", NULL)) {
+               return IMA_ALPHA_PREMUL;
        }
        else {
-               image->alpha_mode = IMA_ALPHA_STRAIGHT;
+               return IMA_ALPHA_STRAIGHT;
        }
 }
 
+void BKE_image_alpha_mode_from_extension(Image *image)
+{
+       image->alpha_mode = BKE_image_alpha_mode_from_extension_ex(image->name);
+}
+
 Image *BKE_image_load(Main *bmain, const char *filepath)
 {
        Image *ima;
@@ -1262,101 +1264,96 @@ char BKE_imtype_from_arg(const char *imtype_arg)
        else return R_IMF_IMTYPE_INVALID;
 }
 
-static int do_add_image_extension(char *string, const char imtype, const ImageFormatData *im_format)
+static bool do_add_image_extension(char *string, const char imtype, const ImageFormatData *im_format)
 {
        const char *extension = NULL;
+       const char *extension_test;
        (void)im_format;  /* may be unused, depends on build options */
 
        if (imtype == R_IMF_IMTYPE_IRIS) {
-               if (!BLI_testextensie(string, ".rgb"))
-                       extension = ".rgb";
+               if (!BLI_testextensie(string, extension_test = ".rgb"))
+                       extension = extension_test;
        }
        else if (imtype == R_IMF_IMTYPE_IRIZ) {
-               if (!BLI_testextensie(string, ".rgb"))
-                       extension = ".rgb";
+               if (!BLI_testextensie(string, extension_test = ".rgb"))
+                       extension = extension_test;
        }
 #ifdef WITH_HDR
        else if (imtype == R_IMF_IMTYPE_RADHDR) {
-               if (!BLI_testextensie(string, ".hdr"))
-                       extension = ".hdr";
+               if (!BLI_testextensie(string, extension_test = ".hdr"))
+                       extension = extension_test;
        }
 #endif
        else if (ELEM5(imtype, R_IMF_IMTYPE_PNG, R_IMF_IMTYPE_FFMPEG, R_IMF_IMTYPE_H264, R_IMF_IMTYPE_THEORA, R_IMF_IMTYPE_XVID)) {
-               if (!BLI_testextensie(string, ".png"))
-                       extension = ".png";
+               if (!BLI_testextensie(string, extension_test = ".png"))
+                       extension = extension_test;
        }
 #ifdef WITH_DDS
        else if (imtype == R_IMF_IMTYPE_DDS) {
-               if (!BLI_testextensie(string, ".dds"))
-                       extension = ".dds";
+               if (!BLI_testextensie(string, extension_test = ".dds"))
+                       extension = extension_test;
        }
 #endif
-       else if (imtype == R_IMF_IMTYPE_RAWTGA) {
-               if (!BLI_testextensie(string, ".tga"))
-                       extension = ".tga";
+       else if (ELEM(imtype, R_IMF_IMTYPE_TARGA, R_IMF_IMTYPE_RAWTGA)) {
+               if (!BLI_testextensie(string, extension_test = ".tga"))
+                       extension = extension_test;
        }
        else if (imtype == R_IMF_IMTYPE_BMP) {
-               if (!BLI_testextensie(string, ".bmp"))
-                       extension = ".bmp";
+               if (!BLI_testextensie(string, extension_test = ".bmp"))
+                       extension = extension_test;
        }
 #ifdef WITH_TIFF
        else if (imtype == R_IMF_IMTYPE_TIFF) {
-               if (!BLI_testextensie(string, ".tif") &&
-                   !BLI_testextensie(string, ".tiff"))
-               {
-                       extension = ".tif";
+               if (!BLI_testextensie_n(string, extension_test = ".tif", ".tiff", NULL)) {
+                       extension = extension_test;
                }
        }
 #endif
 #ifdef WITH_OPENIMAGEIO
        else if (imtype == R_IMF_IMTYPE_PSD) {
-               if (!BLI_testextensie(string, ".psd"))
-                       extension = ".psd";
+               if (!BLI_testextensie(string, extension_test = ".psd"))
+                       extension = extension_test;
        }
 #endif
 #ifdef WITH_OPENEXR
        else if (ELEM(imtype, R_IMF_IMTYPE_OPENEXR, R_IMF_IMTYPE_MULTILAYER)) {
-               if (!BLI_testextensie(string, ".exr"))
-                       extension = ".exr";
+               if (!BLI_testextensie(string, extension_test = ".exr"))
+                       extension = extension_test;
        }
 #endif
 #ifdef WITH_CINEON
        else if (imtype == R_IMF_IMTYPE_CINEON) {
-               if (!BLI_testextensie(string, ".cin"))
-                       extension = ".cin";
+               if (!BLI_testextensie(string, extension_test = ".cin"))
+                       extension = extension_test;
        }
        else if (imtype == R_IMF_IMTYPE_DPX) {
-               if (!BLI_testextensie(string, ".dpx"))
-                       extension = ".dpx";
+               if (!BLI_testextensie(string, extension_test = ".dpx"))
+                       extension = extension_test;
        }
 #endif
-       else if (imtype == R_IMF_IMTYPE_TARGA) {
-               if (!BLI_testextensie(string, ".tga"))
-                       extension = ".tga";
-       }
 #ifdef WITH_OPENJPEG
        else if (imtype == R_IMF_IMTYPE_JP2) {
                if (im_format) {
                        if (im_format->jp2_codec == R_IMF_JP2_CODEC_JP2) {
-                               if (!BLI_testextensie(string, ".jp2"))
-                                       extension = ".jp2";
+                               if (!BLI_testextensie(string, extension_test = ".jp2"))
+                                       extension = extension_test;
                        }
                        else if (im_format->jp2_codec == R_IMF_JP2_CODEC_J2K) {
-                               if (!BLI_testextensie(string, ".j2c"))
-                                       extension = ".j2c";
+                               if (!BLI_testextensie(string, extension_test = ".j2c"))
+                                       extension = extension_test;
                        }
                        else
                                BLI_assert(!"Unsupported jp2 codec was specified in im_format->jp2_codec");
                }
                else {
-                       if (!BLI_testextensie(string, ".jp2"))
-                               extension = ".jp2";
+                       if (!BLI_testextensie(string, extension_test = ".jp2"))
+                               extension = extension_test;
                }
        }
 #endif
        else { //   R_IMF_IMTYPE_AVIRAW, R_IMF_IMTYPE_AVIJPEG, R_IMF_IMTYPE_JPEG90, R_IMF_IMTYPE_QUICKTIME etc
-               if (!(BLI_testextensie(string, ".jpg") || BLI_testextensie(string, ".jpeg")))
-                       extension = ".jpg";
+               if (!(BLI_testextensie_n(string, extension_test = ".jpg", ".jpeg", NULL)))
+                       extension = extension_test;
        }
 
        if (extension) {
@@ -1520,30 +1517,6 @@ void BKE_imbuf_to_image_format(struct ImageFormatData *im_format, const ImBuf *i
 
 }
 
-static void timecode_simple_string(char *text, size_t text_size, const int cfra, int const frs_sec)
-{
-       int f = (int)(cfra % frs_sec);
-       int s = (int)(cfra / frs_sec);
-       int h = 0;
-       int m = 0;
-
-       if (s) {
-               m = (int)(s / 60);
-               s %= 60;
-
-               if (m) {
-                       h = (int)(m / 60);
-                       m %= 60;
-               }
-       }
-
-       if (frs_sec < 100) {
-               BLI_snprintf(text, text_size, "%02d:%02d:%02d.%02d", h, m, s, f);
-       }
-       else {
-               BLI_snprintf(text, text_size, "%02d:%02d:%02d.%03d", h, m, s, f);
-       }
-}
 
 #define STAMP_NAME_SIZE ((MAX_ID_NAME - 2) + 16)
 /* could allow access externally - 512 is for long names,
@@ -1607,8 +1580,9 @@ static void stampdata(Scene *scene, Object *camera, StampData *stamp_data, int d
        }
 
        if (scene->r.stamp & R_STAMP_TIME) {
-               timecode_simple_string(text, sizeof(text), scene->r.cfra, scene->r.frs_sec);
-               BLI_snprintf(stamp_data->time, sizeof(stamp_data->time), do_prefix ? "Time %s" : "%s", text);
+               const short timecode_style = USER_TIMECODE_SMPTE_FULL;
+               BLI_timecode_string_from_time(text, sizeof(text), 0, FRA2TIME(scene->r.cfra), FPS, timecode_style);
+               BLI_snprintf(stamp_data->time, sizeof(stamp_data->time), do_prefix ? "Timecode %s" : "%s", text);
        }
        else {
                stamp_data->time[0] = '\0';
@@ -1912,7 +1886,7 @@ void BKE_imbuf_stamp_info(Scene *scene, Object *camera, struct ImBuf *ibuf)
        if (stamp_data.rendertime[0]) IMB_metadata_change_field(ibuf, "RenderTime", stamp_data.rendertime);
 }
 
-int BKE_imbuf_alpha_test(ImBuf *ibuf)
+bool BKE_imbuf_alpha_test(ImBuf *ibuf)
 {
        int tot;
        if (ibuf->rect_float) {
@@ -2942,7 +2916,7 @@ static ImBuf *image_get_render_result(Image *ima, ImageUser *iuser, void **lock_
        return ibuf;
 }
 
-static void image_get_frame_and_index(Image *ima, ImageUser *iuser, int *frame_r, int *index_r)
+static void image_get_frame_and_index(Image *ima, ImageUser *iuser, int *r_frame, int *r_index)
 {
        int frame = 0, index = 0;
 
@@ -2960,8 +2934,8 @@ static void image_get_frame_and_index(Image *ima, ImageUser *iuser, int *frame_r
                }
        }
 
-       *frame_r = frame;
-       *index_r = index;
+       *r_frame = frame;
+       *r_index = index;
 }
 
 /* Get the ibuf from an image cache for a given image user.
@@ -2970,7 +2944,7 @@ static void image_get_frame_and_index(Image *ima, ImageUser *iuser, int *frame_r
  * call IMB_freeImBuf to de-reference the image buffer after
  * it's done handling it.
  */
-static ImBuf *image_get_cached_ibuf(Image *ima, ImageUser *iuser, int *frame_r, int *index_r)
+static ImBuf *image_get_cached_ibuf(Image *ima, ImageUser *iuser, int *r_frame, int *r_index)
 {
        ImBuf *ibuf = NULL;
        int frame = 0, index = 0;
@@ -3016,16 +2990,16 @@ static ImBuf *image_get_cached_ibuf(Image *ima, ImageUser *iuser, int *frame_r,
                 * a big bottleneck */
        }
 
-       if (frame_r)
-               *frame_r = frame;
+       if (r_frame)
+               *r_frame = frame;
 
-       if (index_r)
-               *index_r = index;
+       if (r_index)
+               *r_index = index;
 
        return ibuf;
 }
 
-BLI_INLINE int image_quick_test(Image *ima, ImageUser *iuser)
+BLI_INLINE bool image_quick_test(Image *ima, ImageUser *iuser)
 {
        if (ima == NULL)
                return FALSE;
@@ -3175,7 +3149,7 @@ void BKE_image_release_ibuf(Image *ima, ImBuf *ibuf, void *lock)
 }
 
 /* checks whether there's an image buffer for given image and user */
-int BKE_image_has_ibuf(Image *ima, ImageUser *iuser)
+bool BKE_image_has_ibuf(Image *ima, ImageUser *iuser)
 {
        ImBuf *ibuf;
 
@@ -3310,7 +3284,7 @@ void BKE_image_pool_release_ibuf(Image *ima, ImBuf *ibuf, ImagePool *pool)
        }
 }
 
-int BKE_image_user_frame_get(const ImageUser *iuser, int cfra, int fieldnr, short *r_is_in_range)
+int BKE_image_user_frame_get(const ImageUser *iuser, int cfra, int fieldnr, bool *r_is_in_range)
 {
        const int len = (iuser->fie_ima * iuser->frames) / 2;
 
@@ -3372,7 +3346,7 @@ int BKE_image_user_frame_get(const ImageUser *iuser, int cfra, int fieldnr, shor
 void BKE_image_user_frame_calc(ImageUser *iuser, int cfra, int fieldnr)
 {
        if (iuser) {
-               short is_in_range;
+               bool is_in_range;
                const int framenr = BKE_image_user_frame_get(iuser, cfra, fieldnr, &is_in_range);
 
                if (is_in_range) {
@@ -3430,7 +3404,7 @@ void BKE_image_user_file_path(ImageUser *iuser, Image *ima, char *filepath)
        BLI_path_abs(filepath, ID_BLEND_PATH(G.main, &ima->id));
 }
 
-int BKE_image_has_alpha(struct Image *image)
+bool BKE_image_has_alpha(struct Image *image)
 {
        ImBuf *ibuf;
        void *lock;
@@ -3646,6 +3620,7 @@ ImBuf *BKE_image_get_ibuf_with_name(Image *image, const char *name)
                                IMB_refImBuf(ibuf);
                                break;
                        }
+                       IMB_moviecacheIter_step(iter);
                }
                IMB_moviecacheIter_free(iter);
        }