De-duplicate stamp callback
authorCampbell Barton <ideasman42@gmail.com>
Fri, 12 Jun 2015 12:34:20 +0000 (14:34 +0200)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 12 Jun 2015 13:29:56 +0000 (15:29 +0200)
source/blender/blenkernel/intern/image.c

index 09934c872f79bc7119d842faaef789e0e9575856..90aa09430ae0a2b7e48e93a9a0c10720de29c671 100644 (file)
@@ -2079,41 +2079,43 @@ void BKE_render_result_stamp_info(Scene *scene, Object *camera, struct RenderRes
        }
 }
 
-
-void BKE_imbuf_stamp_info(RenderResult *rr, struct ImBuf *ibuf)
+void BKE_stamp_info_callback(void *data, const struct StampData *stamp_data, StampCallback callback)
 {
-       struct StampData *stamp_data = rr->stamp_data;
+       if (!callback || !stamp_data) {
+               return;
+       }
+
+#define CALL(member, value_str) \
+       if (stamp_data->member[0]) { \
+               callback(data, value_str, stamp_data->member); \
+       } ((void)0)
 
-       if (!ibuf || !stamp_data) return;
+       CALL(file, "File");
+       CALL(note, "Note");
+       CALL(date, "Date");
+       CALL(marker, "Marker");
+       CALL(time, "Time");
+       CALL(frame, "Frame");
+       CALL(camera, "Camera");
+       CALL(cameralens, "Lens");
+       CALL(scene, "Scene");
+       CALL(strip, "Strip");
+       CALL(rendertime, "RenderTime");
 
-       if (stamp_data->file[0]) IMB_metadata_change_field(ibuf, "File",        stamp_data->file);
-       if (stamp_data->note[0]) IMB_metadata_change_field(ibuf, "Note",        stamp_data->note);
-       if (stamp_data->date[0]) IMB_metadata_change_field(ibuf, "Date",        stamp_data->date);
-       if (stamp_data->marker[0]) IMB_metadata_change_field(ibuf, "Marker",    stamp_data->marker);
-       if (stamp_data->time[0]) IMB_metadata_change_field(ibuf, "Time",        stamp_data->time);
-       if (stamp_data->frame[0]) IMB_metadata_change_field(ibuf, "Frame",      stamp_data->frame);
-       if (stamp_data->camera[0]) IMB_metadata_change_field(ibuf, "Camera",    stamp_data->camera);
-       if (stamp_data->cameralens[0]) IMB_metadata_change_field(ibuf, "Lens",  stamp_data->cameralens);
-       if (stamp_data->scene[0]) IMB_metadata_change_field(ibuf, "Scene",      stamp_data->scene);
-       if (stamp_data->strip[0]) IMB_metadata_change_field(ibuf, "Strip",      stamp_data->strip);
-       if (stamp_data->rendertime[0]) IMB_metadata_change_field(ibuf, "RenderTime", stamp_data->rendertime);
+#undef CALL
 }
 
-void BKE_stamp_info_callback(void *data, const struct StampData *stamp_data, StampCallback callback)
+/* wrap for callback only */
+static void metadata_change_field(void *data, const char *propname, const char *propvalue)
 {
-       if (!callback || !stamp_data) return;
-
-       if (stamp_data->file[0])       callback(data, "File",       stamp_data->file);
-       if (stamp_data->note[0])       callback(data, "Note",       stamp_data->note);
-       if (stamp_data->date[0])       callback(data, "Date",       stamp_data->date);
-       if (stamp_data->marker[0])     callback(data, "Marker",     stamp_data->marker);
-       if (stamp_data->time[0])       callback(data, "Time",       stamp_data->time);
-       if (stamp_data->frame[0])      callback(data, "Frame",      stamp_data->frame);
-       if (stamp_data->camera[0])     callback(data, "Camera",     stamp_data->camera);
-       if (stamp_data->cameralens[0]) callback(data, "Lens",       stamp_data->cameralens);
-       if (stamp_data->scene[0])      callback(data, "Scene",      stamp_data->scene);
-       if (stamp_data->strip[0])      callback(data, "Strip",      stamp_data->strip);
-       if (stamp_data->rendertime[0]) callback(data, "RenderTime", stamp_data->rendertime);
+       IMB_metadata_change_field(data, propname, propvalue);
+}
+
+void BKE_imbuf_stamp_info(RenderResult *rr, struct ImBuf *ibuf)
+{
+       struct StampData *stamp_data = rr->stamp_data;
+
+       BKE_stamp_info_callback(ibuf, stamp_data, metadata_change_field);
 }