default_backend: implements frame_duration to proceed each frame at a different speed
[platform/core/uifw/libpui.git] / backends / voice / default_ani_timeout.c
index 90b3b4b..058b114 100644 (file)
@@ -49,7 +49,6 @@ _ani_backend_timeout_free_frame(default_frame_info_t *frame)
 static default_frame_info_t *
 _ani_backend_timeout_get_frame(default_ani_info *ani_info)
 {
-#define SMOOTH_FRAME 15
        default_frame_info_t *frame, *key_frame, *key_frame2;
        int idx, idx2;
        unsigned int r, g, b, r2, g2, b2;
@@ -59,7 +58,12 @@ _ani_backend_timeout_get_frame(default_ani_info *ani_info)
        frame = (default_frame_info_t *)calloc(sizeof(default_frame_info_t), 1);
        if (!frame) return NULL;
 
-       idx = ((int)(ani_info->frame_idx / SMOOTH_FRAME)) % ani_info->num_key_frames;
+       if (ani_info->frame_idx == 0)
+       {
+               ani_info->frame_max = (unsigned int)(ani_info->frames[ani_info->key_frame_cur].frame_duration / ani_info->interval);
+       }
+
+       idx = ani_info->key_frame_cur;
        idx2 = (idx + 1) % ani_info->num_key_frames;
 
        key_frame = &ani_info->frames[idx];
@@ -71,7 +75,7 @@ _ani_backend_timeout_get_frame(default_ani_info *ani_info)
                free(frame);
                return NULL;
        }
-       div = (double)(ani_info->frame_idx % SMOOTH_FRAME) / (double)SMOOTH_FRAME;
+       div = (double)(ani_info->frame_idx) / (double)ani_info->frame_max;
        r = g = b = r2 = g2 = b2 = 0x0;
        for (int i = 0; i < key_frame->num_led; i++)
        {
@@ -84,11 +88,12 @@ _ani_backend_timeout_get_frame(default_ani_info *ani_info)
                frame->leds[i].color = (r3 << 16) + (g3 << 8) + (b3);
        }
        ani_info->frame_idx++;
-       if (ani_info->frame_idx >= (ani_info->num_key_frames * SMOOTH_FRAME))
+       if (ani_info->frame_idx >= ani_info->frame_max)
        {
-               if (ani_info->repeat >= 0)
-                       ani_info->repeat_cur++;
                ani_info->frame_idx = 0;
+               ani_info->key_frame_cur = (ani_info->key_frame_cur + 1) % ani_info->num_key_frames;
+               if (ani_info->repeat >= 0 && ani_info->key_frame_cur == 0)
+                       ani_info->repeat_cur++;
        }
 
        return frame;
@@ -175,6 +180,10 @@ _ani_timeout_start(pui_ani_t *ani, int repeat)
        if (repeat == 0) info->repeat = 1;
        else info->repeat = repeat;
 
+       info->key_frame_cur = 0;
+       info->frame_idx = 0;
+       info->repeat_cur = 0;
+
        ret = pui_backend_ani_add_frame_cb(ani, _ani_backend_timeout_frame_cb, info->interval / 1000.0);
        if (!ret)
        {